[jboss-cvs] JBossAS SVN: r112146 - 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
Mon Aug 29 00:37:49 EDT 2011


Author: bmaxwell
Date: 2011-08-29 00:37:49 -0400 (Mon, 29 Aug 2011)
New Revision: 112146

Modified:
   branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java
Log:
[JBPAPP-6716] reset security 

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-28 06:12:56 UTC (rev 112145)
+++ branches/JBPAPP_5_1_JBPAPP-6716/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java	2011-08-29 04:37:49 UTC (rev 112146)
@@ -17,64 +17,87 @@
  */
 package org.jboss.test.deployment;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
 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 java.security.Principal;
+import java.util.Collection;
 
 import javax.management.JMX;
-import javax.management.MBeanException;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
-import javax.naming.InitialContext;
-import javax.sql.DataSource;
 
+import org.jboss.deployment.MainDeployerMBean;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.security.SecurityAssociation;
 import org.jboss.security.SimplePrincipal;
-import org.jboss.security.SecurityAssociation;
-import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
-import org.jboss.mx.util.ObjectNameFactory;
-import org.jboss.services.deployment.MBeanData;
 import org.jboss.test.JBossTestCase;
-import org.jboss.deployment.MainDeployerMBean;
 
 /**
  * JBPAPP-6716 MainDeployer tests
  * 
  * @author Shaun Appleton
+ * @author bmaxwell
+ * @author klape
  */
 public class JBPAPP6716UnitTestCase extends JBossTestCase
 {
    private MainDeployerMBean deployer;
    private URL dummyUrl;
+   private String JBOSS_HOME;   
+   private Object[] previousSecurity = new Object[2];
 
    public JBPAPP6716UnitTestCase(String name) throws Exception
    {
       super(name);
-      SecurityAssociation.setPrincipal(new SimplePrincipal("admin"));
-      SecurityAssociation.setCredential("admin");
    }
 
    protected void setUp() throws Exception
    {
       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);
+      
+      JBOSS_HOME = System.getProperty("jbosstest.dist");
    }
+      
+   protected void tearDown() throws Exception
+   {   
+      super.tearDown();
+      setSecurity((Principal) previousSecurity[0], previousSecurity[1]);      
+   }
+      
+   private void setSecurity(Principal username, Object password)
+   {
+      previousSecurity[0] = SecurityAssociation.getPrincipal();
+      previousSecurity[1] = SecurityAssociation.getCredential();
+      
+      SecurityAssociation.setPrincipal(username);
+      SecurityAssociation.setCredential(password);       
+   }
    
    //***** Deploy Tests *****//
 
+   /* this tests these methods:
+    * deploy(URL)
+    * deploy(String)
+    * undeploy(URL)
+    * undeploy(String)
+    * redeploy(URL)
+    * redeploy(String)
+    * isDeployed(URL)
+    *
+    */
    public void testDeployNTimes() throws Exception
    {
       String dummyUrlString = dummyUrl.toExternalForm();
-      int maxNum = (int)((Math.random()*10) + 1);
+      //int maxNum = (int)((Math.random()*10) + 1);
+      int maxNum = 1;
       
       log.info("+++ testDeployNTimes");
       log.info("will deploy "+maxNum+" times");
@@ -130,7 +153,85 @@
          }
       }
    }
