001: /*
002: * (C) Janne Jalkanen 2005
003: *
004: */
005: package com.ecyrd.jspwiki.ui;
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.auth.permissions.WikiPermission;
015:
016: public class WikiCommandTest extends TestCase {
017: TestEngine testEngine;
018: String wiki;
019:
020: protected void setUp() throws Exception {
021: Properties props = new Properties();
022: props.load(TestEngine.findTestProperties());
023: testEngine = new TestEngine(props);
024: wiki = testEngine.getApplicationName();
025: }
026:
027: protected void tearDown() throws Exception {
028: }
029:
030: public void testStaticCommand() {
031: Command a = WikiCommand.CREATE_GROUP;
032: assertEquals("createGroup", a.getRequestContext());
033: assertEquals("NewGroup.jsp", a.getJSP());
034: assertEquals("%uNewGroup.jsp", a.getURLPattern());
035: assertEquals("NewGroupContent.jsp", a.getContentTemplate());
036: assertNull(a.getTarget());
037: assertNull(a.requiredPermission());
038: assertEquals(a, WikiCommand.CREATE_GROUP);
039:
040: a = WikiCommand.ERROR;
041: assertEquals("error", a.getRequestContext());
042: assertEquals("Error.jsp", a.getJSP());
043: assertEquals("%uError.jsp", a.getURLPattern());
044: assertEquals("DisplayMessage.jsp", a.getContentTemplate());
045: assertNull(a.getTarget());
046: assertNull(a.requiredPermission());
047: assertEquals(a, WikiCommand.ERROR);
048:
049: a = WikiCommand.FIND;
050: assertEquals("find", a.getRequestContext());
051: assertEquals("Search.jsp", a.getJSP());
052: assertEquals("%uSearch.jsp", a.getURLPattern());
053: assertEquals("FindContent.jsp", a.getContentTemplate());
054: assertNull(a.getTarget());
055: assertNull(a.requiredPermission());
056: assertEquals(a, WikiCommand.FIND);
057:
058: a = WikiCommand.INSTALL;
059: assertEquals("install", a.getRequestContext());
060: assertEquals("Install.jsp", a.getJSP());
061: assertEquals("%uInstall.jsp", a.getURLPattern());
062: assertNull(a.getContentTemplate());
063: assertNull(a.getTarget());
064: assertNull(a.requiredPermission());
065: assertEquals(a, WikiCommand.INSTALL);
066:
067: a = WikiCommand.LOGIN;
068: assertEquals("login", a.getRequestContext());
069: assertEquals("Login.jsp", a.getJSP());
070: assertEquals("%uLogin.jsp?redirect=%n", a.getURLPattern());
071: assertEquals("LoginContent.jsp", a.getContentTemplate());
072: assertNull(a.getTarget());
073: assertNull(a.requiredPermission());
074: assertEquals(a, WikiCommand.LOGIN);
075:
076: a = WikiCommand.LOGOUT;
077: assertEquals("logout", a.getRequestContext());
078: assertEquals("Logout.jsp", a.getJSP());
079: assertEquals("%uLogout.jsp", a.getURLPattern());
080: assertNull(a.getContentTemplate());
081: assertNull(a.getTarget());
082: assertNull(a.requiredPermission());
083: assertEquals(a, WikiCommand.LOGOUT);
084:
085: a = WikiCommand.PREFS;
086: assertEquals("prefs", a.getRequestContext());
087: assertEquals("UserPreferences.jsp", a.getJSP());
088: assertEquals("%uUserPreferences.jsp", a.getURLPattern());
089: assertEquals("PreferencesContent.jsp", a.getContentTemplate());
090: assertNull(a.getTarget());
091: assertNull(a.requiredPermission());
092: assertEquals(a, WikiCommand.PREFS);
093: }
094:
095: public void testTargetedCommand() {
096: // Get view command
097: Command a = WikiCommand.CREATE_GROUP;
098:
099: // Combine with wiki; make sure it's not equal to old command
100: Command b = a.targetedCommand(wiki);
101: assertNotSame(a, b);
102: assertEquals(a.getRequestContext(), b.getRequestContext());
103: assertEquals(a.getJSP(), b.getJSP());
104: assertEquals(a.getURLPattern(), b.getURLPattern());
105: assertEquals(a.getContentTemplate(), b.getContentTemplate());
106: assertNotNull(b.getTarget());
107: assertNotNull(b.requiredPermission());
108: assertEquals(new WikiPermission(wiki, "createGroups"), b
109: .requiredPermission());
110: assertEquals(wiki, b.getTarget());
111:
112: // Do the same with other commands
113:
114: a = WikiCommand.ERROR;
115: b = a.targetedCommand(wiki);
116: assertNotSame(a, b);
117: assertNotNull(b.getTarget());
118: assertNull(b.requiredPermission());
119: assertEquals(wiki, b.getTarget());
120:
121: a = WikiCommand.FIND;
122: b = a.targetedCommand(wiki);
123: assertNotSame(a, b);
124: assertNotNull(b.getTarget());
125: assertNull(b.requiredPermission());
126: assertEquals(wiki, b.getTarget());
127:
128: a = WikiCommand.INSTALL;
129: b = a.targetedCommand(wiki);
130: assertNotSame(a, b);
131: assertNotNull(b.getTarget());
132: assertNull(b.requiredPermission());
133: assertEquals(wiki, b.getTarget());
134:
135: a = WikiCommand.LOGIN;
136: b = a.targetedCommand(wiki);
137: assertNotSame(a, b);
138: assertNotNull(b.getTarget());
139: assertNotNull(b.requiredPermission());
140: assertEquals(new WikiPermission(wiki, "login"), b
141: .requiredPermission());
142: assertEquals(wiki, b.getTarget());
143:
144: a = WikiCommand.LOGOUT;
145: b = a.targetedCommand(wiki);
146: assertNotSame(a, b);
147: assertNotNull(b.getTarget());
148: assertNotNull(b.requiredPermission());
149: assertEquals(new WikiPermission(wiki, "login"), b
150: .requiredPermission());
151: assertEquals(wiki, b.getTarget());
152:
153: a = WikiCommand.PREFS;
154: b = a.targetedCommand(wiki);
155: assertNotSame(a, b);
156: assertNotNull(b.getTarget());
157: assertNotNull(b.requiredPermission());
158: assertEquals(new WikiPermission(wiki, "editProfile"), b
159: .requiredPermission());
160: assertEquals(wiki, b.getTarget());
161: }
162:
163: public static Test suite() {
164: return new TestSuite(WikiCommandTest.class);
165: }
166: }
|