001: /*
002: JSPWiki - a JSP-based WikiWiki clone.
003:
004: Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
005:
006: This program is free software; you can redistribute it and/or modify
007: it under the terms of the GNU Lesser General Public License as published by
008: the Free Software Foundation; either version 2.1 of the License, or
009: (at your option) any later version.
010:
011: This program is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: GNU Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public License
017: along with this program; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: */
020: package com.ecyrd.jspwiki.auth.acl;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025:
026: import com.ecyrd.jspwiki.auth.acl.AclEntryImpl;
027: import com.ecyrd.jspwiki.auth.permissions.PagePermission;
028: import com.ecyrd.jspwiki.auth.permissions.PermissionFactory;
029:
030: public class AclEntryImplTest extends TestCase {
031: AclEntryImpl m_ae;
032:
033: public AclEntryImplTest(String s) {
034: super (s);
035: }
036:
037: public void setUp() {
038: m_ae = new AclEntryImpl();
039: }
040:
041: public void tearDown() {
042: }
043:
044: public void testAddPermission() {
045: m_ae.addPermission(PagePermission.VIEW);
046:
047: assertTrue("no permission", m_ae
048: .checkPermission(PagePermission.VIEW));
049: assertFalse("permission found", m_ae
050: .checkPermission(PagePermission.EDIT));
051: }
052:
053: public void testAddPermission2() {
054: m_ae.addPermission(PagePermission.VIEW);
055: m_ae.addPermission(PagePermission.EDIT);
056:
057: assertTrue("no editpermission", m_ae
058: .checkPermission(PagePermission.EDIT));
059: assertTrue("no viewpermission", m_ae
060: .checkPermission(PagePermission.VIEW));
061: }
062:
063: public void testAddPermission3() {
064: m_ae.addPermission(PagePermission.COMMENT);
065:
066: assertFalse("has edit permission", m_ae
067: .checkPermission(PagePermission.EDIT));
068: }
069:
070: public void testAddPermission4() {
071: m_ae.addPermission(PagePermission.EDIT);
072:
073: assertTrue("has comment permission", m_ae
074: .checkPermission(PagePermission.COMMENT));
075: }
076:
077: public void testAddPermission5() {
078: m_ae.addPermission(PagePermission.VIEW);
079:
080: assertTrue("has view all", m_ae
081: .checkPermission(PagePermission.VIEW));
082: assertTrue("has view on single page", m_ae
083: .checkPermission(PermissionFactory.getPagePermission(
084: "mywiki:SamplePage", "view")));
085: }
086:
087: public void testRemovePermission() {
088: m_ae.addPermission(PagePermission.VIEW);
089: m_ae.addPermission(PagePermission.EDIT);
090:
091: assertTrue("has edit permission", m_ae
092: .checkPermission(PagePermission.EDIT));
093: assertTrue("has view permission", m_ae
094: .checkPermission(PagePermission.VIEW));
095:
096: m_ae.removePermission(PagePermission.EDIT);
097:
098: assertFalse("no edit permission", m_ae
099: .checkPermission(PagePermission.EDIT));
100: assertTrue("has view permission", m_ae
101: .checkPermission(PagePermission.VIEW));
102: }
103:
104: public void testDefaults() {
105: assertFalse("elements", m_ae.permissions().hasMoreElements());
106: assertNull("principal", m_ae.getPrincipal());
107: }
108:
109: public static Test suite() {
110: return new TestSuite(AclEntryImplTest.class);
111: }
112: }
|