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.WikiPage;
015: import com.ecyrd.jspwiki.auth.permissions.PermissionFactory;
016:
017: public class PageCommandTest extends TestCase {
018: TestEngine testEngine;
019:
020: WikiPage testPage;
021:
022: protected void setUp() throws Exception {
023: Properties props = new Properties();
024: props.load(TestEngine.findTestProperties());
025: testEngine = new TestEngine(props);
026: testEngine.saveText("TestPage", "This is a test.");
027: testPage = testEngine.getPage("TestPage");
028: }
029:
030: protected void tearDown() throws Exception {
031: testEngine.deletePage("TestPage");
032: }
033:
034: public void testStaticCommand() {
035: Command a = PageCommand.VIEW;
036: assertEquals("view", a.getRequestContext());
037: assertEquals("Wiki.jsp", a.getJSP());
038: assertEquals("%uWiki.jsp?page=%n", a.getURLPattern());
039: assertEquals("PageContent.jsp", a.getContentTemplate());
040: assertNull(a.getTarget());
041: assertNull(a.requiredPermission());
042: assertEquals(a, PageCommand.VIEW);
043:
044: a = PageCommand.EDIT;
045: assertEquals("edit", a.getRequestContext());
046: assertEquals("Edit.jsp", a.getJSP());
047: assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
048: assertEquals("EditContent.jsp", a.getContentTemplate());
049: assertNull(a.getTarget());
050: assertNull(a.requiredPermission());
051: assertEquals(a, PageCommand.EDIT);
052:
053: a = PageCommand.PREVIEW;
054: assertEquals("preview", a.getRequestContext());
055: assertEquals("Preview.jsp", a.getJSP());
056: assertEquals("%uPreview.jsp?page=%n", a.getURLPattern());
057: assertEquals("PreviewContent.jsp", a.getContentTemplate());
058: assertNull(a.getTarget());
059: assertNull(a.requiredPermission());
060: assertEquals(a, PageCommand.PREVIEW);
061: }
062:
063: public void testTargetedCommand() {
064: // Get view command
065: Command a = PageCommand.VIEW;
066:
067: // Combine with wiki page; make sure it's not equal to old command
068: Command b = a.targetedCommand(testPage);
069: assertNotSame(a, b);
070: assertEquals(a.getRequestContext(), b.getRequestContext());
071: assertEquals(a.getJSP(), b.getJSP());
072: assertEquals(a.getURLPattern(), b.getURLPattern());
073: assertEquals(a.getContentTemplate(), b.getContentTemplate());
074: assertNotNull(b.getTarget());
075: assertNotNull(b.requiredPermission());
076: assertEquals(PermissionFactory.getPagePermission(testPage,
077: "view"), b.requiredPermission());
078: assertEquals(testPage, b.getTarget());
079:
080: // Do the same with edit command
081: a = PageCommand.EDIT;
082: b = a.targetedCommand(testPage);
083: assertNotSame(a, b);
084: assertNotNull(b.getTarget());
085: assertNotNull(b.requiredPermission());
086: assertEquals(PermissionFactory.getPagePermission(testPage,
087: "edit"), b.requiredPermission());
088: assertEquals(testPage, b.getTarget());
089:
090: // Do the same with delete command
091: a = PageCommand.DELETE;
092: b = a.targetedCommand(testPage);
093: assertNotSame(a, b);
094: assertNotNull(b.getTarget());
095: assertNotNull(b.requiredPermission());
096: assertEquals(PermissionFactory.getPagePermission(testPage,
097: "delete"), b.requiredPermission());
098: assertEquals(testPage, b.getTarget());
099:
100: // Do the same with info command
101: a = PageCommand.INFO;
102: b = a.targetedCommand(testPage);
103: assertNotSame(a, b);
104: assertNotNull(b.getTarget());
105: assertNotNull(b.requiredPermission());
106: assertEquals(PermissionFactory.getPagePermission(testPage,
107: "view"), b.requiredPermission());
108: assertEquals(testPage, b.getTarget());
109: }
110:
111: public static Test suite() {
112: return new TestSuite(PageCommandTest.class);
113: }
114: }
|