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 2014/09/27 10:54:19 UTC
svn commit: r1627938 -
/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/ProducerPassivationTest.java
Author: struberg
Date: Sat Sep 27 08:54:18 2014
New Revision: 1627938
URL: http://svn.apache.org/r1627938
Log:
add more tests for PassivationCapable checks.
This is mainly to make sure that upstream OWB is not hit by a
bug reported against WAS-Liberty
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/ProducerPassivationTest.java
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/ProducerPassivationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/ProducerPassivationTest.java?rev=1627938&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/ProducerPassivationTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/producer/ProducerPassivationTest.java Sat Sep 27 08:54:18 2014
@@ -0,0 +1,132 @@
+/*
+ * 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.producer;
+
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.DefinitionException;
+import javax.inject.Inject;
+import java.io.Serializable;
+
+import junit.framework.Assert;
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+/**
+ * Tests passivation capability detection for producerMethods
+ */
+public class ProducerPassivationTest extends AbstractUnitTest
+{
+ @Test
+ public void testNonSerializableInterfaceWithSerializableImplWorks()
+ {
+ startContainer(SerializableImplProducerOwner.class);
+
+ NonSerializableInterface instance = getInstance(NonSerializableInterface.class);
+ Assert.assertNotNull(instance);
+ }
+
+ @Test
+ public void testNonSerializableBaseClassWithSerializableImplWorks()
+ {
+ startContainer(SerializableExtendedClassProducerOwner.class);
+
+ NonSerializableBaseClass instance = getInstance(NonSerializableBaseClass.class);
+ Assert.assertNotNull(instance);
+ }
+
+ @Test
+ public void testNonSerializableInterfaceInjectionWorks()
+ {
+ startContainer(SerializableImplProducerOwner.class, NonSerializableImplHolder.class);
+
+ NonSerializableImplHolder instance = getInstance(NonSerializableImplHolder.class);
+ Assert.assertNotNull(instance);
+ Assert.assertNotNull(instance.getInstance());
+ }
+
+ @Test(expected = DefinitionException.class)
+ public void testBrokenNonPassivatingProducer()
+ {
+ startContainer(NonSerializableFinalImplProducerOwner.class);
+ }
+
+
+
+ public static interface NonSerializableInterface
+ {
+ }
+
+ public static class SerializableImpl implements NonSerializableInterface, Serializable
+ {
+ }
+
+ public static class SerializableImplProducerOwner
+ {
+ @Produces
+ @SessionScoped
+ public NonSerializableInterface createSerializableImpl()
+ {
+ return new SerializableImpl(); // all fine as the actual impl is Serializable at runtime
+ }
+ }
+
+ public static class NonSerializableImplHolder
+ {
+ private @Inject NonSerializableInterface instance;
+
+ public NonSerializableInterface getInstance()
+ {
+ return instance;
+ }
+ }
+
+ public static final class NonSerializableImpl implements NonSerializableInterface
+ {
+ }
+
+ public static class NonSerializableFinalImplProducerOwner
+ {
+ // this should get detected at boot time already
+ @Produces
+ @SessionScoped
+ public NonSerializableImpl createNonSerializableFinalImpl()
+ {
+ return new NonSerializableImpl();
+ }
+ }
+
+ public static class NonSerializableBaseClass
+ {
+ }
+
+ public static class SerializableExtendedClass extends NonSerializableBaseClass
+ {
+ }
+
+ public static class SerializableExtendedClassProducerOwner
+ {
+ // this should get detected at boot time already
+ @Produces
+ @SessionScoped
+ public NonSerializableBaseClass createSerializableExtendedClass()
+ {
+ return new SerializableExtendedClass();
+ }
+ }
+
+}