Weld SVN: r5799 - in cdi-tck/trunk/impl/src/main: java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean and 2 other directories.
by weld-commits@lists.jboss.org
Author: jharting
Date: 2010-02-05 11:48:35 -0500 (Fri, 05 Feb 2010)
New Revision: 5799
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/OrderInterceptor.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Secure.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Tiger.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Transactional.java
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/beans.xml
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/InitializerSimpleBean.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/NewEnterpriseBeanTest.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/NewSimpleBeanTest.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Order.java
Log:
Tests for @New
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/InitializerSimpleBean.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/InitializerSimpleBean.java 2010-02-05 16:20:57 UTC (rev 5798)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/InitializerSimpleBean.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -21,6 +21,7 @@
import javax.ejb.Stateful;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.inject.Default;
+import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
import javax.inject.Named;
@@ -33,7 +34,11 @@
private static final long serialVersionUID = 1L;
private static int initializerCalls = 0;
+ @SuppressWarnings("unused")
@Inject
+ private BeanManager beanManager;
+
+ @Inject
public void initializer()
{
initializerCalls++;
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/NewEnterpriseBeanTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/NewEnterpriseBeanTest.java 2010-02-05 16:20:57 UTC (rev 5798)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/enterprise/newBean/NewEnterpriseBeanTest.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -97,7 +97,8 @@
@Test
@SpecAssertions({
- @SpecAssertion(section="3.12", id = "j")
+ @SpecAssertion(section="3.12", id = "j"),
+ @SpecAssertion(section="3.12", id = "k")
})
public void testForEachEnterpriseBeanANewBeanExists()
{
@@ -112,6 +113,7 @@
assert newOrderBean.getQualifiers().iterator().next().annotationType().equals(New.class);
assert orderBean.getTypes().equals(newOrderBean.getTypes());
+ assert orderBean.getBeanClass().equals(newOrderBean.getBeanClass());
Bean<LionLocal> lionBean = getBeans(LionLocal.class, TAME_LITERAL).iterator().next();
Bean<LionLocal> newLionBean = getBeans(LionLocal.class, LionLocal.NEW).iterator().next();
@@ -125,5 +127,16 @@
assert newLionBean.getQualifiers().iterator().next().annotationType().equals(New.class);
assert lionBean.getTypes().equals(newLionBean.getTypes());
+ assert lionBean.getBeanClass().equals(newLionBean.getBeanClass());
}
+
+ @Test(groups = { "new" })
+ @SpecAssertion(section = "3.12", id = "h")
+ public void testNewBeanHasSameInjectedFields()
+ {
+ Bean<InitializerSimpleBeanLocal> simpleBean = getBeans(InitializerSimpleBeanLocal.class).iterator().next();
+ Bean<InitializerSimpleBeanLocal> newSimpleBean = getBeans(InitializerSimpleBeanLocal.class, InitializerSimpleBeanLocal.NEW).iterator().next();
+ assert !newSimpleBean.getInjectionPoints().isEmpty();
+ assert simpleBean.getInjectionPoints().equals(newSimpleBean.getInjectionPoints());
+ }
}
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/NewSimpleBeanTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/NewSimpleBeanTest.java 2010-02-05 16:20:57 UTC (rev 5798)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/NewSimpleBeanTest.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -16,6 +16,7 @@
*/
package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
@@ -40,10 +41,12 @@
import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.test.audit.annotations.SpecVersion;
import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
import org.testng.annotations.Test;
@Artifact
@SpecVersion(spec="cdi", version="20091101")
+@BeansXml("beans.xml")
public class NewSimpleBeanTest extends AbstractJSR299Test
{
@@ -204,25 +207,47 @@
@SpecAssertion(section = "3.12", id = "d")
public void testForEachSimpleBeanANewBeanExists()
{
- assert getCurrentManager().getBeans(Order.class).size() == 1;
- assert getCurrentManager().getBeans(Order.class).iterator().next().getQualifiers().size() == 2;
- assert getCurrentManager().getBeans(Order.class).iterator().next().getQualifiers().contains(new DefaultLiteral());
+ assert getBeans(Order.class).size() == 1;
+ assert getUniqueBean(Order.class).getQualifiers().size() == 2;
+ assert getUniqueBean(Order.class).getQualifiers().contains(new DefaultLiteral());
assert getBeans(Order.class, Order.NEW).size() == 1;
- assert getBeans(Order.class, Order.NEW).iterator().next().getQualifiers().size() == 1;
- assert getBeans(Order.class, Order.NEW).iterator().next().getQualifiers().iterator().next().annotationType().equals(New.class);
+ assert getUniqueBean(Order.class, Order.NEW).getQualifiers().size() == 1;
+ assert getUniqueBean(Order.class, Order.NEW).getQualifiers().iterator().next().annotationType().equals(New.class);
- assert getCurrentManager().getBeans(Lion.class, TAME_LITERAL).size() == 1;
- assert getCurrentManager().getBeans(Lion.class, TAME_LITERAL).iterator().next().getQualifiers().size() == 2;
- assert getCurrentManager().getBeans(Lion.class, TAME_LITERAL).iterator().next().getQualifiers().contains(TAME_LITERAL);
- assert getCurrentManager().getBeans(Lion.class, TAME_LITERAL).iterator().next().getQualifiers().contains(new AnyLiteral());
+ assert getBeans(Lion.class, TAME_LITERAL).size() == 1;
+ assert getUniqueBean(Lion.class, TAME_LITERAL).getQualifiers().size() == 2;
+ assert getUniqueBean(Lion.class, TAME_LITERAL).getQualifiers().contains(TAME_LITERAL);
+ assert getUniqueBean(Lion.class, TAME_LITERAL).getQualifiers().contains(new AnyLiteral());
assert getBeans(Lion.class, Lion.NEW).size() == 1;
- assert getBeans(Lion.class, Lion.NEW).iterator().next().getQualifiers().size() == 1;
- assert getBeans(Lion.class, Lion.NEW).iterator().next().getQualifiers().iterator().next().annotationType().equals(New.class);
+ assert getUniqueBean(Lion.class, Lion.NEW).getQualifiers().size() == 1;
+ assert annotationSetMatches(getUniqueBean(Lion.class, Lion.NEW).getQualifiers(), New.class);
}
-
+
@Test(groups = { "new" })
+ @SpecAssertion(section = "3.12", id = "d")
+ public void testNewBeanHasSameBeanClass()
+ {
+ assert getUniqueBean(Order.class).getBeanClass().equals(Order.class);
+ assert getUniqueBean(Order.class, Order.NEW).getBeanClass().equals(Order.class);
+
+ assert getUniqueBean(Lion.class, TAME_LITERAL).getBeanClass().equals(Lion.class);
+ assert getUniqueBean(Lion.class, Lion.NEW).getBeanClass().equals(Lion.class);
+ }
+
+ @Test(groups = { "new" })
+ @SpecAssertion(section = "3.12", id = "e")
+ public void testNewBeanHasSameBeanTypes()
+ {
+ assert typeSetMatches(getUniqueBean(Order.class).getTypes(), Order.class, Serializable.class, Object.class);
+ assert typeSetMatches(getUniqueBean(Order.class, Order.NEW).getTypes(), Order.class, Serializable.class, Object.class);
+
+ assert typeSetMatches(getUniqueBean(Lion.class, TAME_LITERAL).getTypes(), Lion.class, Object.class);
+ assert typeSetMatches(getUniqueBean(Lion.class, Lion.NEW).getTypes(), Lion.class, Object.class);
+ }
+
+ @Test(groups = { "new" })
@SpecAssertion(section = "3.12", id = "f")
public void testNewBeanHasSameConstructor()
{
@@ -255,6 +280,22 @@
assert simpleBean.getInjectionPoints().equals(newSimpleBean.getInjectionPoints());
}
+ @Test(groups = { "new" })
+ @SpecAssertion(section = "3.12", id = "i")
+ public void testNewBeanHasSameInterceptorBindings()
+ {
+ assert getInstanceByType(Order.class).foo();
+ assert getInstanceByType(Order.class, Order.NEW).foo();
+ }
+
+ @Test(groups = { "new" })
+ @SpecAssertion(section = "3.12", id = "xb")
+ public void testNewBeanIsNotAlternative()
+ {
+ assert getUniqueBean(Tiger.class).isAlternative();
+ assert !getUniqueBean(Tiger.class, Tiger.NEW).isAlternative();
+ }
+
@Test
@SpecAssertion(section="3.12", id="z")
public void testNewBeanWithNoMemberValue()
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Order.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Order.java 2010-02-05 16:20:57 UTC (rev 5798)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Order.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -22,6 +22,8 @@
import org.jboss.jsr299.tck.literals.NewLiteral;
+@Secure
+@Transactional
class Order implements Serializable
{
@@ -37,5 +39,10 @@
private static final long serialVersionUID = 1L;
public static boolean constructed = true;
+
+ public boolean foo()
+ {
+ return false;
+ }
}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/OrderInterceptor.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/OrderInterceptor.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/OrderInterceptor.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -0,0 +1,17 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+@Interceptor
+@Secure
+@Transactional
+public class OrderInterceptor
+{
+ @AroundInvoke
+ public Object intercept(InvocationContext ctx) throws Exception
+ {
+ return true;
+ }
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Secure.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Secure.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Secure.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+@Target( { TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+@InterceptorBinding
+@interface Secure
+{
+
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Tiger.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Tiger.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Tiger.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -0,0 +1,21 @@
+package org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import javax.enterprise.inject.Alternative;
+import javax.enterprise.inject.New;
+
+import org.jboss.jsr299.tck.literals.NewLiteral;
+
+@Alternative
+public class Tiger
+{
+
+ public static final New NEW = new NewLiteral()
+ {
+
+ public Class<?> value()
+ {
+ return Tiger.class;
+ }
+ };
+
+}
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Transactional.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Transactional.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/Transactional.java 2010-02-05 16:48:35 UTC (rev 5799)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.interceptor.InterceptorBinding;
+
+@Target( { TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+@InterceptorBinding
+@interface Transactional
+{
+
+}
Added: cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/beans.xml
===================================================================
--- cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/beans.xml (rev 0)
+++ cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/implementation/simple/newSimpleBean/beans.xml 2010-02-05 16:48:35 UTC (rev 5799)
@@ -0,0 +1,8 @@
+<beans>
+ <alternatives>
+ <class>org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean.Tiger</class>
+ </alternatives>
+ <interceptors>
+ <class>org.jboss.jsr299.tck.tests.implementation.simple.newSimpleBean.OrderInterceptor</class>
+ </interceptors>
+</beans>