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 2011/09/26 23:45:58 UTC
svn commit: r1176076 - in
/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused:
./ UnusedBean.java UnusedBeanDeclarer.java UnusedBeanProducer.java
UnusedBeanTest.java
Author: struberg
Date: Mon Sep 26 21:45:58 2011
New Revision: 1176076
URL: http://svn.apache.org/viewvc?rev=1176076&view=rev
Log:
OWB-618 add unit test for wrongly invoked disposal method
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBean.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanDeclarer.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanProducer.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanTest.java
- copied, changed from r1174583, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBean.java?rev=1176076&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBean.java Mon Sep 26 21:45:58 2011
@@ -0,0 +1,41 @@
+/*
+ * 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.unused;
+
+import javax.enterprise.inject.Typed;
+
+/**
+ * This bean will acually never been touched.
+ */
+@Typed
+public class UnusedBean
+{
+
+ private int i;
+
+ public int getI()
+ {
+ return i;
+ }
+
+ public void setI(int i)
+ {
+ this.i = i;
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanDeclarer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanDeclarer.java?rev=1176076&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanDeclarer.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanDeclarer.java Mon Sep 26 21:45:58 2011
@@ -0,0 +1,36 @@
+/*
+ * 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.unused;
+
+import javax.inject.Inject;
+
+/**
+ * This class declares the UnusedBean as injectionpoint
+ * but never uses it. Thus it should never get resolved and
+ * only the proxy should exist!
+ */
+public class UnusedBeanDeclarer
+{
+ private @Inject UnusedBean unusedBean;
+
+ public int doSomething()
+ {
+ return 42;
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanProducer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanProducer.java?rev=1176076&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanProducer.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanProducer.java Mon Sep 26 21:45:58 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.unused;
+
+import org.junit.Assert;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Produces;
+
+/**
+ * producer of our unused bean
+ */
+public class UnusedBeanProducer
+{
+ public static boolean failed = false;
+
+ @Produces @RequestScoped
+ public UnusedBean createUnusedBean()
+ {
+ return new UnusedBean();
+ }
+
+ public void dispose(@Disposes UnusedBean unusedBean)
+ {
+ failed = true;
+ Assert.fail("we should not dispose not-created beans ;)");
+ }
+}
Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanTest.java (from r1174583, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanTest.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java&r1=1174583&r2=1176076&rev=1176076&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/serialization/DependentPassivationCriteriaTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/unused/UnusedBeanTest.java Mon Sep 26 21:45:58 2011
@@ -16,46 +16,43 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.webbeans.newtests.injection.serialization;
+package org.apache.webbeans.newtests.injection.unused;
-import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.newtests.AbstractUnitTest;
-import org.apache.webbeans.newtests.injection.serialization.beans.NonSerializableDependentBean;
-import org.apache.webbeans.newtests.injection.serialization.beans.SerializableInjectionTargetFailA;
import org.junit.Test;
+import org.junit.Assert;
+import javax.enterprise.context.RequestScoped;
import java.util.ArrayList;
import java.util.Collection;
/**
- * <p>This test performs a few tests to ensure correct handling of injecting
- * @Dependent scoped beans into beans of passivating scopes with
- * regard of Serialization handling.</p>
- * <p>In general a non-Serializable @Dependent scoped bean must not get
- * injected into a passivating scoped bean. This is true for plain beans,
- * producer fields and also for producer methods</p>
- * <p>Injection <b>is</b> allowed if the injection point is transient or if
- * the injection target bean either provides a writeObject(ObjectOutputStream)
- * or a Externalizable#writeExternal(ObjectOutput) method.</p>
+ * <p>This test validates OWBs behaviour with unused beans.</p>
*/
-public class DependentPassivationCriteriaTest extends AbstractUnitTest
+public class UnusedBeanTest extends AbstractUnitTest
{
- /**
- * This tests if the container correctly detects a deployment exception
- * according to spec 6.6.4:
- * "
- */
- @Test(expected = WebBeansConfigurationException.class)
- public void testInvalidNonSerializableDependentInjection()
+ @Test
+ public void testUnusedBean()
{
Collection<String> beanXmls = new ArrayList<String>();
Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
- beanClasses.add(NonSerializableDependentBean.class);
- beanClasses.add(SerializableInjectionTargetFailA.class);
+ beanClasses.add(UnusedBean.class);
+ beanClasses.add(UnusedBeanProducer.class);
+ beanClasses.add(UnusedBeanDeclarer.class);
try
{
startContainer(beanClasses, beanXmls);
+
+ UnusedBeanDeclarer unusedBeanDeclarer = getInstance(UnusedBeanDeclarer.class);
+ Assert.assertNotNull(unusedBeanDeclarer);
+
+ unusedBeanDeclarer.doSomething();
+
+ // end the RequestScope to trigger disposal
+ getWebBeansContext().getContextsService().endContext(RequestScoped.class, null);
+ Assert.assertFalse(UnusedBeanProducer.failed);
+
}
finally {
shutDownContainer();