001: /*
002: * (C) Janne Jalkanen 2005
003: *
004: */
005: package com.ecyrd.jspwiki.url;
006:
007: import java.util.Properties;
008:
009: import junit.framework.Test;
010: import junit.framework.TestCase;
011: import junit.framework.TestSuite;
012:
013: import com.ecyrd.jspwiki.TestEngine;
014: import com.ecyrd.jspwiki.WikiContext;
015: import com.ecyrd.jspwiki.WikiEngine;
016: import com.ecyrd.jspwiki.WikiException;
017:
018: public class ShortURLConstructorTest extends TestCase {
019: TestEngine testEngine;
020:
021: Properties props = new Properties();
022:
023: protected void setUp() throws Exception {
024: props.load(TestEngine.findTestProperties());
025: }
026:
027: private URLConstructor getConstructor(String baseURL, String prefix)
028: throws WikiException {
029: props.setProperty(WikiEngine.PROP_BASEURL, baseURL);
030: if (prefix != null)
031: props.setProperty(ShortURLConstructor.PROP_PREFIX, prefix);
032:
033: testEngine = new TestEngine(props);
034: URLConstructor constr = new ShortURLConstructor();
035:
036: constr.initialize(testEngine, props);
037:
038: return constr;
039: }
040:
041: public void testViewURL1() throws Exception {
042: URLConstructor c = getConstructor("http://localhost/", "wiki/");
043:
044: assertEquals("http://localhost/wiki/Main", c.makeURL(
045: WikiContext.VIEW, "Main", true, null));
046: }
047:
048: public void testViewURL2() throws Exception {
049: URLConstructor c = getConstructor("http://localhost/mywiki/",
050: null);
051:
052: assertEquals("http://localhost/mywiki/wiki/Main", c.makeURL(
053: WikiContext.VIEW, "Main", true, null));
054: }
055:
056: public void testViewURL3() throws Exception {
057: URLConstructor c = getConstructor("http://localhost:8080/",
058: null);
059:
060: assertEquals("http://localhost:8080/wiki/Main", c.makeURL(
061: WikiContext.VIEW, "Main", true, null));
062: }
063:
064: public void testViewURL4() throws Exception {
065: URLConstructor c = getConstructor("http://localhost/mywiki/",
066: null);
067:
068: assertEquals("/mywiki/wiki/Main", c.makeURL(WikiContext.VIEW,
069: "Main", false, null));
070: }
071:
072: public void testViewURL5() throws Exception {
073: URLConstructor c = getConstructor("http://localhost/", "");
074:
075: assertEquals("http://localhost/Main", c.makeURL(
076: WikiContext.VIEW, "Main", true, null));
077: }
078:
079: public void testViewURL6() throws Exception {
080: URLConstructor c = getConstructor(
081: "http://localhost/mywiki/app1/", null);
082:
083: assertEquals("http://localhost/mywiki/app1/wiki/Main", c
084: .makeURL(WikiContext.VIEW, "Main", true, null));
085: }
086:
087: public void testViewURL7() throws Exception {
088: URLConstructor c = getConstructor(
089: "http://localhost/mywiki/app1/", "view/");
090:
091: assertEquals("http://localhost/mywiki/app1/view/Main", c
092: .makeURL(WikiContext.VIEW, "Main", true, null));
093: }
094:
095: public void testEditURL1() throws Exception {
096: URLConstructor c = getConstructor("http://localhost/mywiki/",
097: null);
098:
099: assertEquals("http://localhost/mywiki/wiki/Main?do=Edit", c
100: .makeURL(WikiContext.EDIT, "Main", true, null));
101: }
102:
103: public void testAttachURL1() throws Exception {
104: URLConstructor c = getConstructor("http://localhost/mywiki/",
105: null);
106:
107: assertEquals("http://localhost/mywiki/attach/Main/foo.txt",
108: c.makeURL(WikiContext.ATTACH, "Main/foo.txt", true,
109: null));
110: }
111:
112: public void testAttachURLRelative1() throws Exception {
113: URLConstructor c = getConstructor("http://localhost/mywiki/",
114: null);
115:
116: assertEquals("/mywiki/attach/Main/foo.txt", c.makeURL(
117: WikiContext.ATTACH, "Main/foo.txt", false, null));
118: }
119:
120: public void testOtherURL1() throws Exception {
121: URLConstructor c = getConstructor("http://localhost/mywiki/",
122: null);
123:
124: assertEquals("http://localhost/mywiki/foo.jsp", c.makeURL(
125: WikiContext.NONE, "foo.jsp", true, null));
126: }
127:
128: public void testOtherURL2() throws Exception {
129: URLConstructor c = getConstructor(
130: "http://localhost/mywiki/dobble/", null);
131:
132: assertEquals(
133: "http://localhost/mywiki/dobble/foo.jsp?a=1&b=2", c
134: .makeURL(WikiContext.NONE, "foo.jsp", true,
135: "a=1&b=2"));
136: }
137:
138: public static Test suite() {
139: return new TestSuite(ShortURLConstructorTest.class);
140: }
141: }
|