Author: chris.laprun(a)jboss.com
Date: 2009-10-07 16:23:38 -0400 (Wed, 07 Oct 2009)
New Revision: 312
Added:
components/pc/trunk/api/src/test/
components/pc/trunk/api/src/test/java/
components/pc/trunk/api/src/test/java/org/
components/pc/trunk/api/src/test/java/org/gatein/
components/pc/trunk/api/src/test/java/org/gatein/pc/
components/pc/trunk/api/src/test/java/org/gatein/pc/api/
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java
components/pc/trunk/api/src/test/resources/
components/pc/trunk/api/src/test/resources/jboss-unit.xml
Modified:
components/pc/trunk/api/pom.xml
components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java
Log:
- Added extraction of PortletContext components methods as these components are used in
GateIn and internal implementation is leaked.
- Added related tests.
Modified: components/pc/trunk/api/pom.xml
===================================================================
--- components/pc/trunk/api/pom.xml 2009-10-07 15:32:46 UTC (rev 311)
+++ components/pc/trunk/api/pom.xml 2009-10-07 20:23:38 UTC (rev 312)
@@ -1,35 +1,68 @@
<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.pc</groupId>
- <artifactId>pc-parent</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.gatein.pc</groupId>
- <artifactId>pc-api</artifactId>
- <packaging>jar</packaging>
- <name>GateIn - Portlet Container (api)</name>
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.gatein.pc</groupId>
+ <artifactId>pc-parent</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.gatein.pc</groupId>
+ <artifactId>pc-api</artifactId>
+ <packaging>jar</packaging>
+ <name>GateIn - Portlet Container (api)</name>
- <dependencies>
- <dependency>
- <groupId>org.gatein.common</groupId>
- <artifactId>common-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.gatein.wci</groupId>
- <artifactId>wci-wci</artifactId>
- </dependency>
-
- <dependency>
- <groupId>sun-jaxb</groupId>
- <artifactId>jaxb-api</artifactId>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.gatein.common</groupId>
+ <artifactId>common-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.wci</groupId>
+ <artifactId>wci-wci</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>sun-jaxb</groupId>
+ <artifactId>jaxb-api</artifactId>
+ </dependency>
+ <!--<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>-->
+ <dependency>
+ <groupId>org.jboss.unit</groupId>
+ <artifactId>jboss-unit-mc</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jboss.unit</groupId>
+ <artifactId>jboss-unit-tooling-maven2</artifactId>
+ <executions>
+ <execution>
+ <phase>test</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <testsuites>
+ <testsuite>
+ <config>jboss-unit.xml</config>
+ </testsuite>
+ </testsuites>
+ <reports>
+ <xml>target/tests/reports/xml</xml>
+ <html>target/tests/reports/html</html>
+ </reports>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
Modified: components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java
===================================================================
--- components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java 2009-10-07
15:32:46 UTC (rev 311)
+++ components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java 2009-10-07
20:23:38 UTC (rev 312)
@@ -37,11 +37,47 @@
/** . */
protected final String id;
+ private final String applicationName;
+ private final String portletName;
+ private static final String PREFIX = "/";
+ private static final char SEPARATOR = '.';
PortletContext(String id) throws IllegalArgumentException
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "portlet
id", "PortletContext");
- this.id = id;
+
+ // components
+ String trimmedId = id.trim();
+ if (trimmedId.startsWith(PREFIX)) // only consider components if the id starts with
'/'
+ {
+ String compound = trimmedId.substring(1); // exclude starting '/'
+
+ int separator = compound.indexOf(SEPARATOR); // find first separator, other
separator are considered part of the portlet name
+ if (separator != -1)
+ {
+ portletName = compound.substring(separator + 1).trim();
+ applicationName = compound.substring(0, separator).trim();
+ }
+ else
+ {
+ portletName = null;
+ applicationName = null;
+ }
+ }
+ else
+ {
+ portletName = null;
+ applicationName = null;
+ }
+
+ if (portletName == null || applicationName == null)
+ {
+ this.id = trimmedId;
+ }
+ else
+ {
+ this.id = PREFIX + applicationName + SEPARATOR + portletName;
+ }
}
@@ -113,4 +149,14 @@
{
return createPortletContext(portletId, null);
}
+
+ public String getApplicationName()
+ {
+ return applicationName;
+ }
+
+ public String getPortletName()
+ {
+ return portletName;
+ }
}
Added:
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java
===================================================================
--- components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java
(rev 0)
+++
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java 2009-10-07
20:23:38 UTC (rev 312)
@@ -0,0 +1,96 @@
+/*
+* 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.pc.api;
+
+import static org.jboss.unit.api.Assert.*;
+import org.jboss.unit.api.pojo.annotations.Test;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class PortletContextTestCase
+{
+ @Test
+ public void testGetComponents()
+ {
+ PortletContext context =
PortletContext.createPortletContext("/applicationName.portletName");
+ assertEquals("applicationName", context.getApplicationName());
+ assertEquals("portletName", context.getPortletName());
+ assertEquals("/applicationName.portletName", context.getId());
+
+ context = PortletContext.createPortletContext("\t\t\n
/applicationName.portletName \t");
+ assertEquals("applicationName", context.getApplicationName());
+ assertEquals("portletName", context.getPortletName());
+ assertEquals("/applicationName.portletName", context.getId());
+
+ context = PortletContext.createPortletContext("/");
+ assertNull(context.getApplicationName());
+ assertNull(context.getPortletName());
+ assertEquals("/", context.getId());
+
+ context =
PortletContext.createPortletContext("applicationName.portletName");
+ assertNull(context.getApplicationName());
+ assertNull(context.getPortletName());
+ assertEquals("applicationName.portletName", context.getId());
+
+ context =
PortletContext.createPortletContext("/applicationName.portlet.Name");
+ assertEquals("applicationName", context.getApplicationName());
+ assertEquals("portlet.Name", context.getPortletName());
+ assertEquals("/applicationName.portlet.Name", context.getId());
+
+ context = PortletContext.createPortletContext("/.");
+ assertEquals("", context.getApplicationName());
+ assertEquals("", context.getPortletName());
+ assertEquals("/.", context.getId());
+
+ context = PortletContext.createPortletContext("/ applicationName\t. portlet
Name");
+ assertEquals("applicationName", context.getApplicationName());
+ assertEquals("portlet Name", context.getPortletName());
+ assertEquals("/applicationName.portlet Name", context.getId());
+ }
+
+ @Test
+ public void testCreateFromNullOrEmpty()
+ {
+ try
+ {
+ PortletContext.createPortletContext(null);
+ fail("Attempting to create a PortletContext from null should have thrown an
exception.");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+
+ try
+ {
+ PortletContext.createPortletContext("");
+ fail("Attempting to create a PortletContext from empty String should have
thrown an exception.");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+}
Copied: components/pc/trunk/api/src/test/resources/jboss-unit.xml (from rev 305,
components/pc/trunk/federation/src/test/resources/jboss-unit.xml)
===================================================================
--- components/pc/trunk/api/src/test/resources/jboss-unit.xml (rev
0)
+++ components/pc/trunk/api/src/test/resources/jboss-unit.xml 2009-10-07 20:23:38 UTC (rev
312)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<jboss-unit
+ xmlns="urn:jboss:jboss-unit:1.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:jboss-unit:1.0 jboss-unit_1_0.xsd">
+ <pojo>
+ <test>
+ <class name="org.gatein.pc.api.PortletContextTestCase"/>
+ </test>
+ </pojo>
+</jboss-unit>