- 
+   
+   public void testTwiddle()
+   {
+      // run commands and check result
+//      
+//      /bin/twiddle.sh -u admin -p admin invoke "jboss.system:service=MainDeployer" listDeployed > twiddleListTestResults.txt
+//      <jboss_home>/bin/twiddle.sh -u admin -p admin invoke "jboss.system:service=MainDeployer" listDeployedAsString >> twiddleListTestResults.txt
+//      <jboss_home>/bin/twiddle.sh -u admin -p admin invoke "jboss.system:service=MainDeployer" listDeployedModules >> twiddleListTestResults.txt
+//      <jboss_home>/bin/twiddle.sh -u admin -p admin invoke "jboss.system:service=MainDeployer" listDeployedModulesSimpleNames >> twiddleListTestResults.txt
+//      twiddle("-u admin -p admin invoke \"jboss.system:service=MainDeployer\" listDeployed", "");
+      
+      // this was a test to confirm exit code failure would occur
+//     twiddle(invoke + "undeploy "+ "file:/tmp/invalid.war", null);
+      
+      String invoke = "-u admin -p admin invoke jboss.system:service=MainDeployer ";
+      String[] deployments = new String[] 
+                                        { 
+            dummyUrl.toExternalForm(), 
+            dummyUrl.getPath() 
+            };
+      try
+      {
+         // test file:/path/to/dummy.war and /path/to/dummy.war
+         for(String deployment : deployments)
+         {
+            log.info("testing: " + deployment);
+            
+            // deploy(String)
+            twiddle(invoke + "deploy " + deployment, null);
+            
+            // isDeployed(String)
+            twiddle(invoke + "isDeployed " + deployment, "true");
+            
+            // listDeployedAsString()
+            twiddle(invoke + "listDeployedAsString", deployment);
+            
+            // listDeployed()
+            twiddle(invoke + "listDeployed", deployment);
+            
+            // listDeployedModules()
+            twiddle(invoke + "listDeployedModules", deployment);
+            
+            // undeploy(String)
+            twiddle(invoke + "undeploy " + deployment, null);
+      
+            // isDeployed(String)
+            twiddle(invoke + "isDeployed " + deployment, "false");
+            
+            // redeploy(String)
+            twiddle(invoke + "redeploy " + deployment, null);
+            
+            // isDeployed(String)
+            twiddle(invoke + "isDeployed " + deployment, "true");
+            
+            // redeploy(String)
+            twiddle(invoke + "redeploy " + deployment, null);
+   
+            // isDeployed(String)
+            twiddle(invoke + "isDeployed " + deployment, "true");
+         }
+      }
+      finally
+      {
+         cleanUp();
+      }      
+   }
+
+   private void cleanUp()
+   {
+      try
+      {
+         deployer.undeploy(dummyUrl);
+      }
+      catch(Exception e)
+      {
+         // eat it
+      }
+   }
+   
    //***** Listing Methods *****//
 
    public void testListDeployedAsString() throws Exception
@@ -139,26 +240,51 @@
       
       try
       {
-         assertEquals("<pre>[]</pre>", deployer.listDeployedAsString());
+         deployer.deploy(dummyUrl);
+         log.info("calling assert: " + dummyUrl.toExternalForm());
+         log.info(deployer.listDeployedAsString());
+         assertTrue("listDeployedAsString does not contain: " + dummyUrl, deployer.listDeployedAsString().contains(dummyUrl.toExternalForm()));
       }
       catch (Exception e)
       {
          super.fail("Caught exception, message: " + e.getMessage());
       }
+      finally
+      {
+         cleanUp();
+      }
    }
    
    public void testListDeployed() throws Exception
    {
       log.info("+++ testListDeployed");
-      
       try
       {
-         assertEquals("[]", deployer.listDeployed());
+         boolean fail = true;
+         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)
+            fail("listDeployed does not contain: " + dummyUrl);
       }
       catch (Exception e)
       {
          super.fail("Caught exception, message: " + e.getMessage());
       }
+      finally
+      {
+         cleanUp();
+      }
    }
    
    /**
@@ -176,7 +302,7 @@
       for (int tries = 0; tries < 5; tries++)
       {
          // sleep for 3 secs
-         Thread.sleep(3000);
+//         Thread.sleep(3000);
          if(isString)
             isDeployed = deployer.isDeployed(url.toExternalForm());
          else
@@ -186,5 +312,58 @@
             break;
       }
       return isDeployed;
-   }   
+   }
+   
+   private void twiddle(String args, String searchString)
+   {
+      String command = JBOSS_HOME + "/bin/twiddle.sh " + args;      
+      Process child = null;
+      
+      // default to true since searchString may not be checked 
+      boolean pass = true;
+      try
+      {
+         child = Runtime.getRuntime().exec(command, new String[]{"JBOSS_HOME="+JBOSS_HOME}, null);         
+
+         String st;
+         // get input stream from process
+         BufferedReader in = new BufferedReader(new InputStreamReader(child.getInputStream()));
+
+         String output = "";
+         while ((st = in.readLine()) != null)
+         {
+            output = output + st;
+         }
+         in.close();
+
+         // if a searchString is specified, then the output should contain it else pass will be false
+         if (searchString != null)
+         {
+            pass &= output.contains(searchString);
+         }
+
+         // if exit code is not 0, then we also fail
+         pass &= (child.waitFor() == 0);
+         //         pass &= (child.exitValue() == 0);
+
+         if (!pass)
+            fail(command + " failed, exitCode=" + child.exitValue() + " should be 0 and output should contain: "
+                  + searchString + " output:" + output);
+      }
+      catch (IOException ioe)
+      {
+         log.error("twiddle process failed to execute: " + command, ioe);
+         fail("twiddle process failed to execute: " + command);
+      }
+      catch (InterruptedException e)
+      {
+         log.error("twiddle process failed to finish: " + command, e);
+         fail("twiddle process failed to finish: " + command);
+      }
+      finally
+      {
+         if (child != null)
+            child.destroy();
+      }
+   }
 }



More information about the jboss-cvs-commits mailing list