From 0d91b12a6d71c28a7121fc4ff6b91af074334744 Mon Sep 17 00:00:00 2001 From: Josef Cacek Date: Wed, 8 Mar 2017 18:28:32 +0100 Subject: [PATCH] [WFLY-8331] improve logic of deployment overlay tests --- ...tils.java => AbstractOverlayTestBase.java} | 72 +++++++++++++++---- .../ear/OverlayExistingResourceTestCase.java | 56 ++++++++------- .../OverlayNonExistingResourceTestCase.java | 56 ++++++++------- .../jar/JarOverlayTestBase.java | 21 +----- .../jar/OverlayExistingResourceTestCase.java | 29 +++++--- .../OverlayNonExistingResourceTestCase.java | 12 +++- .../war/OverlayExistingResourceTestCase.java | 49 +++++++------ .../OverlayNonExistingResourceTestCase.java | 16 +++-- 8 files changed, 185 insertions(+), 126 deletions(-) rename testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/{jar/OverlayUtils.java => AbstractOverlayTestBase.java} (65%) diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayUtils.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/AbstractOverlayTestBase.java similarity index 65% rename from testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayUtils.java rename to testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/AbstractOverlayTestBase.java index c4e506a3f72a..acd34e6b9fd4 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayUtils.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/AbstractOverlayTestBase.java @@ -20,32 +20,59 @@ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.as.test.integration.deployment.deploymentoverlay.jar; +package org.jboss.as.test.integration.deployment.deploymentoverlay; import java.io.IOException; +import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.jboss.arquillian.container.test.api.Deployer; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ServerSetup; import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.util.MgmtOperationException; +import org.jboss.as.test.integration.security.common.SecurityTraceLoggingServerSetupTask; +import org.jboss.as.test.shared.util.AssumeTestGroupUtil; import org.jboss.dmr.ModelNode; +import org.jboss.logging.Logger; +import org.junit.BeforeClass; /** * @author baranowb * @author lgao */ -public final class OverlayUtils { +@ServerSetup(AbstractOverlayTestBase.TraceLoggingSetup.class) +public abstract class AbstractOverlayTestBase { - public static void setupOverlay(final ManagementClient managementClient, final String deployment, final String overlayName, final Map overlay) throws Exception { + protected static final Logger LOGGER = Logger.getLogger(AbstractOverlayTestBase.class); + + @ArquillianResource + protected ManagementClient managementClient; + + @ArquillianResource + protected Deployer deployer; + + @BeforeClass + public static void beforeClass() { + AssumeTestGroupUtil.assumeElytronProfileTestsEnabled(); + } + + private boolean removeOverlay = false; + + public void setupOverlay(final String deployment, final String overlayName, final Map overlay) + throws Exception { // create overlay ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); + removeOverlay=true; for (Map.Entry overlayItem : overlay.entrySet()) { // add content @@ -84,27 +111,33 @@ public static void setupOverlay(final ManagementClient managementClient, final S ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } - public static void setupOverlay(final ManagementClient managementClient, final String deployment, final String overlayName, final String overlayPath, final String overlayedContent) throws Exception { - setupOverlay(managementClient, deployment, overlayName, Collections.singletonMap(overlayPath, overlayedContent)); + public void setupOverlay(final String deployment, final String overlayName, final String overlayPath, + final String overlayedContent) throws Exception { + setupOverlay(deployment, overlayName, Collections.singletonMap(overlayPath, overlayedContent)); } - public static void removeOverlay(final ManagementClient managementClient, final String deployment, final String overlayName, final Set overlayPaths) throws Exception { + public void removeOverlay(final String deployment, final String overlayName, final Set overlayPaths) + throws Exception { + if (!removeOverlay) { + return; + } for (String overlayPath : overlayPaths) { - removeContentItem(managementClient, overlayName, overlayPath); + removeContentItem(overlayName, overlayPath); } - removeDeploymentItem(managementClient, overlayName, deployment); + removeDeploymentItem(overlayName, deployment); ModelNode op = new ModelNode(); op.get(ModelDescriptionConstants.OP_ADDR).set(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE); ManagementOperations.executeOperation(managementClient.getControllerClient(), op); + removeOverlay = false; } - public static void removeOverlay(final ManagementClient managementClient, final String deployment, final String overlayName, final String overlayPath) throws Exception { - removeOverlay(managementClient, deployment, overlayName, Collections.singleton(overlayPath)); + public void removeOverlay(final String deployment, final String overlayName, final String overlayPath) throws Exception { + removeOverlay(deployment, overlayName, Collections.singleton(overlayPath)); } - protected static void removeContentItem(final ManagementClient managementClient, final String w, final String a) throws IOException, MgmtOperationException { + protected void removeContentItem(final String w, final String a) throws IOException, MgmtOperationException { final ModelNode op; final ModelNode addr; op = new ModelNode(); @@ -116,8 +149,7 @@ protected static void removeContentItem(final ManagementClient managementClient, ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } - - protected static void removeDeploymentItem(final ManagementClient managementClient, final String w, final String a) throws IOException, MgmtOperationException { + protected void removeDeploymentItem(final String w, final String a) throws IOException, MgmtOperationException { final ModelNode op; final ModelNode addr; op = new ModelNode(); @@ -129,4 +161,18 @@ protected static void removeDeploymentItem(final ManagementClient managementClie ManagementOperations.executeOperation(managementClient.getControllerClient(), op); } + public static class TraceLoggingSetup extends SecurityTraceLoggingServerSetupTask { + + @Override + protected Collection getCategories(ManagementClient managementClient, String containerId) { + Set coll = new HashSet<>(super.getCategories(managementClient, containerId)); + coll.add("org.jboss.sasl"); + coll.add("org.jboss.as.ejb3"); + coll.add("org.jboss.as.remoting"); + coll.add("org.jboss.remoting3"); + coll.add("org.jboss.remoting"); + coll.add("org.jboss.naming.remote"); + return coll; + } + } } diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayExistingResourceTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayExistingResourceTestCase.java index 7e030c24ee43..2b4ae2abb3df 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayExistingResourceTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayExistingResourceTestCase.java @@ -31,7 +31,6 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; -import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayUtils; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; @@ -56,7 +55,7 @@ public class OverlayExistingResourceTestCase extends EarOverlayTestBase { private static final String RESOURCE = "/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) - public static Archive createDeployment() throws Exception { + public static Archive createDeployment() throws Exception { return createEARWithOverlayedArchive(true, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @@ -65,39 +64,44 @@ public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); Map overlay = new HashMap(); try{ - OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding(DEPLOYMENT_SHELL, DEPLOYMENT_OVERLAYED, "", - OverlayEJB.class, OverlayableInterface.class)); - Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); - Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding(DEPLOYMENT_SHELL, DEPLOYMENT_OVERLAYED, "", + OverlayEJB.class, OverlayableInterface.class)); + Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); + Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - Assert.assertEquals("HTML resource in ear/war does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); - Assert.assertEquals("HTML Static in ear/war resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); + Assert.assertEquals("HTML resource in ear/war does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); + Assert.assertEquals("HTML Static in ear/war resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); - Assert.assertEquals("Static resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + WEB + "/echoStatic")); - Assert.assertEquals("Resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, - readContent(managementClient.getWebUri() + "/" + WEB + "/echoOverlay")); + Assert.assertEquals("Static resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + WEB + "/echoStatic")); + Assert.assertEquals("Resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, + readContent(managementClient.getWebUri() + "/" + WEB + "/echoOverlay")); - overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); - overlay.put(WEB_OVERLAY, OverlayableInterface.OVERLAYED); - OverlayUtils.setupOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); + overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); + overlay.put(WEB_OVERLAY, OverlayableInterface.OVERLAYED); + setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); - Assert.assertEquals("Overlayed resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); - Assert.assertEquals("Static resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + Assert.assertEquals("Overlayed resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); + Assert.assertEquals("Static resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - Assert.assertEquals("HTML static resource in ear/war does not match post-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); - Assert.assertEquals("HTML resource in ear/war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); + Assert.assertEquals("HTML static resource in ear/war does not match post-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); + Assert.assertEquals("HTML resource in ear/war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); } finally { - try{ + try { ctx.close(); - }catch(Exception e){ + } catch (Exception e) { + LOGGER.error("Closing context failed", e); + } + try { + removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); + } catch (Exception e) { + LOGGER.error("Removing overlay failed", e); } - OverlayUtils.removeOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } } } diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayNonExistingResourceTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayNonExistingResourceTestCase.java index 9ac697b81dfe..2c57382d2c10 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayNonExistingResourceTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/ear/OverlayNonExistingResourceTestCase.java @@ -31,7 +31,6 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; -import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayUtils; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; @@ -56,7 +55,7 @@ public class OverlayNonExistingResourceTestCase extends EarOverlayTestBase { private static final String RESOURCE = "/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) - public static Archive createDeployment() throws Exception { + public static Archive createDeployment() throws Exception { return createEARWithOverlayedArchive(false, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @@ -65,39 +64,44 @@ public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); Map overlay = new HashMap(); try{ - OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding(DEPLOYMENT_SHELL, DEPLOYMENT_OVERLAYED, "", - OverlayEJB.class, OverlayableInterface.class)); - Assert.assertEquals("Overlayed resource in ear/jar does not match pre-overlay expectations!", null, iface.fetchResource()); - Assert.assertEquals("Static resource in ear/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding(DEPLOYMENT_SHELL, DEPLOYMENT_OVERLAYED, "", + OverlayEJB.class, OverlayableInterface.class)); + Assert.assertEquals("Overlayed resource in ear/jar does not match pre-overlay expectations!", null, iface.fetchResource()); + Assert.assertEquals("Static resource in ear/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - Assert.assertEquals("HTML resource in ear/war does not match pre-overlay expectations!", null, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); - Assert.assertEquals("HTML Static resource in ear/war does not match pre-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); + Assert.assertEquals("HTML resource in ear/war does not match pre-overlay expectations!", null, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); + Assert.assertEquals("HTML Static resource in ear/war does not match pre-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); - Assert.assertEquals("Static resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + WEB + "/echoStatic")); - Assert.assertEquals("Resource in ear/war/jar does not match pre-overlay expectations!", null, - readContent(managementClient.getWebUri() + "/" + WEB + "/echoOverlay")); + Assert.assertEquals("Static resource in ear/war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + WEB + "/echoStatic")); + Assert.assertEquals("Resource in ear/war/jar does not match pre-overlay expectations!", null, + readContent(managementClient.getWebUri() + "/" + WEB + "/echoOverlay")); - overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); - overlay.put(WEB_OVERLAY, OverlayableInterface.OVERLAYED); - OverlayUtils.setupOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); + overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); + overlay.put(WEB_OVERLAY, OverlayableInterface.OVERLAYED); + setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); - Assert.assertEquals("Overlayed resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); - Assert.assertEquals("Static resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + Assert.assertEquals("Overlayed resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); + Assert.assertEquals("Static resource in ear/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - Assert.assertEquals("HTML static resource in ear/war does not match post-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); - Assert.assertEquals("HTML resource in ear/war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, - readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); + Assert.assertEquals("HTML static resource in ear/war does not match post-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + STATIC_HTML)); + Assert.assertEquals("HTML resource in ear/war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, + readContent(managementClient.getWebUri() + "/" + WEB + "/" + OVERLAY_HTML)); } finally { - try{ + try { ctx.close(); - }catch(Exception e){ + } catch (Exception e) { + LOGGER.error("Closing context failed", e); + } + try { + removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); + } catch (Exception e) { + LOGGER.error("Removing overlay failed", e); } - OverlayUtils.removeOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } } } diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/JarOverlayTestBase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/JarOverlayTestBase.java index 2f2bc1207068..2e599915afc6 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/JarOverlayTestBase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/JarOverlayTestBase.java @@ -28,33 +28,18 @@ import javax.naming.InitialContext; import javax.naming.NamingException; -import org.jboss.arquillian.container.test.api.Deployer; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.jboss.as.arquillian.container.ManagementClient; +import org.jboss.as.test.integration.deployment.deploymentoverlay.AbstractOverlayTestBase; import org.jboss.as.test.shared.TestSuiteEnvironment; -import org.jboss.as.test.shared.util.AssumeTestGroupUtil; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.BeforeClass; /** * @author baranowb * */ -public class JarOverlayTestBase { - - @ArquillianResource - protected ManagementClient managementClient; - - @ArquillianResource - protected Deployer deployer; - - @BeforeClass - public static void beforeClass() { - AssumeTestGroupUtil.assumeElytronProfileTestsEnabled(); - } +public class JarOverlayTestBase extends AbstractOverlayTestBase { public static Archive createOverlayedArchive(final boolean resourcePresent, final String deploymentOverlayedArchive){ final JavaArchive jar = ShrinkWrap.create(JavaArchive.class, deploymentOverlayedArchive); @@ -68,7 +53,7 @@ public static Archive createOverlayedArchive(final boolean resourcePresent, f } protected static InitialContext getInitialContext() throws NamingException { - final Hashtable env = new Hashtable(); + final Hashtable env = new Hashtable<>(); env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName()); env.put(Context.PROVIDER_URL, "remote+http://" + TestSuiteEnvironment.getServerAddress() + ":" + 8080); diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayExistingResourceTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayExistingResourceTestCase.java index 697073dacba4..95eea534dbc3 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayExistingResourceTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayExistingResourceTestCase.java @@ -39,12 +39,13 @@ @RunWith(Arquillian.class) @RunAsClient public class OverlayExistingResourceTestCase extends JarOverlayTestBase { + private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; @Deployment(name = DEPLOYMENT_OVERLAYED) - public static Archive createDeployment() throws Exception { + public static Archive createDeployment() throws Exception { return createOverlayedArchive(true, DEPLOYMENT_OVERLAYED_ARCHIVE); } @@ -52,19 +53,25 @@ public static Archive createDeployment() throws Exception { public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); try{ - OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_OVERLAYED, "", - OverlayEJB.class, OverlayableInterface.class)); - Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); - Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - OverlayUtils.setupOverlay(managementClient, DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE, OverlayableInterface.OVERLAYED); - Assert.assertEquals("Overlayed resource does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); - Assert.assertEquals("Static resource does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_OVERLAYED, "", + OverlayEJB.class, OverlayableInterface.class)); + Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); + Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + setupOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE, OverlayableInterface.OVERLAYED); + Assert.assertEquals("Overlayed resource does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); + Assert.assertEquals("Static resource does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); } finally { - try{ + try { ctx.close(); - }catch(Exception e){ + } catch (Exception e) { + LOGGER.error("Closing context failed", e); + } + try { + removeOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, + OverlayableInterface.RESOURCE); + } catch (Exception e) { + LOGGER.error("Removing overlay failed", e); } - OverlayUtils.removeOverlay(managementClient, DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE); } } } diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayNonExistingResourceTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayNonExistingResourceTestCase.java index 6048bbe3af4e..a24ab5690c75 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayNonExistingResourceTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/jar/OverlayNonExistingResourceTestCase.java @@ -38,12 +38,13 @@ @RunWith(Arquillian.class) @RunAsClient public class OverlayNonExistingResourceTestCase extends JarOverlayTestBase { + private static final String OVERLAY = "HAL9000"; private static final String DEPLOYMENT_OVERLAYED = "overlayed"; private static final String DEPLOYMENT_OVERLAYED_ARCHIVE = DEPLOYMENT_OVERLAYED + ".jar"; @Deployment(name = DEPLOYMENT_OVERLAYED) - public static Archive createDeployment() throws Exception { + public static Archive createDeployment() throws Exception { return createOverlayedArchive(false, DEPLOYMENT_OVERLAYED_ARCHIVE); } @@ -55,15 +56,20 @@ public void testOverlay() throws Exception { OverlayEJB.class, OverlayableInterface.class)); Assert.assertEquals("Overlayed resource does not match pre-overlay expectations!", null, iface.fetchResource()); Assert.assertEquals("Static resource does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - OverlayUtils.setupOverlay(managementClient, DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE, OverlayableInterface.OVERLAYED); + setupOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE, OverlayableInterface.OVERLAYED); Assert.assertEquals("Overlayed resource does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); } finally { try { ctx.close(); } catch (Exception e) { + LOGGER.error("Closing context failed", e); + } + try { + removeOverlay(DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE); + } catch (Exception e) { + LOGGER.error("Removing overlay failed", e); } - OverlayUtils.removeOverlay(managementClient, DEPLOYMENT_OVERLAYED_ARCHIVE, OVERLAY, OverlayableInterface.RESOURCE); } } diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayExistingResourceTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayExistingResourceTestCase.java index 41f1036a426e..3587a0bd81fa 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayExistingResourceTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayExistingResourceTestCase.java @@ -31,7 +31,6 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; -import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayUtils; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; @@ -56,7 +55,7 @@ public class OverlayExistingResourceTestCase extends WarOverlayTestBase { private static final String RESOURCE = "/WEB-INF/lib/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) - public static Archive createDeployment() throws Exception { + public static Archive createDeployment() throws Exception { return createWARWithOverlayedArchive(true, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @@ -65,34 +64,38 @@ public void testOverlay() throws Exception { final InitialContext ctx = getInitialContext(); Map overlay = new HashMap(); try{ - OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_SHELL, "", - OverlayEJB.class, OverlayableInterface.class)); - Assert.assertEquals("Overlayed resource in war/jar does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); - Assert.assertEquals("Static resource in war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + OverlayableInterface iface = (OverlayableInterface) ctx.lookup(getEjbBinding("", DEPLOYMENT_SHELL, "", + OverlayEJB.class, OverlayableInterface.class)); + Assert.assertEquals("Overlayed resource in war/jar does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, iface.fetchResource()); + Assert.assertEquals("Static resource in war/jar does not match pre-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - Assert.assertEquals("HTML resource in war does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, - readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); - Assert.assertEquals("HTML static resource in war does not match pre-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); + Assert.assertEquals("HTML resource in war does not match pre-overlay expectations!", OverlayableInterface.ORIGINAL, + readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); + Assert.assertEquals("HTML static resource in war does not match pre-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); - overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); - overlay.put(OVERLAY_HTML, OverlayableInterface.OVERLAYED); - OverlayUtils.setupOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); + overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); + overlay.put(OVERLAY_HTML, OverlayableInterface.OVERLAYED); + setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); - Assert.assertEquals("Overlayed resource in war/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); - Assert.assertEquals("Static resource in war/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); - - Assert.assertEquals("HTML static resource in war does not match post-overlay expectations!", OverlayableInterface.STATIC, - readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); - Assert.assertEquals("HTML resource in war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, - readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); + Assert.assertEquals("Overlayed resource in war/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); + Assert.assertEquals("Static resource in war/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); + Assert.assertEquals("HTML static resource in war does not match post-overlay expectations!", OverlayableInterface.STATIC, + readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + STATIC_HTML)); + Assert.assertEquals("HTML resource in war does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, + readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); } finally { - try{ + try { ctx.close(); - }catch(Exception e){ + } catch (Exception e) { + LOGGER.error("Closing context failed", e); + } + try { + removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); + } catch (Exception e) { + LOGGER.error("Removing overlay failed", e); } - OverlayUtils.removeOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } } diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayNonExistingResourceTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayNonExistingResourceTestCase.java index 77940811d7a2..2205ab97075f 100644 --- a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayNonExistingResourceTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/deployment/deploymentoverlay/war/OverlayNonExistingResourceTestCase.java @@ -31,7 +31,6 @@ import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayEJB; -import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayUtils; import org.jboss.as.test.integration.deployment.deploymentoverlay.jar.OverlayableInterface; import org.jboss.shrinkwrap.api.Archive; import org.junit.Assert; @@ -56,7 +55,7 @@ public class OverlayNonExistingResourceTestCase extends WarOverlayTestBase { private static final String RESOURCE = "/WEB-INF/lib/"+DEPLOYMENT_OVERLAYED_ARCHIVE+"//"+OverlayableInterface.RESOURCE; @Deployment(name = DEPLOYMENT_SHELL) - public static Archive createDeployment() throws Exception { + public static Archive createDeployment() throws Exception { return createWARWithOverlayedArchive(false, DEPLOYMENT_OVERLAYED_ARCHIVE,DEPLOYMENT_SHELL_ARCHIVE); } @@ -77,7 +76,7 @@ public void testOverlay() throws Exception { overlay.put(RESOURCE, OverlayableInterface.OVERLAYED); overlay.put(OVERLAY_HTML, OverlayableInterface.OVERLAYED); - OverlayUtils.setupOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); + setupOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay); Assert.assertEquals("Overlayed resource in war/jar does not match post-overlay expectations!", OverlayableInterface.OVERLAYED, iface.fetchResource()); Assert.assertEquals("Static resource in war/jar does not match post-overlay expectations!", OverlayableInterface.STATIC, iface.fetchResourceStatic()); @@ -88,11 +87,16 @@ public void testOverlay() throws Exception { readContent(managementClient.getWebUri() + "/" + DEPLOYMENT_SHELL + "/" + OVERLAY_HTML)); } finally { - try{ + try { ctx.close(); - }catch(Exception e){ + } catch (Exception e) { + LOGGER.error("Closing context failed", e); + } + try { + removeOverlay(DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); + } catch (Exception e) { + LOGGER.error("Removing overlay failed", e); } - OverlayUtils.removeOverlay(managementClient, DEPLOYMENT_SHELL_ARCHIVE, OVERLAY, overlay.keySet()); } } }