001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.page;
018:
019: import java.security.Principal;
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import javax.security.auth.Subject;
024:
025: import junit.framework.Test;
026: import junit.framework.TestCase;
027: import junit.framework.TestSuite;
028:
029: import org.apache.jetspeed.om.folder.Folder;
030: import org.apache.jetspeed.page.psml.CastorXmlPageManager;
031: import org.apache.jetspeed.security.impl.RolePrincipalImpl;
032: import org.apache.jetspeed.security.impl.UserPrincipalImpl;
033:
034: /**
035: * TestSecureCastorXmlPageManager
036: *
037: * @author <a href="rwatler@apache.org">Randy Watler</a>
038: * @version $Id$
039: */
040: public class TestCreateUserHomePagesFromRoles extends TestCase
041: implements PageManagerTestShared {
042: protected CastorXmlPageManager pageManager;
043:
044: /*
045: * (non-Javadoc)
046: *
047: * @see junit.framework.TestCase#setUp()
048: */
049: protected void setUp() throws Exception {
050: super .setUp();
051: pageManager = Shared.makeCastorXMLPageManager("secure-pages",
052: false, true);
053: }
054:
055: /**
056: * <p>
057: * tearDown
058: * </p>
059: *
060: * @see junit.framework.TestCase#tearDown()
061: * @throws java.lang.Exception
062: */
063: protected void tearDown() throws Exception {
064: super .tearDown();
065: }
066:
067: /**
068: * Defines the testcase name for JUnit.
069: *
070: * @param name
071: * the testcase's name.
072: */
073: public TestCreateUserHomePagesFromRoles(String name) {
074: super (name);
075: }
076:
077: /**
078: * Start the tests.
079: *
080: * @param args
081: * the arguments. Not used
082: */
083: public static void main(String args[]) {
084: junit.awtui.TestRunner
085: .main(new String[] { TestCreateUserHomePagesFromRoles.class
086: .getName() });
087: }
088:
089: /**
090: * Creates the test suite.
091: *
092: * @return a test suite (<code>TestSuite</code>) that includes all
093: * methods starting with "test"
094: */
095: public static Test suite() {
096: // All methods starting with "test" will be executed in the test suite.
097: return new TestSuite(TestCreateUserHomePagesFromRoles.class);
098: }
099:
100: static final String FOLDER1 = Folder.ROLE_FOLDER + "role1";
101: static final String FOLDER2 = Folder.ROLE_FOLDER + "role2";
102: static final String FOLDER3 = Folder.ROLE_FOLDER + "role3";
103:
104: static final String DEFAULT_PAGE = Folder.USER_FOLDER + "david"
105: + Folder.PATH_SEPARATOR + "default-page.psml";
106: static final String ROLE_PAGE_1 = Folder.USER_FOLDER + "david"
107: + Folder.PATH_SEPARATOR + "role1-default-page.psml";
108: static final String ROLE_PAGE_2 = Folder.USER_FOLDER + "david"
109: + Folder.PATH_SEPARATOR + "role2-default-page.psml";
110: static final String ROLE_PAGE_3 = Folder.USER_FOLDER + "david"
111: + Folder.PATH_SEPARATOR + "role3-default-page.psml";
112: static final String SUB_PAGE = Folder.USER_FOLDER + "david"
113: + Folder.PATH_SEPARATOR + "sub1" + Folder.PATH_SEPARATOR
114: + "default-page.psml";
115: static final String SUB_LINK = Folder.USER_FOLDER + "david"
116: + Folder.PATH_SEPARATOR + "sub1" + Folder.PATH_SEPARATOR
117: + "apache_portals.link";
118:
119: public void testCreateUserHomePagesFromRoles() throws Exception {
120: PageManager pageManager = Shared.makeCastorXMLPageManager(
121: "pages", false, false);
122:
123: assertTrue("folder1 failed to create", pageManager
124: .folderExists(FOLDER1));
125: assertTrue("folder2 failed to create", pageManager
126: .folderExists(FOLDER2));
127: assertTrue("folder3 failed to create", pageManager
128: .folderExists(FOLDER3));
129:
130: Set principals = new HashSet();
131:
132: // create the role principals
133: Principal rolePrincipal1 = new RolePrincipalImpl("role1");
134: Principal rolePrincipal2 = new RolePrincipalImpl("role2");
135: Principal rolePrincipal3 = new RolePrincipalImpl("role3");
136: principals.add(rolePrincipal1);
137: principals.add(rolePrincipal2);
138: principals.add(rolePrincipal3);
139:
140: // create the user principal
141: Principal userPrincipal = new UserPrincipalImpl("david");
142: principals.add(userPrincipal);
143:
144: // create the subject
145: Subject subject = new Subject(true, principals, new HashSet(),
146: new HashSet());
147:
148: pageManager.createUserHomePagesFromRoles(subject);
149:
150: assertTrue("failed to create default page", pageManager
151: .pageExists(DEFAULT_PAGE));
152: assertTrue("failed to create sub page", pageManager
153: .pageExists(SUB_PAGE));
154: assertTrue("failed to create sub link", pageManager
155: .linkExists(SUB_LINK));
156: }
157:
158: }
|