Skip to content

Commit

Permalink
[WFCORE-2229]: Adding test to cover redeploy-links
Browse files Browse the repository at this point in the history
 * Adding mixed domain tests to cover the new redeploy-affected deployments for overlays
 * Updating existing tests
  • Loading branch information
ehsavoie committed May 31, 2017
1 parent 179d642 commit c3b040c
Show file tree
Hide file tree
Showing 23 changed files with 1,175 additions and 88 deletions.
Expand Up @@ -35,7 +35,7 @@
/** /**
* @author Stuart Douglas * @author Stuart Douglas
*/ */
@WebServlet(urlPatterns = "/*") @WebServlet(urlPatterns = "/servlet")
public class DeploymentOverlayServlet extends HttpServlet { public class DeploymentOverlayServlet extends HttpServlet {


@Override @Override
Expand Down
Expand Up @@ -37,7 +37,6 @@
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.jboss.as.cli.Util; import org.jboss.as.cli.Util;
import org.jboss.as.controller.client.Operation;
import org.jboss.as.controller.client.OperationBuilder; import org.jboss.as.controller.client.OperationBuilder;
import org.jboss.as.controller.client.helpers.domain.DomainClient; import org.jboss.as.controller.client.helpers.domain.DomainClient;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
Expand Down Expand Up @@ -75,6 +74,10 @@
import static org.jboss.as.test.integration.domain.management.util.DomainTestSupport.validateResponse; import static org.jboss.as.test.integration.domain.management.util.DomainTestSupport.validateResponse;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;


import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.client.Operation;
import org.jboss.as.controller.client.helpers.Operations;

/** /**
* Test of various management operations involving deployment overlays * Test of various management operations involving deployment overlays
*/ */
Expand Down Expand Up @@ -248,7 +251,7 @@ public void setupDeploymentOverride() throws Exception {
op = new ModelNode(); op = new ModelNode();
addr = new ModelNode(); addr = new ModelNode();
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD); addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);
addr.add(ModelDescriptionConstants.CONTENT, "WEB-INF/classes/wildcard-new-file"); addr.add(ModelDescriptionConstants.CONTENT, "wildcard-new-file.txt");
op.get(ModelDescriptionConstants.OP_ADDR).set(addr); op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD); op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0); op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);
Expand Down Expand Up @@ -294,12 +297,35 @@ public void testDeploymentOverlayInDomainMode() throws Exception {
executeOnMaster(builder.build()); executeOnMaster(builder.build());


DomainClient client = testSupport.getDomainMasterLifecycleUtil().createDomainClient(); DomainClient client = testSupport.getDomainMasterLifecycleUtil().createDomainClient();
Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "master", "main-one", "standard-sockets")); Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/servlet"));
Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "slave", "main-three", "standard-sockets")); Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/servlet"));

