openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1413396 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes: ./ beans/ common/
Date Sun, 25 Nov 2012 20:02:41 GMT
Author: struberg
Date: Sun Nov 25 20:02:38 2012
New Revision: 1413396

URL: http://svn.apache.org/viewvc?rev=1413396&view=rev
Log:
OWB-725 provide test (currently disabled)

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentModelProducer.java
      - copied, changed from r1413190, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentProducer.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestModelProducer.java
      - copied, changed from r1413190, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestBean.java
Removed:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentProducer.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestBean.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DependentMethodBeanTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/DependentModel.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/RequestModel.java

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DependentMethodBeanTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DependentMethodBeanTest.java?rev=1413396&r1=1413395&r2=1413396&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DependentMethodBeanTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/DependentMethodBeanTest.java
Sun Nov 25 20:02:38 2012
@@ -21,16 +21,14 @@ package org.apache.webbeans.newtests.dis
 import java.util.ArrayList;
 import java.util.Collection;
 
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import junit.framework.Assert;
 import org.apache.webbeans.newtests.AbstractUnitTest;
-import org.apache.webbeans.newtests.disposes.beans.AppScopedBean;
-import org.apache.webbeans.newtests.disposes.beans.DependentProducer;
-import org.apache.webbeans.newtests.disposes.beans.DisposerMethodBean;
-import org.apache.webbeans.newtests.disposes.beans.InjectedIntoBean;
-import org.apache.webbeans.newtests.disposes.beans.IntermediateDependentBean;
-import org.apache.webbeans.newtests.disposes.beans.RequestBean;
+import org.apache.webbeans.newtests.disposes.beans.*;
+import org.apache.webbeans.newtests.disposes.beans.DependentModelProducer;
+import org.apache.webbeans.newtests.disposes.common.DependentModel;
 import org.apache.webbeans.newtests.disposes.common.RequestModel;
 import org.junit.Test;
 
@@ -44,7 +42,7 @@ public class DependentMethodBeanTest ext
         
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
         beanClasses.add(AppScopedBean.class);
-        beanClasses.add(RequestBean.class);
+        beanClasses.add(RequestModelProducer.class);
         
         startContainer(beanClasses, beanXmls);        
 
@@ -66,23 +64,58 @@ public class DependentMethodBeanTest ext
         Collection<String> beanXmls = new ArrayList<String>();
         
         Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
-        beanClasses.add(DependentProducer.class);
+        beanClasses.add(DependentModelProducer.class);
         beanClasses.add(InjectedIntoBean.class);
         beanClasses.add(IntermediateDependentBean.class);
         
-        startContainer(beanClasses, beanXmls);        
+        startContainer(beanClasses, beanXmls);
         Bean<InjectedIntoBean> bean = (Bean<InjectedIntoBean>)getBeanManager().getBeans("injectedIntoBean").iterator().next();
-         
+
         CreationalContext<InjectedIntoBean> cc = getBeanManager().createCreationalContext(bean);
-        
+
         InjectedIntoBean model = (InjectedIntoBean) getBeanManager().getReference(bean, InjectedIntoBean.class,
cc);
         
         Assert.assertFalse(model.isBeanNull());
-        
+
         shutDownContainer();
         
         //Disposer should only be called once
