[gatein-commits] gatein SVN: r953 - in portal/trunk/component: common and 21 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Dec 6 16:03:39 EST 2009


Author: julien_viet
Date: 2009-12-06 16:03:39 -0500 (Sun, 06 Dec 2009)
New Revision: 953

Added:
   portal/trunk/component/common/src/test/resources/conf/test-configuration.xml
   portal/trunk/component/test/
   portal/trunk/component/test/pom.xml
   portal/trunk/component/test/src/
   portal/trunk/component/test/src/main/
   portal/trunk/component/test/src/main/java/
   portal/trunk/component/test/src/main/java/org/
   portal/trunk/component/test/src/main/java/org/exoplatform/
   portal/trunk/component/test/src/main/java/org/exoplatform/component/
   portal/trunk/component/test/src/main/java/org/exoplatform/component/test/
   portal/trunk/component/test/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java
   portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfigurationUnit.java
   portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfiguredBy.java
   portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ContainerScope.java
   portal/trunk/component/test/src/main/java/org/exoplatform/component/test/GateInTestClassLoader.java
   portal/trunk/component/test/src/main/java/org/exoplatform/component/test/package-info.java
   portal/trunk/component/test/src/main/resources/
   portal/trunk/component/test/src/main/resources/conf/
   portal/trunk/component/test/src/main/resources/conf/jcr/
   portal/trunk/component/test/src/main/resources/conf/jcr/jcr-configuration.xml
   portal/trunk/component/test/src/main/resources/conf/jcr/repository-configuration.xml
   portal/trunk/component/test/src/main/resources/conf/portal-configuration.xml
   portal/trunk/component/test/src/main/resources/conf/root-configuration.xml
   portal/trunk/component/test/src/test/
   portal/trunk/component/test/src/test/java/
   portal/trunk/component/test/src/test/java/org/
   portal/trunk/component/test/src/test/java/org/exoplatform/
   portal/trunk/component/test/src/test/java/org/exoplatform/component/
   portal/trunk/component/test/src/test/java/org/exoplatform/component/test/
   portal/trunk/component/test/src/test/java/org/exoplatform/component/test/TestSomething.java
   portal/trunk/component/test/src/test/resources/
Removed:
   portal/trunk/component/common/src/main/java/conf/portal/
   portal/trunk/component/common/src/test/resources/conf/portal/
Modified:
   portal/trunk/component/common/pom.xml
   portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
   portal/trunk/component/pom.xml
   portal/trunk/component/portal/src/test/java/conf/portal/test-configuration.xml
Log:
- initial effort for rationalizing the unit test configuration


Modified: portal/trunk/component/common/pom.xml
===================================================================
--- portal/trunk/component/common/pom.xml	2009-12-06 17:47:33 UTC (rev 952)
+++ portal/trunk/component/common/pom.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -30,6 +30,7 @@
   <packaging>jar</packaging>
   <name>GateIn Portal Component Common</name>
   <dependencies>
+
     <dependency>
       <groupId>org.exoplatform.kernel</groupId>
       <artifactId>exo.kernel.commons</artifactId>
@@ -60,7 +61,15 @@
       <artifactId>chromattic.spi</artifactId>
       <version>${version.chromattic}</version>
     </dependency>
+
     <dependency>
+      <groupId>org.exoplatform.portal</groupId>
+      <artifactId>exo.portal.component.test</artifactId>
+      <version>3.0.0-Beta04-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>

Modified: portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java
===================================================================
--- portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java	2009-12-06 17:47:33 UTC (rev 952)
+++ portal/trunk/component/common/src/test/java/org/exoplatform/commons/chromattic/ChromatticIntegrationTestCase.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -18,9 +18,12 @@
  */
 package org.exoplatform.commons.chromattic;
 
-import junit.framework.TestCase;
 import org.chromattic.api.Chromattic;
 import org.chromattic.api.ChromatticSession;
