[weld-commits] Weld SVN: r4752 - in core/trunk/tests/src: test/java/org/jboss/weld/tests and 5 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Sat Nov 7 16:36:11 EST 2009


Author: pete.muir at jboss.org
Date: 2009-11-07 16:36:10 -0500 (Sat, 07 Nov 2009)
New Revision: 4752

Added:
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/BuiltInBeanPassivationCapableTest.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Checker.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ConstructorInjectionPointConsumer.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Consumer.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Cow.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/CowEventObserver.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Dog.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/FieldInjectionPointConsumer.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/MethodInjectionPointConsumer.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Produced.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Checker.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceConsumer.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducer.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducerFieldPassivationCapableTest.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Horse.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/HorseRemote.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Produced.java
   core/trunk/tests/src/test/resources/org/jboss/weld/tests/builtinBeans/
   core/trunk/tests/src/test/resources/org/jboss/weld/tests/builtinBeans/ee/
   core/trunk/tests/src/test/resources/org/jboss/weld/tests/builtinBeans/ee/persistence.xml
Modified:
   core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java
Log:
Tests for WELD-214, WELD-64, WELD-250, WELD-227, WELD-231

Modified: core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java	2009-11-07 21:32:43 UTC (rev 4751)
+++ core/trunk/tests/src/main/java/org/jboss/weld/test/AbstractWeldTest.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -119,10 +119,10 @@
       return bytes.toByteArray();
    }
 
