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 ShortViewURLConstructorTest 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(ShortViewURLConstructor.PROP_PREFIX,
032: prefix);
033:
034: testEngine = new TestEngine(props);
035: URLConstructor constr = new ShortViewURLConstructor();
036:
037: constr.initialize(testEngine, props);
038:
039: return constr;
040: }
041:
042: public void testViewURL1() throws Exception {
043: URLConstructor c = getConstructor("http://localhost/", "wiki/");
044:
045: assertEquals("http://localhost/wiki/Main", c.makeURL(
046: WikiContext.VIEW, "Main", true, null));
047: }
048:
049: public void testViewURL2() throws Exception {
050: URLConstructor c = getConstructor("http://localhost/mywiki/",
051: null);
052:
053: assertEquals("http://localhost/mywiki/wiki/Main", c.makeURL(
054: WikiContext.VIEW, "Main", true, null));
055: }
056:
057: public void testViewURL3() throws Exception {
058: URLConstructor c = getConstructor("http://localhost:8080/",
059: null);
060:
061: assertEquals("http://localhost:8080/wiki/Main", c.makeURL(
062: WikiContext.VIEW, "Main", true, null));
063: }
064:
065: public void testViewURL4() throws Exception {
066: URLConstructor c = getConstructor("http://localhost/mywiki/",
067: null);
068:
069: assertEquals("/mywiki/wiki/Main", c.makeURL(WikiContext.VIEW,
070: "Main", false, null));
071: }
072:
073: public void testViewURL5() throws Exception {
074: URLConstructor c = getConstructor("http://localhost/", "");
075:
076: assertEquals("http://localhost/Main", c.makeURL(
077: WikiContext.VIEW, "Main", true, null));
078: }
079:
080: public void testViewURL6() throws Exception {
081: URLConstructor c = getConstructor(
082: "http://localhost/mywiki/app1/", null);
083:
084: assertEquals("http://localhost/mywiki/app1/wiki/Main", c
085: .makeURL(WikiContext.VIEW, "Main", true, null));
086: }
087:
088: public void testViewURL7() throws Exception {
089: URLConstructor c = getConstructor(
090: "http://localhost/mywiki/app1/", "view/");
091:
092: assertEquals("http://localhost/mywiki/app1/view/Main", c
093: .makeURL(WikiContext.VIEW, "Main", true, null));
094: }
095:
096: public void testEditURL1() throws Exception {
097: URLConstructor c = getConstructor("http://localhost/mywiki/",
098: null);
099:
100: assertEquals("http://localhost/mywiki/Edit.jsp?page=Main", c
101: .makeURL(WikiContext.EDIT, "Main", true, null));
102: }
103:
104: public void testAttachURL1() throws Exception {
105: URLConstructor c = getConstructor("http://localhost/mywiki/",
106: null);
107:
108: assertEquals("http://localhost/mywiki/attach/Main/foo.txt",
109: c.makeURL(WikiContext.ATTACH, "Main/foo.txt", true,
110: null));
111: }
112:
113: public void testAttachURLRelative1() throws Exception {
114: URLConstructor c = getConstructor("http://localhost/mywiki/",
115: null);
116:
117: assertEquals("/mywiki/attach/Main/foo.txt", c.makeURL(
118: WikiContext.ATTACH, "Main/foo.txt", false, null));
119: }
120:
121: public void testOtherURL1() throws Exception {
122: URLConstructor c = getConstructor("http://localhost/mywiki/",
123: null);
124:
125: assertEquals("http://localhost/mywiki/foo.jsp", c.makeURL(
126: WikiContext.NONE, "foo.jsp", true, null));
127: }
128:
129: public void testOtherURL2() throws Exception {
130: URLConstructor c = getConstructor(
131: "http://localhost/mywiki/dobble/", null);
132:
133: assertEquals(
134: "http://localhost/mywiki/dobble/foo.jsp?a=1&b=2", c
135: .makeURL(WikiContext.NONE, "foo.jsp", true,
136: "a=1&b=2"));
137: }
138:
139: public static Test suite() {
140: return new TestSuite(ShortViewURLConstructorTest.class);
141: }
142: }
|