[jboss-cvs] JBossAS SVN: r112173 - branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 30 18:21:51 EDT 2011
Author: bmaxwell
Date: 2011-08-30 18:21:51 -0400 (Tue, 30 Aug 2011)
New Revision: 112173
Modified:
branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java
Log:
[JBPAPP6716] updating testcase with more tests
Modified: branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java 2011-08-30 19:48:59 UTC (rev 112172)
+++ branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java 2011-08-30 22:21:51 UTC (rev 112173)
@@ -18,11 +18,18 @@
package org.jboss.test.deployment;
import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
+import java.net.URLConnection;
import java.security.Principal;
import java.util.Collection;
+import java.util.Date;
+import java.util.Properties;
import javax.management.JMX;
import javax.management.MBeanServerConnection;
@@ -32,6 +39,7 @@
import org.jboss.mx.util.ObjectNameFactory;
import org.jboss.security.SecurityAssociation;
import org.jboss.security.SimplePrincipal;
+import org.jboss.system.server.ServerConfigImplMBean;
import org.jboss.test.JBossTestCase;
/**
@@ -44,8 +52,12 @@
public class JBPAPP6716UnitTestCase extends JBossTestCase
{
private MainDeployerMBean deployer;
+ private ServerConfigImplMBean serverInfo;
private URL dummyUrl;
- private String JBOSS_HOME;
+ private URL dummyIndexUrl;
+ private String hostname;
+ private String JBOSS_HOME;
+ private String JBOSS_DEPLOY;
private Object[] previousSecurity = new Object[2];
public JBPAPP6716UnitTestCase(String name) throws Exception
@@ -58,12 +70,25 @@
super.setUp();
setSecurity(new SimplePrincipal("admin"), "admin");
+
dummyUrl = getDeployURL("dummy.war");
+
MBeanServerConnection server = getServer();
+
ObjectName objectName = ObjectNameFactory.create("jboss.system:service=MainDeployer");
deployer = JMX.newMBeanProxy(server, objectName, MainDeployerMBean.class);
+ objectName = ObjectNameFactory.create("jboss.system:type=ServerConfig");
+ serverInfo = JMX.newMBeanProxy(server, objectName, ServerConfigImplMBean.class);
+
JBOSS_HOME = System.getProperty("jbosstest.dist");
+
+ // find the jboss config being run for this test
+ File deployDir = new File(serverInfo.getServerHomeDir(), "deploy");
+ JBOSS_DEPLOY = deployDir.getAbsolutePath();
+
+ hostname = System.getProperty("jbosstest.server.host");
+ dummyIndexUrl = new URL("http://" + hostname + ":8080/dummy/index.html");
}
protected void tearDown() throws Exception
@@ -93,67 +118,60 @@
* isDeployed(URL)
*
*/
- public void testDeployNTimes() throws Exception
+ public void testDeployUnDeployReDeployIsDeployed() throws Exception
{
String dummyUrlString = dummyUrl.toExternalForm();
- //int maxNum = (int)((Math.random()*10) + 1);
- int maxNum = 1;
-
- log.info("+++ testDeployNTimes");
- log.info("will deploy "+maxNum+" times");
-
- for (int tries = 0; tries < maxNum; tries++)
+
+ log.info("+++ testDeployUnDeployReDeployIsDeployed");
+
+ try
{
- log.info("Test iteration "+tries);
-
- try
- {
- //Deploy & undeploy with URL
- deployer.deploy(dummyUrl);
- assertTrue("Failed to deploy URL", isDeployed(dummyUrl, false));
+ //Deploy & undeploy with URL
+ deployer.deploy(dummyUrl);
+ assertTrue("Failed to deploy URL", isDeployed(dummyUrl, false));
- deployer.undeploy(dummyUrl);
- assertTrue(dummyUrlString + " is not deployed when it should be", !isDeployed(dummyUrl, false));
+ deployer.undeploy(dummyUrl);
+ assertTrue(dummyUrlString + " is not deployed when it should be", !isDeployed(dummyUrl, false));
- //Deploy & undeploy with String
- deployer.deploy(dummyUrlString);
- assertTrue(isDeployed(dummyUrl, true));
+ //Deploy & undeploy with String
+ deployer.deploy(dummyUrlString);
+ assertTrue(isDeployed(dummyUrl, true));
- deployer.undeploy(dummyUrlString);
- assertTrue(!isDeployed(dummyUrl, true));
+ deployer.undeploy(dummyUrlString);
+ assertTrue(!isDeployed(dummyUrl, true));
- //Redploy
- deployer.deploy(dummyUrl);
- assertTrue(isDeployed(dummyUrl, false));
+ //Redploy
+ deployer.deploy(dummyUrl);
+ assertTrue(isDeployed(dummyUrl, false));
- //With URL
- deployer.redeploy(dummyUrl);
- assertTrue(isDeployed(dummyUrl, false));
+ //With URL
+ deployer.redeploy(dummyUrl);
+ assertTrue(isDeployed(dummyUrl, false));
- //With String
- deployer.redeploy(dummyUrlString);
- assertTrue(isDeployed(dummyUrl, true));
- }
- catch (Exception e)
+ //With String
+ deployer.redeploy(dummyUrlString);
+ assertTrue(isDeployed(dummyUrl, true));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+ finally
+ {
+ try
{
- e.printStackTrace();
- super.fail("Caught exception, message: " + e.getMessage());
+ //make sure it's undeployed before moving on
+ deployer.undeploy(dummyUrl);
}
- finally
+ catch(Exception ignore)
{
- try
- {
- //make sure it's undeployed before moving on
- deployer.undeploy(dummyUrl);
- }
- catch(Exception ignore)
- {
- //ignore
- }
+ //ignore
}
}
}
+
public void testTwiddle()
{
// run commands and check result
@@ -219,6 +237,84 @@
cleanUp();
}
}
+
+ public void testDeploymentsInDeployDirectory()
+ {
+ File dummyWarFile = new File(JBOSS_DEPLOY,"dummy.war");
+ try
+ {
+ // copy dummy.war to deploy directory
+ copyUrlToFile(dummyUrl, dummyWarFile);
+
+ // wait 1 second for deployment, max of 5 seconds, then fail
+ int attempts = 0;
+ do
+ {
+ Thread.sleep(1000);
+ attempts++;
+ } while (deployer.isDeployed(dummyWarFile.getAbsolutePath()) == false && attempts < 5);
+
+ if(attempts >= 5)
+ {
+ fail("Failed to deploy: " + dummyWarFile.getAbsolutePath() + " waited 5 seconds and it has not been deployed");
+ }
+
+ // call undeploy, confirm dummy.war file is still in deploy dir and that it is not running, else fail
+ log.info("call undeploy, confirm dummy.war file is still in deploy dir and that it is not running, else fail");
+ deployer.undeploy(dummyWarFile.getAbsolutePath());
+
+ if( ! dummyWarFile.exists() )
+ {
+ fail("The file: " + dummyWarFile.getAbsolutePath() + " should exist, undeploy should have not removed it from: " + JBOSS_DEPLOY);
+ }
+ if( isDummyRunning() )
+ {
+ fail("The url: " + dummyWarFile.getAbsolutePath() + " should not be accessible, because dummy.war should be stopped, after the previous undeploy call");
+ }
+
+ // call deploy, confirm dummy.war is started again and is accessible
+ deployer.deploy(dummyWarFile.getAbsolutePath());
+
+ if(deployer.isDeployed(dummyWarFile.getAbsolutePath()) == false)
+ {
+ fail("Failure: " + dummyWarFile.getAbsolutePath() + " should be deployed and started");
+ }
+ if( ! isDummyRunning() )
+ {
+ fail("The url: " + dummyWarFile.getAbsolutePath() + " should be accessible, because dummy.war should have been started again by the previous deploy call");
+ }
+ }
+ catch(Exception e)
+ {
+ fail(e.getMessage());
+ }
+ finally
+ {
+ // remove dummy.war from deploy directory
+ if(dummyWarFile.delete() == false)
+ {
+ fail("Failed to remove: " + dummyWarFile.getAbsolutePath() + " test deployment from: " + JBOSS_DEPLOY);
+ }
+ int attempts = 0;
+ try
+ {
+ do
+ {
+ Thread.sleep(1000);
+ attempts++;
+ } while (deployer.isDeployed(dummyWarFile.getAbsolutePath()) == true && attempts < 5);
+
+ if(attempts >= 5)
+ {
+ fail("Failed to undeploy: " + dummyWarFile.getAbsolutePath() + " waited 5 seconds and it has not been undeployed");
+ }
+ }
+ catch(Exception e)
+ {
+
+ }
+ }
+ }
private void cleanUp()
{
@@ -254,28 +350,22 @@
cleanUp();
}
}
-
- public void testListDeployed() throws Exception
+
+ // this tests methods: listDeployed, listDeployedModules
+ public void testListDeployedListDeployedModules() throws Exception
{
- log.info("+++ testListDeployed");
+ log.info("+++ testListDeployedListDeployedModules");
try
{
- boolean fail = true;
+ // deploy the dummy.war & make sure it is deployed
deployer.deploy(dummyUrl);
assertTrue("listDeployedAsString does not contain: " + dummyUrl, deployer.listDeployedAsString().contains(dummyUrl.toExternalForm()));
- Collection collection = deployer.listDeployed();
- for(Object o : collection)
- {
- log.info(o.toString());
- if(o.toString().contains(dummyUrl.toExternalForm()))
- {
- log.info(o.toString() + " matched " + dummyUrl);
- fail = false;
- break;
- }
- }
- if(fail)
+
+ if(collectionContains(deployer.listDeployed(), dummyUrl.toExternalForm()) == false)
fail("listDeployed does not contain: " + dummyUrl);
+
+ if(collectionContains(deployer.listDeployedModules(), dummyUrl.toExternalForm()) == false)
+ fail("listDeployedModules does not contain: " + dummyUrl);
}
catch (Exception e)
{
@@ -366,4 +456,92 @@
child.destroy();
}
}
-}
+
+ private void copyUrlToFile(URL url, File file) throws Exception
+ {
+ log.info("Copying url: " + url + " to file: " + file);
+ InputStream is = url.openStream();
+ FileOutputStream fos = new FileOutputStream(file);
+
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = is.read(buf)) > 0)
+ {
+ fos.write(buf, 0, len);
+ }
+
+ is.close();
+ fos.close();
+ }
+
+ private boolean collectionContains(Collection collection, String string)
+ {
+ for(Object o : collection)
+ {
+ log.info(o.toString());
+ if(o.toString().contains(string))
+ {
+ log.debug(o.toString() + " matched " + string);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isDummyRunning()
+ {
+ try
+ {
+ String content = readURL(dummyIndexUrl, false);
+ log.info("dummy.war content: " + content);
+ if(content != null && content.contains("Test html"))
+ {
+ log.info("dummy.war is running at: " + dummyIndexUrl);
+ return true;
+ }
+ }
+ catch(Exception e)
+ {
+ fail("Failed to test if dummy.war is running: " + e.getMessage());
+ }
+
+ log.info("dummy.war is not running at: " + dummyIndexUrl);
+ return false;
+ }
+
+ private String readURL(URL url, boolean failOnException)
+ {
+ BufferedReader in = null;
+ try
+ {
+ URLConnection uc = url.openConnection();
+ in = new BufferedReader( new InputStreamReader(uc.getInputStream()));
+
+ String inputLine = in.readLine();
+ return inputLine;
+ }
+ catch (Exception e)
+ {
+ if(failOnException)
+ {
+ log.error("Error occured trying to read: " + url, e);
+ fail("Unable to read url: " + url);
+ }
+ return null;
+ }
+ finally
+ {
+ if ( in != null )
+ {
+ try
+ {
+ in.close();
+ }
+ catch (Exception e)
+ {
+ // eat it
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list