[exo-jcr-commits] exo-jcr SVN: r1070 - in kernel/branches/config-branch/exo.kernel.container/src: main/java/org/exoplatform/container/jmx and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Dec 15 11:57:58 EST 2009


Author: julien_viet
Date: 2009-12-15 11:57:58 -0500 (Tue, 15 Dec 2009)
New Revision: 1070

Added:
   kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestPortalContainerManagedIntegration.java
   kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/support/SimpleManagementAware.java
   kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/support/
   kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/support/ContainerBuilder.java
   kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/portal-configuration.xml
   kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/root-configuration.xml
Modified:
   kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
   kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ExoModelMBean.java
   kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManageableContainer.java
   kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManagementContextImpl.java
   kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/RootContainerBootstrap.java
   kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java
Log:
- more unit testing
- actually fix bugs


Modified: kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java	2009-12-15 16:34:43 UTC (rev 1069)
+++ kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/RootContainer.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -420,6 +420,7 @@
       }
       catch (Exception e)
       {
+         e.printStackTrace();
          log.error("Could not build root container", e);
          return null;
       }

Modified: kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ExoModelMBean.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ExoModelMBean.java	2009-12-15 16:34:43 UTC (rev 1069)
+++ kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ExoModelMBean.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -173,6 +173,12 @@
 
    //
 
+
+   public ManagementContext getManagementContext()
+   {
+      return context;
+   }
+
    public Object getManagedResource()
    {
       return mr;

Modified: kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManageableContainer.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManageableContainer.java	2009-12-15 16:34:43 UTC (rev 1069)
+++ kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManageableContainer.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -19,6 +19,7 @@
 package org.exoplatform.container.jmx;
 
 import org.exoplatform.container.CachingContainer;
+import org.exoplatform.management.ManagementContext;
 import org.picocontainer.ComponentAdapter;
 import org.picocontainer.PicoContainer;
 import org.picocontainer.PicoRegistrationException;
@@ -98,10 +99,16 @@
          if (parentManagementContext != null)
          {
             managementContext = new ManagementContextImpl(parentManagementContext, new HashMap<String, String>());
+            managementContext.container  = this;
          }
       }
    }
 
+   public ManagementContext getManagementContext()
+   {
+      return managementContext;
+   }
+
    public final MBeanServer getMBeanServer()
    {
       return managementContext != null ? managementContext.server : null;

Modified: kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManagementContextImpl.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManagementContextImpl.java	2009-12-15 16:34:43 UTC (rev 1069)
+++ kernel/branches/config-branch/exo.kernel.container/src/main/java/org/exoplatform/container/jmx/ManagementContextImpl.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -67,6 +67,10 @@
 
    public ManagementContextImpl(MBeanServer server, Map<String, String> scopingProperties)
    {
+      if (server == null)
+      {
+         throw new NullPointerException();
+      }
       this.registrations = new HashMap<Object, ObjectName>();
       this.parent = null;
       this.scopingProperties = scopingProperties;
@@ -75,12 +79,21 @@
 
    public ManagementContextImpl(ManagementContextImpl parent, Map<String, String> scopingProperties)
    {
+      if (parent == null)
+      {
+         throw new NullPointerException();
+      }
       this.registrations = new HashMap<Object, ObjectName>();
       this.parent = parent;
       this.scopingProperties = scopingProperties;
       this.server = parent.server;
    }
 
+   public ManagementContext getParent()
+   {
+      return parent;
+   }
+
    public void register(Object o)
    {
       ObjectName name = manageMBean(o);
@@ -279,4 +292,10 @@
          }
       }
    }
+
+   @Override
+   public String toString()
+   {
+      return "ManagementContextImpl[container=" + container + "]";
+   }
 }

Modified: kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/RootContainerBootstrap.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/RootContainerBootstrap.java	2009-12-15 16:34:43 UTC (rev 1069)
+++ kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/RootContainerBootstrap.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -16,9 +16,11 @@
  */
 package org.exoplatform.container;
 
+import junit.framework.AssertionFailedError;
 import org.exoplatform.container.configuration.ConfigurationManager;
 import org.exoplatform.container.configuration.ConfigurationManagerImpl;
 
