[exo-jcr-commits] exo-jcr SVN: r1009 - in kernel/branches/mc-int-branch/exo.kernel.mc-integration: exo.kernel.mc-int-demo/src/main/java/org/exoplatform/kernel/demos/mc and 4 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Dec 11 11:01:38 EST 2009
Author: mstruk
Date: 2009-12-11 11:01:37 -0500 (Fri, 11 Dec 2009)
New Revision: 1009
Added:
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/ExternalMCInjectionTest.java
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/test/java/org/exoplatform/kernel/it/TestExternalMCInjectionIntegration.java
Modified:
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/resources/conf/mc-int-config.xml
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java
kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java
Log:
Fix imports + add test for external property injection config
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java 2009-12-11 15:14:51 UTC (rev 1008)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCComponentAdapter.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -2,7 +2,6 @@
import org.jboss.beans.info.spi.BeanAccessMode;
import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
-import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.dependency.plugins.helpers.StatelessController;
import org.jboss.dependency.spi.ControllerState;
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java 2009-12-11 15:14:51 UTC (rev 1008)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int/src/main/java/org/exoplatform/container/mc/impl/MCIntegrationImpl.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -5,22 +5,14 @@
import org.exoplatform.services.log.Log;
import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
import org.jboss.beans.metadata.spi.AnnotationMetaData;
-import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.dependency.AbstractKernelController;
-import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
-import org.jboss.kernel.spi.deployment.KernelDeployment;
import org.jboss.mc.common.ThreadLocalUtils;
import org.jboss.mc.servlet.vdf.api.VDFThreadLocalUtils;
import org.picocontainer.ComponentAdapter;
import javax.servlet.ServletContext;
-import java.io.IOException;
import java.lang.annotation.Annotation;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Set;
/**
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java 2009-12-11 15:14:51 UTC (rev 1008)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/java/org/exoplatform/kernel/demos/mc/ExternallyControlledInjectingBean.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -16,9 +16,11 @@
private String stringValue;
private int startCount;
+ private ConfigurationHolder config;
+
public ExternallyControlledInjectingBean()
{
-
+ config = new ConfigurationHolder();
}
public TransactionManager getTransactionManager()
@@ -74,4 +76,24 @@
public void stop()
{
}
+
+ public ConfigurationHolder getConfig()
+ {
+ return config;
+ }
+
+ public static class ConfigurationHolder
+ {
+ private String someProperty;
+
+ public String getSomeProperty()
+ {
+ return someProperty;
+ }
+
+ public void setSomeProperty(String someProperty)
+ {
+ this.someProperty = someProperty;
+ }
+ }
}
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/resources/conf/mc-int-config.xml
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/resources/conf/mc-int-config.xml 2009-12-11 15:14:51 UTC (rev 1008)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-demo/src/main/resources/conf/mc-int-config.xml 2009-12-11 16:01:37 UTC (rev 1009)
@@ -24,6 +24,8 @@
</map>
</property>
<property name="stringValue"><inject bean="InjectedBean" property="someString"/></property>
+ <!-- You can't use nested properties for injected properties, as property injection order is random -->
<!--property name="bean.anotherProperty">Test value</property-->
+ <property name="config.someProperty">Test value</property>
</bean>
</deployment>
\ No newline at end of file
Added: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/ExternalMCInjectionTest.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/ExternalMCInjectionTest.java (rev 0)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/ExternalMCInjectionTest.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -0,0 +1,158 @@
+package org.exoplatform.kernel.it;
+
+import org.exoplatform.commons.Environment;
+import org.exoplatform.container.RootContainer;
+import org.exoplatform.kernel.demos.mc.ExternallyControlledInjectingBean;
+import org.exoplatform.kernel.demos.mc.InjectedBean;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.dependency.spi.Controller;
+import org.junit.Assert;
+import org.junit.Test;
+
+import javax.transaction.TransactionManager;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:mstrukel at redhat.com">Marko Strukelj</a>
+ */
+public class ExternalMCInjectionTest
+{
+ protected Log log = ExoLogger.getLogger(getClass());
+
+ protected String beanName;
+ protected ExternallyControlledInjectingBean bean;
+ protected boolean inJboss;
+ protected boolean mcIntActive = true;
+
+ public ExternalMCInjectionTest()
+ {
+ beanName = "ExternallyControlledInjectingBean";
+ }
+
+ protected void init()
+ {
+ log.info("init() method called");
+ RootContainer rootContainer = RootContainer.getInstance();
+ bean = (ExternallyControlledInjectingBean) rootContainer.getComponentInstance(beanName);
+ log.info("Retrieved " + beanName + ": " + bean);
+ Assert.assertNotNull(beanName + " not installed", bean);
+ inJboss = Environment.getInstance().getPlatform() == Environment.JBOSS_PLATFORM;
+ log.info("Running inside JBoss? " + inJboss);
+ }
+
+ @Test
+ public void test()
+ {
+ init();
+ tests();
+ }
+
+ protected void tests()
+ {
+ testTransactionManager();
+ testNameLookupMethodInjection();
+ testMapInjection();
+ testPropertyValueMethodInjection();
+ testNestedPropertyInjection();
+ testStarted();
+ }
+
+ private void testTransactionManager()
+ {
+ TransactionManager tm = bean.getTransactionManager();
+
+ if (inJboss && mcIntActive)
+ {
+ try
+ {
+ int status = tm.getStatus();
+ log.info("Status before tx: " + tm.getStatus());
+ tm.begin();
+ Assert.assertFalse("TX status didn't change: ", status == tm.getStatus());
+ log.info("Status in tx: " + tm.getStatus());
+ tm.commit();
+ Assert.assertTrue("TX status didn't return to original: ", status == tm.getStatus());
+ log.info("Status after tx: " + tm.getStatus());
+ }
+ catch (Exception ex)
+ {
+ throw new RuntimeException("Failed to use TransactionManager: ", ex);
+ }
+ }
+ else
+ {
+ Assert.assertNull("Injection should not have worked", tm);
+ }
+ log.info("testTransactionManager passed");
+ }
+
+ protected void testNameLookupMethodInjection()
+ {
+ boolean found = bean.getBean() != null;
+ if (inJboss && mcIntActive)
+ {
+ Assert.assertTrue("Method injection by name lookup not executed", found);
+ }
+ else
+ {
+ Assert.assertFalse("Method injection by name lookup should not have worked", found);
+ }
+ log.info("testNameLookupMethodInjection passed");
+ }
+
+ protected void testMapInjection()
+ {
+ Map bindings = bean.getBindingsMap();
+ boolean found = bindings != null;
+ if (inJboss && mcIntActive)
+ {
+ Assert.assertTrue("Map injection not executed", found);
+ Assert.assertEquals("Bindings size", bindings.size(), 1);
+ Assert.assertTrue("Controller not bound", bindings.get(Controller.class) instanceof Controller);
+ }
+ else
+ {
+ Assert.assertFalse("Map injection should not have worked", found);
+ }
+ log.info("testMapInjection passed");
+ }
+
+ protected void testPropertyValueMethodInjection()
+ {
+ String propertyValue = bean.getStringValue();
+ boolean found = propertyValue != null;
+ if (inJboss && mcIntActive)
+ {
+ Assert.assertTrue("Property value method injection not executed", found);
+ Assert.assertEquals("Invalid injected value", propertyValue, InjectedBean.SOME_PROPERTY_VALUE);
+ }
+ else
+ {
+ Assert.assertFalse("Property value method injection should not have worked", found);
+ }
+ log.info("testPropertyValueMethodInjection passed");
+ }
+
+ protected void testNestedPropertyInjection()
+ {
+ String propertyValue = bean.getConfig().getSomeProperty();
+ boolean found = propertyValue != null;
+ if (inJboss && mcIntActive)
+ {
+ Assert.assertTrue("Nested property value method injection not executed", found);
+ Assert.assertEquals("Invalid injected value", propertyValue, "Test value");
+ }
+ else
+ {
+ Assert.assertFalse("Nested property value method injection should not have worked", found);
+ }
+ log.info("testNestedPropertyInjection passed");
+ }
+
+ protected void testStarted()
+ {
+ Assert.assertEquals("start() method not called exactly once", 1, bean.getStartCount());
+ log.info("testStarted passed");
+ }
+}
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java 2009-12-11 15:14:51 UTC (rev 1008)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -15,10 +15,7 @@
import org.junit.Assert;
import org.junit.Test;
-import javax.transaction.NotSupportedException;
-import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
-import java.util.HashMap;
import java.util.Map;
/**
@@ -78,10 +75,13 @@
{
try
{
+ int status = tm.getStatus();
log.info("Status before tx: " + tm.getStatus());
tm.begin();
+ Assert.assertFalse("TX status didn't change: ", status == tm.getStatus());
log.info("Status in tx: " + tm.getStatus());
tm.commit();
+ Assert.assertTrue("TX status didn't return to original: ", status == tm.getStatus());
log.info("Status after tx: " + tm.getStatus());
}
catch (Exception ex)
@@ -181,24 +181,4 @@
Assert.assertEquals("start() method not called exactly once", 1, bean.getStartCount());
log.info("testStarted passed");
}
-
- static class CallCounter
- {
- private Map<String, Integer> called = new HashMap<String, Integer>();
-
- public void add(String name)
- {
- Integer count = called.get(name);
- if (count == null)
- {
- count = 0;
- }
- called.put(name, 1 + count);
- }
-
- public Map<String, Integer> getCallMap()
- {
- return called;
- }
- }
}
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java 2009-12-11 15:14:51 UTC (rev 1008)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/main/java/org/exoplatform/kernel/it/MCInjectionTest3.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -1,7 +1,5 @@
package org.exoplatform.kernel.it;
-import java.util.HashMap;
-
/**
* @author <a href="mailto:mstrukel at redhat.com">Marko Strukelj</a>
*/
Added: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/test/java/org/exoplatform/kernel/it/TestExternalMCInjectionIntegration.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/test/java/org/exoplatform/kernel/it/TestExternalMCInjectionIntegration.java (rev 0)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-int-tests/src/test/java/org/exoplatform/kernel/it/TestExternalMCInjectionIntegration.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -0,0 +1,12 @@
+package org.exoplatform.kernel.it;
+
+/**
+ * @author <a href="mailto:mstrukel at redhat.com">Marko Strukelj</a>
+ */
+public class TestExternalMCInjectionIntegration extends TestMCInjectionIntegration
+{
+ public TestExternalMCInjectionIntegration()
+ {
+ testClass = org.exoplatform.kernel.it.ExternalMCInjectionTest.class.getName();
+ }
+}
Modified: kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java
===================================================================
--- kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java 2009-12-11 15:14:51 UTC (rev 1008)
+++ kernel/branches/mc-int-branch/exo.kernel.mc-integration/exo.kernel.mc-kernel-extras/src/main/java/org/jboss/dependency/plugins/helpers/StatelessController.java 2009-12-11 16:01:37 UTC (rev 1009)
@@ -22,10 +22,9 @@
package org.jboss.dependency.plugins.helpers;
import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.plugins.AbstractController;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.plugins.AbstractController;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
More information about the exo-jcr-commits
mailing list