Return-Path: Delivered-To: apmail-portals-jetspeed-dev-archive@www.apache.org Received: (qmail 66311 invoked from network); 5 Jul 2005 21:58:45 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Jul 2005 21:58:45 -0000 Received: (qmail 29757 invoked by uid 500); 5 Jul 2005 21:57:13 -0000 Delivered-To: apmail-portals-jetspeed-dev-archive@portals.apache.org Received: (qmail 29584 invoked by uid 500); 5 Jul 2005 21:57:11 -0000 Mailing-List: contact jetspeed-dev-help@portals.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@portals.apache.org Received: (qmail 29144 invoked by uid 99); 5 Jul 2005 21:57:07 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jul 2005 14:57:07 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 05 Jul 2005 14:56:54 -0700 Received: (qmail 65031 invoked by uid 65534); 5 Jul 2005 21:56:48 -0000 Message-ID: <20050705215648.65030.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r209328 [13/14] - in /portals/jetspeed-2/trunk/components/portal: src/ src/java/ src/java/org/ src/java/org/apache/ src/java/org/apache/jetspeed/ src/java/org/apache/jetspeed/aggregator/ src/java/org/apache/jetspeed/aggregator/impl/ src/jav... Date: Tue, 05 Jul 2005 21:55:50 -0000 To: jetspeed-dev@portals.apache.org From: dlestrat@apache.org X-Mailer: svnmailer-1.0.2 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/pipeline/TestPipeline.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/pipeline/TestPipeline.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/pipeline/TestPipeline.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/pipeline/TestPipeline.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.pipeline; + +import junit.framework.Test; + +import org.apache.jetspeed.pipeline.valve.Valve; +import org.apache.jetspeed.test.JetspeedTest; +import org.apache.jetspeed.test.JetspeedTestSuite; + +/** + * TestPipeline + * + * @author David Sean Taylor + * @version $Id: TestPipeline.java 188605 2005-05-24 16:02:26Z ate $ + */ +public class TestPipeline extends JetspeedTest +{ + + /** + * Defines the testcase name for JUnit. + * + * @param name the testcase's name. + */ + public TestPipeline(String name) + { + super(name); + } + + /** + * Start the tests. + * + * @param args the arguments. Not used + */ + public static void main(String args[]) + { + junit.awtui.TestRunner.main(new String[] { TestPipeline.class.getName()}); + } + + public void setup() + { + } + + /** + * Creates the test suite. + * + * @return a test suite (TestSuite) that includes all methods + * starting with "test" + */ + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new JetspeedTestSuite(TestPipeline.class); + } + + /** + * Tests + * + * @throws Exception + */ + public void testPipeline() throws Exception + { + assertNotNull(engine); + Pipeline pipeline = engine.getPipeline(); + assertNotNull(pipeline); + Valve[] valves = pipeline.getValves(); + assertTrue(valves[0].toString().equals("LocalizationValve")); + assertTrue(valves[1].toString().equals("CapabilityValveImpl")); + assertTrue(valves[2].toString().equals("PortalURLValveImpl")); + assertTrue(valves[3].toString().equals("SecurityValve")); + assertTrue(valves[4].toString().equals("PasswordCredentialValve")); + assertTrue(valves[5].toString().equals("LoginValidationValve")); + assertTrue(valves[6].toString().equals("ProfilerValve")); + assertTrue(valves[7].toString().equals("ContainerValve")); + assertTrue(valves[8].toString().equals("ActionValveImpl")); + assertTrue(valves[9].toString().equals("AggregatorValve")); + assertTrue(valves[10].toString().equals("CleanupValveImpl")); + assertNotNull(engine.getPipeline("action-pipeline")); + assertNotNull(engine.getPipeline("portlet-pipeline")); + } +} Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTest.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTest.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTest.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTest.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,97 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.test; + +import junit.framework.Test; +import junit.framework.TestCase; + +import org.apache.jetspeed.engine.Engine; +import org.apache.jetspeed.engine.JetspeedEngineConstants; + + +/** + * Tests the Jetspeed Engine. + * + * @author David Sean Taylor + * @since 2.0 + * @version $Id: JetspeedTest.java 185962 2004-03-08 01:03:33Z jford $ + */ +public abstract class JetspeedTest extends TestCase implements JetspeedEngineConstants +{ + + + + + /** + * Creates a new instance. + */ + public JetspeedTest(String testName) + { + super(testName); + + } + + /** + * Return the Test + */ + public static Test suite() + { + return new JetspeedTestSuite(JetspeedTest.class); + } + + protected Engine engine = null; + protected JetspeedTestSuite jsuite; + + /** + * Setup the test. + */ + public void setUp() throws Exception + { + + super.setUp(); + } + + /** + * Override to set your own properties file + * + */ +// public String getPropertiesFile() +// { +// return jsuite.getPropertiesFile(); +// } + + /** + * Override to set your own application root + * + */ + public String getApplicationRoot() + { + return jsuite.getApplicationRoot(); + } + + /** + * Tear down the test. + */ + public void tearDown() throws Exception + { + + } + + + + + +} \ No newline at end of file Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTestSuite.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTestSuite.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTestSuite.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/test/JetspeedTestSuite.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,225 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Iterator; +import java.util.Properties; +import java.util.Map.Entry; + +import javax.servlet.ServletConfig; + +import junit.framework.Test; +import junit.framework.TestResult; +import junit.framework.TestSuite; + +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.jetspeed.Jetspeed; +import org.apache.jetspeed.PortalTestConstants; +import org.apache.jetspeed.engine.Engine; +import org.apache.jetspeed.engine.JetspeedEngineConstants; +import org.apache.jetspeed.engine.SpringEngine; +import org.apache.jetspeed.exception.JetspeedException; +import org.jmock.Mock; + +import com.mockrunner.mock.web.MockServletConfig; +import com.mockrunner.mock.web.MockServletContext; + +/** + *

+ * JetspeedTestSuite + *

+ * + * @author Scott T. Weaver + * @version $Id: JetspeedTestSuite.java 187753 2004-10-15 21:47:25Z ate $ + * + */ +public class JetspeedTestSuite extends TestSuite +{ + protected static Engine engine = null; + + /** + * + */ + public JetspeedTestSuite() + { + super(); + startEngine(getApplicationRoot(), getPropertiesFile()); + + } + + /** + * @param arg0 + * @param arg1 + */ + public JetspeedTestSuite(Class arg0, String arg1) + { + super(arg0, arg1); + startEngine(getApplicationRoot(), getPropertiesFile()); + + } + + /** + * @param arg0 + */ + public JetspeedTestSuite(Class arg0) + { + super(arg0); + startEngine(getApplicationRoot(), getPropertiesFile()); + + } + + /** + * @param arg0 + */ + public JetspeedTestSuite(String arg0) + { + super(arg0); + startEngine(getApplicationRoot(), getPropertiesFile()); + + } + + protected static void startEngine(String applicationRoot, String propertiesFilename) + { + try + { + if (engine != null) + { + return; + } + + Configuration properties = (Configuration) new PropertiesConfiguration(propertiesFilename); + + properties.setProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, applicationRoot); + //properties.setProperty(WEBAPP_ROOT_KEY, null); + initializeConfiguration(properties, applicationRoot); + Mock servletConfigMock = new Mock(ServletConfig.class); + MockServletConfig msc = new MockServletConfig(); + msc.setServletContext(new MockServletContext()); + engine = Jetspeed.createEngine(properties, applicationRoot, msc, SpringEngine.class); + + } + catch (Exception e) + { + e.printStackTrace(); + + } + } + protected static void stopEngine() + { + try + { + if (engine != null) + { + Jetspeed.shutdown(); + } + } + catch (JetspeedException e) + { + e.printStackTrace(); + } + finally + { + engine = null; + } + } + + /** + * Override to set your own application root + * + */ + public String getApplicationRoot() + { + String applicationRoot = System.getProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, PortalTestConstants.PORTAL_WEBAPP_PATH); + return applicationRoot; + } + + /** + * Override to set your own properties file + * + */ + public String getPropertiesFile() + { + String jetspeedProperties = System.getProperty(JetspeedEngineConstants.APPLICATION_ROOT_KEY, PortalTestConstants.PORTAL_WEBAPP_PATH) + "/WEB-INF/conf/jetspeed.properties"; + return jetspeedProperties; + } + + /* + * Implement this method to override any properties in your TestSuite. + * If you override this method in a derived class, call super.overrideProperties to get these settings + * + * @param properties The base configuration properties for the Jetspeed system. + */ + protected static void initializeConfiguration(Configuration properties, String appRoot) + { + String testPropsPath = appRoot + "/WEB-INF/conf/test/jetspeed.properties"; + try + { + File testFile = new File(testPropsPath); + if (testFile.exists()) + { + FileInputStream is = new FileInputStream(testPropsPath); + Properties props = new Properties(); + props.load(is); + + Iterator it = props.entrySet().iterator(); + while (it.hasNext()) + { + Entry entry = (Entry) it.next(); + //if (entry.getValue() != null && ((String)entry.getValue()).length() > 0) + properties.setProperty((String) entry.getKey(), (String) entry.getValue()); + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + } + + /** + * @see junit.framework.Test#run(junit.framework.TestResult) + */ + public void run(TestResult arg0) + { + try + { + super.run(arg0); + } + finally + { + stopEngine(); + } + } + + /** + * @see junit.framework.TestSuite#runTest(junit.framework.Test, junit.framework.TestResult) + */ + public void runTest(Test arg0, TestResult arg1) + { + if(arg0 instanceof JetspeedTest) + { + JetspeedTest jtest = (JetspeedTest) arg0; + jtest.engine = engine; + jtest.jsuite = this; + } + super.runTest(arg0, arg1); + } + +} Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/TestWebXML.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/TestWebXML.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/TestWebXML.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/TestWebXML.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.tools; + +import org.apache.jetspeed.test.JetspeedTestSuite; + +import junit.framework.Test; +import junit.framework.TestCase; + +/** + * Tests of rewriting the Web.xml for PAM deployment + * + * @author David Sean Taylor + * @since 2.0 + * @version $Id: TestWebXML.java 186206 2004-03-25 21:42:32Z jford $ + */ +public class TestWebXML extends TestCase +{ + /** + * Creates a new instance. + */ + public TestWebXML(String testName) + { + super(testName); + } + + /** + * Return the Test + */ + public static Test suite() + { + return new JetspeedTestSuite(TestWebXML.class); + } + + /** + * Setup the test. + */ + public void setUp() + { + } + + private static final String TEST_WEB_XML = "./test/testdata/deploy/web.xml"; + + public void testReadWrite() throws Exception + { + // DeployUtilities util = new DeployUtilities(); + // util.processWebXML(TEST_WEB_XML, "PATest"); + } + +} Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestJetspeedPortletDescriptor.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestJetspeedPortletDescriptor.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestJetspeedPortletDescriptor.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestJetspeedPortletDescriptor.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,117 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.tools.pamanager; + +import java.io.FileReader; +import java.util.Collection; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; + +import org.apache.jetspeed.om.common.JetspeedServiceReference; +import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; +import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite; +import org.apache.jetspeed.prefs.util.test.AbstractPrefsSupportedTestCase; +import org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata; +import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor; + + +/** + * Tests jetspeed-portlet.xml XML-Java mappings + * + * @author Jeremy Ford + * @author David Sean Taylor + * @version $Id: TestJetspeedPortletDescriptor.java 188438 2005-03-23 22:57:11Z ate $ + */ +public class TestJetspeedPortletDescriptor + extends AbstractPrefsSupportedTestCase { + + private static final String PORTLET_01 = "HelloWorld Portlet"; + private static final String PORTLET_02 = "Display the Portlet Request Information"; + private static final String PORTLET_03 = "Pick a number game"; + private static final String PORTLET_04 = "Attribute Scope Demo"; + + /** + * Start the tests. + * + * @param args the arguments. Not used + */ + public static void main(String args[]) + { + TestRunner.main(new String[] { TestPortletDescriptor.class.getName()}); + } + + + /** + * Creates the test suite. + * + * @return a test suite (TestSuite) that includes all methods + * starting with "test" + */ + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new TestSuite(TestJetspeedPortletDescriptor.class); + } + + public void testLoadPortletApplicationTree() throws Exception + { + System.out.println("Testing loadPortletApplicationTree"); + PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet.xml"), "unit-test"); + MutablePortletApplication app = pad.createPortletApplication(); + assertNotNull("App is null", app); + assertNotNull("Version is null", app.getVersion()); + assertTrue("Version invalid: " + app.getVersion(), app.getVersion().equals("1.0")); + assertNotNull("PA Identifier is null", app.getApplicationIdentifier()); + assertTrue( + "PA Identifier invalid: " + app.getApplicationIdentifier(), + app.getApplicationIdentifier().equals("TestRegistry")); + + ExtendedPortletMetadata md = new ExtendedPortletMetadata(new FileReader("./test/testdata/deploy/jetspeed-portlet.xml"), app); + md.load(); + + PortletDefinitionComposite def1 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_01); + PortletDefinitionComposite def2 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_02); + PortletDefinitionComposite def3 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_03); + PortletDefinitionComposite def4 = (PortletDefinitionComposite)app.getPortletDefinitionByName(PORTLET_04); + + Collection titles = app.getMetadata().getFields("title"); + Collection def1Titles = def1.getMetadata().getFields("title"); + Collection def2Subjects = def2.getMetadata().getFields("subject"); + Collection def3Creators = def3.getMetadata().getFields("creator"); + Collection def4Field1 = def4.getMetadata().getFields("field1"); + Collection def4Fiels2 = def4.getMetadata().getFields("field2"); + + assertEquals(titles.size(), 3); + assertEquals(def1Titles.size(), 4); + assertEquals(def2Subjects.size(), 5); + assertEquals(def3Creators.size(), 4); + assertEquals(def4Field1.size(), 3); + assertEquals(def4Fiels2.size(), 2); + + Collection servicesCollection = app.getJetspeedServices(); + assertNotNull("Metadata services is null", servicesCollection); + assertEquals("Expected 2 service definitions", servicesCollection.size(), 2); + Object[] services = servicesCollection.toArray(); + JetspeedServiceReference service = (JetspeedServiceReference)services[0]; + System.out.println("**** service = " + service.getName()); + + assertEquals( ((JetspeedServiceReference)services[0]).getName(), "PortletRegistryComponent"); + assertEquals( ((JetspeedServiceReference)services[1]).getName(), "PortletEntityAccessComponent"); + } + +} Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptor.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptor.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptor.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptor.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,417 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.tools.pamanager; + +import java.io.File; +import java.io.FileReader; +import java.util.Collection; +import java.util.Iterator; +import java.util.Locale; + +import javax.portlet.PortletMode; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; + +import org.apache.jetspeed.components.util.RegistrySupportedTestCase; +import org.apache.jetspeed.om.common.MutableLanguage; +import org.apache.jetspeed.om.common.ParameterComposite; +import org.apache.jetspeed.om.common.UserAttribute; +import org.apache.jetspeed.om.common.portlet.ContentTypeComposite; +import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; +import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite; +import org.apache.jetspeed.om.common.preference.PreferenceComposite; +import org.apache.jetspeed.util.DirectoryHelper; +import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor; +import org.apache.jetspeed.util.descriptor.PortletApplicationWar; +import org.apache.pluto.om.common.DisplayName; +import org.apache.pluto.om.common.LanguageSet; +import org.apache.pluto.om.common.ParameterSet; +import org.apache.pluto.om.common.Preference; +import org.apache.pluto.om.common.PreferenceSet; +import org.apache.pluto.om.portlet.ContentTypeSet; +import org.apache.pluto.om.portlet.PortletDefinition; +import org.apache.pluto.om.portlet.PortletDefinitionList; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.input.SAXBuilder; +import org.jdom.xpath.XPath; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/** + * TestPortletDescriptor - tests loading the portlet.xml deployment descriptor + * into Java objects + * + * @author David Sean Taylor + * + * @version $Id: TestPortletDescriptor.java 188438 2005-03-23 22:57:11Z ate $ + */ +public class TestPortletDescriptor extends RegistrySupportedTestCase +{ + /** + * Start the tests. + * + * @param args the arguments. Not used + */ + public static void main(String args[]) + { + TestRunner.main(new String[] { TestPortletDescriptor.class.getName()}); + } + + public static Test suite() + + { + + // All methods starting with "test" will be executed in the test suite. + + return new TestSuite(TestPortletDescriptor.class); + + } + + /* + * Overrides the database properties + */ + // public void overrideProperties(Configuration properties) + // { + // super.overrideProperties(properties); + // } + + public void testLoadPortletApplicationTree() throws Exception + { + System.out.println("Testing loadPortletApplicationTree"); + PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet.xml"), "unit-test"); + MutablePortletApplication app = pad.createPortletApplication(); + assertNotNull("App is null", app); + assertNotNull("Version is null", app.getVersion()); + assertTrue("Version invalid: " + app.getVersion(), app.getVersion().equals("1.0")); + assertNotNull("PA Identifier is null", app.getApplicationIdentifier()); + assertTrue( + "PA Identifier invalid: " + app.getApplicationIdentifier(), + app.getApplicationIdentifier().equals("TestRegistry")); + + validateUserInfo(app); + + // portlets + PortletDefinitionList portletsList = app.getPortletDefinitionList(); + Iterator it = portletsList.iterator(); + int count = 0; + while (it.hasNext()) + { + PortletDefinitionComposite portlet = (PortletDefinitionComposite) it.next(); + String identifier = portlet.getPortletIdentifier(); + assertNotNull("Portlet.Identifier is null", identifier); + if (identifier.equals("HelloPortlet")) + { + validateHelloPortlet(portlet); + } + count++; + } + assertTrue("Portlet Count != 4, = " + count, count == 4); + + } + + private void validateUserInfo(MutablePortletApplication app) + { + // Portlet User Attributes + Collection userAttributeSet = app.getUserAttributes(); + Iterator it = userAttributeSet.iterator(); + while (it.hasNext()) + { + UserAttribute userAttribute = (UserAttribute) it.next(); + assertNotNull("User attribute name is null, ", userAttribute.getName()); + if (userAttribute.getName().equals("user.name.given")) + { + assertTrue( + "User attribute description: " + userAttribute.getDescription(), + userAttribute.getDescription().equals("User Given Name")); + } + if (userAttribute.getName().equals("user.name.family")) + { + assertTrue( + "User attribute description: " + userAttribute.getDescription(), + userAttribute.getDescription().equals("User Last Name")); + } + if (userAttribute.getName().equals("user.home-info.online.email")) + { + assertTrue( + "User attribute description: " + userAttribute.getDescription(), + userAttribute.getDescription().equals("User eMail")); + } + } + } + + private void validateHelloPortlet(PortletDefinitionComposite portlet) + { + // Portlet Name + assertNotNull("Portlet.Name is null", portlet.getName()); + assertTrue("Portlet.Name invalid: " + portlet.getName(), portlet.getName().equals("HelloWorld Portlet")); + + // Portlet Class + assertNotNull("Portlet.Class is null", portlet.getClassName()); + assertTrue( + "Portlet.Class invalid: " + portlet.getClassName(), + portlet.getClassName().equals("org.apache.jetspeed.portlet.helloworld.HelloWorld")); + + // Expiration Cache + assertNotNull("Portlet.Expiration is null", portlet.getExpirationCache()); + assertTrue("Portlet.Expiration invalid: " + portlet.getExpirationCache(), portlet.getExpirationCache().equals("-1")); + + // Display Name + DisplayName displayName = portlet.getDisplayName(Locale.ENGLISH); + assertNotNull("Display Name is null", displayName); + assertTrue( + "Portlet.DisplayName invalid: " + displayName.getDisplayName(), + displayName.getDisplayName().equals("HelloWorld Portlet Wrapper")); + + // Init Parameters + ParameterSet paramsList = portlet.getInitParameterSet(); + Iterator it = paramsList.iterator(); + int count = 0; + while (it.hasNext()) + { + ParameterComposite parameter = (ParameterComposite) it.next(); + assertTrue("InitParam.Name invalid: " + parameter.getName(), parameter.getName().equals("hello")); + assertTrue("InitParam.Value invalid: " + parameter.getValue(), parameter.getValue().equals("Hello Portlet")); + assertTrue( + "InitParam.Description invalid: " + parameter.getDescription(Locale.ENGLISH), + parameter.getDescription(Locale.ENGLISH).getDescription().equals("test init param")); + count++; + } + assertTrue("InitParam Count != 1, count = " + count, count == 1); + + // Supports Content Type + ContentTypeSet supports = portlet.getContentTypeSet(); + it = supports.iterator(); + count = 0; + while (it.hasNext()) + { + ContentTypeComposite contentType = (ContentTypeComposite) it.next(); + assertTrue("MimeType invalid: " + contentType.getContentType(), contentType.getContentType().equals("text/html")); + + // Portlet Modes + Iterator modesIterator = contentType.getPortletModes(); + int modesCount = 0; + while (modesIterator.hasNext()) + { + PortletMode mode = (PortletMode) modesIterator.next(); + // System.out.println("mode = " + mode); + modesCount++; + } + assertTrue("Portlets Modes Count != 3, count = " + count, modesCount == 3); + + count++; + } + assertTrue("ContentType Count != 1, count = " + count, count == 1); + + // Portlet Info + LanguageSet infos = portlet.getLanguageSet(); + it = infos.iterator(); + count = 0; + while (it.hasNext()) + { + MutableLanguage info = (MutableLanguage) it.next(); + assertTrue("PortletInfo.Title invalid: " + info.getTitle(), info.getTitle().equals("HelloWorldTitle")); + assertTrue( + "PortletInfo.ShortTitle invalid: " + info.getShortTitle(), + info.getShortTitle().equals("This is the short title")); + Iterator keywords = info.getKeywords(); + assertNotNull("Keywords cannot be null", keywords); + int keywordCount = 0; + while (keywords.hasNext()) + { + String keyword = (String) keywords.next(); + if (keywordCount == 0) + { + assertTrue("PortletInfo.Keywords invalid: + " + keyword, keyword.equals("Test")); + } + else + { + assertTrue("PortletInfo.Keywords invalid: + " + keyword, keyword.equals("David")); + } + keywordCount++; + } + assertTrue("Keywords Count != 2, count = " + count, keywordCount == 2); + + count++; + } + assertTrue("PortletInfo Count != 1, count = " + count, count == 1); + + // Portlet Preferences + PreferenceSet prefs = portlet.getPreferenceSet(); + it = prefs.iterator(); + count = 0; + while (it.hasNext()) + { + PreferenceComposite pref = (PreferenceComposite) it.next(); + assertNotNull("Preference.Name is null", pref.getName()); + if (pref.getName().equals("time-server")) + { + assertTrue("Preference.Name invalid: " + pref.getName(), pref.getName().equals("time-server")); + assertTrue("Preference.Modifiable invalid: ", pref.isReadOnly() == false); + validatePreferences(pref, new String[] { "http://timeserver.myco.com", "http://timeserver.foo.com" }); + } + else + { + assertTrue("Preference.Name invalid: " + pref.getName(), pref.getName().equals("port")); + assertTrue("Preference.Modifiable invalid: ", pref.isReadOnly() == true); + validatePreferences(pref, new String[] { "404" }); + } + count++; + } + assertTrue("PortletPreference Count != 2, count = " + count, count == 2); + + } + + private void validatePreferences(PreferenceComposite pref, String[] expectedValues) + { + Iterator values = pref.getValues(); + + int count = 0; + while (values.hasNext()) + { + String value = (String) values.next(); + assertTrue("Preference.Value invalid: + " + value + "[" + count + "]", value.equals(expectedValues[count])); + count++; + // System.out.println("value = " + value); + } + assertTrue("Value Count != expectedCount, count = " + expectedValues.length, count == (expectedValues.length)); + + } + + public void testWritingToDB() throws Exception + { + + + MutablePortletApplication app = portletRegistry.getPortletApplication("HW_App"); + if (app != null) + { + portletRegistry.removeApplication(app); + + } + + PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet2.xml"), "HW_App"); + app = pad.createPortletApplication(); + + app.setName("HW_App"); + + + portletRegistry.registerPortletApplication(app); + + // store.invalidateAll(); + + + PortletDefinition pd = portletRegistry.getPortletDefinitionByUniqueName("HW_App::PreferencePortlet"); + + assertNotNull(pd); + + assertNotNull(pd.getPreferenceSet()); + + Preference pref1 = pd.getPreferenceSet().get("pref1"); + + assertNotNull(pref1); + + Iterator itr = pref1.getValues(); + int count = 0; + while (itr.hasNext()) + { + count++; + System.out.println("Value " + count + "=" + itr.next()); + } + + assertTrue(count > 0); + + + pd = portletRegistry.getPortletDefinitionByUniqueName("HW_App::PickANumberPortlet"); + + assertNotNull(pd); + + + portletRegistry.removeApplication(app); + + + } + + public void testInfusingWebXML() throws Exception + { + File warFile = new File("./test/testdata/deploy/webapp"); + PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" ); + + SAXBuilder builder = new SAXBuilder(false); + + // Use the local dtd instead of remote dtd. This + // allows to deploy the application offline + builder.setEntityResolver(new EntityResolver() + { + public InputSource resolveEntity(java.lang.String publicId, java.lang.String systemId) + throws SAXException, java.io.IOException + { + + if (systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd")) + { + return new InputSource(PortletApplicationWar.class.getResourceAsStream("web-app_2_3.dtd")); + } + else + return null; + } + }); + + FileReader srcReader = new FileReader("./test/testdata/deploy/webapp/WEB-INF/web.xml"); + FileReader targetReader = null; + Document doc = builder.build(srcReader); + + Element root = doc.getRootElement(); + + try + { + Object jetspeedServlet = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_XPATH); + Object jetspeedServletMapping = XPath.selectSingleNode(root, PortletApplicationWar.JETSPEED_SERVLET_MAPPING_XPATH); + + assertNull(jetspeedServlet); + assertNull(jetspeedServletMapping); + + PortletApplicationWar targetWar = paWar.copyWar("./target/webapp"); + targetWar.processWebXML(); + + targetReader = new FileReader("./target/webapp/WEB-INF/web.xml"); + + Document targetDoc = builder.build(targetReader); + Element targetRoot = targetDoc.getRootElement(); + + jetspeedServlet = XPath.selectSingleNode(targetDoc, PortletApplicationWar.JETSPEED_SERVLET_XPATH); + jetspeedServletMapping = XPath.selectSingleNode(targetDoc, PortletApplicationWar.JETSPEED_SERVLET_MAPPING_XPATH); + + + assertNotNull(jetspeedServlet); + assertNotNull(jetspeedServletMapping); + + } + finally + { + srcReader.close(); + paWar.close(); + targetReader.close(); + File warFile2 = new File("./target/webapp"); + DirectoryHelper dirHelper = new DirectoryHelper(warFile2); + dirHelper.remove(); + dirHelper.close(); + } + + } + +} Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptorSecurityRoles.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptorSecurityRoles.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptorSecurityRoles.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptorSecurityRoles.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,183 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.jetspeed.tools.pamanager; + +import java.io.File; + +import junit.framework.Test; +import junit.framework.TestSuite; +import junit.textui.TestRunner; + +import org.apache.jetspeed.components.util.RegistrySupportedTestCase; +import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; +import org.apache.jetspeed.om.common.servlet.MutableWebApplication; +import org.apache.jetspeed.om.servlet.impl.SecurityRoleImpl; +import org.apache.jetspeed.util.DirectoryHelper; +import org.apache.jetspeed.util.descriptor.PortletApplicationWar; +import org.apache.pluto.om.common.SecurityRole; +import org.apache.pluto.om.common.SecurityRoleRef; +import org.apache.pluto.om.common.SecurityRoleRefSet; +import org.apache.pluto.om.common.SecurityRoleSet; +import org.apache.pluto.om.portlet.PortletDefinition; + +/** + * TestPortletDescriptorSecurityRoles - test and validate security roles and + * security role references from portlet.xml and web.xml deployment descriptor. + * + * @author Ate Douma + * + * @version $Id: TestPortletDescriptorSecurityRoles.java,v 1.4 2004/05/27 + * 19:57:24 weaver Exp $ + */ +public class TestPortletDescriptorSecurityRoles extends RegistrySupportedTestCase +{ + + /** + * Start the tests. + * + * @param args + * the arguments. Not used + */ + public static void main( String args[] ) + { + TestRunner.main(new String[]{TestPortletDescriptorSecurityRoles.class.getName()}); + } + + /** + * Creates the test suite. + * + * @return a test suite (TestSuite) that includes all + * methods starting with "test" + */ + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new TestSuite(TestPortletDescriptorSecurityRoles.class); + } + + public void setUp() throws Exception + { + super.setUp(); + + } + + public void testSecurityRoles() throws Exception + { + System.out.println("Testing securityRoles"); + File warFile = new File("./test/testdata/deploy/webapp"); + PortletApplicationWar paWar = new PortletApplicationWar(new DirectoryHelper(warFile), "unit-test", "/" ); + + MutablePortletApplication app = paWar.createPortletApp(); + assertNotNull("App is null", app); + + MutableWebApplication webApp = paWar.createWebApp(); + assertNotNull("WebApp is null", webApp); + + app.setWebApplicationDefinition(webApp); + + PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet"); + assertNotNull("TestPortlet is null", portlet); + checkWebSecurityRoles(webApp); + checkPortletSecurityRoleRefs(portlet); + boolean validateFailed = false; + try + { + paWar.validate(); + } + catch (PortletApplicationException e) + { + validateFailed = true; + } + assertTrue("Invalid PortletDescriptor validation result", validateFailed); + SecurityRoleImpl role = new SecurityRoleImpl(); + role.setRoleName("users.manager"); + webApp.addSecurityRole(role); + try + { + paWar.validate(); + validateFailed = false; + } + catch (PortletApplicationException e) + { + } + assertEquals("Invalid PortletDescriptor validation result", false, validateFailed); + + // persist the app + try + { + + portletRegistry.registerPortletApplication(app); + + } + catch (Exception e) + { + String msg = "Unable to register portlet application, " + app.getName() + + ", through the portlet registry: " + e.toString(); + + throw new Exception(msg, e); + } + // clear cache + + + // read back in + app = portletRegistry.getPortletApplication("unit-test"); + validateFailed = true; + try + { + paWar.validate(); + validateFailed = false; + } + catch (PortletApplicationException e) + { + } + assertEquals("Invalid loaded PortletDescriptor validation result", false, validateFailed); + + // remove the app + try + { + + portletRegistry.removeApplication(app); + + } + catch (Exception e) + { + String msg = "Unable to remove portlet application, " + app.getName() + + ", through the portlet portletRegistry: " + e.toString(); + throw new Exception(msg, e); + } + + } + + private void checkWebSecurityRoles( MutableWebApplication webApp ) + { + SecurityRoleSet roles = webApp.getSecurityRoles(); + assertEquals("Invalid number of security role definitions found", 1, roles.size()); + SecurityRole role = roles.get("users.admin"); + assertNotNull("Role users.admin undefined", role); + } + + private void checkPortletSecurityRoleRefs( PortletDefinition portlet ) + { + SecurityRoleRefSet roleRefs = portlet.getInitSecurityRoleRefSet(); + assertEquals("Invalid number of security role references found", 2, roleRefs.size()); + SecurityRoleRef roleRef = roleRefs.get("admin"); + assertNotNull("Security Role Ref admin undefined", roleRef); + assertEquals("security Role link expected", "users.admin", roleRef.getRoleLink()); + roleRef = roleRefs.get("users.manager"); + assertNotNull("Security Role Ref users.manager undefined", roleRef); + assertNull("Undefined security Role link for users.managers expected", roleRef.getRoleLink()); + } +} Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/TestUserInfoManager.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,224 @@ +/* Copyright 2004 Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.userinfo; + +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.prefs.Preferences; + +import javax.portlet.PortletRequest; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.jetspeed.components.portletregistry.PortletRegistry; +import org.apache.jetspeed.mockobjects.request.MockRequestContext; +import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; +import org.apache.jetspeed.prefs.PropertyException; +import org.apache.jetspeed.prefs.om.Property; +import org.apache.jetspeed.request.RequestContext; +import org.apache.jetspeed.security.SecurityException; +import org.apache.jetspeed.security.SecurityHelper; +import org.apache.jetspeed.security.User; +import org.apache.jetspeed.security.util.test.AbstractSecurityTestcase; +import org.apache.jetspeed.util.descriptor.ExtendedPortletMetadata; +import org.apache.jetspeed.util.descriptor.PortletApplicationDescriptor; + +/** + *

Unit test for {@link UserInfoManager}

+ * + * @author David Le Strat + */ +public class TestUserInfoManager extends AbstractSecurityTestcase +{ + + /** The user info manager. */ + private UserInfoManager uim; + + private PortletRegistry portletRegistry; + + + /** + * @see junit.framework.TestCase#setUp() + */ + public void setUp() throws Exception + { + super.setUp(); + + uim = (UserInfoManager) ctx.getBean("org.apache.jetspeed.userinfo.UserInfoManager"); + portletRegistry = (PortletRegistry) ctx.getBean("portletRegistry"); + } + + /** + * @see junit.framework.TestCase#tearDown() + */ + public void tearDown() throws Exception + { + super.tearDown(); + } + + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new TestSuite(TestUserInfoManager.class); + } + + /** Test set user info map. */ + public void testSetUserInfoMap() throws Exception + { + PortletApplicationDescriptor pad = new PortletApplicationDescriptor(new FileReader("./test/testdata/deploy/portlet.xml"), "unit-test"); + MutablePortletApplication app = pad.createPortletApplication(); + assertNotNull("App is null", app); + + // persist the app + try + { + portletRegistry.registerPortletApplication(app); + } + catch (Exception e) + { + String msg = + "Unable to register portlet application, " + app.getName() + ", through the portlet portletRegistry: " + e.toString(); + + throw new Exception(msg, e); + } + + RequestContext request = initRequestContext("anon"); + + // Without linked attributes + // There are no preferences associated to the user profile. + Map userInfo = uim.getUserInfoMap(app.getId(), request); + assertNull(PortletRequest.USER_INFO + " is null", userInfo); + + // The user has preferences associated to the user profile. + initUser(); + request = initRequestContext("test"); + userInfo = uim.getUserInfoMap(app.getId(), request); + assertNotNull(PortletRequest.USER_INFO + " should not be null", userInfo); + assertEquals("should contain user.name.given", "Test Dude", (String) userInfo.get("user.name.given")); + assertEquals("should contain user.name.family", "Dudley", (String) userInfo.get("user.name.family")); + assertNull("should not contain user.home-info.online.email", userInfo.get("user.home-info.online.email")); + + // With linked attributes + ExtendedPortletMetadata extMetaData = new ExtendedPortletMetadata(new FileReader("./test/testdata/deploy/jetspeed-portlet.xml"), app); + extMetaData.load(); + + userInfo = uim.getUserInfoMap(app.getId(), request); + assertNotNull(PortletRequest.USER_INFO + " should not be null", userInfo); + assertEquals("should contain user-name-given", "Test Dude", (String) userInfo.get("user-name-given")); + assertEquals("should contain user-name-family", "Dudley", (String) userInfo.get("user-name-family")); + + // remove the app + try + { + portletRegistry.removeApplication(app); + } + catch (Exception e) + { + String msg = + "Unable to remove portlet application, " + app.getName() + ", through the portlet portletRegistry: " + e.toString(); + throw new Exception(msg, e); + } + + destroyUser(); + } + + /** + *

Initialize the mock request context.

+ * @param username The username. + * @return The request context. + */ + private RequestContext initRequestContext(String username) + { + RequestContext request = new MockRequestContext("default-other"); + + request.setSubject(SecurityHelper.createSubject(username)); + return request; + } + + /** + *

Init test user.

+ */ + private void initUser() throws Exception + { + User user = null; + try + { + ums.addUser("test", "password01"); + user = ums.getUser("test"); + } + catch (SecurityException sex) + { + assertTrue("user exists. should not have thrown an exception.", false); + } + Preferences userInfoPrefs = user.getPreferences().node("userinfo"); + Map propertyKeys = initPropertyKeysMap(); + try + { + propertyManager.addPropertyKeys(userInfoPrefs, propertyKeys); + } + catch (PropertyException pex) + { + assertTrue("should have add propertyKeys. should not have thrown an exception.", false); + } + userInfoPrefs.put("user.name.given", "Test Dude"); + userInfoPrefs.put("user.name.family", "Dudley"); + } + + /** + *

Init property property keys map.

+ */ + protected Map initPropertyKeysMap() + { + // Build a few property keys. + Map propertyKeys = new HashMap(); + propertyKeys.put("user.name.given", new Integer(Property.STRING_TYPE)); + propertyKeys.put("user.name.family", new Integer(Property.STRING_TYPE)); + + return propertyKeys; + } + + /** + *

Destroy user test object.

+ */ + protected void destroyUser() + { + try + { + if (ums.userExists("test")) + { + ums.removeUser("test"); + } + } + catch (SecurityException sex) + { + System.out.println("could not remove test users. exception caught: " + sex); + } + } + + protected String[] getConfigurations() + { + + String[] confs = super.getConfigurations(); + List confList = new ArrayList(Arrays.asList(confs)); + confList.add("META-INF/registry-dao.xml"); + confList.add("org/apache/jetspeed/userinfo/user-info.xml"); + return (String[]) confList.toArray(new String[1]); + } +} Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/user-info.xml URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/user-info.xml?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/user-info.xml (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/userinfo/user-info.xml Tue Jul 5 14:55:37 2005 @@ -0,0 +1,27 @@ + + + + + + + + + + + \ No newline at end of file Added: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java (added) +++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/window/TestWindows.java Tue Jul 5 14:55:37 2005 @@ -0,0 +1,172 @@ +/* + * Copyright 2000-2001,2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jetspeed.window; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent; +import org.apache.jetspeed.container.window.PortletWindowAccessor; +import org.apache.jetspeed.container.window.impl.PortletWindowAccessorImpl; +import org.apache.jetspeed.om.common.portlet.MutablePortletEntity; +import org.apache.jetspeed.om.page.ContentFragment; +import org.apache.jetspeed.om.page.Fragment; +import org.apache.jetspeed.om.page.psml.ContentFragmentImpl; +import org.apache.pluto.om.window.PortletWindow; +import org.apache.pluto.om.window.PortletWindowList; +import org.apache.pluto.om.window.PortletWindowListCtrl; +import org.jmock.Mock; +import org.jmock.core.Invocation; +import org.jmock.core.matcher.InvokeAtLeastOnceMatcher; +import org.jmock.core.matcher.InvokeCountMatcher; +import org.jmock.core.matcher.InvokeOnceMatcher; +import org.jmock.core.stub.CustomStub; +import org.jmock.core.stub.ReturnStub; + +/** + * @author Scott T. Weaver + * +*/ +public class TestWindows extends TestCase +{ + protected PortletWindowAccessor windowAccess; + protected Mock fragMock; + protected Mock entityAccessMock; + protected Mock entityMock; + protected Mock windowListMock; + + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new TestSuite(TestWindows.class); + } + + /** + *

+ * setUp + *

+ * + * @see junit.framework.TestCase#setUp() + * @throws java.lang.Exception + */ + protected void setUp() throws Exception + { + super.setUp(); + entityAccessMock = new Mock(PortletEntityAccessComponent.class); + fragMock = new Mock(Fragment.class); + entityMock = new Mock(MutablePortletEntity.class); + windowListMock = new Mock(CompositeWindowList.class); + windowAccess = new PortletWindowAccessorImpl((PortletEntityAccessComponent) entityAccessMock.proxy(), true); + } + + public void testWindowAccess() throws Exception + { + List windows = new ArrayList(); + ContentFragment f1 = new ContentFragmentImpl((Fragment) fragMock.proxy(), new HashMap()); + MutablePortletEntity entity = (MutablePortletEntity) entityMock.proxy(); + CompositeWindowList windowList = (CompositeWindowList) windowListMock.proxy(); + entityAccessMock.expects(new InvokeAtLeastOnceMatcher()).method("getPortletEntityForFragment") + .withAnyArguments().will(new ReturnStub(entity)); + fragMock.expects(new InvokeAtLeastOnceMatcher()).method("getId").withNoArguments() + .will(new ReturnStub("frag1")); + entityMock.expects(new InvokeAtLeastOnceMatcher()).method("getPortletWindowList").withNoArguments().will( + new ReturnStub(windowList)); + + windowListMock.expects(new InvokeCountMatcher(4)).method("add").withAnyArguments().will( + new ListAppendStub(windows)); + + + PortletWindow window = windowAccess.getPortletWindow(f1); + assertNotNull(window); + assertEquals("frag1", window.getId().toString()); + + // Make sure the portlet entity's window list got updated + assertEquals(1, windows.size()); + + PortletWindow windowInList = (PortletWindow) windows.get(0); + + // The window in the entities list should be the same as the one + // returned by getPortletWindow(f1) + assertEquals(windowInList, window); + + // remove the window + windowAccess.removeWindow(window); + + // Calling this after a remove go through th procedure of adding a newly + // created window + // back the portlet entity's list. We check this through vefirying calls + // to our mocks + windowAccess.getPortletWindow(f1); + + // Test same remove but via entity + windowAccess.removeWindow(window); + + assertNotNull(windowAccess.getPortletWindow(f1)); + + windowListMock.expects(new InvokeOnceMatcher()).method("iterator").withNoArguments().will(new ReturnStub(windows.iterator())); + + windowAccess.removeWindows(entity); + + windowAccess.getPortletWindow(f1); + // Double that second call bypasses creating a new window + //windowAccess.getPortletWindow(f1); + + windowListMock.verify(); + + } + + interface CompositeWindowList extends PortletWindowList, PortletWindowListCtrl + { + + } + + class ListAppendStub extends CustomStub + { + + List list; + + /** + * @param arg0 + */ + public ListAppendStub( List list ) + { + super("Appends object to a list"); + this.list = list; + } + + /** + *

+ * invoke + *

+ * + * @see org.jmock.core.Stub#invoke(org.jmock.core.Invocation) + * @param arg0 + * @return @throws + * java.lang.Throwable + */ + public Object invoke( Invocation invocation ) throws Throwable + { + list.add(invocation.parameterValues.get(0)); + return null; + } + } + +} \ No newline at end of file Added: portals/jetspeed-2/trunk/components/portal/test/assembly/TestCastorXmlPageManager.groovy URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/assembly/TestCastorXmlPageManager.groovy?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/test/assembly/TestCastorXmlPageManager.groovy (added) +++ portals/jetspeed-2/trunk/components/portal/test/assembly/TestCastorXmlPageManager.groovy Tue Jul 5 14:55:37 2005 @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.picocontainer.defaults.DefaultPicoContainer +import org.apache.jetspeed.idgenerator.JetspeedIdGenerator +import org.apache.jetspeed.page.impl.CastorXmlPageManager +import org.apache.jetspeed.components.ComponentAssemblyTestCase +import org.apache.jetspeed.cache.file.FileCache + +// create the root container +container = new DefaultPicoContainer() + +applicationRoot = ComponentAssemblyTestCase.getApplicationRoot("portal", "test") + +// +// ID Generator +// +idgenerator = new JetspeedIdGenerator() +container.registerComponentInstance("IdGenerator", idgenerator) + +// +// Page Manager +// +Long scanRate = 120 +cacheSize = 100 +fileCache = new FileCache(scanRate, cacheSize) +root = applicationRoot + "/testdata/pages" +container.registerComponentInstance("CastorXmlPageManager", + new CastorXmlPageManager(idgenerator, fileCache, root)) + +return container Added: portals/jetspeed-2/trunk/components/portal/test/assembly/TestDatabasePageManager.groovy URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/assembly/TestDatabasePageManager.groovy?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/test/assembly/TestDatabasePageManager.groovy (added) +++ portals/jetspeed-2/trunk/components/portal/test/assembly/TestDatabasePageManager.groovy Tue Jul 5 14:55:37 2005 @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.picocontainer.defaults.DefaultPicoContainer +import org.apache.jetspeed.idgenerator.JetspeedIdGenerator +import org.apache.jetspeed.page.impl.DatabasePageManager +import org.apache.jetspeed.components.ComponentAssemblyTestCase + +// create the root container +container = new DefaultPicoContainer() + +// +// ID Generator +// +idgenerator = new JetspeedIdGenerator() +container.registerComponentInstance("IdGenerator", idgenerator) + + +// +// Persistence Store Service +// +// TODO: get persistence store service + +// +// Page Manager +// +container.registerComponentInstance("DatabasePageManager", + new DatabasePageManager(null, idgenerator, null)) + +return container Added: portals/jetspeed-2/trunk/components/portal/test/deployment/.cvsignore URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/.cvsignore?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/test/deployment/.cvsignore (added) +++ portals/jetspeed-2/trunk/components/portal/test/deployment/.cvsignore Tue Jul 5 14:55:37 2005 @@ -0,0 +1 @@ +templates Added: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/README.txt URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/README.txt?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/README.txt (added) +++ portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/README.txt Tue Jul 5 14:55:37 2005 @@ -0,0 +1,15 @@ +Copyright 2004 The Apache Software Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +This is were you things to be deployed to Jetspeed (not implemented yet) \ No newline at end of file Added: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/demo.war URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/demo.war?rev=209328&view=auto ============================================================================== Binary file - no diff available. Propchange: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/demo.war ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/jetspeed-layouts.war URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/jetspeed-layouts.war?rev=209328&view=auto ============================================================================== Binary file - no diff available. Propchange: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/jetspeed-layouts.war ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/portletstd.jar URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/portletstd.jar?rev=209328&view=auto ============================================================================== Binary file - no diff available. Propchange: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/portletstd.jar ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/portlet.xml URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/portlet.xml?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/portlet.xml (added) +++ portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/portlet.xml Tue Jul 5 14:55:37 2005 @@ -0,0 +1,53 @@ + + + + + TestPortlet + org.apache.jetspeed.portlet.helloworld.HelloWorld + HelloWorld Portlet Wrapper + This is a desciption of the HelloWorld portlet + -1 + + text/html + EDIT + VIEW + HELP + + + HelloWorldTitle + This is the short title + Test,David + + + + time-server + http://timeserver.myco.com + http://timeserver.foo.com + false + + + port + 404 + true + + + + + + + + Added: portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/web.xml URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/web.xml?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/web.xml (added) +++ portals/jetspeed-2/trunk/components/portal/test/deployment/deploy/security-app/WEB-INF/web.xml Tue Jul 5 14:55:37 2005 @@ -0,0 +1,31 @@ + + + + + Jetspeed Container Application + MVC Servlet for Jetspeed Portlet Applications + + + + + index.jsp + + + + + Added: portals/jetspeed-2/trunk/components/portal/test/deployment/redeploy/demo.war URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/redeploy/demo.war?rev=209328&view=auto ============================================================================== Binary file - no diff available. Propchange: portals/jetspeed-2/trunk/components/portal/test/deployment/redeploy/demo.war ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: portals/jetspeed-2/trunk/components/portal/test/deployment/webapps/.cvsignore URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/test/deployment/webapps/.cvsignore?rev=209328&view=auto ============================================================================== --- portals/jetspeed-2/trunk/components/portal/test/deployment/webapps/.cvsignore (added) +++ portals/jetspeed-2/trunk/components/portal/test/deployment/webapps/.cvsignore Tue Jul 5 14:55:37 2005 @@ -0,0 +1,2 @@ +META-INF +WEB-INF --------------------------------------------------------------------- To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org For additional commands, e-mail: jetspeed-dev-help@portals.apache.org