Assert.assertEquals("new file", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/wildcard-new-file.txt"));
Assert.assertEquals("new file", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/wildcard-new-file.txt"));

//Remove the wildcard overlay
ModelNode op = Operations.createRemoveOperation(PathAddress.pathAddress(ModelDescriptionConstants.SERVER_GROUP, "main-server-group")
.append(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD)
.append(ModelDescriptionConstants.DEPLOYMENT, "*.war")
.toModelNode());
op.get("redeploy-affected").set(true);
executeOnMaster(op);
Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/servlet"));
Assert.assertEquals("OVERRIDDEN", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/servlet"));
Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/wildcard-new-file.txt"));
Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/wildcard-new-file.txt"));
op = Operations.createRemoveOperation(PathAddress.pathAddress(ModelDescriptionConstants.SERVER_GROUP, "main-server-group")
.append(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY)
.append(ModelDescriptionConstants.DEPLOYMENT, "test.war")
.toModelNode());
op.get("redeploy-affected").set(true);
executeOnMaster(op);
Assert.assertEquals("NON OVERRIDDEN", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/servlet"));
Assert.assertEquals("NON OVERRIDDEN", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/servlet"));
Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "master", "main-one", "standard-sockets", "/test/wildcard-new-file.txt"));
Assert.assertEquals("<html><head><title>Error</title></head><body>Not Found</body></html>", performHttpCall(client, "slave", "main-three", "standard-sockets", "/test/wildcard-new-file.txt"));
} }


private String performHttpCall(DomainClient client, String host, String server, String socketBindingGroup) throws Exception { private String performHttpCall(DomainClient client, String host, String server, String socketBindingGroup, String path) throws Exception {
ModelNode op = new ModelNode(); ModelNode op = new ModelNode();
op.get(OP).set(READ_RESOURCE_OPERATION); op.get(OP).set(READ_RESOURCE_OPERATION);
op.get(OP_ADDR).add(HOST, host).add(SERVER, server).add(SOCKET_BINDING_GROUP, socketBindingGroup).add(SOCKET_BINDING, "http"); op.get(OP_ADDR).add(HOST, host).add(SERVER, server).add(SOCKET_BINDING_GROUP, socketBindingGroup).add(SOCKET_BINDING, "http");
Expand All @@ -309,7 +335,7 @@ private String performHttpCall(DomainClient client, String host, String server,
URL url = new URL("http", URL url = new URL("http",
TestSuiteEnvironment.formatPossibleIpv6Address(socketBinding.get("bound-address").asString()), TestSuiteEnvironment.formatPossibleIpv6Address(socketBinding.get("bound-address").asString()),
socketBinding.get("bound-port").asInt(), socketBinding.get("bound-port").asInt(),
"/test/"); path);
HttpGet get = new HttpGet(url.toURI()); HttpGet get = new HttpGet(url.toURI());
HttpClient httpClient = HttpClients.createDefault(); HttpClient httpClient = HttpClients.createDefault();
HttpResponse response = httpClient.execute(get); HttpResponse response = httpClient.execute(get);
Expand All @@ -319,9 +345,10 @@ private String performHttpCall(DomainClient client, String host, String server,
public static String getContent(HttpResponse response) throws IOException { public static String getContent(HttpResponse response) throws IOException {
InputStreamReader reader = new InputStreamReader(response.getEntity().getContent()); InputStreamReader reader = new InputStreamReader(response.getEntity().getContent());
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
char[] buffer = new char[8];
int c; int c;
while (-1 != (c = reader.read())) { while ((c = reader.read(buffer)) != -1) {
content.append((char) c); content.append(buffer, 0, c);
} }
reader.close(); reader.close();
return content.toString(); return content.toString();
Expand Down
@@ -0,0 +1,143 @@
/*
* Copyright 2017 JBoss by Red Hat.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.as.test.integration.deployment.deploymentoverlay;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CONTENT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT;

import java.io.IOException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.hamcrest.CoreMatchers;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;

import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.client.OperationBuilder;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.test.integration.common.HttpRequest;
import org.jboss.as.test.integration.management.base.ContainerResourceMgmtTestBase;
import org.jboss.as.test.shared.FileUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* @author Stuart Douglas
* @author Emmanuel Hugonnet (c) 2017 Red Hat, inc.
*/
@RunWith(Arquillian.class)
@RunAsClient
public class AffectedDeploymentOverlayTestCase extends ContainerResourceMgmtTestBase {

private static final String DEPLOYMENT_NAME = "test.war";
public static final String TEST_OVERLAY = "test";
public static final String TEST_WILDCARD = "test-wildcard";
private static final PathAddress TEST_OVERLAY_ADDRESS = PathAddress.pathAddress(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_OVERLAY);
private static final PathAddress TEST_WILDCARD_ADDRESS = PathAddress.pathAddress(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, TEST_WILDCARD);

@Before
public void setup() throws Exception {
getModelControllerClient().execute(Operations.createAddOperation(TEST_OVERLAY_ADDRESS.toModelNode()));

//add an override that will not be linked via a wildcard
//add the content
ModelNode op = Operations.createAddOperation(TEST_OVERLAY_ADDRESS.append(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml").toModelNode());
op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);
OperationBuilder builder = new OperationBuilder(op, true);
builder.addInputStream(AffectedDeploymentOverlayTestCase.class.getResourceAsStream("override.xml"));
getModelControllerClient().execute(builder.build());

//add the non-wildcard link
getModelControllerClient().execute(Operations.createAddOperation(TEST_OVERLAY_ADDRESS.append(DEPLOYMENT, DEPLOYMENT_NAME).toModelNode()));

//add the deployment overlay that will be linked via wildcard
getModelControllerClient().execute(Operations.createAddOperation(TEST_WILDCARD_ADDRESS.toModelNode()));

op = Operations.createAddOperation(TEST_WILDCARD_ADDRESS.append(ModelDescriptionConstants.CONTENT, "WEB-INF/web.xml").toModelNode());
op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.BYTES).set(FileUtils.readFile(AffectedDeploymentOverlayTestCase.class, "wildcard-override.xml").getBytes());
getModelControllerClient().execute(op);

op = Operations.createAddOperation(TEST_WILDCARD_ADDRESS.append(ModelDescriptionConstants.CONTENT, "WEB-INF/classes/wildcard-new-file").toModelNode());
op.get(ModelDescriptionConstants.CONTENT).get(ModelDescriptionConstants.INPUT_STREAM_INDEX).set(0);

builder = new OperationBuilder(op, true);
builder.addInputStream(AffectedDeploymentOverlayTestCase.class.getResourceAsStream("wildcard-new-file"));
getModelControllerClient().execute(builder.build());
}

@After
public void tearDown() throws Exception {
getModelControllerClient().execute(Operations.createRemoveOperation(TEST_OVERLAY_ADDRESS.append(CONTENT, "WEB-INF/web.xml").toModelNode()));
getModelControllerClient().execute(Operations.createRemoveOperation(TEST_OVERLAY_ADDRESS.append(DEPLOYMENT, DEPLOYMENT_NAME).toModelNode()));
getModelControllerClient().execute(Operations.createRemoveOperation(TEST_OVERLAY_ADDRESS.toModelNode()));

getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.append(DEPLOYMENT, "*.war").toModelNode()));
getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.append(CONTENT, "WEB-INF/web.xml").toModelNode()));
getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.append(CONTENT, "WEB-INF/classes/wildcard-new-file").toModelNode()));
getModelControllerClient().execute(Operations.createRemoveOperation(TEST_WILDCARD_ADDRESS.toModelNode()));
}

@Deployment(name = DEPLOYMENT_NAME)
public static Archive<?> deploy() {
return ShrinkWrap.create(WebArchive.class, DEPLOYMENT_NAME)
.addPackage(AffectedDeploymentOverlayTestCase.class.getPackage())
.setWebXML(AffectedDeploymentOverlayTestCase.class.getPackage(), "web.xml");
}

@Test
public void testContentOverridden(@ArquillianResource URL url) throws Exception {
String response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS);
Assert.assertEquals("Overlay doesn't contain valid output", "UPDATED", response.trim());
try {
HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS);
Assert.fail("Overlay servlet shouldn't be up and working properly");
} catch (IOException ioex) {
Assert.assertThat(ioex.getMessage(), CoreMatchers.containsString("HTTP Status 500 Response:"));
}
getModelControllerClient().execute(Operations.createOperation("redeploy-links", TEST_OVERLAY_ADDRESS.toModelNode()));
response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS);
Assert.assertEquals("Overlay doesn't contain valid output", "OVERRIDDEN", response.trim());
try {
HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS);
Assert.fail("Overlay servlet shouldn't be up and working properly");
} catch (IOException ioex) {
Assert.assertThat(ioex.getMessage(), CoreMatchers.containsString("HTTP Status 500 Response:"));
}
//add the wildcard link
getModelControllerClient().execute(Operations.createAddOperation(TEST_WILDCARD_ADDRESS.append(ModelDescriptionConstants.DEPLOYMENT, "*.war").toModelNode()));
getModelControllerClient().execute(Operations.createOperation("redeploy-links", TEST_OVERLAY_ADDRESS.toModelNode()));//This will redeploy the deployment
response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS);
Assert.assertEquals("Overlay doesn't contain valid output", "OVERRIDDEN", response.trim());
response = HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS);
Assert.assertEquals("Overlay doesn't contain valid output", "test", response.trim());
getModelControllerClient().execute(Operations.createOperation("redeploy-links", TEST_WILDCARD_ADDRESS.toModelNode()));//This will redeploy the deployment
response = HttpRequest.get(url + "/simple/", 10, TimeUnit.SECONDS);
Assert.assertEquals("Overlaydoesn't contain valid output", "OVERRIDDEN", response.trim());
response = HttpRequest.get(url + "/overlay/", 10, TimeUnit.SECONDS);
Assert.assertEquals("Overlay doesn't contain valid output", "test", response.trim());
}

}
Expand Up @@ -12,6 +12,7 @@
import org.jboss.as.arquillian.api.ServerSetupTask; import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient; import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.client.OperationBuilder; import org.jboss.as.controller.client.OperationBuilder;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.test.integration.management.ManagementOperations; import org.jboss.as.test.integration.management.ManagementOperations;
import org.jboss.as.test.integration.management.util.MgmtOperationException; import org.jboss.as.test.integration.management.util.MgmtOperationException;
Expand Down Expand Up @@ -133,28 +134,20 @@ public void tearDown(final ManagementClient managementClient, final String conta


} }


