Source Code Cross Referenced for TestPortletDescriptorSecurityRoles.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » tools » pamanager » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » jetspeed 2.1.3 » org.apache.jetspeed.tools.pamanager 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.tools.pamanager;
018:
019:        import java.io.File;
020:
021:        import junit.framework.Test;
022:        import junit.framework.TestSuite;
023:        import junit.textui.TestRunner;
024:
025:        import org.apache.jetspeed.AbstractRequestContextTestCase;
026:        import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
027:        import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
028:        import org.apache.jetspeed.om.servlet.impl.SecurityRoleImpl;
029:        import org.apache.jetspeed.util.DirectoryHelper;
030:        import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
031:        import org.apache.pluto.om.common.SecurityRole;
032:        import org.apache.pluto.om.common.SecurityRoleRef;
033:        import org.apache.pluto.om.common.SecurityRoleRefSet;
034:        import org.apache.pluto.om.common.SecurityRoleSet;
035:        import org.apache.pluto.om.portlet.PortletDefinition;
036:
037:        /**
038:         * TestPortletDescriptorSecurityRoles - test and validate security roles and
039:         * security role references from portlet.xml and web.xml deployment descriptor.
040:         *
041:         * @author <a href="ate@douma.nu">Ate Douma </a>
042:         *
043:         * @version $Id: TestPortletDescriptorSecurityRoles.java,v 1.4 2004/05/27
044:         *                19:57:24 weaver Exp $
045:         */
046:        public class TestPortletDescriptorSecurityRoles extends
047:                AbstractRequestContextTestCase {
048:
049:            /**
050:             * Start the tests.
051:             *
052:             * @param args
053:             *                  the arguments. Not used
054:             */
055:            public static void main(String args[]) {
056:                TestRunner
057:                        .main(new String[] { TestPortletDescriptorSecurityRoles.class
058:                                .getName() });
059:            }
060:
061:            /**
062:             * Creates the test suite.
063:             *
064:             * @return a test suite (<code>TestSuite</code>) that includes all
065:             *              methods starting with "test"
066:             */
067:            public static Test suite() {
068:                // All methods starting with "test" will be executed in the test suite.
069:                return new TestSuite(TestPortletDescriptorSecurityRoles.class);
070:            }
071:
072:            public void setUp() throws Exception {
073:                super .setUp();
074:
075:            }
076:
077:            public void testSecurityRoles() throws Exception {
078:                System.out.println("Testing securityRoles");
079:                File warFile = new File("./test/testdata/deploy/webapp");
080:                PortletApplicationWar paWar = new PortletApplicationWar(
081:                        new DirectoryHelper(warFile), "unit-test", "/");
082:
083:                MutablePortletApplication app = paWar.createPortletApp();
084:                assertNotNull("App is null", app);
085:
086:                MutableWebApplication webApp = paWar.createWebApp();
087:                assertNotNull("WebApp is null", webApp);
088:
089:                app.setWebApplicationDefinition(webApp);
090:
091:                PortletDefinition portlet = app
092:                        .getPortletDefinitionByName("TestPortlet");
093:                assertNotNull("TestPortlet is null", portlet);
094:                checkWebSecurityRoles(webApp);
095:                checkPortletSecurityRoleRefs(portlet);
096:                boolean validateFailed = false;
097:                try {
098:                    paWar.validate();
099:                } catch (PortletApplicationException e) {
100:                    validateFailed = true;
101:                }
102:                assertTrue("Invalid PortletDescriptor validation result",
103:                        validateFailed);
104:                SecurityRoleImpl role = new SecurityRoleImpl();
105:                role.setRoleName("users.manager");
106:                webApp.addSecurityRole(role);
107:                try {
108:                    paWar.validate();
109:                    validateFailed = false;
110:                } catch (PortletApplicationException e) {
111:                }
112:                assertEquals("Invalid PortletDescriptor validation result",
113:                        false, validateFailed);
114:
115:                // persist the app
116:                try {
117:
118:                    portletRegistry.registerPortletApplication(app);
119:
120:                } catch (Exception e) {
121:                    String msg = "Unable to register portlet application, "
122:                            + app.getName()
123:                            + ", through the portlet registry: " + e.toString();
124:
125:                    throw new Exception(msg, e);
126:                }
127:                // clear cache
128:
129:                // read back in
130:                app = portletRegistry.getPortletApplication("unit-test");
131:                validateFailed = true;
132:                try {
133:                    paWar.validate();
134:                    validateFailed = false;
135:                } catch (PortletApplicationException e) {
136:                }
137:                assertEquals(
138:                        "Invalid loaded PortletDescriptor validation result",
139:                        false, validateFailed);
140:
141:                // remove the app
142:                try {
143:
144:                    portletRegistry.removeApplication(app);
145:
146:                } catch (Exception e) {
147:                    String msg = "Unable to remove portlet application, "
148:                            + app.getName()
149:                            + ", through the portlet portletRegistry: "
150:                            + e.toString();
151:                    throw new Exception(msg, e);
152:                }
153:
154:            }
155:
156:            private void checkWebSecurityRoles(MutableWebApplication webApp) {
157:                SecurityRoleSet roles = webApp.getSecurityRoles();
158:                assertEquals(
159:                        "Invalid number of security role definitions found", 1,
160:                        roles.size());
161:                SecurityRole role = roles.get("users.admin");
162:                assertNotNull("Role users.admin undefined", role);
163:            }
164:
165:            private void checkPortletSecurityRoleRefs(PortletDefinition portlet) {
166:                SecurityRoleRefSet roleRefs = portlet
167:                        .getInitSecurityRoleRefSet();
168:                assertEquals(
169:                        "Invalid number of security role references found", 2,
170:                        roleRefs.size());
171:                SecurityRoleRef roleRef = roleRefs.get("admin");
172:                assertNotNull("Security Role Ref admin undefined", roleRef);
173:                assertEquals("security Role link expected", "users.admin",
174:                        roleRef.getRoleLink());
175:                roleRef = roleRefs.get("users.manager");
176:                assertNotNull("Security Role Ref users.manager undefined",
177:                        roleRef);
178:                assertNull(
179:                        "Undefined security Role link for users.managers expected",
180:                        roleRef.getRoleLink());
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.