tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [5/9] tomee git commit: Applying Romain's test format
Date Wed, 02 Aug 2017 23:06:16 GMT
Applying Romain's test format


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

Branch: refs/heads/master
Commit: cf1295be75a2c109ec55407537fd742e02c55ac5
Parents: 7baf260
Author: Jonathan Gallimore <jon@jrg.me.uk>
Authored: Wed Jul 19 15:47:50 2017 +0100
Committer: Jonathan Gallimore <jon@jrg.me.uk>
Committed: Wed Jul 19 15:47:50 2017 +0100

----------------------------------------------------------------------
 .../ApplicationResourceLifecycleTest.java       | 103 ++++++++-----------
 1 file changed, 44 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/cf1295be/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
index 1b44277..48c0c6b 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/assembler/classic/ApplicationResourceLifecycleTest.java
@@ -16,84 +16,69 @@
  */
 package org.apache.openejb.assembler.classic;
 
-import org.apache.openejb.OpenEJB;
-import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.config.AppModule;
-import org.apache.openejb.config.ConfigurationFactory;
-import org.apache.openejb.config.EjbModule;
-import org.apache.openejb.core.LocalInitialContextFactory;
-import org.apache.openejb.jee.EjbJar;
-import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.config.sys.Resources;
+import org.apache.openejb.testing.ApplicationComposers;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testing.SimpleLog;
 import org.junit.Test;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.io.IOException;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicBoolean;
+import javax.annotation.Resource;
 
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+@Classes
+@SimpleLog
 public class ApplicationResourceLifecycleTest {
-
-    private static final AtomicBoolean POST_CONSTRUCT = new AtomicBoolean(false);
-    private static final AtomicBoolean PRE_DESTROY = new AtomicBoolean(false);
-
+    @Resource(name = "test")
+    private MyResource resource;
+
+    @Module
+    public Resources resources() {
+        return new Resources() {{
+            getResource().add(new org.apache.openejb.config.sys.Resource() {{
+                setId("test");
+                setClassName(MyResource.class.getName());
+            }});
+        }};
+    }
 
     @Test
-    public void test() throws OpenEJBException, NamingException, IOException {
-        final ConfigurationFactory config = new ConfigurationFactory();
-        final Assembler assembler = new Assembler();
-
-        assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
-        assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
-
-        final AppModule app = new AppModule(ApplicationResourceLifecycleTest.class.getClassLoader(),
ApplicationResourceLifecycleTest.class.getSimpleName());
-
-        final EjbJar ejbJar = new EjbJar();
-        ejbJar.addEnterpriseBean(new SingletonBean(ApplicationResource.class));
-        app.getEjbModules().add(new EjbModule(ejbJar));
-        app.getEjbModules().iterator().next().getAltDDs().put("resources.xml", getClass().getClassLoader().getResource("app-resources.xml"));
-
-        assembler.createApplication(config.configureApplication(app));
-
-        final Properties properties = new Properties();
-        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
-        properties.setProperty("openejb.embedded.initialcontext.close", "destroy");
-
-        // some hack to be sure to call destroy()
-        InitialContext context = new InitialContext(properties);
-        assertNotNull(context);
-
-        assertTrue(POST_CONSTRUCT.getAndSet(false));
-        assertFalse(PRE_DESTROY.get());
-
-        ApplicationResource bean = (ApplicationResource) context.lookup("ApplicationResourceLocalBean");
-
-        assertNotNull(bean);
-        context.close();
-
-        OpenEJB.destroy();
-        assertFalse(POST_CONSTRUCT.get());
-        assertTrue(PRE_DESTROY.get());
+    public void lifecycle() throws Exception {
+        new ApplicationComposers(this).evaluate(this, new Runnable() {
+            @Override
+            public void run() {
+                assertTrue(resource.init);
+                assertFalse(resource.destroy);
+            }
+        });
+        assertTrue(resource.init);
+        assertTrue(resource.destroy);
     }
 
-    public static class ApplicationResource {
+    public static class MyResource {
+        private boolean init;
+        private boolean destroy;
 
         @PostConstruct
-        public void start() {
-            POST_CONSTRUCT.set(true);
+        private void init() {
+            init = true;
         }
 
         @PreDestroy
-        public void stop() {
-            PRE_DESTROY.set(true);
+        private void destroy() {
+            destroy = true;
+        }
+
+        public boolean isInit() {
+            return init;
         }
 
+        public boolean isDestroy() {
+            return destroy;
+        }
     }
 }


Mime
View raw message