You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/11/11 00:18:12 UTC

svn commit: r834705 - in /incubator/openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/config/ test/java/org/apache/webbeans/test/component/pfield/ test/java/org/apache/webbeans/test/unittests/pfield/

Author: gerdogdu
Date: Tue Nov 10 23:18:11 2009
New Revision: 834705

URL: http://svn.apache.org/viewvc?rev=834705&view=rev
Log:
OWB-161 Producer fields do not honor generics, thanks to Joe Bergmark

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldDefinitionParameterized.java   (with props)
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldInjectedWrongType.java   (with props)
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/pfield/ProducerFieldComponentTest.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=834705&r1=834704&r2=834705&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Tue Nov 10 23:18:11 2009
@@ -739,7 +739,7 @@
         
         Annotation[] fieldAnns = field.getDeclaredAnnotations();
 
-        DefinitionUtil.defineProducerMethodApiTypes(component, returnType, fieldAnns);
+        DefinitionUtil.defineProducerMethodApiTypes(component, field.getGenericType(), fieldAnns);
         DefinitionUtil.defineScopeType(component, fieldAnns, "WebBeans producer method : " + field.getName() + " in class " + parent.getReturnType().getName() + " must declare default @Scope annotation");
         WebBeansUtil.checkProducerGenericType(component,field);
         DefinitionUtil.defineQualifiers(component, fieldAnns);

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldDefinitionParameterized.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldDefinitionParameterized.java?rev=834705&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldDefinitionParameterized.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldDefinitionParameterized.java Tue Nov 10 23:18:11 2009
@@ -0,0 +1,28 @@
+/*
+ *  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.test.component.pfield;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.Produces;
+
+public class ProducerFieldDefinitionParameterized
+{
+    private @Produces
+    List<Double> producedList = new ArrayList<Double>();
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldDefinitionParameterized.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldInjectedWrongType.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldInjectedWrongType.java?rev=834705&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldInjectedWrongType.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldInjectedWrongType.java Tue Nov 10 23:18:11 2009
@@ -0,0 +1,32 @@
+/*
+ *  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.test.component.pfield;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+public class ProducerFieldInjectedWrongType
+{
+    @Inject
+    private List<String> myList;
+
+    public List<String> getMyList()
+    {
+        return myList;
+    }
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/pfield/ProducerFieldInjectedWrongType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/pfield/ProducerFieldComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/pfield/ProducerFieldComponentTest.java?rev=834705&r1=834704&r2=834705&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/pfield/ProducerFieldComponentTest.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/pfield/ProducerFieldComponentTest.java Tue Nov 10 23:18:11 2009
@@ -24,7 +24,9 @@
 import org.apache.webbeans.test.component.CheckWithMoneyPayment;
 import org.apache.webbeans.test.component.PaymentProcessorComponent;
 import org.apache.webbeans.test.component.pfield.ProducerFieldDefinitionComponent;
+import org.apache.webbeans.test.component.pfield.ProducerFieldDefinitionParameterized;
 import org.apache.webbeans.test.component.pfield.ProducerFieldInjectedComponent;
+import org.apache.webbeans.test.component.pfield.ProducerFieldInjectedWrongType;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -70,5 +72,29 @@
         
         Assert.assertNotNull(injectedComponentInstance.getPaymentProcessorName());
     }
+    
+    @Test
+    public void testInjectedProducerFieldIncorrectType()
+    {
+        ContextFactory.initRequestContext(null);
+
+        defineManagedBean(ProducerFieldDefinitionParameterized.class);
+        Bean<ProducerFieldInjectedWrongType> beanInjected = defineManagedBean(ProducerFieldInjectedWrongType.class);
+
+        Exception expected = null;
+        ProducerFieldInjectedWrongType instance = null;
+        try
+        {
+            instance = getManager().getInstance(beanInjected);
+        }
+        catch (Exception caught)
+        {
+            System.out.println(caught.getMessage());
+            expected = caught;
+        }
+        Assert.assertNotNull(expected);
+        Assert.assertNull(instance);
+        Assert.assertTrue(expected instanceof javax.enterprise.inject.UnsatisfiedResolutionException);
+    }
 
 }