Author: adietish
Date: 2011-04-11 12:42:51 -0400 (Mon, 11 Apr 2011)
New Revision: 30479
Modified:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentBuilderIntegrationTest.java
Log:
[JBIDE-8690] added test that checks if app was deployed
Modified:
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentBuilderIntegrationTest.java
===================================================================
---
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentBuilderIntegrationTest.java 2011-04-11
16:37:33 UTC (rev 30478)
+++
workspace/adietish/org.jboss.ide.eclipse.as7.deployment.tests/src/org/jboss/ide/eclipse/as7/deployment/tests/DeploymentBuilderIntegrationTest.java 2011-04-11
16:42:51 UTC (rev 30479)
@@ -14,14 +14,18 @@
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertNotNull;
+import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.StringWriter;
import java.net.ConnectException;
+import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
+import java.text.MessageFormat;
import java.util.List;
import org.eclipse.core.runtime.FileLocator;
@@ -40,12 +44,14 @@
public class DeploymentBuilderIntegrationTest {
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 PORT = 9999;
-
+ private static final int MGMT_PORT = 9999;
+ private static final int WEB_PORT = 8080;
+
@Before
public void setUp() throws UnknownHostException, IOException {
assertAs7IsRunning();
@@ -54,10 +60,10 @@
private void assertAs7IsRunning() throws UnknownHostException, IOException {
try {
Socket socket = new Socket();
- socket.connect(new InetSocketAddress(HOST, PORT));
+ socket.connect(new InetSocketAddress(HOST, MGMT_PORT));
socket.close();
} catch (ConnectException e) {
- fail("JBoss as7 seems not to run on " + HOST + ", test cannot access
it's management API on port " + PORT);
+ fail("JBoss as7 seems not to run on " + HOST + ", test cannot access
it's management API on port " + MGMT_PORT);
}
}
@@ -65,15 +71,16 @@
@Test
public void canDeploy() throws DeploymentException, URISyntaxException, IOException {
File file = getWarFile("minimalistic.war");
- new DeploymentBuilder(HOST, PORT).add(file).deploy();
+ new DeploymentBuilder(HOST, MGMT_PORT).add(file).deploy();
}
+
@Ignore
@Test
public void returnsDeployables() throws DeploymentException, URISyntaxException,
IOException {
String warName = "minimalistic.war";
File file = getWarFile(warName );
- List<Deployable> deployables = new DeploymentBuilder(HOST,
PORT).add(file).deploy();
+ List<Deployable> deployables = new DeploymentBuilder(HOST,
MGMT_PORT).add(file).deploy();
assertEquals(1, deployables.size());
assertEquals(warName, deployables.get(0).getName());
}
@@ -81,14 +88,45 @@
@Test
public void canGetDeploymentStatus() throws DeploymentException, URISyntaxException,
IOException {
File file = getWarFile("minimalistic.war");
- List<Deployable> deployables = new DeploymentBuilder(HOST,
PORT).add(file).deploy();
+ List<Deployable> deployables = new DeploymentBuilder(HOST,
MGMT_PORT).add(file).deploy();
Deployable deployable = deployables.get(0);
assertNotNull(deployable.getStatus());
}
+ @Ignore
+ @Test
+ public void isDeployed() throws DeploymentException, URISyntaxException, IOException {
+ String warName = "minimalistic.war";
+ File file = getWarFile(warName );
+ List<Deployable> deployables = new DeploymentBuilder(HOST,
MGMT_PORT).add(file).deploy();
+ Deployable deployable = deployables.get(0);
+ deployable.getStatus(); // wait for deployment to have finished
+ String response = getServerResponse(new
URL(MessageFormat.format("http://{0}:{1}/{2}", HOST, WEB_PORT,
deployable.getName())));
+ }
+
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(BufferedInputStream in) throws IOException {
+ StringWriter writer = new StringWriter();
+ for(int data = -1; ((data = in.read()) != -1); ) {
+ writer.write(data);
+ }
+ return writer.toString();
+ }
}