(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 15 Jul 2010 13:49:11 +0000 (13:49 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Thu, 15 Jul 2010 13:49:11 +0000 (13:49 +0000)
support/cdi/src/main/resources/META-INF/services/org.wamblee.inject.InjectorFactory [new file with mode: 0644]
support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java [new file with mode: 0644]
support/cdi/src/test/java/org/wamblee/cdi/BeanManagerSetup.java
support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java [new file with mode: 0644]
support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorTest.java
support/cdi/src/test/java/org/wamblee/cdi/InjectorFactoryBuilderTest.java [new file with mode: 0644]
support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java

diff --git a/support/cdi/src/main/resources/META-INF/services/org.wamblee.inject.InjectorFactory b/support/cdi/src/main/resources/META-INF/services/org.wamblee.inject.InjectorFactory
new file mode 100644 (file)
index 0000000..99ad17c
--- /dev/null
@@ -0,0 +1,3 @@
+
+
+org.wamblee.cdi.CdiInjectorFactory
diff --git a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java
new file mode 100644 (file)
index 0000000..8115ac4
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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 static junit.framework.Assert.*;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.naming.InitialContext;
+
+import org.junit.Test;
+import org.wamblee.support.jndi.StubInitialContextFactory;
+
+public class BeanManagerLookupTest {
+
+    @Test
+    public void testLookupInJndi() throws Exception {
+        BeanManagerSetup setup = new BeanManagerSetup();
+        setup.initialize();
+        StubInitialContextFactory.register();
+        InitialContext ctx = new InitialContext(); 
+        ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager());
+        try {
+            ctx = new InitialContext(); 
+            BeanManager manager = (BeanManager) ctx.lookup(BeanManagerLookup.BEAN_MANAGER_JNDI);
+            assertSame(setup.getBeanManager(), manager);
+        } finally {
+            setup.shutdown();
+            StubInitialContextFactory.unregister();
+        }
+    }
+}
index 8ad67b8731f08df9dc22cbde77eb6eaf78e9ccfb..cbf85bcf325fbf89ffa02cfe5aa1f6b8804bda10 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * 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.inject.spi.BeanManager;
diff --git a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java
new file mode 100644 (file)
index 0000000..76931da
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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 org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.wamblee.inject.Injector;
+import org.wamblee.inject.InjectorFactory;
+
+import static junit.framework.TestCase.*;
+
+public class CdiInjectorFactoryTest {
+
+    private BeanManagerSetup manager;
+
+    @Before
+    public void setUp() {
+        manager = new BeanManagerSetup();
+        manager.initialize();
+    }
+
+    @After
+    public void tearDown() {
+        manager.shutdown();
+    }
+
+    @Test
+    public void testGetInjector() {
+        InjectorFactory factory = new CdiInjectorFactory(manager.getBeanManager());
+        Injector injector = factory.create(MyPojo.class);
+        MyPojo pojo = new MyPojo();
+        injector.inject(pojo);
+        assertNotNull(pojo.getSingleton());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testBeanManagerNull() {
+        CdiInjectorFactory factory = new CdiInjectorFactory(null);
+    }
+}
index 53d7df913176c607803afcb1f2d4b0b233c64b94..21133fa70361619436d347185a79757cffd3531a 100644 (file)
@@ -17,23 +17,45 @@ package org.wamblee.cdi;
 
 import static junit.framework.Assert.*;
 
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 
 public class CdiInjectorTest {
-
     
-    @Test
-    public void testInject() { 
-        fail(); 
+    private BeanManagerSetup manager; 
+    
+    @Before
+    public void setUp() { 
+        manager = new BeanManagerSetup();
+        manager.initialize(); 
+    }
+    
+    @After
+    public void tearDown() { 
+        manager.shutdown();
     }
     
     @Test
+    public void testInject() {      
+        CdiInjector injector = new CdiInjector(manager.getBeanManager(), MyPojo.class);
+        MyPojo pojo = new MyPojo(); 
+        injector.inject(pojo);
+        assertNotNull(pojo.getSingleton());
+    }
+    
+    @Test(expected = IllegalArgumentException.class)
     public void testWrongType() { 
-        fail();
+        CdiInjector injector = new CdiInjector(manager.getBeanManager(), String.class);
+        MyPojo pojo = new MyPojo(); 
+        injector.inject(pojo);
     }
     
     @Test
     public void testNullObject() { 
-        fail();
+        CdiInjector injector = new CdiInjector(manager.getBeanManager(), MyPojo.class);
+        injector.inject(null);
+        
+        // ok should simply ignore. 
     }
 }
diff --git a/support/cdi/src/test/java/org/wamblee/cdi/InjectorFactoryBuilderTest.java b/support/cdi/src/test/java/org/wamblee/cdi/InjectorFactoryBuilderTest.java
new file mode 100644 (file)
index 0000000..97c85bf
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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 static junit.framework.Assert.*;
+
+import javax.naming.InitialContext;
+
+import org.junit.Test;
+import org.wamblee.inject.InjectorFactory;
+import org.wamblee.inject.InjectorFactoryBuilder;
+import org.wamblee.support.jndi.StubInitialContextFactory;
+
+public class InjectorFactoryBuilderTest {
+    
+    
+
+    @Test
+    public void testCdiInjectorFactoryIsFound() throws Exception { 
+        BeanManagerSetup setup = new BeanManagerSetup();
+        setup.initialize();
+        StubInitialContextFactory.register();
+        InitialContext ctx = new InitialContext(); 
+        ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager());
+        try {
+            InjectorFactory factory = InjectorFactoryBuilder.getInjectorFactory();
+            assertTrue(factory instanceof CdiInjectorFactory);
+        } finally {
+            setup.shutdown();
+            StubInitialContextFactory.unregister();
+        }
+    }
+}
index 829f5ceb531cd192d6be8e7ecec2920660b16a87..2a3b124297c47b7dab8a3de95946f0027d2bd49a 100644 (file)
@@ -51,7 +51,7 @@ public class SimpleInjectorTest {
     @Test
     public void testGetSingleton() {
         MyPojo pojo = new MyPojo();
-        SimpleInjector injector = new SimpleInjector(new CdiInjectorFactory());
+        SimpleInjector injector = new SimpleInjector(new CdiInjectorFactory(BeanManagerLookup.lookup()));
         injector.inject(pojo);
 
         MySingleton obj = pojo.getSingleton();