+import org.exoplatform.component.test.AbstractGateInTest;
+import org.exoplatform.component.test.ConfigurationUnit;
+import org.exoplatform.component.test.ConfiguredBy;
+import org.exoplatform.component.test.ContainerScope;
 import org.exoplatform.container.PortalContainer;
 
 import javax.jcr.Session;
@@ -30,7 +33,11 @@
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
  * @version $Revision$
  */
-public class ChromatticIntegrationTestCase extends TestCase
+ at ConfiguredBy({
+   @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/jcr/jcr-configuration.xml"),
+   @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/test-configuration.xml")
+})
+public class ChromatticIntegrationTestCase extends AbstractGateInTest
 {
 
    /** . */
@@ -56,7 +63,7 @@
    public void testConfiguratorInitialized() throws Exception
    {
       assertNotNull(testLF);
-      assertEquals("test", testLF.getWorkspaceName());
+      assertEquals("portal-test", testLF.getWorkspaceName());
       assertNotNull(testLF.getChromattic());
       assertSame(chromatticManager, testLF.getManager());
    }
@@ -114,11 +121,11 @@
       {
          ChromatticSession session = testLF.getChromattic().openSession();
          FooEntity foo = session.create(FooEntity.class);
-         assertEquals("test", foo.getWorkspace());
+         assertEquals("portal-test", foo.getWorkspace());
          jcrSession = session.getJCRSession();
          assertTrue(jcrSession.isLive());
          Workspace workspace = jcrSession.getWorkspace();
-         assertEquals("test", workspace.getName());
+         assertEquals("portal-test", workspace.getName());
 
          session.close();
          assertTrue(jcrSession.isLive());
@@ -159,13 +166,13 @@
 
          // Check how chromattic see the session
          FooEntity foo = session.create(FooEntity.class);
-         assertEquals("test", foo.getWorkspace());
+         assertEquals("portal-test", foo.getWorkspace());
 
          // Check related JCR session
          jcrSession = session.getJCRSession();
          assertTrue(jcrSession.isLive());
          Workspace workspace = jcrSession.getWorkspace();
-         assertEquals("test", workspace.getName());
+         assertEquals("portal-test", workspace.getName());
 
          // Closing chromattic session should not close the underlying JCR session
          session.close();

Added: portal/trunk/component/common/src/test/resources/conf/test-configuration.xml
===================================================================
--- portal/trunk/component/common/src/test/resources/conf/test-configuration.xml	                        (rev 0)
+++ portal/trunk/component/common/src/test/resources/conf/test-configuration.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,52 @@
+<?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_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+  xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+  <component>
+    <key>org.exoplatform.commons.chromattic.ChromatticManager</key>
+    <type>org.exoplatform.commons.chromattic.ChromatticManager</type>
+  </component>
+  <external-component-plugins>
+    <target-component>org.exoplatform.commons.chromattic.ChromatticManager</target-component>
+    <component-plugin>
+      <name>chromattic</name>
+      <set-method>addLifeCycle</set-method>
+      <type>org.exoplatform.commons.chromattic.ChromatticLifeCycle</type>
+      <init-params>
+        <value-param>
+          <name>name</name>
+          <value>test</value>
+        </value-param>
+        <value-param>
+          <name>workspace-name</name>
+          <value>portal-test</value>
+        </value-param>
+        <values-param>
+          <name>entities</name>
+          <value>org.exoplatform.commons.chromattic.FooEntity</value>
+        </values-param>
+      </init-params>
+    </component-plugin>
+  </external-component-plugins>
+</configuration>

Modified: portal/trunk/component/pom.xml
===================================================================
--- portal/trunk/component/pom.xml	2009-12-06 17:47:33 UTC (rev 952)
+++ portal/trunk/component/pom.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -35,6 +35,7 @@
    <name>GateIn Portal Component</name>
 
    <modules>
+      <module>test</module>
       <module>common</module>
       <module>pc</module>
       <module>xml-parser</module>

Modified: portal/trunk/component/portal/src/test/java/conf/portal/test-configuration.xml
===================================================================
--- portal/trunk/component/portal/src/test/java/conf/portal/test-configuration.xml	2009-12-06 17:47:33 UTC (rev 952)
+++ portal/trunk/component/portal/src/test/java/conf/portal/test-configuration.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -24,6 +24,10 @@
   xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
   xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
 
+  <component>
+    <key>org.exoplatform.commons.chromattic.ChromatticManager</key>
+    <type>org.exoplatform.commons.chromattic.ChromatticManager</type>
+  </component>
 
   <component>
     <key>org.exoplatform.portal.pom.config.POMSessionManager</key>

Added: portal/trunk/component/test/pom.xml
===================================================================
--- portal/trunk/component/test/pom.xml	                        (rev 0)
+++ portal/trunk/component/test/pom.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,77 @@
+<!--
+  ~ 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.
+  -->
+
+<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.exoplatform.portal</groupId>
+    <artifactId>exo.portal.component</artifactId>
+    <version>3.0.0-Beta04-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>exo.portal.component.test</artifactId>
+  <packaging>jar</packaging>
+  <name>GateIn Portal Component Test</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+    </dependency>
+
+    <dependency>
+       <groupId>commons-collections</groupId>
+       <artifactId>commons-collections</artifactId>
+       <version>3.2.1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.exoplatform.kernel</groupId>
+      <artifactId>exo.kernel.commons</artifactId>
+      <version>${org.exoplatform.kernel.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.exoplatform.kernel</groupId>
+      <artifactId>exo.kernel.container</artifactId>
+      <version>${org.exoplatform.kernel.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.exoplatform.jcr</groupId>
+      <artifactId>exo.jcr.component.ext</artifactId>
+      <version>${org.exoplatform.jcr.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.exoplatform.core</groupId>
+      <artifactId>exo.core.component.organization.jdbc</artifactId>
+      <version>${org.exoplatform.core.version}</version>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <resources>
+       <resource>
+          <directory>src/main/resources</directory>
+       </resource>
+    </resources>
+  </build>
+
+</project>

Added: portal/trunk/component/test/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java
===================================================================
--- portal/trunk/component/test/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java	                        (rev 0)
+++ portal/trunk/component/test/src/main/java/org/exoplatform/component/test/AbstractGateInTest.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,86 @@
+/*
+ * 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.
+ */
+package org.exoplatform.component.test;
+
+import junit.framework.TestCase;
+
+import java.util.EnumMap;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * An abstract test that takes care of running the unit tests with the semantic described by the
+ * {#link GateInTestClassLoader}.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public abstract class AbstractGateInTest extends TestCase
+{
+
+   protected AbstractGateInTest()
+   {
+   }
+
+   protected AbstractGateInTest(String name)
+   {
+      super(name);
+   }
+
+   @Override
+   public void runBare() throws Throwable
+   {
+      ClassLoader realClassLoader = Thread.currentThread().getContextClassLoader();
+
+      //
+      Set<String> rootConfigPaths = new HashSet<String>();
+      rootConfigPaths.add("conf/root-configuration.xml");
+
+      //
+      Set<String> portalConfigPaths = new HashSet<String>();
+      portalConfigPaths.add("conf/portal-configuration.xml");
+
+      //
+      EnumMap<ContainerScope, Set<String>> configs = new EnumMap<ContainerScope, Set<String>>(ContainerScope.class);
+      configs.put(ContainerScope.ROOT, rootConfigPaths);
+      configs.put(ContainerScope.PORTAL, portalConfigPaths);
+
+      //
+      ConfiguredBy cfBy = getClass().getAnnotation(ConfiguredBy.class);
+      if (cfBy != null)
+      {
+         for (ConfigurationUnit src : cfBy.value())
+         {
+            configs.get(src.scope()).add(src.path());
+         }
+      }
+
+      //
+      try
+      {
+         ClassLoader testClassLoader = new GateInTestClassLoader(realClassLoader, rootConfigPaths, portalConfigPaths);
+         Thread.currentThread().setContextClassLoader(testClassLoader);
+         super.runBare();
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(realClassLoader);
+      }
+   }
+}

Added: portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfigurationUnit.java
===================================================================
--- portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfigurationUnit.java	                        (rev 0)
+++ portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfigurationUnit.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+package org.exoplatform.component.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Describe a configuration unit that targets a container scoped by the {@link org.exoplatform.component.test.ContainerScope}
+ * type. The path value is the absolute path that will be used to retrieve the configuration file via the
+ * {@link ClassLoader#getResources(String)} mechanism therefore the format is described by this mechanisme.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ConfigurationUnit
+{
+   /**
+    * The container scope.
+    *
+    * @return the container scope
+    */
+   ContainerScope scope();
+
+   /**
+    * The configuration path.
+    *
+    * @return the configuration path
+    */
+   String path();
+
+}

Added: portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfiguredBy.java
===================================================================
--- portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfiguredBy.java	                        (rev 0)
+++ portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ConfiguredBy.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.exoplatform.component.test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotates a unit test extending the {@link org.exoplatform.component.test.AbstractGateInTest} to provide
+ * the various configuration unit relevant for executing the unit test.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Target(ElementType.TYPE)
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ConfiguredBy
+{
+
+   /**
+    * Returns the various relevant configuration units.
+    *
+    * @return the configuration units
+    */
+   ConfigurationUnit[] value();
+
+}

Added: portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ContainerScope.java
===================================================================
--- portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ContainerScope.java	                        (rev 0)
+++ portal/trunk/component/test/src/main/java/org/exoplatform/component/test/ContainerScope.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+package org.exoplatform.component.test;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public enum ContainerScope
+{
+
+   ROOT, PORTAL
+
+}

Added: portal/trunk/component/test/src/main/java/org/exoplatform/component/test/GateInTestClassLoader.java
===================================================================
--- portal/trunk/component/test/src/main/java/org/exoplatform/component/test/GateInTestClassLoader.java	                        (rev 0)
+++ portal/trunk/component/test/src/main/java/org/exoplatform/component/test/GateInTestClassLoader.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+package org.exoplatform.component.test;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Set;
+import java.util.Vector;
+
+/**
+ * The GateIn test classloader overrides the <code>getResources(String)</code> method to filter the resources
+ * returned by the parent classloader in the following manner:
+ * <ul>
+ * <li>The loading of the <code>conf/configuration.xml</code> resource is replaced by the the configuration units
+ * scoped at {@link org.exoplatform.component.test.ContainerScope#ROOT}.</li>
+ * <li>The loading of the <code>conf/portal/configuration.xml</code> resource is replaced by the the configuration units
+ * scoped at {@link org.exoplatform.component.test.ContainerScope#PORTAL}.</li>
+ * </ul>
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public final class GateInTestClassLoader extends ClassLoader
+{
+
+   /** . */
+   private final Set<String> rootConfigPaths;
+
+   /** . */
+   private final Set<String> portalConfigPaths;
+
+   public GateInTestClassLoader(ClassLoader parent, Set<String> rootConfigPaths, Set<String> portalConfigPaths)
+   {
+      super(parent);
+
+      //
+      this.rootConfigPaths = rootConfigPaths;
+      this.portalConfigPaths = portalConfigPaths;
+   }
+
+   @Override
+   public Enumeration<URL> getResources(String name) throws IOException
+   {
+      System.out.println("name = " + name);
+      if ("conf/configuration.xml".equals(name))
+      {
+         return getURLs(rootConfigPaths);
+      }
+      else if ("conf/portal/configuration.xml".equals(name))
+      {
+         return getURLs(portalConfigPaths);
+      }
+      else if ("conf/portal/test-configuration.xml".equals(name))
+      {
+         return new Vector<URL>().elements();
+      }
+      else
+      {
+         return super.getResources(name);
+      }
+   }
+
+   private Enumeration<URL> getURLs(Set<String> paths) throws IOException
+   {
+      ArrayList<URL> urls = new ArrayList<URL>();
+      for (String path : paths)
+      {
+         urls.addAll(Collections.list(super.getResources(path)));
+      }
+      return Collections.enumeration(urls);
+   }
+}

Added: portal/trunk/component/test/src/main/java/org/exoplatform/component/test/package-info.java
===================================================================
--- portal/trunk/component/test/src/main/java/org/exoplatform/component/test/package-info.java	                        (rev 0)
+++ portal/trunk/component/test/src/main/java/org/exoplatform/component/test/package-info.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,4 @@
+/**
+ * The component provides a test infrastructure for various test of the GateIn components.
+ */
+package org.exoplatform.component.test;

Added: portal/trunk/component/test/src/main/resources/conf/jcr/jcr-configuration.xml
===================================================================
--- portal/trunk/component/test/src/main/resources/conf/jcr/jcr-configuration.xml	                        (rev 0)
+++ portal/trunk/component/test/src/main/resources/conf/jcr/jcr-configuration.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,183 @@
+<?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_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+   xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+  <component>
+     <key>org.exoplatform.services.idgenerator.IDGeneratorService</key>
+     <type>org.exoplatform.services.idgenerator.impl.IDGeneratorServiceImpl</type>
+  </component>
+
+  <component>
+     <type>org.exoplatform.services.security.IdentityRegistry</type>
+  </component>
+
+  <component>
+     <key>org.exoplatform.services.document.DocumentReaderService</key>
+     <type>org.exoplatform.services.document.impl.DocumentReaderServiceImpl</type>
+     <component-plugins>
+        <component-plugin>
+           <name>pdf.document.reader</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.PDFDocumentReader</type>
+           <description>to read the pdf inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.types</name>
+                 <description>description</description>
+                 <value>application/pdf</value>
+              </values-param>
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>document.readerMSWord</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.MSWordDocumentReader</type>
+           <description>to read the ms word inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.typesMSWord</name>
+                 <description>description</description>
+                 <value>application/msword</value>
+              </values-param>
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>document.readerMSExcel</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.MSExcelDocumentReader</type>
+           <description>to read the ms excel inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.typesMSExcel</name>
+                 <description>description</description>
+                 <value>application/excel</value>
+              </values-param>
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>document.readerMSOutlook</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.MSOutlookDocumentReader</type>
+           <description>to read the ms outlook inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.typesMSOutlook</name>
+                 <description>description</description>
+                 <value>application/vnd.ms-outlook</value>
+              </values-param>
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>PPTdocument.reader</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.PPTDocumentReader</type>
+           <description>to read the ms ppt inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.typesPPT</name>
+                 <description>description</description>
+                 <value>application/ppt</value>
+              </values-param>
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>document.readerHTML</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.HTMLDocumentReader</type>
+           <description>to read the html inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.typesHTML</name>
+                 <description>description</description>
+                 <value>text/html</value>
+              </values-param>
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>document.readerXML</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.XMLDocumentReader</type>
+           <description>to read the xml inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.typesXML</name>
+                 <description>description</description>
+                 <value>text/xml</value>
+              </values-param>
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>TPdocument.reader</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.TextPlainDocumentReader</type>
+           <description>to read the plain text inputstream</description>
+           <init-params>
+              <values-param>
+                 <name>document.known.typesTextPlain</name>
+                 <description>description</description>
+                 <value>text/plain</value>
+              </values-param>
+              <!-- values-param>
+                 <name>defaultEncoding</name>
+                 <description>description</description>
+                 <value>UTF-8</value>
+              </values-param -->
+           </init-params>
+        </component-plugin>
+
+        <component-plugin>
+           <name>document.readerOO</name>
+           <set-method>addDocumentReader</set-method>
+           <type>org.exoplatform.services.document.impl.OpenOfficeDocumentReader</type>
+           <description>to read the OO inputstream</description>
+        </component-plugin>
+
+     </component-plugins>
+  </component>
+
+  <component>
+    <key>org.exoplatform.services.jcr.config.RepositoryServiceConfiguration</key>
+    <type>org.exoplatform.services.jcr.impl.config.RepositoryServiceConfigurationImpl</type>
+    <init-params>
+      <value-param>
+        <name>conf-path</name>
+        <description>JCR configuration file</description>
+        <value>jar:/conf/jcr/repository-configuration.xml</value>
+      </value-param>
+    </init-params>
+  </component>
+
+  <component>
+    <key>org.exoplatform.services.jcr.RepositoryService</key>
+    <type>org.exoplatform.services.jcr.impl.RepositoryServiceImpl</type>
+  </component>
+
+</configuration>

Added: portal/trunk/component/test/src/main/resources/conf/jcr/repository-configuration.xml
===================================================================
--- portal/trunk/component/test/src/main/resources/conf/jcr/repository-configuration.xml	                        (rev 0)
+++ portal/trunk/component/test/src/main/resources/conf/jcr/repository-configuration.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,129 @@
+<!--
+  ~ 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.
+  -->
+
+<repository-service default-repository="repository">
+  <repositories>
+    <repository name="repository" system-workspace="system" default-workspace="portal-test">
+      <security-domain>gatein-domain</security-domain>
+      <access-control>optional</access-control>
+      <authentication-policy>org.exoplatform.services.jcr.impl.core.access.JAASAuthenticator</authentication-policy>
+
+      <!-- System --> 
+      <workspaces>
+        <workspace name="system">
+          <container class="org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer">
+            <properties>
+              <property name="source-name" value="jdbcexo"/>
+              <property name="dialect" value="hsqldb"/>
+              <property name="multi-db" value="false"/>
+              <property name="update-storage" value="true"/>
+              <property name="max-buffer-size" value="204800"/>
+              <property name="swap-directory" value="../temp/swap/system"/>
+            </properties>
+            <value-storages>
+              <value-storage id="system" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
+                <properties>
+                  <property name="path" value="../temp/values/system"/>
+                </properties>
+                <filters>
+                  <filter property-type="Binary"/>
+                </filters>
+              </value-storage>
+            </value-storages>
+          </container>
+          <initializer class="org.exoplatform.services.jcr.impl.core.ScratchWorkspaceInitializer">
+            <properties>
+              <property name="root-nodetype" value="nt:unstructured"/>
+              <property name="root-permissions" value="*:/platform/administrators read;*:/platform/administrators add_node;*:/platform/administrators set_property;*:/platform/administrators remove"/>
+            </properties>
+          </initializer>
+          <cache enabled="true">
+            <properties>
+              <property name="max-size" value="20000"/>
+              <property name="live-time" value="30000"/>
+            </properties>
+          </cache>
+          <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+            <properties>
+              <property name="index-dir" value="../temp/jcrlucenedb/system"/>
+            </properties>
+          </query-handler>
+          <lock-manager>
+            <time-out>15m</time-out><!-- 15min -->
+            <persister class="org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister">
+              <properties>
+                <property name="path" value="../temp/lock/system"/>
+              </properties>
+            </persister>
+           </lock-manager>
+        </workspace>
+
+        <!-- Portal system data -->
+        <workspace name="portal-test">
+          <container class="org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer">
+            <properties>
+              <property name="source-name" value="jdbcexo"/>
+              <property name="dialect" value="hsqldb"/>
+              <property name="multi-db" value="false"/>
+              <property name="update-storage" value="true"/>
+              <property name="max-buffer-size" value="204800"/>
+              <property name="swap-directory" value="../temp/swap/portal-test"/>
+            </properties>
+            <value-storages>
+              <value-storage id="portal-test" class="org.exoplatform.services.jcr.impl.storage.value.fs.TreeFileValueStorage">
+                <properties>
+                  <property name="path" value="../temp/values/portal-test"/>
+                </properties>
+                <filters>
+                  <filter property-type="Binary"/>
+                </filters>
+              </value-storage>
+            </value-storages>
+          </container>
+          <initializer class="org.exoplatform.services.jcr.impl.core.ScratchWorkspaceInitializer">
+            <properties>
+              <property name="root-nodetype" value="nt:unstructured"/>
+              <property name="root-permissions" value="any read;*:/platform/administrators read;*:/platform/administrators add_node;*:/platform/administrators set_property;*:/platform/administrators remove"/>
+            </properties>
+          </initializer>
+          <cache enabled="true">
+            <properties>
+              <property name="max-size" value="20000"/>
+              <property name="live-time" value="30000"/>
+            </properties>
+          </cache>
+          <query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex">
+            <properties>
+              <property name="index-dir" value="../temp/jcrlucenedb/portal-test"/>
+            </properties>
+          </query-handler>
+          <lock-manager>
+            <time-out>15m</time-out><!-- 15min -->
+            <persister class="org.exoplatform.services.jcr.impl.core.lock.FileSystemLockPersister">
+              <properties>
+                <property name="path" value="../temp/lock/portal-test"/>
+              </properties>
+            </persister>
+          </lock-manager>
+        </workspace>
+
+      </workspaces>
+    </repository>
+  </repositories>
+</repository-service>

Added: portal/trunk/component/test/src/main/resources/conf/portal-configuration.xml
===================================================================
--- portal/trunk/component/test/src/main/resources/conf/portal-configuration.xml	                        (rev 0)
+++ portal/trunk/component/test/src/main/resources/conf/portal-configuration.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,27 @@
+<?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_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+  xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+</configuration>

Added: portal/trunk/component/test/src/main/resources/conf/root-configuration.xml
===================================================================
--- portal/trunk/component/test/src/main/resources/conf/root-configuration.xml	                        (rev 0)
+++ portal/trunk/component/test/src/main/resources/conf/root-configuration.xml	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,73 @@
+<?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_0.xsd http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+               xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+
+  <component>
+    <type>org.exoplatform.container.definition.PortalContainerConfig</type>
+  </component>
+
+  <component>
+    <key>org.exoplatform.services.naming.InitialContextInitializer</key>
+    <type>org.exoplatform.services.naming.InitialContextInitializer</type>
+    <init-params>
+      <properties-param>
+        <name>default-properties</name>
+        <description>Default initial context properties</description>
+      </properties-param>
+    </init-params>
+  </component>
+
+  <external-component-plugins>
+    <target-component>org.exoplatform.services.naming.InitialContextInitializer</target-component>
+    <component-plugin>
+      <name>bind.datasource</name>
+      <set-method>addPlugin</set-method>
+      <type>org.exoplatform.services.naming.BindReferencePlugin</type>
+      <init-params>
+        <value-param>
+          <name>bind-name</name>
+          <value>jdbcexo</value>
+        </value-param>
+        <value-param>
+          <name>class-name</name>
+          <value>javax.sql.DataSource</value>
+        </value-param>
+        <value-param>
+          <name>factory</name>
+          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
+        </value-param>
+        <properties-param>
+          <name>ref-addresses</name>
+          <description>ref-addresses</description>
+          <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
+          <property name="url" value="jdbc:hsqldb:file:../temp/data/exodb"/>
+          <property name="username" value="sa"/>
+          <property name="password" value=""/>
+        </properties-param>
+      </init-params>
+    </component-plugin>
+  </external-component-plugins>
+
+</configuration>

Added: portal/trunk/component/test/src/test/java/org/exoplatform/component/test/TestSomething.java
===================================================================
--- portal/trunk/component/test/src/test/java/org/exoplatform/component/test/TestSomething.java	                        (rev 0)
+++ portal/trunk/component/test/src/test/java/org/exoplatform/component/test/TestSomething.java	2009-12-06 21:03:39 UTC (rev 953)
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+package org.exoplatform.component.test;
+
+import org.exoplatform.container.PortalContainer;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at ConfiguredBy(@ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/jcr/jcr-configuration.xml"))
+public class TestSomething extends AbstractGateInTest
+{
+
+   @Override
+   protected void setUp() throws Exception
+   {
+   }
+
+   public void testFoo() throws Exception
+   {
+
+      long t1 = System.currentTimeMillis();
+      PortalContainer container = PortalContainer.getInstance();
+      long t2 = System.currentTimeMillis();
+      System.out.println("container = " + container);
+      System.out.println("t = " + (t2 - t1));
+
+   }
+}



More information about the gatein-commits mailing list