Author: nfilotto
Date: 2010-02-18 15:52:14 -0500 (Thu, 18 Feb 2010)
New Revision: 1916
Added:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-config-with-settings.xml
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-test-settings-configuration.xml
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
Log:
EXOJCR-528: Unit tests for the PortalContainer has been added
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2010-02-18
17:56:36 UTC (rev 1915)
+++
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java 2010-02-18
20:52:14 UTC (rev 1916)
@@ -154,6 +154,7 @@
{
MockServletContext scontext = new MockServletContext(name);
pcontainer = new PortalContainer(this, scontext);
+ PortalContainer.setInstance(pcontainer);
ConfigurationManagerImpl cService = new
MockConfigurationManagerImpl(scontext);
cService.addConfiguration(ContainerUtil.getConfigurationURL("conf/portal/configuration.xml"));
cService.addConfiguration(ContainerUtil.getConfigurationURL("conf/portal/test-configuration.xml"));
@@ -161,7 +162,6 @@
pcontainer.registerComponentInstance(ConfigurationManager.class,
cService);
pcontainer.initContainer();
registerComponentInstance(name, pcontainer);
- PortalContainer.setInstance(pcontainer);
pcontainer.start();
}
catch (Exception ex)
Modified:
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-02-18
17:56:36 UTC (rev 1915)
+++
kernel/trunk/exo.kernel.container/src/main/java/org/exoplatform/container/definition/PortalContainerConfig.java 2010-02-18
20:52:14 UTC (rev 1916)
@@ -66,7 +66,7 @@
/**
* The name of the setting corresponding to the rest context name
*/
- public static final String REST_CONTEXT_SETTING_NAME = "rest.context";
+ public static final String REST_CONTEXT_SETTING_NAME = "rest";
/**
* The name of the setting corresponding to the relam name
Added:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java
(rev 0)
+++
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java 2010-02-18
20:52:14 UTC (rev 1916)
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.container;
+
+import org.exoplatform.container.jmx.AbstractTestContainer;
+import org.exoplatform.container.support.ContainerBuilder;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.ValueParam;
+
+import java.net.URL;
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 18 f�vr. 2010
+ */
+public class TestPortalContainer extends AbstractTestContainer
+{
+ public void testInitValues()
+ {
+ createRootContainer("portal-container-config-with-settings.xml");
+ assertEquals("myPortal", PortalContainer.DEFAULT_PORTAL_CONTAINER_NAME);
+ assertEquals("myRest", PortalContainer.DEFAULT_REST_CONTEXT_NAME);
+ assertEquals("my-exo-domain", PortalContainer.DEFAULT_REALM_NAME);
+ // With portal container with no portal container
+ PortalContainer portal = PortalContainer.getInstance();
+ assertEquals("myPortal", portal.getName());
+ assertEquals("myRest", portal.getRestContextName());
+ assertEquals("my-exo-domain", portal.getRealmName());
+
+ assertTrue(PortalContainer.isPortalContainerName("myPortal"));
+ assertTrue(PortalContainer.isPortalContainerName("portal"));
+ assertFalse(PortalContainer.isPortalContainerName("foo"));
+
+ URL rootURL =
getClass().getResource("portal-container-config-with-settings.xml");
+ URL portalURL =
getClass().getResource("portal-container-test-settings-configuration.xml");
+ assertNotNull(rootURL);
+ assertNotNull(portalURL);
+ //
+ new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
+ // With portal container with no portal container
+ portal = PortalContainer.getInstance();
+ assertEquals("portal", portal.getName());
+ assertEquals("myRest-pcdef", portal.getRestContextName());
+ assertEquals("my-exo-domain-pcdef", portal.getRealmName());
+
+ assertNotNull(portal.getContext());
+ assertEquals("portal", portal.getContext().getPortalContainerName());
+ assertEquals("myRest-pcdef", portal.getContext().getRestContextName());
+ assertEquals("my-exo-domain-pcdef", portal.getContext().getRealmName());
+
+ assertEquals("portal", PortalContainer.getCurrentPortalContainerName());
+ assertEquals("myRest-pcdef",
PortalContainer.getCurrentRestContextName());
+ assertEquals("my-exo-domain-pcdef",
PortalContainer.getCurrentRealmName());
+
+ assertEquals("myRest-pcdef",
PortalContainer.getRestContextName("portal"));
+ assertEquals("my-exo-domain-pcdef",
PortalContainer.getRealmName("portal"));
+ assertEquals("myRest",
PortalContainer.getRestContextName("foo"));
+ assertEquals("my-exo-domain",
PortalContainer.getRealmName("foo"));
+
+ assertTrue(PortalContainer.isPortalContainerName("myPortal"));
+ assertTrue(PortalContainer.isPortalContainerName("portal"));
+ assertFalse(PortalContainer.isPortalContainerName("foo"));
+
+ // With no portal container
+ PortalContainer.setInstance(null);
+
+ assertEquals("myPortal",
PortalContainer.getCurrentPortalContainerName());
+ assertEquals("myRest", PortalContainer.getCurrentRestContextName());
+ assertEquals("my-exo-domain", PortalContainer.getCurrentRealmName());
+
+ assertTrue(PortalContainer.isPortalContainerName("myPortal"));
+ assertTrue(PortalContainer.isPortalContainerName("portal"));
+ assertFalse(PortalContainer.isPortalContainerName("foo"));
+ }
+
+ public void testSettings()
+ {
+ URL rootURL =
getClass().getResource("portal-container-config-with-settings.xml");
+ URL portalURL =
getClass().getResource("portal-container-test-settings-configuration.xml");
+ assertNotNull(rootURL);
+ assertNotNull(portalURL);
+ //
+ new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
+ // With portal container
+ PortalContainer portal = PortalContainer.getInstance();
+ MyComponent component =
(MyComponent)portal.getComponentInstanceOfType(MyComponent.class);
+ assertNotNull(component);
+ assertEquals("portal", component.getValue("portal"));
+ assertEquals("myRest-pcdef", component.getValue("rest"));
+ assertEquals("my-exo-domain-pcdef",
component.getValue("realm"));
+ assertEquals("value", component.getValue("foo"));
+ assertEquals("before value after", component.getValue("before foo
after"));
+
+ assertEquals("value", portal.getSetting("foo"));
+ assertNull(portal.getSetting("foo2"));
+ assertEquals("value", portal.getSetting("string"));
+ assertEquals(new Integer(10), portal.getSetting("int"));
+ assertEquals(new Long(10), portal.getSetting("long"));
+ assertEquals(new Double(10), portal.getSetting("double"));
+ assertEquals(new Boolean(true), portal.getSetting("boolean"));
+
+ assertNotNull(portal.getContext());
+ assertEquals("value", portal.getContext().getSetting("foo"));
+ assertNull(portal.getContext().getSetting("foo2"));
+ assertEquals("value",
portal.getContext().getSetting("string"));
+ assertEquals(new Integer(10), portal.getContext().getSetting("int"));
+ assertEquals(new Long(10), portal.getContext().getSetting("long"));
+ assertEquals(new Double(10), portal.getContext().getSetting("double"));
+ assertEquals(new Boolean(true),
portal.getContext().getSetting("boolean"));
+
+ assertEquals("value",
PortalContainer.getCurrentSetting("foo"));
+ assertNull(PortalContainer.getCurrentSetting("foo2"));
+ assertEquals("value",
PortalContainer.getCurrentSetting("string"));
+ assertEquals(new Integer(10), PortalContainer.getCurrentSetting("int"));
+ assertEquals(new Long(10), PortalContainer.getCurrentSetting("long"));
+ assertEquals(new Double(10),
PortalContainer.getCurrentSetting("double"));
+ assertEquals(new Boolean(true),
PortalContainer.getCurrentSetting("boolean"));
+
+ assertEquals("value", PortalContainer.getSetting("portal",
"foo"));
+ assertNull(PortalContainer.getSetting("portal", "foo2"));
+ assertEquals("value", PortalContainer.getSetting("portal",
"string"));
+ assertEquals(new Integer(10), PortalContainer.getSetting("portal",
"int"));
+ assertEquals(new Long(10), PortalContainer.getSetting("portal",
"long"));
+ assertEquals(new Double(10), PortalContainer.getSetting("portal",
"double"));
+ assertEquals(new Boolean(true), PortalContainer.getSetting("portal",
"boolean"));
+
+ assertNull(PortalContainer.getSetting("foo", "foo"));
+ assertNull(PortalContainer.getSetting("foo", "foo2"));
+ assertNull(PortalContainer.getSetting("foo", "string"));
+ assertNull(PortalContainer.getSetting("foo", "int"));
+ assertNull(PortalContainer.getSetting("foo", "long"));
+ assertNull(PortalContainer.getSetting("foo", "double"));
+ assertNull(PortalContainer.getSetting("foo", "boolean"));
+
+ // With no portal container
+ PortalContainer.setInstance(null);
+
+ assertNull(PortalContainer.getCurrentSetting("foo"));
+ assertNull(PortalContainer.getCurrentSetting("foo2"));
+ assertNull(PortalContainer.getCurrentSetting("string"));
+ assertNull(PortalContainer.getCurrentSetting("int"));
+ assertNull(PortalContainer.getCurrentSetting("long"));
+ assertNull(PortalContainer.getCurrentSetting("double"));
+ assertNull(PortalContainer.getCurrentSetting("boolean"));
+ }
+
+ public static class MyComponent
+ {
+ private final InitParams params;
+ public MyComponent(InitParams params)
+ {
+ this.params = params;
+ }
+
+ public String getValue(String name)
+ {
+ final ValueParam vp = params.getValueParam(name);
+ return vp == null ? null : vp.getValue();
+ }
+ }
+}
Modified:
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-02-18
17:56:36 UTC (rev 1915)
+++
kernel/trunk/exo.kernel.container/src/test/java/org/exoplatform/container/definition/TestPortalContainerConfig.java 2010-02-18
20:52:14 UTC (rev 1916)
@@ -1,5 +1,3 @@
-package org.exoplatform.container.definition;
-
/*
* Copyright (C) 2003-2010 eXo Platform SAS.
*
@@ -16,6 +14,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not,
see<http://www.gnu.org/licenses/>.
*/
+package org.exoplatform.container.definition;
+
import org.exoplatform.container.RootContainer;
import org.exoplatform.container.jmx.AbstractTestContainer;
import org.exoplatform.container.monitor.jvm.J2EEServerInfo;
@@ -31,7 +31,7 @@
public class TestPortalContainerConfig extends AbstractTestContainer
{
- public void testInitValues() throws Exception
+ public void testInitValues()
{
RootContainer rootContainer = createRootContainer("empty-config.xml");
PortalContainerConfig config =
@@ -260,8 +260,12 @@
}
finally
{
- if (oldPath != null)
+ if (oldPath == null)
{
+ System.getProperties().remove(J2EEServerInfo.EXO_CONF_PARAM);
+ }
+ else
+ {
System.setProperty(J2EEServerInfo.EXO_CONF_PARAM, oldPath);
}
}
Added:
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-config-with-settings.xml
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-config-with-settings.xml
(rev 0)
+++
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-config-with-settings.xml 2010-02-18
20:52:14 UTC (rev 1916)
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+ <!--
+
+ Copyright (C) 2009 eXo Platform SAS. 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.
+ -->
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+ <component>
+ <!-- The full qualified name of the PortalContainerConfig -->
+ <type>org.exoplatform.container.definition.PortalContainerConfig</type>
+ <init-params>
+ <!-- The name of the default portal container -->
+ <value-param>
+ <name>default.portal.container</name>
+ <value>myPortal</value>
+ </value-param>
+ <!-- The name of the default rest ServletContext -->
+ <value-param>
+ <name>default.rest.context</name>
+ <value>myRest</value>
+ </value-param>
+ <!-- The name of the default realm -->
+ <value-param>
+ <name>default.realm.name</name>
+ <value>my-exo-domain</value>
+ </value-param>
+ </init-params>
+ </component>
+ <external-component-plugins>
+ <!-- The full qualified name of the PortalContainerConfig -->
+ <target-component>org.exoplatform.container.definition.PortalContainerConfig</target-component>
+ <component-plugin>
+ <!-- The name of the plugin -->
+ <name>Add PortalContainer Definitions</name>
+ <!-- The name of the method to call on the PortalContainerConfig in order to
register the PortalContainerDefinitions -->
+ <set-method>registerPlugin</set-method>
+ <!-- The full qualified name of the PortalContainerDefinitionPlugin -->
+ <type>org.exoplatform.container.definition.PortalContainerDefinitionPlugin</type>
+ <init-params>
+ <object-param>
+ <name>portal</name>
+ <object
type="org.exoplatform.container.definition.PortalContainerDefinition">
+ <!-- The name of the portal container -->
+ <field name="name">
+ <string>portal</string>
+ </field>
+ <!-- The name of the context name of the rest web application -->
+ <field name="restContextName">
+ <string>myRest-pcdef</string>
+ </field>
+ <!-- The name of the realm -->
+ <field name="realmName">
+ <string>my-exo-domain-pcdef</string>
+ </field>
+ <!-- A map of settings tied to the portal container -->
+ <field name="settings">
+ <map type="java.util.HashMap">
+ <entry>
+ <key>
+ <string>foo</string>
+ </key>
+ <value>
+ <string>value</string>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <string>string</string>
+ </key>
+ <value>
+ <string>value</string>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <string>int</string>
+ </key>
+ <value>
+ <int>10</int>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <string>long</string>
+ </key>
+ <value>
+ <long>10</long>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <string>double</string>
+ </key>
+ <value>
+ <double>10</double>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <string>boolean</string>
+ </key>
+ <value>
+ <boolean>true</boolean>
+ </value>
+ </entry>
+ </map>
+ </field>
+ </object>
+ </object-param>
+ </init-params>
+ </component-plugin>
+ </external-component-plugins>
+</configuration>
\ No newline at end of file
Added:
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-test-settings-configuration.xml
===================================================================
---
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-test-settings-configuration.xml
(rev 0)
+++
kernel/trunk/exo.kernel.container/src/test/resources/org/exoplatform/container/portal-container-test-settings-configuration.xml 2010-02-18
20:52:14 UTC (rev 1916)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+ <!--
+
+ Copyright (C) 2009 eXo Platform SAS. 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.
+ -->
+<configuration
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd
http://www.exoplaform.org/xml/ns/kernel_1_1.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_1.xsd">
+ <component>
+ <type>org.exoplatform.container.TestPortalContainer$MyComponent</type>
+ <init-params>
+ <!-- The name of the portal container -->
+ <value-param>
+ <name>portal</name>
+ <value>${portal.container.name}</value>
+ </value-param>
+ <!-- The name of the rest ServletContext -->
+ <value-param>
+ <name>rest</name>
+ <value>${portal.container.rest}</value>
+ </value-param>
+ <!-- The name of the realm -->
+ <value-param>
+ <name>realm</name>
+ <value>${portal.container.realm}</value>
+ </value-param>
+ <value-param>
+ <name>foo</name>
+ <value>${portal.container.foo}</value>
+ </value-param>
+ <value-param>
+ <name>before foo after</name>
+ <value>before ${portal.container.foo} after</value>
+ </value-param>
+ </init-params>
+ </component>
+
+</configuration>
\ No newline at end of file