[jboss-cvs] JBossAS SVN: r112127 - 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
Thu Aug 25 12:24:17 EDT 2011
Author: ShaunA
Date: 2011-08-25 12:24:17 -0400 (Thu, 25 Aug 2011)
New Revision: 112127
Added:
branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java
Log:
Initial unit test
Added: 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 (rev 0)
+++ branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java 2011-08-25 16:24:17 UTC (rev 112127)
@@ -0,0 +1,387 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, 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.test.deployment;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.net.URL;
+import java.nio.channels.FileChannel;
+import java.sql.Connection;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import javax.management.MBeanException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+
+import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.services.deployment.MBeanData;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * JBPAPP-6716 MainDeployer tests
+ *
+ * @author Shaun Appleton
+ */
+public class JBPAPP6716UnitTestCase extends JBossTestCase
+{
+
+ private ObjectName mainDeployer = ObjectNameFactory
+ .create("jboss.system:service=MainDeployer");
+
+ public JBPAPP6716UnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Try to get a list of deployments
+ */
+
+
+ public void testRedeployURL() throws Exception
+ {
+ log.info("+++ testRedeployURL");
+
+ MBeanServerConnection server = getServer();
+
+ String[] paramTypes = {"java.net.URL"};
+ Object[] inputParams = new Object[1];
+ //inputParams[0] = new URL("file:///home/YOUR-USER/temp/test.ear");
+
+ inputParams[0] = new URL("file:///home/sappleto/jbossBuilds/JBPAPP_5_1/testsuite/output/lib/dummy.war"); //TODO change to use resource available in JBPAPP-xyz branch
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "redeploy", inputParams, paramTypes)); // just output at the moment
+
+ assertTrue(((Boolean)server.invoke(mainDeployer, "isDeployed", inputParams, paramTypes)).booleanValue()); // did it deploy?
+
+ assertTrue(isDeployed(server, inputParams)); // did it deploy?
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+ public void testDeployNTimes() throws Exception
+ {
+
+
+ int maxNum = (int)((Math.random()*10) + 1);
+
+ log.info("+++ testDeployNTimes");
+ log.info("will deploy "+maxNum+" times");
+
+ for (int tries = 0; tries < maxNum; tries++)
+ {
+ log.info("redeployment number:"+tries);
+ // sleep for 3 secs
+ Thread.sleep(3000);
+
+ MBeanServerConnection server = getServer();
+
+ String[] paramTypes = {"java.net.URL"};
+ Object[] inputParams = new Object[1];
+ //inputParams[0] = new URL("file:///home/YOUR-USER/temp/test.ear");
+
+ inputParams[0] = new URL("file:///home/sappleto/jbossBuilds/JBPAPP_5_1/testsuite/output/lib/dummy.war"); //TODO change to use resource available in JBPAPP-xyz branch
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "deploy", inputParams, paramTypes)); // just output at the moment
+
+ assertTrue(((Boolean)server.invoke(mainDeployer, "isDeployed", inputParams, paramTypes)).booleanValue()); // did it deploy?
+
+ assertTrue(isDeployed(server, inputParams)); // did it deploy?
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+ }
+
+
+ public void testReDeployNTimes() throws Exception
+ {
+
+
+ int maxNum = (int)((Math.random()*10) + 1);
+
+ log.info("+++ testReDeployNTimes");
+ log.info("will redeploy "+maxNum+" times");
+
+ for (int tries = 0; tries < maxNum; tries++)
+ {
+ log.info("redeployment number:"+tries);
+ // sleep for 3 secs
+ Thread.sleep(3000);
+
+ MBeanServerConnection server = getServer();
+
+ String[] paramTypes = {"java.net.URL"};
+ Object[] inputParams = new Object[1];
+ //inputParams[0] = new URL("file:///home/YOUR-USER/temp/test.ear");
+
+ inputParams[0] = new URL("file:///home/sappleto/jbossBuilds/JBPAPP_5_1/testsuite/output/lib/dummy.war"); //TODO change to use resource available in JBPAPP-xyz branch
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "redeploy", inputParams, paramTypes)); // just output at the moment
+
+ assertTrue(((Boolean)server.invoke(mainDeployer, "isDeployed", inputParams, paramTypes)).booleanValue()); // did it deploy?
+
+ assertTrue(isDeployed(server, inputParams)); // did it deploy?
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+ }
+ public void testRedeployString() throws Exception
+ {
+ log.info("+++ testRedeployString");
+
+ MBeanServerConnection server = getServer();
+
+ String [] string = new String[2];
+ string[0]="file:///../../../../default/deploy/jboss-seam-numberguess.ear/"; //TODO change to a better resource
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "redeploy", string, null)); // just output at the moment
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+ public void testUndeployString() throws Exception
+ {
+ log.info("+++ testUndeployString");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "listDeployedAsString", null, null)); // just output at the moment
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+ public void testUndeployURL() throws Exception
+ {
+ log.info("+++ testUndeployURL");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "listDeployedAsString", null, null)); // just output at the moment
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+
+ public void testDeployString() throws Exception
+ {
+ log.info("+++ testDeployString");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "listDeployedAsString", null, null)); // just output at the moment
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+ public void testDeployURL() throws Exception
+ {
+ log.info("+++ testDeployURL");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "listDeployedAsString", null, null)); // just output at the moment
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+
+
+
+ public void isDeployedString() throws Exception
+ {
+ log.info("+++ testisDeployedURL");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "listDeployedAsString", null, null)); // just output at the moment
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+ public void isDeployedURL() throws Exception
+ {
+ log.info("+++ testisDeployedURL");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ log.info (server.invoke(mainDeployer, "listDeployedAsString", null, null)); // just output at the moment
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+ public void testListDeployedAsString() throws Exception
+ {
+ log.info("+++ testListDeployedAsString");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ assertEquals("<pre>[]</pre>", server.invoke(mainDeployer, "listDeployedAsString", null, null));
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+ }
+
+ public void testListDeployed() throws Exception
+ {
+ log.info("+++ testListDeployed");
+
+ MBeanServerConnection server = getServer();
+
+ try
+ {
+
+ assertEquals("[]", server.invoke(mainDeployer, "listDeployed", null, null));
+
+ }
+ catch (Exception e)
+ {
+ super.fail("Caught exception, message: " + e.getMessage());
+ }
+
+ }
+
+ /**
+ * Verifies that a given module is acutally deployed. Waits for a while,
+ * checking every few seconds, to see if the module has deployed yet.
+ *
+ * @param server
+ * User to invoke methods on the dpeloyment service.
+ * @param module
+ * The name of the module (must include the suffix).
+ * @return
+ */
+ private boolean isDeployed(MBeanServerConnection server, Object[] module)
+ throws Exception
+ {
+ Boolean isDeployed = new Boolean(false);
+ for (int tries = 0; tries < 5; tries++)
+ {
+ // sleep for 3 secs
+ Thread.sleep(3000);
+ isDeployed = (Boolean) server.invoke(mainDeployer, "isDeployed", module , new String[] { "java.net.URL" });
+
+ if (isDeployed.booleanValue())
+ {
+ break;
+ }
+ }
+ log.info("Module '" + module + "' deployed: " + isDeployed);
+ return isDeployed.booleanValue();
+ }
+
+}
More information about the jboss-cvs-commits
mailing list