Author: chris.laprun(a)jboss.com
Date: 2010-06-20 15:48:45 -0400 (Sun, 20 Jun 2010)
New Revision: 3395
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/WSRPConsumerBaseTest.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/BehaviorBackedServiceFactory.java
Log:
- Make it possible for BehaviorBackedServiceFactory to know which MarkupBehavior is
requested.
- Make WSRPConsumerBaseTest use BehaviorBackedServiceFactory.
- Make sure that MarkupTestCase properly request a MarkupBehavior.
- MarkupTestCase now uses a specific MockUserContext instead of AbstractUserContext as new
code doesn't allow for empty locales.
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/WSRPConsumerBaseTest.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/WSRPConsumerBaseTest.java 2010-06-20
12:18:14 UTC (rev 3394)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/WSRPConsumerBaseTest.java 2010-06-20
19:48:45 UTC (rev 3395)
@@ -24,8 +24,8 @@
package org.gatein.wsrp.consumer;
import junit.framework.TestCase;
-import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.protocol.v1.BehaviorBackedServiceFactory;
import org.gatein.wsrp.test.protocol.v1.BehaviorRegistry;
import org.gatein.wsrp.test.protocol.v1.MarkupBehavior;
import org.gatein.wsrp.test.protocol.v1.PortletManagementBehavior;
@@ -65,13 +65,14 @@
protected TestWSRPProducer producer = new TestWSRPProducerImpl();
/** . */
- protected WSRPConsumer consumer = new WSRPConsumerImpl();
+ protected WSRPConsumerImpl consumer = new WSRPConsumerImpl();
private boolean strict = true;
private String sdClassName;
private String mClassName;
private String pmClassName;
private String rClassName;
+ protected static String requestedMarkupBehavior;
public void setUp() throws Exception
@@ -80,7 +81,8 @@
producer.reset();
// set the test producer identifier
- consumer.getProducerInfo().setId(TEST_PRODUCER_ID);
+ ProducerInfo producerInfo = consumer.getProducerInfo();
+ producerInfo.setId(TEST_PRODUCER_ID);
// reset the behaviors
BehaviorRegistry registry = producer.getBehaviorRegistry();
@@ -91,13 +93,16 @@
registerAdditionalMarkupBehaviors(registry);
// use a fresh ConsumerRegistry
- consumer.getProducerInfo().setRegistry(new MockConsumerRegistry());
+ producerInfo.setRegistry(new MockConsumerRegistry());
+ // use
+ producerInfo.setEndpointConfigurationInfo(new EndpointConfigurationInfo(new
BehaviorBackedServiceFactory(registry)));
+
// make sure we use clean producer info for each test
consumer.refreshProducerInfo();
// use cache to avoid un-necessary calls
- consumer.getProducerInfo().setExpirationCacheSeconds(120);
+ producerInfo.setExpirationCacheSeconds(120);
}
protected void setRegistrationBehavior(RegistrationBehavior behavior)
@@ -129,26 +134,6 @@
registry.setPortletManagementBehavior(behavior);
}
- public TestWSRPProducer getProducer()
- {
- return producer;
- }
-
- public void setProducer(TestWSRPProducer producer)
- {
- this.producer = producer;
- }
-
- public WSRPConsumer getConsumer()
- {
- return consumer;
- }
-
- public void setConsumer(WSRPConsumer consumer)
- {
- this.consumer = consumer;
- }
-
public void testProducerId()
{
ExtendedAssert.assertEquals(TEST_PRODUCER_ID, consumer.getProducerId());
@@ -246,4 +231,22 @@
{
return
producer.getBehaviorRegistry().getServiceDescriptionBehavior().getPortletNumber();
}
+
+ /**
+ * So that BehaviorBackedServiceFactory can retrieve the proper behavior when
retrieving the markup service for
+ * invocation.
+ *
+ * @return
+ */
+ public static String getRequestedMarkupBehavior()
+ {
+ return requestedMarkupBehavior;
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ // reset the requested markup behavior
+ requestedMarkupBehavior = null;
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-06-20
12:18:14 UTC (rev 3394)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2010-06-20
19:48:45 UTC (rev 3395)
@@ -66,7 +66,9 @@
import javax.servlet.http.HttpSession;
import javax.xml.ws.Holder;
+import java.util.Collections;
import java.util.List;
+import java.util.Locale;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -75,6 +77,7 @@
*/
public class MarkupTestCase extends V1ConsumerBaseTest
{
+
public MarkupTestCase() throws Exception
{
super();
@@ -282,9 +285,12 @@
render.setInstanceContext(new AbstractInstanceContext(portletHandle));
render.setSecurityContext(new
AbstractSecurityContext(MockHttpServletRequest.createMockRequest(null)));
- render.setUserContext(new AbstractUserContext());
+ render.setUserContext(new MockUserContext());
render.setWindowContext(new AbstractWindowContext("windowcontext"));
render.setPortalContext(new AbstractPortalContext());
+
+ requestedMarkupBehavior = portletHandle;
+
return render;
}
@@ -294,8 +300,20 @@
ActionInvocation action = new ActionInvocation(ac);
action.setInstanceContext(new AbstractInstanceContext(portletHandle));
action.setSecurityContext(new
AbstractSecurityContext(MockHttpServletRequest.createMockRequest(null)));
- action.setUserContext(new AbstractUserContext());
+ action.setUserContext(new MockUserContext());
action.setTarget(PortletContext.createPortletContext(portletHandle));
+
+ requestedMarkupBehavior = portletHandle;
+
return action;
}
+
+ static class MockUserContext extends AbstractUserContext
+ {
+ @Override
+ public List<Locale> getLocales()
+ {
+ return Collections.singletonList(Locale.ENGLISH);
+ }
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/BehaviorBackedServiceFactory.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/BehaviorBackedServiceFactory.java 2010-06-20
12:18:14 UTC (rev 3394)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/BehaviorBackedServiceFactory.java 2010-06-20
19:48:45 UTC (rev 3395)
@@ -26,6 +26,7 @@
import org.gatein.common.NotYetImplemented;
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.WindowState;
+import org.gatein.wsrp.consumer.WSRPConsumerBaseTest;
import org.gatein.wsrp.services.MarkupService;
import org.gatein.wsrp.services.PortletManagementService;
import org.gatein.wsrp.services.RegistrationService;
@@ -75,7 +76,12 @@
public BehaviorBackedServiceFactory()
{
- registry = new BehaviorRegistry();
+ this(new BehaviorRegistry());
+ }
+
+ public BehaviorBackedServiceFactory(BehaviorRegistry registry)
+ {
+ this.registry = registry;
registry.registerMarkupBehavior(new SimpleMarkupBehavior());
}
@@ -92,7 +98,13 @@
}
if (WSRPV1MarkupPortType.class.isAssignableFrom(serviceClass))
{
- return (T)registry.getMarkupBehaviorFor(MARKUP);
+ String requestedMarkupBehavior =
WSRPConsumerBaseTest.getRequestedMarkupBehavior();
+ if (requestedMarkupBehavior == null)
+ {
+ requestedMarkupBehavior = MARKUP;
+ }
+
+ return (T)registry.getMarkupBehaviorFor(requestedMarkupBehavior);
}
if (WSRPV1PortletManagementPortType.class.isAssignableFrom(serviceClass))
{