Author: andygumbrecht
Date: Thu Aug 28 14:27:29 2014
New Revision: 1621140

URL: http://svn.apache.org/r1621140
Log:
TOMEE-1338 - Initial work on test for WAR save. In progress.

Added:
    
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java
Modified:
    
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java
    
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java

Modified: 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java?rev=1621140&r1=1621139&r2=1621140&view=diff
==============================================================================
--- 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java
 (original)
+++ 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/Deployer.java
 Thu Aug 28 14:27:29 2014
@@ -25,12 +25,18 @@ import org.apache.openejb.assembler.clas
 import java.util.Collection;
 import java.util.Properties;
 
-// The signature of this intf must never change without caution
+// The signature of this interface must never change without caution
 // it is used in many tools either internal or external (intellij idea)
 public interface Deployer {
     String FILENAME = "filename";
     String ALT_DD = "altDD";
 
+    /**
+     * Returns a unique file per runtime. Clients can test for the existence 
of this file
+     * to determine if the deployer is on the local machine.
+     *
+     * @return String - The canonical pathname
+     */
     String getUniqueFile();
 
     Collection<AppInfo> getDeployedApps();

Modified: 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java?rev=1621140&r1=1621139&r2=1621140&view=diff
==============================================================================
--- 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
 (original)
+++ 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
 Thu Aug 28 14:27:29 2014
@@ -106,7 +106,7 @@ public class DeployerEjb implements Depl
                     throw new OpenEJBRuntimeException(e);
                 }
             } else {
-                throw new OpenEJBRuntimeException("can't create unique file, 
please set java.io.tmpdir to a writable folder or create work folder", e);
+                throw new OpenEJBRuntimeException("cannot create unique file, 
please set java.io.tmpdir to a writable folder or create work folder", e);
             }
         }
         uniqueFile = unique;
@@ -272,14 +272,14 @@ public class DeployerEjb implements Depl
         }
     }
 
-    private void saveIfNeeded(Properties properties, File file, AppInfo 
appInfo) {
+    private void saveIfNeeded(final Properties properties, final File file, 
final AppInfo appInfo) {
         if (SAVE_DEPLOYMENTS || 
"true".equalsIgnoreCase(properties.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS,
 "false"))) {
             appInfo.properties.setProperty("save-deployment", "true");
             saveDeployment(file, true);
         }
     }
 
-    private static File copyBinaries(final Properties props) throws 
OpenEJBException {
+    private synchronized File copyBinaries(final Properties props) throws 
OpenEJBException {
         final File dump = 
ProvisioningUtil.cacheFile(props.getProperty(OPENEJB_PATH_BINARIES, 
"dump.war"));
         if (dump.exists()) {
             Files.delete(dump);
@@ -314,7 +314,7 @@ public class DeployerEjb implements Depl
             config = null;
         }
         if (config == null || !config.getParentFile().exists()) {
-            LOGGER.info("can't save the added app because the conf folder 
doesn't exist, it will not be present next time you'll start");
+            LOGGER.info("Cannot save the added app because the conf folder 
does not exist, it will not be present on a restart");
             return;
         }
 
@@ -359,7 +359,7 @@ public class DeployerEjb implements Depl
             os = IO.write(config);
             JaxbOpenejb.marshal(AdditionalDeployments.class, 
additionalDeployments, os);
         } catch (final Exception e) {
-            LOGGER.error("can't save the added app, will not be present next 
time you'll start", e);
+            LOGGER.error("cannot save the added app, will not be present next 
time you'll start", e);
         } finally {
             IO.close(os);
         }

Added: 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java
URL: 
http://svn.apache.org/viewvc/tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java?rev=1621140&view=auto
==============================================================================
--- 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java
 (added)
+++ 
tomee/tomee/branches/tomee-1.7.x/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java
 Thu Aug 28 14:27:29 2014
@@ -0,0 +1,144 @@
+package org.apache.openejb.assembler;
+
+import org.apache.openejb.jee.WebApp;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.loader.FileUtils;
+import org.apache.openejb.loader.Files;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.testing.AppResource;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.util.WebArchives;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import java.io.File;
+import java.util.concurrent.atomic.AtomicReference;
+
+@RunWith(ApplicationComposer.class)
+public class DeployerEjbTest {
+
+    private static final AtomicReference<String> property = new 
AtomicReference<String>(null);
+    private static final AtomicReference<File> warArchive = new 
AtomicReference<File>(null);
+    private static final String OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS = 
"openejb.deployer.save-deployments";
+
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+
+        final FileUtils base = SystemInstance.get().getBase();
+        final File conf = base.getDirectory("conf", false);
+        Files.delete(conf);
+
+        final File apps = base.getDirectory("apps", true);
+        Files.delete(apps);
+
+        base.getDirectory("apps", true);
+        base.getDirectory("conf", true);
+
+        property.set(System.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS));
+        System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, 
Boolean.TRUE.toString());
+        warArchive.set(WebArchives.warArchive(TestClass.class));
+    }
+
+    @AfterClass
+    public static void afterClass() {
+
+        final String s = property.get();
+        if (null != s) {
+            System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, "true");
+        } else {
+            System.clearProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS);
+        }
+
+        final File file = warArchive.get();
+        if (file != null && file.exists()) {
+            if (!file.delete()) {
+                file.deleteOnExit();
+            }
+        }
+    }
+
+    @Module
+    @Classes(value = {DeployerEjb.class})
+    public WebApp war() {
+        return new WebApp().contextRoot("/initial");
+    }
+
+    @AppResource
+    private Context context;
+
+    @Before
+    public void before() throws Exception {
+        System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, 
Boolean.TRUE.toString());
+    }
+
+    @After
+    public void after() throws Exception {
+        System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, 
Boolean.FALSE.toString());
+    }
+
+    private Deployer getDeployer() throws NamingException {
+        return (Deployer) context.lookup("openejb/DeployerRemote");
+    }
+
+    @Test
+    public void testGetUniqueFile() throws Exception {
+
+        final String uniqueFile = getDeployer().getUniqueFile();
+        Assert.assertTrue(new File(uniqueFile).exists());
+    }
+
+    @Test
+    public void testGetDeployedApps() throws Exception {
+
+    }
+
+    @Test
+    public void testDeploy() throws Exception {
+
+        final File deployments = new 
File(SystemInstance.get().getBase().getDirectory("conf", false), 
"deployments.xml");
+        Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), 
deployments.exists());
+
+        final Deployer deployer = getDeployer();
+
+        final File war = warArchive.get();
+        if (!war.exists()) {
+            Assert.fail("War file does not exist: " + war.getAbsolutePath());
+        }
+
+        deployer.deploy(war.getAbsolutePath());
+        Assert.assertTrue("Failed to find: " + deployments.getAbsolutePath(), 
deployments.exists());
+    }
+
+    @Test
+    public void testDeploy1() throws Exception {
+
+    }
+
+    @Test
+    public void testDeploy2() throws Exception {
+
+    }
+
+    @Test
+    public void testUndeploy() throws Exception {
+
+    }
+
+    @Test
+    public void testReload() throws Exception {
+
+    }
+
+    public static class TestClass {
+        public TestClass() {
+        }
+    }
+}
\ No newline at end of file


Reply via email to