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.FileReader;
020: import java.util.Collection;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025: import junit.textui.TestRunner;
026:
027: import org.apache.jetspeed.om.common.JetspeedServiceReference;
028: import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
029: import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
030: import org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata;
031: import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor;
032:
033: /**
034: * Tests jetspeed-portlet.xml XML-Java mappings
035: *
036: * @author <a href="mailto:jford@apache.com">Jeremy Ford</a>
037: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
038: * @version $Id: TestJetspeedPortletDescriptor.java 517121 2007-03-12 07:45:49Z ate $
039: */
040: public class TestJetspeedPortletDescriptor extends TestCase {
041: //extends AbstractPrefsSupportedTestCase {
042:
043: private static final String PORTLET_01 = "HelloPortlet";
044: private static final String PORTLET_02 = "DisplayRequestPortlet";
045: private static final String PORTLET_03 = "PickANumberPortlet";
046: private static final String PORTLET_04 = "AttributeScopePortlet";
047:
048: /**
049: * Start the tests.
050: *
051: * @param args the arguments. Not used
052: */
053: public static void main(String args[]) {
054: TestRunner.main(new String[] { TestPortletDescriptor.class
055: .getName() });
056: }
057:
058: /**
059: * Creates the test suite.
060: *
061: * @return a test suite (<code>TestSuite</code>) that includes all methods
062: * starting with "test"
063: */
064: public static Test suite() {
065: // All methods starting with "test" will be executed in the test suite.
066: return new TestSuite(TestJetspeedPortletDescriptor.class);
067: }
068:
069: public void testLoadPortletApplicationTree() throws Exception {
070: System.out.println("Testing loadPortletApplicationTree");
071: PortletApplicationDescriptor pad = new PortletApplicationDescriptor(
072: new FileReader("./test/testdata/deploy/portlet.xml"),
073: "unit-test");
074: MutablePortletApplication app = pad.createPortletApplication();
075: assertNotNull("App is null", app);
076: assertNotNull("Version is null", app.getVersion());
077: assertTrue("Version invalid: " + app.getVersion(), app
078: .getVersion().equals("1.0"));
079: assertNotNull("PA Identifier is null", app
080: .getApplicationIdentifier());
081: assertTrue("PA Identifier invalid: "
082: + app.getApplicationIdentifier(), app
083: .getApplicationIdentifier().equals("TestRegistry"));
084:
085: ExtendedPortletMetadata md = new ExtendedPortletMetadata(
086: new FileReader(
087: "./test/testdata/deploy/jetspeed-portlet.xml"),
088: app);
089: md.load();
090:
091: PortletDefinitionComposite def1 = (PortletDefinitionComposite) app
092: .getPortletDefinitionByName(PORTLET_01);
093: PortletDefinitionComposite def2 = (PortletDefinitionComposite) app
094: .getPortletDefinitionByName(PORTLET_02);
095: PortletDefinitionComposite def3 = (PortletDefinitionComposite) app
096: .getPortletDefinitionByName(PORTLET_03);
097: PortletDefinitionComposite def4 = (PortletDefinitionComposite) app
098: .getPortletDefinitionByName(PORTLET_04);
099:
100: Collection titles = app.getMetadata().getFields("title");
101: Collection def1Titles = def1.getMetadata().getFields("title");
102: Collection def2Subjects = def2.getMetadata().getFields(
103: "subject");
104: Collection def3Creators = def3.getMetadata().getFields(
105: "creator");
106: Collection def4Field1 = def4.getMetadata().getFields("field1");
107: Collection def4Fiels2 = def4.getMetadata().getFields("field2");
108:
109: String securityRef = app.getJetspeedSecurityConstraint();
110: assertEquals(titles.size(), 3);
111: assertEquals(def1Titles.size(), 4);
112: assertEquals(def2Subjects.size(), 5);
113: assertEquals(def3Creators.size(), 4);
114: assertEquals(def4Field1.size(), 3);
115: assertEquals(def4Fiels2.size(), 2);
116:
117: // Security Constraints tests
118: assertEquals(securityRef, "admin-only");
119: assertEquals(def1.getJetspeedSecurityConstraint(), "users-1");
120: assertEquals(def2.getJetspeedSecurityConstraint(), "users-2");
121: assertEquals(def3.getJetspeedSecurityConstraint(), "users-4");
122: assertNull(def4.getJetspeedSecurityConstraint());
123:
124: Collection servicesCollection = app.getJetspeedServices();
125: assertNotNull("Metadata services is null", servicesCollection);
126: assertEquals("Expected 2 service definitions",
127: servicesCollection.size(), 2);
128: Object[] services = servicesCollection.toArray();
129: JetspeedServiceReference service = (JetspeedServiceReference) services[0];
130: System.out.println("**** service = " + service.getName());
131:
132: assertEquals(
133: ((JetspeedServiceReference) services[0]).getName(),
134: "PortletRegistryComponent");
135: assertEquals(
136: ((JetspeedServiceReference) services[1]).getName(),
137: "PortletEntityAccessComponent");
138: }
139:
140: }
|