Skip to content

Commit

Permalink
[WFLY-8331] improve logic of deployment overlay tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwart committed Mar 10, 2017
1 parent 0804872 commit 0d91b12
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 126 deletions.
Expand Up @@ -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<String, String> 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<String, String> 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<String, String> overlayItem : overlay.entrySet()) {
// add content
Expand Down Expand Up @@ -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<String> overlayPaths) throws Exception {
public void removeOverlay(final String deployment, final String overlayName, final Set<String> 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();
Expand All @@ -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();
Expand All @@ -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<String> getCategories(ManagementClient managementClient, String containerId) {
Set<String> 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;
}
}
}
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -65,39 +64,44 @@ public void testOverlay() throws Exception {
final InitialContext ctx = getInitialContext();
Map<String, String> overlay = new HashMap<String, String>();
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());
}
}
}
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -65,39 +64,44 @@ public void testOverlay() throws Exception {
final InitialContext ctx = getInitialContext();
Map<String, String> overlay = new HashMap<String, String>();
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());
}
}
}

0 comments on commit 0d91b12

Please sign in to comment.