+import java.lang.reflect.Field;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -32,8 +34,25 @@
 
    public static RootContainer bootstrap(URL configurationURL, String... profiles)
    {
+      // Must clear the top container first otherwise it's not going to work well
+      // it's a big ugly but I don't want to change anything in the ExoContainerContext class for now
+      // and this is for unit testing
       try
       {
+         Field topContainerField = ExoContainerContext.class.getDeclaredField("topContainer");
+         topContainerField.setAccessible(true);
+         topContainerField.set(null, null);
+      }
+      catch (Exception e)
+      {
+         AssertionFailedError err = new AssertionFailedError();
+         err.initCause(e);
+         throw err;
+      }
+
+      // Create a root container manually
+      try
+      {
          RootContainer container = new RootContainer();
          ConfigurationManager manager = new ConfigurationManagerImpl(new HashSet<String>(Arrays.asList(profiles)));
          manager.addConfiguration(configurationURL);

Modified: kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java	2009-12-15 16:34:43 UTC (rev 1069)
+++ kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/AbstractTestContainer.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -20,10 +20,15 @@
 
 import junit.framework.TestCase;
 
+import org.exoplatform.container.PortalContainer;
 import org.exoplatform.container.RootContainer;
 import org.exoplatform.container.RootContainerBootstrap;
 
+import java.io.IOException;
 import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
 
 /**
  * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
@@ -39,4 +44,41 @@
       return RootContainerBootstrap.bootstrap(url);
    }
 
+   public PortalContainer createPortalContainer(RootContainer container, String name, String relativeConfigurationFile)
+   {
+      final URL url = getClass().getResource(relativeConfigurationFile);
+      ClassLoader cl = new ClassLoader(Thread.currentThread().getContextClassLoader())
+      {
+         @Override
+         public Enumeration<URL> getResources(String name) throws IOException
+         {
+            if ("conf/portal/configuration.xml".equals(name))
+            {
+               return Collections.enumeration(Arrays.asList(url));
+            }
+            else if ("conf/portal/test-configuration.xml".equals(name))
+            {
+               return Collections.enumeration(Collections.<URL>emptyList());
+            }
+            else
+            {
+               return super.getResources(name);
+            }
+         }
+      };
+
+      //
+      Thread.currentThread().setContextClassLoader(cl);
+
+      //
+      try
+      {
+         return container.getPortalContainer(name);
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(null);
+      }
+   }
+
 }

Added: kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestPortalContainerManagedIntegration.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestPortalContainerManagedIntegration.java	                        (rev 0)
+++ kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/TestPortalContainerManagedIntegration.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2003-2007 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.jmx;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.RootContainer;
+import org.exoplatform.container.jmx.support.SimpleManagementAware;
+import org.exoplatform.container.support.ContainerBuilder;
+
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class TestPortalContainerManagedIntegration extends AbstractTestContainer
+{
+
+   public void testManagementContext()
+   {
+      URL rootURL = TestPortalContainerManagedIntegration.class.getResource("root-configuration.xml");
+      URL portalURL = TestPortalContainerManagedIntegration.class.getResource("portal-configuration.xml");
+
+      //
+      RootContainer root = new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
+      ManagementContextImpl rootManagementContext = (ManagementContextImpl)root.getManagementContext();
+
+      //
+      PortalContainer portal = PortalContainer.getInstance();
+      ManagementContextImpl portalManagementContext = (ManagementContextImpl)portal.getManagementContext();
+      assertSame(root.getManagementContext(), portalManagementContext.getParent());
+      assertSame(portal, portalManagementContext.findContainer());
+
+      //
+      SimpleManagementAware rootManagementAware = (SimpleManagementAware)root.getComponentInstance("RootManagementAware");
+      ManagementContextImpl rootManagementAwareContext = (ManagementContextImpl)((ExoModelMBean)rootManagementAware.context).getManagementContext();
+      assertSame(rootManagementContext, rootManagementAwareContext.getParent());
+
+      //
+      SimpleManagementAware portalManagementAware = (SimpleManagementAware)portal.getComponentInstance("PortalManagementAware");
+      ManagementContextImpl portalManagementAwareContext = (ManagementContextImpl)((ExoModelMBean)portalManagementAware.context).getManagementContext();
+      assertSame(portalManagementContext, portalManagementAwareContext.getParent());
+   }
+
+}

Added: kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/support/SimpleManagementAware.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/support/SimpleManagementAware.java	                        (rev 0)
+++ kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/jmx/support/SimpleManagementAware.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2003-2007 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.jmx.support;
+
+import org.exoplatform.management.ManagementAware;
+import org.exoplatform.management.ManagementContext;
+import org.exoplatform.management.annotations.Managed;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.NamingContext;
+import org.exoplatform.management.jmx.annotations.Property;
+
+/**
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+ at Managed
+ at NameTemplate(@Property(key = "name", value = "SimpleManagementAware"))
+public class SimpleManagementAware implements ManagementAware
+{
+
+   public ManagementContext context;
+
+   public void setContext(ManagementContext context)
+   {
+      this.context = context;
+   }
+}

Added: kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/support/ContainerBuilder.java
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/support/ContainerBuilder.java	                        (rev 0)
+++ kernel/branches/config-branch/exo.kernel.container/src/test/java/org/exoplatform/container/support/ContainerBuilder.java	2009-12-15 16:57:58 UTC (rev 1070)
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2003-2007 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.support;
+
+import junit.framework.AssertionFailedError;
+import org.exoplatform.commons.utils.Tools;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.RootContainer;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * An helper for building a root container and a portal container.
+ *
+ * @author <a href="mailto:julien.viet at exoplatform.com">Julien Viet</a>
+ * @version $Revision$
+ */
+public class ContainerBuilder
+{
+
+   private ClassLoader loader;
+
+   private List<URL> configURLs;
+
+   private List<URL> portalConfigURLs;
+
+   private Set<String> profiles;
+
+   public ContainerBuilder()
+   {
+      this.loader = Thread.currentThread().getContextClassLoader();
+      this.configURLs = new ArrayList<URL>();
+      this.portalConfigURLs = new ArrayList<URL>();
+   }
+
+   public ContainerBuilder withRoot(String configPath)
+   {
+      configURLs.addAll(urls(configPath));
+      return this;
+   }
+
+   public ContainerBuilder withRoot(URL configURL)
+   {
+      configURLs.add(configURL);
+      return this;
+   }
+
+   public ContainerBuilder withPortal(String configPath)
+   {
+      portalConfigURLs.addAll(urls(configPath));
+      return this;
+   }
+
+   public ContainerBuilder withPortal(URL configURL)
+   {
+      portalConfigURLs.add(configURL);
+      return this;
+   }
+
+   private List<URL> urls(String path)
+   {
+      try
+      {
+         return Collections.list(loader.getResources(path));
+      }
+      catch (IOException e)
+      {
+         AssertionFailedError err = new AssertionFailedError();
+         err.initCause(e);
+         throw err;
+      }
+   }
+
+   public ContainerBuilder withLoader(ClassLoader loader)
+   {
+      this.loader = loader;
+      return this;
+   }
+
+   public ContainerBuilder profiledBy(String ... profiles)
+   {
+      this.profiles = Tools.set(profiles);
+      return this;
+   }
+
+   public RootContainer build()
+   {
+      try
+      {
+         return _build();
+      }
+      catch (Exception e)
+      {
+         AssertionFailedError err = new AssertionFailedError();
+         err.initCause(e);
+         throw err;
+      }
+   }
+
+   private RootContainer _build() throws Exception
+   {
+      // Must clear the top container first otherwise it's not going to work well
+      // it's a big ugly but I don't want to change anything in the ExoContainerContext class for now
+      // and this is for unit testing
+      Field topContainerField = ExoContainerContext.class.getDeclaredField("topContainer");
+      topContainerField.setAccessible(true);
+      topContainerField.set(null, null);
+
+      //
+      ClassLoader rootCL = new ClassLoader(loader)
+      {
+         @Override
+         public Enumeration<URL> getResources(String name) throws IOException
+         {
+            if ("conf/configuration.xml".equals(name))
+            {
+               return Collections.enumeration(configURLs);
+            }
+            else if ("conf/portal/configuration.xml".equals(name))
+            {
+               return Collections.enumeration(portalConfigURLs);
+            }
+            else if ("conf/portal/test-configuration.xml".equals(name))
+            {
+               return Collections.enumeration(Collections.<URL>emptyList());
+            }
+            else
+            {
+               return super.getResources(name);
+            }
+         }
+      };
+
+      //
+      ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+
+      // Boot root container
+      RootContainer root;
+      try
+      {
+         Thread.currentThread().setContextClassLoader(rootCL);
+         root = RootContainer.getInstance();
+         root.getPortalContainer("portal");
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(oldCL);
+      }
+
+      //
+      return root;
+   }
+}

Added: kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/portal-configuration.xml
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/portal-configuration.xml	                        (rev 0)
+++ kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/portal-configuration.xml	2009-12-15 16:57:58 UTC (rev 1070)
@@ -0,0 +1,32 @@
+<?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>PortalManagementAware</key>
+    <type>org.exoplatform.container.jmx.support.SimpleManagementAware</type>
+  </component>
+
+</configuration>
\ No newline at end of file

Added: kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/root-configuration.xml
===================================================================
--- kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/root-configuration.xml	                        (rev 0)
+++ kernel/branches/config-branch/exo.kernel.container/src/test/resources/org/exoplatform/container/jmx/root-configuration.xml	2009-12-15 16:57:58 UTC (rev 1070)
@@ -0,0 +1,36 @@
+<?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>RootManagementAware</key>
+    <type>org.exoplatform.container.jmx.support.SimpleManagementAware</type>
+  </component>
+
+</configuration>
\ No newline at end of file



More information about the exo-jcr-commits mailing list