You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2014/08/28 18:27:24 UTC
svn commit: r1621159 - in /tomee/tomee/trunk/container/openejb-core/src:
main/java/org/apache/openejb/assembler/DeployerEjb.java
main/java/org/apache/openejb/testing/ApplicationComposers.java
test/java/org/apache/openejb/assembler/DeployerEjbTest.java
Author: andygumbrecht
Date: Thu Aug 28 16:27:24 2014
New Revision: 1621159
URL: http://svn.apache.org/r1621159
Log:
TOMEE-1338 - DeployerEjb tests
Fix DeployerEjb property override.
Fix potential NP if OpenEjb.destroy is called be user.
Modified:
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java?rev=1621159&r1=1621158&r2=1621159&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/assembler/DeployerEjb.java Thu Aug 28 16:27:24 2014
@@ -273,7 +273,8 @@ public class DeployerEjb implements Depl
}
private void saveIfNeeded(final Properties properties, final File file, final AppInfo appInfo) {
- if (SAVE_DEPLOYMENTS || "true".equalsIgnoreCase(properties.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, "false"))) {
+ if ((SAVE_DEPLOYMENTS && null == properties.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS))
+ || "true".equalsIgnoreCase(properties.getProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, "false"))) {
appInfo.properties.setProperty("save-deployment","true");
saveDeployment(file, true);
}
@@ -402,9 +403,16 @@ public class DeployerEjb implements Depl
}
private void reload(final AppInfo info) {
+
if (info.webAppAlone) {
- SystemInstance.get().getComponent(WebAppDeployer.class).reload(info.path);
- } else {
+ final WebAppDeployer component = SystemInstance.get().getComponent(WebAppDeployer.class);
+
+ if (null != component) {
+ component.reload(info.path);
+ return;
+ }
+ }
+
try {
assembler.destroyApplication(info);
assembler.createApplication(info);
@@ -413,4 +421,3 @@ public class DeployerEjb implements Depl
}
}
}
-}
Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java?rev=1621159&r1=1621158&r2=1621159&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java Thu Aug 28 16:27:24 2014
@@ -880,10 +880,16 @@ public final class ApplicationComposers
// no-op
}
- final Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext();
- for (final String entry : globalJndiEntries) {
- context.unbind(entry);
+ final ContainerSystem component = SystemInstance.get().getComponent(ContainerSystem.class);
+
+ if (null != component) {
+ final Context context = component.getJNDIContext();
+
+ for (final String entry : globalJndiEntries) {
+ context.unbind(entry);
+ }
}
+
globalJndiEntries.clear();
try {
Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java?rev=1621159&r1=1621158&r2=1621159&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java (original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/assembler/DeployerEjbTest.java Thu Aug 28 16:27:24 2014
@@ -1,5 +1,8 @@
package org.apache.openejb.assembler;
+import org.apache.openejb.OpenEJB;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.assembler.classic.AppInfo;
import org.apache.openejb.jee.WebApp;
import org.apache.openejb.junit.ApplicationComposer;
import org.apache.openejb.loader.FileUtils;
@@ -20,6 +23,10 @@ import org.junit.runner.RunWith;
import javax.naming.Context;
import javax.naming.NamingException;
import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
@RunWith(ApplicationComposer.class)
@@ -76,12 +83,17 @@ public class DeployerEjbTest {
@Before
public void before() throws Exception {
+ final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml");
+ if (deployments.exists()) {
+ Files.delete(deployments);
+ }
System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.TRUE.toString());
}
@After
public void after() throws Exception {
System.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString());
+ OpenEJB.destroy();
}
private Deployer getDeployer() throws NamingException {
@@ -97,15 +109,46 @@ public class DeployerEjbTest {
@Test
public void testGetDeployedApps() throws Exception {
+ getAppInfos();
+ }
+
+ private Collection<AppInfo> getAppInfos() throws Exception {
+ final Deployer deployer = getDeployer();
+ Collection<AppInfo> deployedApps = deployer.getDeployedApps();
+
+ if (null == deployedApps) {
+ deployedApps = new ArrayList<AppInfo>();
+ }
+
+ if (deployedApps.size() < 1) {
+ getAppInfo();
+ deployedApps.addAll(deployer.getDeployedApps());
+ }
+ Assert.assertTrue("Found no deployed apps", deployedApps.size() > 0);
+ return deployedApps;
}
@Test
- public void testDeploy() throws Exception {
+ public void testDeployWarSave() throws Exception {
+
+ final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps();
+ Assert.assertTrue("Found more than one app", deployedApps.size() < 2);
final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml");
Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists());
+ getAppInfo();
+
+ Assert.assertTrue("Failed to find: " + deployments.getAbsolutePath(), deployments.exists());
+ }
+
+ private AppInfo getAppInfo() throws IOException, NamingException, OpenEJBException {
+ return getAppInfo(null);
+ }
+
+ private AppInfo getAppInfo(final Properties p) throws IOException, NamingException, OpenEJBException {
+
final Deployer deployer = getDeployer();
final File war = warArchive.get();
@@ -113,28 +156,92 @@ public class DeployerEjbTest {
Assert.fail("War file does not exist: " + war.getAbsolutePath());
}
- deployer.deploy(war.getAbsolutePath());
- Assert.assertTrue("Failed to find: " + deployments.getAbsolutePath(), deployments.exists());
+ return (null != p ? deployer.deploy(war.getAbsolutePath(), p) : deployer.deploy(war.getAbsolutePath()));
}
@Test
- public void testDeploy1() throws Exception {
+ public void testDeployWarNoSave() throws Exception {
+ final Collection<AppInfo> deployedApps = getDeployer().getDeployedApps();
+ Assert.assertTrue("Found more than one app", deployedApps.size() < 2);
+
+ final File deployments = new File(SystemInstance.get().getBase().getDirectory("conf", false), "deployments.xml");
+ if (deployments.exists()) {
+ Files.delete(deployments);
+ }
+
+ Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists());
+ final Properties p = new Properties();
+ p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString());
+ getAppInfo(p);
+
+ Assert.assertFalse("Found existing: " + deployments.getAbsolutePath(), deployments.exists());
}
@Test
- public void testDeploy2() throws Exception {
+ public void testDeployProperties() throws Exception {
+ final Properties p = new Properties();
+ final String path = warArchive.get().getAbsolutePath();
+
+ p.setProperty(Deployer.FILENAME, path);
+ p.setProperty(OPENEJB_DEPLOYER_SAVE_DEPLOYMENTS, Boolean.FALSE.toString());
+ final Deployer deployer = getDeployer();
+ final AppInfo appInfo = deployer.deploy(p);
+ Assert.assertTrue("Paths do not match: " + path + " - " + appInfo.path, path.equals(appInfo.path));
}
@Test
public void testUndeploy() throws Exception {
+ final AppInfo appInfo = getDeployedApp();
+
+ Assert.assertNotNull("Failed to deploy app", appInfo);
+
+ final Deployer deployer = getDeployer();
+ deployer.undeploy(appInfo.path);
+ final Collection<AppInfo> appInfos = getAppInfos();
+ Assert.assertTrue("Failed to undeploy app", appInfos.size() < 2);
+ }
+
+ private AppInfo getDeployedApp() throws Exception {
+ final Collection<AppInfo> appInfos = getAppInfos();
+
+ AppInfo appInfo = null;
+ final File file = warArchive.get();
+
+ if (appInfos.size() < 2) {
+ appInfo = getAppInfo();
+ } else {
+
+ final String name = file.getName().toLowerCase();
+
+ for (final AppInfo info : appInfos) {
+ if (name.contains(info.appId.toLowerCase())) {
+ appInfo = info;
+ }
+ }
+ }
+ return appInfo;
}
@Test
public void testReload() throws Exception {
+ final AppInfo appInfo = getDeployedApp();
+
+ final Deployer deployer = getDeployer();
+ deployer.reload(appInfo.path);
+
+ final Collection<AppInfo> deployedApps = deployer.getDeployedApps();
+ boolean found = false;
+ for (final AppInfo app : deployedApps) {
+ if (app.path.equals(appInfo.path)) {
+ found = true;
+ }
+ }
+
+ Assert.assertTrue("Failed to find app after redeploy", found);
}
public static class TestClass {