private void removeContentItem(final ManagementClient managementClient, final String w, final String a) throws IOException, MgmtOperationException { private void removeContentItem(final ManagementClient managementClient, final String overlayName, final String content) throws IOException, MgmtOperationException {
final ModelNode op; final ModelNode addr = new ModelNode();
final ModelNode addr; addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName);
op = new ModelNode(); addr.add(ModelDescriptionConstants.CONTENT, content);
addr = new ModelNode(); final ModelNode op = Operations.createRemoveOperation(addr);
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, w);
addr.add(ModelDescriptionConstants.CONTENT, a);
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op); ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
} }




private void removeDeploymentItem(final ManagementClient managementClient, final String w, final String a) throws IOException, MgmtOperationException { private void removeDeploymentItem(final ManagementClient managementClient, final String overlayName, final String deploymentRuntimeName) throws IOException, MgmtOperationException {
final ModelNode op; final ModelNode addr = new ModelNode();
final ModelNode addr; addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, overlayName);
op = new ModelNode(); addr.add(ModelDescriptionConstants.DEPLOYMENT, deploymentRuntimeName);
addr = new ModelNode(); final ModelNode op = Operations.createRemoveOperation(addr);
addr.add(ModelDescriptionConstants.DEPLOYMENT_OVERLAY, w);
addr.add(ModelDescriptionConstants.DEPLOYMENT, a);
op.get(ModelDescriptionConstants.OP_ADDR).set(addr);
op.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.REMOVE);
ManagementOperations.executeOperation(managementClient.getControllerClient(), op); ManagementOperations.executeOperation(managementClient.getControllerClient(), op);
} }
} }
Expand Down
11 changes: 9 additions & 2 deletions testsuite/mixed-domain/pom.xml
Expand Up @@ -96,14 +96,21 @@
<!-- System properties to forked surefire JVM which runs clients. --> <!-- System properties to forked surefire JVM which runs clients. -->
<argLine>${jvm.args.ip.client} ${jvm.args.timeouts}</argLine> <argLine>${jvm.args.ip.client} ${jvm.args.timeouts}</argLine>
<skipTests>${ts.skipTests}</skipTests> <skipTests>${ts.skipTests}</skipTests>

