Author: julien(a)jboss.com
Date: 2007-03-19 14:14:33 -0400 (Mon, 19 Mar 2007)
New Revision: 6753
Added:
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestDriver.java
Log:
allows portlet container tests to setup test parameters
Added:
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestDriver.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestDriver.java
(rev 0)
+++
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestDriver.java 2007-03-19
18:14:33 UTC (rev 6753)
@@ -0,0 +1,143 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.framework.portlet;
+
+import org.jboss.portal.common.test.info.TestInfo;
+import org.jboss.portal.common.test.info.TestContainerInfo;
+import org.jboss.portal.common.test.info.TestItemInfo;
+import org.jboss.portal.common.test.info.TestParameterInfo;
+import org.jboss.portal.common.test.driver.DriverResponse;
+import org.jboss.portal.common.test.driver.DriverCommand;
+import org.jboss.portal.common.test.driver.TestDriverException;
+import org.jboss.portal.test.framework.driver.http.response.InvokeGetResponse;
+import org.jboss.portal.test.framework.driver.http.HttpTestDriver;
+import org.jboss.portal.test.framework.driver.http.HttpTestContext;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * Registry of action sequences. Every sequence is binded with test id
+ *
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 6720 $
+ */
+public class PortletTestDriver implements HttpTestDriver
+{
+
+ /** . */
+ private final Map entries;
+
+ /** . */
+ protected final TestContainerInfo container;
+
+ /** . */
+ private static PortletTestContext context;
+
+ public PortletTestDriver(String name)
+ {
+ entries = Collections.synchronizedMap(new HashMap());
+ container = new TestContainerInfo(name);
+ }
+
+ /**
+ * Adding sequence to registry. Sequence can be null as this will clear the binding
+ *
+ * @param testName
+ * @param portletTest
+ */
+ public void addSequence(String testName, PortletTest portletTest)
+ {
+ if (testName == null)
+ {
+ throw new IllegalArgumentException("Test name must be provided");
+ }
+ if (portletTest == null)
+ {
+ throw new IllegalArgumentException("Portlet test can't be null");
+ }
+ if (entries.containsKey(testName))
+ {
+ throw new IllegalArgumentException("Portlet test cannot be bound
twice");
+ }
+
+ //
+ TestInfo test = new TestInfo(testName);
+ for (Iterator i = portletTest.parameters.iterator();i.hasNext();)
+ {
+ String parameterName = (String)i.next();
+ test.addParameter(new TestParameterInfo(parameterName));
+ }
+
+ //
+ entries.put(testName, portletTest);
+ container.addChild(test);
+ }
+
+ public void removeSequence(String testName)
+ {
+ container.removeChild(testName);
+ }
+
+ public PortletTest getSequence(String testName)
+ {
+ if (testName == null)
+ {
+ throw new IllegalArgumentException("Test name can't be null");
+ }
+ return (PortletTest)entries.get(testName);
+ }
+
+ public TestItemInfo getInfo()
+ {
+ return container;
+ }
+
+ public DriverResponse invoke(String testId, DriverCommand command) throws
TestDriverException
+ {
+ TestInfo info = (TestInfo)getInfo().findItem(testId);
+ return new InvokeGetResponse("/test/" + info.getName());
+ }
+
+ public void pushContext(String testId, HttpTestContext ctx)
+ {
+ context = new PortletTestContext(ctx);
+ }
+
+ public HttpTestContext popContext(String testId)
+ {
+ return context.httpTestContext;
+ }
+
+ /**
+ * The current portlet test context statically available.
+ *
+ * @return the portlet test context.
+ */
+ public static PortletTestContext getPortletTestContext()
+ {
+ return context;
+ }
+}
Property changes on:
trunk/portlet/src/main/org/jboss/portal/test/framework/portlet/PortletTestDriver.java
___________________________________________________________________
Name: svn:executable
+ *