[jboss-cvs] JBossAS SVN: r91162 - in projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers: exceptions and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 13 10:50:58 EDT 2009


Author: alesj
Date: 2009-07-13 10:50:58 -0400 (Mon, 13 Jul 2009)
New Revision: 91162

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/DeployersExceptionsTestSuite.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionHandler.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/ComplexException.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleException.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionHandler.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionHandlerTestCase.java
Modified:
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/DeployersImplTestSuite.java
Log:
[JBDEPLOY-205]; adding tests.

Modified: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/DeployersImplTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/DeployersImplTestSuite.java	2009-07-13 14:34:38 UTC (rev 91161)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/DeployersImplTestSuite.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -21,21 +21,22 @@
 */
 package org.jboss.test.deployers;
 
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jboss.test.deployers.annotations.DeployersAnnotationsTestSuite;
 import org.jboss.test.deployers.classloading.DeployersClassLoadingTestSuite;
 import org.jboss.test.deployers.deployer.DeployersDeployerTestSuite;
+import org.jboss.test.deployers.exceptions.DeployersExceptionsTestSuite;
+import org.jboss.test.deployers.main.DeployersMainTestSuite;
 import org.jboss.test.deployers.managed.DeployersManagedTestSuite;
 import org.jboss.test.deployers.scope.DeployersScopeTestSuite;
-import org.jboss.test.deployers.main.DeployersMainTestSuite;
-import org.jboss.test.deployers.annotations.DeployersAnnotationsTestSuite;
 
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
 /**
  * Deployers Impl Test Suite.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 37459 $
  */
 public class DeployersImplTestSuite extends TestSuite
@@ -55,6 +56,7 @@
       suite.addTest(DeployersScopeTestSuite.suite());
       suite.addTest(DeployersMainTestSuite.suite());
       suite.addTest(DeployersAnnotationsTestSuite.suite());
+      suite.addTest(DeployersExceptionsTestSuite.suite());
 
       return suite;
    }

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/DeployersExceptionsTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/DeployersExceptionsTestSuite.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/DeployersExceptionsTestSuite.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -0,0 +1,49 @@
+/*
+ * 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.exceptions;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import org.jboss.test.deployers.exceptions.test.SimpleExceptionHandlerTestCase;
+
+/**
+ * Exceptions test suite.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeployersExceptionsTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("Deployers Exceptions Tests");
+
+      suite.addTest(SimpleExceptionHandlerTestCase.suite());
+      
+      return suite;
+   }
+}

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionHandler.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionHandler.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionHandler.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -0,0 +1,33 @@
+/*
+ * 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.exceptions.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class AnySimpleExceptionHandler extends SimpleExceptionHandler
+{
+   public boolean matchExactExceptionType()
+   {
+      return false;
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/ComplexException.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/ComplexException.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/ComplexException.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -0,0 +1,33 @@
+/*
+ * 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.exceptions.support;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ComplexException extends SimpleException
+{
+   public ComplexException(String message, Throwable cause)
+   {
+      super(message, cause);
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleException.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleException.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleException.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -0,0 +1,38 @@
+/*
+ * 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.exceptions.support;
+
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SimpleException extends Exception
+{
+   public static final Set<Object> failures = new HashSet<Object>();
+   
+   public SimpleException(String message, Throwable cause)
+   {
+      super(message, cause);
+   }
+}

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionDeployer.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -0,0 +1,42 @@
+/*
+ * 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.exceptions.support;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SimpleExceptionDeployer extends AbstractSimpleRealDeployer<Exception>
+{
+   public SimpleExceptionDeployer()
+   {
+      super(Exception.class);
+   }
+
+   public void deploy(DeploymentUnit unit, Exception deployment) throws DeploymentException
+   {
+      throw DeploymentException.rethrowAsDeploymentException("Failed", deployment);
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionHandler.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionHandler.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionHandler.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -0,0 +1,46 @@
+/*
+ * 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.exceptions.support;
+
+import org.jboss.deployers.spi.deployer.exceptions.ExceptionHandler;
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SimpleExceptionHandler implements ExceptionHandler<SimpleException>
+{
+   public Class<SimpleException> getExceptionType()
+   {
+      return SimpleException.class;
+   }
+
+   public boolean matchExactExceptionType()
+   {
+      return true;
+   }
+
+   public void handleException(SimpleException exception, ControllerContext context)
+   {
+      SimpleException.failures.add(context.getName() + "_" + getClass().getSimpleName());
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionHandlerTestCase.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionHandlerTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionHandlerTestCase.java	2009-07-13 14:50:58 UTC (rev 91162)
@@ -0,0 +1,118 @@
+/*
+ * 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.exceptions.test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.plugins.attachments.AttachmentsImpl;
+import org.jboss.deployers.plugins.deployers.DeployersImpl;
+import org.jboss.deployers.spi.deployer.Deployers;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.exceptions.support.AnySimpleExceptionHandler;
+import org.jboss.test.deployers.exceptions.support.ComplexException;
+import org.jboss.test.deployers.exceptions.support.SimpleException;
+import org.jboss.test.deployers.exceptions.support.SimpleExceptionDeployer;
+import org.jboss.test.deployers.exceptions.support.SimpleExceptionHandler;
+
+/**
+ * Simple exception handler test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+ at SuppressWarnings({"ThrowableInstanceNeverThrown"})
+public class SimpleExceptionHandlerTestCase extends AbstractDeployerTest
+{
+   public SimpleExceptionHandlerTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(SimpleExceptionHandlerTestCase.class);
+   }
+
+   @Override
+   protected Deployers createDeployers()
+   {
+      Deployers deployers = super.createDeployers();
+      ((DeployersImpl)deployers).addExceptionHandler(new SimpleExceptionHandler());
+      ((DeployersImpl)deployers).addExceptionHandler(new AnySimpleExceptionHandler());
+      return deployers;
+   }
+
+   protected void testExceptionHandling(Exception exception, Set<Object> expected) throws Throwable
+   {
+      Deployment deployment = createSimpleDeployment("Test");
+      AttachmentsImpl attachments = new AttachmentsImpl();
+      attachments.addAttachment(Exception.class, exception);
+      deployment.setPredeterminedManagedObjects(attachments);
+
+      DeployerClient main = createMainDeployer(new SimpleExceptionDeployer()); 
+
+      SimpleException.failures.clear();
+      try
+      {
+         assertDeploy(main, deployment);
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         assertEquals(expected, SimpleException.failures);         
+      }
+      finally
+      {
+         assertUndeploy(main, deployment);
+      }
+   }
+
+   public void testExactMatch() throws Throwable
+   {
+      Exception exception = new ComplexException("Failure", null);
+      testExceptionHandling(exception, Collections.<Object>singleton("Test_AnySimpleExceptionHandler"));
+   }
+
+   public void testAnyMatch() throws Throwable
+   {
+      Exception exception = new SimpleException("Failure", null);
+      Set<Object> expected = new HashSet<Object>(Arrays.asList("Test_SimpleExceptionHandler", "Test_AnySimpleExceptionHandler"));
+      testExceptionHandling(exception, expected);
+   }
+
+   public void testNoMatch() throws Throwable
+   {
+      Exception exception = new IllegalArgumentException("Failed");
+      testExceptionHandling(exception, Collections.<Object>emptySet());
+   }
+
+   public void testNested() throws Throwable
+   {
+      Exception exception = new IllegalArgumentException("Failed", new ComplexException("Nested", null));
+      testExceptionHandling(exception, Collections.<Object>singleton("Test_AnySimpleExceptionHandler"));
+   }
+}




More information about the jboss-cvs-commits mailing list