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 2012/04/01 18:30:58 UTC

svn commit: r1308149 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives: common/YetAnotherPencil.java tests/AlternativeBeanResolvingTest.java tests/AlternativeProducerMethodTest.java

Author: struberg
Date: Sun Apr  1 16:30:57 2012
New Revision: 1308149

URL: http://svn.apache.org/viewvc?rev=1308149&view=rev
Log:
OWB-658 test for InjectionResolver fix which slipped into r1308123 already

Please note that the behaviour might still not be 100% deterministic for such cases
as the spec leaves too much room for interpretation. I'll take that to the
CDI EG and come back with a solution and final fix later.

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/common/YetAnotherPencil.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeProducerMethodTest.java

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/common/YetAnotherPencil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/common/YetAnotherPencil.java?rev=1308149&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/common/YetAnotherPencil.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/common/YetAnotherPencil.java Sun Apr  1 16:30:57 2012
@@ -0,0 +1,27 @@
+/*
+ * 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.concepts.alternatives.common;
+
+import javax.enterprise.context.RequestScoped;
+
+@Pen
+@RequestScoped
+public class YetAnotherPencil
+{
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java?rev=1308149&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeBeanResolvingTest.java Sun Apr  1 16:30:57 2012
@@ -0,0 +1,73 @@
+/*
+ * 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.concepts.alternatives.tests;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.AnnotationLiteral;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.concepts.alternatives.common.AlternativeOnClassAndProducerMethodBean;
+import org.apache.webbeans.newtests.concepts.alternatives.common.AlternativeOnClassOnlyBean;
+import org.apache.webbeans.newtests.concepts.alternatives.common.DefaultBeanProducerWithoutDisposes;
+import org.apache.webbeans.newtests.concepts.alternatives.common.Pen;
+import org.apache.webbeans.newtests.concepts.alternatives.common.Pencil;
+import org.apache.webbeans.newtests.concepts.alternatives.common.PencilProducerBean;
+import org.apache.webbeans.newtests.concepts.alternatives.common.YetAnotherPencil;
+import org.junit.Test;
+import org.junit.Assert;
+
+/**
+ * Test bean resolving if @Alternative annotated beans are involved
+ * See OWB-658 for the original problem.
+ */
+public class AlternativeBeanResolvingTest extends AbstractUnitTest
+{
+    private static final String PACKAGE_NAME = AlternativeProducerMethodTest.class.getPackage().getName();
+
+    /**
+     * see OWB-658
+     */
+    @Test
+    public void testObjectBeanQuery()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+        beanXmls.add(getXmlPath(PACKAGE_NAME, "AlternativeOnProducerFieldTest"));
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(Pen.class);
+        beanClasses.add(Pencil.class);
+        beanClasses.add(PencilProducerBean.class);
+        beanClasses.add(DefaultBeanProducerWithoutDisposes.class);
+        beanClasses.add(AlternativeOnClassAndProducerMethodBean.class);
+        beanClasses.add(YetAnotherPencil.class);
+
+        // available but not enabled in beans.xml
+        beanClasses.add(AlternativeOnClassOnlyBean.class);
+
+        startContainer(beanClasses, null);
+
+        Set<Bean<?>> beans = getBeanManager().getBeans(Object.class, new AnnotationLiteral<Pen>(){});
+        Assert.assertNotNull(beans);
+        Assert.assertEquals(2, beans.size());
+    }
+
+}

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeProducerMethodTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeProducerMethodTest.java?rev=1308149&r1=1308148&r2=1308149&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeProducerMethodTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/concepts/alternatives/tests/AlternativeProducerMethodTest.java Sun Apr  1 16:30:57 2012
@@ -104,12 +104,7 @@ public class AlternativeProducerMethodTe
 
         startContainer(beanClasses, beanXmls);
 
-        Annotation[] anns = new Annotation[1];
-        anns[0] = new AnnotationLiteral<QualifierProducerBased>()
-        {
-        };
-
-        IProducedBean producedBean = getInstance(IProducedBean.class, anns);
+        IProducedBean producedBean = getInstance(IProducedBean.class, new AnnotationLiteral<QualifierProducerBased>(){});
         Assert.assertNotNull(producedBean);
         Assert.assertEquals("AlternativeOnClassAndProducerMethodBean", producedBean.getProducerType());