portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wea...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/deployment TestSimpleDeployment.java
Date Thu, 15 Jan 2004 16:15:23 GMT
weaver      2004/01/15 08:15:23

  Modified:    portal/src/test/org/apache/jetspeed/deployment
                        TestSimpleDeployment.java
  Log:
  - added proper setUp and tearDown procedures to make sure the test has
    cleaned up after itself.
  
  - added testing for auto deploying portlet web applications.
  
  Revision  Changes    Path
  1.2       +86 -30    jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/deployment/TestSimpleDeployment.java
  
  Index: TestSimpleDeployment.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/deployment/TestSimpleDeployment.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestSimpleDeployment.java	14 Jan 2004 19:35:52 -0000	1.1
  +++ TestSimpleDeployment.java	15 Jan 2004 16:15:23 -0000	1.2
  @@ -7,18 +7,26 @@
   package org.apache.jetspeed.deployment;
   
   import java.io.File;
  +import java.io.IOException;
   import java.util.HashMap;
   
  +import junit.framework.AssertionFailedError;
   import junit.framework.Test;
   import junit.framework.TestSuite;
   
  +import org.apache.commons.configuration.Configuration;
   import org.apache.jetspeed.Jetspeed;
   import org.apache.jetspeed.deployment.fs.FileSystemScanner;
   import org.apache.jetspeed.deployment.fs.JARObjectHandlerImpl;
   import org.apache.jetspeed.deployment.impl.DeployDecoratorEventListener;
  +import org.apache.jetspeed.deployment.impl.DeployPortletAppEventListener;
   import org.apache.jetspeed.deployment.simpleregistry.SimpleRegistry;
   import org.apache.jetspeed.deployment.simpleregistry.impl.InMemoryRegistryImpl;
  +import org.apache.jetspeed.registry.JetspeedPortletRegistry;
   import org.apache.jetspeed.test.JetspeedTest;
  +import org.apache.jetspeed.tools.pamanager.FileSystemPAM;
  +import org.apache.jetspeed.tools.pamanager.PortletApplicationException;
  +import org.apache.jetspeed.util.DirectoryUtils;
   
   /**
    * <p>
  @@ -31,6 +39,17 @@
    */
   public class TestSimpleDeployment extends JetspeedTest
   {
  +    protected static final String TEST_PORTLET_APP_NAME = "HW_App";
  +    protected String webAppsDir;
  +
  +    protected String delpoySrc;
  +
  +    protected File deployRootFile;
  +
  +    protected String testDb;
  +
  +    protected String deployRoot;
  +
       /**
        * @param testName
        */
  @@ -61,55 +80,92 @@
           return new TestSuite(TestSimpleDeployment.class);
       }
   
  -    public void testDecorators() throws Exception
  +    public void overrideProperties(Configuration properties)
  +    {
  +        super.overrideProperties(properties);
  +    }
  +
  +    public void testDeploy() throws Exception
       {
  -        String deploySrc = new File("./test/deployment/deploy").getCanonicalPath();
  -        File deployRootFile = new File("./test/deployment/templates/decorator");
  -        String deployRoot = deployRootFile.getCanonicalPath();
  +
  +		
           if (deployRootFile.exists())
           {
  -        	assertTrue("Unable to clean deployment directory.", deleteDir(deployRootFile));
  +            assertTrue("Unable to clean deployment directory.", DirectoryUtils.rmdir(deployRootFile));
           }
  -        else 
  +        else
           {
  -        	deployRootFile.mkdirs();			
  +            deployRootFile.mkdirs();
           }
  -        System.out.println("Deployment src: " + deploySrc);
  +        System.out.println("Deployment src: " + delpoySrc);
           DeploymentEventDispatcher ded = new DeploymentEventDispatcher(deployRoot);
           SimpleRegistry registry = new InMemoryRegistryImpl();
           DeployDecoratorEventListener ddel = new DeployDecoratorEventListener(registry);
  +        DeployPortletAppEventListener dpal = new DeployPortletAppEventListener(webAppsDir,
testDb);
           ded.addDeploymentListener(ddel);
  +        ded.addDeploymentListener(dpal);
           HashMap handlers = new HashMap();
           handlers.put("jar", JARObjectHandlerImpl.class);
  -        FileSystemScanner fScanner = new FileSystemScanner(deploySrc, handlers, ded, 500,
"decorator.properties");
  +        handlers.put("war", JARObjectHandlerImpl.class);
  +        FileSystemScanner fScanner = new FileSystemScanner(delpoySrc, handlers, ded, 500,
"decorator.properties");
           fScanner.start();
           Thread.sleep(10000);
  -        fScanner.safeStop();
  -        
  -        File decoratorVm = new File(deployRoot+File.separator+"html"+File.separator+"portletstd"+File.separator+"decorator.vm");
  -        
  -        assertTrue(decoratorVm.getCanonicalPath()+" was not created!", decoratorVm.exists());
  -        
  -        
  +        fScanner.safeStop();        
  +
  +        File decoratorVm =
  +            new File(deployRoot + File.separator + "html" + File.separator + "portletstd"
+ File.separator + "decorator.vm");
  +
  +        assertTrue(decoratorVm.getCanonicalPath() + " was not created!", decoratorVm.exists());
  +        assertNotNull(TEST_PORTLET_APP_NAME+" was not registered into the portlet registery.",
JetspeedPortletRegistry.getPortletApplicationByIndetifier(TEST_PORTLET_APP_NAME));
  +
       }
   
  -    public static boolean deleteDir(File dir)
  +
  +
  +    /**
  +     * @see junit.framework.TestCase#setUp()
  +     */
  +    public void setUp()
       {
  -        if (dir.isDirectory())
  +	
  +		try
           {
  -            String[] children = dir.list();
  -            for (int i = 0; i < children.length; i++)
  -            {
  -                boolean success = deleteDir(new File(dir, children[i]));
  -                if (!success)
  -                {
  -                    return false;
  -                }
  -            }
  +			super.setUp();
  +		    // set up test data
  +            delpoySrc = new File("./test/deployment/deploy").getCanonicalPath();
  +            deployRootFile = new File("./test/deployment/templates/decorator");
  +            deployRoot = deployRootFile.getCanonicalPath();
  +            webAppsDir = new File("./test/deployment/webapps").getCanonicalPath();
  +            testDb = new File("./test/db/hsql/Registry").getCanonicalPath();
  +            // remove any prior left overs
  +			FileSystemPAM pam = new FileSystemPAM();
  +			pam.undeploy(webAppsDir, TEST_PORTLET_APP_NAME);	
           }
  +        catch (Exception e)
  +        {
  +			e.printStackTrace();
  +            throw new AssertionFailedError("Unable to set up test environment "+e.toString());
         
  +        }
  +        
  +    }
   
  -        // The directory is now empty so delete it
  -        return dir.delete();
  +    /**
  +     * @see junit.framework.TestCase#tearDown()
  +     */
  +    public void tearDown()
  +    {
  +        
  +        super.tearDown();
  +		FileSystemPAM pam = new FileSystemPAM();
  +		try
  +        {
  +            pam.undeploy(webAppsDir, TEST_PORTLET_APP_NAME);
  +        }
  +        catch (PortletApplicationException e)
  +        {            
  +            e.printStackTrace();
  +        }
  +		
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message