You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by dd...@apache.org on 2004/09/16 06:40:47 UTC
svn commit: rev 46155 - portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet
Author: ddewolf
Date: Wed Sep 15 21:40:47 2004
New Revision: 46155
Added:
portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestConfig.java
portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestConfigFactory.java
Modified:
portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestPortlet.java
Log:
Adding dynamic testsuite configuration. Supports friendly names.
Added: portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestConfig.java
==============================================================================
--- (empty file)
+++ portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestConfig.java Wed Sep 15 21:40:47 2004
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+package org.apache.pluto.portalImpl.portlet;
+
+/**
+ * TestPortlet Configuration.
+ *
+ * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
+ * @version 1.0
+ * @since Sep 15, 2004
+ */
+public class TestConfig {
+
+ private String testClassName;
+ private String name;
+ private String displayURI;
+
+ public TestConfig() {
+
+ }
+
+ public String getTestClassName() {
+ return testClassName;
+ }
+
+ public void setTestClassName(String testClassName) {
+ this.testClassName = testClassName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String testName) {
+ this.name = testName;
+ }
+
+ public String getDisplayURI() {
+ return displayURI;
+ }
+
+ public void setDisplayURI(String displayURI) {
+ this.displayURI = displayURI;
+ }
+
+
+}
+
Added: portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestConfigFactory.java
==============================================================================
--- (empty file)
+++ portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestConfigFactory.java Wed Sep 15 21:40:47 2004
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+package org.apache.pluto.portalImpl.portlet;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.commons.digester.Digester;
+import org.xml.sax.SAXException;
+
+/**
+ * @author <a href="ddewolf@apache.com">David H. DeWolf</a>
+ *
+ */
+public class TestConfigFactory {
+
+ private Digester digester = new Digester();
+
+ public TestConfigFactory() {
+ digester = new Digester();
+ digester.addObjectCreate("testportlet-config",
+ java.util.ArrayList.class);
+
+ digester.addObjectCreate("testportlet-config/testsuite-config",
+ TestConfig.class);
+
+ digester.addBeanPropertySetter("testportlet-config/testsuite-config/name",
+ "name");
+
+ digester.addBeanPropertySetter("testportlet-config/testsuite-config/class",
+ "testClassName");
+
+ digester.addBeanPropertySetter("testportlet-config/testsuite-config/display-uri",
+ "displayURI");
+
+ digester.addSetRoot("testportlet-config/testsuite-config",
+ "add");
+
+ }
+
+ public List createTests(InputStream in)
+ throws SAXException, IOException {
+ return (List)digester.parse(in);
+ }
+}
Modified: portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestPortlet.java
==============================================================================
--- portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestPortlet.java (original)
+++ portals/pluto/trunk/testsuite/src/java/org/apache/pluto/portalImpl/portlet/TestPortlet.java Wed Sep 15 21:40:47 2004
@@ -21,9 +21,13 @@
import javax.portlet.*;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Map;
import java.util.ArrayList;
import java.util.TreeMap;
+import java.util.List;
+import java.util.Iterator;
+import java.util.HashMap;
import org.apache.pluto.portalImpl.portlet.test.SimpleAttributeTest;
import org.apache.pluto.portalImpl.portlet.test.PortletTest;
@@ -39,30 +43,51 @@
public class TestPortlet extends GenericPortlet {
- public static final Map TESTS = new TreeMap();
- public static final ArrayList TEST_IDX;
-
- static {
- TESTS.put("01_simple_parameter_test", new SimpleParameterTest());
- TESTS.put("02_simple_attribute_test", new SimpleAttributeTest());
- TESTS.put("03_complex_attribute_test", new ComplexAttributeTest());
- TESTS.put("04_ext_app_scoped_attr_test", new ExternalAppScopedAttributeTest());
- TESTS.put("05_simple_preference_test", new SimplePreferenceTest());
- TESTS.put("06_portlet_mode_test", null);
- TESTS.put("07_window_state_test", null);
- TESTS.put("08_security_mapping_test", new SecurityMappingTest());
- TESTS.put("09_misc_test", new MiscTest());
- TESTS.put("10_context_init_param_test", new ContextInitParameterTest());
+ private String portletName;
- TEST_IDX = new ArrayList(TESTS.keySet());
- }
+ private List configs;
+ private Map tests;
- private String portletName;
- public void init() {
- portletName = getPortletContext().getInitParameter("display-name");
+ public void init() throws PortletException {
+ portletName = getInitParameter("display-name");
if(portletName==null) {
portletName = "Test Portlet";
}
+
+ String configFile = getInitParameter("config");
+ if(configFile==null) {
+ configFile = "/WEB-INF/testsuite-config.xml";
+ }
+
+ InputStream in = getPortletContext().getResourceAsStream(configFile);
+ if( in !=null ) {
+ TestConfigFactory fact = new TestConfigFactory();
+ try {
+ configs = fact.createTests(in);
+ tests = new HashMap();
+ Iterator it = configs.iterator();
+ int i = 0;
+ while(it.hasNext()) {
+ TestConfig config = (TestConfig)it.next();
+ String name= config.getTestClassName();
+ if(name != null) {
+ Class cl = Class.forName(config.getTestClassName());
+ PortletTest test = (PortletTest)cl.newInstance();
+ tests.put(String.valueOf(i++), test);
+ }
+ else {
+ i++;
+ }
+
+ }
+ }
+ catch (Throwable t) {
+ throw new PortletException("Unable to read configuration", t);
+ }
+ }
+ else {
+ throw new IllegalStateException("Configuration File Not Found");
+ }
}
@@ -71,7 +96,7 @@
throws PortletException, java.io.IOException {
String testId = getTestId(request);
- PortletTest test = (PortletTest)TESTS.get(testId);
+ PortletTest test = (PortletTest)tests.get(testId);
if(test!=null && test instanceof ActionTest) {
TestResults results = test.doTest(getPortletContext(), request, response);
@@ -96,7 +121,13 @@
throws PortletException, IOException {
String testId = getTestId(request);
- PortletTest test = (PortletTest)TESTS.get(testId);
+
+ TestConfig config = null;
+ if(testId != null) {
+ config = (TestConfig)configs.get(Integer.parseInt(testId));
+ }
+
+ PortletTest test = (PortletTest)tests.get(testId);
response.setTitle(portletName);
PortletMode mode = request.getPortletMode();
@@ -114,12 +145,18 @@
request.setAttribute("results", results);
}
- if("xx_introduction".equals(testId)) {
- request.setAttribute("tests", TEST_IDX);
+ if(testId == null) {
+ request.setAttribute("tests", configs);
}
PortletContext context = getPortletContext();
- PortletRequestDispatcher rd = context.getRequestDispatcher("/jsp/"+testId.substring(3)+".jsp");
+ PortletRequestDispatcher rd = null;
+ if(config != null) {
+ rd = context.getRequestDispatcher(config.getDisplayURI());
+ }
+ else {
+ rd = context.getRequestDispatcher("/jsp/introduction.jsp");
+ }
rd.include(request,response);
}
@@ -137,32 +174,32 @@
}
private String getTestId(PortletRequest req) {
- String testId = req.getParameter("testId");
+ String testId = req.getParameter("testId");
String previous = req.getParameter("previousTestId");
String next = req.getParameter("nextTestId");
if(testId == null && next == null &&
- previous == null && TESTS.size() > 0) {
- testId = "xx_introduction";
+ previous == null && tests.size() > 0) {
+ return null;
}
// Retrieve the test which is next to the previous
else if(testId == null && previous !=null) {
- int idx = TEST_IDX.indexOf(previous);
- if(idx >= TEST_IDX.size()-1) {
- testId = (String)TEST_IDX.get(0);
+ int pId = Integer.parseInt(previous);
+ if(pId >= configs.size()-1) {
+ testId = "0";
}
else {
- testId = (String)TEST_IDX.get(idx+1);
+ testId = String.valueOf(pId+1);
}
}
// Retrieve the test which is previous to the next
else if(testId == null && next !=null) {
- int idx = TEST_IDX.indexOf(next);
- if(idx <= 0) {
- testId = (String)TEST_IDX.get(TEST_IDX.size()-1);
+ int nId = Integer.parseInt(next);
+ if(nId <= 0) {
+ testId = String.valueOf(configs.size()-1);
}
else {
- testId = (String)TEST_IDX.get(idx - 1);
+ testId = String.valueOf(nId - 1);
}
}