Package org.jboss.arquillian.core.test.context

Examples of org.jboss.arquillian.core.test.context.ManagerTestContextImpl


public class ContextActivationTestCase
{
   @Test
   public void shouldBeAbleToReceiveObjectAfterReActivation()
   {
      ManagerTestContext context = new ManagerTestContextImpl();

      try
      {
         Assert.assertFalse(context.isActive());

         context.activate();
         Assert.assertTrue(context.isActive());

         ObjectStore store = context.getObjectStore();
         store.add(Boolean.class, true);

         Assert.assertEquals(
               "Verify that we can get objects from a active context",
               new Boolean(true),
               store.get(Boolean.class));

         context.deactivate();
         Assert.assertFalse(context.isActive());

         try
         {
            context.getObjectStore();
            Assert.fail("Trying to get ObjectStore outside active context should have thrown Exception");
         }
         catch (Exception e) {
         }

         context.activate();
         store = context.getObjectStore();

         Assert.assertEquals(
               "Verify that we can get objects from a active context",
               new Boolean(true),
               store.get(Boolean.class));
      }
      finally
      {
         context.deactivate();
         context.destroy();
      }

   }
View Full Code Here


   }
   @Test
   public void shouldBeAbleToReadFromChildThread() throws Exception
   {
      final Cacther catcher = new Cacther();
      final ManagerTestContext context = new ManagerTestContextImpl();
      final CountDownLatch setupLatch = new CountDownLatch(1);
      final CountDownLatch checkLatch = new CountDownLatch(1);
      Thread setup = new Thread()
      {
         public void run()
         {
            context.activate();
            context.getObjectStore().add(Object.class, new Object());

            setupLatch.countDown();

            Thread check = new Thread()
            {
               public void run()
               {
                  Assert.assertTrue("Context should be active on a sub thread", context.isActive());

                  checkLatch.countDown();
               };
            };
            check.setUncaughtExceptionHandler(catcher);
            check.start();
            try
            {
               if(!checkLatch.await(1, TimeUnit.SECONDS))
               {
                  Assert.fail("Check Thread never called?");
               }
            }
            catch (Exception e)
            {
               throw new RuntimeException(e);
            }
            finally
            {
               context.deactivate();
               context.destroy();
            }
         };
      };
      setup.setUncaughtExceptionHandler(catcher);
      setup.start();
View Full Code Here

   @Test
   public void shouldNotBeAbleToReadFromDifferentThread() throws Exception
   {
      final Cacther catcher = new Cacther();
      final ManagerTestContext context = new ManagerTestContextImpl();
      final CountDownLatch setupLatch = new CountDownLatch(1);
      final CountDownLatch checkLatch = new CountDownLatch(1);
      Thread setup = new Thread()
      {
         public void run()
         {
            context.activate();
            context.getObjectStore().add(Object.class, new Object());

            setupLatch.countDown();

            try
            {
               if(!checkLatch.await(1, TimeUnit.SECONDS))
               {
                  Assert.fail("Check Thread never called?");
               }
            }
            catch (Exception e)
            {
               throw new RuntimeException(e);
            }
            finally
            {
               context.deactivate();
               context.destroy();
            }
         };
      };
      setup.setUncaughtExceptionHandler(catcher);
      Thread check = new Thread()
      {
         public void run()
         {
            Assert.assertFalse("Context should not be active on a different Thread", context.isActive());

            checkLatch.countDown();
         };
      };
      check.setUncaughtExceptionHandler(catcher);
View Full Code Here

public class ContextActivationTestCase
{
   @Test
   public void shouldBeAbleToReceiveObjectAfterReActivation()
   {
      ManagerTestContext context = new ManagerTestContextImpl();

      try
      {
         Assert.assertFalse(context.isActive());
        
         context.activate();
         Assert.assertTrue(context.isActive());
        
         ObjectStore store = context.getObjectStore();
         store.add(Boolean.class, true);
        
         Assert.assertEquals(
               "Verify that we can get objects from a active context",
               new Boolean(true),
               store.get(Boolean.class));
        
         context.deactivate();
         Assert.assertFalse(context.isActive());
        
         try
         {
            context.getObjectStore();
            Assert.fail("Trying to get ObjectStore outside active context should have thrown Exception");
         }
         catch (Exception e) {
         }
  
         context.activate();
         store = context.getObjectStore();
  
         Assert.assertEquals(
               "Verify that we can get objects from a active context",
               new Boolean(true),
               store.get(Boolean.class));
      }
      finally
      {
         context.deactivate();
         context.destroy();
      }
     
   }
View Full Code Here

  
   @Test
   public void shouldNotBeAbleToReadFromDifferentThread() throws Exception
   {
      final CountDownLatch latch = new CountDownLatch(1);
      final ManagerTestContext context = new ManagerTestContextImpl();
      try
      {
         context.activate();
         context.getObjectStore().add(Object.class, new Object());
        
         Thread thread = new Thread()
         {
            public void run()
            {
               Assert.assertFalse(context.isActive());
              
               latch.countDown();
            };
         };
         thread.start();
        
         if(!latch.await(1, TimeUnit.SECONDS))
         {
            Assert.fail("Thread never called?");
         }
      }
      finally
      {
         context.deactivate();
         context.destroy();
      }
   }
View Full Code Here

TOP

Related Classes of org.jboss.arquillian.core.test.context.ManagerTestContextImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.