You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2013/01/20 17:08:56 UTC

svn commit: r1435871 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection: constructor/ constructor/beans/ injectionpoint/beans/ injectionpoint/tests/

Author: struberg
Date: Sun Jan 20 16:08:56 2013
New Revision: 1435871

URL: http://svn.apache.org/viewvc?rev=1435871&view=rev
Log:
OWB-764 add unit test for multi-param ct injection

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/ConstructorInjectionTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/Administrator.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithSingleParamInjectConstructor.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithTwoParamInjectConstructor.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/User.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/ConstructorInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/ConstructorInjectionTest.java?rev=1435871&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/ConstructorInjectionTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/ConstructorInjectionTest.java Sun Jan 20 16:08:56 2013
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.injection.constructor;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.injection.constructor.beans.Administrator;
+import org.apache.webbeans.newtests.injection.constructor.beans.BeanWithSingleParamInjectConstructor;
+import org.apache.webbeans.newtests.injection.constructor.beans.BeanWithTwoParamInjectConstructor;
+import org.apache.webbeans.newtests.injection.constructor.beans.User;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test @Inject constructors.
+ */
+public class ConstructorInjectionTest extends AbstractUnitTest
+{
+
+    @Test
+    public void testSingleParamCtInjection() throws Exception
+    {
+        startContainer(BeanWithSingleParamInjectConstructor.class, User.class);
+
+        BeanWithSingleParamInjectConstructor instance = getInstance(BeanWithSingleParamInjectConstructor.class);
+        Assert.assertNotNull(instance);
+        Assert.assertNotNull(instance.getUser());
+
+        User user = getInstance(User.class);
+        Assert.assertNotNull(user);
+
+        Assert.assertTrue(user.getSelf() == instance.getUser().getSelf());
+    }
+
+    @Test
+    public void testTwoParamCtInjection() throws Exception
+    {
+        startContainer(BeanWithTwoParamInjectConstructor.class, User.class, Administrator.class);
+
+        BeanWithTwoParamInjectConstructor instance = getInstance(BeanWithTwoParamInjectConstructor.class);
+        Assert.assertNotNull(instance);
+        Assert.assertNotNull(instance.getUser());
+        Assert.assertNotNull(instance.getAdministrator());
+
+        User user = getInstance(User.class);
+        Assert.assertNotNull(user);
+        Assert.assertTrue(user.getSelf() == instance.getUser().getSelf());
+
+        Administrator administrator = getInstance(Administrator.class);
+        Assert.assertNotNull(administrator);
+        Assert.assertTrue(administrator.getSelf() == instance.getAdministrator().getSelf());
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/Administrator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/Administrator.java?rev=1435871&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/Administrator.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/Administrator.java Sun Jan 20 16:08:56 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.injection.constructor.beans;
+
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Typed;
+
+@SessionScoped
+@Typed(Administrator.class)
+public class Administrator extends User
+{
+    private String role;
+
+    public String getRole()
+    {
+        return role;
+    }
+
+    public void setRole(String role)
+    {
+        this.role = role;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithSingleParamInjectConstructor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithSingleParamInjectConstructor.java?rev=1435871&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithSingleParamInjectConstructor.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithSingleParamInjectConstructor.java Sun Jan 20 16:08:56 2013
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.injection.constructor.beans;
+
+import javax.inject.Inject;
+
+public class BeanWithSingleParamInjectConstructor
+{
+    private User user;
+
+    @Inject
+    public BeanWithSingleParamInjectConstructor(User user)
+    {
+        this.user = user;
+    }
+
+    public User getUser()
+    {
+        return user;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithTwoParamInjectConstructor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithTwoParamInjectConstructor.java?rev=1435871&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithTwoParamInjectConstructor.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/BeanWithTwoParamInjectConstructor.java Sun Jan 20 16:08:56 2013
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.injection.constructor.beans;
+
+import javax.inject.Inject;
+
+public class BeanWithTwoParamInjectConstructor
+{
+    private User user;
+    private Administrator administrator;
+
+    @Inject
+    public BeanWithTwoParamInjectConstructor(User user, Administrator administrator)
+    {
+        this.user = user;
+        this.administrator = administrator;
+    }
+
+    public User getUser()
+    {
+        return user;
+    }
+
+    public Administrator getAdministrator()
+    {
+        return administrator;
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/User.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/User.java?rev=1435871&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/User.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/constructor/beans/User.java Sun Jan 20 16:08:56 2013
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.injection.constructor.beans;
+
+import javax.enterprise.context.SessionScoped;
+import java.io.Serializable;
+
+/**
+ * Sample User Bean
+ */
+@SessionScoped
+public class User implements Serializable
+{
+    private String name;
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public User getSelf()
+    {
+        return this;
+    }
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java?rev=1435871&r1=1435870&r2=1435871&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java Sun Jan 20 16:08:56 2013
@@ -15,13 +15,31 @@
  */
 package org.apache.webbeans.newtests.injection.injectionpoint.beans;
 
+import javax.enterprise.context.SessionScoped;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.inject.Inject;
+import java.io.Serializable;
 
-public class ConstructorInjectionPointOwner extends AbstractInjectionPointOwner {
+public class ConstructorInjectionPointOwner extends AbstractInjectionPointOwner
+{
 
     @Inject
-    public ConstructorInjectionPointOwner(InjectionPoint ip) {
+    public ConstructorInjectionPointOwner(InjectionPoint ip)
+    {
         injectionPoint = ip;
     }
+
+    public ConstructorInjectionPointOwner()
+    {
+
+    }
+
+    @SessionScoped
+    public static class SomeInnerClassWithInstructorInjectionPoint implements Serializable
+    {
+
+        public SomeInnerClassWithInstructorInjectionPoint()
+        {
+        }
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java?rev=1435871&r1=1435870&r2=1435871&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java Sun Jan 20 16:08:56 2013
@@ -16,6 +16,7 @@
 package org.apache.webbeans.newtests.injection.injectionpoint.tests;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.junit.Assert.assertThat;
 
 import java.util.ArrayList;
@@ -42,12 +43,17 @@ public class InjectionPointInjectionTest
         beanClasses.add(MethodInjectionPointOwner.class);
         beanClasses.add(InjectionPointObserver.class);
         beanClasses.add(InjectionPointBeansOwner.class);
-        startContainer(beanClasses, null);  
+        beanClasses.add(ConstructorInjectionPointOwner.SomeInnerClassWithInstructorInjectionPoint.class);
+        startContainer(beanClasses, null);
 
         Bean<InjectionPointBeansOwner> bean = (Bean<InjectionPointBeansOwner>) getBeanManager().getBeans(InjectionPointBeansOwner.class).iterator().next();
         CreationalContext<InjectionPointBeansOwner> cc = getBeanManager().createCreationalContext(bean);
         InjectionPointBeansOwner owner = (InjectionPointBeansOwner) getBeanManager().getReference(bean, InjectionPointBeansOwner.class, cc);
 
+        ConstructorInjectionPointOwner.SomeInnerClassWithInstructorInjectionPoint innerClass
+                = getInstance(ConstructorInjectionPointOwner.SomeInnerClassWithInstructorInjectionPoint.class);
+        assertThat(innerClass, is(notNullValue()));
+
         assertThat(owner.getConstructorInjectionName(), is("constructorInjection"));
         assertThat(owner.getFieldInjectionName(), is("fieldInjection"));
         assertThat(owner.getMethodInjectionName(), is("methodInjection"));