[jboss-cvs] JBossAS SVN: r86742 - trunk/testsuite/src/main/org/jboss/test/deployers.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Apr 3 08:31:01 EDT 2009


Author: emuckenhuber
Date: 2009-04-03 08:31:01 -0400 (Fri, 03 Apr 2009)
New Revision: 86742

Added:
   trunk/testsuite/src/main/org/jboss/test/deployers/DeploymentManagerUnitTestCase.java
Log:
add deployment manager testcase

Added: trunk/testsuite/src/main/org/jboss/test/deployers/DeploymentManagerUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/DeploymentManagerUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/DeploymentManagerUnitTestCase.java	2009-04-03 12:31:01 UTC (rev 86742)
@@ -0,0 +1,286 @@
+/*
+ * 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.deployers;
+
+import java.util.Collection;
+
+import javax.naming.InitialContext;
+
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.test.JBossTestCase;
+
+/**
+ * Basic DeploymentManager test.
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DeploymentManagerUnitTestCase extends JBossTestCase
+{
+   /** A basic failing deployment. */
+   final static String FAILING_DEPLOYMENT = "deployers-failing-jboss-beans.xml";
+   /** A empty deployment, this will deploy ok. */
+   final static String EMTPY_DEPLOYMENT = "deployers-empty-jboss-beans.xml";
+   /** A simple nested deployment. */
+   final static String NESTED_DEPLOYMENT = "profileservice-datasource.ear";
+   
+   /** The deployers target profile. */
+   final static ProfileKey deployersKey = new ProfileKey("deployers");
+   
+   /** The deployment manager. */
+   private DeploymentManager deployMgr;
+
+   public DeploymentManagerUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * Test the available profiles.
+    * 
+    * @throws Exception
+    */
+   public void testAvaiableProfiles() throws Exception
+   {
+      Collection<ProfileKey> keys = getDeploymentManager().getProfiles();
+      assertNotNull(keys);
+      log.debug("available keys: " + keys);
+      keys.contains(new ProfileKey("applications"));
+      keys.contains(deployersKey);
+   }
+   
+   /**
+    * Test a override of the applications, without
+    * removing/stopping them before.
+    * 
+    * @throws Exception
+    */
+   public void testDistributeOverride() throws Exception
+   {
+      try
+      {
+         // 
+         DeploymentProgress start = distributeAndStart(NESTED_DEPLOYMENT, true);
+         assertComplete(start);
+         //
+         start = distributeAndStart(NESTED_DEPLOYMENT, true);
+         assertComplete(start);
+      }
+      finally
+      {
+         stopAndRemove(new String[] { NESTED_DEPLOYMENT });
+      }
+   }
+   
+   /**
+    * Basic copyContent test to the default location.
+    * 
+    * @throws Exception
+    */
+   public void testCopyContent() throws Exception
+   {
+      try
+      {
+         // failed 
+         deployFailed(true);
+         // complete
+         deployEmpty(true);
+         // Test redeploy
+         redeployCheckComplete(EMTPY_DEPLOYMENT);
+         // TODO implement prepare 
+         prepareCheckComplete(EMTPY_DEPLOYMENT);
+      }
+      finally
+      {
+         stopAndRemove(new String[]
+            { FAILING_DEPLOYMENT, EMTPY_DEPLOYMENT } );
+      }
+   }
+   
+   /**
+    * Basic noCopyContent test.
+    * 
+    * @throws Exception
+    */
+   public void testNoCopyContent() throws Exception
+   {
+      try
+      {
+         // failed 
+         deployFailed(false);
+         // complete
+         deployEmpty(false);
+         // test redeploy
+         redeployCheckComplete(EMTPY_DEPLOYMENT);
+         // TODO implement prepare
+         prepareCheckComplete(EMTPY_DEPLOYMENT);
+      }
+      finally
+      {
+         stopAndRemove(new String[]
+            { FAILING_DEPLOYMENT, EMTPY_DEPLOYMENT } );
+      }
+   }
+   
+   /**
+    * Test copyContent to the deployers target profile.
+    * 
+    * @throws Exception
+    */
+   public void testDepoyersDir() throws Exception
+   {
+      getDeploymentManager().loadProfile(deployersKey);
+      try
+      {
+         // failed 
+         deployFailed(true);
+         // complete
+         deployEmpty(true);
+         // Test redeploy
+         redeployCheckComplete(EMTPY_DEPLOYMENT);
+      }
+      finally
+      {
+         try
+         {
+            stopAndRemove(new String[]
+               { FAILING_DEPLOYMENT, EMTPY_DEPLOYMENT } );
+         }
+         finally
+         {
+            // Make sure that we release the profile
+            getDeploymentManager().releaseProfile();
+         }
+      }
+   }
+
+   void deployFailed(boolean isCopyContent) throws Exception
+   {
+      DeploymentProgress start = distributeAndStart(FAILING_DEPLOYMENT, isCopyContent);
+      assertFailed(start);      
+   }
+   
+   void deployEmpty(boolean isCopyContent) throws Exception
+   {
+      DeploymentProgress start = distributeAndStart(EMTPY_DEPLOYMENT, isCopyContent);
+      assertComplete(start);      
+   }
+   
+   DeploymentProgress distributeAndStart(String deploymentName, boolean copyContent) throws Exception
+   {
+      // The deployment manager
+      DeploymentManager deployMgr = getDeploymentManager();
+      
+      // Distribute
+      DeploymentProgress distribute = deployMgr.distribute(deploymentName, 
+            getDeployURL(deploymentName), copyContent);
+      distribute.run();
+      // Distribute always have to work
+      assertComplete(distribute);
+      
+      // Get the repository names
+      String[] uploadedNames = distribute.getDeploymentID().getRepositoryNames();
+      assertNotNull(uploadedNames);
+      
+      // Start
+      DeploymentProgress start = deployMgr.start(uploadedNames);
+      start.run();
+      // Return the start deployment progress
+      return start;
+   }
+   
+   void redeployCheckComplete(String name) throws Exception
+   {
+      // The deployment manager
+      DeploymentManager deployMgr = getDeploymentManager();
+      
+      // Redeploy
+      DeploymentProgress redeploy = deployMgr.redeploy(name);
+      redeploy.run();
+      assertComplete(redeploy);
+   }
+   
+   void prepareCheckComplete(String name) throws Exception
+   {
+      // The deployment manager
+      DeploymentManager deployMgr = getDeploymentManager();
+      
+      // Prepare
+      DeploymentProgress prepare = deployMgr.prepare(name);
+      prepare.run();
+      assertComplete(prepare);
+   }
+   
+   void stopAndRemove(String[] names) throws Exception
+   {
+      // The deployment manager
+      DeploymentManager deployMgr = getDeploymentManager();
+      
+      try
+      {
+         DeploymentProgress stop = deployMgr.stop(names);
+         stop.run();
+         assertComplete(stop);
+      }
+      finally
+      {
+         DeploymentProgress remove = deployMgr.remove(names);
+         remove.run();
+         assertComplete(remove);
+      }
+   }
+   
+   void assertFailed(DeploymentProgress progress) throws Exception
+   {
+      assertFalse(progress.getDeploymentStatus().isCompleted());
+      assertTrue(progress.getDeploymentStatus().isFailed());
+   }
+   
+   void assertComplete(DeploymentProgress progress) throws Exception
+   {
+      if(progress.getDeploymentStatus().isFailed())
+      {
+         throw new RuntimeException("deployment failed.", progress.getDeploymentStatus().getFailure());
+      }
+      //
+      assertTrue(progress.getDeploymentStatus().isCompleted());
+   }
+   
+   DeploymentManager getDeploymentManager() throws Exception
+   {
+      if(this.deployMgr == null)
+      {
+         this.deployMgr = getProfileService().getDeploymentManager();
+      }
+      return deployMgr;
+   }
+   
+   ProfileService getProfileService() throws Exception
+   {
+      InitialContext ctx = getInitialContext();
+      return (ProfileService) ctx.lookup("ProfileService");
+   } 
+   
+}




More information about the jboss-cvs-commits mailing list