1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.tools.pamanager;
18
19 import java.io.FileReader;
20 import java.util.Collection;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25 import junit.textui.TestRunner;
26
27 import org.apache.jetspeed.om.common.JetspeedServiceReference;
28 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
29 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
30 import org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata;
31 import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor;
32
33
34 /***
35 * Tests jetspeed-portlet.xml XML-Java mappings
36 *
37 * @author <a href="mailto:jford@apache.com">Jeremy Ford</a>
38 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
39 * @version $Id: TestJetspeedPortletDescriptor.java 517121 2007-03-12 07:45:49Z ate $
40 */
41 public class TestJetspeedPortletDescriptor
42 extends TestCase {
43
44
45 private static final String PORTLET_01 = "HelloPortlet";
46 private static final String PORTLET_02 = "DisplayRequestPortlet";
47 private static final String PORTLET_03 = "PickANumberPortlet";
48 private static final String PORTLET_04 = "AttributeScopePortlet";
49
50 /***
51 * Start the tests.
52 *
53 * @param args the arguments. Not used
54 */
55 public static void main(String args[])
56 {
57 TestRunner.main(new String[] { TestPortletDescriptor.class.getName()});
58 }
59
60
61 /***
62 * Creates the test suite.
63 *
64 * @return a test suite (<code>TestSuite</code>) that includes all methods
65 * starting with "test"
66 */
67 public static Test suite()
68 {
69
70 return new TestSuite(TestJetspeedPortletDescriptor.class);
71 }
72
73 public void testLoadPortletApplicationTree() throws Exception
74 {
75 System.out.println("Testing loadPortletApplicationTree");
76 PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet.xml"), "unit-test");
77 MutablePortletApplication app = pad.createPortletApplication();
78 assertNotNull("App is null", app);
79 assertNotNull("Version is null", app.getVersion());
80 assertTrue("Version invalid: " + app.getVersion(), app.getVersion().equals("1.0"));
81 assertNotNull("PA Identifier is null", app.getApplicationIdentifier());
82 assertTrue(
83 "PA Identifier invalid: " + app.getApplicationIdentifier(),
84 app.getApplicationIdentifier().equals("TestRegistry"));
85
86 ExtendedPortletMetadata md = new ExtendedPortletMetadata(new FileReader("./test/testdata/deploy/jetspeed-portlet.xml"), app);
87 md.load();
88
89 PortletDefinitionComposite def1 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_01);
90 PortletDefinitionComposite def2 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_02);
91 PortletDefinitionComposite def3 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_03);
92 PortletDefinitionComposite def4 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_04);
93
94 Collection titles = app.getMetadata().getFields("title");
95 Collection def1Titles = def1.getMetadata().getFields("title");
96 Collection def2Subjects = def2.getMetadata().getFields("subject");
97 Collection def3Creators = def3.getMetadata().getFields("creator");
98 Collection def4Field1 = def4.getMetadata().getFields("field1");
99 Collection def4Fiels2 = def4.getMetadata().getFields("field2");
100
101 String securityRef = app.getJetspeedSecurityConstraint();
102 assertEquals(titles.size(), 3);
103 assertEquals(def1Titles.size(), 4);
104 assertEquals(def2Subjects.size(), 5);
105 assertEquals(def3Creators.size(), 4);
106 assertEquals(def4Field1.size(), 3);
107 assertEquals(def4Fiels2.size(), 2);
108
109
110 assertEquals(securityRef, "admin-only");
111 assertEquals(def1.getJetspeedSecurityConstraint(), "users-1");
112 assertEquals(def2.getJetspeedSecurityConstraint(), "users-2");
113 assertEquals(def3.getJetspeedSecurityConstraint(), "users-4");
114 assertNull(def4.getJetspeedSecurityConstraint());
115
116 Collection servicesCollection = app.getJetspeedServices();
117 assertNotNull("Metadata services is null", servicesCollection);
118 assertEquals("Expected 2 service definitions", servicesCollection.size(), 2);
119 Object[] services = servicesCollection.toArray();
120 JetspeedServiceReference service = (JetspeedServiceReference)services[0];
121 System.out.println("**** service = " + service.getName());
122
123 assertEquals( ((JetspeedServiceReference)services[0]).getName(), "PortletRegistryComponent");
124 assertEquals( ((JetspeedServiceReference)services[1]).getName(), "PortletEntityAccessComponent");
125 }
126
127 }