openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1562050 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test: component/decorator/clean/ unittests/config/ unittests/decorator/ unittests/dependent/ unittests/inject/
Date Tue, 28 Jan 2014 12:36:05 GMT
Author: struberg
Date: Tue Jan 28 12:36:04 2014
New Revision: 1562050

URL: http://svn.apache.org/r1562050
Log:
OWB-763 move tests to AbstractUnitTest, continued

Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/LargeTransactionDecorator.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/ServiceDecorator.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ClassTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/DecoratorExceptionTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/dependent/DependentComponentTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/CurrentInjectedComponentTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/LargeTransactionDecorator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/LargeTransactionDecorator.java?rev=1562050&r1=1562049&r2=1562050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/LargeTransactionDecorator.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/LargeTransactionDecorator.java
Tue Jan 28 12:36:04 2014
@@ -29,8 +29,8 @@ public class LargeTransactionDecorator i
 {
     @Inject @Delegate Account account;
 
-    BigDecimal depositeAmount = null;
-    BigDecimal withDrawAmount = null;
+    public static BigDecimal depositeAmount = null;
+    public static BigDecimal withDrawAmount = null;
 
     @Override
     public void deposit(BigDecimal amount)

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/ServiceDecorator.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/ServiceDecorator.java?rev=1562050&r1=1562049&r2=1562050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/ServiceDecorator.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/decorator/clean/ServiceDecorator.java
Tue Jan 28 12:36:04 2014
@@ -32,7 +32,7 @@ public  class ServiceDecorator implement
 {
     @Inject @Delegate @Binding1 IService delegate;
 
-    private String delegateAttr = null;
+    public static String delegateAttr = null;
 
     @Override
     public String service()

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ClassTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ClassTest.java?rev=1562050&r1=1562049&r2=1562050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ClassTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/config/ClassTest.java
Tue Jan 28 12:36:04 2014
@@ -25,18 +25,14 @@ import java.util.Map;
 
 import junit.framework.Assert;
 
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.util.ClassUtil;
 import org.junit.Test;
 
-public class ClassTest extends TestContext
+public class ClassTest extends AbstractUnitTest
 {
     public Map<String, ?> map = null;
-    
-    public ClassTest()
-    {
-        super(ClassTest.class.getName());
-    }
+
 
     @Test
     public void testTypeVariableTest()

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java?rev=1562050&r1=1562049&r2=1562050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/Decorator1Test.java
Tue Jan 28 12:36:04 2014
@@ -30,9 +30,8 @@ import javax.enterprise.inject.spi.Decor
 import junit.framework.Assert;
 
 import org.apache.webbeans.annotation.DefaultLiteral;
-import org.apache.webbeans.component.AbstractOwbBean;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.test.annotation.binding.Binding1;
 import org.apache.webbeans.test.annotation.binding.Binding1Literal;
 import org.apache.webbeans.test.component.CheckWithCheckPayment;
 import org.apache.webbeans.test.component.decorator.clean.Account;
@@ -41,42 +40,21 @@ import org.apache.webbeans.test.componen
 import org.apache.webbeans.test.component.decorator.clean.ServiceDecorator;
 import org.apache.webbeans.test.component.service.IService;
 import org.apache.webbeans.test.component.service.ServiceImpl1;
-import org.junit.Before;
 import org.junit.Test;
 
-public class Decorator1Test extends TestContext
+public class Decorator1Test extends AbstractUnitTest
 {
-
-    public Decorator1Test()
-    {
-        super(Decorator1Test.class.getName());
-    }
-
-    @Override
-    @Before
-    public void init()
-    {
-        super.init();
-        
-    }
-
     @Test
     public void test1()
     {
-        clear();
-        
-        initializeDecoratorType(ServiceDecorator.class);
-        initializeDecoratorType(LargeTransactionDecorator.class);        
+        addDecorator(ServiceDecorator.class);
+        addDecorator(LargeTransactionDecorator.class);
         
-        defineDecorator(ServiceDecorator.class);
-        defineManagedBean(CheckWithCheckPayment.class);
-        AbstractOwbBean<ServiceImpl1> component = defineManagedBean(ServiceImpl1.class);
-
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        webBeansContext.getContextFactory().initRequestContext(null);
-        webBeansContext.getContextFactory().initApplicationContext(null);
+        startContainer(ServiceDecorator.class, CheckWithCheckPayment.class, ServiceImpl1.class,
Binding1.class);
 
-        ServiceImpl1 serviceImpl = getManager().getInstance(component);
+        ServiceDecorator.delegateAttr = null;
+
+        ServiceImpl1 serviceImpl = getInstance(ServiceImpl1.class, new Annotation[]{new Binding1Literal()});
         String s = serviceImpl.service();
 
         Assert.assertEquals("ServiceDecorator", s);
@@ -84,25 +62,24 @@ public class Decorator1Test extends Test
         Set<Type> apiTyeps = new HashSet<Type>();
         apiTyeps.add(IService.class);
 
-        List<Decorator<?>> decs = getManager().resolveDecorators(apiTyeps, new
Annotation[] { new Binding1Literal() });
-
-        ServiceDecorator dec = (ServiceDecorator) getManager().getInstance(decs.get(0));
-        Assert.assertEquals(null, dec.getDelegateAttr());
+        List<Decorator<?>> decs = getBeanManager().resolveDecorators(apiTyeps,
new Annotation[]{new Binding1Literal()});
+        Assert.assertNotNull(decs);
+        Assert.assertTrue(decs.size() > 0);
 
+        Assert.assertEquals(ServiceDecorator.delegateAttr, "ServiceImpl1");
     }
 
     @Test
     public void test2()
     {
-        clear();
-        initializeDecoratorType(LargeTransactionDecorator.class);
+        addDecorator(LargeTransactionDecorator.class);
         
-        defineDecorator(LargeTransactionDecorator.class);
-        AbstractOwbBean<AccountComponent> component = defineManagedBean(AccountComponent.class);
+        startContainer(LargeTransactionDecorator.class, AccountComponent.class);
 
-        WebBeansContext.getInstance().getContextFactory().initRequestContext(null);
+        AccountComponent account = getInstance(AccountComponent.class);
 
-        AccountComponent account = getManager().getInstance(component);
+        LargeTransactionDecorator.depositeAmount = null;
+        LargeTransactionDecorator.withDrawAmount = null;
 
         account.deposit(new BigDecimal(1500));
         account.withdraw(new BigDecimal(3000));
@@ -110,11 +87,12 @@ public class Decorator1Test extends Test
         Set<Type> apiTyeps = new HashSet<Type>();
         apiTyeps.add(Account.class);
 
-        List<Decorator<?>> decs = getManager().resolveDecorators(apiTyeps, new
Annotation[] { new DefaultLiteral() });
+        List<Decorator<?>> decs = getBeanManager().resolveDecorators(apiTyeps,
new Annotation[] { DefaultLiteral.INSTANCE });
+        Assert.assertNotNull(decs);
+        Assert.assertTrue(decs.size() > 0);
 
-        LargeTransactionDecorator dec = (LargeTransactionDecorator) getManager().getInstance(decs.get(0));
-        Assert.assertEquals(null, dec.getDepositeAmount());
-        Assert.assertEquals(null, dec.getWithDrawAmount());
+        Assert.assertEquals(1500, LargeTransactionDecorator.depositeAmount.intValue());
+        Assert.assertEquals(3000, LargeTransactionDecorator.withDrawAmount.intValue());
 
     }
 

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/DecoratorExceptionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/DecoratorExceptionTest.java?rev=1562050&r1=1562049&r2=1562050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/DecoratorExceptionTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/decorator/DecoratorExceptionTest.java
Tue Jan 28 12:36:04 2014
@@ -26,7 +26,7 @@ import java.util.Set;
 import junit.framework.Assert;
 
 import org.apache.webbeans.annotation.RequestedScopeLiteral;
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.test.annotation.binding.DummyAnnotationLiteral;
 import org.apache.webbeans.test.component.CheckWithCheckPaymentDecoratorField;
 import org.apache.webbeans.test.component.IPayment;
@@ -34,37 +34,25 @@ import org.apache.webbeans.test.componen
 import org.apache.webbeans.test.component.decorator.broken.DelegateAttributeMustImplementAllDecoratedTypes;
 import org.apache.webbeans.test.component.decorator.broken.MoreThanOneDelegateAttribute;
 import org.apache.webbeans.test.component.decorator.broken.PaymentDecorator;
-import org.junit.Before;
 import org.junit.Test;
 
-public class DecoratorExceptionTest extends TestContext
-{
-    public DecoratorExceptionTest()
-    {
-        super(DecoratorExceptionTest.class.getName());
-    }
-
-    @Override
-    @Before
-    public void init()
-    {
-        super.init();
-    }
-
+import javax.enterprise.inject.spi.DefinitionException;
 
+public class DecoratorExceptionTest extends AbstractUnitTest
+{
     @Test
     public void testDelegateAttributeIsnotInterface()
     {
         try
         {
-            defineDecorator(DelegateAttributeIsnotInterface.class);
+            addDecorator(DelegateAttributeIsnotInterface.class);
+            startContainer();
+            Assert.fail("DefinitionException expected");
         }
-        catch (Exception e)
+        catch (DefinitionException e)
         {
-            System.out.println("got expected exception: " + e.getMessage());
-            return; // all ok!
+            return; // all ok
         }
-        Assert.fail("expecting an exception!");
     }
 
     @Test
@@ -72,14 +60,14 @@ public class DecoratorExceptionTest exte
     {
         try
         {
-            defineDecorator(MoreThanOneDelegateAttribute.class);
+            addDecorator(MoreThanOneDelegateAttribute.class);
+            startContainer();
+            Assert.fail("DefinitionException expected");
         }
-        catch (Exception e)
+        catch (DefinitionException e)
         {
-            System.out.println("got expected exception: " + e.getMessage());
-            return; // all ok!
+            return; // all ok
         }
-        Assert.fail("expecting an exception!");
     }
 
     @Test
@@ -87,15 +75,14 @@ public class DecoratorExceptionTest exte
     {
         try
         {
-            defineDecorator(PaymentDecorator.class);
-            defineManagedBean(CheckWithCheckPaymentDecoratorField.class);
+            addDecorator(PaymentDecorator.class);
+            startContainer(CheckWithCheckPaymentDecoratorField.class);
+            Assert.fail("DefinitionException expected");
         }
-        catch (Exception e)
+        catch (DefinitionException e)
         {
-            System.out.println("got expected exception: " + e.getMessage());
-            return; // all ok!
+            return; // all ok
         }
-        Assert.fail("expecting an exception!");
     }
 
     @Test
@@ -103,14 +90,14 @@ public class DecoratorExceptionTest exte
     {
         try
         {
-            defineDecorator(DelegateAttributeMustImplementAllDecoratedTypes.class);
+            addDecorator(DelegateAttributeMustImplementAllDecoratedTypes.class);
+            startContainer();
+            Assert.fail("DefinitionException expected");
         }
-        catch (Exception e)
+        catch (DefinitionException e)
         {
-            System.out.println("got expected exception: " + e.getMessage());
-            return; // all ok!
+            return; // all ok
         }
-        Assert.fail("expecting an exception!");
     }
 
     @Test
@@ -118,7 +105,7 @@ public class DecoratorExceptionTest exte
     {
         try
         {
-
+            startContainer(IPayment.class);
             Set<Type> api = new HashSet<Type>();
             api.add(IPayment.class);
 
@@ -126,14 +113,13 @@ public class DecoratorExceptionTest exte
             anns[0] = new DummyAnnotationLiteral();
             anns[1] = new DummyAnnotationLiteral();
 
-            getManager().resolveDecorators(api, anns);
+            getBeanManager().resolveDecorators(api, anns);
+            Assert.fail("IllegalArgumentException expected");
         }
-        catch (Exception e)
+        catch (IllegalArgumentException e)
         {
-            System.out.println("got expected exception: " + e.getMessage());
-            return; // all ok!
+            return; // all ok
         }
-        Assert.fail("expecting an exception!");
     }
 
     @Test
@@ -141,21 +127,20 @@ public class DecoratorExceptionTest exte
     {
         try
         {
-
+            startContainer(IPayment.class);
             Set<Type> api = new HashSet<Type>();
             api.add(IPayment.class);
 
             Annotation[] anns = new Annotation[2];
             anns[0] = new RequestedScopeLiteral();
 
-            getManager().resolveDecorators(api, anns);
+            getBeanManager().resolveDecorators(api, anns);
+            Assert.fail("IllegalArgumentException expected");
         }
-        catch (Exception e)
+        catch (IllegalArgumentException e)
         {
-            System.out.println("got expected exception: " + e.getMessage());
-            return; // all ok!
+            return; // all ok
         }
-        Assert.fail("expecting an exception!");
     }
 
     @Test
@@ -163,20 +148,19 @@ public class DecoratorExceptionTest exte
     {
         try
         {
-
+            startContainer();
             Set<Type> api = new HashSet<Type>();
 
             Annotation[] anns = new Annotation[2];
             anns[0] = new DummyAnnotationLiteral();
 
-            getManager().resolveDecorators(api, anns);
+            getBeanManager().resolveDecorators(api, anns);
+            Assert.fail("IllegalArgumentException expected");
         }
-        catch (Exception e)
+        catch (IllegalArgumentException e)
         {
-            System.out.println("got expected exception: " + e.getMessage());
-            return; // all ok!
+            return; // all ok
         }
-        Assert.fail("expecting an exception!");
     }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/dependent/DependentComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/dependent/DependentComponentTest.java?rev=1562050&r1=1562049&r2=1562050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/dependent/DependentComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/dependent/DependentComponentTest.java
Tue Jan 28 12:36:04 2014
@@ -18,73 +18,37 @@
  */
 package org.apache.webbeans.test.unittests.dependent;
 
-import java.util.List;
-
 import junit.framework.Assert;
 
-import org.apache.webbeans.component.AbstractOwbBean;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.test.component.dependent.DependentComponent;
 import org.apache.webbeans.test.component.dependent.DependentOwnerComponent;
 import org.apache.webbeans.test.component.dependent.circular.DependentA;
 import org.apache.webbeans.test.component.dependent.circular.DependentB;
-import org.junit.Before;
 import org.junit.Test;
 
-public class DependentComponentTest extends TestContext
+public class DependentComponentTest extends AbstractUnitTest
 {
-    public DependentComponentTest()
-    {
-        super(DependentComponentTest.class.getName());
-    }
-
-    @Override
-    @Before
-    public void init()
-    {
-        super.init();
-    }
-
     @Test
     public void testDependent()
     {
-        clear();
-        defineManagedBean(DependentComponent.class);
-        defineManagedBean(DependentOwnerComponent.class);
+        startContainer(DependentComponent.class, DependentOwnerComponent.class);
 
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        webBeansContext.getContextFactory().initRequestContext(null);
-
-        List<AbstractOwbBean<?>> comps = getComponents();
-
-        Assert.assertEquals(2, comps.size());
-
-        DependentOwnerComponent comp = (DependentOwnerComponent) getManager().getInstance(comps.get(1));
+        DependentOwnerComponent comp = getInstance(DependentOwnerComponent.class);
 
         DependentComponent dc = comp.getDependent();
 
         Assert.assertNotNull(dc);
-
-        webBeansContext.getContextFactory().destroyRequestContext(null);
     }
 
     @Test
     public void testDependentCircular()
     {
-        clear();
-
-        WebBeansContext.getInstance().getContextFactory().initRequestContext(null);
+        startContainer(DependentA.class, DependentB.class);
 
-        AbstractOwbBean<DependentA> componentA = defineManagedBean(DependentA.class);
-        AbstractOwbBean<DependentB> componentB = defineManagedBean(DependentB.class);
-        
-        Assert.assertNotNull(componentB);
-        
-        DependentA dependentA = getManager().getInstance(componentA);
+        DependentA dependentA = getInstance(DependentA.class);
         Assert.assertNotNull(dependentA);
         Assert.assertNotNull(dependentA.getDependentB());
-
     }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/CurrentInjectedComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/CurrentInjectedComponentTest.java?rev=1562050&r1=1562049&r2=1562050&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/CurrentInjectedComponentTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/inject/CurrentInjectedComponentTest.java
Tue Jan 28 12:36:04 2014
@@ -18,65 +18,31 @@
  */
 package org.apache.webbeans.test.unittests.inject;
 
-import java.util.List;
 
 import junit.framework.Assert;
 
-import org.apache.webbeans.component.AbstractOwbBean;
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.ContextFactory;
-import org.apache.webbeans.test.TestContext;
+import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.test.component.ContaintsCurrentComponent;
 import org.apache.webbeans.test.component.CurrentBindingComponent;
 import org.apache.webbeans.test.component.service.ITyped2;
 import org.apache.webbeans.test.component.service.Typed2;
-import org.junit.Before;
 import org.junit.Test;
 
-public class CurrentInjectedComponentTest extends TestContext
+public class CurrentInjectedComponentTest extends AbstractUnitTest
 {
-    public CurrentInjectedComponentTest()
-    {
-        super(CurrentInjectedComponentTest.class.getSimpleName());
-    }
-
-    @Override
-    @Before
-    public void init()
-    {
-        super.init();
-    }
 
     @SuppressWarnings("unchecked")
     @Test
     public void testTypedComponent() throws Throwable
     {
-        clear();
-
-        defineManagedBean(Typed2.class);
-        defineManagedBean(CurrentBindingComponent.class);
-        defineManagedBean(ContaintsCurrentComponent.class);
-        List<AbstractOwbBean<?>> comps = getComponents();
+        startContainer(Typed2.class, CurrentBindingComponent.class, ContaintsCurrentComponent.class);
 
-        Object session = getSession();
-        ContextFactory contextFactory = WebBeansContext.getInstance().getContextFactory();
-        contextFactory.initRequestContext(null);
-        contextFactory.initSessionContext(session);
 
-        Assert.assertEquals(3, comps.size());
-
-        getManager().getInstance(comps.get(0));
-        getManager().getInstance(comps.get(1));
-
-        Object object = getManager().getInstance(comps.get(2));
-
-        Assert.assertTrue(object instanceof ContaintsCurrentComponent);
-
-        ContaintsCurrentComponent i = (ContaintsCurrentComponent) object;
+        ContaintsCurrentComponent i = getInstance(ContaintsCurrentComponent.class);
 
         Assert.assertTrue(i.getInstance() instanceof CurrentBindingComponent);
 
-        Object obj2 = getManager().getInstance(comps.get(1));
+        Object obj2 = getInstance(CurrentBindingComponent.class);
 
         Assert.assertSame(i.getInstance().getTyped2(), ((CurrentBindingComponent) obj2).getTyped2());
 
@@ -84,9 +50,6 @@ public class CurrentInjectedComponentTes
         ITyped2 typed2 = bc.getTyped2();
 
         Assert.assertNotNull(typed2);
-
-        contextFactory.destroyRequestContext(null);
-        contextFactory.destroySessionContext(session);
     }
 
 }



Mime
View raw message