deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject [2/2] deltaspike git commit: DELTASPIKE-1130 check session after starting a new request
Date Fri, 22 Apr 2016 09:59:17 GMT
DELTASPIKE-1130 check session after starting a new request


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/83dd59c2
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/83dd59c2
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/83dd59c2

Branch: refs/heads/master
Commit: 83dd59c218ff938e3e0ee861c017b03feae55620
Parents: a330151
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Apr 22 11:21:24 2016 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Apr 22 11:57:54 2016 +0200

----------------------------------------------------------------------
 .../cdise/tck/ContainerCtrlTckTest.java         | 78 ++++++++++++++++++++
 1 file changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/83dd59c2/deltaspike/cdictrl/tck/src/main/java/org/apache/deltaspike/cdise/tck/ContainerCtrlTckTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/cdictrl/tck/src/main/java/org/apache/deltaspike/cdise/tck/ContainerCtrlTckTest.java
b/deltaspike/cdictrl/tck/src/main/java/org/apache/deltaspike/cdise/tck/ContainerCtrlTckTest.java
index 2160f5b..536508b 100644
--- a/deltaspike/cdictrl/tck/src/main/java/org/apache/deltaspike/cdise/tck/ContainerCtrlTckTest.java
+++ b/deltaspike/cdictrl/tck/src/main/java/org/apache/deltaspike/cdise/tck/ContainerCtrlTckTest.java
@@ -271,4 +271,82 @@ public class ContainerCtrlTckTest
 
         cdiContainer.shutdown();
     }
+
+    @Test
+    public void testNewRequests()
+    {
+        CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
+        Assert.assertNotNull(cdiContainer);
+
+        cdiContainer.boot();
+        cdiContainer.getContextControl().startContext(SessionScoped.class);
+        cdiContainer.getContextControl().startContext(RequestScoped.class);
+
+        BeanManager beanManager = cdiContainer.getBeanManager();
+        Assert.assertNotNull(beanManager);
+
+        TestUser testUser = resolveInstance(beanManager, TestUser.class);
+
+        Assert.assertNotNull(testUser);
+        testUser.setName("tester");
+
+
+        CarRepair carRepair = resolveInstance(beanManager, CarRepair.class);
+
+        Assert.assertNotNull(carRepair);
+
+        Car car = carRepair.getCar();
+
+        Assert.assertNotNull(car);
+        Assert.assertNotNull(car.getUser());
+        Assert.assertEquals("tester", car.getUser().getName());
+
+
+        carRepair.getCar().getUser().setName("tck-tester");
+        Assert.assertEquals("tck-tester", testUser.getName());
+
+        cdiContainer.getContextControl().stopContext(RequestScoped.class);
+        cdiContainer.getContextControl().startContext(RequestScoped.class);
+
+        try
+        {
+            testUser = resolveInstance(beanManager, TestUser.class);
+
+            Assert.assertNotNull(testUser);
+            Assert.assertNotNull(testUser.getName());
+            Assert.assertEquals("tck-tester", testUser.getName());
+        }
+        catch (ContextNotActiveException e)
+        {
+            Assert.fail(e.getMessage());
+        }
+
+        try
+        {
+            carRepair = resolveInstance(beanManager, CarRepair.class);
+
+            Assert.assertNotNull(carRepair);
+
+            car = carRepair.getCar();
+
+            Assert.assertNotNull(car);
+            Assert.assertNotNull(car.getUser());
+            Assert.assertNotNull(car.getUser().getName());
+            Assert.assertEquals("tck-tester", car.getUser().getName());
+        }
+        catch (ContextNotActiveException e)
+        {
+            Assert.fail(e.getMessage());
+        }
+
+        cdiContainer.shutdown();
+    }
+
+    private <T> T resolveInstance(BeanManager beanManager, Class<T> beanClass)
+    {
+        Set<Bean<?>> beans = beanManager.getBeans(beanClass);
+        Bean<?> bean = beanManager.resolve(beans);
+
+        return (T) beanManager.getReference(bean, beanClass, beanManager.createCreationalContext(bean));
+    }
 }


Mime
View raw message