Author: adietish
Date: 2011-04-13 05:11:43 -0400 (Wed, 13 Apr 2011)
New Revision: 30547
Added:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneOperationsIntegrationTest.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneOperations.java
Removed:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneDeployerIntegrationTest.java
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java
Modified:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath
Log:
Modified: workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath
===================================================================
--- workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath 2011-04-13 03:47:54
UTC (rev 30546)
+++ workspace/adietish/org.jboss.ide.eclipse.as7.deployment/.classpath 2011-04-13 09:11:43
UTC (rev 30547)
@@ -2,12 +2,12 @@
<classpath>
<classpathentry exported="true" kind="lib"
path="jboss-threads-2.0.0.CR8.jar"
sourcepath="jboss-threads-2.0.0.CR8-sources.jar"/>
<classpathentry exported="true" kind="lib"
path="jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT.jar"
sourcepath="jboss-as-controller-client-7.0.0.Beta3-SNAPSHOT-sources.jar"/>
- <classpathentry exported="true" kind="lib"
path="jboss-as-protocol-7.0.0.Beta3-SNAPSHOT.jar"
sourcepath="jboss-as-protocol-7.0.0.Beta3-SNAPSHOT-sources.jar"/>
- <classpathentry exported="true" kind="lib"
path="jboss-dmr-1.0.0.Beta5.jar"
sourcepath="jboss-dmr-1.0.0.Beta5-sources.jar"/>
- <classpathentry exported="true" kind="lib"
path="jboss-marshalling-1.3.0.CR8.jar"
sourcepath="jboss-marshalling-1.3.0.CR8-sources.jar"/>
+ <classpathentry exported="true" kind="lib"
path="jboss-as-protocol-7.0.0.Beta3-SNAPSHOT.jar"/>
+ <classpathentry exported="true" kind="lib"
path="jboss-dmr-1.0.0.Beta5.jar"/>
+ <classpathentry exported="true" kind="lib"
path="jboss-logging-3.0.0.Beta3.jar"/>
+ <classpathentry exported="true" kind="lib"
path="jboss-marshalling-1.3.0.CR8.jar"/>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con"
path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
- <classpathentry kind="lib"
path="jboss-logging-3.0.0.Beta3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Deleted:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java 2011-04-13
03:47:54 UTC (rev 30546)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java 2011-04-13
09:11:43 UTC (rev 30547)
@@ -1,185 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as7.deployment;
-
-import static org.jboss.as.protocol.StreamUtils.safeClose;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
-
-import org.jboss.as.controller.client.ModelControllerClient;
-import org.jboss.as.controller.client.helpers.standalone.DeploymentPlan;
-import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
-import
org.jboss.as.controller.client.helpers.standalone.DuplicateDeploymentNameException;
-import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
-
-/**
- * Used to deploy/undeploy deployments to a running <b>standalone</b>
- * application server
- *
- * @author <a href="kabir.khan(a)jboss.com">Kabir Khan</a>
- * @author <a href="adietish(a)redhat.xn--com">andr-rtb Dietisheim</a>
- */
-public class StandaloneDeployer {
-
- public static final long DEFAULT_TIMEOUT = 15000;
-
- private final List<AbstractDeployable> deployments = new
ArrayList<AbstractDeployable>();
- private final ModelControllerClient client;
- private final ServerDeploymentManager manager;
- private long timeout = DEFAULT_TIMEOUT;
-
- public StandaloneDeployer(String host, int port) throws UnknownHostException {
- client = ModelControllerClient.Factory.create(host, port);
- manager = ServerDeploymentManager.Factory.create(client);
- }
-
- public synchronized StandaloneDeployer addWar(File file) {
- deployments.add(new WarDeployable(file));
- return this;
- }
-
- public synchronized StandaloneDeployer addWarDeployment(String name, File file) {
- deployments.add(new WarDeployable(name, file));
- return this;
- }
-
- public synchronized void deploy() throws DuplicateDeploymentNameException, IOException,
ExecutionException,
- InterruptedException, TimeoutException {
- DeploymentPlanBuilder builder = manager.newDeploymentPlan();
- for (AbstractDeployable deployment : deployments) {
- builder = deployment.addDeployment(builder);
- }
-
- try {
- manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
- } finally {
- markDeploymentsDeployed();
- }
- }
-
- private void markDeploymentsDeployed() {
- for (AbstractDeployable deployment : deployments) {
- deployment.deployed = true;
- }
- }
-
- public synchronized void undeploy() throws ExecutionException, InterruptedException,
TimeoutException {
- DeploymentPlanBuilder builder = manager.newDeploymentPlan();
- for (AbstractDeployable deployment : deployments) {
- builder = deployment.removeDeployment(builder);
- }
- DeploymentPlan plan = builder.build();
- if (plan.getDeploymentActions().size() > 0) {
- manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
- }
- }
-
- public MBeanServerConnection getConnection() throws Exception {
- return JMXConnectorFactory.connect(new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi"),
- new HashMap<String, Object>()).getMBeanServerConnection();
- }
-
- public String showJndi() throws Exception {
- return (String) getConnection().invoke(new ObjectName("jboss:type=JNDIView"),
"list", new Object[] { true },
- new String[] { "boolean" });
- }
-
- public long getTimeout() {
- return timeout;
- }
-
- public void setTimeout(long timeout) {
- this.timeout = timeout;
- }
-
- public void dispose() {
- safeClose(client);
- }
-
- private abstract class AbstractDeployable {
-
- private boolean deployed;
-
- public synchronized DeploymentPlanBuilder addDeployment(DeploymentPlanBuilder builder)
- throws DuplicateDeploymentNameException, IOException, ExecutionException,
InterruptedException {
- String name = getName();
- return builder.add(name, getFile()).deploy(name);
- }
-
- public synchronized DeploymentPlanBuilder removeDeployment(DeploymentPlanBuilder
builder) {
- String name = getName();
- if (deployed) {
- return builder.undeploy(name).remove(name);
- }
- else {
- return builder;
- }
- }
-
- protected abstract String getName();
-
- protected abstract File getFile();
- }
-
- private class WarDeployable extends AbstractDeployable {
-
- private File file;
- private String name;
-
- public WarDeployable(String name, File file) {
- this(file);
- this.name = name;
- }
-
- public WarDeployable(File file) {
- this.file = file;
- }
-
- @Override
- protected File getFile() {
- return file;
- }
-
- @Override
- protected String getName() {
- if (name != null) {
- return name;
- } else {
- return file.getName();
- }
- }
-
- }
-}
Copied:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneOperations.java
(from rev 30533,
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneDeployer.java)
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneOperations.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneOperations.java 2011-04-13
09:11:43 UTC (rev 30547)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as7.deployment;
+
+import static org.jboss.as.protocol.StreamUtils.safeClose;
+
+import java.io.File;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.jboss.as.controller.client.ModelControllerClient;
+import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
+import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
+
+/**
+ * Used to deploy/undeploy deployments to a running <b>standalone</b>
+ * application server
+ *
+ * @author <a href="kabir.khan(a)jboss.com">Kabir Khan</a>
+ * @author <a href="adietish(a)redhat.xn--com">andr-rtb Dietisheim</a>
+ */
+public class StandaloneOperations {
+
+ public static final long DEFAULT_TIMEOUT = 15000;
+
+ private final List<IDeploymentPlanBuilderOperation> deployments = new
ArrayList<IDeploymentPlanBuilderOperation>();
+ private final ModelControllerClient client;
+ private final ServerDeploymentManager manager;
+ private long timeout = DEFAULT_TIMEOUT;
+
+ public StandaloneOperations(String host, int port) throws UnknownHostException {
+ client = ModelControllerClient.Factory.create(host, port);
+ manager = ServerDeploymentManager.Factory.create(client);
+ }
+
+ public synchronized StandaloneOperations deploy(File file) {
+ deployments.add(new DeployOperation(file));
+ return this;
+ }
+
+ public synchronized StandaloneOperations deploy(String name, File file) {
+ deployments.add(new DeployOperation(name, file));
+ return this;
+ }
+
+ public synchronized StandaloneOperations undeploy(String name) {
+ deployments.add(new UndeployOperation(name));
+ return this;
+ }
+
+ public synchronized StandaloneOperations undeploy(File file) {
+ deployments.add(new UndeployOperation(file));
+ return this;
+ }
+
+ public synchronized void execute() throws DeployerException {
+ try {
+ DeploymentPlanBuilder builder = manager.newDeploymentPlan();
+ for (IDeploymentPlanBuilderOperation deployment : deployments) {
+ builder = deployment.addTo(builder);
+ }
+ manager.execute(builder.build()).get(timeout, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ throw new DeployerException(e);
+ }
+ }
+
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public void dispose() {
+ safeClose(client);
+ }
+
+ private static class DeployOperation extends FileOperation {
+
+ private DeployOperation(File file) {
+ super(file);
+ }
+
+ private DeployOperation(String name, File file) {
+ super(name, file);
+ }
+
+ public synchronized DeploymentPlanBuilder addTo(DeploymentPlanBuilder builder) throws
Exception {
+ String name = getName();
+ return builder.add(name, getFile()).deploy(name);
+ }
+ }
+
+ private static class UndeployOperation extends FileOperation {
+
+ private UndeployOperation(File file) {
+ super(file);
+ }
+
+ private UndeployOperation(String name) {
+ super(name, null);
+ }
+
+ public synchronized DeploymentPlanBuilder addTo(DeploymentPlanBuilder builder) throws
Exception {
+ String name = getName();
+ return builder.undeploy(name).undeploy(name);
+ }
+ }
+
+ private abstract static class FileOperation extends NamedOperation {
+
+ private File file;
+
+ private FileOperation(File file) {
+ this(null, file);
+ }
+
+ private FileOperation(String name, File file) {
+ super(name);
+ this.file = file;
+ }
+
+ protected File getFile() {
+ return file;
+ }
+
+ protected String getName() {
+ if (name != null) {
+ return name;
+ } else {
+ return file.getName();
+ }
+ }
+
+ }
+
+ private abstract static class NamedOperation implements IDeploymentPlanBuilderOperation
{
+
+ protected String name;
+
+ private NamedOperation(String name) {
+ this.name = name;
+ }
+ }
+
+ private interface IDeploymentPlanBuilderOperation {
+
+ public DeploymentPlanBuilder addTo(DeploymentPlanBuilder builder) throws Exception;
+
+ }
+}
Property changes on:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment/src/org/jboss/ide/eclipse/as7/deployment/StandaloneOperations.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneDeployerIntegrationTest.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneDeployerIntegrationTest.java 2011-04-13
03:47:54 UTC (rev 30546)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneDeployerIntegrationTest.java 2011-04-13
09:11:43 UTC (rev 30547)
@@ -1,128 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.as7.deployment.tests;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.net.HttpURLConnection;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.text.MessageFormat;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
-import org.jboss.ide.eclipse.as7.deployment.StandaloneDeployer;
-import org.junit.Test;
-import org.osgi.framework.Bundle;
-
-/**
- *
- * @author <a href="kabir.khan(a)jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class StandaloneDeployerIntegrationTest {
-
- private static final String WAR_FOLDER = "/wars/";
- private static final String BUNDLE_ID =
"org.jboss.ide.eclipse.as7.deployment.tests";
-
- private static final int WEBAPP_RESPONSE_TIMEOUT = 10 * 1024;
-
- private static final String HOST = "localhost";
- private static final int MGMT_PORT = 9999;
- private static final int WEB_PORT = 8080;
-
-
-
- @Test
- public void canDeploy() throws Exception {
- StandaloneDeployer deployer = null;
- try {
- File warFile = getWarFile("minimalistic.war");
- deployer = new StandaloneDeployer(HOST, MGMT_PORT);
- deployer.addWar(warFile).deploy();
-
- String response = getServerResponse(new URL(
- MessageFormat.format("http://{0}:{1}/{2}",
- HOST, String.valueOf(WEB_PORT), "minimalistic")));
- assertTrue(response.indexOf("minimalistic") >= 0);
-
- } finally {
- quietlyCleanup(deployer);
- }
- }
-
- @Test
- public void cannotDeployWarTwice() throws Exception {
- StandaloneDeployer deployer = null;
- try {
- File warFile = getWarFile("minimalistic.war");
- deployer = new StandaloneDeployer(HOST, MGMT_PORT);
- deployer.addWar(warFile).deploy();
- deployer.addWar(warFile).deploy();
- } finally {
- quietlyCleanup(deployer);
- }
- }
-
- private File getWarFile(String name) throws URISyntaxException, IOException {
- Bundle bundle = Platform.getBundle(BUNDLE_ID);
- URL entryUrl = bundle.getEntry(WAR_FOLDER + name);
- return new File(FileLocator.resolve(entryUrl).toURI());
- }
-
- private String getServerResponse(URL url) throws IOException {
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setUseCaches(false);
- connection.setDoInput(true);
- connection.setAllowUserInteraction(false);
- connection.setConnectTimeout(WEBAPP_RESPONSE_TIMEOUT);
- connection.setInstanceFollowRedirects(true);
- connection.setDoOutput(false);
- BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
- return toString(in);
- }
-
- private String toString(InputStream in) throws IOException {
- StringWriter writer = new StringWriter();
- for (int data = -1; ((data = in.read()) != -1);) {
- writer.write(data);
- }
- return writer.toString();
- }
-
- private void quietlyCleanup(StandaloneDeployer deployer) {
- try {
- if (deployer != null) {
- deployer.undeploy();
- deployer.dispose();
- }
- } catch (Exception e) {
- // ignore
- }
-
- }
-}
Copied:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneOperationsIntegrationTest.java
(from rev 30534,
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneDeployerIntegrationTest.java)
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneOperationsIntegrationTest.java
(rev 0)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneOperationsIntegrationTest.java 2011-04-13
09:11:43 UTC (rev 30547)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.as7.deployment.tests;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.ide.eclipse.as7.deployment.DeployerException;
+import org.jboss.ide.eclipse.as7.deployment.StandaloneOperations;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ *
+ * @author <a href="kabir.khan(a)jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class StandaloneOperationsIntegrationTest {
+
+ private static final String WAR_FOLDER = "/wars/";
+ private static final String BUNDLE_ID =
"org.jboss.ide.eclipse.as7.deployment.tests";
+
+ private static final int WEBAPP_RESPONSE_TIMEOUT = 10 * 1024;
+
+ private static final String HOST = "localhost";
+ private static final int MGMT_PORT = 9999;
+ private static final int WEB_PORT = 8080;
+
+ @Test
+ public void canDeploy() throws Exception {
+ StandaloneOperations deployer = null;
+ File warFile = getWarFile("minimalistic.war");
+ try {
+ deployer = new StandaloneOperations(HOST, MGMT_PORT);
+ quietlyUndeploy(warFile, deployer); // make sure doesn't
+ // exist
+ deployer.deploy(warFile).execute();
+
+ String response = getServerResponse(new URL(
+ MessageFormat.format(
+ "http://{0}:{1}/{2}", HOST, String.valueOf(WEB_PORT),
"minimalistic")));
+ assertTrue(response.indexOf("minimalistic") >= 0);
+
+ } finally {
+ quietlyUndeploy(warFile, deployer);
+ }
+ }
+
+ @Test(expected = DeployerException.class)
+ public void cannotDeployWarTwice() throws Exception {
+ StandaloneOperations deployer = null;
+ File warFile = getWarFile("minimalistic.war");
+ try {
+ deployer = new StandaloneOperations(HOST, MGMT_PORT);
+ deployer.deploy(warFile).execute();
+ deployer.deploy(warFile).execute();
+ } finally {
+ quietlyUndeploy(warFile, deployer);
+ }
+ }
+
+ private File getWarFile(String name) throws URISyntaxException, IOException {
+ Bundle bundle = Platform.getBundle(BUNDLE_ID);
+ URL entryUrl = bundle.getEntry(WAR_FOLDER + name);
+ return new File(FileLocator.resolve(entryUrl).toURI());
+ }
+
+ private String getServerResponse(URL url) throws IOException {
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setUseCaches(false);
+ connection.setDoInput(true);
+ connection.setAllowUserInteraction(false);
+ connection.setConnectTimeout(WEBAPP_RESPONSE_TIMEOUT);
+ connection.setInstanceFollowRedirects(true);
+ connection.setDoOutput(false);
+ BufferedInputStream in = new BufferedInputStream(connection.getInputStream());
+ return toString(in);
+ }
+
+ private String toString(InputStream in) throws IOException {
+ StringWriter writer = new StringWriter();
+ for (int data = -1; ((data = in.read()) != -1);) {
+ writer.write(data);
+ }
+ return writer.toString();
+ }
+
+ private void quietlyUndeploy(File file, StandaloneOperations deployer) {
+ try {
+ if (deployer != null) {
+ deployer.undeploy(file);
+ deployer.dispose();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ // ignore
+ }
+ }
+}
Property changes on:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/StandaloneOperationsIntegrationTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain