Author: julien(a)jboss.com
Date: 2008-02-18 06:21:08 -0500 (Mon, 18 Feb 2008)
New Revision: 10014
Added:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/EventControllerContextSupport.java
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerContextSupport.java
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletInvocationContextSupport.java
modules/portlet/trunk/controller/src/test/resources/local-jboss-unit.xml
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletInvokerSupport.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletSupport.java
Removed:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletInvokerSupport.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletSupport.java
Modified:
modules/portlet/trunk/controller/pom.xml
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortlet.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortletInvoker.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortlet.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventInfoSupport.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventingInfoSupport.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java
Log:
started to add test case for portlet controller + refactor some stuff to be reused in
portlet controller test cases
Modified: modules/portlet/trunk/controller/pom.xml
===================================================================
--- modules/portlet/trunk/controller/pom.xml 2008-02-18 08:26:22 UTC (rev 10013)
+++ modules/portlet/trunk/controller/pom.xml 2008-02-18 11:21:08 UTC (rev 10014)
@@ -20,6 +20,22 @@
<type>jar</type>
</dependency>
+ <!-- Dependencies for tests -->
+
+ <dependency>
+ <groupId>org.jboss.unit</groupId>
+ <artifactId>jboss-unit-remote</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.portal.portlet</groupId>
+ <artifactId>portlet-portlet</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
<!--TEST SCOPE-->
<!--dependency>
<groupId>org.jboss.portal.portlet</groupId>
@@ -192,4 +208,32 @@
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jboss.unit</groupId>
+ <artifactId>jboss-unit-tooling-maven2</artifactId>
+ <executions>
+ <execution>
+ <phase>test</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <testsuites>
+ <testsuite>
+ <config>local-jboss-unit.xml</config>
+ </testsuite>
+ </testsuites>
+ <reports>
+ <xml>target/tests/reports/xml</xml>
+ <html>target/tests/reports/html</html>
+ </reports>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletController.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -29,8 +29,6 @@
import org.jboss.portal.portlet.controller.request.PortletResourceRequest;
import org.jboss.portal.portlet.controller.response.ControllerResponse;
-import java.io.IOException;
-
/**
* The portlet controller which handles the page state management and the interactions
between the action phase and the
* event phase. It really only does that and not more.
@@ -46,10 +44,66 @@
*/
public class PortletController
{
- public ControllerResponse process(PortletControllerContext controllerContext,
ControllerRequest controllerRequest) throws IOException, PortletInvokerException
+
+ /** . */
+ private boolean distributeNonConsumableEvents;
+
+ /** . */
+ private boolean distributeNonProduceableEvents;
+
+ public PortletController()
{
+ distributeNonConsumableEvents = true;
+ distributeNonProduceableEvents = true;
+ }
+
+ /**
+ * This option configures the behavior of the controller when an event returned by
the
+ * event controller is not declared by the target receiving portlet. If the value is
true, then the event
+ * will be fired whatsoever otherwise it will be discarded.
+ *
+ * @return true if the controller distribute a non declared event
+ */
+ public boolean getDistributeNonConsumableEvents()
+ {
+ return distributeNonConsumableEvents;
+ }
+
+ public void setDistributeNonConsumableEvents(boolean distributeNonConsumableEvents)
+ {
+ this.distributeNonConsumableEvents = distributeNonConsumableEvents;
+ }
+
+ /**
+ * This option configures the behavior of the controller when a portlet produces an
event it does
+ * not declare. If the value is true then the event will be managed by the event
controller for
+ * further redistribution, otherwise it will be discarded.
+ *
+ * @return true if the controller distribute a non declared event
+ */
+ public boolean getDistributeNonProduceableEvents()
+ {
+ return distributeNonProduceableEvents;
+ }
+
+ public void setDistributeNonProduceableEvents(boolean distributeNonProduceableEvents)
+ {
+ this.distributeNonProduceableEvents = distributeNonProduceableEvents;
+ }
+
+ public ControllerResponse process(PortletControllerContext controllerContext,
ControllerRequest controllerRequest) throws PortletInvokerException
+ {
+ if (controllerContext == null)
+ {
+ throw new IllegalArgumentException("Null context");
+ }
+ if (controllerRequest == null)
+ {
+ throw new IllegalArgumentException("Null request");
+ }
+
+ //
RequestHandler handler;
-
if (controllerRequest instanceof PortletRequest)
{
handler = new PortletRequestHandler(this);
@@ -60,9 +114,10 @@
}
else
{
- throw new PortletInvokerException("Unknown request type: " +
controllerRequest.getClass().getName());
+ throw new IllegalArgumentException("Unknown request type: " +
controllerRequest.getClass().getName());
}
+ //
return handler.handle(controllerContext, controllerRequest);
}
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletRequestHandler.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -28,6 +28,7 @@
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.controller.event.Event;
import org.jboss.portal.portlet.controller.event.EventControllerContext;
import org.jboss.portal.portlet.controller.request.PortletActionRequest;
@@ -48,7 +49,6 @@
import org.jboss.portal.portlet.spi.PortletInvocationContext;
import javax.servlet.http.Cookie;
-import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -65,7 +65,10 @@
super(PortletRequest.class, controller);
}
- ControllerResponse processResponse(PortletControllerContext context, PortletRequest
portletRequest, PortletInvocationResponse response) throws IOException,
PortletInvokerException
+ ControllerResponse processResponse(
+ PortletControllerContext context,
+ PortletRequest portletRequest,
+ PortletInvocationResponse response) throws PortletInvokerException
{
StateControllerContext stateContext = context.getStateControllerContext();
@@ -118,6 +121,39 @@
Event event = eventQueue.removeFirst();
//
+ String targetId = event.getWindowId();
+
+ //
+ PortletInfo targetPortletInfo = context.getPortletInfo(targetId);
+
+ //
+ if (targetPortletInfo == null)
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Cannot deliver event " + event +" because the
target of the event does not have a portlet info");
+ }
+
+ //
+ continue;
+ }
+
+ //
+ if (!controller.getDistributeNonConsumableEvents())
+ {
+ if
(!targetPortletInfo.getEventing().getConsumedEvents().containsKey(event.getName()))
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Cannot deliver event " + event +" because
the target of the event does not accept the event name");
+ }
+
+ //
+ continue;
+ }
+ }
+
+ //
PortletInvocationResponse eventResponse = deliverEvent(context, event,
pageState, requestProperties.getCookies());
//
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/PortletResourceRequestHandler.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -39,8 +39,6 @@
import org.jboss.portal.portlet.controller.response.ResourceResponse;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
-import java.io.IOException;
-
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -53,7 +51,7 @@
super(PortletResourceRequest.class, controller);
}
- ControllerResponse processResponse(PortletControllerContext controllerContext,
PortletResourceRequest request, PortletInvocationResponse response) throws IOException,
PortletInvokerException
+ ControllerResponse processResponse(PortletControllerContext controllerContext,
PortletResourceRequest request, PortletInvocationResponse response) throws
PortletInvokerException
{
return new ResourceResponse(response);
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/RequestHandler.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -52,7 +52,7 @@
this.controller = controller;
}
- public ControllerResponse handle(PortletControllerContext controllerContext,
ControllerRequest request) throws PortletInvokerException, IOException
+ public ControllerResponse handle(PortletControllerContext controllerContext,
ControllerRequest request) throws PortletInvokerException
{
if (!t.isInstance(request))
{
@@ -66,7 +66,7 @@
return processResponse(controllerContext, req, response);
}
- abstract ControllerResponse processResponse(PortletControllerContext
controllerContext, T request, PortletInvocationResponse response) throws IOException,
PortletInvokerException;
+ abstract ControllerResponse processResponse(PortletControllerContext
controllerContext, T request, PortletInvocationResponse response) throws
PortletInvokerException;
abstract PortletInvocationResponse invoke(PortletControllerContext controllerContext,
T controllerRequest) throws PortletInvokerException;
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/event/Event.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -72,4 +72,9 @@
{
return windowId;
}
+
+ public String toString()
+ {
+ return "Event[name=" + name + ",windowId=" + windowId +
",payload=" + payload + "]";
+ }
}
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/request/ContainerRequest.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 630 $
*/
-public class ContainerRequest extends ControllerRequest
+public abstract class ContainerRequest extends ControllerRequest
{
/** . */
Added:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/EventControllerContextSupport.java
===================================================================
---
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/EventControllerContextSupport.java
(rev 0)
+++
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/EventControllerContextSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -0,0 +1,131 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.portlet.controller;
+
+import org.jboss.portal.portlet.controller.event.EventControllerContext;
+import org.jboss.portal.portlet.controller.event.Event;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class EventControllerContextSupport implements EventControllerContext
+{
+
+ /** . */
+ private final Map<Point, List<Point>> wires = new HashMap<Point,
List<Point>>();
+
+ public List<Event> getConsumedEvents(Event producedEvent)
+ {
+ List<Point> dsts = wires.get(new Point(producedEvent.getName(),
producedEvent.getWindowId()));
+
+ //
+ List<Event> consumedEvents = new ArrayList<Event>();
+ if (dsts != null)
+ {
+ for (Point dst : dsts)
+ {
+ consumedEvents.add(new Event(dst.name, producedEvent.getPayload(),
dst.windowId));
+ }
+ }
+
+ //
+ return Collections.unmodifiableList(consumedEvents);
+ }
+
+ public void createWire(QName srcName, String srcWindowId, QName dstName, String
dstWindowId)
+ {
+ Point src = new Point(srcName, srcWindowId);
+
+ //
+ List<Point> dsts = wires.get(src);
+
+ //
+ if (dsts == null)
+ {
+ dsts = new ArrayList<Point>();
+ wires.put(src, dsts);
+ }
+
+ //
+ Point dst = new Point(dstName, dstWindowId);
+
+ if (dsts.contains(dst))
+ {
+ throw new IllegalStateException("Such a wire already exists");
+ }
+
+ //
+ dsts.add(dst);
+ }
+
+ private static class Point
+ {
+
+ final QName name;
+
+ final String windowId;
+
+ private Point(QName name, String windowId)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (windowId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.name = name;
+ this.windowId = windowId;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof Point)
+ {
+ Point that = (Point)obj;
+ return name.equals(that.name) && windowId.equals(that.windowId);
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode() + windowId.hashCode();
+ }
+ }
+}
Added:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerContextSupport.java
===================================================================
---
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerContextSupport.java
(rev 0)
+++
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerContextSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -0,0 +1,132 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.portlet.controller;
+
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.EventInvocation;
+import org.jboss.portal.portlet.invocation.ResourceInvocation;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.NoSuchPortletException;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.support.info.PortletInfoSupport;
+import org.jboss.portal.portlet.support.PortletInvokerSupport;
+import org.jboss.portal.portlet.support.PortletSupport;
+
+import javax.servlet.http.Cookie;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public final class PortletControllerContextSupport implements PortletControllerContext
+{
+
+ /** . */
+ private final StateControllerContext stateControllerContext = new
StateControllerContextImpl(this);
+
+ /** . */
+ private final EventControllerContextSupport eventControllerContext = new
EventControllerContextSupport();
+
+ /** . */
+ private final PortletInvokerSupport invoker = new PortletInvokerSupport();
+
+ public PortletInvokerSupport getInvoker()
+ {
+ return invoker;
+ }
+
+ public PortletInfo getPortletInfo(String windowId)
+ {
+ if (windowId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ PortletSupport portlet = invoker.getPortlet(windowId);
+
+ //
+ return portlet != null ? portlet.getInfo() : null;
+ }
+
+ //
+ public PortletInvocationContext createPortletInvocationContext(String windowId,
PageNavigationalState pageState)
+ {
+ if (windowId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ return new PortletInvocationContextSupport(windowId, pageState);
+ }
+
+ private PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
+ {
+ PortletInvocationContextSupport context =
(PortletInvocationContextSupport)invocation.getContext();
+
+ //
+ PortletContext target =
PortletContext.createPortletContext(context.getWindowId());
+
+ //
+ invocation.setTarget(target);
+
+ //
+ return invoker.invoke(invocation);
+ }
+
+ public PortletInvocationResponse invoke(ActionInvocation actionInvocation) throws
PortletInvokerException
+ {
+ return invoke((PortletInvocation)actionInvocation);
+ }
+
+ public PortletInvocationResponse invoke(List<Cookie> requestCookies,
EventInvocation eventInvocation) throws PortletInvokerException
+ {
+ return invoke(eventInvocation);
+ }
+
+ public PortletInvocationResponse invoke(ResourceInvocation resourceInvocation) throws
PortletInvokerException
+ {
+ return invoke((PortletInvocation)resourceInvocation);
+ }
+
+ public EventControllerContextSupport getEventControllerContext()
+ {
+ return eventControllerContext;
+ }
+
+ public StateControllerContext getStateControllerContext()
+ {
+ return stateControllerContext;
+ }
+}
Added:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java
===================================================================
---
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java
(rev 0)
+++
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -0,0 +1,229 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.portlet.controller;
+
+import org.jboss.portal.portlet.controller.request.ControllerRequest;
+import org.jboss.portal.portlet.controller.request.PortletActionRequest;
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.response.ControllerResponse;
+import org.jboss.portal.portlet.controller.response.PageUpdateResponse;
+import org.jboss.portal.portlet.OpaqueStateString;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.support.PortletSupport;
+import org.jboss.portal.portlet.support.PortletInvokerSupport;
+import org.jboss.portal.portlet.support.info.EventInfoSupport;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.response.UpdateNavigationalStateResponse;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.EventInvocation;
+import org.jboss.portal.common.util.ParameterMap;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.unit.api.pojo.annotations.Test;
+import static org.jboss.unit.api.Assert.*;
+
+import javax.xml.namespace.QName;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@Test
+public class PortletControllerTestCase
+{
+
+ /** . */
+ PortletController controller = new PortletController();
+
+ /** . */
+ PortletControllerContextSupport context = new PortletControllerContextSupport();
+
+ /** . */
+ PortletInvokerSupport invoker = context.getInvoker();
+
+ @Test
+ public void testActionReturnsUpdateNavigationalState() throws PortletInvokerException
+ {
+ PortletSupport fooPortlet = invoker.addPortlet("foo");
+ fooPortlet.addHandler(new PortletSupport.ActionHandler()
+ {
+ protected PortletInvocationResponse invoke(ActionInvocation action) throws
PortletInvokerException
+ {
+ return new UpdateNavigationalStateResponse();
+ }
+ });
+
+ ControllerRequest request = new PortletActionRequest(
+ "foo",
+ new OpaqueStateString(""),
+ new ParameterMap(),
+ new WindowNavigationalState(),
+ context.getStateControllerContext().createPageState(false)
+ );
+
+ ControllerResponse response = controller.process(context, request);
+
+ PageUpdateResponse pageUpdate = assertInstanceOf(response,
PageUpdateResponse.class);
+
+ PageNavigationalState pageNS = assertNotNull(pageUpdate.getPageState());
+
+ assertEquals(Tools.toSet("foo"), pageNS.getWindowIds());
+
+ }
+
+ @Test
+ public void testActionThrowsPortletInvokerException() throws PortletInvokerException
+ {
+
+ final PortletInvokerException e = new PortletInvokerException();
+
+ PortletSupport fooPortlet = invoker.addPortlet("foo");
+ fooPortlet.addHandler(new PortletSupport.ActionHandler()
+ {
+ protected PortletInvocationResponse invoke(ActionInvocation action) throws
PortletInvokerException
+ {
+ throw e;
+ }
+ });
+
+ //
+ ControllerRequest request = new PortletActionRequest(
+ "foo",
+ new OpaqueStateString(""),
+ new ParameterMap(),
+ new WindowNavigationalState(),
+ context.getStateControllerContext().createPageState(false)
+ );
+
+ try
+ {
+ controller.process(context, request);
+ fail();
+ }
+ catch (PortletInvokerException ex)
+ {
+ assertSame(e, ex);
+ }
+
+ }
+
+ @Test
+ public void testProcessActionProducedEventIsDistributed() throws
PortletInvokerException
+ {
+ QName srcName = new QName("juu", "foo");
+ QName dstName = new QName("juu", "bar");
+
+ //
+ PortletSupport fooPortlet = invoker.addPortlet("foo");
+ PortletSupport barPortlet = invoker.addPortlet("bar");
+
+ //
+ EventProducerAction fooEventProducer = new EventProducerAction(srcName);
+ NoOpEventProcessor fooEventConsumer = new NoOpEventProcessor();
+
+ // Create wire
+ context.getEventControllerContext().createWire(srcName, "foo", dstName,
"bar");
+
+ //
+ ControllerRequest request = new PortletActionRequest(
+ "foo",
+ new OpaqueStateString(""),
+ new ParameterMap(),
+ new WindowNavigationalState(),
+ context.getStateControllerContext().createPageState(false)
+ );
+
+ //
+ controller.setDistributeNonConsumableEvents(true);
+ fooPortlet.addHandler(fooEventProducer);
+ barPortlet.addHandler(fooEventConsumer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(1);
+ barPortlet.assertInvocationCountIs(1);
+
+ //
+ controller.setDistributeNonConsumableEvents(false);
+ fooPortlet.addHandler(fooEventProducer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(2);
+ barPortlet.assertInvocationCountIs(1);
+
+ //
+ barPortlet.getInfo().getEventing().addConsumedEvent(new
EventInfoSupport(dstName));
+
+ //
+ controller.setDistributeNonConsumableEvents(true);
+ fooPortlet.addHandler(fooEventProducer);
+ barPortlet.addHandler(fooEventConsumer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(3);
+ barPortlet.assertInvocationCountIs(2);
+
+ //
+ controller.setDistributeNonConsumableEvents(false);
+ fooPortlet.addHandler(fooEventProducer);
+ barPortlet.addHandler(fooEventConsumer);
+ controller.process(context, request);
+ fooPortlet.assertInvocationCountIs(4);
+ barPortlet.assertInvocationCountIs(3);
+ }
+
+ private static class EventProducerAction extends PortletSupport.ActionHandler
+ {
+
+ /** . */
+ private final QName name;
+
+ private EventProducerAction(QName name)
+ {
+ this.name = name;
+ }
+
+ protected PortletInvocationResponse invoke(ActionInvocation action) throws
PortletInvokerException
+ {
+ UpdateNavigationalStateResponse update = new UpdateNavigationalStateResponse();
+ update.queueEvent(new UpdateNavigationalStateResponse.Event(name, null));
+ return update;
+ }
+ }
+
+ private static class NoOpEventProcessor extends PortletSupport.EventHandler
+ {
+
+ /** . */
+ private QName name;
+
+ /** . */
+ private Serializable payload;
+
+ protected PortletInvocationResponse invoke(EventInvocation action) throws
PortletInvokerException
+ {
+ name = action.getName();
+ payload = action.getPayload();
+
+ //
+ return new UpdateNavigationalStateResponse();
+ }
+ }
+}
Added:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletInvocationContextSupport.java
===================================================================
---
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletInvocationContextSupport.java
(rev 0)
+++
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletInvocationContextSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.portlet.controller;
+
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PortletInvocationContextSupport extends
org.jboss.portal.portlet.support.spi.PortletInvocationContextSupport
+{
+
+ /** . */
+ private final String windowId;
+
+ /** . */
+ private final PageNavigationalState pageNavigationalState;
+
+ public PortletInvocationContextSupport(String windowId, PageNavigationalState
pageNavigationalState)
+ {
+ this.windowId = windowId;
+ this.pageNavigationalState = pageNavigationalState;
+ }
+
+ public String getWindowId()
+ {
+ return windowId;
+ }
+
+ public PageNavigationalState getPageNavigationalState()
+ {
+ return pageNavigationalState;
+ }
+}
Added: modules/portlet/trunk/controller/src/test/resources/local-jboss-unit.xml
===================================================================
--- modules/portlet/trunk/controller/src/test/resources/local-jboss-unit.xml
(rev 0)
+++ modules/portlet/trunk/controller/src/test/resources/local-jboss-unit.xml 2008-02-18
11:21:08 UTC (rev 10014)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jboss-unit
+ xmlns="urn:jboss:jboss-unit:1.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:jboss-unit:1.0 jboss-unit_1_0.xsd">
+ <pojo>
+ <test>
+ <class
name="org.jboss.portal.portlet.controller.PortletControllerTestCase"/>
+ </test>
+ </pojo>
+</jboss-unit>
Modified:
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java
===================================================================
---
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -25,8 +25,8 @@
import org.jboss.portal.portlet.federation.FederatedPortletInvoker;
import org.jboss.portal.portlet.federation.FederatingPortletInvoker;
import org.jboss.portal.portlet.federation.impl.FederatingPortletInvokerService;
-import org.jboss.portal.test.portlet.state.PortletInvokerSupport;
-import org.jboss.portal.test.portlet.state.PortletSupport;
+import org.jboss.portal.portlet.support.PortletInvokerSupport;
+import org.jboss.portal.portlet.support.PortletSupport;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletContext;
@@ -71,14 +71,13 @@
{
federatingInvoker = new FederatingPortletInvokerService();
federatedInvoker = new PortletInvokerSupport();
- federatedPortlet = new PortletSupport();
// Configure
- PortletInfoSupport fooInfo = federatedPortlet.getInfoSupport();
+ PortletInfoSupport fooInfo = new PortletInfoSupport();
fooInfo.getMeta().setDisplayName("FooPortlet");
// Wire
- federatedInvoker.addInternalPortlet("MyPortlet", federatedPortlet);
+ federatedPortlet = federatedInvoker.addPortlet("MyPortlet", fooInfo);
federatingInvoker.registerInvoker("foo", federatedInvoker);
// Basic setup
Modified:
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java
===================================================================
---
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/federation/src/test/java/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -23,7 +23,7 @@
package org.jboss.portal.test.portlet.federation;
import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.test.portlet.state.PortletInvokerSupport;
+import org.jboss.portal.portlet.support.PortletInvokerSupport;
import org.jboss.portal.portlet.federation.FederatingPortletInvoker;
import org.jboss.portal.portlet.federation.FederatedPortletInvoker;
import org.jboss.portal.portlet.federation.impl.FederatingPortletInvokerService;
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortlet.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortlet.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortlet.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -37,12 +37,12 @@
private final PortletContext context;
/** . */
- private final Portlet delegate;
+ private final Portlet next;
- public ConsumerPortlet(PortletContext context, Portlet delegate)
+ public ConsumerPortlet(PortletContext context, Portlet next)
{
this.context = context;
- this.delegate = delegate;
+ this.next = next;
}
public PortletContext getContext()
@@ -52,11 +52,16 @@
public PortletInfo getInfo()
{
- return delegate.getInfo();
+ return next.getInfo();
}
public boolean isRemote()
{
- return delegate.isRemote();
+ return next.isRemote();
}
+
+ public Portlet getNext()
+ {
+ return next;
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortletInvoker.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortletInvoker.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/consumer/ConsumerPortletInvoker.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -23,6 +23,7 @@
package org.jboss.portal.portlet.state.consumer;
import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.common.FixMe;
import org.jboss.portal.portlet.InvalidPortletIdException;
import org.jboss.portal.portlet.NoSuchPortletException;
import org.jboss.portal.portlet.Portlet;
@@ -38,6 +39,7 @@
import org.jboss.portal.portlet.state.NoSuchStateException;
import org.jboss.portal.portlet.state.PropertyChange;
import org.jboss.portal.portlet.state.PropertyMap;
+import org.jboss.portal.portlet.state.DestroyCloneFailure;
import java.util.ArrayList;
import java.util.List;
@@ -103,11 +105,21 @@
return popCtx.getId();
}
+ /**
+ * Returns the producer.
+ *
+ * @return the producer
+ */
public PortletInvoker getProducer()
{
return producer;
}
+ /**
+ * Sets the producer.
+ *
+ * @param producer the producer
+ */
public void setProducer(PortletInvoker producer)
{
this.producer = producer;
@@ -118,16 +130,16 @@
this.persistenceManager = persistenceManager;
}
- public Set getPortlets() throws PortletInvokerException
+
+ public Set<Portlet> getPortlets() throws PortletInvokerException
{
+ // We don't need proxies here because we return the list of offered portlets
return producer.getPortlets();
}
public Portlet getPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
{
- ConsumerContext cpc = getConsumerContext(portletContext);
- Portlet delegate = producer.getPortlet(cpc.portletContext);
- return new ConsumerPortlet(portletContext, delegate);
+ return getConsumerContext(portletContext).getPortlet();
}
public PortletInvocationResponse invoke(PortletInvocation invocation) throws
IllegalArgumentException, PortletInvokerException
@@ -147,7 +159,7 @@
try
{
- invocation.setTarget(consumerContext.portletContext);
+ invocation.setTarget(consumerContext.producerPortletContext);
invocation.setInstanceContext(pictx);
//
@@ -214,7 +226,7 @@
ConsumerContext consumerContext = getConsumerContext(portletContext);
//
- PortletContext clonedContext =
producer.createClone(consumerContext.portletContext);
+ PortletContext clonedContext =
producer.createClone(consumerContext.producerPortletContext);
byte[] state = clonedContext.getState();
if (state != null)
@@ -229,18 +241,18 @@
}
}
- public List destroyClones(List portletContexts) throws IllegalArgumentException,
PortletInvokerException, UnsupportedOperationException
+ public List<DestroyCloneFailure> destroyClones(List<PortletContext>
portletContexts) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
{
if (portletContexts == null)
{
throw new IllegalArgumentException();
}
- portletContexts = new ArrayList(portletContexts);
+ portletContexts = new ArrayList<PortletContext>(portletContexts);
for (int i = 0; i < portletContexts.size(); i++)
{
- PortletContext portletContext = (PortletContext)portletContexts.get(i);
+ PortletContext portletContext = portletContexts.get(i);
ConsumerContext consumerContext = getConsumerContext(portletContext);
- portletContexts.set(i, consumerContext.portletContext);
+ portletContexts.set(i, consumerContext.producerPortletContext);
if (consumerContext.stateId != null)
{
try
@@ -259,8 +271,9 @@
}
//
- List failures = producer.destroyClones(portletContexts);
+ List<DestroyCloneFailure> failures =
producer.destroyClones(portletContexts);
+ // Probably should wrap the portlet context here ????
// for (Iterator i = failures.iterator(); i.hasNext();)
// {
// DestroyCloneFailure failure = (DestroyCloneFailure)i.next();
@@ -274,13 +287,13 @@
public PropertyMap getProperties(PortletContext portletContext, Set keys) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
{
ConsumerContext consumerContext = getConsumerContext(portletContext);
- return producer.getProperties(consumerContext.portletContext, keys);
+ return producer.getProperties(consumerContext.producerPortletContext, keys);
}
public PropertyMap getProperties(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
{
ConsumerContext consumerContext = getConsumerContext(portletContext);
- return producer.getProperties(consumerContext.portletContext);
+ return producer.getProperties(consumerContext.producerPortletContext);
}
public PortletContext setProperties(PortletContext portletContext, PropertyChange[]
changes) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
@@ -288,7 +301,7 @@
ConsumerContext consumerContext = getConsumerContext(portletContext);
//
- PortletContext updatedPortletContext =
producer.setProperties(consumerContext.portletContext, changes);
+ PortletContext updatedPortletContext =
producer.setProperties(consumerContext.producerPortletContext, changes);
byte[] state = updatedPortletContext.getState();
if (state != null)
@@ -366,7 +379,7 @@
}
}
- private ConsumerContext getConsumerContext(PortletContext portletContext) throws
IllegalArgumentException, NoSuchPortletException, InvalidPortletIdException
+ private ConsumerContext getConsumerContext(PortletContext portletContext) throws
IllegalArgumentException, InvalidPortletIdException
{
if (portletContext == null)
{
@@ -383,7 +396,7 @@
try
{
ConsumerStateContext stateCtx = persistenceManager.loadState(stateId);
- return new ConsumerContext(stateId, stateCtx.getPortletId(),
stateCtx.getBytes());
+ return new ConsumerContext(portletContext,
PortletContext.createStatefulPortletContext(stateCtx.getPortletId(), stateCtx.getBytes()),
stateId);
}
catch (NoSuchStateException e)
{
@@ -396,27 +409,58 @@
}
else
{
- return new ConsumerContext(portletContext, null);
+ return new ConsumerContext(portletContext, portletContext, null);
}
}
+ /**
+ * A context which defines how the consumer see the producer portlet.
+ */
private class ConsumerContext
{
- private final PortletContext portletContext;
+ /** . */
+ private final PortletContext consumerPortletContext;
- /** . */
+ /** The target portlet context. */
+ private final PortletContext producerPortletContext;
+
+ /** The id in the store. */
private final String stateId;
- public ConsumerContext(PortletContext portletContext, String stateId)
+ /** The lazy created portlet. */
+ private Portlet portlet;
+
+ public ConsumerContext(
+ PortletContext consumerPortletContext,
+ PortletContext producerPortletContext,
+ String stateId)
{
- this.portletContext = portletContext;
+ this.consumerPortletContext = consumerPortletContext;
+ this.producerPortletContext = producerPortletContext;
this.stateId = stateId;
}
- public ConsumerContext(String stateId, String id, byte[] state)
+ public Portlet getPortlet() throws PortletInvokerException
{
- this(PortletContext.createStatefulPortletContext(id, state), stateId);
+ if (portlet == null)
+ {
+ Portlet producerPortlet = producer.getPortlet(producerPortletContext);
+
+ //
+ if (stateId == null)
+ {
+ portlet = producerPortlet;
+ }
+ else
+ {
+ portlet = new ConsumerPortlet(consumerPortletContext, producerPortlet);
+ }
+ }
+
+ //
+ return portlet;
}
+
}
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortlet.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortlet.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortlet.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -37,12 +37,12 @@
private final PortletContext context;
/** . */
- private final Portlet delegate;
+ private final Portlet next;
- public ProducerPortlet(PortletContext context, Portlet delegate)
+ public ProducerPortlet(PortletContext context, Portlet next)
{
this.context = context;
- this.delegate = delegate;
+ this.next = next;
}
public PortletContext getContext()
@@ -52,16 +52,21 @@
public PortletInfo getInfo()
{
- return delegate.getInfo();
+ return next.getInfo();
}
public boolean isRemote()
{
- return delegate.isRemote();
+ return next.isRemote();
}
public String toString()
{
- return "ProducerPortlet[" + context + ",delegate=" + delegate +
"]";
+ return "ProducerPortlet[" + context + ",delegate=" + next +
"]";
}
+
+ public Portlet getNext()
+ {
+ return next;
+ }
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/state/producer/ProducerPortletInvoker.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -55,7 +55,6 @@
import org.apache.log4j.Logger;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
@@ -129,7 +128,7 @@
this.stateConverter = stateConverter;
}
- public Set getPortlets() throws PortletInvokerException
+ public Set<Portlet> getPortlets() throws PortletInvokerException
{
return portletInvoker.getPortlets();
}
@@ -140,10 +139,16 @@
{
throw new IllegalArgumentException("No null portlet id accepted");
}
+
+ //
String portletId = portletContext.getId();
+
+ //
if (CONSUMER_CLONE_ID.equals(portletId))
{
byte[] state = portletContext.getState();
+
+ //
if (state != null)
{
try
@@ -405,7 +410,7 @@
}
}
- public List destroyClones(List portletContexts) throws IllegalArgumentException,
PortletInvokerException, UnsupportedOperationException
+ public List<DestroyCloneFailure> destroyClones(List<PortletContext>
portletContexts) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
{
if (portletContexts == null)
{
@@ -413,11 +418,9 @@
}
//
- List result = new ArrayList();
- for (Iterator i = portletContexts.iterator(); i.hasNext();)
+ List<DestroyCloneFailure> result = new
ArrayList<DestroyCloneFailure>();
+ for (PortletContext portletContext : portletContexts)
{
- PortletContext portletContext = (PortletContext)i.next();
-
// We only take care of producer hosted state
if (!(portletContext instanceof StatefulPortletContext))
{
@@ -519,9 +522,8 @@
{
throw new IllegalArgumentException("No null changes accepted");
}
- for (int i = 0; i < changes.length; i++)
+ for (PropertyChange change : changes)
{
- PropertyChange change = changes[i];
if (change == null)
{
throw new IllegalArgumentException("No null change accepted");
@@ -558,9 +560,8 @@
PropertyMap properties = new SimplePropertyMap(statefulContext.getProperties());
// Clone argument
- for (int i = 0; i < changes.length; i++)
+ for (PropertyChange change : changes)
{
- PropertyChange change = changes[i];
String key = change.getKey();
int type = change.getType();
@@ -640,10 +641,9 @@
PreferencesInfo prefs = portlet.getInfo().getPreferences();
// Collect missing or read only properties from the referenced portlet
- Set keys = new HashSet();
- for (Iterator i = prefs.getKeys().iterator(); i.hasNext();)
+ Set<String> keys = new HashSet<String>();
+ for (String key : prefs.getKeys())
{
- String key = (String)i.next();
PreferenceInfo pref = prefs.getPreference(key);
if (Boolean.TRUE.equals(pref.isReadOnly()) ||
!props.keySet().contains(pref.getKey()))
{
@@ -654,12 +654,11 @@
// Get the missing or read only properties from the referenced portlet properties
// and add them to the actual state
PropertyMap refPreferencesInfo = portletInvoker.getProperties(portletContext,
keys);
- for (Iterator i = refPreferencesInfo.entrySet().iterator();i.hasNext();)
+ for (Map.Entry<String, Value> entry : refPreferencesInfo.entrySet())
{
- Map.Entry entry = (Map.Entry)i.next();
- String key = (String)entry.getKey();
- Value value = (Value)entry.getValue();
- props.setProperty(key, (Value)value.clone());
+ String key = entry.getKey();
+ Value value = entry.getValue();
+ props.setProperty(key, value.clone());
}
}
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventInfoSupport.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventInfoSupport.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventInfoSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -53,6 +53,15 @@
/** . */
private List<QName> aliases;
+ public EventInfoSupport(QName name)
+ {
+ this.name = name;
+ this.type = null;
+ this.aliases = new ArrayList<QName>();
+ this.displayName = new LocalizedString("Event " + name);
+ this.description = new LocalizedString("Description of event " + name);
+ }
+
public EventInfoSupport(QName name, TypeInfoSupport type)
{
this.name = name;
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventingInfoSupport.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventingInfoSupport.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/support/info/EventingInfoSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -55,7 +55,7 @@
public void addConsumedEvent(EventInfoSupport event)
{
- producedEvents.put(event.getName(), event);
+ consumedEvents.put(event.getName(), event);
}
public Map<QName, EventInfoSupport> getProducedEvents()
Copied:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletInvokerSupport.java
(from rev 10000,
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletInvokerSupport.java)
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletInvokerSupport.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletInvokerSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -0,0 +1,214 @@
+/******************************************************************************
+ * 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.portlet.support;
+
+import org.jboss.portal.portlet.InvalidPortletIdException;
+import org.jboss.portal.portlet.NoSuchPortletException;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.PortletInvoker;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.support.info.PortletInfoSupport;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.state.PropertyChange;
+import org.jboss.portal.portlet.state.PropertyMap;
+import org.jboss.portal.portlet.state.SimplePropertyMap;
+import org.jboss.portal.portlet.state.DestroyCloneFailure;
+import org.jboss.portal.common.value.Value;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6712 $
+ */
+public class PortletInvokerSupport implements PortletInvoker
+{
+
+ /** . */
+ private Map<String, PortletSupport> portlets;
+
+ public PortletInvokerSupport()
+ {
+ this.portlets = new HashMap<String, PortletSupport>();
+ }
+
+ public void setValid(String portletId, boolean valid)
+ {
+ getPortlet(portletId).valid = valid;
+ }
+
+ public PortletSupport addPortlet(String portletId)
+ {
+ return addPortlet(portletId, new PortletInfoSupport());
+ }
+
+ public PortletSupport addPortlet(String portletId, PortletInfoSupport info)
+ {
+ if (portletId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (info == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ PortletSupport portlet = new PortletSupport(portletId, info);
+
+ //
+ if (portlets.put(portletId, portlet) != null)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ return portlet;
+ }
+
+ public PortletInvokerSupport removePortlet(String portletId)
+ {
+ if (portlets.remove(portletId) == null)
+ {
+ throw new IllegalStateException();
+ }
+ return this;
+ }
+
+ /**
+ * Returns a portlet or null if it is not found. The portlet is returned whether it is
tagged as valid or not.
+ * This method is not equivalent to the
<code>getPortlet(PortletContext)</code> method which returns a portlet
+ * only if that one is valid. It should be used for configuration purposes.
+ *
+ * @param portletId the portlet id
+ * @return the portlet
+ * @throws IllegalArgumentException if the portlet id is null
+ */
+ public PortletSupport getPortlet(String portletId) throws IllegalArgumentException
+ {
+ if (portletId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ return portlets.get(portletId);
+ }
+
+ public Set<Portlet> getPortlets()
+ {
+ return new HashSet<Portlet>(portlets.values());
+ }
+
+ public Portlet getPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
+ {
+ return internalGetPortlet(portletContext);
+ }
+
+ public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
+ {
+ PortletContext portletContext = invocation.getTarget();
+ PortletSupport portlet = internalGetPortlet(portletContext);
+ return portlet.invoke(invocation);
+ }
+
+ private PortletSupport internalGetPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
+ {
+ if (portletContext == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ String portletId = portletContext.getId();
+
+ //
+ PortletSupport portlet = portlets.get(portletId);
+
+ //
+ if (portlet == null)
+ {
+ throw new NoSuchPortletException(portletId);
+ }
+
+ //
+ if (!portlet.valid)
+ {
+ throw new InvalidPortletIdException(portletId);
+ }
+
+ //
+ return portlet;
+ }
+
+ public PropertyMap getProperties(PortletContext portletContext, Set<String>
keys) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
+ {
+ PortletSupport internalPortlet = internalGetPortlet(portletContext);
+ PropertyMap props = new SimplePropertyMap();
+ for (String key : keys)
+ {
+ Value value = internalPortlet.state.get(key);
+ if (value != null)
+ {
+ props.put(key, value.clone());
+ }
+ }
+ return props;
+ }
+
+ public PropertyMap getProperties(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+ {
+ PortletSupport internalPortlet = internalGetPortlet(portletContext);
+ PropertyMap props = new SimplePropertyMap();
+ for (String key: internalPortlet.state.keySet())
+ {
+ Value value = internalPortlet.state.get(key);
+ if (value != null)
+ {
+ props.put(key, value.clone());
+ }
+ }
+ return props;
+ }
+
+ public PortletContext createClone(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<DestroyCloneFailure> destroyClones(List<PortletContext>
portletContexts) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public PortletContext setProperties(PortletContext portletContext, PropertyChange[]
changes) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletInvokerSupport.java
___________________________________________________________________
Name: svn:executable
+
Copied:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletSupport.java
(from rev 10000,
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletSupport.java)
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletSupport.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -0,0 +1,204 @@
+/******************************************************************************
+ * 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.portlet.support;
+
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.support.info.PortletInfoSupport;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.EventInvocation;
+import org.jboss.portal.portlet.invocation.RenderInvocation;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.common.value.Value;
+import static org.jboss.unit.api.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 6116 $
+ */
+public final class PortletSupport implements Portlet
+{
+
+ /** . */
+ private final PortletContext portletContext;
+
+ /** . */
+ boolean valid;
+
+ /** . */
+ final Map<String, Value> state;
+
+ /** . */
+ private int invocationCount;
+
+ /** . */
+ private final ArrayList<InvocationHandler> handlers = new
ArrayList<InvocationHandler>();
+
+ /** . */
+ private final PortletInfoSupport info;
+
+ public PortletSupport(String portletId, PortletInfoSupport info)
+ {
+ if (portletId == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (info == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.portletContext = PortletContext.createPortletContext(portletId);
+ this.valid = true;
+ this.state = new HashMap<String, Value>();
+ this.info = info;
+ }
+
+ public void addPreference(String key, Value value)
+ {
+ info.getPreferences().addPreference(key);
+ state.put(key, value);
+ }
+
+ public void addPreference(String key, Value value, Boolean readOnly)
+ {
+ info.getPreferences().addPreference(key, readOnly);
+ state.put(key, value);
+ }
+
+ public int getInvocationCount()
+ {
+ return invocationCount;
+ }
+
+ public void addHandler(InvocationHandler handler)
+ {
+ handlers.add(handler);
+ }
+
+ public void assertInvocationCountIs(int expectedInvocationCount)
+ {
+ assertEquals(expectedInvocationCount, invocationCount);
+ }
+
+ public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
+ {
+ assertNotNull(invocation);
+
+ //
+ if (invocationCount == handlers.size())
+ {
+ throw new AssertionError();
+ }
+
+ //
+ InvocationHandler handler = handlers.get(invocationCount++);
+
+ //
+ return handler.invoke(invocation);
+ }
+
+ public PortletContext getContext()
+ {
+ return portletContext;
+ }
+
+ public PortletInfoSupport getInfo()
+ {
+ return info;
+ }
+
+ public boolean isRemote()
+ {
+ return false;
+ }
+
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ public static class InvocationHandler
+ {
+ protected PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
+ {
+ throw new PortletInvokerException("No implementations");
+ }
+ }
+
+ public static abstract class ActionHandler extends InvocationHandler
+ {
+ protected final PortletInvocationResponse invoke(PortletInvocation invocation)
throws PortletInvokerException
+ {
+ if (invocation instanceof ActionInvocation)
+ {
+ return invoke((ActionInvocation)invocation);
+ }
+
+ //
+ throw new AssertionError();
+ }
+
+ protected abstract PortletInvocationResponse invoke(ActionInvocation action) throws
PortletInvokerException;
+ }
+
+ public static abstract class EventHandler extends InvocationHandler
+ {
+ protected final PortletInvocationResponse invoke(PortletInvocation invocation)
throws PortletInvokerException
+ {
+ if (invocation instanceof EventInvocation)
+ {
+ return invoke((EventInvocation)invocation);
+ }
+
+ //
+ throw new AssertionError();
+ }
+
+ protected abstract PortletInvocationResponse invoke(EventInvocation action) throws
PortletInvokerException;
+ }
+
+ public static abstract class RenderHandler extends InvocationHandler
+ {
+ protected final PortletInvocationResponse invoke(PortletInvocation invocation)
throws PortletInvokerException
+ {
+ if (invocation instanceof RenderInvocation)
+ {
+ return invoke((RenderInvocation)invocation);
+ }
+
+ //
+ throw new AssertionError();
+ }
+
+ protected abstract PortletInvocationResponse invoke(RenderInvocation action) throws
PortletInvokerException;
+ }
+}
Property changes on:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/portlet/support/PortletSupport.java
___________________________________________________________________
Name: svn:executable
+
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/AbstractStatefulPortletInvokerTestCase.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -32,6 +32,7 @@
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.portlet.support.info.PortletInfoSupport;
+import org.jboss.portal.portlet.support.PortletSupport;
import org.jboss.portal.portlet.info.MetaInfo;
import org.jboss.portal.portlet.invocation.ActionInvocation;
import org.jboss.portal.portlet.invocation.PortletInvocation;
@@ -72,6 +73,11 @@
/**
*
*/
+ protected abstract PortletSupport getPortletSupport(PortletContext portletRef) throws
PortletInvokerException;
+
+ /**
+ *
+ */
protected abstract Portlet getPortlet(PortletContext portletRef) throws
PortletInvokerException;
/**
@@ -82,7 +88,7 @@
/**
*
*/
- protected abstract PortletContext createPOPRef(PortletSupport portletSupport) throws
PortletInvokerException;
+ protected abstract PortletContext createPOPRef(PortletInfoSupport portletInfo) throws
PortletInvokerException;
/**
*
@@ -202,15 +208,6 @@
/**
*
*/
- protected final PortletContext createPOPRef(PortletInfoSupport portletInfo) throws
PortletInvokerException
- {
- PortletSupport portletSupport = new PortletSupport(portletInfo);
- return createPOPRef(portletSupport);
- }
-
- /**
- *
- */
protected final PortletContext createLocalCCPRef() throws Exception
{
PortletContext popCtx = createPOPRef();
@@ -796,7 +793,8 @@
public void invokeCloneBeforeWriteWithUpdate(boolean pop) throws Exception
{
PortletInfoSupport info = new PortletInfoSupport();
- PortletSupport portletSupport = new PortletSupport(info)
+
+ PortletSupport.InvocationHandler handler = new PortletSupport.InvocationHandler()
{
public PortletInvocationResponse invoke(PortletInvocation invocation)
{
@@ -809,13 +807,17 @@
PortletContext ctx;
if (pop)
{
- PortletContext popCtx = createPOPRef(portletSupport);
+ PortletContext popCtx = createPOPRef(info);
+ PortletSupport portletSupport = getPortletSupport(popCtx);
+ portletSupport.addHandler(handler);
addPreference(popCtx, "abc", new StringValue("def"));
ctx = popCtx;
}
else
{
- PortletContext popCtx = createPOPRef(portletSupport);
+ PortletContext popCtx = createPOPRef(info);
+ PortletSupport portletSupport = getPortletSupport(popCtx);
+ portletSupport.addHandler(handler);
addPreference(popCtx, "abc", new StringValue("def"));
PortletContext ccpCtx = createClone(popCtx);
ctx = ccpCtx;
@@ -848,7 +850,8 @@
final Boolean[] ise = {Boolean.FALSE};
PortletInfoSupport info = new PortletInfoSupport();
- PortletSupport portletSupport = new PortletSupport(info)
+
+ PortletSupport.InvocationHandler handler = new PortletSupport.InvocationHandler()
{
public PortletInvocationResponse invoke(PortletInvocation invocation)
{
@@ -865,7 +868,11 @@
}
}
};
- PortletContext popCtx = createPOPRef(portletSupport);
+
+ //
+ PortletContext popCtx = createPOPRef(info);
+ PortletSupport portletSupport = getPortletSupport(popCtx);
+ portletSupport.addHandler(handler);
addPreference(popCtx, "abc", new StringValue("def"));
//
@@ -882,7 +889,7 @@
public void testInvokeReadWriteWithUpdate() throws Exception
{
PortletInfoSupport info = new PortletInfoSupport();
- PortletSupport portletSupport = new PortletSupport(info)
+ PortletSupport.InvocationHandler handler = new PortletSupport.InvocationHandler()
{
public PortletInvocationResponse invoke(PortletInvocation invocation)
{
@@ -891,7 +898,9 @@
return null;
}
};
- PortletContext popCtx = createPOPRef(portletSupport);
+ PortletContext popCtx = createPOPRef(info);
+ PortletSupport portletSupport = getPortletSupport(popCtx);
+ portletSupport.addHandler(handler);
addPreference(popCtx, "abc", new StringValue("def"));
//
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ConsumerStatefulPortletInvokerTestCase.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -25,8 +25,9 @@
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.NoSuchPortletException;
import org.jboss.portal.portlet.support.info.PortletInfoSupport;
+import org.jboss.portal.portlet.support.PortletInvokerSupport;
+import org.jboss.portal.portlet.support.PortletSupport;
import org.jboss.portal.portlet.impl.state.StateManagementPolicyService;
import org.jboss.portal.portlet.impl.state.StateConverterV0;
import org.jboss.portal.portlet.impl.state.consumer.ConsumerPersistenceManagerService;
@@ -39,7 +40,9 @@
import org.jboss.portal.portlet.state.PropertyMap;
import org.jboss.portal.portlet.state.StateConverter;
import org.jboss.portal.portlet.state.consumer.ConsumerPortletInvoker;
+import org.jboss.portal.portlet.state.consumer.ConsumerPortlet;
import org.jboss.portal.portlet.state.producer.ProducerPortletInvoker;
+import org.jboss.portal.portlet.state.producer.ProducerPortlet;
import org.jboss.portal.common.value.Value;
import static org.jboss.unit.api.Assert.*;
@@ -107,29 +110,49 @@
consumer.setProducer(producer);
}
+ protected PortletSupport getPortletSupport(PortletContext portletRef) throws
PortletInvokerException
+ {
+ Portlet portlet = consumer.getPortlet(portletRef);
+
+ //
+ if (portlet instanceof ConsumerPortlet)
+ {
+ portlet = ((ConsumerPortlet)portlet).getNext();
+ }
+
+ //
+ if (portlet instanceof ProducerPortlet)
+ {
+ portlet = ((ProducerPortlet)portlet).getNext();
+ }
+
+ //
+ return (PortletSupport)portlet;
+ }
+
protected Portlet getPortlet(PortletContext portletRef) throws
PortletInvokerException
{
return consumer.getPortlet(portletRef);
}
- protected PortletContext createPOPRef(PortletSupport portletSupport) throws
PortletInvokerException
+ protected PortletContext createPOPRef(PortletInfoSupport portletSupport) throws
PortletInvokerException
{
- container.addInternalPortlet("PortletId", portletSupport);
+ container.addPortlet("PortletId", portletSupport);
Portlet portlet = getSinglePOP();
return portlet.getContext();
}
protected PortletContext createNonExistingPOPRef() throws PortletInvokerException
{
- container.addInternalPortlet("NonExistingPortletId", new
PortletInfoSupport());
+ container.addPortlet("NonExistingPortletId", new PortletInfoSupport());
PortletContext popContext = getSinglePOP().getContext();
- container.removeInternalPortlet("NonExistingPortletId");
+ container.removePortlet("NonExistingPortletId");
return popContext;
}
protected PortletContext createInvalidPOPRef() throws PortletInvokerException
{
- container.addInternalPortlet("InvalidPortletId", new
PortletInfoSupport());
+ container.addPortlet("InvalidPortletId", new PortletInfoSupport());
PortletContext popContext = getSinglePOP().getContext();
container.setValid("InvalidPortletId", false);
return popContext;
@@ -145,12 +168,12 @@
protected void addPreference(PortletContext popRef, String key, Value defaultValue)
{
- container.getInternalPortlet(popRef.getId()).addPreference(key, defaultValue);
+ container.getPortlet(popRef.getId()).addPreference(key, defaultValue);
}
protected void addPreference(PortletContext popRef, String key, Value defaultValue,
Boolean readOnly)
{
- container.getInternalPortlet(popRef.getId()).addPreference(key, defaultValue,
readOnly);
+ container.getPortlet(popRef.getId()).addPreference(key, defaultValue, readOnly);
}
protected void destroyClone(PortletContext portletRef) throws Exception
@@ -224,7 +247,7 @@
private Portlet getSinglePOP() throws PortletInvokerException
{
- Set portlets = producer.getPortlets();
+ Set portlets = consumer.getPortlets();
assertNotNull(portlets);
assertEquals(1, portlets.size());
return (Portlet)portlets.iterator().next();
Deleted:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletInvokerSupport.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletInvokerSupport.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletInvokerSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -1,258 +0,0 @@
-/******************************************************************************
- * 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.portlet.state;
-
-import org.jboss.portal.portlet.InvalidPortletIdException;
-import org.jboss.portal.portlet.NoSuchPortletException;
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletContext;
-import org.jboss.portal.portlet.PortletInvoker;
-import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.support.info.PortletInfoSupport;
-import org.jboss.portal.portlet.info.PortletInfo;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.state.PropertyChange;
-import org.jboss.portal.portlet.state.PropertyMap;
-import org.jboss.portal.portlet.state.SimplePropertyMap;
-import org.jboss.portal.portlet.state.DestroyCloneFailure;
-import org.jboss.portal.common.value.Value;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 6712 $
- */
-public class PortletInvokerSupport implements PortletInvoker
-{
-
- /** . */
- private Map<String, Portlet> portlets;
-
- public PortletInvokerSupport()
- {
- this.portlets = new HashMap<String, Portlet>();
- }
-
- public void setValid(String portletId, boolean valid)
- {
- getInternalPortlet(portletId).valid = valid;
- }
-
- public InternalPortlet addInternalPortlet(String portletId, PortletInfoSupport info)
- {
- return addInternalPortlet(portletId, new PortletSupport(info));
- }
-
- public InternalPortlet addInternalPortlet(String portletId, PortletSupport support)
- {
- if (portletId == null)
- {
- throw new IllegalArgumentException();
- }
- if (support == null)
- {
- throw new IllegalArgumentException();
- }
- InternalPortlet portlet = new InternalPortlet(portletId, support);
- if (portlets.put(portletId, portlet) != null)
- {
- throw new IllegalStateException();
- }
- return portlet;
- }
-
- public PortletInvokerSupport removeInternalPortlet(String portletId)
- {
- if (portlets.remove(portletId) == null)
- {
- throw new IllegalStateException();
- }
- return this;
- }
-
- public InternalPortlet getInternalPortlet(String portletId)
- {
- if (portletId == null)
- {
- throw new IllegalArgumentException();
- }
- InternalPortlet portlet = (InternalPortlet)portlets.get(portletId);
- if (portlet == null)
- {
- throw new IllegalArgumentException();
- }
- return portlet;
- }
-
- public Set<Portlet> getPortlets()
- {
- return new HashSet<Portlet>(portlets.values());
- }
-
- public Portlet getPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
- {
- return internalGetPortlet(portletContext);
- }
-
- public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
- {
- PortletContext portletContext = invocation.getTarget();
- InternalPortlet portlet = internalGetPortlet(portletContext);
- return portlet.support.invoke(invocation);
- }
-
- private InternalPortlet internalGetPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
- {
- if (portletContext == null)
- {
- throw new IllegalArgumentException();
- }
- String portletId = portletContext.getId();
- InternalPortlet portlet = (InternalPortlet)portlets.get(portletId);
- if (portlet == null)
- {
- throw new NoSuchPortletException(portletId);
- }
- if (portlet.isValid() == false)
- {
- throw new InvalidPortletIdException(portletId);
- }
- return portlet;
- }
-
- public static class InternalPortlet implements Portlet
- {
-
- /** . */
- private final PortletContext portletContext;
-
- /** . */
- private final PortletSupport support;
-
- /** . */
- private boolean valid;
-
- /** . */
- private Map<String, Value> state;
-
- public InternalPortlet(String portletId, PortletSupport support)
- {
- if (portletId == null)
- {
- throw new IllegalArgumentException();
- }
- if (support == null)
- {
- throw new IllegalArgumentException();
- }
- this.portletContext = PortletContext.createPortletContext(portletId);
- this.support = support;
- this.valid = true;
- this.state = new HashMap<String, Value>();
- }
-
- public void addPreference(String key, Value value)
- {
- support.getInfoSupport().getPreferences().addPreference(key);
- state.put(key, value);
- }
-
- public void addPreference(String key, Value value, Boolean readOnly)
- {
- support.getInfoSupport().getPreferences().addPreference(key, readOnly);
- state.put(key, value);
- }
-
- public PortletContext getContext()
- {
- return portletContext;
- }
-
- public PortletInfo getInfo()
- {
- return support.getInfoSupport();
- }
-
- public boolean isRemote()
- {
- return false;
- }
-
- public boolean isValid()
- {
- return valid;
- }
- }
-
- public PropertyMap getProperties(PortletContext portletContext, Set<String>
keys) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
- {
- InternalPortlet internalPortlet = internalGetPortlet(portletContext);
- PropertyMap props = new SimplePropertyMap();
- for (String key : keys)
- {
- Value value = internalPortlet.state.get(key);
- if (value != null)
- {
- props.put(key, value.clone());
- }
- }
- return props;
- }
-
- public PropertyMap getProperties(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- InternalPortlet internalPortlet = internalGetPortlet(portletContext);
- PropertyMap props = new SimplePropertyMap();
- for (String key: internalPortlet.state.keySet())
- {
- Value value = internalPortlet.state.get(key);
- if (value != null)
- {
- props.put(key, value.clone());
- }
- }
- return props;
- }
-
- public PortletContext createClone(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public List<DestroyCloneFailure> destroyClones(List<PortletContext>
portletContexts) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public PortletContext setProperties(PortletContext portletContext, PropertyChange[]
changes) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-}
Deleted:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletSupport.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletSupport.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/PortletSupport.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -1,68 +0,0 @@
-/******************************************************************************
- * 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.portlet.state;
-
-import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.support.info.PortletInfoSupport;
-import org.jboss.portal.portlet.info.PortletInfo;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 6116 $
- */
-public class PortletSupport
-{
-
- /** . */
- protected final PortletInfoSupport info;
-
- /** . */
- protected boolean valid;
-
- public PortletSupport(PortletInfoSupport info)
- {
- if (info == null)
- {
- throw new IllegalArgumentException();
- }
- this.info = info;
- this.valid = true;
- }
-
- public PortletSupport()
- {
- this(new PortletInfoSupport());
- }
-
- public PortletInfoSupport getInfoSupport()
- {
- return info;
- }
-
- public PortletInvocationResponse invoke(PortletInvocation invocation) throws
PortletInvokerException
- {
- throw new PortletInvokerException("No implementations");
- }
-}
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java 2008-02-18
08:26:22 UTC (rev 10013)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/state/ProducerStatefulPortletInvokerTestCase.java 2008-02-18
11:21:08 UTC (rev 10014)
@@ -25,7 +25,6 @@
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletContext;
import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.NoSuchPortletException;
import org.jboss.portal.portlet.impl.state.StateManagementPolicyService;
import org.jboss.portal.portlet.impl.state.StateConverterV0;
import
org.jboss.portal.portlet.impl.state.producer.PortletStatePersistenceManagerService;
@@ -37,7 +36,10 @@
import org.jboss.portal.portlet.state.PropertyMap;
import org.jboss.portal.portlet.state.StateConverter;
import org.jboss.portal.portlet.state.producer.ProducerPortletInvoker;
+import org.jboss.portal.portlet.state.producer.ProducerPortlet;
import org.jboss.portal.portlet.support.info.PortletInfoSupport;
+import org.jboss.portal.portlet.support.PortletInvokerSupport;
+import org.jboss.portal.portlet.support.PortletSupport;
import org.jboss.portal.common.value.Value;
import static org.jboss.unit.api.Assert.*;
@@ -98,24 +100,24 @@
assertEquals(0, persistenceManager.getSize());
}
- protected PortletContext createPOPRef(PortletSupport portletSupport) throws
PortletInvokerException
+ protected PortletContext createPOPRef(PortletInfoSupport portletSupport) throws
PortletInvokerException
{
- container.addInternalPortlet("PortletId", portletSupport);
+ container.addPortlet("PortletId", portletSupport);
Portlet portlet = getSinglePOP();
return portlet.getContext();
}
protected PortletContext createNonExistingPOPRef()
{
- container.addInternalPortlet("NonExistingPortletId", new
PortletInfoSupport());
+ container.addPortlet("NonExistingPortletId", new PortletInfoSupport());
PortletContext popCtx = getSinglePOP().getContext();
- container.removeInternalPortlet("NonExistingPortletId");
+ container.removePortlet("NonExistingPortletId");
return popCtx;
}
protected PortletContext createInvalidPOPRef()
{
- container.addInternalPortlet("InvalidPortletId", new
PortletInfoSupport());
+ container.addPortlet("InvalidPortletId", new PortletInfoSupport());
PortletContext popCtx = getSinglePOP().getContext();
container.setValid("InvalidPortletId", false);
return popCtx;
@@ -131,12 +133,12 @@
protected void addPreference(PortletContext popRef, String key, Value defaultValue)
{
- container.getInternalPortlet(popRef.getId()).addPreference(key, defaultValue);
+ container.getPortlet(popRef.getId()).addPreference(key, defaultValue);
}
protected void addPreference(PortletContext popRef, String key, Value defaultValue,
Boolean readOnly)
{
- container.getInternalPortlet(popRef.getId()).addPreference(key, defaultValue,
readOnly);
+ container.getPortlet(popRef.getId()).addPreference(key, defaultValue, readOnly);
}
protected void destroyClone(PortletContext portletRef) throws Exception
@@ -146,22 +148,22 @@
protected PortletContext createClone(PortletContext portletRef) throws
PortletInvokerException
{
- return producer.createClone((PortletContext)portletRef);
+ return producer.createClone(portletRef);
}
protected PortletContext setProperties(PortletContext portletRef, PropertyChange[]
changes) throws PortletInvokerException
{
- return producer.setProperties((PortletContext)portletRef, changes);
+ return producer.setProperties(portletRef, changes);
}
protected PropertyMap getProperties(PortletContext portletRef) throws
PortletInvokerException
{
- return producer.getProperties((PortletContext)portletRef);
+ return producer.getProperties(portletRef);
}
protected PropertyMap getProperties(PortletContext portletRef, Set keys) throws
PortletInvokerException
{
- return producer.getProperties((PortletContext)portletRef, keys);
+ return producer.getProperties(portletRef, keys);
}
protected List destroyClones(List portletRefs) throws PortletInvokerException
@@ -169,6 +171,20 @@
return producer.destroyClones(portletRefs);
}
+ protected PortletSupport getPortletSupport(PortletContext portletRef) throws
PortletInvokerException
+ {
+ Portlet portlet = producer.getPortlet(portletRef);
+
+ //
+ if (portlet instanceof ProducerPortlet)
+ {
+ portlet = ((ProducerPortlet)portlet).getNext();
+ }
+
+ //
+ return (PortletSupport)portlet;
+ }
+
protected Portlet getPortlet(PortletContext portletRef) throws
PortletInvokerException
{
if (portletRef == null)
@@ -177,13 +193,13 @@
}
else
{
- return producer.getPortlet((PortletContext)portletRef);
+ return producer.getPortlet(portletRef);
}
}
protected String getPortletId(PortletContext portletRef) throws
PortletInvokerException
{
- return ((PortletContext)portletRef).getId();
+ return portletRef.getId();
}
protected void invoke(PortletInvocation invocation) throws PortletInvokerException