Author: julien(a)jboss.com
Date: 2008-03-07 13:11:53 -0500 (Fri, 07 Mar 2008)
New Revision: 10239
Added:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/WiringEventControllerContext.java
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/EventControllerContextSafeInvoker.java
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java
Log:
no compile fix
Modified:
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/EventControllerContextSafeInvoker.java
===================================================================
---
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/EventControllerContextSafeInvoker.java 2008-03-07
14:32:43 UTC (rev 10238)
+++
modules/portlet/trunk/controller/src/main/java/org/jboss/portal/portlet/controller/EventControllerContextSafeInvoker.java 2008-03-07
18:11:53 UTC (rev 10239)
@@ -40,11 +40,11 @@
/** . */
private final Logger log = Logger.getLogger(EventControllerContextSafeInvoker.class);
- public boolean eventProduced(EventControllerContext context, EventPhaseContext
context, Event sourceEvent, Event producedEvent)
+ public boolean eventProduced(EventControllerContext controllerContext,
EventPhaseContext phaseContext, Event sourceEvent, Event producedEvent)
{
try
{
- context.eventProduced(session, sourceEvent, producedEvent);
+ controllerContext.eventProduced(phaseContext, sourceEvent, producedEvent);
//
return true;
@@ -59,11 +59,11 @@
}
}
- public boolean eventConsumed(EventControllerContext context, EventPhaseContext
context, Event consumedEvent, PortletInvocationResponse consumerResponse)
+ public boolean eventConsumed(EventControllerContext controllerContext,
EventPhaseContext phaseContext, Event consumedEvent, PortletInvocationResponse
consumerResponse)
{
try
{
- context.eventConsumed(session, consumedEvent, consumerResponse);
+ controllerContext.eventConsumed(phaseContext, consumedEvent, consumerResponse);
//
return true;
@@ -77,11 +77,11 @@
}
}
- public boolean eventFailed(EventControllerContext context, EventPhaseContext context,
Event failedEvent, Throwable throwable)
+ public boolean eventFailed(EventControllerContext controllerContext, EventPhaseContext
phaseContext, Event failedEvent, Throwable throwable)
{
try
{
- context.eventFailed(session, failedEvent, throwable);
+ controllerContext.eventFailed(phaseContext, failedEvent, throwable);
//
return true;
@@ -95,11 +95,11 @@
}
}
- public boolean eventDiscarded(EventControllerContext context, EventPhaseContext
context, Event discardedEvent, int cause)
+ public boolean eventDiscarded(EventControllerContext controllerContext,
EventPhaseContext phaseContext, Event discardedEvent, int cause)
{
try
{
- context.eventDiscarded(session, discardedEvent, cause);
+ controllerContext.eventDiscarded(phaseContext, discardedEvent, cause);
//
return true;
Modified:
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 2008-03-07
14:32:43 UTC (rev 10238)
+++
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/PortletControllerTestCase.java 2008-03-07
18:11:53 UTC (rev 10239)
@@ -65,7 +65,7 @@
PortletControllerContextSupport context = new PortletControllerContextSupport();
/** . */
- EventControllerContextSupport eventControllerContext = new
EventControllerContextSupport();
+ WiringEventControllerContext eventControllerContext = new
WiringEventControllerContext();
/** . */
PortletInvokerSupport invoker = context.getInvoker();
Copied:
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/WiringEventControllerContext.java
(from rev 10237,
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/WiringEventControllerContext.java
(rev 0)
+++
modules/portlet/trunk/controller/src/test/java/org/jboss/portal/portlet/controller/WiringEventControllerContext.java 2008-03-07
18:11:53 UTC (rev 10239)
@@ -0,0 +1,208 @@
+/******************************************************************************
+ * 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 org.jboss.portal.portlet.controller.event.EventPhaseContext;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+
+import static org.jboss.unit.api.Assert.*;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.Map;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class WiringEventControllerContext implements EventControllerContext
+{
+
+ /** . */
+ private final Map<Coordinate, List<Coordinate>> wires = new
HashMap<Coordinate, List<Coordinate>>();
+
+ /** . */
+ private final List<EventCallback> callbacks = new
LinkedList<EventCallback>();
+
+ public void eventProduced(EventPhaseContext context, Event sourceEvent, Event
producedEvent)
+ {
+ List<Coordinate> dsts = wires.get(new Coordinate(producedEvent.getName(),
producedEvent.getWindowId()));
+
+ //
+ if (dsts != null)
+ {
+ for (Coordinate dst : dsts)
+ {
+ context.queueEvent(new Event(dst.name, producedEvent.getPayload(),
dst.windowId));
+ }
+ }
+ }
+
+ public void eventConsumed(EventPhaseContext context, Event consumedEvent,
PortletInvocationResponse consumerResponse)
+ {
+ callbacks.add(new EventCallback(EventCallback.EVENT_CONSUMED, consumedEvent,
consumerResponse));
+ }
+
+ public void eventFailed(EventPhaseContext context, Event failedEvent, Throwable
throwable)
+ {
+ callbacks.add(new EventCallback(EventCallback.EVENT_FAILED, failedEvent,
throwable));
+ }
+
+ public void eventDiscarded(EventPhaseContext context, Event discardedEvent, int
cause)
+ {
+ callbacks.add(new EventCallback(EventCallback.EVENT_DISCARDED, discardedEvent,
cause));
+ }
+
+ public void createWire(QName srcName, String srcWindowId, QName dstName, String
dstWindowId)
+ {
+ Coordinate src = new Coordinate(srcName, srcWindowId);
+
+ //
+ List<Coordinate> dsts = wires.get(src);
+
+ //
+ if (dsts == null)
+ {
+ dsts = new ArrayList<Coordinate>();
+ wires.put(src, dsts);
+ }
+
+ //
+ Coordinate dst = new Coordinate(dstName, dstWindowId);
+
+ if (dsts.contains(dst))
+ {
+ throw new IllegalStateException("Such a wire already exists");
+ }
+
+ //
+ dsts.add(dst);
+ }
+
+ public static class EventCallback
+ {
+
+ /** . */
+ public static final int EVENT_CONSUMED = 0;
+
+ /** . */
+ public static final int EVENT_FAILED = 1;
+
+ /** . */
+ public static final int EVENT_DISCARDED = 2;
+
+ /** . */
+ private final int type;
+
+ /** . */
+ private final Event event;
+
+ /** . */
+ private final Object data;
+
+ private EventCallback(int type, Event event, Object data)
+ {
+ this.type = type;
+ this.event = event;
+ this.data = data;
+ }
+
+ public int getType()
+ {
+ return type;
+ }
+
+ public Event getEvent()
+ {
+ return event;
+ }
+
+ public PortletInvocationResponse assertConsumed()
+ {
+ assertEquals(EVENT_CONSUMED, type);
+ return (PortletInvocationResponse)data;
+ }
+
+ public Throwable assertFailed()
+ {
+ assertEquals(EVENT_FAILED, type);
+ return (Throwable)data;
+ }
+
+ public int assertDiscarded()
+ {
+ assertEquals(EVENT_DISCARDED, type);
+ return (Integer)data;
+ }
+ }
+
+ private static class Coordinate
+ {
+
+ /** . */
+ final QName name;
+
+ /** . */
+ final String windowId;
+
+ private Coordinate(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 Coordinate)
+ {
+ Coordinate that = (Coordinate)obj;
+ return name.equals(that.name) && windowId.equals(that.windowId);
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode() + windowId.hashCode();
+ }
+ }
+}