-   protected Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException
+   protected <T> T deserialize(byte[] bytes) throws IOException, ClassNotFoundException
    {
       ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
-      return in.readObject();
+      return (T) in.readObject();
    }
 
    protected BeanManagerImpl getCurrentManager()

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/BuiltInBeanPassivationCapableTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/BuiltInBeanPassivationCapableTest.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/BuiltInBeanPassivationCapableTest.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,133 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import static org.jboss.weld.tests.builtinBeans.Checker.checkBeanManager;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkEquality;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkEvent;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkInjectionPoint;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkInstance;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkPrincipal;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkUserTransaction;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkValidator;
+import static org.jboss.weld.tests.builtinBeans.Checker.checkValidatorFactory;
+
+import java.security.Principal;
+
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.transaction.UserTransaction;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+ at Artifact
+public class BuiltInBeanPassivationCapableTest extends AbstractWeldTest
+{
+
+   @Test
+   public void testDefaultValidatorBean() throws Throwable
+   {
+      Validator validator = getCurrentManager().getInstanceByType(Validator.class);
+      Validator validator1 = deserialize(serialize(validator));
+      assert checkValidator(validator1);
+   }
+
+   @Test
+   public void testDefaultValidatorFactoryBean() throws Throwable
+   {
+      ValidatorFactory validatorFactory = getCurrentManager().getInstanceByType(ValidatorFactory.class);
+      ValidatorFactory validatorFactory1 = deserialize(serialize(validatorFactory));
+      assert checkValidatorFactory(validatorFactory1);
+   }
+
+   @Test(groups="incontainer-broken")
+   public void testPrincipal() throws Throwable
+   {
+      Principal principal = getCurrentManager().getInstanceByType(Principal.class);
+      Principal principal1 = deserialize(serialize(principal));
+      assert checkPrincipal(principal1);
+   }
+
+   @Test
+   public void testUserTransactionBean() throws Throwable
+   {
+      UserTransaction userTransaction = getCurrentManager().getInstanceByType(UserTransaction.class);
+      UserTransaction userTransaction1 = deserialize(serialize(userTransaction));
+      assert checkUserTransaction(userTransaction1);
+   }
+   
+   @Test 
+   public void testBeanManagerBean() throws Throwable
+   {
+      BeanManager beanManager = getCurrentManager().getInstanceByType(BeanManager.class);
+      BeanManager beanManager1 = deserialize(serialize(beanManager));
+      assert checkBeanManager(beanManager1);
+      assert checkEquality(beanManager, beanManager1);
+   }
+   
+   @Test
+   public void testInstance() throws Throwable
+   {
+      Instance<Cow> instance = getCurrentManager().getInstanceByType(Consumer.class).getCow();
+      Instance<Cow> instance1 = deserialize(serialize(instance));
+      assert checkInstance(instance1);
+      assert checkEquality(instance, instance1);
+   }
+   
+   @Test
+   public void testEvent() throws Throwable
+   {
+      Event<Cow> event = getCurrentManager().getInstanceByType(Consumer.class).getEvent();
+      CowEventObserver observer = getCurrentManager().getInstanceByType(CowEventObserver.class);
+      Event<Cow> event1 = deserialize(serialize(event));
+      assert checkEvent(event1, observer);
+      assert checkEquality(event, event1);
+   }
+   
+   @Test
+   public void testFieldInjectionPoint() throws Throwable
+   {
+      Dog.reset();
+      getCurrentManager().getInstanceByType(FieldInjectionPointConsumer.class).ping();
+      InjectionPoint injectionPoint = Dog.getInjectionPoint();
+      InjectionPoint injectionPoint1 = deserialize(serialize(injectionPoint));
+      assert checkInjectionPoint(injectionPoint1, FieldInjectionPointConsumer.class);
+      assert checkEquality(injectionPoint, injectionPoint1);
+   }
+   
+   @Test
+   public void testConstructorInjectionPoint() throws Throwable
+   {
+      Dog.reset();
+      getCurrentManager().getInstanceByType(ConstructorInjectionPointConsumer.class).ping();
+      InjectionPoint injectionPoint = Dog.getInjectionPoint();
+      InjectionPoint injectionPoint1 = deserialize(serialize(injectionPoint));
+      assert checkInjectionPoint(injectionPoint1, ConstructorInjectionPointConsumer.class);
+      assert checkEquality(injectionPoint, injectionPoint1);
+   }
+   
+   @Test
+   public void testMethodInjectionPoint() throws Throwable
+   {
+      Dog.reset();
+      getCurrentManager().getInstanceByType(MethodInjectionPointConsumer.class).ping();
+      InjectionPoint injectionPoint = Dog.getInjectionPoint();
+      InjectionPoint injectionPoint1 = deserialize(serialize(injectionPoint));
+      assert checkInjectionPoint(injectionPoint1, MethodInjectionPointConsumer.class);
+      assert checkEquality(injectionPoint, injectionPoint1);
+   }
+   
+   @Test
+   public void testAllOnBean() throws Throwable
+   {
+      Consumer consumer = getCurrentManager().getInstanceByType(Consumer.class);
+      consumer.check();
+      Consumer consumer1 = deserialize(serialize(consumer));
+      consumer1.check();
+   }
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/BuiltInBeanPassivationCapableTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Checker.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Checker.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Checker.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,122 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import java.security.Principal;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+
+public class Checker
+{
+   
+   public static boolean checkPrincipal(Principal principal)
+   {
+      principal.getName();
+      return true;
+   }
+   
+   public static boolean checkBeanManager(BeanManager beanManager)
+   {
+      return beanManager != null && beanManager.isScope(ApplicationScoped.class);
+   }
+   
+   public static boolean checkUserTransaction(UserTransaction userTransaction)
+   {
+      try
+      {
+         if (userTransaction != null)
+         {
+            userTransaction.getStatus();
+            return true;
+         }
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+      return false;
+   }
+   
+   public static boolean checkValidator(Validator validator)
+   {
+      try
+      {
+         if (validator != null)
+         {
+            validator.unwrap(String.class);
+         }
+      }
+      catch (ValidationException e)
+      {
+         return true;
+      }
+      return false;
+   }
+
+   public static boolean checkValidatorFactory(ValidatorFactory validatorFactory)
+   {
+      try
+      {
+         if (validatorFactory != null)
+         {
+            validatorFactory.unwrap(String.class);
+         }
+      }
+      catch (ValidationException e)
+      {
+         return true;
+      }
+      return false;
+   }
+   
+   public static boolean checkInstance(Instance<Cow> cow)
+   {
+      if (cow != null && cow.get() != null)
+      {
+         return cow.get().getName().equals("Daisy");
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   public static boolean checkEvent(Event<Cow> cowEvent, CowEventObserver observer)
+   {
+      observer.reset();
+      if (cowEvent != null)
+      {
+         cowEvent.fire(new Cow());
+         return observer.isObserved(); 
+      }
+      else
+      {
+         return false;
+      }
+   }
+
+   public static boolean checkInjectionPoint(InjectionPoint injectionPoint, Class<?> injectedClass)
+   {
+      if (injectionPoint != null)
+      {
+         return injectedClass.equals(injectionPoint.getBean().getBeanClass());
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   public static boolean checkEquality(Object object1, Object object2)
+   {
+      return object1.equals(object2) && object1.hashCode() == object2.hashCode();
+   }
+   
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Checker.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ConstructorInjectionPointConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ConstructorInjectionPointConsumer.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ConstructorInjectionPointConsumer.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,19 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+
+ at SessionScoped
+public class ConstructorInjectionPointConsumer implements Serializable
+{
+   
+   public ConstructorInjectionPointConsumer() {}
+   
+   @Inject
+   public ConstructorInjectionPointConsumer(Dog dog) {}
+   
+   public void ping() {}
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ConstructorInjectionPointConsumer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Consumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Consumer.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Consumer.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,60 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import java.io.Serializable;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.transaction.UserTransaction;
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+
+ at SessionScoped
+public class Consumer implements Serializable
+{
+   
+   @Inject Validator validator;
+   @Inject ValidatorFactory validatorFactory;
+   // Not working incontainer as there is no principal
+   //@Inject Principal principal;
+   @Inject UserTransaction userTransaction;
+   @Inject BeanManager beanManager;
+   @Inject Instance<Cow> cow;
+   @Inject Event<Cow> event;
+   @Inject CowEventObserver observer;
+   
+   @PostConstruct
+   public void postConstruct()
+   {
+      cow.get().setName("Daisy");
+   }
+   
+   public Instance<Cow> getCow()
+   {
+      return cow;
+   }
+   
+   public Event<Cow> getEvent()
+   {
+      return event;
+   }
+   
+   public void check()
+   {
+      assert Checker.checkBeanManager(beanManager);
+
+      // Not working incontainer as there is no principal
+      //assert Checker.checkPrincipal(principal);
+      assert Checker.checkUserTransaction(userTransaction);
+      assert Checker.checkValidator(validator);
+      assert Checker.checkValidatorFactory(validatorFactory);
+      assert Checker.checkInstance(cow);
+      assert Checker.checkEvent(event, observer);
+   }
+   
+   
+   
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Consumer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Cow.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Cow.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Cow.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import javax.enterprise.context.RequestScoped;
+
+ at RequestScoped
+public class Cow
+{
+   
+   private String name;
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Cow.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/CowEventObserver.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/CowEventObserver.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/CowEventObserver.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,29 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
+
+ at ApplicationScoped
+public class CowEventObserver implements Serializable
+{
+   
+   private boolean observed;
+   
+   public void observeEvent(@Observes Cow cow)
+   {
+      this.observed = true;
+   }
+   
+   public boolean isObserved()
+   {
+      return observed;
+   }
+   
+   public void reset()
+   {
+      this.observed = false;
+   }
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/CowEventObserver.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Dog.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Dog.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Dog.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,29 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import java.io.Serializable;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+
+public class Dog implements Serializable
+{
+   
+   private static InjectionPoint injectionPoint;
+   
+   @Inject
+   public Dog(InjectionPoint injectionPoint)
+   {
+      Dog.injectionPoint = injectionPoint;
+   }
+   
+   public static void reset()
+   {
+      Dog.injectionPoint = null;
+   }
+   
+   public static InjectionPoint getInjectionPoint()
+   {
+      return injectionPoint;
+   }
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Dog.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/FieldInjectionPointConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/FieldInjectionPointConsumer.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/FieldInjectionPointConsumer.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,16 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+
+ at SessionScoped
+public class FieldInjectionPointConsumer implements Serializable
+{
+   
+   @Inject Dog dogField;
+   
+   public void ping() {}
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/FieldInjectionPointConsumer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/MethodInjectionPointConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/MethodInjectionPointConsumer.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/MethodInjectionPointConsumer.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,17 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+
+ at SessionScoped
+public class MethodInjectionPointConsumer implements Serializable
+{
+   
+   @Inject
+   public void setDog(Dog dog) {}
+   
+   public void ping() {}
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/MethodInjectionPointConsumer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Produced.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Produced.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Produced.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,22 @@
+package org.jboss.weld.tests.builtinBeans;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+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.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { TYPE, METHOD, FIELD, PARAMETER })
+ at Documented
+ at interface Produced
+{
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/Produced.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Checker.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Checker.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Checker.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,65 @@
+package org.jboss.weld.tests.builtinBeans.ee;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+public class Checker
+{
+   
+   public static boolean checkUserTransaction(UserTransaction userTransaction)
+   {
+      try
+      {
+         if (userTransaction != null)
+         {
+            userTransaction.getStatus();
+            return true;
+         }
+      }
+      catch (SystemException e)
+      {
+         throw new RuntimeException(e);
+      }
+      return false;
+   }
+   
+   
+   public static boolean checkEntityManager(EntityManager entityManager)
+   {
+      if (entityManager != null)
+      {
+         return entityManager.isOpen();
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   public static boolean checkEntityManagerFactory(EntityManagerFactory entityManagerFactory)
+   {
+      if (entityManagerFactory != null)
+      {
+         return entityManagerFactory.isOpen();
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+   public static boolean checkRemoteEjb(HorseRemote horse)
+   {
+      if (horse != null)
+      {
+         return horse.ping();
+      }
+      else
+      {
+         return false;
+      }
+   }
+   
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Checker.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceConsumer.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceConsumer.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,33 @@
+package org.jboss.weld.tests.builtinBeans.ee;
+
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkEntityManager;
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkEntityManagerFactory;
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkRemoteEjb;
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkUserTransaction;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.UserTransaction;
+
+ at SessionScoped
+public class EEResourceConsumer implements Serializable
+{
+   
+   @Inject @Produced UserTransaction userTransaction;
+   @Inject @Produced EntityManager entityManager;
+   @Inject @Produced EntityManagerFactory entityManagerFactory;
+   @Inject @Produced HorseRemote horse;
+   
+   public void check()
+   {
+      assert checkUserTransaction(userTransaction);
+      assert checkEntityManager(entityManager);
+      assert checkEntityManagerFactory(entityManagerFactory);
+      assert checkRemoteEjb(horse);
+   }
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceConsumer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducer.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducer.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,35 @@
+package org.jboss.weld.tests.builtinBeans.ee;
+
+import javax.annotation.Resource;
+import javax.ejb.EJB;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceUnit;
+import javax.transaction.UserTransaction;
+
+public class EEResourceProducer
+{
+   
+   @Resource(mappedName="java:comp/UserTransaction")
+   @Produced
+   @Produces
+   private UserTransaction transaction;
+   
+   @PersistenceContext
+   @Produces
+   @Produced
+   private EntityManager entityManager;
+   
+   @PersistenceUnit
+   @Produces
+   @Produced
+   private EntityManagerFactory entityManagerFactory;
+   
+   @EJB
+   @Produces
+   @Produced
+   private HorseRemote horse;
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducerFieldPassivationCapableTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducerFieldPassivationCapableTest.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducerFieldPassivationCapableTest.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,73 @@
+package org.jboss.weld.tests.builtinBeans.ee;
+
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkEntityManager;
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkEntityManagerFactory;
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkRemoteEjb;
+import static org.jboss.weld.tests.builtinBeans.ee.Checker.checkUserTransaction;
+
+import java.lang.annotation.Annotation;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.transaction.UserTransaction;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+ at Artifact
+ at IntegrationTest
+ at Packaging(PackagingType.EAR)
+ at Resource(source = "persistence.xml", destination = "META-INF/persistence.xml")
+public class EEResourceProducerFieldPassivationCapableTest extends AbstractWeldTest
+{
+   
+   private static final Annotation PRODUCED = new AnnotationLiteral<Produced>() {};
+   
+   @Test
+   public void testResource() throws Throwable
+   {
+      UserTransaction userTransaction = getCurrentManager().getInstanceByType(UserTransaction.class, PRODUCED);
+      UserTransaction userTransaction1 = deserialize(serialize(userTransaction));
+      assert checkUserTransaction(userTransaction1);
+   }
+   
+   @Test
+   public void testEntityManager() throws Throwable
+   {
+      EntityManager entityManager = getCurrentManager().getInstanceByType(EntityManager.class, PRODUCED);
+      EntityManager entityManager1 = deserialize(serialize(entityManager));
+      assert checkEntityManager(entityManager1);
+   }
+   
+   @Test
+   public void testEntityManagerFactory() throws Throwable
+   {
+      EntityManagerFactory entityManagerFactory = getCurrentManager().getInstanceByType(EntityManagerFactory.class, PRODUCED);
+      EntityManagerFactory entityManagerFactory1 = deserialize(serialize(entityManagerFactory));
+      assert checkEntityManagerFactory(entityManagerFactory1);
+   }
+   
+   @Test
+   public void testRemoteEjb() throws Throwable
+   {
+      HorseRemote horse = getCurrentManager().getInstanceByType(HorseRemote.class, PRODUCED);
+      HorseRemote horse1 = deserialize(serialize(horse));
+      assert checkRemoteEjb(horse1);
+   }
+   
+   @Test
+   public void testAllOnBean() throws Throwable
+   {
+      EEResourceConsumer consumer = getCurrentManager().getInstanceByType(EEResourceConsumer.class);
+      consumer.check();
+      EEResourceConsumer consumer1 = deserialize(serialize(consumer));
+      consumer1.check();
+   }
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/EEResourceProducerFieldPassivationCapableTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Horse.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Horse.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Horse.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,13 @@
+package org.jboss.weld.tests.builtinBeans.ee;
+
+import javax.ejb.Stateful;
+
+
+ at Stateful
+public class Horse implements HorseRemote
+{
+   public boolean ping()
+   {
+      return true;
+   }
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Horse.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/HorseRemote.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/HorseRemote.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/HorseRemote.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,11 @@
+package org.jboss.weld.tests.builtinBeans.ee;
+
+import javax.ejb.Remote;
+
+ at Remote
+public interface HorseRemote
+{
+
+   public boolean ping();
+   
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/HorseRemote.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Produced.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Produced.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Produced.java	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,22 @@
+package org.jboss.weld.tests.builtinBeans.ee;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+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.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { TYPE, METHOD, FIELD, PARAMETER })
+ at Documented
+ at interface Produced
+{
+
+}


Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/builtinBeans/ee/Produced.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/builtinBeans/ee/persistence.xml
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/builtinBeans/ee/persistence.xml	                        (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/builtinBeans/ee/persistence.xml	2009-11-07 21:36:10 UTC (rev 4752)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
+             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
+             version="1.0">
+   <persistence-unit name="test">
+      <jta-data-source>java:/DefaultDS</jta-data-source>
+   </persistence-unit>
+</persistence>
\ No newline at end of file


Property changes on: core/trunk/tests/src/test/resources/org/jboss/weld/tests/builtinBeans/ee/persistence.xml
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the weld-commits mailing list