1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.page;
18
19 import java.security.Principal;
20 import java.util.HashSet;
21 import java.util.Set;
22
23 import javax.security.auth.Subject;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 import org.apache.jetspeed.om.folder.Folder;
30 import org.apache.jetspeed.page.psml.CastorXmlPageManager;
31 import org.apache.jetspeed.security.impl.RolePrincipalImpl;
32 import org.apache.jetspeed.security.impl.UserPrincipalImpl;
33
34 /***
35 * TestSecureCastorXmlPageManager
36 *
37 * @author <a href="rwatler@apache.org">Randy Watler</a>
38 * @version $Id$
39 */
40 public class TestCreateUserHomePagesFromRoles extends TestCase implements PageManagerTestShared
41 {
42 protected CastorXmlPageManager pageManager;
43
44
45
46
47
48
49 protected void setUp() throws Exception
50 {
51 super.setUp();
52 pageManager = Shared.makeCastorXMLPageManager("secure-pages", false, true);
53 }
54
55 /***
56 * <p>
57 * tearDown
58 * </p>
59 *
60 * @see junit.framework.TestCase#tearDown()
61 * @throws java.lang.Exception
62 */
63 protected void tearDown() throws Exception
64 {
65 super.tearDown();
66 }
67
68 /***
69 * Defines the testcase name for JUnit.
70 *
71 * @param name
72 * the testcase's name.
73 */
74 public TestCreateUserHomePagesFromRoles( String name )
75 {
76 super(name);
77 }
78
79 /***
80 * Start the tests.
81 *
82 * @param args
83 * the arguments. Not used
84 */
85 public static void main( String args[] )
86 {
87 junit.awtui.TestRunner.main(new String[]{TestCreateUserHomePagesFromRoles.class.getName()});
88 }
89
90 /***
91 * Creates the test suite.
92 *
93 * @return a test suite (<code>TestSuite</code>) that includes all
94 * methods starting with "test"
95 */
96 public static Test suite()
97 {
98
99 return new TestSuite(TestCreateUserHomePagesFromRoles.class);
100 }
101
102
103 static final String FOLDER1 = Folder.ROLE_FOLDER + "role1";
104 static final String FOLDER2 = Folder.ROLE_FOLDER + "role2";
105 static final String FOLDER3 = Folder.ROLE_FOLDER + "role3";
106
107 static final String DEFAULT_PAGE = Folder.USER_FOLDER + "david" + Folder.PATH_SEPARATOR + "default-page.psml";
108 static final String ROLE_PAGE_1 = Folder.USER_FOLDER + "david" + Folder.PATH_SEPARATOR + "role1-default-page.psml";
109 static final String ROLE_PAGE_2 = Folder.USER_FOLDER + "david" + Folder.PATH_SEPARATOR + "role2-default-page.psml";
110 static final String ROLE_PAGE_3 = Folder.USER_FOLDER + "david" + Folder.PATH_SEPARATOR + "role3-default-page.psml";
111 static final String SUB_PAGE = Folder.USER_FOLDER + "david" + Folder.PATH_SEPARATOR + "sub1" + Folder.PATH_SEPARATOR + "default-page.psml";
112 static final String SUB_LINK = Folder.USER_FOLDER + "david" + Folder.PATH_SEPARATOR + "sub1" + Folder.PATH_SEPARATOR + "apache_portals.link";
113
114 public void testCreateUserHomePagesFromRoles() throws Exception
115 {
116 PageManager pageManager = Shared.makeCastorXMLPageManager("pages", false, false);
117
118 assertTrue("folder1 failed to create", pageManager.folderExists(FOLDER1));
119 assertTrue("folder2 failed to create", pageManager.folderExists(FOLDER2));
120 assertTrue("folder3 failed to create", pageManager.folderExists(FOLDER3));
121
122 Set principals = new HashSet();
123
124
125 Principal rolePrincipal1 = new RolePrincipalImpl("role1");
126 Principal rolePrincipal2 = new RolePrincipalImpl("role2");
127 Principal rolePrincipal3 = new RolePrincipalImpl("role3");
128 principals.add(rolePrincipal1);
129 principals.add(rolePrincipal2);
130 principals.add(rolePrincipal3);
131
132
133 Principal userPrincipal = new UserPrincipalImpl("david");
134 principals.add(userPrincipal);
135
136
137 Subject subject = new Subject(true, principals, new HashSet(), new HashSet());
138
139 pageManager.createUserHomePagesFromRoles(subject);
140
141 assertTrue("failed to create default page", pageManager.pageExists(DEFAULT_PAGE));
142 assertTrue("failed to create sub page", pageManager.pageExists(SUB_PAGE));
143 assertTrue("failed to create sub link", pageManager.linkExists(SUB_LINK));
144 }
145
146 }