Author: chris.laprun(a)jboss.com
Date: 2010-08-19 13:57:41 -0400 (Thu, 19 Aug 2010)
New Revision: 3876
Added:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/WSRP1ConsumerBaseTest.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/InteropServiceDescriptionTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/V2ConsumerBaseTest.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java
Removed:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/WSRPConsumerBaseTest.java
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/V1ConsumerBaseTest.java
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/behaviors/PerUserInitCookieMarkupBehavior.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/BehaviorBackedServiceFactory.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/PerUserInitCookieMarkupBehavior.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/SessionMarkupBehavior.java
Log:
- Added WSRP 2 test cases (right now, simply a copy of the WSRP 1 tests sightly adapted to
WSRP 2).
- Moved WSRPConsumerBaseTest to protocol/v1/WSRP1ConsumerBaseTest as it was full of
version 1 specific code. Duplicated it for WSRP 2.
- Fixed WSRP 2 behaviors which were not up to date for some reason.
Deleted:
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-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/WSRPConsumerBaseTest.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -1,252 +0,0 @@
-/*
- * JBoss, a division of Red Hat
- * Copyright 2010, 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.gatein.wsrp.consumer;
-
-import junit.framework.TestCase;
-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;
-import org.gatein.wsrp.test.protocol.v1.RegistrationBehavior;
-import org.gatein.wsrp.test.protocol.v1.ServiceDescriptionBehavior;
-import org.gatein.wsrp.test.protocol.v1.TestProducerBehavior;
-import org.gatein.wsrp.test.protocol.v1.TestWSRPProducer;
-import org.gatein.wsrp.test.protocol.v1.TestWSRPProducerImpl;
-import org.gatein.wsrp.test.protocol.v1.behaviors.BasicMarkupBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.BasicPortletManagementBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.BasicServiceDescriptionBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.EmptyMarkupBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.InitCookieNotRequiredMarkupBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.NullMarkupBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.PerGroupInitCookieMarkupBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.PerUserInitCookieMarkupBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.ResourceMarkupBehavior;
-import org.gatein.wsrp.test.protocol.v1.behaviors.SessionMarkupBehavior;
-import org.gatein.wsrp.test.support.MockConsumerRegistry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
- * @version $Revision: 11344 $
- */
-public abstract class WSRPConsumerBaseTest extends TestCase
-{
- private static Logger log = LoggerFactory.getLogger(WSRPConsumerBaseTest.class);
-
- /** . */
- private static final String TEST_PRODUCER_ID = "test_producer";
-
- /** . */
- protected TestWSRPProducer producer = new TestWSRPProducerImpl();
-
- /** . */
- 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
- {
- // reset producer state
- producer.reset();
-
- // set the test producer identifier
- ProducerInfo producerInfo = consumer.getProducerInfo();
- producerInfo.setId(TEST_PRODUCER_ID);
-
- // reset the behaviors
- BehaviorRegistry registry = producer.getBehaviorRegistry();
- setSDClassName(sdClassName);
- setMClassName(mClassName);
- setPMClassName(pmClassName);
- setRClassName(rClassName);
- registerAdditionalMarkupBehaviors(registry);
-
- // use a fresh ConsumerRegistry
- 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
- producerInfo.setExpirationCacheSeconds(120);
- }
-
- protected void setRegistrationBehavior(RegistrationBehavior behavior)
- {
- producer.getBehaviorRegistry().setRegistrationBehavior(behavior);
- }
-
- protected void setServiceDescriptionBehavior(ServiceDescriptionBehavior behavior)
- {
- if (behavior == null)
- {
- log.info("Given service description behavior was null, using the default
one instead!");
- behavior = new BasicServiceDescriptionBehavior();
- }
-
- producer.getBehaviorRegistry().setServiceDescriptionBehavior(behavior);
- }
-
- protected void setPortletManagementBehavior(PortletManagementBehavior behavior)
- {
- BehaviorRegistry registry = producer.getBehaviorRegistry();
-
- if (behavior == null)
- {
- log.info("Given portlet management behavior was null, using the default one
instead!");
- behavior = new BasicPortletManagementBehavior(registry);
- }
-
- registry.setPortletManagementBehavior(behavior);
- }
-
- public void testProducerId()
- {
- ExtendedAssert.assertEquals(TEST_PRODUCER_ID, consumer.getProducerId());
- }
-
- public void setSDClassName(String behaviorClassName)
- {
- sdClassName = behaviorClassName;
- setServiceDescriptionBehavior(createBehavior(behaviorClassName,
ServiceDescriptionBehavior.class));
- }
-
- public void setMClassName(String behaviorClassName)
- {
- mClassName = behaviorClassName;
- if (behaviorClassName != null)
- {
-
producer.getBehaviorRegistry().registerMarkupBehavior(createBehavior(behaviorClassName,
MarkupBehavior.class));
- }
- }
-
- public void setPMClassName(String behaviorClassName)
- {
- pmClassName = behaviorClassName;
- setPortletManagementBehavior(createBehavior(behaviorClassName,
PortletManagementBehavior.class));
- }
-
- public void setRClassName(String behaviorClassName)
- {
- rClassName = behaviorClassName;
- setRegistrationBehavior(createBehavior(behaviorClassName,
RegistrationBehavior.class));
- }
-
- public void setStrict(boolean strict)
- {
- this.strict = strict;
- producer.usingStrictModeChangedTo(strict);
- }
-
- public boolean isStrict()
- {
- return strict;
- }
-
- private <T extends TestProducerBehavior> T createBehavior(String
behaviorClassName, Class<T> expectedBehaviorClass)
- {
- if (behaviorClassName != null)
- {
- try
- {
- Class behaviorClass =
getClass().getClassLoader().loadClass(behaviorClassName);
- if (expectedBehaviorClass.isAssignableFrom(behaviorClass))
- {
- return expectedBehaviorClass.cast(behaviorClass.newInstance());
- }
- else
- {
- throw new IllegalArgumentException(behaviorClassName + " is not a
" + expectedBehaviorClass.getSimpleName());
- }
- }
- catch (ClassNotFoundException e)
- {
- throw new IllegalArgumentException("Could not find behavior: " +
behaviorClassName, e);
- }
- catch (IllegalAccessException e)
- {
- throw new IllegalArgumentException("Could not access behavior: " +
behaviorClassName, e);
- }
- catch (InstantiationException e)
- {
- throw new IllegalArgumentException("Could not instantiate behavior:
" + behaviorClassName, e);
- }
- }
-
- return null;
- }
-
- protected void registerAdditionalMarkupBehaviors(BehaviorRegistry registry)
- {
- registry.registerMarkupBehavior(new BasicMarkupBehavior(registry));
- registry.registerMarkupBehavior(new EmptyMarkupBehavior(registry));
- registry.registerMarkupBehavior(new
InitCookieNotRequiredMarkupBehavior(registry));
- registry.registerMarkupBehavior(new PerGroupInitCookieMarkupBehavior(registry));
- registry.registerMarkupBehavior(new PerUserInitCookieMarkupBehavior(registry));
- registry.registerMarkupBehavior(new NullMarkupBehavior(registry));
- registry.registerMarkupBehavior(new SessionMarkupBehavior(registry));
- registry.registerMarkupBehavior(new ResourceMarkupBehavior(registry));
- }
-
- protected Set<String> getPortletHandles()
- {
- return
producer.getBehaviorRegistry().getServiceDescriptionBehavior().getPortletHandles();
- }
-
- protected int getPortletNumber()
- {
- 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/V1ConsumerBaseTest.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/V1ConsumerBaseTest.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/V1ConsumerBaseTest.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -1,30 +1,29 @@
-/******************************************************************************
- * 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. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v1;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.info.MetaInfo;
-import org.gatein.wsrp.consumer.WSRPConsumerBaseTest;
import org.gatein.wsrp.test.ExtendedAssert;
import org.gatein.wsrp.test.protocol.v1.TestProducerBehavior;
@@ -32,7 +31,7 @@
* @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
* @version $Revision: 11320 $
*/
-public class V1ConsumerBaseTest extends WSRPConsumerBaseTest
+public class V1ConsumerBaseTest extends WSRP1ConsumerBaseTest
{
public V1ConsumerBaseTest() throws Exception
{
Copied:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/WSRP1ConsumerBaseTest.java
(from rev 3841,
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/WSRP1ConsumerBaseTest.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/WSRP1ConsumerBaseTest.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -0,0 +1,222 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v1;
+
+import junit.framework.TestCase;
+import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+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.PortletManagementBehavior;
+import org.gatein.wsrp.test.protocol.v1.RegistrationBehavior;
+import org.gatein.wsrp.test.protocol.v1.ServiceDescriptionBehavior;
+import org.gatein.wsrp.test.protocol.v1.TestProducerBehavior;
+import org.gatein.wsrp.test.protocol.v1.TestWSRPProducer;
+import org.gatein.wsrp.test.protocol.v1.TestWSRPProducerImpl;
+import org.gatein.wsrp.test.protocol.v1.behaviors.BasicMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.BasicPortletManagementBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.BasicServiceDescriptionBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.EmptyMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.InitCookieNotRequiredMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.NullMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.PerGroupInitCookieMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.PerUserInitCookieMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.ResourceMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.SessionMarkupBehavior;
+import org.gatein.wsrp.test.support.MockConsumerRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 11344 $
+ */
+public abstract class WSRP1ConsumerBaseTest extends TestCase
+{
+ private static Logger log = LoggerFactory.getLogger(WSRP1ConsumerBaseTest.class);
+
+ /** . */
+ private static final String TEST_PRODUCER_ID = "test_producer";
+
+ /** . */
+ protected TestWSRPProducer producer = new TestWSRPProducerImpl();
+
+ /** . */
+ protected WSRPConsumerImpl consumer = new WSRPConsumerImpl();
+
+ private boolean strict = true;
+ protected static String requestedMarkupBehavior;
+
+
+ public void setUp() throws Exception
+ {
+ // reset producer state
+ producer.reset();
+
+ // set the test producer identifier
+ ProducerInfo producerInfo = consumer.getProducerInfo();
+ producerInfo.setId(TEST_PRODUCER_ID);
+
+ // reset the behaviors
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+ setServiceDescriptionBehavior(null);
+ setPortletManagementBehavior(null);
+ setRegistrationBehavior(null);
+ registerAdditionalMarkupBehaviors(registry);
+
+ // use a fresh ConsumerRegistry
+ 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
+ producerInfo.setExpirationCacheSeconds(120);
+ }
+
+ protected void setRegistrationBehavior(RegistrationBehavior behavior)
+ {
+ producer.getBehaviorRegistry().setRegistrationBehavior(behavior);
+ }
+
+ protected void setServiceDescriptionBehavior(ServiceDescriptionBehavior behavior)
+ {
+ if (behavior == null)
+ {
+ log.debug("Given service description behavior was null, using the default
one instead!");
+ behavior = new BasicServiceDescriptionBehavior();
+ }
+
+ producer.getBehaviorRegistry().setServiceDescriptionBehavior(behavior);
+ }
+
+ protected void setPortletManagementBehavior(PortletManagementBehavior behavior)
+ {
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+
+ if (behavior == null)
+ {
+ log.debug("Given portlet management behavior was null, using the default
one instead!");
+ behavior = new BasicPortletManagementBehavior(registry);
+ }
+
+ registry.setPortletManagementBehavior(behavior);
+ }
+
+ public void testProducerId()
+ {
+ ExtendedAssert.assertEquals(TEST_PRODUCER_ID, consumer.getProducerId());
+ }
+
+ public void setStrict(boolean strict)
+ {
+ this.strict = strict;
+ producer.usingStrictModeChangedTo(strict);
+ }
+
+ public boolean isStrict()
+ {
+ return strict;
+ }
+
+ private <T extends TestProducerBehavior> T createBehavior(String
behaviorClassName, Class<T> expectedBehaviorClass)
+ {
+ if (behaviorClassName != null)
+ {
+ try
+ {
+ Class behaviorClass =
getClass().getClassLoader().loadClass(behaviorClassName);
+ if (expectedBehaviorClass.isAssignableFrom(behaviorClass))
+ {
+ return expectedBehaviorClass.cast(behaviorClass.newInstance());
+ }
+ else
+ {
+ throw new IllegalArgumentException(behaviorClassName + " is not a
" + expectedBehaviorClass.getSimpleName());
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException("Could not find behavior: " +
behaviorClassName, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new IllegalArgumentException("Could not access behavior: " +
behaviorClassName, e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new IllegalArgumentException("Could not instantiate behavior:
" + behaviorClassName, e);
+ }
+ }
+
+ return null;
+ }
+
+ protected void registerAdditionalMarkupBehaviors(BehaviorRegistry registry)
+ {
+ registry.registerMarkupBehavior(new BasicMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new EmptyMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new
InitCookieNotRequiredMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new PerGroupInitCookieMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new PerUserInitCookieMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new NullMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new SessionMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new ResourceMarkupBehavior(registry));
+ }
+
+ protected Set<String> getPortletHandles()
+ {
+ return
producer.getBehaviorRegistry().getServiceDescriptionBehavior().getPortletHandles();
+ }
+
+ protected int getPortletNumber()
+ {
+ 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;
+ }
+}
Property changes on:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/WSRP1ConsumerBaseTest.java
___________________________________________________________________
Name: svn:executable
+ *
Copied:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/InteropServiceDescriptionTestCase.java
(from rev 3841,
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/InteropServiceDescriptionTestCase.java)
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/InteropServiceDescriptionTestCase.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/InteropServiceDescriptionTestCase.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v2;
+
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class InteropServiceDescriptionTestCase extends V2ConsumerBaseTest
+{
+ public InteropServiceDescriptionTestCase() throws Exception
+ {
+ super();
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ setStrict(false);
+ super.setUp();
+ }
+
+ public void testUsesRelaxedMode()
+ {
+ ExtendedAssert.assertFalse(isStrict());
+ }
+
+ public void testGetPortlets() throws PortletInvokerException
+ {
+ //invoke consumer
+ Set returnedPortlets = consumer.getPortlets();
+
+ int portletNumber = returnedPortlets.size();
+ ExtendedAssert.assertEquals(getPortletNumber(), portletNumber);
+ Set<String> handles = getPortletHandles();
+ Set<String> consumerHandles = new HashSet<String>(portletNumber);
+ for (Object o : returnedPortlets)
+ {
+ Portlet portlet = (Portlet)o;
+ consumerHandles.add(portlet.getContext().getId());
+ }
+
+ ExtendedAssert.assertTrue(handles.containsAll(consumerHandles));
+ }
+
+ @Override
+ protected void registerAdditionalMarkupBehaviors(BehaviorRegistry registry)
+ {
+ // do nothing so that we don't pollute the service description with markup
behaviors
+ }
+}
Copied:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java
(from rev 3841,
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/v2/MarkupTestCase.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/MarkupTestCase.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -0,0 +1,332 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v2;
+
+import org.gatein.pc.api.Mode;
+import org.gatein.pc.api.OpaqueStateString;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.WindowState;
+import org.gatein.pc.api.invocation.ActionInvocation;
+import org.gatein.pc.api.invocation.RenderInvocation;
+import org.gatein.pc.api.invocation.response.ErrorResponse;
+import org.gatein.pc.api.invocation.response.FragmentResponse;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.invocation.response.UpdateNavigationalStateResponse;
+import org.gatein.pc.portlet.impl.spi.AbstractInstanceContext;
+import org.gatein.pc.portlet.impl.spi.AbstractPortalContext;
+import org.gatein.pc.portlet.impl.spi.AbstractSecurityContext;
+import org.gatein.pc.portlet.impl.spi.AbstractUserContext;
+import org.gatein.pc.portlet.impl.spi.AbstractWindowContext;
+import org.gatein.wsrp.WSRPResourceURL;
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
+import org.gatein.wsrp.test.protocol.v2.behaviors.BasicMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.EmptyMarkupBehavior;
+import
org.gatein.wsrp.test.protocol.v2.behaviors.GroupedPortletsServiceDescriptionBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.InitCookieMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.InitCookieNotRequiredMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.NullMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.PerGroupInitCookieMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.PerUserInitCookieMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.ResourceMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.SessionMarkupBehavior;
+import org.gatein.wsrp.test.support.MockHttpServletRequest;
+import org.gatein.wsrp.test.support.TestPortletInvocationContext;
+import org.oasis.wsrp.v2.CookieProtocol;
+import org.oasis.wsrp.v2.EventDescription;
+import org.oasis.wsrp.v2.ExportDescription;
+import org.oasis.wsrp.v2.Extension;
+import org.oasis.wsrp.v2.InvalidHandle;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.ItemDescription;
+import org.oasis.wsrp.v2.ModelDescription;
+import org.oasis.wsrp.v2.ModelTypes;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.ResourceList;
+import org.oasis.wsrp.v2.ResourceSuspended;
+
+import javax.servlet.http.HttpSession;
+import javax.xml.ws.Holder;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11320 $
+ * @since 2.4 (May 4, 2006)
+ */
+public class MarkupTestCase extends V2ConsumerBaseTest
+{
+
+ public MarkupTestCase() throws Exception
+ {
+ super();
+ }
+
+ public void testInvalidHandle()
+ {
+ try
+ {
+ consumer.invoke(createRenderInvocation("Invalid portlet handle"));
+ ExtendedAssert.fail("Should have failed on invalid portlet handle");
+ }
+ catch (PortletInvokerException expected)
+ {
+ // expected
+ }
+ }
+
+ public void testEmptyRender() throws Exception
+ {
+
checkRenderResult(consumer.invoke(createRenderInvocation(EmptyMarkupBehavior.PORTLET_HANDLE)),
"");
+ }
+
+ public void testNullAction() throws Exception
+ {
+
ExtendedAssert.assertTrue(consumer.invoke(createActionInvocation(NullMarkupBehavior.PORTLET_HANDLE))
instanceof ErrorResponse);
+ }
+
+ public void testNullRender() throws Exception
+ {
+
ExtendedAssert.assertTrue(consumer.invoke(createRenderInvocation(NullMarkupBehavior.PORTLET_HANDLE))
instanceof ErrorResponse);
+ }
+
+ public void testRender() throws Exception
+ {
+ RenderInvocation render =
createRenderInvocation(BasicMarkupBehavior.PORTLET_HANDLE, Mode.EDIT,
+ WindowState.NORMAL, "someNS");
+ FragmentResponse result = checkRenderResult(consumer.invoke(render),
"portlet1:edit:normal:someNS");
+ ExtendedAssert.assertEquals(15, result.getCacheControl().getExpirationSecs());
+
+ render = createRenderInvocation(SessionMarkupBehavior.PORTLET_HANDLE);
+ result = checkRenderResult(consumer.invoke(render),
"portlet2:0:view:maximized");
+ ExtendedAssert.assertEquals(0, result.getCacheControl().getExpirationSecs());
+ }
+
+ public void testAction() throws Exception
+ {
+ ActionInvocation action =
createActionInvocation(BasicMarkupBehavior.PORTLET_HANDLE);
+
+ PortletInvocationResponse response = consumer.invoke(action);
+ ExtendedAssert.assertNotNull(response);
+ ExtendedAssert.assertTrue("Was expecting a RenderResponse. Got: " +
response, response instanceof UpdateNavigationalStateResponse);
+ UpdateNavigationalStateResponse render =
(UpdateNavigationalStateResponse)response;
+ ExtendedAssert.assertEquals(BasicMarkupBehavior.NS,
render.getNavigationalState().getStringValue());
+ }
+
+ public void testSessionHandling() throws Exception
+ {
+ RenderInvocation render =
createRenderInvocation(SessionMarkupBehavior.PORTLET_HANDLE);
+
+ PortletInvocationResponse response = consumer.invoke(render);
+
+ checkRenderResult(response, "portlet2:0:view:maximized");
+
+ // checking session information
+ ProducerSessionInformation sessionInfo =
consumer.getProducerSessionInformationFrom(render);
+ String sessionId =
sessionInfo.getSessionIdForPortlet(SessionMarkupBehavior.PORTLET_HANDLE);
+ ExtendedAssert.assertNotNull(sessionId);
+ ExtendedAssert.assertEquals(SessionMarkupBehavior.SESSION_ID, sessionId);
+ ExtendedAssert.assertFalse(sessionInfo.isPerGroupCookies());
+ ExtendedAssert.assertFalse(sessionInfo.isInitCookieDone());
+
+ response = consumer.invoke(render);
+ checkRenderResult(response, "portlet2:1:view:maximized");
+ }
+
+ public void testInitCookieNotCalledWhenNotNeeded() throws Exception
+ {
+ String handle =
InitCookieNotRequiredMarkupBehavior.INIT_COOKIE_NOT_REQUIRED_HANDLE;
+ InitCookieMarkupBehavior behavior =
(InitCookieMarkupBehavior)producer.getBehaviorRegistry().getMarkupBehaviorFor(handle);
+
+ ProducerSessionInformation sessionInfo = commonInitCookieTest(handle, behavior,
CookieProtocol.NONE.value());
+
+ ExtendedAssert.assertNotNull(sessionInfo);
+ ExtendedAssert.assertFalse(sessionInfo.isPerGroupCookies());
+ ExtendedAssert.assertFalse(sessionInfo.isInitCookieDone());
+
+ ExtendedAssert.assertEquals(0, behavior.getInitCookieCallCount());
+ }
+
+ public void testInitCookiePerUser() throws PortletInvokerException, InvalidHandle
+ {
+ String handle = PerUserInitCookieMarkupBehavior.PER_USER_INIT_COOKIE_HANDLE;
+ InitCookieMarkupBehavior behavior =
(InitCookieMarkupBehavior)producer.getBehaviorRegistry().getMarkupBehaviorFor(handle);
+
+
+ ProducerSessionInformation sessionInfo = commonInitCookieTest(handle, behavior,
CookieProtocol.PER_USER.value());
+
+ ExtendedAssert.assertFalse(sessionInfo.isPerGroupCookies());
+ ExtendedAssert.assertTrue(sessionInfo.isInitCookieDone());
+
+ ExtendedAssert.assertNotNull(sessionInfo.getUserCookie());
+
+ ExtendedAssert.assertEquals(1, behavior.getInitCookieCallCount());
+ }
+
+ public void testInitCookiePerGroup() throws PortletInvokerException, OperationFailed,
ResourceSuspended, ModifyRegistrationRequired, InvalidRegistration, InvalidHandle
+ {
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+
+ // need to setup with a specific service description behavior: we wrap the current
service description
+ Holder<List<PortletDescription>> offeredPortlets = new
Holder<List<PortletDescription>>();
+ registry.getServiceDescriptionBehavior().getServiceDescription(null, null, null,
null, new Holder<Boolean>(),
+ offeredPortlets, new Holder<List<ItemDescription>>(),
+ null, new Holder<List<ItemDescription>>(), new
Holder<List<ItemDescription>>(), new Holder<CookieProtocol>(), new
Holder<ModelDescription>(), new Holder<List<String>>(),
+ new Holder<ResourceList>(), new
Holder<List<EventDescription>>(), new Holder<ModelTypes>(), new
Holder<List<String>>(), new Holder<ExportDescription>(), new
Holder<Boolean>(), new Holder<List<Extension>>());
+ setServiceDescriptionBehavior(new
GroupedPortletsServiceDescriptionBehavior(offeredPortlets.value));
+
+ String handle = PerGroupInitCookieMarkupBehavior.PER_GROUP_INIT_COOKIE_HANDLE;
+ InitCookieMarkupBehavior behavior =
(InitCookieMarkupBehavior)registry.getMarkupBehaviorFor(handle);
+
+ ProducerSessionInformation sessionInfo = commonInitCookieTest(handle, behavior,
CookieProtocol.PER_GROUP.value());
+ ExtendedAssert.assertTrue(sessionInfo.isPerGroupCookies());
+ ExtendedAssert.assertTrue(sessionInfo.isInitCookieDone());
+ ExtendedAssert.assertNull(sessionInfo.getUserCookie());
+
+ ExtendedAssert.assertEquals(3, behavior.getInitCookieCallCount());
+ }
+
+ public void testResource() throws PortletInvokerException, MalformedURLException
+ {
+ RenderInvocation render =
createRenderInvocation(ResourceMarkupBehavior.PORTLET_HANDLE);
+ PortletInvocationResponse response = consumer.invoke(render);
+
+ String resourceID = WSRPResourceURL.encodeResource(null, new
URL("http://localhost:8080/test-resource-portlet/gif/logo.gif"), false);
+ String expectedResult = "<img src='Resource id=" + resourceID +
" ns=null ws=null m=null'/>";
+
+ //NOTE: the value we get back is from the TestPortletInvocationContext, not what we
would normally receive
+ checkRenderResult(response, expectedResult);
+ }
+
+ private ProducerSessionInformation commonInitCookieTest(String handle,
InitCookieMarkupBehavior behavior, String cookieProtocol)
+ throws PortletInvokerException
+ {
+ RenderInvocation render = createRenderInvocation(handle);
+ TestPortletInvocationContext invocationContext =
(TestPortletInvocationContext)render.getContext();
+ HttpSession session = invocationContext.getClientRequest().getSession();
+
+ // set init cookie requirement
+ producer.setRequiresInitCookie(CookieProtocol.fromValue(cookieProtocol));
+
+ // tell the producer which markup behavior we want to use
+ producer.setCurrentMarkupBehaviorHandle(handle);
+
+ render = createRenderInvocation(handle, invocationContext);
+
+ ExtendedAssert.assertEquals(0, behavior.getInitCookieCallCount());
+
+ consumer.invoke(render);
+
+ ExtendedAssert.assertEquals(cookieProtocol,
consumer.getProducerInfo().getRequiresInitCookie().value());
+
+ return consumer.getProducerSessionInformationFrom(session);
+ }
+
+ private FragmentResponse checkRenderResult(PortletInvocationResponse response, String
markup)
+ {
+ ExtendedAssert.assertNotNull(response);
+ if (response instanceof ErrorResponse)
+ {
+ ErrorResponse errorResponse = (ErrorResponse)response;
+ ExtendedAssert.fail("Got an ErrorResponse instead of a FragmentResponse.
Message: " + errorResponse.getMessage());
+ }
+ ExtendedAssert.assertTrue("Was expecting a FragmentResponse. Got: " +
response, response instanceof FragmentResponse);
+ FragmentResponse fragment = (FragmentResponse)response;
+ ExtendedAssert.assertEquals(markup, fragment.getChars().toString());
+ return fragment;
+ }
+
+ private RenderInvocation createRenderInvocation(String portletHandle)
+ {
+ return createRenderInvocation(portletHandle, null);
+ }
+
+ private RenderInvocation createRenderInvocation(String portletHandle,
TestPortletInvocationContext invocationContext)
+ {
+ return createRenderInvocation(portletHandle, Mode.VIEW, WindowState.MAXIMIZED,
null, invocationContext);
+ }
+
+ private RenderInvocation createRenderInvocation(String portletHandle, Mode mode,
WindowState state, String navigationalState)
+ {
+ return createRenderInvocation(portletHandle, mode, state, navigationalState,
null);
+ }
+
+ private RenderInvocation createRenderInvocation(String portletHandle, Mode mode,
WindowState state, String navigationalState, TestPortletInvocationContext
invocationContext)
+ {
+ if (invocationContext == null)
+ {
+ invocationContext = new TestPortletInvocationContext();
+ }
+
+ RenderInvocation render = new RenderInvocation(invocationContext);
+ render.setTarget(PortletContext.createPortletContext(portletHandle));
+ render.setMode(mode);
+ render.setWindowState(state);
+ if (navigationalState != null)
+ {
+ render.setNavigationalState(new OpaqueStateString(navigationalState));
+ }
+
+ render.setInstanceContext(new AbstractInstanceContext(portletHandle));
+ render.setSecurityContext(new
AbstractSecurityContext(MockHttpServletRequest.createMockRequest(null)));
+ render.setUserContext(new MockUserContext());
+ render.setWindowContext(new AbstractWindowContext("windowcontext"));
+ render.setPortalContext(new AbstractPortalContext());
+
+ requestedMarkupBehavior = portletHandle;
+
+ return render;
+ }
+
+ private ActionInvocation createActionInvocation(String portletHandle)
+ {
+ TestPortletInvocationContext ac = new TestPortletInvocationContext();
+ ActionInvocation action = new ActionInvocation(ac);
+ action.setInstanceContext(new AbstractInstanceContext(portletHandle));
+ action.setSecurityContext(new
AbstractSecurityContext(MockHttpServletRequest.createMockRequest(null)));
+ 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);
+ }
+ }
+}
Copied:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
(from rev 3841,
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java)
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/PortletManagementTestCase.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -0,0 +1,160 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v2;
+
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.state.DestroyCloneFailure;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
+import org.gatein.wsrp.test.protocol.v2.behaviors.BasicMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.BasicPortletManagementBehavior;
+import
org.gatein.wsrp.test.protocol.v2.behaviors.DestroyClonesPortletManagementBehavior;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class PortletManagementTestCase extends V2ConsumerBaseTest
+{
+ public PortletManagementTestCase() throws Exception
+ {
+ }
+
+ /*public void testClone() throws Exception
+ {
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ PortletContext clone = consumer.createClone(original);
+ ExtendedAssert.assertNotNull(clone);
+ ExtendedAssert.assertFalse(original.equals(clone));
+ ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE,
clone.getId());
+
+ Portlet originalPortlet = consumer.getPortlet(original);
+ Portlet clonePortlet = consumer.getPortlet(clone);
+ ExtendedAssert.assertNotNull(clonePortlet);
+
ExtendedAssert.assertFalse(originalPortlet.getContext().equals(clonePortlet.getContext()));
+
+ // information about the portlet should be the same
+ MetaInfo originalInfo = originalPortlet.getInfo().getMeta();
+ MetaInfo cloneInfo = clonePortlet.getInfo().getMeta();
+ ExtendedAssert.assertEquals(originalInfo.getMetaValue(MetaInfo.TITLE),
cloneInfo.getMetaValue(MetaInfo.TITLE));
+ ExtendedAssert.assertEquals(originalInfo.getMetaValue(MetaInfo.DESCRIPTION),
cloneInfo.getMetaValue(MetaInfo.DESCRIPTION));
+ }
+
+ public void testGetSetProperties() throws Exception
+ {
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ PropertyMap props = consumer.getProperties(original);
+ checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE);
+
+ PortletContext clone = consumer.createClone(original);
+ props = consumer.getProperties(clone);
+ checkProperties(props, BasicPortletManagementBehavior.PROPERTY_VALUE);
+
+ consumer.setProperties(clone, new PropertyChange[]
+ {
+ PropertyChange.newUpdate(BasicPortletManagementBehavior.PROPERTY_NAME,
+ new StringValue(BasicPortletManagementBehavior.PROPERTY_NEW_VALUE))
+ });
+ checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_NEW_VALUE);
+
+ consumer.setProperties(clone, new PropertyChange[]
+ {
+ PropertyChange.newReset(BasicPortletManagementBehavior.PROPERTY_NAME)
+ });
+ checkProperties(consumer.getProperties(clone),
BasicPortletManagementBehavior.PROPERTY_VALUE);
+ }
+
+ private void checkProperties(PropertyMap props, String expectedValue)
+ {
+ ExtendedAssert.assertNotNull(props);
+ ExtendedAssert.assertEquals(1, props.size());
+ ExtendedAssert.assertEquals(expectedValue,
+ props.getProperty(BasicPortletManagementBehavior.PROPERTY_NAME).asString());
+ }*/
+
+ public void testDestroyClones() throws Exception
+ {
+ // switch the behavior for portlet management
+ BehaviorRegistry behaviorRegistry = producer.getBehaviorRegistry();
+ behaviorRegistry.setPortletManagementBehavior(new
DestroyClonesPortletManagementBehavior(behaviorRegistry));
+
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ PortletContext clone = consumer.createClone(PortletStateType.OPAQUE, original);
+ ExtendedAssert.assertNotNull(clone);
+ Portlet portlet = consumer.getPortlet(clone);
+ ExtendedAssert.assertNotNull(portlet);
+ ExtendedAssert.assertEquals(BasicPortletManagementBehavior.CLONED_HANDLE,
portlet.getContext().getId());
+
+ List clones = new ArrayList(1);
+ clones.add(clone);
+ List result = consumer.destroyClones(clones);
+ ExtendedAssert.assertTrue(result.isEmpty());
+ try
+ {
+ consumer.getPortlet(clone);
+ ExtendedAssert.fail("Should have failed: clone should not exist
anymore!");
+ }
+ catch (PortletInvokerException expected)
+ {
+ }
+
+ // re-create clone and try again with an added invalid portlet context
+ clone = consumer.createClone(PortletStateType.OPAQUE, original);
+ PortletContext invalidContext =
PortletContext.createPortletContext("invalid");
+ clones.add(invalidContext);
+ result = consumer.destroyClones(clones);
+ ExtendedAssert.assertEquals(1, result.size());
+ DestroyCloneFailure failure = (DestroyCloneFailure)result.get(0);
+ ExtendedAssert.assertEquals("invalid", failure.getPortletId());
+ try
+ {
+ consumer.getPortlet(clone);
+ ExtendedAssert.fail("Should have failed: clone should not exist
anymore!");
+ }
+ catch (PortletInvokerException expected)
+ {
+ }
+ }
+
+ /*public void testInvalidSetProperties() throws Exception
+ {
+ PortletContext original =
PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE);
+ try
+ {
+ consumer.setProperties(original, null);
+ ExtendedAssert.fail("Shouldn't be possible to set properties with null
changes");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ //expected
+ }
+ }*/
+}
Copied:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java
(from rev 3841,
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java)
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v2;
+
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.protocol.v1.behaviors.BasicMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v1.behaviors.SessionMarkupBehavior;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11320 $
+ * @since 2.4
+ */
+public class ServiceDescriptionTestCase extends InteropServiceDescriptionTestCase
+{
+
+ public ServiceDescriptionTestCase() throws Exception
+ {
+ super();
+ }
+
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ // use strict mode
+ setStrict(true);
+ }
+
+ public void testUsesRelaxedMode()
+ {
+ ExtendedAssert.assertTrue(isStrict());
+ }
+
+ public void testGetPortlet() throws Exception
+ {
+ //obtain one portlet
+ Portlet portlet =
consumer.getPortlet(PortletContext.createPortletContext(BasicMarkupBehavior.PORTLET_HANDLE));
+ checkPortlet(portlet, "", BasicMarkupBehavior.PORTLET_HANDLE);
+
+ portlet =
consumer.getPortlet(PortletContext.createPortletContext(SessionMarkupBehavior.PORTLET_HANDLE));
+ checkPortlet(portlet, "2", SessionMarkupBehavior.PORTLET_HANDLE);
+ }
+}
Copied:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/V2ConsumerBaseTest.java
(from rev 3841,
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v1/V1ConsumerBaseTest.java)
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/V2ConsumerBaseTest.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/V2ConsumerBaseTest.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v2;
+
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.info.MetaInfo;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.protocol.v2.TestProducerBehavior;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 11320 $
+ */
+public class V2ConsumerBaseTest extends WSRP2ConsumerBaseTest
+{
+ public V2ConsumerBaseTest() throws Exception
+ {
+ }
+
+ protected void checkPortlet(Portlet portlet, String suffix, String handle)
+ {
+ MetaInfo meta = portlet.getInfo().getMeta();
+ ExtendedAssert.assertEquals(handle, portlet.getContext().getId());
+ ExtendedAssert.assertEquals(TestProducerBehavior.SAMPLE_DESCRIPTION + suffix,
TestProducerBehavior.extractString(meta.getMetaValue(MetaInfo.DESCRIPTION)));
+ ExtendedAssert.assertEquals(TestProducerBehavior.SAMPLE_TITLE + suffix,
TestProducerBehavior.extractString(meta.getMetaValue(MetaInfo.TITLE)));
+ ExtendedAssert.assertEquals(TestProducerBehavior.SAMPLE_SHORTTITLE + suffix,
TestProducerBehavior.extractString(meta.getMetaValue(MetaInfo.SHORT_TITLE)));
+ ExtendedAssert.assertEquals(TestProducerBehavior.SAMPLE_DISPLAYNAME + suffix,
TestProducerBehavior.extractString(meta.getMetaValue(MetaInfo.DISPLAY_NAME)));
+ ExtendedAssert.assertEquals(TestProducerBehavior.SAMPLE_KEYWORD + suffix,
TestProducerBehavior.extractString(meta.getMetaValue(MetaInfo.KEYWORDS)));
+ }
+
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+}
Property changes on:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/V2ConsumerBaseTest.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -0,0 +1,222 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, 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.gatein.wsrp.protocol.v2;
+
+import junit.framework.TestCase;
+import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
+import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.gatein.wsrp.test.protocol.v2.BehaviorBackedServiceFactory;
+import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
+import org.gatein.wsrp.test.protocol.v2.PortletManagementBehavior;
+import org.gatein.wsrp.test.protocol.v2.RegistrationBehavior;
+import org.gatein.wsrp.test.protocol.v2.ServiceDescriptionBehavior;
+import org.gatein.wsrp.test.protocol.v2.TestProducerBehavior;
+import org.gatein.wsrp.test.protocol.v2.TestWSRPProducer;
+import org.gatein.wsrp.test.protocol.v2.TestWSRPProducerImpl;
+import org.gatein.wsrp.test.protocol.v2.behaviors.BasicMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.BasicPortletManagementBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.BasicServiceDescriptionBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.EmptyMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.InitCookieNotRequiredMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.NullMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.PerGroupInitCookieMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.PerUserInitCookieMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.ResourceMarkupBehavior;
+import org.gatein.wsrp.test.protocol.v2.behaviors.SessionMarkupBehavior;
+import org.gatein.wsrp.test.support.MockConsumerRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 11344 $
+ */
+public abstract class WSRP2ConsumerBaseTest extends TestCase
+{
+ private static Logger log = LoggerFactory.getLogger(WSRP2ConsumerBaseTest.class);
+
+ /** . */
+ private static final String TEST_PRODUCER_ID = "test_producer";
+
+ /** . */
+ protected TestWSRPProducer producer = new TestWSRPProducerImpl();
+
+ /** . */
+ protected WSRPConsumerImpl consumer = new WSRPConsumerImpl();
+
+ private boolean strict = true;
+ protected static String requestedMarkupBehavior;
+
+
+ public void setUp() throws Exception
+ {
+ // reset producer state
+ producer.reset();
+
+ // set the test producer identifier
+ ProducerInfo producerInfo = consumer.getProducerInfo();
+ producerInfo.setId(TEST_PRODUCER_ID);
+
+ // reset the behaviors
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+ setServiceDescriptionBehavior(null);
+ setPortletManagementBehavior(null);
+ setRegistrationBehavior(null);
+ registerAdditionalMarkupBehaviors(registry);
+
+ // use a fresh ConsumerRegistry
+ 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
+ producerInfo.setExpirationCacheSeconds(120);
+ }
+
+ protected void setRegistrationBehavior(RegistrationBehavior behavior)
+ {
+ producer.getBehaviorRegistry().setRegistrationBehavior(behavior);
+ }
+
+ protected void setServiceDescriptionBehavior(ServiceDescriptionBehavior behavior)
+ {
+ if (behavior == null)
+ {
+ log.debug("Given service description behavior was null, using the default
one instead!");
+ behavior = new BasicServiceDescriptionBehavior();
+ }
+
+ producer.getBehaviorRegistry().setServiceDescriptionBehavior(behavior);
+ }
+
+ protected void setPortletManagementBehavior(PortletManagementBehavior behavior)
+ {
+ BehaviorRegistry registry = producer.getBehaviorRegistry();
+
+ if (behavior == null)
+ {
+ log.debug("Given portlet management behavior was null, using the default
one instead!");
+ behavior = new BasicPortletManagementBehavior(registry);
+ }
+
+ registry.setPortletManagementBehavior(behavior);
+ }
+
+ public void testProducerId()
+ {
+ ExtendedAssert.assertEquals(TEST_PRODUCER_ID, consumer.getProducerId());
+ }
+
+ public void setStrict(boolean strict)
+ {
+ this.strict = strict;
+ producer.usingStrictModeChangedTo(strict);
+ }
+
+ public boolean isStrict()
+ {
+ return strict;
+ }
+
+ private <T extends TestProducerBehavior> T createBehavior(String
behaviorClassName, Class<T> expectedBehaviorClass)
+ {
+ if (behaviorClassName != null)
+ {
+ try
+ {
+ Class behaviorClass =
getClass().getClassLoader().loadClass(behaviorClassName);
+ if (expectedBehaviorClass.isAssignableFrom(behaviorClass))
+ {
+ return expectedBehaviorClass.cast(behaviorClass.newInstance());
+ }
+ else
+ {
+ throw new IllegalArgumentException(behaviorClassName + " is not a
" + expectedBehaviorClass.getSimpleName());
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException("Could not find behavior: " +
behaviorClassName, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new IllegalArgumentException("Could not access behavior: " +
behaviorClassName, e);
+ }
+ catch (InstantiationException e)
+ {
+ throw new IllegalArgumentException("Could not instantiate behavior:
" + behaviorClassName, e);
+ }
+ }
+
+ return null;
+ }
+
+ protected void registerAdditionalMarkupBehaviors(BehaviorRegistry registry)
+ {
+ registry.registerMarkupBehavior(new BasicMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new EmptyMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new
InitCookieNotRequiredMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new PerGroupInitCookieMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new PerUserInitCookieMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new NullMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new SessionMarkupBehavior(registry));
+ registry.registerMarkupBehavior(new ResourceMarkupBehavior(registry));
+ }
+
+ protected Set<String> getPortletHandles()
+ {
+ return
producer.getBehaviorRegistry().getServiceDescriptionBehavior().getPortletHandles();
+ }
+
+ protected int getPortletNumber()
+ {
+ 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/test/protocol/v1/BehaviorBackedServiceFactory.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/BehaviorBackedServiceFactory.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/BehaviorBackedServiceFactory.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -26,7 +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.protocol.v1.WSRP1ConsumerBaseTest;
import org.gatein.wsrp.services.MarkupService;
import org.gatein.wsrp.services.PortletManagementService;
import org.gatein.wsrp.services.RegistrationService;
@@ -64,10 +64,6 @@
{
private BehaviorRegistry registry;
private final static String MARKUP = "markup";
- private final static String SD_URL = "sd";
- private final static String M_URL = "m";
- private final static String PM_URL = "pm";
- private final static String R_URL = "r";
private boolean initialized = false;
private String wsdl = DEFAULT_WSDL_URL;
public static final String DEFAULT_WSDL_URL =
"http://example.com/producer?wsdl";
@@ -98,7 +94,7 @@
}
if (WSRPV1MarkupPortType.class.isAssignableFrom(serviceClass))
{
- String requestedMarkupBehavior =
WSRPConsumerBaseTest.getRequestedMarkupBehavior();
+ String requestedMarkupBehavior =
WSRP1ConsumerBaseTest.getRequestedMarkupBehavior();
if (requestedMarkupBehavior == null)
{
requestedMarkupBehavior = MARKUP;
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/PerUserInitCookieMarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/PerUserInitCookieMarkupBehavior.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v1/behaviors/PerUserInitCookieMarkupBehavior.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -23,11 +23,6 @@
package org.gatein.wsrp.test.protocol.v1.behaviors;
-import java.util.List;
-
-import javax.xml.soap.MimeHeaders;
-import javax.xml.ws.handler.soap.SOAPMessageContext;
-
import org.gatein.wsrp.handler.RequestHeaderClientHandler;
import org.gatein.wsrp.test.handler.MockSOAPMessage;
import org.gatein.wsrp.test.handler.MockSOAPMessageContext;
@@ -38,6 +33,10 @@
import org.oasis.wsrp.v1.V1OperationFailed;
import org.oasis.wsrp.v1.V1RegistrationContext;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import java.util.List;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -55,10 +54,10 @@
{
portletHandle = PER_USER_INIT_COOKIE_HANDLE;
}
-
+
@Override
public List<V1Extension> initCookie(V1RegistrationContext registrationContext)
throws V1InvalidRegistration,
- V1AccessDenied, V1OperationFailed
+ V1AccessDenied, V1OperationFailed
{
//Set the Cookie through the RequestHeaderClientHandler manually here since we use
a test BehaviourBackedServiceFactory instead
//of the real SOAPServiceFactory.
@@ -67,12 +66,10 @@
MimeHeaders headers = new MimeHeaders();
headers.setHeader("Set-Cookie", "name=value");
message.setMimeHeaders(headers);
-
+
RequestHeaderClientHandler rhch = new RequestHeaderClientHandler();
rhch.handleResponse(msgContext);
-
+
return super.initCookie(registrationContext);
}
-
-
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/BehaviorBackedServiceFactory.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/BehaviorBackedServiceFactory.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/BehaviorBackedServiceFactory.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -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.protocol.v2.WSRP2ConsumerBaseTest;
import org.gatein.wsrp.services.MarkupService;
import org.gatein.wsrp.services.PortletManagementService;
import org.gatein.wsrp.services.RegistrationService;
@@ -63,10 +64,6 @@
{
private BehaviorRegistry registry;
private final static String MARKUP = "markup";
- private final static String SD_URL = "sd";
- private final static String M_URL = "m";
- private final static String PM_URL = "pm";
- private final static String R_URL = "r";
private boolean initialized = false;
private String wsdl = DEFAULT_WSDL_URL;
public static final String DEFAULT_WSDL_URL =
"http://example.com/producer?wsdl";
@@ -75,7 +72,12 @@
public BehaviorBackedServiceFactory()
{
- registry = new BehaviorRegistry();
+ this(new BehaviorRegistry());
+ }
+
+ public BehaviorBackedServiceFactory(BehaviorRegistry registry)
+ {
+ this.registry = registry;
registry.registerMarkupBehavior(new SimpleMarkupBehavior());
}
@@ -92,7 +94,12 @@
}
if (WSRPV2MarkupPortType.class.isAssignableFrom(serviceClass))
{
- return (T)registry.getMarkupBehaviorFor(MARKUP);
+ String requestedMarkupBehavior =
WSRP2ConsumerBaseTest.getRequestedMarkupBehavior();
+ if (requestedMarkupBehavior == null)
+ {
+ requestedMarkupBehavior = MARKUP;
+ }
+ return (T)registry.getMarkupBehaviorFor(requestedMarkupBehavior);
}
if (WSRPV2PortletManagementPortType.class.isAssignableFrom(serviceClass))
{
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/MarkupBehavior.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -160,7 +160,14 @@
throw new NotYetImplemented();
}
- public void getMarkup(@WebParam(name = "registrationContext",
targetNamespace = "urn:oasis:names:tc:wsrp:v2:types") RegistrationContext
registrationContext, @WebParam(name = "portletContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") PortletContext portletContext,
@WebParam(name = "runtimeContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") RuntimeContext runtimeContext,
@WebParam(name = "userContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") UserContext userContext, @WebParam(name =
"markupParams", targetNamespace = "urn:oasis:names:tc:wsrp:v2:types")
MarkupParams markupParams, @WebParam(name = "markupContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<MarkupContext> markupContext, @WebParam(name = "sessionContext",
targetNamespace = "urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<SessionContext> sessionContext, @WebParam(name = "extensions",
targetNamespace = "urn:oasi!
s:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<List<Extension>> extensions) throws AccessDenied,
InconsistentParameters, InvalidCookie, InvalidHandle, InvalidRegistration, InvalidSession,
InvalidUserCategory, MissingParameters, ModifyRegistrationRequired, OperationFailed,
ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
+ public void getMarkup(@WebParam(name = "registrationContext",
targetNamespace = "urn:oasis:names:tc:wsrp:v2:types") RegistrationContext
registrationContext,
+ @WebParam(name = "portletContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") PortletContext portletContext,
+ @WebParam(name = "runtimeContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") RuntimeContext runtimeContext,
+ @WebParam(name = "userContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") UserContext userContext,
+ @WebParam(name = "markupParams", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") MarkupParams markupParams,
+ @WebParam(name = "markupContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<MarkupContext> markupContext,
+ @WebParam(name = "sessionContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<SessionContext> sessionContext,
+ @WebParam(name = "extensions", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types", mode = WebParam.Mode.OUT)
Holder<List<Extension>> extensions) throws AccessDenied,
InconsistentParameters, InvalidCookie, InvalidHandle, InvalidRegistration, InvalidSession,
InvalidUserCategory, MissingParameters, ModifyRegistrationRequired, OperationFailed,
ResourceSuspended, UnsupportedLocale, UnsupportedMimeType, UnsupportedMode,
UnsupportedWindowState
{
GetMarkup gm = new GetMarkup();
gm.setMarkupParams(markupParams);
@@ -181,6 +188,9 @@
MarkupResponse markupResponse =
WSRPTypeFactory.createMarkupResponse(markupContext.value);
modifyResponseIfNeeded(markupResponse);
+
+ markupContext.value = markupResponse.getMarkupContext();
+ sessionContext.value = markupResponse.getSessionContext();
}
public List<Extension> initCookie(@WebParam(name =
"registrationContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") RegistrationContext registrationContext,
@WebParam(name = "userContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") UserContext userContext) throws
AccessDenied, InvalidRegistration, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/BasicPortletManagementBehavior.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -143,13 +143,20 @@
WSRP2ExceptionFactory.throwMissingParametersIfValueIsMissing(portletHandles,
"portlet handles", "DestroyPortlets");
}
+ List<FailedPortlets> failedPortletsList = failedPortlets.value;
+ if (failedPortletsList == null)
+ {
+ failedPortletsList = new ArrayList<FailedPortlets>();
+ failedPortlets.value = failedPortletsList;
+ }
+
for (String handle : portletHandles)
{
if (!CLONED_HANDLE.equals(handle))
{
ArrayList<String> failed = new ArrayList<String>();
failed.add(handle);
- failedPortlets.value.add(WSRPTypeFactory.createFailedPortlets(failed,
ErrorCodes.Codes.OPERATIONFAILED, "Handle '" + handle + "'
doesn't exist"));
+ failedPortletsList.add(WSRPTypeFactory.createFailedPortlets(failed,
ErrorCodes.Codes.OPERATIONFAILED, "Handle '" + handle + "'
doesn't exist"));
}
}
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/PerUserInitCookieMarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/PerUserInitCookieMarkupBehavior.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/PerUserInitCookieMarkupBehavior.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -23,8 +23,25 @@
package org.gatein.wsrp.test.protocol.v2.behaviors;
+import org.gatein.wsrp.handler.RequestHeaderClientHandler;
+import org.gatein.wsrp.test.handler.MockSOAPMessage;
+import org.gatein.wsrp.test.handler.MockSOAPMessageContext;
import org.gatein.wsrp.test.protocol.v2.BehaviorRegistry;
+import org.oasis.wsrp.v2.AccessDenied;
+import org.oasis.wsrp.v2.Extension;
+import org.oasis.wsrp.v2.InvalidRegistration;
+import org.oasis.wsrp.v2.ModifyRegistrationRequired;
+import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.OperationNotSupported;
+import org.oasis.wsrp.v2.RegistrationContext;
+import org.oasis.wsrp.v2.ResourceSuspended;
+import org.oasis.wsrp.v2.UserContext;
+import javax.jws.WebParam;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+import java.util.List;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -42,4 +59,21 @@
{
portletHandle = PER_USER_INIT_COOKIE_HANDLE;
}
+
+ @Override
+ public List<Extension> initCookie(@WebParam(name =
"registrationContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") RegistrationContext registrationContext,
@WebParam(name = "userContext", targetNamespace =
"urn:oasis:names:tc:wsrp:v2:types") UserContext userContext) throws
AccessDenied, InvalidRegistration, ModifyRegistrationRequired, OperationFailed,
OperationNotSupported, ResourceSuspended
+ {
+ //Set the Cookie through the RequestHeaderClientHandler manually here since we use
a test BehaviourBackedServiceFactory instead
+ //of the real SOAPServiceFactory.
+ MockSOAPMessage message = new MockSOAPMessage();
+ SOAPMessageContext msgContext =
MockSOAPMessageContext.createMessageContext(message, getClass().getClassLoader());
+ MimeHeaders headers = new MimeHeaders();
+ headers.setHeader("Set-Cookie", "name=value");
+ message.setMimeHeaders(headers);
+
+ RequestHeaderClientHandler rhch = new RequestHeaderClientHandler();
+ rhch.handleResponse(msgContext);
+
+ return super.initCookie(registrationContext, userContext);
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/SessionMarkupBehavior.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/SessionMarkupBehavior.java 2010-08-19
16:17:17 UTC (rev 3875)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/protocol/v2/behaviors/SessionMarkupBehavior.java 2010-08-19
17:57:41 UTC (rev 3876)
@@ -50,6 +50,7 @@
import org.oasis.wsrp.v2.ResourceSuspended;
import org.oasis.wsrp.v2.RuntimeContext;
import org.oasis.wsrp.v2.SessionContext;
+import org.oasis.wsrp.v2.SessionParams;
import org.oasis.wsrp.v2.UnsupportedLocale;
import org.oasis.wsrp.v2.UnsupportedMimeType;
import org.oasis.wsrp.v2.UnsupportedMode;
@@ -86,7 +87,15 @@
public String getMarkupString(Mode mode, WindowState windowState, String
navigationalState, GetMarkup getMarkup)
{
StringBuffer markupString = new StringBuffer("portlet2:");
- sessionId = getMarkup.getRuntimeContext().getSessionParams().getSessionID();
+ SessionParams sessionParams = getMarkup.getRuntimeContext().getSessionParams();
+ if (sessionParams != null)
+ {
+ sessionId = sessionParams.getSessionID();
+ }
+ else
+ {
+ sessionId = null;
+ }
// if we have a session, increments count to simulate session usage
if (SESSION_ID.equals(sessionId))