cdi project in initial revision
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 14 Jul 2010 19:54:22 +0000 (19:54 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Wed, 14 Jul 2010 19:54:22 +0000 (19:54 +0000)
testing and docs to be added.

20 files changed:
support/cdi/.classpath [new file with mode: 0644]
support/cdi/.project [new file with mode: 0644]
support/cdi/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
support/cdi/.settings/org.maven.ide.eclipse.prefs [new file with mode: 0644]
support/cdi/TODO.txt [new file with mode: 0644]
support/cdi/pom.xml [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/Injectable.java [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/Injector.java [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/InjectorCache.java [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/InjectorFactory.java [new file with mode: 0644]
support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java [new file with mode: 0644]
support/cdi/src/test/java/org/wamblee/cdi/MyPojo.java [new file with mode: 0644]
support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java [new file with mode: 0644]
support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java [new file with mode: 0644]
support/cdi/src/test/resources/META-INF/beans.xml [new file with mode: 0644]
support/general/pom.xml
support/pom.xml

diff --git a/support/cdi/.classpath b/support/cdi/.classpath
new file mode 100644 (file)
index 0000000..6eaa0fe
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+       <classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
+       <classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+       <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+       <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/support/cdi/.project b/support/cdi/.project
new file mode 100644 (file)
index 0000000..b0870aa
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>wamblee-support-cdi</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.maven.ide.eclipse.maven2Builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+               <nature>org.maven.ide.eclipse.maven2Nature</nature>
+       </natures>
+</projectDescription>
diff --git a/support/cdi/.settings/org.eclipse.jdt.core.prefs b/support/cdi/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..dda5544
--- /dev/null
@@ -0,0 +1,6 @@
+#Wed Jul 14 20:45:46 CEST 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/support/cdi/.settings/org.maven.ide.eclipse.prefs b/support/cdi/.settings/org.maven.ide.eclipse.prefs
new file mode 100644 (file)
index 0000000..38db043
--- /dev/null
@@ -0,0 +1,9 @@
+#Wed Jul 14 20:45:45 CEST 2010
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
diff --git a/support/cdi/TODO.txt b/support/cdi/TODO.txt
new file mode 100644 (file)
index 0000000..d9a6915
--- /dev/null
@@ -0,0 +1,6 @@
+
+* move maven dependency version to root pom
+* add test code for complete behavior. 
+* setup site 
+* integrate with wamblee-utils. 
+
diff --git a/support/cdi/pom.xml b/support/cdi/pom.xml
new file mode 100644 (file)
index 0000000..e05b96c
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<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.wamblee</groupId>
+    <artifactId>wamblee-utils</artifactId>
+    <version>0.2.5-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.wamblee</groupId>
+  <artifactId>wamblee-support-cdi</artifactId>
+  <packaging>jar</packaging>
+  <name>/support/cdi</name>
+  <url>http://wamblee.org</url>
+  <dependencies>
+    <dependency>
+      <groupId>org.jboss.weld</groupId>
+      <artifactId>weld-se</artifactId>
+      <version>1.0.1-Final</version>
+    </dependency>
+    
+    <!-- always include the APIs last because they contain garbled/unusable classes -->
+    <!-- dependency>
+      <groupId>javax</groupId>
+      <artifactId>javaee-api</artifactId>
+    </dependency -->
+   
+  </dependencies>
+  
+  <distributionManagement>
+    <site>
+      <id>support-cdi</id>
+      <url>file:${distrib}/support/cdi</url>
+    </site>
+  </distributionManagement>
+
+</project>
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java b/support/cdi/src/main/java/org/wamblee/cdi/BeanManagerLookup.java
new file mode 100644 (file)
index 0000000..2952653
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+import java.util.logging.Logger;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Class that encapsulates beanmanager lookup in a way so that the lookup can be
+ * explicitly overriden (e.g. for unit test).
+ * 
+ * In case no bean manager is found the beanmanager is set to null and the
+ * problem is logged.
+ * 
+ * @author Erik Brakkee
+ */
+public class BeanManagerLookup {
+
+    private static final Logger LOGGER = Logger
+        .getLogger(BeanManagerLookup.class.getName());
+
+    private static final String BEAN_MANAGER_JNDI = "java:comp/BeanManager";
+    private static BeanManager mgr = null;
+
+    /**
+     * Sets the bean manager (mainly for testability).
+     * 
+     * @param aMgr
+     *            Bean manager.
+     */
+    public static void setBeanManager(BeanManager aMgr) {
+        mgr = aMgr;
+    }
+
+    /**
+     * Looks up the bean manager if not already cached and returns it.
+     * 
+     * @return Bean manager.
+     */
+    public static BeanManager lookup() {
+        if (mgr == null) {
+            try {
+                InitialContext ctx = new InitialContext();
+                mgr = (BeanManager) ctx.lookup(BEAN_MANAGER_JNDI);
+                LOGGER.info("Beanmanager successfully located");
+            } catch (NamingException e) {
+                LOGGER.warning("No beanmanager was found, using null");
+                mgr = null;
+            }
+        }
+        return mgr;
+    }
+}
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java b/support/cdi/src/main/java/org/wamblee/cdi/CdiInjector.java
new file mode 100644 (file)
index 0000000..46d434b
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+/**
+ * Class encapsulating bean injection into a specific non-contextual object of a
+ * given class.
+ * 
+ * @author Erik Brakkee
+ */
+public class CdiInjector implements Injector {
+    private Class clazz;
+    private InjectionTarget target;
+    private CreationalContext ctx;
+
+    /**
+     * Constructs the injector.
+     * 
+     * @param aMgr
+     *            Bean manager.
+     * @param aClass
+     *            Class to analyse for injection.
+     */
+    public CdiInjector(BeanManager aMgr, Class<?> aClass) {
+        clazz = aClass;
+        AnnotatedType<?> type = aMgr.createAnnotatedType(aClass);
+        target = aMgr.createInjectionTarget(type);
+        ctx = aMgr.createCreationalContext(null);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.wamblee.cdi.Injector#inject(java.lang.Object)
+     */
+    public void inject(Object aComponent) {
+        if (aComponent != null) {
+            if (!clazz.isInstance(aComponent)) {
+                throw new RuntimeException("Object '" + aComponent +
+                    "' is of type " + aComponent.getClass().getName() +
+                    " but expected " + clazz.getName());
+            }
+            target.inject(aComponent, ctx);
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java b/support/cdi/src/main/java/org/wamblee/cdi/CdiInjectorFactory.java
new file mode 100644 (file)
index 0000000..74d1a66
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+import java.util.logging.Logger;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Factory that creates CDI injectors. In case no beanmanager is found then
+ * injectors will do nothing. This class may be subclassed for testing to
+ * override the injectors that are returned.
+ * 
+ * @author Erik Brakkee
+ */
+public class CdiInjectorFactory implements InjectorFactory {
+
+    private static final Logger LOGGER = Logger
+        .getLogger(CdiInjectorFactory.class.getName());
+
+    private BeanManager beanManager;
+
+    /**
+     * Constructs the factory using the default bean manager.
+     */
+    public CdiInjectorFactory() {
+        this(BeanManagerLookup.lookup());
+    }
+
+    /**
+     * Constructs the factory using an explicit bean manager.
+     * 
+     * @param aBeanManager
+     */
+    public CdiInjectorFactory(BeanManager aBeanManager) {
+        beanManager = aBeanManager;
+    }
+
+    @Override
+    public Injector create(Class aClass) {
+        if (beanManager == null) {
+            // Typically for unit test.
+            return new Injector() {
+                @Override
+                public void inject(Object aComponent) {
+                    // Empty.
+                }
+            };
+        }
+        return new CdiInjector(beanManager, aClass);
+    }
+
+}
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/Injectable.java b/support/cdi/src/main/java/org/wamblee/cdi/Injectable.java
new file mode 100644 (file)
index 0000000..6e9f7b8
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+/**
+ * This abstract base class performs injection at construction.
+ * Be sure not to initialize fields of derived classes to null as these will override the initializations
+ * of this base class. 
+ *  
+ * Use this by subclassing through
+ * {@link #Injectable()). 
+ * 
+ * @author Erik Brakkee
+ */
+public abstract class Injectable {
+
+    /**
+     * Inheritance style constructor.
+     */
+    protected Injectable() {
+        SimpleInjector.inject(this);
+    }
+}
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/Injector.java b/support/cdi/src/main/java/org/wamblee/cdi/Injector.java
new file mode 100644 (file)
index 0000000..ad1648e
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+/**
+ * Interface used to perform injection with.
+ * 
+ * @author Erik Brakkee
+ */
+public interface Injector {
+
+    /**
+     * Injects beans into a given component of the required class.
+     * 
+     * @param aComponent
+     *            Component to inject into.
+     */
+    public abstract void inject(Object aComponent);
+
+}
\ No newline at end of file
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/InjectorCache.java b/support/cdi/src/main/java/org/wamblee/cdi/InjectorCache.java
new file mode 100644 (file)
index 0000000..69595c6
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Cache of {@link CdiInjector}s for efficiency to avoid duplicate analysis of a
+ * given class.
+ * 
+ * @author Erik Brakkee
+ */
+public class InjectorCache {
+
+    private Map<String, Injector> injectors;
+
+    private InjectorFactory injectorFactory;
+
+    /**
+     * Constructs an empty cache.
+     * 
+     * @param aMgr
+     *            Bean manager.
+     */
+    public InjectorCache(InjectorFactory aInjectorFactory) {
+        injectorFactory = aInjectorFactory;
+        injectors = new ConcurrentHashMap<String, Injector>();
+    }
+
+    /**
+     * Gets the injector for a given class. This returns a cached injector or
+     * creates a new injector and caches it.
+     * 
+     * @param aClass
+     *            Class to find injector for.
+     * @return Injector.
+     */
+    public Injector getInjector(Class aClass) {
+        Injector injector = injectors.get(aClass.getName());
+        if (injector == null) {
+            // create and add injector
+            // NOTE: in rare circumstances this will lead to parallel
+            // creation of
+            // an injector for the same class. However, only one of them
+            // will be the final one
+            // in the map. There are no side effects of this duplicate
+            // creation of injectors.
+            injector = injectorFactory.create(aClass);
+            injectors.put(aClass.getName(), injector);
+        }
+        return injector;
+    }
+}
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/InjectorFactory.java b/support/cdi/src/main/java/org/wamblee/cdi/InjectorFactory.java
new file mode 100644 (file)
index 0000000..1761d24
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+/**
+ * Injector factory used. This may be subclasses for testing.
+ * 
+ * @author Erik Brakkee
+ */
+public interface InjectorFactory {
+
+    Injector create(Class aClass);
+
+}
diff --git a/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java b/support/cdi/src/main/java/org/wamblee/cdi/SimpleInjector.java
new file mode 100644 (file)
index 0000000..7a8db0d
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.cdi;
+
+/**
+ * Singleton injector access. This should be used as main entry point for
+ * injection. A different {@link InjectorFactory} can be plugged in for testing.
+ * 
+ * @author Erik Brakkee
+ */
+public class SimpleInjector {
+
+    private static InjectorCache cache = new InjectorCache(
+        new CdiInjectorFactory());
+
+    /**
+     * Override the injector factory (mainly fo runit test).
+     * 
+     * @param aFactory
+     *            Factory.
+     */
+    public static void setInjectorFactory(InjectorFactory aFactory) {
+        cache = new InjectorCache(aFactory);
+    }
+
+    /**
+     * Injects into a given object.
+     * 
+     * @param aObject
+     *            Object to inject into.
+     */
+    public static void inject(Object aObject) {
+        cache.getInjector(aObject.getClass()).inject(aObject);
+    }
+}
diff --git a/support/cdi/src/test/java/org/wamblee/cdi/MyPojo.java b/support/cdi/src/test/java/org/wamblee/cdi/MyPojo.java
new file mode 100644 (file)
index 0000000..b207c63
--- /dev/null
@@ -0,0 +1,17 @@
+package org.wamblee.cdi;
+
+import javax.inject.Inject;
+
+public class MyPojo {
+
+    @Inject
+    private MySingleton singleton; 
+    
+    public MyPojo() { 
+        // Empty.
+    }
+    
+    public MySingleton getSingleton() {
+        return singleton;
+    }
+}
diff --git a/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java b/support/cdi/src/test/java/org/wamblee/cdi/MySingleton.java
new file mode 100644 (file)
index 0000000..7754c54
--- /dev/null
@@ -0,0 +1,19 @@
+package org.wamblee.cdi;
+
+import javax.enterprise.context.ApplicationScoped;
+
+
+@ApplicationScoped
+public class MySingleton {
+    
+    private static int instances = 0; 
+
+    public MySingleton() { 
+        System.out.println("Constructing object.");
+        instances++;
+    }
+    
+    public static int getInstances() {
+        return instances;
+    }
+}
diff --git a/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java b/support/cdi/src/test/java/org/wamblee/cdi/WeldTest.java
new file mode 100644 (file)
index 0000000..c860882
--- /dev/null
@@ -0,0 +1,55 @@
+package org.wamblee.cdi;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+import org.jboss.weld.environment.se.Weld;
+import org.jboss.weld.environment.se.WeldContainer;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import static junit.framework.TestCase.*;
+
+public class WeldTest {
+    
+    private Weld weld;
+    private WeldContainer container; 
+    private BeanManager beanManager; 
+
+    @Before
+    public void setUp() {
+        weld = new Weld();
+        container = weld.initialize(); 
+        beanManager = container.getBeanManager();
+    }
+    
+    @After
+    public void tearDown() { 
+        weld.shutdown(); 
+    }
+    
+    @Test
+    public void testGetSingleton() { 
+        AnnotatedType<MyPojo> type = beanManager.createAnnotatedType(MyPojo.class);
+        InjectionTarget<MyPojo> target = beanManager.createInjectionTarget(type);
+        CreationalContext<MyPojo> ctx = beanManager.createCreationalContext(null);
+        
+        MyPojo pojo = new MyPojo(); 
+        
+        target.inject(pojo, ctx); 
+        
+        MySingleton obj = pojo.getSingleton(); 
+        
+        assertNotNull(obj);
+        
+        MyPojo pojo2 = new MyPojo(); 
+        target.inject(pojo2, ctx); 
+                
+        // Objects will not be the same as they are contextual references to the same object.
+        // assertSame(pojo2, pojo);
+
+        assertEquals(1, MySingleton.getInstances());
+    }
+}
diff --git a/support/cdi/src/test/resources/META-INF/beans.xml b/support/cdi/src/test/resources/META-INF/beans.xml
new file mode 100644 (file)
index 0000000..82ec09d
--- /dev/null
@@ -0,0 +1,5 @@
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+   
+</beans>
\ No newline at end of file
index b0017cd5db96c1150bd74742d2f4bb91456c92df..8354f98fd8b8165179d13efc89c2072c59613612 100644 (file)
@@ -61,7 +61,7 @@
   
   <distributionManagement>
     <site>
-      <id>test-enterprise-site</id>
+      <id>support-general</id>
       <url>file:${distrib}/support/general</url>
     </site>
   </distributionManagement>
index 31be4b22484f7d19c1b65a55107f2a1c4b7f20b7..c31a72768d0dff2894d645d5c79b61eb01f1b7de 100644 (file)
@@ -16,6 +16,7 @@
 
   <modules>
     <module>general</module>
+    <module>cdi</module>
     <module>spring</module>
   </modules>