@Test
public void testDeploymentStreamApi() throws Exception {
final JavaArchive archive = ShrinkWrapUtils.createJavaArchive("servermodule/test-deployment.sar",
Simple.class.getPackage());
final ServerDeploymentManager manager = ServerDeploymentManager.Factory
.create(InetAddress.getByName(managementClient.getMgmtAddress()), managementClient.getMgmtPort(), getCallbackHandler());
final ModelControllerClient client = managementClient.getControllerClient();
testDeployments(client, new DeploymentExecutor() {
@Override
public void initialDeploy() {
final InputStream is = archive.as(ZipExporter.class).exportAsInputStream();
try {
Future<?> future = manager.execute(manager.newDeploymentPlan()
.add("test-deployment.sar", is).deploy("test-deployment.sar").build());
awaitDeploymentExecution(future);
} finally {
if (is != null) try {
is.close();
} catch (IOException ignore) {
//
}
}
}
@Override
public void fullReplace() {
final InputStream is = archive.as(ZipExporter.class).exportAsInputStream();
try {
Future<?> future = manager.execute(manager.newDeploymentPlan()
.replace("test-deployment.sar", is).build());
awaitDeploymentExecution(future);
} finally {
if (is != null) try {
is.close();
} catch (IOException ignore) {
//
}
}
}
@Override
public void undeploy() {
Future<?> future = manager.execute(manager.newDeploymentPlan().undeploy("test-deployment.sar")
.remove("test-deployment.sar").build());
awaitDeploymentExecution(future);
}
});
}