<skipTests>false</skipTests>
<systemPropertyVariables> <systemPropertyVariables combine.children="append">
<mcast>${mcast}</mcast>
<mcast1>${mcast1}</mcast1>
<mcast2>${mcast2}</mcast2>
<mcast.ttl>${mcast.ttl}</mcast.ttl>
<jboss.options>${surefire.system.args}</jboss.options> <jboss.options>${surefire.system.args}</jboss.options>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<jboss.home>${jboss.home}</jboss.home> <jboss.home>${jboss.home}</jboss.home>
<module.path>${jboss.home}/modules</module.path> <module.path>${jboss.home}/modules</module.path>
<jboss.test.host.master.address>${node0}</jboss.test.host.master.address> <jboss.test.host.master.address>${node0}</jboss.test.host.master.address>
<jboss.test.host.slave.address>${node1}</jboss.test.host.slave.address> <jboss.test.host.slave.address>${node1}</jboss.test.host.slave.address>
<jboss.default.multicast.address>${mcast}</jboss.default.multicast.address>
<jboss.modcluster.multicast.address>${mcast1}</jboss.modcluster.multicast.address>
<server.jvm.args>${surefire.system.args} ${jvm.args.ip.server} ${jvm.args.jacoco} ${jvm.args.other} ${jvm.args.timeouts} -Dnode0=${node0} -Dnode1=${node1} -Djboss.default.multicast.address=${mcast} -Djboss.messaging.cluster.password=ILoveWildfly </server.jvm.args>
</systemPropertyVariables> </systemPropertyVariables>
<includes> <includes>
<!-- include>**/*TestCase.java</include --> <!-- include>**/*TestCase.java</include -->
Expand Down

0 comments on commit c3b040c

Please sign in to comment.