gatein SVN: r703 - components/pc/trunk.
by do-not-reply@jboss.org
Author: aheritier
Date: 2009-11-19 16:03:22 -0500 (Thu, 19 Nov 2009)
New Revision: 703
Modified:
components/pc/trunk/pom.xml
Log:
update gatein-parent 1.0.0-Beta03 -> 1.0.0-Beta04
Modified: components/pc/trunk/pom.xml
===================================================================
--- components/pc/trunk/pom.xml 2009-11-19 20:56:04 UTC (rev 702)
+++ components/pc/trunk/pom.xml 2009-11-19 21:03:22 UTC (rev 703)
@@ -12,7 +12,7 @@
<parent>
<groupId>org.gatein</groupId>
<artifactId>gatein-parent</artifactId>
- <version>1.0.0-Beta03</version>
+ <version>1.0.0-Beta04</version>
</parent>
<scm>
15 years, 1 month
gatein SVN: r702 - components/mop/trunk.
by do-not-reply@jboss.org
Author: aheritier
Date: 2009-11-19 15:56:04 -0500 (Thu, 19 Nov 2009)
New Revision: 702
Modified:
components/mop/trunk/pom.xml
Log:
update gatein-parent 1.0.0-Beta03 -> 1.0.0-Beta04
Modified: components/mop/trunk/pom.xml
===================================================================
--- components/mop/trunk/pom.xml 2009-11-19 20:53:18 UTC (rev 701)
+++ components/mop/trunk/pom.xml 2009-11-19 20:56:04 UTC (rev 702)
@@ -25,7 +25,7 @@
<parent>
<groupId>org.gatein</groupId>
<artifactId>gatein-parent</artifactId>
- <version>1.0.0-Beta03</version>
+ <version>1.0.0-Beta04</version>
</parent>
<!-- ****************** -->
15 years, 1 month
gatein SVN: r701 - components/common/trunk.
by do-not-reply@jboss.org
Author: aheritier
Date: 2009-11-19 15:53:18 -0500 (Thu, 19 Nov 2009)
New Revision: 701
Modified:
components/common/trunk/pom.xml
Log:
update gatein-parent 1.0.0-Beta03 -> 1.0.0-Beta04
Modified: components/common/trunk/pom.xml
===================================================================
--- components/common/trunk/pom.xml 2009-11-19 20:50:20 UTC (rev 700)
+++ components/common/trunk/pom.xml 2009-11-19 20:53:18 UTC (rev 701)
@@ -12,7 +12,7 @@
<parent>
<groupId>org.gatein</groupId>
<artifactId>gatein-parent</artifactId>
- <version>1.0.0-Beta03</version>
+ <version>1.0.0-Beta04</version>
</parent>
<scm>
15 years, 1 month
gatein SVN: r699 - tools/packager/trunk.
by do-not-reply@jboss.org
Author: aheritier
Date: 2009-11-19 15:47:32 -0500 (Thu, 19 Nov 2009)
New Revision: 699
Modified:
tools/packager/trunk/pom.xml
Log:
update gatein-parent 1.0.0-Beta03 -> 1.0.0-Beta04
Modified: tools/packager/trunk/pom.xml
===================================================================
--- tools/packager/trunk/pom.xml 2009-11-19 20:43:49 UTC (rev 698)
+++ tools/packager/trunk/pom.xml 2009-11-19 20:47:32 UTC (rev 699)
@@ -22,7 +22,7 @@
<parent>
<groupId>org.gatein</groupId>
<artifactId>gatein-parent</artifactId>
- <version>1.0.0-Beta03</version>
+ <version>1.0.0-Beta04</version>
</parent>
<modelVersion>4.0.0</modelVersion>
15 years, 1 month
gatein SVN: r698 - tools/maven/dep/trunk.
by do-not-reply@jboss.org
Author: aheritier
Date: 2009-11-19 15:43:49 -0500 (Thu, 19 Nov 2009)
New Revision: 698
Modified:
tools/maven/dep/trunk/pom.xml
Log:
upgrade jboss-parent to v 5-beta-5
Modified: tools/maven/dep/trunk/pom.xml
===================================================================
--- tools/maven/dep/trunk/pom.xml 2009-11-19 20:35:09 UTC (rev 697)
+++ tools/maven/dep/trunk/pom.xml 2009-11-19 20:43:49 UTC (rev 698)
@@ -14,7 +14,7 @@
<parent>
<artifactId>jboss-parent</artifactId>
<groupId>org.jboss</groupId>
- <version>5-beta-4</version>
+ <version>5-beta-5</version>
</parent>
<scm>
15 years, 1 month
gatein SVN: r696 - tools/maven/parent/tags.
by do-not-reply@jboss.org
Author: aheritier
Date: 2009-11-19 15:35:01 -0500 (Thu, 19 Nov 2009)
New Revision: 696
Added:
tools/maven/parent/tags/1.0.0-Beta04/
Log:
[maven-scm] copy for tag 1.0.0-Beta04
Copied: tools/maven/parent/tags/1.0.0-Beta04 (from rev 695, tools/maven/parent/trunk)
15 years, 1 month
gatein SVN: r694 - in components/wsrp/trunk: producer and 11 other directories.
by do-not-reply@jboss.org
Author: chris.laprun(a)jboss.com
Date: 2009-11-19 14:58:55 -0500 (Thu, 19 Nov 2009)
New Revision: 694
Added:
components/wsrp/trunk/producer/src/test/
components/wsrp/trunk/producer/src/test/java/
components/wsrp/trunk/producer/src/test/java/org/
components/wsrp/trunk/producer/src/test/java/org/gatein/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/AbsoluteURLReplacementGeneratorTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestEntityResolver.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/registration/
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/registration/RegistrationPropertyDescriptionTestCase.java
Modified:
components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java
components/wsrp/trunk/producer/pom.xml
Log:
- Added missing methods in WSRPUtils.
- Added producer tests which compiles but don't currently work, so they are deactivated.
Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java 2009-11-19 18:14:17 UTC (rev 693)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/WSRPUtils.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -417,6 +417,33 @@
return desc;
}
+ public static PropertyDescription convertToPropertyDescription(RegistrationPropertyDescription propertyDescription)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyDescription, "RegistrationPropertyDescription");
+ PropertyDescription propDesc = WSRPTypeFactory.createPropertyDescription(propertyDescription.getName().toString(),
+ propertyDescription.getType());
+
+ // todo: deal with languages properly!!
+ LocalizedString hint = propertyDescription.getHint();
+ if (hint != null)
+ {
+ propDesc.setHint(convertToWSRPLocalizedString(hint));
+ }
+ LocalizedString label = propertyDescription.getLabel();
+ if (label != null)
+ {
+ propDesc.setLabel(convertToWSRPLocalizedString(label));
+ }
+ return propDesc;
+ }
+
+ public static org.oasis.wsrp.v1.LocalizedString convertToWSRPLocalizedString(LocalizedString regLocalizedString)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(regLocalizedString, "LocalizedString");
+ return WSRPTypeFactory.createLocalizedString(toString(regLocalizedString.getLocale()),
+ regLocalizedString.getResourceName(), regLocalizedString.getValue());
+ }
+
private static LocalizedString getLocalizedStringOrNull(org.oasis.wsrp.v1.LocalizedString wsrpLocalizedString)
{
if (wsrpLocalizedString == null)
Modified: components/wsrp/trunk/producer/pom.xml
===================================================================
--- components/wsrp/trunk/producer/pom.xml 2009-11-19 18:14:17 UTC (rev 693)
+++ components/wsrp/trunk/producer/pom.xml 2009-11-19 19:58:55 UTC (rev 694)
@@ -21,7 +21,8 @@
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.gatein.wsrp</groupId>
<artifactId>wsrp-parent</artifactId>
@@ -41,7 +42,7 @@
<groupId>org.gatein.wsrp</groupId>
<artifactId>wsrp-common</artifactId>
</dependency>
-
+
<dependency>
<groupId>org.gatein.common</groupId>
<artifactId>common-common</artifactId>
@@ -58,7 +59,7 @@
<groupId>org.gatein.pc</groupId>
<artifactId>pc-federation</artifactId>
</dependency>
-
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@@ -75,6 +76,28 @@
<groupId>org.jboss</groupId>
<artifactId>jbossxb</artifactId>
</dependency>
+
+ <!-- tests -->
+ <dependency>
+ <groupId>org.gatein.wsrp</groupId>
+ <artifactId>test-framework</artifactId>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
+ <!-- Disable some tests for now until we can find some time to work on migrating them -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>org/gatein/wsrp/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
\ No newline at end of file
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/AbsoluteURLReplacementGeneratorTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/AbsoluteURLReplacementGeneratorTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/AbsoluteURLReplacementGeneratorTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,65 @@
+/*
+* 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.gatein.wsrp.producer;
+
+import junit.framework.TestCase;
+import org.gatein.wsrp.test.support.MockHttpServletRequest;
+
+import static org.gatein.wsrp.producer.AbsoluteURLReplacementGenerator.PORT_END;
+import static org.gatein.wsrp.producer.AbsoluteURLReplacementGenerator.SCH_END;
+import static org.gatein.wsrp.test.support.MockHttpServletRequest.*;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class AbsoluteURLReplacementGeneratorTestCase extends TestCase
+{
+ private AbsoluteURLReplacementGenerator gen;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ gen = new AbsoluteURLReplacementGenerator(MockHttpServletRequest.createMockRequest(null));
+ }
+
+ public void testNonAbsoluteURL()
+ {
+ String url = "foo";
+ assertEquals(url, gen.getAbsoluteURLFor(url));
+ }
+
+ public void testAbsoluteURL()
+ {
+ String url = "/foo";
+ assertEquals(scheme + SCH_END + serverName + PORT_END + serverPort + url, gen.getAbsoluteURLFor(url));
+ }
+
+ public void testWSRPEncodedURL()
+ {
+ String url = "wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite";
+ assertEquals(url, gen.getAbsoluteURLFor(url));
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/AbsoluteURLReplacementGeneratorTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,67 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.gatein.wsrp.producer;
+
+import junit.framework.TestCase;
+import org.gatein.common.NotYetImplemented;
+
+/**
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.org">Boleslaw Dawidowicz</a>
+ * @version $Revision: 8808 $
+ */
+public abstract class WSRPProducerBaseTest extends TestCase
+{
+
+ /** . */
+ protected WSRPProducerImpl producer = WSRPProducerImpl.getInstance();
+ protected RegistrationInterface registrationService;
+ protected ServiceDescriptionInterface serviceDescriptionService;
+ protected MarkupInterface markupService;
+ protected PortletManagementInterface portletManagementService;
+
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ serviceDescriptionService = producer.getServiceDescriptionInterface();
+ markupService = producer.getMarkupInterface();
+ registrationService = producer.getRegistrationInterface();
+ portletManagementService = producer.getPortletManagementInterface();
+ }
+
+ protected WSRPProducerBaseTest(String name) throws Exception
+ {
+ super(name);
+ }
+
+ public void deploy(String warFileName) throws Exception
+ {
+ throw new NotYetImplemented("deploy");
+ }
+
+ public void undeploy(String warFileName) throws Exception
+ {
+ throw new NotYetImplemented("undeploy");
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,353 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.gatein.wsrp.producer.config;
+
+import junit.framework.TestCase;
+import org.gatein.registration.RegistrationPolicy;
+import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.registration.policies.DefaultRegistrationPropertyValidator;
+import org.gatein.registration.policies.RegistrationPropertyValidator;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.producer.config.impl.ProducerConfigurationImpl;
+import org.gatein.wsrp.producer.config.impl.xml.ProducerConfigurationFactory;
+import org.gatein.wsrp.producer.config.impl.xml.ProducerConfigurationProvider;
+import org.gatein.wsrp.registration.LocalizedString;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.jboss.xb.binding.JBossXBException;
+import org.jboss.xb.binding.ObjectModelFactory;
+import org.jboss.xb.binding.ObjectModelProvider;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.XercesXsMarshaller;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.xml.sax.SAXException;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URL;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 10408 $
+ * @since 2.6
+ */
+public class ProducerConfigurationTestCase extends TestCase
+{
+ private Unmarshaller unmarshaller;
+ private ObjectModelFactory factory;
+
+ private static DefaultSchemaResolver RESOLVER;
+
+ static
+ {
+ RESOLVER = new DefaultSchemaResolver();
+ RESOLVER.setCacheResolvedSchemas(true);
+ RESOLVER.addSchemaLocation("http://www.w3.org/XML/1998/namespace", "xsd/xml.xsd");
+ RESOLVER.addSchemaLocation("urn:jboss:portal:wsrp:producer:v2_7", "xsd/jboss-wsrp-producer_2_7.xsd");
+ }
+
+ protected void setUp() throws Exception
+ {
+ unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ factory = new ProducerConfigurationFactory();
+ unmarshaller.setEntityResolver(new org.gatein.wsrp.producer.config.TestEntityResolver());
+ }
+
+ public void testCustomPolicyUnmarshalling() throws Exception
+ {
+ ProducerConfiguration producerConfiguration = getProducerConfiguration("custom-policy.xml");
+ assertTrue(producerConfiguration.isUsingStrictMode());
+
+ ProducerRegistrationRequirements requirements = producerConfiguration.getRegistrationRequirements();
+ assertNotNull(requirements);
+ RegistrationPolicy policy = requirements.getPolicy();
+ assertTrue(policy instanceof TestRegistrationPolicy);
+ }
+
+ public void testExtendedUnmarshalling() throws Exception
+ {
+ ProducerConfiguration producerConfiguration = getProducerConfiguration("extended.xml");
+ assertTrue(producerConfiguration.isUsingStrictMode());
+
+ ProducerRegistrationRequirements requirements = producerConfiguration.getRegistrationRequirements();
+ assertNotNull(requirements);
+ RegistrationPolicy policy = requirements.getPolicy();
+ assertTrue(policy instanceof DefaultRegistrationPolicy);
+ RegistrationPropertyValidator propertyValidator = ((DefaultRegistrationPolicy)policy).getValidator();
+ assertNotNull(propertyValidator);
+ assertTrue(propertyValidator instanceof DefaultRegistrationPropertyValidator);
+ assertTrue(requirements.isRegistrationRequired());
+ assertTrue(requirements.isRegistrationRequiredForFullDescription());
+ Map properties = requirements.getRegistrationProperties();
+ assertNotNull(properties);
+ assertEquals(2, properties.size());
+
+ checkRegistrationProperty(requirements, 1);
+ checkRegistrationProperty(requirements, 2);
+ }
+
+ public void testMinimalRegistrationUnmarshalling() throws Exception
+ {
+ ProducerConfiguration producerConfiguration = getProducerConfiguration("minimal-registration.xml");
+ assertTrue(producerConfiguration.isUsingStrictMode());
+
+ ProducerRegistrationRequirements requirements = producerConfiguration.getRegistrationRequirements();
+ assertNotNull(requirements);
+ assertTrue(requirements.isRegistrationRequired());
+ assertTrue(!requirements.isRegistrationRequiredForFullDescription());
+ Map properties = requirements.getRegistrationProperties();
+ assertNotNull(properties);
+ assertTrue(properties.isEmpty());
+ assertNotNull(requirements.getPolicy());
+ }
+
+ public void testMinimalUnmarshalling() throws Exception
+ {
+ ProducerConfiguration producerConfiguration = getProducerConfiguration("minimal.xml");
+ assertTrue(producerConfiguration.isUsingStrictMode());
+
+ ProducerRegistrationRequirements requirements = producerConfiguration.getRegistrationRequirements();
+ assertNotNull(requirements);
+ assertFalse(requirements.isRegistrationRequired());
+ assertFalse(requirements.isRegistrationRequiredForFullDescription());
+ assertTrue(requirements.getRegistrationProperties().isEmpty());
+ assertNull(requirements.getPolicy());
+ }
+
+ public void testInvalidMultipleRegistrationConfiguration() throws Exception
+ {
+ try
+ {
+ getProducerConfiguration("invalid2.xml");
+ fail("Only one registration-configuration element allowed!");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testInvalidTypeValue() throws Exception
+ {
+ try
+ {
+ getProducerConfiguration("invalid-type.xml");
+ fail("Invalid type for property description should fail.");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testInvalidPropertyValidator()
+ {
+ try
+ {
+ getProducerConfiguration("invalid3.xml");
+ fail("Doesn't make sense to define a property validator if a registration policy other than DefaultRegistrationPolicy");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testInvalidFullServiceDescriptionValue()
+ {
+ try
+ {
+ getProducerConfiguration("invalid1.xml");
+ fail("Invalid value for fullServiceDescriptionRequiresRegistration should have caused failure");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testUseStrictMode() throws IOException, JBossXBException
+ {
+ ProducerConfiguration producerConfiguration = getProducerConfiguration("strict-mode.xml");
+ assertFalse(producerConfiguration.isUsingStrictMode());
+ }
+
+ public void testChangeListeners() throws IOException, JBossXBException
+ {
+ ProducerConfiguration producerConfiguration = getProducerConfiguration("minimal.xml");
+ assertTrue(producerConfiguration.isUsingStrictMode());
+
+ TestProducerConfigurationChangeListener listener = new TestProducerConfigurationChangeListener();
+ producerConfiguration.addChangeListener(listener);
+ assertFalse(listener.called);
+
+ // we're not changing the value, the listeners shouldn't be called
+ producerConfiguration.setUsingStrictMode(true);
+ assertFalse(listener.called);
+
+ producerConfiguration.setUsingStrictMode(false);
+ assertFalse(producerConfiguration.isUsingStrictMode());
+ assertTrue(listener.called);
+ }
+
+ public void testSaveAndReload() throws IOException, ParserConfigurationException, SAXException, JBossXBException
+ {
+ ProducerConfiguration configuration = new ProducerConfigurationImpl();
+ configuration.setUsingStrictMode(false);
+ ProducerRegistrationRequirements registrationRequirements = configuration.getRegistrationRequirements();
+ registrationRequirements.setRegistrationRequiredForFullDescription(true);
+ registrationRequirements.setRegistrationRequired(true);
+ String prop1 = "prop1";
+ registrationRequirements.addEmptyRegistrationProperty(prop1);
+ registrationRequirements.getRegistrationPropertyWith(prop1).setDefaultLabel("label1");
+ String prop2 = "prop2";
+ registrationRequirements.addEmptyRegistrationProperty(prop2);
+ registrationRequirements.getRegistrationPropertyWith(prop2).setDefaultHint("hint2");
+ String prop3 = "prop3";
+ registrationRequirements.addEmptyRegistrationProperty(prop3);
+ registrationRequirements.getRegistrationPropertyWith(prop3).setDefaultDescription("description3");
+ String prop4 = "prop4";
+ registrationRequirements.addEmptyRegistrationProperty(prop4);
+ RegistrationPropertyDescription propDesc4 = registrationRequirements.getRegistrationPropertyWith(prop4);
+ propDesc4.setDefaultLabel("label4");
+ propDesc4.setDefaultHint("hint4");
+ propDesc4.setDefaultDescription("description4");
+
+ File tmp = File.createTempFile("producer-configuration-test-case", "xml");
+ tmp.deleteOnExit();
+
+ writeConfigToFile(configuration, tmp);
+
+ configuration = getProducerConfiguration(tmp.toURL());
+
+ assertFalse(configuration.isUsingStrictMode());
+
+ registrationRequirements = configuration.getRegistrationRequirements();
+ assertTrue(registrationRequirements.isRegistrationRequired());
+ assertTrue(registrationRequirements.isRegistrationRequiredForFullDescription());
+
+ assertEquals(4, registrationRequirements.getRegistrationProperties().size());
+ assertEquals("label1", registrationRequirements.getRegistrationPropertyWith(prop1).getLabel().getValue());
+ assertEquals("hint2", registrationRequirements.getRegistrationPropertyWith(prop2).getHint().getValue());
+ assertEquals("description3", registrationRequirements.getRegistrationPropertyWith(prop3).getDescription().getValue());
+ propDesc4 = registrationRequirements.getRegistrationPropertyWith(prop4);
+ assertEquals("label4", propDesc4.getLabel().getValue());
+ assertEquals("hint4", propDesc4.getHint().getValue());
+ assertEquals("description4", propDesc4.getDescription().getValue());
+ }
+
+ private void writeConfigToFile(ProducerConfiguration configuration, File file)
+ throws IOException, ParserConfigurationException, SAXException
+ {
+ StringWriter xmlOutput = new StringWriter();
+
+ // get the XML Schema source
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("xsd/jboss-wsrp-producer_2_7.xsd");
+
+ Reader xsReader = new InputStreamReader(is);
+
+ // create an instance of XML Schema marshaller
+ XercesXsMarshaller marshaller = new XercesXsMarshaller();
+
+ marshaller.setSchemaResolver(RESOLVER);
+
+ // we need to specify what elements are top most (roots) providing namespace URI, prefix and local name
+ marshaller.addRootElement("urn:jboss:portal:wsrp:producer:v2_7", "", "producer-configuration");
+
+ // declare default namespace
+ marshaller.declareNamespace("wpc", "urn:jboss:portal:wsrp:producer:v2_7");
+
+ // add schema location by declaring xsi namespace and adding xsi:schemaLocation attribute
+ marshaller.declareNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
+ marshaller.addAttribute("xsi", "schemaLocation", "string",
+ "urn:jboss:portal:wsrp:producer:v2_7 http://www.jboss.org/portal/xsd/jboss-wsrp-producer_2_7.xsd");
+
+ // create an instance of Object Model Provider
+ ObjectModelProvider provider = new ProducerConfigurationProvider();
+
+ marshaller.setProperty("org.jboss.xml.binding.marshalling.indent", "true");
+ marshaller.marshal(xsReader, provider, configuration, xmlOutput);
+
+ // close XML Schema reader
+ xsReader.close();
+
+ file.createNewFile();
+ Writer configFile = new BufferedWriter(new FileWriter(file));
+ configFile.write(xmlOutput.toString());
+ configFile.flush();
+ configFile.close();
+ }
+
+ private ProducerConfiguration getProducerConfiguration(String fileName) throws JBossXBException, IOException
+ {
+ URL location = Thread.currentThread().getContextClassLoader().getResource(fileName);
+ assertNotNull(location);
+ System.out.println("location = " + location);
+
+ return getProducerConfiguration(location);
+ }
+
+ private ProducerConfiguration getProducerConfiguration(URL location) throws JBossXBException, IOException
+ {
+ Object o = unmarshaller.unmarshal(location.openStream(), factory, null);
+ assertNotNull(o);
+ assertTrue(o instanceof ProducerConfiguration);
+ return (ProducerConfiguration)o;
+ }
+
+ private void checkRegistrationProperty(ProducerRegistrationRequirements requirements, int index)
+ {
+ RegistrationPropertyDescription desc = requirements.getRegistrationPropertyWith("name" + index);
+ assertNotNull(desc);
+ assertEquals(new QName("name" + index), desc.getName());
+ assertEquals(WSRPConstants.XSD_STRING, desc.getType());
+
+ LocalizedString localizedString = new LocalizedString("hint" + index, Locale.ENGLISH);
+ localizedString.setResourceName("resource.hint" + index);
+ localizedString.setValue("hint" + index);
+ assertEquals(localizedString, desc.getHint());
+
+ localizedString = new LocalizedString("label" + index, Locale.ENGLISH);
+ localizedString.setResourceName("resource.label" + index);
+ localizedString.setValue("label" + index);
+ assertEquals(localizedString, desc.getLabel());
+ }
+
+ private static class TestProducerConfigurationChangeListener implements ProducerConfigurationChangeListener
+ {
+ boolean called = false;
+
+ public void usingStrictModeChangedTo(boolean strictMode)
+ {
+ called = true;
+ }
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/ProducerConfigurationTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestEntityResolver.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestEntityResolver.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestEntityResolver.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,66 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.gatein.wsrp.producer.config;
+
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class TestEntityResolver implements EntityResolver
+{
+ private static final String CONSUMER = "-//JBoss Portal//DTD WSRP Remote Producer Configuration 2.6//EN";
+ private static final String PRODUCER = "-//JBoss Portal//DTD WSRP Local Producer Configuration 2.6//EN";
+
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException
+ {
+ String dtd;
+ if (PRODUCER.equals(publicId))
+ {
+ dtd = "jboss-wsrp-producer_2_6.dtd";
+ }
+ else if (CONSUMER.equals(publicId))
+ {
+ dtd = "jboss-wsrp-consumer_2_6.dtd";
+ }
+ else
+ {
+ return null;
+ }
+
+ InputStream dtdStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(dtd);
+ if (dtdStream != null)
+ {
+ return new InputSource(dtdStream);
+ }
+
+ return null;
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestEntityResolver.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,81 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.producer.config;
+
+import org.gatein.registration.InvalidConsumerDataException;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationManager;
+import org.gatein.registration.RegistrationPolicy;
+import org.gatein.wsrp.registration.PropertyDescription;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 11406 $
+ * @since 2.6
+ */
+public class TestRegistrationPolicy implements RegistrationPolicy
+{
+ public void validateRegistrationDataFor(Map<QName, ? extends PropertyDescription> registrationProperties, String consumerIdentity) throws IllegalArgumentException, RegistrationException
+ {
+ }
+
+ public String createRegistrationHandleFor(String registrationId) throws IllegalArgumentException
+ {
+ return null;
+ }
+
+ public String getAutomaticGroupNameFor(String consumerName) throws IllegalArgumentException
+ {
+ return null;
+ }
+
+ public String getConsumerIdFrom(String consumerName, Map registrationProperties) throws IllegalArgumentException, InvalidConsumerDataException
+ {
+ return null;
+ }
+
+ public void validateConsumerName(String consumerName) throws IllegalArgumentException, RegistrationException
+ {
+ }
+
+ public void validateConsumerGroupName(String groupName) throws IllegalArgumentException, RegistrationException
+ {
+ }
+
+ public RegistrationManager getManager()
+ {
+ return null;
+ }
+
+ public void setManager(RegistrationManager manager)
+ {
+ }
+
+ public void setExpectations(Map<QName, ? extends PropertyDescription> registrationPropertyDescriptions)
+ {
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/config/TestRegistrationPolicy.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,777 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2009, 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.wsrp.WSRPActionURL;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPPortletURL;
+import org.gatein.wsrp.WSRPRenderURL;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.oasis.wsrp.v1.BlockingInteractionResponse;
+import org.oasis.wsrp.v1.CacheControl;
+import org.oasis.wsrp.v1.GetMarkup;
+import org.oasis.wsrp.v1.InitCookie;
+import org.oasis.wsrp.v1.InteractionParams;
+import org.oasis.wsrp.v1.InvalidRegistration;
+import org.oasis.wsrp.v1.MarkupContext;
+import org.oasis.wsrp.v1.MarkupResponse;
+import org.oasis.wsrp.v1.NamedString;
+import org.oasis.wsrp.v1.OperationFailed;
+import org.oasis.wsrp.v1.PerformBlockingInteraction;
+import org.oasis.wsrp.v1.PortletContext;
+import org.oasis.wsrp.v1.RuntimeContext;
+import org.oasis.wsrp.v1.SessionContext;
+import org.oasis.wsrp.v1.StateChange;
+import org.oasis.wsrp.v1.UnsupportedMode;
+import org.oasis.wsrp.v1.UpdateResponse;
+
+import java.rmi.RemoteException;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 13149 $
+ * @since 2.4
+ */
+public class MarkupTestCase extends NeedPortletHandleTest
+{
+ private static final String DEFAULT_VIEW_MARKUP = "<p>symbol unset stock value: value unset</p>";
+ private static final String DEFAULT_MARKUP_PORTLET_WAR = "test-markup-portlet.war";
+
+ public MarkupTestCase()
+ throws Exception
+ {
+ super("MarkupTestCase", DEFAULT_MARKUP_PORTLET_WAR);
+ }
+
+ public void testGetMarkupViewNoSession() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+
+ checkMarkupResponse(response, DEFAULT_VIEW_MARKUP);
+ }
+
+ public void testInvalidGetMarkup() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+ getMarkup.getMarkupParams().setMode("invalid mode");
+
+ try
+ {
+ markupService.getMarkup(getMarkup);
+ ExtendedAssert.fail();
+ }
+ catch (UnsupportedMode unsupportedMode)
+ {
+ // expected
+ }
+ }
+
+ public void testGetMarkupWithSessionID() throws Exception
+ {
+ // The consumer should never have access to or be able to set a sessionID. Sessions are handled by the Producer using cookies.
+ GetMarkup getMarkup = createMarkupRequest();
+ getMarkup.getRuntimeContext().setSessionID("Hello World");
+
+ try
+ {
+ markupService.getMarkup(getMarkup);
+ ExtendedAssert.fail("A sessionID should not be allowed to be passed in GetMarkup()");
+ }
+ catch (OperationFailed operationFailed)
+ {
+ // expected
+ }
+ }
+
+ public void testGetMarkupEditNoSession() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+ getMarkup.getMarkupParams().setMode(WSRPConstants.EDIT_MODE);
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+
+ checkMarkupResponse(response, "<form method='post' action='wsrp_rewrite?wsrp-urlType=blockingAction&wsrp" +
+ "-interactionState=JBPNS_/wsrp_rewrite' id='wsrp_rewrite_portfolioManager'><table><tr><td>Stock symbol</t" +
+ "d><td><input name='symbol'/></td></tr><tr><td><input type='submit' value='Submit'></td></tr></table></form>");
+ }
+
+ public void testGetMarkupRenderParameters() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archiveName = "test-renderparam-portlet.war";
+ deploy(archiveName);
+
+ try
+ {
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = markupService.getMarkup(gm);
+
+ String markupString = res.getMarkupContext().getMarkupString();
+
+ String julienLink = extractLink(markupString, 0);
+ WSRPPortletURL julienURL = WSRPPortletURL.create(julienLink);
+
+ ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Anonymous!");
+ ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 0");
+
+ ExtendedAssert.assertTrue(julienURL instanceof WSRPRenderURL);
+ WSRPRenderURL julienRender = (WSRPRenderURL)julienURL;
+
+ // We're now trying to get a hello for Julien ;)
+ gm.getMarkupParams().setNavigationalState(julienRender.getNavigationalState().getStringValue());
+ res = markupService.getMarkup(gm);
+ markupString = res.getMarkupContext().getMarkupString();
+ ExtendedAssert.assertString1ContainsString2(markupString, "Hello, Julien!");
+
+ // julien.length() * 2 to bypass second link
+ WSRPPortletURL incrementURL = WSRPPortletURL.create(extractLink(markupString, julienLink.length() * 2));
+ ExtendedAssert.assertTrue(incrementURL instanceof WSRPActionURL);
+ WSRPActionURL incrementAction = (WSRPActionURL)incrementURL;
+
+ // let's see now if we can increment the counter
+ PerformBlockingInteraction performBlockingInteraction =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
+ interactionParams.setInteractionState(incrementAction.getInteractionState().getStringValue());
+ markupService.performBlockingInteraction(performBlockingInteraction);
+ res = markupService.getMarkup(gm);
+ markupString = res.getMarkupContext().getMarkupString();
+ ExtendedAssert.assertString1ContainsString2(markupString, "Counter: 1");
+ }
+ finally
+ {
+ undeploy(archiveName);
+ }
+ }
+
+ private String extractLink(String markupString, int fromIndex)
+ {
+ int urlStartIndex = markupString.indexOf("='", fromIndex);
+ int urlEndIndex = markupString.indexOf("'>", urlStartIndex);
+ return markupString.substring(urlStartIndex + 2, urlEndIndex);
+ }
+
+ // fix-me: add more tests
+ public void testGetMarkupSession() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ // deploy session-manipulating portlet
+ String sessionPortletArchive = "test-session-portlet.war";
+ deploy(sessionPortletArchive);
+
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+
+ checkMarkupResponseWithSession(response, 0);
+
+ response = markupService.getMarkup(getMarkup);
+ checkMarkupResponseWithSession(response, 1);
+
+ // fix-me: try to reuse the old session id: what should happen?
+// runtimeContext.setSessionID(sessionID);
+// getMarkup.setRuntimeContext(runtimeContext);
+// try
+// {
+// markupService.getMarkup(getMarkup);
+// fail("The session should be invalid...");
+// }
+// catch (InvalidSessionFault expected)
+// {
+// }
+ }
+ finally
+ {
+ // reset state
+ undeploy(sessionPortletArchive);
+ }
+ }
+
+ public void testPerformBlockingInteractionNoRedirect() throws Exception
+ {
+ checkPBIAndGetNavigationalState("RHAT");
+ }
+
+ public void testPerformBlockingInteractionRedirect() throws Exception
+ {
+ PerformBlockingInteraction performBlockingInteraction =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getDefaultHandle());
+ InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
+
+ // crappy way but this is a test! ;)
+ NamedString namedString = new NamedString();
+ namedString.setName("symbol");
+ namedString.setValue("HELP");
+ interactionParams.getFormParameters().add(namedString);
+
+ BlockingInteractionResponse response = markupService.performBlockingInteraction(performBlockingInteraction);
+ ExtendedAssert.assertNotNull(response);
+
+ // this is a redirect...
+ String redirectURL = response.getRedirectURL();
+ ExtendedAssert.assertNotNull(redirectURL);
+ ExtendedAssert.assertEquals("/WEB-INF/jsp/help.jsp", redirectURL); // fix-me: handle URL re-writing
+
+ // no update response
+ UpdateResponse updateResponse = response.getUpdateResponse();
+ ExtendedAssert.assertNull(updateResponse);
+ }
+
+ public void testGMAndPBIInteraction() throws Exception
+ {
+ testGetMarkupViewNoSession();
+ String symbol = "AAPL";
+ String navigationalState = checkPBIAndGetNavigationalState(symbol);
+
+ GetMarkup getMarkup = createMarkupRequest();
+ getMarkup.getMarkupParams().setNavigationalState(navigationalState);
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, "<p>" + symbol + " stock value: 123.45</p>");
+ }
+
+
+ public void testPBIWithSessionID() throws Exception
+ {
+ String portletHandle = getDefaultHandle();
+ PerformBlockingInteraction performBlockingInteraction = WSRPTypeFactory.createDefaultPerformBlockingInteraction(portletHandle);
+
+ RuntimeContext runtimeContext = performBlockingInteraction.getRuntimeContext();
+ //the sessionID should never be set by the consumer. Sessions are handled by cookies instead
+ runtimeContext.setSessionID("Hello World");
+
+ try
+ {
+ markupService.performBlockingInteraction(performBlockingInteraction);
+ ExtendedAssert.fail("Should not be able to pass a sessionID in a PerformBlockingInteraction()");
+ }
+ catch (OperationFailed expected)
+ {
+ // expected
+ }
+ }
+
+ public void testMarkupCaching() throws Exception
+ {
+ GetMarkup getMarkup = createMarkupRequest();
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+
+ CacheControl cacheControl = response.getMarkupContext().getCacheControl();
+ ExtendedAssert.assertNotNull(cacheControl);
+ ExtendedAssert.assertEquals(WSRPConstants.CACHE_PER_USER, cacheControl.getUserScope());
+ ExtendedAssert.assertEquals(15, cacheControl.getExpires());
+
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String sessionPortletArchive = "test-session-portlet.war";
+ deploy(sessionPortletArchive);
+
+ response = markupService.getMarkup(createMarkupRequestForCurrentlyDeployedPortlet());
+
+ cacheControl = response.getMarkupContext().getCacheControl();
+ ExtendedAssert.assertNull(cacheControl);
+
+ undeploy(sessionPortletArchive);
+ }
+
+ public void testGetMarkupWithDispatcherPortlet() throws Exception
+ {
+
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String dispatcherPortletArchive = "test-dispatcher-portlet.war";
+ deploy(dispatcherPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, "test");
+ }
+ finally
+ {
+ undeploy(dispatcherPortletArchive);
+ }
+ }
+
+ public void testGetMarkupWithNoContent() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String basicPortletArchive = "test-basic-portlet.war";
+ deploy(basicPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, "");
+ }
+ finally
+ {
+ undeploy(basicPortletArchive);
+ }
+ }
+
+ public void testGetMarkupWithNonStandardLocalesStrictMode() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+ getMarkup.getMarkupParams().getLocales().add("en_US");
+
+ try
+ {
+ markupService.getMarkup(getMarkup);
+ //fail("Should have trown an UnsupportetLocaleFault"); // ideally cf http://jira.jboss.com/jira/browse/JBPORTAL-857
+ ExtendedAssert.fail("Should have trown an exception"); // right now
+ }
+ catch (Exception expected)
+ {
+ // expected
+ }
+ finally
+ {
+ // checkMarkupResponse(response, "GetLocalesPortlet"); // should we return try to generate markup regardless?
+ undeploy(getLocalesPortletArchive);
+ }
+ }
+
+ public void testGetMarkupWithNonStandardLocalesLenientMode() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+ getMarkup.getMarkupParams().getLocales().add("en_US");
+
+ // Use the lenient mode
+ producer.usingStrictModeChangedTo(false);
+
+ // markup should be properly generated
+ checkMarkupResponse(markupService.getMarkup(getMarkup), "English (United States)");
+ undeploy(getLocalesPortletArchive);
+ }
+
+ public void testGetMarkupWithoutDeclaredLocale() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequest(getPortletHandleFrom("No Declared"));
+
+ try
+ {
+ checkMarkupResponse(markupService.getMarkup(getMarkup), Locale.getDefault().getDisplayName());
+ }
+ finally
+ {
+ undeploy(getLocalesPortletArchive);
+ }
+ }
+
+ public void testGetMarkupLocales() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String getLocalesPortletArchive = "test-getlocales-portlet.war";
+ deploy(getLocalesPortletArchive);
+
+ GetMarkup getMarkup = createMarkupRequest(getPortletHandleFrom("Simple"));
+
+ try
+ {
+ List<String> locales = getMarkup.getMarkupParams().getLocales();
+ locales.add("en");
+ locales.add("fr");
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, Locale.ENGLISH.getDisplayName());
+
+ locales.clear();
+ locales.add("fr");
+ locales.add("en");
+ response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, Locale.FRENCH.getDisplayName());
+
+ locales.clear();
+ locales.add("de");
+ locales.add("en");
+ response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, Locale.ENGLISH.getDisplayName());
+ }
+ finally
+ {
+ undeploy(getLocalesPortletArchive);
+ }
+ }
+
+ public void testGetMarkupWithEncodedURLs() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String encodeURLPortletArchive = "test-encodeurl-portlet.war";
+ deploy(encodeURLPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, "wsrp_rewrite?wsrp-urlType=blockingAction&wsrp-interactionState=JBPNS_/wsrp_rewrite\n" +
+ "wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite");
+ }
+ finally
+ {
+ undeploy(encodeURLPortletArchive);
+ }
+ }
+
+ public void testGetMarkupWithUserContext() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String userContextPortletArchive = "test-usercontext-portlet.war";
+ deploy(userContextPortletArchive);
+
+ try
+ {
+ GetMarkup getMarkup = createMarkupRequestForCurrentlyDeployedPortlet();
+ getMarkup.setUserContext(WSRPTypeFactory.createUserContext("johndoe"));
+
+ MarkupResponse response = markupService.getMarkup(getMarkup);
+ checkMarkupResponse(response, "user: johndoe");
+ }
+ finally
+ {
+ undeploy(userContextPortletArchive);
+ }
+ }
+
+ public void testGetMarkupMultiValuedFormParams() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String multiValuedPortletArchive = "test-multivalued-portlet.war";
+ deploy(multiValuedPortletArchive);
+
+ NamedString namedString = createNamedString("multi", "value1");
+ try
+ {
+ PerformBlockingInteraction action =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ List<NamedString> formParameters = action.getInteractionParams().getFormParameters();
+ formParameters.add(namedString);
+ BlockingInteractionResponse actionResponse = markupService.performBlockingInteraction(action);
+ GetMarkup markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+ markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
+ MarkupResponse response = markupService.getMarkup(markupRequest);
+ checkMarkupResponse(response, "multi: value1");
+
+ formParameters.clear();
+ formParameters.add(namedString);
+ formParameters.add(createNamedString("multi", "value2"));
+ actionResponse = markupService.performBlockingInteraction(action);
+ markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+ markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
+ response = markupService.getMarkup(markupRequest);
+ checkMarkupResponse(response, "multi: value1, value2");
+
+ formParameters.clear();
+ formParameters.add(new NamedString());
+ actionResponse = markupService.performBlockingInteraction(action);
+ markupRequest = createMarkupRequestForCurrentlyDeployedPortlet();
+ markupRequest.getMarkupParams().setNavigationalState(actionResponse.getUpdateResponse().getNavigationalState());
+ response = markupService.getMarkup(markupRequest);
+ checkMarkupResponse(response, "multi: ");
+ }
+ finally
+ {
+ undeploy(multiValuedPortletArchive);
+ }
+ }
+
+ public void testImplicitCloning() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archiveName = "test-implicitcloning-portlet.war";
+ deploy(archiveName);
+
+ try
+ {
+ // check the initial value
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = markupService.getMarkup(gm);
+ String markupString = res.getMarkupContext().getMarkupString();
+ ExtendedAssert.assertEquals("initial", markupString);
+
+ // modify the preference value
+ PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ pbi.getInteractionParams().setPortletStateChange(StateChange.CLONE_BEFORE_WRITE); // request cloning if needed
+ String value = "new value";
+ pbi.getInteractionParams().getFormParameters().add(createNamedString("value", value));
+ BlockingInteractionResponse response = markupService.performBlockingInteraction(pbi);
+ ExtendedAssert.assertNotNull(response);
+
+ // check that we got a new portlet context
+ PortletContext pc = response.getUpdateResponse().getPortletContext();
+ ExtendedAssert.assertNotNull(pc);
+
+ // get the markup again and check that we still get the initial value with the initial portlet context
+ res = markupService.getMarkup(gm);
+ markupString = res.getMarkupContext().getMarkupString();
+ ExtendedAssert.assertEquals("initial", markupString);
+
+ // retrieving the markup with the new portlet context should return the new value
+ gm.setPortletContext(pc);
+ res = markupService.getMarkup(gm);
+ markupString = res.getMarkupContext().getMarkupString();
+ ExtendedAssert.assertEquals(value, markupString);
+ }
+ finally
+ {
+ undeploy(archiveName);
+ }
+ }
+
+ private NamedString createNamedString(String name, String value)
+ {
+ NamedString namedString = new NamedString();
+ namedString.setName(name);
+ namedString.setValue(value);
+ return namedString;
+ }
+
+ public void testGetMarkupWithResource() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archive = "test-resource-portlet.war";
+ deploy(archive);
+
+ try
+ {
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = markupService.getMarkup(gm);
+ String markupString = res.getMarkupContext().getMarkupString();
+
+ // accept either localhost or 127.0.0.1 for the host part of the generated markup
+ String markupStart = "<img src='wsrp_rewrite?wsrp-urlType=resource&wsrp-url=http%3A%2F%2F";
+ String markupEnd = "%3A8080%2Ftest-resource-portlet%2Fgif%2Flogo.gif&wsrp-requiresRewrite=true/wsrp_rewrite'/>";
+ String localhostMarkup = markupStart + "localhost" + markupEnd;
+ String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
+ boolean result = localhostMarkup.equals(markupString) || homeIPMarkup.equals(markupString);
+ ExtendedAssert.assertTrue(result);
+ }
+ finally
+ {
+ undeploy(archive);
+ }
+ }
+
+ public void testGetMarkupWithNonURLEncodedResource() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archive = "test-resourcenoencodeurl-portlet.war";
+ deploy(archive);
+
+ try
+ {
+ GetMarkup gm = createMarkupRequestForCurrentlyDeployedPortlet();
+ MarkupResponse res = markupService.getMarkup(gm);
+ String markupString = res.getMarkupContext().getMarkupString();
+
+ // accept either localhost or 127.0.0.1 for the host part of the generated markup
+ String markupStart = "<img src='http://";
+ String markupEnd = ":8080/test-resourcenoencodeurl-portlet/gif/logo.gif'/>";
+ String localhostMarkup = markupStart + "localhost" + markupEnd;
+ String homeIPMarkup = markupStart + "127.0.0.1" + markupEnd;
+ boolean result = localhostMarkup.equals(markupString) || homeIPMarkup.equals(markupString);
+ ExtendedAssert.assertTrue(result);
+ }
+ finally
+ {
+ undeploy(archive);
+ }
+ }
+
+ public void testApplicationScopeVariableHandling() throws Exception
+ {
+ undeploy(DEFAULT_MARKUP_PORTLET_WAR);
+ String archive = "test-applicationscope-portlet.war";
+ deploy(archive);
+
+ try
+ {
+ // set appVar to value in the application scope by the first portlet
+ PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getPortletHandleFrom("Set"));
+ pbi.getInteractionParams().getFormParameters().add(createNamedString("appVar", "value"));
+ markupService.performBlockingInteraction(pbi);
+
+ // the second portlet reads the appVar value and outputs it
+ GetMarkup gm = createMarkupRequest(getPortletHandleFrom("Get"));
+ MarkupResponse res = markupService.getMarkup(gm);
+ checkMarkupResponse(res, "appVar=value");
+ }
+ finally
+ {
+ undeploy(archive);
+ }
+ }
+
+ public void testGetMarkupNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ GetMarkup gm = createMarkupRequest();
+ try
+ {
+ markupService.getMarkup(gm);
+ ExtendedAssert.fail("Should have thrown InvalidRegistration!");
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ public void testPerformBlockingInteractionNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ PerformBlockingInteraction pbi = WSRPTypeFactory.createDefaultPerformBlockingInteraction(getHandleForCurrentlyDeployedArchive());
+ try
+ {
+ markupService.performBlockingInteraction(pbi);
+ ExtendedAssert.fail("Should have thrown InvalidRegistration!");
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ public void testInitCookieNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ InitCookie initCookie = WSRPTypeFactory.createInitCookie(null);
+ try
+ {
+ markupService.initCookie(initCookie);
+ ExtendedAssert.fail("Should have thrown InvalidRegistration!");
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ private String checkPBIAndGetNavigationalState(String symbol) throws Exception
+ {
+ PerformBlockingInteraction performBlockingInteraction =
+ WSRPTypeFactory.createDefaultPerformBlockingInteraction(getDefaultHandle());
+ InteractionParams interactionParams = performBlockingInteraction.getInteractionParams();
+ interactionParams.getFormParameters().add(createNamedString("symbol", symbol));
+
+ BlockingInteractionResponse response = markupService.performBlockingInteraction(performBlockingInteraction);
+ ExtendedAssert.assertNotNull(response);
+
+ // this is not a redirect...
+ ExtendedAssert.assertNull(response.getRedirectURL());
+
+ // check update response
+ UpdateResponse updateResponse = response.getUpdateResponse();
+ ExtendedAssert.assertNotNull(updateResponse);
+ // request was readOnly so no updated portlet context
+ ExtendedAssert.assertNull(updateResponse.getPortletContext());
+ // check that no sessionId is getting passed.
+ ExtendedAssert.assertNull(updateResponse.getSessionContext());
+
+ String navigationalState = updateResponse.getNavigationalState();
+ ExtendedAssert.assertNotNull(navigationalState);
+ ExtendedAssert.assertEquals(updateResponse.getNewMode(), WSRPConstants.VIEW_MODE);
+ MarkupContext markupContext = updateResponse.getMarkupContext();
+ ExtendedAssert.assertNull(markupContext); // we don't return markup for now
+
+ return navigationalState;
+ }
+
+ private void checkMarkupResponseWithSession(MarkupResponse response, int count) throws RemoteException, InvalidRegistration, OperationFailed
+ {
+ ExtendedAssert.assertNotNull(response);
+
+ // Markup context
+ MarkupContext markupContext = response.getMarkupContext();
+ ExtendedAssert.assertNotNull(markupContext);
+ String markupString = markupContext.getMarkupString();
+ ExtendedAssert.assertString1ContainsString2(markupString, "count = " + count);
+ ExtendedAssert.assertString1ContainsString2(markupString, "<a href='wsrp_rewrite?wsrp-urlType=render&wsrp-navigationalState=JBPNS_/wsrp_rewrite'>render</a>");
+
+ // checking session
+ checkSessionForCurrentlyDeployedPortlet(response);
+ }
+
+ private MarkupContext checkMarkupResponse(MarkupResponse response, String markupString)
+ {
+ ExtendedAssert.assertNotNull(response);
+
+ // Markup context
+ MarkupContext markupContext = response.getMarkupContext();
+ ExtendedAssert.assertNotNull(markupContext);
+ ExtendedAssert.assertEquals("text/html", markupContext.getMimeType());
+ ExtendedAssert.assertEquals("title", markupContext.getPreferredTitle());
+ ExtendedAssert.assertTrue(markupContext.isRequiresUrlRewriting());
+ ExtendedAssert.assertEquals(markupString, markupContext.getMarkupString());
+
+ // Session context
+ SessionContext sessionContext = response.getSessionContext();
+ // The session information is should never be sent to the consumer, Cookies are used instead.
+ ExtendedAssert.assertNull(sessionContext);
+
+ return markupContext;
+ }
+
+ protected String getMostUsedPortletWARFileName()
+ {
+ return DEFAULT_MARKUP_PORTLET_WAR;
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,248 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.gatein.wsrp.protocol.v1;
+
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.oasis.wsrp.v1.GetMarkup;
+import org.oasis.wsrp.v1.GetServiceDescription;
+import org.oasis.wsrp.v1.InvalidRegistration;
+import org.oasis.wsrp.v1.InvalidRegistrationFault;
+import org.oasis.wsrp.v1.MarkupResponse;
+import org.oasis.wsrp.v1.OperationFailed;
+import org.oasis.wsrp.v1.OperationFailedFault;
+import org.oasis.wsrp.v1.PortletDescription;
+import org.oasis.wsrp.v1.ServiceDescription;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 11547 $
+ * @since 2.4
+ */
+public abstract class NeedPortletHandleTest extends V1ProducerBaseTest
+{
+ private String mostUsedPortletWARFileName;
+ private String currentlyDeployedArchiveName;
+ private Map<String, List<String>> war2Handles = new HashMap<String, List<String>>(7);
+
+
+ public NeedPortletHandleTest(String portletWARFileName)
+ throws Exception
+ {
+ this("NeedPortletHandleTest", portletWARFileName);
+ this.mostUsedPortletWARFileName = portletWARFileName;
+ }
+
+ protected NeedPortletHandleTest(String name, String portletWARFileName)
+ throws Exception
+ {
+ super(name);
+ this.mostUsedPortletWARFileName = portletWARFileName;
+ }
+
+ protected String getDefaultHandle()
+ {
+ return getFirstHandleFor(mostUsedPortletWARFileName);
+ }
+
+ /**
+ * @param archiveName
+ * @return
+ * @since 2.6.3
+ */
+ private String getFirstHandleFor(String archiveName)
+ {
+ return war2Handles.get(archiveName).get(0);
+ }
+
+ protected String getHandleForCurrentlyDeployedArchive()
+ {
+ return getFirstHandleFor(currentlyDeployedArchiveName);
+ }
+
+ /**
+ * @return
+ * @since 2.6.3
+ */
+ protected List<String> getHandlesForCurrentlyDeployedArchive()
+ {
+ return war2Handles.get(currentlyDeployedArchiveName);
+ }
+
+ /**
+ * Each time we deploy a new archive, check to see if the service description has changed and add any new portlet
+ * handles found.
+ *
+ * @param archiveName
+ * @throws Exception
+ */
+ public void deploy(String archiveName) throws Exception
+ {
+ super.deploy(archiveName);
+ currentlyDeployedArchiveName = archiveName;
+
+ if (!war2Handles.containsKey(archiveName))
+ {
+ GetServiceDescription getServiceDescription = WSRPTypeFactory.createGetServiceDescription();
+ ServiceDescription serviceDescription = serviceDescriptionService.getServiceDescription(getServiceDescription);
+ List<PortletDescription> offered = serviceDescription.getOfferedPortlets();
+ if (offered != null)
+ {
+ for (PortletDescription portletDescription : offered)
+ {
+ String handle = portletDescription.getPortletHandle();
+ String warName = handle.substring(1, handle.indexOf('.')) + ".war";
+ if (warName.equals(archiveName))
+ {
+ List<String> handles = war2Handles.get(warName);
+ if (handles == null)
+ {
+ handles = new ArrayList<String>(3);
+ war2Handles.put(warName, handles);
+ }
+
+ handles.add(handle);
+ }
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException(archiveName + " didn't contain any portlets...");
+ }
+ }
+ }
+
+ public void undeploy(String archiveName) throws Exception
+ {
+ try
+ {
+ super.undeploy(archiveName);
+ }
+ catch (Exception e)
+ {
+ // if an exception occurred the portlet is still probably deployed, so just exit
+ e.printStackTrace();
+ return;
+ }
+
+ currentlyDeployedArchiveName = null;
+
+ // only remove the mapping if we're not undeploying the most used portlet (optimization, as it avoids parsing the SD)
+ if (!mostUsedPortletWARFileName.equals(archiveName))
+ {
+ war2Handles.remove(archiveName);
+ }
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ this.mostUsedPortletWARFileName = getMostUsedPortletWARFileName();
+ deploy(mostUsedPortletWARFileName);
+
+ // reset strict mode
+ producer.usingStrictModeChangedTo(true);
+ }
+
+ /**
+ * Sub-classes need to implement this method to return the local WAR file name of the portlet being deployed most of
+ * the time in the context of the test case. This is required since we cannot rely on the name to be properly set at
+ * all time via the constructor.
+ *
+ * @return
+ */
+ protected abstract String getMostUsedPortletWARFileName();
+
+ public void tearDown() throws Exception
+ {
+ undeploy(mostUsedPortletWARFileName);
+ super.tearDown();
+ }
+
+ /**
+ * Creates a valid Markup request.
+ *
+ * @return a basic, valid GetMarkup object representing the markup request
+ */
+ protected GetMarkup createMarkupRequestForCurrentlyDeployedPortlet() throws Exception
+ {
+ return createMarkupRequest(getHandleForCurrentlyDeployedArchive());
+ }
+
+ /**
+ * @param handle
+ * @return
+ * @throws RemoteException
+ * @throws InvalidRegistrationFault
+ * @throws OperationFailedFault
+ * @since 2.6.3
+ */
+ protected GetMarkup createMarkupRequest(String handle) throws RemoteException, InvalidRegistration, OperationFailed
+ {
+ GetMarkup getMarkup = WSRPTypeFactory.createDefaultMarkupRequest(handle);
+ getMarkup.getMarkupParams().getMarkupCharacterSets().add(WSRPConstants.DEFAULT_CHARACTER_SET);
+
+ return getMarkup;
+ }
+
+ protected String getPortletHandleFrom(String partialHandle)
+ {
+ List<String> handles = getHandlesForCurrentlyDeployedArchive();
+ for (String handle : handles)
+ {
+ if (handle.contains(partialHandle))
+ {
+ return handle;
+ }
+ }
+
+ throw new IllegalArgumentException("Couldn't find a portlet handle matching '" + partialHandle + "' in " + currentlyDeployedArchiveName);
+ }
+
+ protected GetMarkup createMarkupRequest() throws Exception
+ {
+ return createMarkupRequestForCurrentlyDeployedPortlet();
+ }
+
+ protected void checkSessionForCurrentlyDeployedPortlet(MarkupResponse response)
+ throws RemoteException, InvalidRegistration, OperationFailed
+ {
+ // We don't send any portlet session information, just user cookies... The producer takes care of the details
+ // What this means, though is that we don't have access to individual portlet session ids... so we can only
+ // check that we get a cookie... Not very test-friendly...
+ /*ProducerSessionInformation sessionInfo = RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+ ExtendedAssert.assertNotNull(sessionInfo);
+ ExtendedAssert.assertTrue(sessionInfo.getUserCookie().lastIndexOf("JSESSIONID") != -1);
+
+ // Check that we are not sending sessionID's
+ SessionContext sessionContext = response.getSessionContext();
+ ExtendedAssert.assertNull(sessionContext);*/
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,412 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.gatein.wsrp.protocol.v1;
+
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.oasis.wsrp.v1.AccessDenied;
+import org.oasis.wsrp.v1.ClonePortlet;
+import org.oasis.wsrp.v1.DestroyFailed;
+import org.oasis.wsrp.v1.DestroyPortlets;
+import org.oasis.wsrp.v1.DestroyPortletsResponse;
+import org.oasis.wsrp.v1.GetPortletDescription;
+import org.oasis.wsrp.v1.GetPortletProperties;
+import org.oasis.wsrp.v1.GetPortletPropertyDescription;
+import org.oasis.wsrp.v1.GetServiceDescription;
+import org.oasis.wsrp.v1.InconsistentParameters;
+import org.oasis.wsrp.v1.InvalidHandle;
+import org.oasis.wsrp.v1.InvalidRegistration;
+import org.oasis.wsrp.v1.InvalidUserCategory;
+import org.oasis.wsrp.v1.MissingParameters;
+import org.oasis.wsrp.v1.ModelDescription;
+import org.oasis.wsrp.v1.OperationFailed;
+import org.oasis.wsrp.v1.PortletContext;
+import org.oasis.wsrp.v1.PortletDescriptionResponse;
+import org.oasis.wsrp.v1.PortletPropertyDescriptionResponse;
+import org.oasis.wsrp.v1.Property;
+import org.oasis.wsrp.v1.PropertyDescription;
+import org.oasis.wsrp.v1.PropertyList;
+import org.oasis.wsrp.v1.SetPortletProperties;
+import org.w3c.dom.Element;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 11547 $
+ * @since 2.4
+ */
+public class PortletManagementTestCase extends NeedPortletHandleTest
+{
+ private static final String TEST_BASIC_PORTLET_WAR = "test-basic-portlet.war";
+
+ public PortletManagementTestCase() throws Exception
+ {
+ super("PortletManagementTestCase", TEST_BASIC_PORTLET_WAR);
+ }
+
+ public void testClonePortlet() throws Exception
+ {
+ String handle = getDefaultHandle();
+ PortletContext initialContext = WSRPTypeFactory.createPortletContext(handle);
+
+ // first check that we get a new PortletContext
+ PortletContext cloneContext = clonePortlet(handle);
+ ExtendedAssert.assertNotNull(cloneContext);
+ ExtendedAssert.assertFalse(initialContext.equals(cloneContext));
+
+ // then check that the initial state is identical
+ GetPortletProperties getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, cloneContext);
+ List<Property> result = portletManagementService.getPortletProperties(getPortletProperties).getProperties();
+ getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, initialContext);
+ checkGetPropertiesResponse(portletManagementService.getPortletProperties(getPortletProperties), result);
+
+ // check that new clone is not listed in service description
+ GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+ checkServiceDescriptionWithOnlyBasicPortlet(gs);
+ }
+
+ public void testClonePortletNoRegistrationWhenRequired()
+ {
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ String handle = getDefaultHandle();
+ ClonePortlet clonePortlet = WSRPTypeFactory.createSimpleClonePortlet(handle);
+
+ try
+ {
+ portletManagementService.clonePortlet(clonePortlet);
+ ExtendedAssert.fail("Should have thrown InvalidRegistrationFault");
+ }
+ catch (InvalidRegistration invalidRegistrationFault)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ public void testDestroyPortlets() throws Exception
+ {
+ // first try to destroy POP, should fail
+ String handle = getDefaultHandle();
+ DestroyPortlets destroyPortlets = WSRPTypeFactory.createDestroyPortlets(null, Collections.<String>singletonList(handle));
+ DestroyPortletsResponse response = portletManagementService.destroyPortlets(destroyPortlets);
+ ExtendedAssert.assertNotNull(response);
+ List<DestroyFailed> failures = response.getDestroyFailed();
+ ExtendedAssert.assertNotNull(failures);
+ ExtendedAssert.assertEquals(1, failures.size());
+ DestroyFailed failure = failures.get(0);
+ ExtendedAssert.assertNotNull(failure);
+ ExtendedAssert.assertEquals(handle, failure.getPortletHandle());
+ ExtendedAssert.assertNotNull(failure.getReason());
+
+ // clone portlet and try to destroy it
+ PortletContext portletContext = clonePortlet(handle);
+ destroyPortlets = WSRPTypeFactory.createDestroyPortlets(null, Collections.<String>singletonList(portletContext.getPortletHandle()));
+ response = portletManagementService.destroyPortlets(destroyPortlets);
+ ExtendedAssert.assertNotNull(response);
+ failures = response.getDestroyFailed();
+ ExtendedAssert.assertNull(failures);
+ }
+
+ public void testDestroyPortletsNoRegistrationWhenRequired()
+ {
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ String handle = getDefaultHandle();
+ DestroyPortlets dp = WSRPTypeFactory.createDestroyPortlets(null, Collections.<String>singletonList(handle));
+
+ try
+ {
+ portletManagementService.destroyPortlets(dp);
+ ExtendedAssert.fail("Should have thrown InvalidRegistrationFault");
+ }
+ catch (InvalidRegistration invalidRegistrationFault)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ public void testGetPortletDescription() throws Exception
+ {
+ String handle = getDefaultHandle();
+ GetPortletDescription gpd = WSRPTypeFactory.createGetPortletDescription(null, handle);
+
+ PortletDescriptionResponse response = portletManagementService.getPortletDescription(gpd);
+ ExtendedAssert.assertNotNull(response);
+
+ checkBasicPortletDescription(response.getPortletDescription(), handle);
+ }
+
+ public void testGetPortletDescriptionNoRegistrationWhenRequired()
+ {
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ String handle = getDefaultHandle();
+ GetPortletDescription gpd = WSRPTypeFactory.createGetPortletDescription(null, handle);
+
+ try
+ {
+ portletManagementService.getPortletDescription(gpd);
+ ExtendedAssert.fail("Should have thrown InvalidRegistrationFault");
+ }
+ catch (InvalidRegistration invalidRegistrationFault)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ public void testGetPortletPropertiesNoRegistration() throws Exception
+ {
+ String handle = getDefaultHandle();
+ PortletContext initialContext = WSRPTypeFactory.createPortletContext(handle);
+ GetPortletProperties getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, initialContext);
+
+ List<String> names = getPortletProperties.getNames();
+ Collections.addAll(names, "prefName1", "prefName2");
+
+ PropertyList response = portletManagementService.getPortletProperties(getPortletProperties);
+ List<Property> expected = new ArrayList<Property>(2);
+ Collections.addAll(expected, WSRPTypeFactory.createProperty("prefName1", "en", "prefValue1"),
+ WSRPTypeFactory.createProperty("prefName2", "en", "prefValue2"));
+ checkGetPropertiesResponse(response, expected);
+
+ names.clear();
+ response = portletManagementService.getPortletProperties(getPortletProperties);
+ checkGetPropertiesResponse(response, expected);
+
+ names.add("prefName2");
+ response = portletManagementService.getPortletProperties(getPortletProperties);
+ checkGetPropertiesResponse(response, Collections.<Property>singletonList(WSRPTypeFactory.createProperty("prefName2", "en", "prefValue2")));
+ }
+
+ public void testGetPortletPropertyDescription() throws Exception
+ {
+ String handle = getDefaultHandle();
+ GetPortletPropertyDescription getPortletPropertyDescription = WSRPTypeFactory.createSimpleGetPortletPropertyDescription(handle);
+
+ PortletPropertyDescriptionResponse response = portletManagementService.getPortletPropertyDescription(getPortletPropertyDescription);
+
+ ModelDescription desc = response.getModelDescription();
+ ExtendedAssert.assertNotNull(desc);
+ List<PropertyDescription> propertyDescriptions = desc.getPropertyDescriptions();
+ ExtendedAssert.assertNotNull(propertyDescriptions);
+
+ List<PropertyDescription> expected = new ArrayList<PropertyDescription>(2);
+ PropertyDescription description = WSRPTypeFactory.createPropertyDescription("prefName1", WSRPConstants.XSD_STRING);
+ description.setHint(WSRPTypeFactory.createLocalizedString("prefName1"));
+ description.setLabel(WSRPTypeFactory.createLocalizedString("prefName1"));
+ expected.add(description);
+ description = WSRPTypeFactory.createPropertyDescription("prefName2", WSRPConstants.XSD_STRING);
+ description.setHint(WSRPTypeFactory.createLocalizedString("prefName2"));
+ description.setLabel(WSRPTypeFactory.createLocalizedString("prefName2"));
+ expected.add(description);
+
+ checkPropertyDescriptions(expected, propertyDescriptions);
+ }
+
+ public void testGetPortletPropertiesNoRegistrationWhenRequired()
+ {
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ String handle = getDefaultHandle();
+ GetPortletPropertyDescription getPortletPropertyDescription = WSRPTypeFactory.createSimpleGetPortletPropertyDescription(handle);
+
+ try
+ {
+ portletManagementService.getPortletPropertyDescription(getPortletPropertyDescription);
+ ExtendedAssert.fail("Should have thrown InvalidRegistrationFault");
+ }
+ catch (InvalidRegistration invalidRegistrationFault)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ public void testSetPortletProperties() throws Exception
+ {
+ String handle = getDefaultHandle();
+
+ PortletContext portletContext = clonePortlet(handle);
+ PropertyList propertyList = WSRPTypeFactory.createPropertyList();
+ List<Property> properties = propertyList.getProperties();
+ Collections.addAll(properties, WSRPTypeFactory.createProperty("prefName1", "en", "newPrefValue1"),
+ WSRPTypeFactory.createProperty("prefName2", "en", "newPrefValue2"));
+ SetPortletProperties setPortletProperties = WSRPTypeFactory.createSetPortletProperties(null, portletContext, propertyList);
+
+ PortletContext response = portletManagementService.setPortletProperties(setPortletProperties);
+ GetPortletProperties getPortletProperties = WSRPTypeFactory.createGetPortletProperties(null, response);
+ checkGetPropertiesResponse(portletManagementService.getPortletProperties(getPortletProperties), properties);
+
+ portletContext = WSRPTypeFactory.createPortletContext(handle);
+ setPortletProperties.setPortletContext(portletContext);
+ try
+ {
+ response = portletManagementService.setPortletProperties(setPortletProperties);
+ ExtendedAssert.fail("Setting properties on Producer-Offered Portlet should fail...");
+ }
+ catch (InconsistentParameters expected)
+ {
+ // expected
+ }
+ }
+
+ public void testSetPortletPropertiesNoRegistrationWhenRequired()
+ {
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
+
+ PropertyList propertyList = WSRPTypeFactory.createPropertyList();
+ List<Property> properties = propertyList.getProperties();
+ Collections.addAll(properties, WSRPTypeFactory.createProperty("prefName1", "en", "newPrefValue1"),
+ WSRPTypeFactory.createProperty("prefName2", "en", "newPrefValue2"));
+ SetPortletProperties setPortletProperties = WSRPTypeFactory.createSetPortletProperties(null,
+ WSRPTypeFactory.createPortletContext(getDefaultHandle()), propertyList);
+
+ try
+ {
+ portletManagementService.setPortletProperties(setPortletProperties);
+ ExtendedAssert.fail("Should have thrown InvalidRegistrationFault");
+ }
+ catch (InvalidRegistration invalidRegistration)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ private PortletContext clonePortlet(String handle) throws InvalidUserCategory, InconsistentParameters,
+ InvalidRegistration, MissingParameters, OperationFailed, AccessDenied, InvalidHandle
+ {
+ ClonePortlet clonePortlet = WSRPTypeFactory.createSimpleClonePortlet(handle);
+ return portletManagementService.clonePortlet(clonePortlet);
+ }
+
+ private List<Property> checkGetPropertiesResponse(PropertyList response, List<Property> expected)
+ {
+ ExtendedAssert.assertNotNull(response);
+ List<Property> properties = response.getProperties();
+ ExtendedAssert.assertEquals(expected.toArray(), properties.toArray(), false, "Didn't receive expected properties!", new PropertyDecorator());
+ return properties;
+ }
+
+ private void checkPropertyDescriptions(List<PropertyDescription> expected, List<PropertyDescription> propertyDescriptions)
+ {
+ ExtendedAssert.assertEquals(expected.size(), propertyDescriptions.size());
+ PropertyDescription propDesc = propertyDescriptions.get(0);
+ ExtendedAssert.assertNotNull(propDesc);
+ String name = propDesc.getName();
+ if ("prefName1".equals(name))
+ {
+ assertEquals(expected.get(0), propDesc);
+ assertEquals(expected.get(1), propertyDescriptions.get(1));
+ }
+ else if ("prefName2".equals(name))
+ {
+ assertEquals(expected.get(1), propDesc);
+ assertEquals(expected.get(0), propertyDescriptions.get(1));
+ }
+ else
+ {
+ ExtendedAssert.fail("Unexpected PropertyDescription named '" + name + "'");
+ }
+ }
+
+ protected String getMostUsedPortletWARFileName()
+ {
+ return TEST_BASIC_PORTLET_WAR;
+ }
+
+ private static class PropertyDecorator implements ExtendedAssert.Decorator
+ {
+ private Property prop;
+
+ public void decorate(Object decorated)
+ {
+ prop = (Property)decorated;
+ }
+
+ public boolean equals(Object o)
+ {
+ if (o instanceof ExtendedAssert.DecoratedObject)
+ {
+ ExtendedAssert.DecoratedObject decoratedObject = (ExtendedAssert.DecoratedObject)o;
+ Property that = (Property)decoratedObject.getDecorated();
+
+ String name = prop.getName();
+ if (name != null ? !name.equals(that.getName()) : that.getName() != null)
+ {
+ return false;
+ }
+
+ String value = prop.getStringValue();
+ if (value != null ? !value.equals(that.getStringValue()) : that.getStringValue() != null)
+ {
+ return false;
+ }
+
+ String lang = prop.getLang();
+ if (lang != null ? !lang.equals(that.getLang()) : that.getLang() != null)
+ {
+ return false;
+ }
+
+ List<Element> any = prop.getAny();
+ return !(any != null ? !any.equals(that.getAny()) : that.getAny() != null);
+
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+
+ public String toString()
+ {
+ return new StringBuffer().append("Property: ").append(prop.getName()).append("=")
+ .append(prop.getStringValue()).append(" (").append(prop.getLang()).append(")").toString();
+ }
+ }
+}
\ No newline at end of file
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/PortletManagementTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,340 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.gatein.wsrp.protocol.v1;
+
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.oasis.wsrp.v1.GetMarkup;
+import org.oasis.wsrp.v1.GetServiceDescription;
+import org.oasis.wsrp.v1.InvalidRegistration;
+import org.oasis.wsrp.v1.ModifyRegistration;
+import org.oasis.wsrp.v1.OperationFailed;
+import org.oasis.wsrp.v1.PropertyDescription;
+import org.oasis.wsrp.v1.RegistrationContext;
+import org.oasis.wsrp.v1.RegistrationData;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 12309 $
+ * @since 2.4
+ */
+public class RegistrationTestCase extends V1ProducerBaseTest
+{
+ public RegistrationTestCase() throws Exception
+ {
+ super("RegistrationTestCase");
+ }
+
+ /**
+ * R355: The portal MUST pass a name for itself that uniquely identifies it.
+ *
+ * @throws Exception
+ */
+ public void testUniqueNameRegistration() throws Exception
+ {
+ // not sure how to test this...
+ }
+
+ /**
+ * R356: The portal MAY pass information describing the portal [vendor] type and version.
+ * <p/>
+ * However, WSRP v1 7.1.1 states: The consumerAgent value MUST start with "productName.majorVersion.minorVersion"
+ * where "productName" identifies the product the Consumer installed for its deployment, and majorVersion and
+ * minorVersion are vendor-defined indications of the version of its product. This string can then contain any
+ * additional characters/words the product or Consumer wish to supply.
+ *
+ * @throws Exception
+ */
+ public void testConsumerAgent() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+ RegistrationData regData = createBaseRegData();
+ regData.setConsumerAgent("invalid consumer agent");
+
+ try
+ {
+ registrationService.register(regData);
+ ExtendedAssert.fail("Trying to register with an invalid consumer agent String should fail.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ }
+
+
+ regData.setConsumerAgent(WSRPConstants.CONSUMER_AGENT);
+ registrationService.register(regData);
+ }
+
+ public void testDeregister() throws Exception
+ {
+ // initiate registration
+ configureRegistrationSettings(true, false);
+ RegistrationContext rc = registerConsumer();
+
+ // deregister
+ registrationService.deregister(rc);
+
+ // try to get markup, portlet handle doesn't matter since it should fail before trying to retrieve the portlet
+ GetMarkup getMarkup = WSRPTypeFactory.createDefaultMarkupRequest("foo");
+ getMarkup.getMarkupParams().getMarkupCharacterSets().add(WSRPConstants.DEFAULT_CHARACTER_SET);
+
+ try
+ {
+ markupService.getMarkup(getMarkup);
+ ExtendedAssert.fail("Consumer tried to access info with a de-registered context. Operations should fail.");
+ }
+ catch (InvalidRegistration invalidRegistrationFault)
+ {
+ // expected
+ }
+
+ // Get description with old registration context should fail
+ GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+ gs.setRegistrationContext(rc);
+
+ try
+ {
+ serviceDescriptionService.getServiceDescription(gs);
+ ExtendedAssert.fail("Required registration info has been modified: operations should fail until registration is modified.");
+ }
+ catch (InvalidRegistration invalidRegistrationFault)
+ {
+ // expected
+ }
+
+ // Get description should still work without registration context
+ gs = getNoRegistrationServiceDescriptionRequest();
+
+ ExtendedAssert.assertNotNull(serviceDescriptionService.getServiceDescription(gs));
+ }
+
+ public void testModifyRegistration() throws Exception
+ {
+ // initiate registration
+ configureRegistrationSettings(true, false);
+ RegistrationContext rc = registerConsumer();
+
+ // now modify Producer's set of required registration info
+ String newPropName = "New Prop";
+ RegistrationPropertyDescription regProp = new RegistrationPropertyDescription(newPropName,
+ new QName("urn:oasis:names:tc:wsrp:v1:types", "LocalizedString", "ns1"));
+ regProp.setDefaultLabel("New Registration Property");
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().addRegistrationProperty(regProp);
+
+ // try to get markup, portlet handle doesn't matter since it should fail before trying to retrieve the portlet
+ GetMarkup getMarkup = WSRPTypeFactory.createDefaultMarkupRequest("foo");
+ getMarkup.getMarkupParams().getMarkupCharacterSets().add(WSRPConstants.DEFAULT_CHARACTER_SET);
+ getMarkup.setRegistrationContext(rc);
+
+ try
+ {
+ markupService.getMarkup(getMarkup);
+ ExtendedAssert.fail("Required registration info has been modified: operations should fail until registration is modified.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ // WSRP primer recommends returning OperationFailedFault and NOT InvalidRegistrationFault
+ // kinda weird... will be replaced by ModifyRegistrationRequiredFault in WSRP 2.0
+ }
+
+ // Get description should return information just as if consumer wasn't registered
+ GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+ gs.setRegistrationContext(rc);
+
+ try
+ {
+ serviceDescriptionService.getServiceDescription(gs);
+ ExtendedAssert.fail("Required registration info has been modified: operations should fail until registration is modified.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ // WSRP primer recommends returning OperationFailedFault and NOT InvalidRegistrationFault
+ // kinda weird... will be replaced by ModifyRegistrationRequiredFault in WSRP 2.0
+ }
+
+ // remove registration context, try again and check that we get new registration info
+ gs.setRegistrationContext(null);
+ List<PropertyDescription> pds = serviceDescriptionService.getServiceDescription(gs)
+ .getRegistrationPropertyDescription().getPropertyDescriptions();
+ ExtendedAssert.assertEquals(2, pds.size());
+
+ // Check that one of the returned property description is equal to the one we just added
+ PropertyDescription description = pds.get(1);
+ if (description.getName().startsWith("New"))
+ {
+ assertEquals(WSRPUtils.convertToPropertyDescription(regProp), description);
+ }
+ else
+ {
+ assertEquals(WSRPUtils.convertToPropertyDescription(regProp), pds.get(0));
+ }
+
+ // Update registration data
+ RegistrationData regData = createBaseRegData();
+ regData.getRegistrationProperties().add(WSRPTypeFactory.createProperty(newPropName, "en", "blah"));
+
+ // Modify registration and get service description
+ ModifyRegistration registration = new ModifyRegistration();
+ registration.setRegistrationContext(rc);
+ registration.setRegistrationData(regData);
+ registrationService.modifyRegistration(registration);
+ gs.setRegistrationContext(rc);
+ checkServiceDescriptionWithOnlyBasicPortlet(gs);
+ }
+
+ public void testModifyRegistrationIncorrectData() throws Exception
+ {
+ // initiate registration
+ configureRegistrationSettings(true, false);
+ RegistrationContext rc = registerConsumer();
+
+ // now modify Producer's set of required registration info
+ String newPropName = "New Prop";
+ RegistrationPropertyDescription regProp = new RegistrationPropertyDescription(newPropName,
+ new QName("urn:oasis:names:tc:wsrp:v1:types", "LocalizedString", "ns1"));
+ regProp.setDefaultLabel("New Registration Property");
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().addRegistrationProperty(regProp);
+
+ try
+ {
+ ModifyRegistration registration = new ModifyRegistration();
+ registration.setRegistrationContext(rc);
+ registration.setRegistrationData(createBaseRegData());
+ registrationService.modifyRegistration(registration);
+ ExtendedAssert.fail("Passing incorrect data should fail");
+ }
+ catch (OperationFailed operationFailed)
+ {
+ // expected
+ }
+ }
+
+ public void testRegister() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ // service description request without registration info
+ GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+
+ RegistrationContext registrationContext = registerConsumer();
+ ExtendedAssert.assertNotNull(registrationContext);
+ ExtendedAssert.assertNotNull(registrationContext.getRegistrationHandle());
+
+ gs.setRegistrationContext(registrationContext);
+
+ checkServiceDescriptionWithOnlyBasicPortlet(gs);
+ }
+
+ public void testRegisterWhenRegistrationNotRequired() throws Exception
+ {
+ configureRegistrationSettings(false, false);
+
+ try
+ {
+ registerConsumer();
+ ExtendedAssert.fail("Shouldn't be possible to register if no registration is required.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ }
+ }
+
+ public void testDeregisterWhenRegistrationNotRequired() throws Exception
+ {
+ configureRegistrationSettings(false, false);
+
+ try
+ {
+ registrationService.deregister(null);
+ ExtendedAssert.fail("Shouldn't be possible to deregister if no registration is required.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ }
+ }
+
+ public void testModifyRegistrationWhenRegistrationNotRequired() throws Exception
+ {
+ configureRegistrationSettings(false, false);
+
+ try
+ {
+ registrationService.modifyRegistration(null);
+ ExtendedAssert.fail("Shouldn't be possible to modify registration if no registration is required.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ }
+ }
+
+ public void testModifyRegistrationNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ try
+ {
+ registrationService.modifyRegistration(null);
+ ExtendedAssert.fail("Shouldn't be possible to modify registration if no registration is required.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+
+ public void testDeregisterNoRegistrationWhenRegistrationRequired() throws Exception
+ {
+ configureRegistrationSettings(true, false);
+
+ try
+ {
+ registrationService.deregister(null);
+ ExtendedAssert.fail("Shouldn't be possible to modify registration if no registration is required.");
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected
+ }
+ catch (Exception e)
+ {
+ ExtendedAssert.fail(e.getMessage());
+ }
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,154 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.gatein.wsrp.protocol.v1;
+
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.jboss.logging.Logger;
+import org.oasis.wsrp.v1.OperationFailed;
+import org.oasis.wsrp.v1.RegistrationContext;
+import org.oasis.wsrp.v1.ReleaseSessions;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Tests the behavior of the ReleaseSession method.
+ *
+ * @author Matt Wringe
+ */
+public class ReleaseSessionTestCase extends NeedPortletHandleTest
+{
+
+ // default portlet war used in this test
+ private static final String DEFAULT_SESSION_PORTLET_WAR = "test-session-portlet.war";
+
+ private static final Logger log = Logger.getLogger(ReleaseSessionTestCase.class);
+
+
+ protected String getMostUsedPortletWARFileName()
+ {
+ return DEFAULT_SESSION_PORTLET_WAR;
+ }
+
+ public ReleaseSessionTestCase() throws Exception
+ {
+ super("SessionWar", DEFAULT_SESSION_PORTLET_WAR);
+ log.debug("Instantiating ReleaseSessionTestCase");
+ }
+
+
+ public void testReleaseSession() throws Exception
+ {
+ // possible registration contexts are: actual RegistrationContext, null, and a made up value
+ RegistrationContext fakeRegContext = WSRPTypeFactory.createRegistrationContext("Fake Registration Handle");
+ RegistrationContext[] regContexts = new RegistrationContext[]{null, null, fakeRegContext};
+
+ // possible types of sessionIDs include null and a made up value.
+ // Note: a valid session id cannot be used since the sessionID should never be sent to the consumer
+ String nullSessionID = null;
+ String fakeSessionID = "Fake Session ID";
+
+ String[][] sessionIDs = new String[][]{{nullSessionID},
+ {nullSessionID, nullSessionID},
+ {fakeSessionID},
+ {fakeSessionID, fakeSessionID},
+ {fakeSessionID, nullSessionID},
+ {nullSessionID, fakeSessionID}};
+
+ for (int i = 0; i < regContexts.length; i++)
+ {
+ for (String[] sessionID : sessionIDs)
+ {
+ ReleaseSessions releaseSession = WSRPTypeFactory.createReleaseSessions(regContexts[i], Arrays.asList(sessionID));
+ releaseSessions(releaseSession, false, i);
+ releaseSessions(releaseSession, true, i);
+ }
+ }
+ }
+
+ private void releaseSessions(ReleaseSessions releaseSessions, boolean useRegistration, int index) throws Exception
+ {
+ setUp();
+ try
+ {
+ if (useRegistration)
+ {
+ configureRegistrationSettings(true, false);
+
+ // faking correct registration context when we're supposed to have one... previous impl registered consumer
+ // all the time but this cannot be done anymore since we prevent registering if no registration is required
+ // so we need to wait for the proper case to init the registration context... Hackish! :(
+ if (index == 0)
+ {
+ releaseSessions.setRegistrationContext(registerConsumer());
+ }
+ }
+ log.info(getSetupString(releaseSessions));
+ markupService.releaseSessions(releaseSessions);
+ ExtendedAssert.fail("ReleaseSessions did not thrown an OperationFailed Fault." + getSetupString(releaseSessions));
+ }
+ catch (OperationFailed operationFailedFault)
+ {
+ // expected fault.
+ }
+ finally
+ {
+ tearDown();
+ }
+ }
+
+ private String getSetupString(ReleaseSessions releaseSessions)
+ {
+ StringBuffer message = new StringBuffer("ReleaseSessions Setup:\n");
+
+ if (releaseSessions == null)
+ {
+ message.append(" ReleaseSessions : null");
+ }
+ else
+ {
+ RegistrationContext regContext = releaseSessions.getRegistrationContext();
+ List<String> sessionIDs = releaseSessions.getSessionIDs();
+ message.append(" RegistrationContext : ").append(regContext != null ? regContext.getRegistrationHandle() : null);
+ message.append(" | SessionIDs : ");
+ if (sessionIDs != null)
+ {
+ for (int i = 0; i < sessionIDs.size(); i++)
+ {
+ message.append(sessionIDs.get(i)).append(i == sessionIDs.size() - 1 ? "" : ", ");
+ }
+ }
+
+ }
+
+ if (producer.getConfigurationService().getConfiguration().getRegistrationRequirements().isRegistrationRequired())
+ {
+ message.append(" | with registration required.");
+ }
+
+ return message.toString();
+ }
+
+}
\ No newline at end of file
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ReleaseSessionTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,153 @@
+/******************************************************************************
+ * 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, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.gatein.wsrp.protocol.v1;
+
+import org.gatein.wsrp.WSRPUtils;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.oasis.wsrp.v1.GetServiceDescription;
+import org.oasis.wsrp.v1.ModelDescription;
+import org.oasis.wsrp.v1.PropertyDescription;
+import org.oasis.wsrp.v1.ServiceDescription;
+
+import java.util.List;
+
+/**
+ * Tests WSRP Service Description
+ *
+ * @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 11547 $
+ * @since 2.4 (Feb 20, 2006)
+ */
+public class ServiceDescriptionTestCase extends V1ProducerBaseTest
+{
+ public ServiceDescriptionTestCase() throws Exception
+ {
+ super("ServiceDescriptionTestCase");
+ }
+
+ public void testNotRequiringRegistration() throws Throwable
+ {
+ producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(false);
+
+ GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+
+ ServiceDescription sd = checkServiceDescriptionWithOnlyBasicPortlet(gs);
+
+ // registration is not required
+ ExtendedAssert.assertFalse(sd.isRequiresRegistration());
+
+ // No registration properties
+ ExtendedAssert.assertNull(sd.getRegistrationPropertyDescription());
+ }
+
+ public void testRequiringRegistrationNotProvidingPortlets() throws Throwable
+ {
+ RegistrationPropertyDescription regProp = configureRegistrationSettings(true, false);
+
+ // service description request without registration info
+ GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+
+ //Invoke the Web Service
+ ServiceDescription sd = serviceDescriptionService.getServiceDescription(gs);
+ ExtendedAssert.assertNotNull(sd);
+ ExtendedAssert.assertTrue(sd.isRequiresRegistration());
+
+ // Check registration properties
+ checkRequiredRegistrationProperties(sd, regProp);
+
+ // No offered portlets without registration!
+ ExtendedAssert.assertNull(sd.getOfferedPortlets());
+ }
+
+ public void testRequiringRegistrationProvidingPortlets() throws Throwable
+ {
+ RegistrationPropertyDescription regProp = configureRegistrationSettings(true, true);
+
+ // service description request without registration info
+ GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
+
+ //Invoke the Web Service, we should have the complete description
+ ServiceDescription sd = checkServiceDescriptionWithOnlyBasicPortlet(gs);
+ ExtendedAssert.assertNotNull(sd);
+ ExtendedAssert.assertTrue(sd.isRequiresRegistration());
+
+ // Check registration properties
+ checkRequiredRegistrationProperties(sd, regProp);
+ }
+
+ public void testLiveDeployment() throws Throwable
+ {
+ try
+ {
+ GetServiceDescription gsd = getNoRegistrationServiceDescriptionRequest();
+
+ deploy("test-basic-portlet.war");
+ ServiceDescription sd = serviceDescriptionService.getServiceDescription(gsd);
+ ExtendedAssert.assertEquals(1, sd.getOfferedPortlets().size());
+
+ deploy("test-markup-portlet.war");
+ sd = serviceDescriptionService.getServiceDescription(gsd);
+ // should now have 2 offered portlets
+ ExtendedAssert.assertEquals(2, sd.getOfferedPortlets().size());
+
+ deploy("test-session-portlet.war");
+ sd = serviceDescriptionService.getServiceDescription(gsd);
+ // should now have 3 offered portlets
+ ExtendedAssert.assertEquals(3, sd.getOfferedPortlets().size());
+
+ undeploy("test-markup-portlet.war");
+ sd = serviceDescriptionService.getServiceDescription(gsd);
+ // should now have only 2 offered portlets again
+ ExtendedAssert.assertEquals(2, sd.getOfferedPortlets().size());
+
+ undeploy("test-session-portlet.war");
+ // only basic portlet should still be offered
+ checkServiceDescriptionWithOnlyBasicPortlet(gsd);
+ }
+ finally
+ {
+ undeploy("test-basic-portlet.war");
+ undeploy("test-markup-portlet.war");
+ undeploy("test-session-portlet.war");
+ }
+ }
+
+ private void checkRequiredRegistrationProperties(ServiceDescription sd, RegistrationPropertyDescription regProp)
+ {
+ ModelDescription registrationPropertyDescription = sd.getRegistrationPropertyDescription();
+ ExtendedAssert.assertNotNull(registrationPropertyDescription);
+ List<PropertyDescription> propertyDescriptions = registrationPropertyDescription.getPropertyDescriptions();
+ ExtendedAssert.assertNotNull(propertyDescriptions);
+ ExtendedAssert.assertEquals(1, propertyDescriptions.size());
+ assertEquals(WSRPUtils.convertToPropertyDescription(regProp), propertyDescriptions.get(0));
+ }
+}
\ No newline at end of file
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,283 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+
+package org.gatein.wsrp.protocol.v1;
+
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationManager;
+import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import org.gatein.registration.policies.DefaultRegistrationPropertyValidator;
+import org.gatein.wsrp.WSRPConstants;
+import org.gatein.wsrp.WSRPTypeFactory;
+import org.gatein.wsrp.producer.WSRPProducerBaseTest;
+import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.registration.RegistrationPropertyDescription;
+import org.gatein.wsrp.test.ExtendedAssert;
+import org.oasis.wsrp.v1.GetServiceDescription;
+import org.oasis.wsrp.v1.LocalizedString;
+import org.oasis.wsrp.v1.MarkupType;
+import org.oasis.wsrp.v1.MissingParameters;
+import org.oasis.wsrp.v1.OperationFailed;
+import org.oasis.wsrp.v1.PortletDescription;
+import org.oasis.wsrp.v1.PropertyDescription;
+import org.oasis.wsrp.v1.RegistrationContext;
+import org.oasis.wsrp.v1.RegistrationData;
+import org.oasis.wsrp.v1.ServiceDescription;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 12302 $
+ * @since 2.4
+ */
+public abstract class V1ProducerBaseTest extends WSRPProducerBaseTest
+{
+ private static final String CONSUMER = "test-consumer";
+
+ public V1ProducerBaseTest() throws Exception
+ {
+ this("V1ProducerBaseTest");
+ }
+
+ protected V1ProducerBaseTest(String name) throws Exception
+ {
+ super(name);
+ }
+
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+
+ resetRegistrationInfo();
+ }
+
+ public void tearDown() throws Exception
+ {
+ resetRegistrationInfo();
+ super.tearDown();
+ }
+
+ /**
+ * Checks that the specified portlet description corresponds to the expected description of test-basic-portlet. If
+ * the handle parameter is not null, checks that it corresponds to the specified portlet decription.
+ *
+ * @param desc the tested PortletDescription
+ * @param handle the PortletHandle to be checked
+ */
+ public void checkBasicPortletDescription(PortletDescription desc, String handle)
+ {
+ ExtendedAssert.assertNotNull(desc);
+ /**
+ * @wsrp.specification
+ * Portlet handle must be less than 255 characters (WSRP 1.0 5.1.2)
+ */
+ ExtendedAssert.assertTrue(desc.getPortletHandle().length() <= 255);
+ if (handle != null)
+ {
+ ExtendedAssert.assertEquals(handle, desc.getPortletHandle());
+ }
+ ExtendedAssert.assertEquals("title", desc.getTitle().getValue());
+ List<MarkupType> markupTypes = desc.getMarkupTypes();
+ ExtendedAssert.assertEquals(1, markupTypes.size());
+ MarkupType markupType = markupTypes.get(0);
+
+ List<String> states = new ArrayList<String>(3);
+ states.add(WSRPConstants.NORMAL_WINDOW_STATE);
+ states.add(WSRPConstants.MAXIMIZED_WINDOW_STATE);
+ states.add(WSRPConstants.MINIMIZED_WINDOW_STATE);
+ MarkupType expected = WSRPTypeFactory.createMarkupType("text/html",
+ Collections.<String>singletonList(WSRPConstants.VIEW_MODE), states, Collections.<String>singletonList("en"));
+ assertEquals(expected, markupType);
+ }
+
+ protected ServiceDescription checkServiceDescriptionWithOnlyBasicPortlet(GetServiceDescription gs)
+ throws Exception
+ {
+ deploy("test-basic-portlet.war");
+ //Invoke the Web Service
+ ServiceDescription sd = producer.getServiceDescription(gs);
+
+ ExtendedAssert.assertNotNull("sd != null", sd);
+
+ // Check offered portlets
+ List<PortletDescription> offeredPortlets = sd.getOfferedPortlets();
+ ExtendedAssert.assertNotNull(offeredPortlets);
+ for (PortletDescription offeredPortlet : offeredPortlets)
+ {
+ System.out.println("handle " + offeredPortlet.getPortletHandle());
+ }
+ ExtendedAssert.assertEquals(1, offeredPortlets.size());
+
+ // Check portlet description
+ PortletDescription desc = offeredPortlets.get(0);
+
+ checkBasicPortletDescription(desc, null);
+
+ undeploy("test-basic-portlet.war");
+ return sd; // for further testing...
+ }
+
+ protected RegistrationContext registerConsumer() throws OperationFailed, MissingParameters
+ {
+ RegistrationData registrationData = createBaseRegData();
+ return producer.register(registrationData);
+ }
+
+ protected RegistrationData createBaseRegData()
+ {
+ RegistrationData regData = WSRPTypeFactory.createDefaultRegistrationData();
+ regData.setConsumerName(CONSUMER);
+ regData.getRegistrationProperties().add(WSRPTypeFactory.createProperty("regProp", "en", "regValue"));
+ return regData;
+ }
+
+ protected RegistrationPropertyDescription configureRegistrationSettings(boolean requiresRegistration, boolean provideUnregisteredFullDescription)
+ {
+ // define expected registration infos
+ ProducerRegistrationRequirements registrationRequirements = producer.getConfigurationService().getConfiguration().getRegistrationRequirements();
+ registrationRequirements.setRegistrationRequired(requiresRegistration);
+ registrationRequirements.setRegistrationRequiredForFullDescription(!provideUnregisteredFullDescription);
+
+ if (requiresRegistration)
+ {
+ // fix-me: http://jira.jboss.com/jira/browse/JBPORTAL-821
+ RegistrationPropertyDescription regProp = new RegistrationPropertyDescription("regProp",
+ new QName("urn:oasis:names:tc:wsrp:v1:types", "LocalizedString", "ns1"));
+ regProp.setDefaultLabel("Registration Property");
+ registrationRequirements.addRegistrationProperty(regProp);
+
+ // Use default registration policy: this wiring is normally handled at the producer start, should maybe use a
+ // registration policy that is automatically configured when none is provided to avoid having a null one?
+ DefaultRegistrationPolicy defaultRegistrationPolicy = new DefaultRegistrationPolicy();
+ defaultRegistrationPolicy.setValidator(new DefaultRegistrationPropertyValidator());
+ registrationRequirements.setPolicy(defaultRegistrationPolicy);
+
+ RegistrationManager registrationManager = producer.getRegistrationManager();
+ registrationManager.setPolicy(defaultRegistrationPolicy);
+ registrationRequirements.addRegistrationPropertyChangeListener(registrationManager);
+
+ // create consumer for policy to be able to make decisions properly
+ try
+ {
+ registrationManager.createConsumer(CONSUMER);
+ }
+ catch (RegistrationException e)
+ {
+ ExtendedAssert.fail("Couldn't create consumer. Cause: " + e.getLocalizedMessage());
+ }
+
+ return regProp;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ protected void resetRegistrationInfo() throws RegistrationException
+ {
+ ProducerRegistrationRequirements registrationRequirements = producer.getConfigurationService().getConfiguration().getRegistrationRequirements();
+ registrationRequirements.setRegistrationRequired(false);
+ registrationRequirements.clearRegistrationProperties();
+ registrationRequirements.clearRegistrationPropertyChangeListeners();
+ producer.getRegistrationManager().clear();
+ registrationRequirements.removeRegistrationPropertyChangeListener(producer.getRegistrationManager());
+ }
+
+ protected GetServiceDescription getNoRegistrationServiceDescriptionRequest()
+ {
+ GetServiceDescription gs = WSRPTypeFactory.createGetServiceDescription();
+ gs.getDesiredLocales().add("en-US");
+ gs.getDesiredLocales().add("en");
+ return gs;
+ }
+
+ /** === asserts === * */
+
+ protected static void assertEquals(MarkupType expected, MarkupType tested)
+ {
+ String message = "Expected: <" + expected + ">, got: <" + tested + ">. Failed on: ";
+
+ if (expected != tested)
+ {
+ if (expected == null || tested == null)
+ {
+ ExtendedAssert.fail(message + "Different classes or not both null.");
+ }
+
+
+ assertEquals(message + "Extensions", expected.getExtensions(), tested.getExtensions());
+ assertEquals(message + "Locales", expected.getLocales(), tested.getLocales());
+ assertEquals(message + "Modes", expected.getModes(), tested.getModes());
+ assertEquals(message + "Window states", expected.getWindowStates(), tested.getWindowStates());
+ }
+ }
+
+ protected static void assertEquals(PropertyDescription expected, PropertyDescription tested)
+ {
+ String message = "Expected: <" + expected + ">, got: <" + tested + ">. Failed on ";
+
+ if (expected != tested)
+ {
+ if (expected == null || tested == null)
+ {
+ ExtendedAssert.fail(message + "Different classes or not both null.");
+ }
+
+ assertEquals(message + "extensions.", expected.getExtensions(), tested.getExtensions());
+ assertEquals(message + "hint.", expected.getHint(), tested.getHint());
+ assertEquals(message + "label.", expected.getLabel(), tested.getLabel());
+ ExtendedAssert.assertEquals(message + "name.", expected.getName(), tested.getName());
+ ExtendedAssert.assertEquals(message + "type.", expected.getType(), tested.getType());
+ }
+ }
+
+ protected static void assertEquals(String message, LocalizedString expected, LocalizedString tested)
+ {
+ String precise = "Expected: <" + expected + ">, got: <" + tested + ">. Failed on ";
+
+ if (expected != tested)
+ {
+ if (expected == null || tested == null)
+ {
+ ExtendedAssert.fail(message + ": Different classes or not both null.");
+ }
+
+ ExtendedAssert.assertEquals(precise + "lang.", expected.getLang(), tested.getLang());
+ ExtendedAssert.assertEquals(precise + "resource name.", expected.getResourceName(), tested.getResourceName());
+ ExtendedAssert.assertEquals(precise + "value.", expected.getValue(), tested.getValue());
+ }
+ }
+
+ protected void checkException(Exception e, String errorCode)
+ {
+ Throwable cause = e.getCause();
+// ExtendedAssert.assertTrue(cause instanceof SOAPFaultException);
+// ExtendedAssert.assertEquals(errorCode, ((SOAPFaultException)cause).getFault().getLocalPart());
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java
___________________________________________________________________
Name: svn:executable
+ *
Added: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/registration/RegistrationPropertyDescriptionTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/registration/RegistrationPropertyDescriptionTestCase.java (rev 0)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/registration/RegistrationPropertyDescriptionTestCase.java 2009-11-19 19:58:55 UTC (rev 694)
@@ -0,0 +1,124 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, 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.registration;
+
+import junit.framework.TestCase;
+import org.gatein.wsrp.WSRPConstants;
+
+import javax.xml.namespace.QName;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
+ * @version $Revision: 12017 $
+ * @since 2.6
+ */
+public class RegistrationPropertyDescriptionTestCase extends TestCase
+{
+ private RegistrationPropertyDescription desc;
+
+ protected void setUp() throws Exception
+ {
+ desc = new RegistrationPropertyDescription("foo", WSRPConstants.XSD_STRING);
+ }
+
+ public void testNotify()
+ {
+ TestParent parent = new TestParent();
+ desc.setValueChangeListener(parent);
+ desc.setDefaultHint(null);
+ assertFalse(parent.notifyCalled);
+ parent.resetNotifyCalled();
+ desc.setDefaultHint("hint");
+ assertTrue(parent.notifyCalled);
+ }
+
+ public void testChangingNameUpdatesParent()
+ {
+ TestParent parent = new TestParent();
+ desc.setValueChangeListener(parent);
+ assertNotNull(parent.getRegistrationPropertyWith("foo"));
+
+ desc.setName(QName.valueOf("bar"));
+ assertEquals(desc, parent.getRegistrationPropertyWith("bar"));
+ assertNull(parent.getRegistrationPropertyWith("foo"));
+ }
+
+ public void testModifyIfNeeded()
+ {
+ String oldValue = "old";
+ String newValue = "new";
+ assertEquals(oldValue, desc.modifyIfNeeded(oldValue, oldValue));
+ assertEquals(newValue, desc.modifyIfNeeded(oldValue, newValue));
+ assertEquals(null, desc.modifyIfNeeded(null, null));
+ assertEquals(newValue, desc.modifyIfNeeded(null, newValue));
+ assertEquals(null, desc.modifyIfNeeded(oldValue, null));
+ }
+
+ public void testGetLang()
+ {
+ assertEquals(Locale.getDefault(), desc.getLang());
+ desc.setLabel(new LocalizedString("etiquette", Locale.FRENCH));
+ assertEquals(Locale.FRENCH, desc.getLang());
+ }
+
+ class TestParent implements ValueChangeListener
+ {
+ private boolean notifyCalled;
+
+ // prop name fakes the existence of a property as only one property exists for the tests
+ private String propName = "foo";
+
+ void resetNotifyCalled()
+ {
+ notifyCalled = false;
+ }
+
+ public RegistrationPropertyDescription getRegistrationPropertyWith(String name)
+ {
+ // return desc only if it matches the name we know about (used to fake property name updates)
+ if (propName.equals(name))
+ {
+ return desc;
+ }
+
+ return null;
+ }
+
+ public void valueHasChanged(RegistrationPropertyDescription originating, Object oldValue, Object newValue, boolean isName)
+ {
+ if (isName)
+ {
+ // fake updating the property map if the old name was foo...
+ if ("foo".equals(oldValue))
+ {
+ // then set the prop name to the new property name
+ propName = originating.getName().getLocalPart();
+ }
+
+ notifyCalled = true;
+ }
+ }
+ }
+}
Property changes on: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/registration/RegistrationPropertyDescriptionTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
15 years, 1 month