-        Assert.assertEquals(1, DependentProducer.disposerCount); 
-    } 
+        Assert.assertEquals(1, DependentModelProducer.disposerCount);
+    }
+
+    //X @Test temporarily disabled
+    @SuppressWarnings("unchecked")
+    public void testDisposerMethodWithRequestScoped()
+    {
+        Collection<String> beanXmls = new ArrayList<String>();
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(DependentModelProducer.class);
+        beanClasses.add(DependentModel.class);
+        beanClasses.add(RequestModel.class);
+        beanClasses.add(RequestModelProducer.class);
+
+        startContainer(beanClasses, beanXmls);
+
+        RequestModelProducer.producerGotDestroyed = false;
+        DependentModelProducer.producerGotDestroyed = false;
+        DependentModelProducer.disposerCount = 0;
+
+        RequestModel model = getInstance(RequestModel.class);
+
+        Assert.assertEquals(0, model.getID());
+
+        getLifecycle().getContextService().endContext(RequestScoped.class, null);
+
+        Assert.assertFalse(DependentModelProducer.producerGotDestroyed);
+        Assert.assertFalse(RequestModelProducer.producerGotDestroyed);
+
+        shutDownContainer();
+
+        //Disposer should only be called once
+        Assert.assertEquals(1, DependentModelProducer.disposerCount);
+    }
+
+
 
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentModelProducer.java
(from r1413190, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentProducer.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentModelProducer.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentModelProducer.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentProducer.java&r1=1413190&r2=1413396&rev=1413396&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentProducer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/DependentModelProducer.java
Sun Nov 25 20:02:38 2012
@@ -18,18 +18,22 @@
  */
 package org.apache.webbeans.newtests.disposes.beans;
 
+import javax.annotation.PreDestroy;
+import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.New;
 import javax.enterprise.inject.Produces;
 
 import org.apache.webbeans.newtests.disposes.common.DependentModel;
 import org.apache.webbeans.newtests.disposes.common.HttpHeader;
 
-public class DependentProducer
+@ApplicationScoped
+public class DependentModelProducer
 {
     public static int disposerCount = 0;
 
+    public static boolean producerGotDestroyed = false;
+
     @Produces @Dependent @HttpHeader
     public static DependentModel dproduce()
     {
@@ -40,7 +44,14 @@ public class DependentProducer
     
     public static void ddispose(@Disposes @HttpHeader DependentModel model)
     {
-        DependentProducer.disposerCount++;
+        DependentModelProducer.disposerCount++;
         System.out.println("disposed DependentModel from DependentDisposer");
     }
+
+    @PreDestroy
+    public void destroyMe()
+    {
+        producerGotDestroyed = true;
+    }
+
 }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestModelProducer.java
(from r1413190, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestBean.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestModelProducer.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestModelProducer.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestBean.java&r1=1413190&r2=1413396&rev=1413396&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/beans/RequestModelProducer.java
Sun Nov 25 20:02:38 2012
@@ -23,23 +23,34 @@ import javax.enterprise.context.Applicat
 import javax.enterprise.inject.Disposes;
 import javax.enterprise.inject.New;
 import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
 import javax.inject.Named;
 
+import org.apache.webbeans.newtests.disposes.common.DependentModel;
+import org.apache.webbeans.newtests.disposes.common.HttpHeader;
 import org.apache.webbeans.newtests.disposes.common.RequestModel;
 
 @ApplicationScoped
 @Named("org.apache.webbeans.newtests.disposes.beans.RequestBean")
-public class RequestBean {
+public class RequestModelProducer {
+
+    @Inject @HttpHeader
+    private DependentModel dependentModel;
+
+    public static boolean producerGotDestroyed = false;
 
     @Produces @RequestScoped @Named("rproduce")
-    public RequestModel rproduce(@New RequestModel rmodel)
+    public RequestModel rproduce()
     {
+        RequestModel rmodel =  new RequestModel();
+        rmodel.setDisposeModel(dependentModel);
+
     	System.out.println("produced RequestModel=" + rmodel);
     	return rmodel;
     }
     
     public void rdispose(@Disposes RequestModel rmodel)
     {
-    	System.out.println("disposed RequestModel=" + rmodel);
+        producerGotDestroyed = true;
     }    
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/DependentModel.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/DependentModel.java?rev=1413396&r1=1413395&r2=1413396&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/DependentModel.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/DependentModel.java
Sun Nov 25 20:02:38 2012
@@ -18,6 +18,9 @@
  */
 package org.apache.webbeans.newtests.disposes.common;
 
+import javax.enterprise.inject.Typed;
+
+@Typed()
 public class DependentModel
 {
     public boolean value = false;
@@ -25,7 +28,7 @@ public class DependentModel
     public int id = 0;
     
     public DependentModel() {
-    	System.out.println(this.getClass().getSimpleName() + ".DependentModel() is invoked");
+    	System.out.println(this.getClass().getSimpleName() + ".DependentModel() is constructed");
     }
     /**
      * @return the value

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/RequestModel.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/RequestModel.java?rev=1413396&r1=1413395&r2=1413396&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/RequestModel.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/disposes/common/RequestModel.java
Sun Nov 25 20:02:38 2012
@@ -18,13 +18,32 @@
  */
 package org.apache.webbeans.newtests.disposes.common;
 
+import javax.annotation.PreDestroy;
+import javax.enterprise.inject.Typed;
 import javax.inject.Inject;
 
-public class RequestModel {
+@Typed
+public class RequestModel
+{
 
-	@Inject @HttpHeader DependentModel disposeModel;
+	private DependentModel disposeModel;
 	
-	public int getID() {
+	public int getID()
+    {
 		return disposeModel.getId();
 	}
+
+    public DependentModel getDisposeModel() {
+        return disposeModel;
+    }
+
+    public void setDisposeModel(DependentModel disposeModel) {
+        this.disposeModel = disposeModel;
+    }
+
+    @PreDestroy
+    public void destroyMe()
+    {
+        System.out.println("RequestModel got destroyed");
+    }
 }



Mime
View raw message