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.GroupPrincipal;
015: import com.ecyrd.jspwiki.auth.permissions.GroupPermission;
016:
017: public class GroupCommandTest extends TestCase {
018: protected void setUp() throws Exception {
019: Properties props = new Properties();
020: props.load(TestEngine.findTestProperties());
021: new TestEngine(props);
022: }
023:
024: protected void tearDown() throws Exception {
025: }
026:
027: public void testStaticCommand() {
028: Command a;
029:
030: a = GroupCommand.VIEW_GROUP;
031: assertEquals("viewGroup", a.getRequestContext());
032: assertEquals("Group.jsp", a.getJSP());
033: assertEquals("%uGroup.jsp?group=%n", a.getURLPattern());
034: assertEquals("GroupContent.jsp", a.getContentTemplate());
035: assertNull(a.getTarget());
036: assertNull(a.requiredPermission());
037: assertEquals(a, GroupCommand.VIEW_GROUP);
038:
039: a = GroupCommand.EDIT_GROUP;
040: assertEquals("editGroup", a.getRequestContext());
041: assertEquals("EditGroup.jsp", a.getJSP());
042: assertEquals("%uEditGroup.jsp?group=%n", a.getURLPattern());
043: assertEquals("EditGroupContent.jsp", a.getContentTemplate());
044: assertNull(a.getTarget());
045: assertNull(a.requiredPermission());
046: assertEquals(a, GroupCommand.EDIT_GROUP);
047:
048: a = GroupCommand.DELETE_GROUP;
049: assertEquals("deleteGroup", a.getRequestContext());
050: assertEquals("DeleteGroup.jsp", a.getJSP());
051: assertEquals("%uDeleteGroup.jsp?group=%n", a.getURLPattern());
052: assertNull(null);
053: assertNull(a.getTarget());
054: assertNull(a.requiredPermission());
055: assertEquals(a, GroupCommand.DELETE_GROUP);
056: }
057:
058: public void testTargetedCommand() {
059: // Get view command
060: Command a = GroupCommand.VIEW_GROUP;
061: GroupPrincipal group = new GroupPrincipal("Test");
062:
063: // Combine with wiki group; make sure it's not equal to old command
064: Command b = a.targetedCommand(group);
065: assertNotSame(a, b);
066: assertEquals(a.getRequestContext(), b.getRequestContext());
067: assertEquals(a.getJSP(), b.getJSP());
068: assertEquals(a.getURLPattern(), b.getURLPattern());
069: assertEquals(a.getContentTemplate(), b.getContentTemplate());
070: assertNotNull(b.getTarget());
071: assertNotNull(b.requiredPermission());
072: assertEquals(new GroupPermission("*:Test", "view"), b
073: .requiredPermission());
074: assertEquals(group, b.getTarget());
075:
076: // Do the same with edit command
077: a = GroupCommand.EDIT_GROUP;
078: b = a.targetedCommand(group);
079: assertNotSame(a, b);
080: assertNotNull(b.getTarget());
081: assertNotNull(b.requiredPermission());
082: assertEquals(new GroupPermission("*:Test", "edit"), b
083: .requiredPermission());
084: assertEquals(group, b.getTarget());
085:
086: // Do the same with delete command
087: a = GroupCommand.DELETE_GROUP;
088: b = a.targetedCommand(group);
089: assertNotSame(a, b);
090: assertNotNull(b.getTarget());
091: assertNotNull(b.requiredPermission());
092: assertEquals(new GroupPermission("*:Test", "delete"), b
093: .requiredPermission());
094: assertEquals(group, b.getTarget());
095: }
096:
097: public static Test suite() {
098: return new TestSuite(GroupCommandTest.class);
099: }
100: }
|