You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by we...@apache.org on 2004/07/02 16:39:05 UTC
cvs commit: jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/deployment TestSimpleDeployment.java
weaver 2004/07/02 07:39:05
Modified: portal/src/test/org/apache/jetspeed/deployment
TestSimpleDeployment.java
Log:
- Changes do to PAM refactoring
- basic sanity tests on VFS added
Revision Changes Path
1.10 +213 -85 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.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestSimpleDeployment.java 23 Jun 2004 18:42:52 -0000 1.9
+++ TestSimpleDeployment.java 2 Jul 2004 14:39:05 -0000 1.10
@@ -7,27 +7,34 @@
package org.apache.jetspeed.deployment;
import java.io.File;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.Iterator;
-import java.util.Locale;
import javax.portlet.Portlet;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.commons.vfs.AllFileSelector;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileType;
+import org.apache.commons.vfs.VFS;
+import org.apache.commons.vfs.impl.StandardFileSystemManager;
import org.apache.jetspeed.components.util.RegistrySupportedTestCase;
-import org.apache.jetspeed.deployment.fs.FileSystemScanner;
-import org.apache.jetspeed.deployment.fs.JARObjectHandlerImpl;
+import org.apache.jetspeed.container.window.PortletWindowAccessor;
+import org.apache.jetspeed.container.window.impl.PortletWindowAccessorImpl;
+import org.apache.jetspeed.deployment.impl.AutoDeploymentManager;
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.factory.JetspeedPortletFactory;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
-import org.apache.jetspeed.test.JetspeedTestSuite;
import org.apache.jetspeed.tools.pamanager.FileSystemPAM;
import org.apache.jetspeed.util.DirectoryUtils;
+import org.apache.jetspeed.util.descriptor.PortletApplicationWar;
import org.apache.pluto.om.portlet.PortletDefinition;
/**
@@ -35,100 +42,135 @@
* TestSimpleDeployment
* </p>
*
- * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
+ * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
* @version $Id$
- *
+ *
*/
public class TestSimpleDeployment extends RegistrySupportedTestCase
{
protected static final String TEST_PORTLET_APP_NAME = "HW_App";
protected String webAppsDir;
- protected String delpoySrc;
+ protected File deploySrc;
protected File deployRootFile;
protected String testDb;
-
- protected String deployRoot;
+ private PortletApplicationWar paWar1;
+ private PortletApplicationWar paWar2;
+ private PortletApplicationWar paWar3;
+ protected File webAppsDirFile;
+ protected File copyFrom;
+ protected StandardFileSystemManager fsManager;
+ protected PortletWindowAccessor windowAccess;
/**
* @param testName
*/
- public TestSimpleDeployment(String testName)
+ public TestSimpleDeployment( String testName )
{
super(testName);
}
/**
* Start the tests.
- *
- * @param args the arguments. Not used
+ *
+ * @param args
+ * the arguments. Not used
*/
- public static void main(String args[])
+ public static void main( String args[] )
{
- junit.awtui.TestRunner.main(new String[] { TestSimpleDeployment.class.getName()});
+ junit.awtui.TestRunner.main(new String[]{TestSimpleDeployment.class.getName()});
}
/**
* Creates the test suite.
- *
- * @return a test suite (<code>TestSuite</code>) that includes all methods
- * starting with "test"
+ *
+ * @return a test suite (<code>TestSuite</code>) that includes all
+ * methods starting with "test"
*/
public static Test suite()
{
// All methods starting with "test" will be executed in the test suite.
- return new JetspeedTestSuite(TestSimpleDeployment.class);
+ // return new JetspeedTestSuite(TestSimpleDeployment.class);
+ return new TestSuite(TestSimpleDeployment.class);
+ }
+
+ public void testFileSystemManagerOnWar() throws Exception
+ {
+ File demoApp = new File(deploySrc, "demo.war");
+
+ FileObject fsObject = fsManager.toFileObject(demoApp);
+ assertEquals(FileType.FILE, fsObject.getType());
+ FileObject testObj = fsManager.createFileSystem(fsObject);
+ assertEquals(FileType.FOLDER, testObj.getType());
+ // assertEquals("org.apache.commons.vfs.provider.jar.JarFileSystem", testObj.getFileSystem().getClass().getName());
+ FileObject webXml = testObj.resolveFile("WEB-INF/web.xml");
+ assertNotNull(webXml);
+ assertNotNull(webXml.getContent().getInputStream());
+
+ }
+
+ public void testFileSystemManagerOnDir() throws Exception
+ {
+ File demoApp = new File("./test/testdata/deploy/webapp");
+ assertTrue(demoApp.exists());
+ FileObject testObj = fsManager.toFileObject(demoApp);
+ assertEquals(FileType.FOLDER, testObj.getType());
+ // assertEquals("org.apache.commons.vfs.provider.jar.JarFileSystem", testObj.getFileSystem().getClass().getName());
+ FileObject webXml = testObj.resolveFile("WEB-INF/web.xml");
+ assertNotNull(webXml);
+ assertNotNull(webXml.getContent().getInputStream());
+
+ }
+
+ public void testFileSystemManagerForJars() throws Exception
+ {
+ File demoApp = new File(deploySrc, "portletstd.jar");
+ FileObject testObj = fsManager.createFileSystem(fsManager.toFileObject(demoApp));
+ assertEquals("org.apache.commons.vfs.provider.jar.JarFileSystem", testObj.getFileSystem().getClass().getName());
+
}
-
-// public void overrideProperties(Configuration properties)
-// {
-// super.overrideProperties(properties);
-// }
public void testDeploy() throws Exception
{
-
- if (deployRootFile.exists())
- {
- assertTrue("Unable to clean deployment directory.", DirectoryUtils.rmdir(deployRootFile));
- }
- else
- {
- deployRootFile.mkdirs();
- }
- System.out.println("Deployment src: " + delpoySrc);
- DeploymentEventDispatcher ded = new DeploymentEventDispatcher(deployRoot);
+ System.out.println("Deployment src: " + deploySrc);
+
SimpleRegistry simpleRegistry = new InMemoryRegistryImpl();
- DeployDecoratorEventListener ddel = new DeployDecoratorEventListener(simpleRegistry);
+ DeployDecoratorEventListener ddel = new DeployDecoratorEventListener(simpleRegistry, deployRootFile
+ .getAbsolutePath());
+
+ DeployPortletAppEventListener dpal = new DeployPortletAppEventListener(webAppsDir, new FileSystemPAM(
+ webAppsDir, portletRegistry, VFS.getManager(), entityAccess, windowAccess), portletRegistry, VFS.getManager());
+ ArrayList eventListeners = new ArrayList(2);
+ eventListeners.add(ddel);
+ eventListeners.add(dpal);
+ // Use a -1 delay to disable auto scan
+ AutoDeploymentManager autoDeployment = new AutoDeploymentManager(deploySrc.getAbsolutePath(), -1, eventListeners, fsManager);
- DeployPortletAppEventListener dpal = new DeployPortletAppEventListener(webAppsDir, new FileSystemPAM(portletRegistry, Locale.getDefault()), portletRegistry, Locale.getDefault());
- ded.addDeploymentListener(ddel);
- ded.addDeploymentListener(dpal);
- HashMap handlers = new HashMap();
- handlers.put("jar", JARObjectHandlerImpl.class);
- handlers.put("war", JARObjectHandlerImpl.class);
- FileSystemScanner fScanner = new FileSystemScanner(delpoySrc, handlers, ded, 500);
- fScanner.start();
- Thread.sleep(10000);
- fScanner.safeStop();
+ autoDeployment.start();
+ autoDeployment.fireDeploymentEvent();
- File decoratorVm =
- new File(deployRoot + File.separator + "html" + File.separator + "portletstd" + File.separator + "decorator.vm");
+ File decoratorVm = new File(deployRootFile.getAbsolutePath() + File.separator + "html" + File.separator
+ + "portletstd" + File.separator + "decorator.vm");
+
+ File demoApp = new File(webAppsDirFile, TEST_PORTLET_APP_NAME);
+ File securityApp = new File(webAppsDirFile, "TestSecurityRoles");
assertTrue(decoratorVm.getCanonicalPath() + " was not created!", decoratorVm.exists());
-
- assertNotNull(TEST_PORTLET_APP_NAME+" was not registered into the portlet registery.", portletRegistry.getPortletApplicationByIdentifier(TEST_PORTLET_APP_NAME));
- assertTrue(TEST_PORTLET_APP_NAME+" directory was not created, app not deployed.", new File(webAppsDir+"/"+TEST_PORTLET_APP_NAME).exists());
+
+ verifyDemoAppCreated(TEST_PORTLET_APP_NAME, demoApp);
+ verifyDemoAppCreated("TestSecurityRoles", securityApp);
+
MutablePortletApplication jetspeedApp = portletRegistry.getPortletApplicationByIdentifier("jetspeed");
assertNotNull("jetspeed was not registered into the portlet registery.", jetspeedApp);
- assertFalse("local app, jetspeed, got deployed when it should have only been registered.", new File(webAppsDir+"/jetspeed").exists());
-
- //make sure we can load registered app's classed
- Iterator portletDefItr = jetspeedApp.getPortletDefinitions().iterator();
- while(portletDefItr.hasNext())
+ assertFalse("local app, jetspeed, got deployed when it should have only been registered.", new File(webAppsDir
+ + "/jetspeed").exists());
+
+ //make sure we can load registered app's classes
+ Iterator portletDefItr = jetspeedApp.getPortletDefinitions().iterator();
+ while (portletDefItr.hasNext())
{
PortletDefinition def = (PortletDefinition) portletDefItr.next();
try
@@ -138,53 +180,113 @@
}
catch (Exception e)
{
- assertNull("Unable to load registered portlet class, "+def.getClassName(), e);
+ assertNull("Unable to load registered portlet class, " + def.getClassName(), e);
}
-
+
}
+ // test undeploy
+ File demoWar = new File(deploySrc, "demo.war");
+ demoWar.delete();
+ autoDeployment.fireUndeploymentEvent();
+ verifyDemoAppDeleted(TEST_PORTLET_APP_NAME, demoApp);
+
+ // test deploy again
+ copyDeployables();
+ autoDeployment.fireDeploymentEvent();
+ verifyDemoAppCreated(TEST_PORTLET_APP_NAME, demoApp);
+ demoWar.delete();
+ autoDeployment.fireUndeploymentEvent();
+ verifyDemoAppDeleted(TEST_PORTLET_APP_NAME, demoApp);
+
+ autoDeployment.stop();
+
+ }
+ /**
+ * <p>
+ * verifyDemoAppCreated
+ * </p>
+ *
+ * @param demoApp
+ */
+ private void verifyDemoAppCreated( String appName, File appFile )
+ {
+ assertNotNull(appName + " was not registered into the portlet registery.", portletRegistry
+ .getPortletApplicationByIdentifier(TEST_PORTLET_APP_NAME));
+ assertTrue(appName + " directory was not created, app not deployed.", appFile.exists());
}
+
+
+
+ /**
+ * <p>
+ * verifyDemoAppDeleted
+ * </p>
+ *
+ * @param demoApp
+ */
+ private void verifyDemoAppDeleted( String appName, File appFile )
+ {
+ assertNull(appName + " was not removed from the registry.", portletRegistry
+ .getPortletApplicationByIdentifier(TEST_PORTLET_APP_NAME));
+ assertFalse(appName+" directory was not deleted.", appFile.exists());
+ }
/**
* @see junit.framework.TestCase#setUp()
*/
public void setUp()
{
-
- try
+
+ try
{
- super.setUp();
- // set up test data
- delpoySrc = new File("./test/deployment/deploy").getCanonicalPath();
- deployRootFile = new File("./test/deployment/templates/decorator");
- deployRoot = deployRootFile.getCanonicalPath();
- File webAppsDirFile = new File("./target/webapps");
-
- if(!webAppsDirFile.exists())
- {
- webAppsDirFile.mkdirs();
- }
+ super.setUp();
+ copyFrom = new File("./test/deployment/deploy");
+ deploySrc = new File("./target/deployment/deploy");
+ deploySrc.mkdirs();
+ deployRootFile = new File("./target/deployment/templates/decorators");
+ deployRootFile.mkdirs();
+ webAppsDirFile = new File("./target/deployment/webapps");
+ webAppsDirFile.mkdirs();
+
webAppsDir = webAppsDirFile.getCanonicalPath();
testDb = new File("./test/db/hsql/Registry").getCanonicalPath();
- // remove any prior left overs
+ fsManager = new StandardFileSystemManager();
+ fsManager.setConfiguration("./src/webapp/WEB-INF/conf/vfs-providers.xml");
+ fsManager.init();
+
+ copyDeployables();
+ windowAccess = new PortletWindowAccessorImpl(entityAccess);
- FileSystemPAM pam = new FileSystemPAM(portletRegistry, Locale.getDefault());
-
- pam.undeploy(webAppsDir, TEST_PORTLET_APP_NAME);
- pam.unregister(webAppsDir, "jetspeed");
- pam.undeploy(webAppsDir, "struts-demo");
-
}
catch (Exception e)
{
- e.printStackTrace();
- throw new AssertionFailedError("Unable to set up test environment "+e.toString());
+ e.printStackTrace();
+ throw new AssertionFailedError("Unable to set up test environment " + e.toString());
}
+
+ }
+
+ /**
+ * <p>
+ * copyDeployables
+ * </p>
+ *
+ * @throws FileSystemException
+ */
+ protected void copyDeployables() throws FileSystemException
+ {
+ FileObject copyFromObj = fsManager.toFileObject(copyFrom);
+ FileObject deploySrcObj = fsManager.toFileObject(deploySrc);
+ fsManager.getFilesCache().clear(deploySrcObj.getFileSystem());
+ deploySrcObj.copyFrom(copyFromObj, new AllFileSelector());
+ copyFromObj.close();
+ deploySrcObj.close();
}
/**
@@ -192,10 +294,36 @@
*/
public void tearDown() throws Exception
{
-
+ FileSystemPAM pam = new FileSystemPAM(webAppsDir, portletRegistry, VFS.getManager(), entityAccess, windowAccess);
+
+ try
+ {
+ paWar1 = new PortletApplicationWar(webAppsDir + "/" + TEST_PORTLET_APP_NAME, TEST_PORTLET_APP_NAME, "/"
+ + TEST_PORTLET_APP_NAME, VFS.getManager());
+ pam.undeploy(paWar1);
+ }
+ catch (Exception e1)
+ {
+
+ }
+
+ pam.unregister("jetspeed");
+
+ try
+ {
+ paWar3 = new PortletApplicationWar(webAppsDir + "/TestSecurityRoles", "TestSecurityRoles", "/TestSecurityRoles", VFS.getManager());
+
+ pam.undeploy(paWar3);
+ }
+ catch (Exception e3)
+ {
+
+ }
+
+ DirectoryUtils.rmdir(new File("./target/deployment"));
+
super.tearDown();
-
-
+
}
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org