[jbosstools-commits] JBoss Tools SVN: r30699 - trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Apr 21 09:03:15 EDT 2011


Author: adietish
Date: 2011-04-21 09:03:15 -0400 (Thu, 21 Apr 2011)
New Revision: 30699

Modified:
   trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java
   trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java
Log:
[JBIDE-8690] corrected tests

Modified: trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java
===================================================================
--- trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java	2011-04-21 13:01:50 UTC (rev 30698)
+++ trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/DeployerTestUtils.java	2011-04-21 13:03:15 UTC (rev 30699)
@@ -23,6 +23,7 @@
 
 import java.io.BufferedInputStream;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
@@ -39,10 +40,10 @@
  * @author André Dietisheim
  */
 public class DeployerTestUtils {
-	
+
 	public static final String GWT_HELLOWORLD_WAR = "gwt-helloworld.war";
 	public static final String MINIMALISTIC_WAR = "minimalistic.war";
-	
+
 	public static final String HOST = "localhost";
 	public static final int MGMT_PORT = 9999;
 	public static final int WEB_PORT = 8080;
@@ -51,7 +52,8 @@
 	private static final String BUNDLE_ID = "org.jboss.ide.eclipse.as.management.as7.tests";
 
 	private static final int WEBAPP_RESPONSE_TIMEOUT = 10 * 1024;
-	
+	private static final long WAIT_DEPLOYED_TIMEOUT = 10 * 1024;
+
 	public static File getWarFile(String name) throws URISyntaxException, IOException {
 		Bundle bundle = Platform.getBundle(BUNDLE_ID);
 		URL entryUrl = bundle.getEntry(WAR_FOLDER + name);
@@ -59,12 +61,21 @@
 	}
 
 	public static String getWebappResponse(String name, String host, int port) throws IOException {
-		return getServerResponse(new URL(
-				MessageFormat.format(
-						"http://{0}:{1}/{2}", host, String.valueOf(port), name)));
+		long until = System.currentTimeMillis() + WAIT_DEPLOYED_TIMEOUT;
+		while (System.currentTimeMillis() < until) {
+			try {
+				return getServerResponse(new URL(
+						MessageFormat.format(
+								"http://{0}:{1}/{2}", host, String.valueOf(port), name)));
+			} catch (FileNotFoundException e) {
+				e.printStackTrace();
+			}
+
+		}
+		return null;
 	}
 
-		public static String getServerResponse(URL url) throws IOException {
+	public static String getServerResponse(URL url) throws IOException {
 		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 		connection.setUseCaches(false);
 		connection.setDoInput(true);

Modified: trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java
===================================================================
--- trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java	2011-04-21 13:01:50 UTC (rev 30698)
+++ trunk/as/org.jboss.ide.eclipse.as.management.as7.tests/src/org/jboss/ide/eclipse/as/management/as7/tests/TypedDeployerIntegrationTest.java	2011-04-21 13:03:15 UTC (rev 30699)
@@ -21,9 +21,12 @@
  */
 package org.jboss.ide.eclipse.as.management.as7.tests;
 
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
 import java.net.UnknownHostException;
 import java.util.concurrent.ExecutionException;
 
@@ -60,7 +63,8 @@
 			
 			String response = DeployerTestUtils.getWebappResponse(
 					"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
-			assertTrue(response.indexOf("minimalistic") >= 0);
+			assertTrue(response != null 
+					&& response.indexOf("minimalistic") >= 0);
 
 		} finally {
 			quietlyUndeploy(warFile);
@@ -68,14 +72,15 @@
 	}
 
 	@Test
-	public void deployedWarHasDeployedStatus() throws Exception {
+	public void deployedWarIsResponding() throws Exception {
 		File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
 		try {
 			waitUntilFinished(deployer.deploy(warFile));
 			
 			String response = DeployerTestUtils.getWebappResponse(
 					"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
-			assertTrue(response.indexOf("minimalistic") >= 0);
+			assertTrue(response != null 
+					&& response.indexOf("minimalistic") >= 0);
 
 		} finally {
 			quietlyUndeploy(warFile);
@@ -108,21 +113,39 @@
 			waitUntilFinished(deployer.replace(name, warFile2));
 			String response = DeployerTestUtils.getWebappResponse(
 					"minimalistic", DeployerTestUtils.HOST, DeployerTestUtils.WEB_PORT);
-			assertTrue(response.indexOf("GWT") >= 0);
+			assertTrue(response != null 
+					&& response.indexOf("GWT") >= 0);
 		} finally {
-			quietlyUndeploy(warFile);
+			quietlyUndeploy(name);
 		}
 	}
 	
-	private void quietlyUndeploy(File file) {
+	@Test
+	public void canQueryDeploymentState() throws URISyntaxException, IOException, DeployerException {
+		String deploymentName = "testDeployment";
+		File warFile = DeployerTestUtils.getWarFile(DeployerTestUtils.MINIMALISTIC_WAR);
 		try {
-			waitUntilFinished(deployer.undeploy(file.getName()));
+			waitUntilFinished(deployer.deploy(deploymentName, warFile));
+			String state = deployer.getDeploymentState(deploymentName);
+			assertNotNull(state);
+		} finally {
+			quietlyUndeploy(deploymentName);
+		}
+	}
+	
+	private void quietlyUndeploy(String name) {
+		try {
+			waitUntilFinished(deployer.undeploy(name));
 		} catch (Exception e) {
 			e.printStackTrace();
 			// ignore
 		}
 	}
 	
+	private void quietlyUndeploy(File file) {
+		quietlyUndeploy(file.getName());
+	}
+	
 	private void waitUntilFinished(DeploymentResult result) throws DeployerException {
 		result.getStatus(); // wait for operation to finish
 	}



More information about the jbosstools-commits mailing list