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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 20 14:54:46 EDT 2009


Author: alesj
Date: 2009-07-20 14:54:45 -0400 (Mon, 20 Jul 2009)
New Revision: 91437

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionNotificationListener.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionNotificationListener.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionNotificationListenerTestCase.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionNotificationListener.java
Removed:
   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/SimpleExceptionHandler.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionHandlerTestCase.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionHandler.java
Modified:
   projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/DeployersExceptionsTestSuite.java
Log:
Rename to notification listener.

Modified: projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2009-07-20 18:47:56 UTC (rev 91436)
+++ projects/jboss-deployers/trunk/deployers-impl/src/main/java/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -58,7 +58,7 @@
 import org.jboss.deployers.spi.deployer.Deployers;
 import org.jboss.deployers.spi.deployer.DeploymentStage;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.exceptions.ExceptionHandler;
+import org.jboss.deployers.spi.deployer.exceptions.ExceptionNotificationListener;
 import org.jboss.deployers.spi.deployer.managed.ManagedObjectCreator;
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.DeploymentMBean;
@@ -136,7 +136,7 @@
    private ManagedObjectCreator mgtObjectCreator = null;
 
    /** The exception handlers */
-   private final Set<ExceptionHandler<? extends Throwable>> exceptionHandlers = CollectionsFactory.createLazySet();
+   private final Set<ExceptionNotificationListener<? extends Throwable>> exceptionNotificationListeners = CollectionsFactory.createLazySet();
 
    /**
     * Create a new DeployersImpl.
@@ -368,67 +368,67 @@
    }
 
    /**
-    * Check exception handler.
+    * Check exception notification listener.
     *
-    * @param handler the handler
+    * @param listener the handler
     */
-   protected void checkExceptionHandler(ExceptionHandler<? extends Throwable> handler)
+   protected void checkExceptionNotificationListener(ExceptionNotificationListener<? extends Throwable> listener)
    {
-      if (handler == null)
-         throw new IllegalArgumentException("Null handler");
+      if (listener == null)
+         throw new IllegalArgumentException("Null listener");
 
-      if (handler.getExceptionType() == null)
-         throw new IllegalArgumentException("Null exception type: " + handler);
+      if (listener.getExceptionType() == null)
+         throw new IllegalArgumentException("Null exception type: " + listener);
    }
 
    /**
-    * Set exception handlers.
+    * Set exception notification listeners.
     *
-    * @param exceptionHandlers the exception handlers
+    * @param exceptionNotificationListeners the exception notification listeners
     */
-   public void setExceptionHandlers(Set<ExceptionHandler<? extends Throwable>> exceptionHandlers)
+   public void setExceptionNotificationListener(Set<ExceptionNotificationListener<? extends Throwable>> exceptionNotificationListeners)
    {
-      if (exceptionHandlers == null)
-         throw new IllegalArgumentException("Null exception handlers");
+      if (exceptionNotificationListeners == null)
+         throw new IllegalArgumentException("Null exception notification listeners");
 
-      for (ExceptionHandler<? extends Throwable> handler : exceptionHandlers)
-         checkExceptionHandler(handler);
+      for (ExceptionNotificationListener<? extends Throwable> listener : exceptionNotificationListeners)
+         checkExceptionNotificationListener(listener);
 
-      synchronized (this.exceptionHandlers)
+      synchronized (this.exceptionNotificationListeners)
       {
-         this.exceptionHandlers.addAll(exceptionHandlers);
+         this.exceptionNotificationListeners.addAll(exceptionNotificationListeners);
       }
    }
 
    /**
-    * Add exception handler.
+    * Add exception notification listener.
     *
-    * @param handler the exception handler
-    * @return Set::add(handler)
+    * @param listener the exception notification listener
+    * @return Set::add(listener)
     */
-   public boolean addExceptionHandler(ExceptionHandler<? extends Throwable> handler)
+   public boolean addExceptionNotificationListener(ExceptionNotificationListener<? extends Throwable> listener)
    {
-      checkExceptionHandler(handler);
-      synchronized (this.exceptionHandlers)
+      checkExceptionNotificationListener(listener);
+      synchronized (this.exceptionNotificationListeners)
       {
-         return exceptionHandlers.add(handler);
+         return exceptionNotificationListeners.add(listener);
       }
    }
 
    /**
-    * Remove exception handler.
+    * Remove exception notification listener.
     *
-    * @param handler the exception handler
-    * @return Set::remove(handler)
+    * @param listener the exception notification listener
+    * @return Set::remove(listener)
     */
-   public boolean removeExceptionHandler(ExceptionHandler<? extends Throwable> handler)
+   public boolean removeExceptionNotificationListener(ExceptionNotificationListener<? extends Throwable> listener)
    {
-      if (handler == null)
-         throw new IllegalArgumentException("Null handler");
+      if (listener == null)
+         throw new IllegalArgumentException("Null listener");
 
-      synchronized (this.exceptionHandlers)
+      synchronized (this.exceptionNotificationListeners)
       {
-         return exceptionHandlers.remove(handler);
+         return exceptionNotificationListeners.remove(listener);
       }
    }
 
@@ -924,14 +924,14 @@
          return null;
 
       // handle original first
-      handleException(original, context);
+      notify(original, context);
 
       Throwable result = original;
       Throwable cause = result.getCause();
       while (cause != null)
       {
          // then each cause
-         handleException(cause, context);
+         notify(cause, context);
 
          result = cause;
          cause = cause.getCause();
@@ -940,27 +940,27 @@
    }
 
    /**
-    * Handle exception.
+    * Notify.
     *
-    * @param exception the exception to handle
+    * @param exception the exception to notify
     * @param context the context that has this exception as its problem
     */
    @SuppressWarnings("unchecked")
-   protected void handleException(Throwable exception, ControllerContext context)
+   protected void notify(Throwable exception, ControllerContext context)
    {
-      for (ExceptionHandler handler : exceptionHandlers)
+      for (ExceptionNotificationListener listener : exceptionNotificationListeners)
       {
-         Class<? extends Throwable> type = handler.getExceptionType();
-         if (handler.matchExactExceptionType())
+         Class<? extends Throwable> type = listener.getExceptionType();
+         if (listener.matchExactExceptionType())
          {
             if (type.equals(exception.getClass()))
             {
-               handler.handleException(exception, context);
+               listener.notify(exception, context);
             }
          }
          else if (type.isInstance(exception))
          {
-            handler.handleException(exception, context);
+            listener.notify(exception, context);
          }
       }
    }

Modified: 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	2009-07-20 18:47:56 UTC (rev 91436)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/DeployersExceptionsTestSuite.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -24,7 +24,7 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
-import org.jboss.test.deployers.exceptions.test.SimpleExceptionHandlerTestCase;
+import org.jboss.test.deployers.exceptions.test.SimpleExceptionNotificationListenerTestCase;
 
 /**
  * Exceptions test suite.
@@ -42,7 +42,7 @@
    {
       TestSuite suite = new TestSuite("Deployers Exceptions Tests");
 
-      suite.addTest(SimpleExceptionHandlerTestCase.suite());
+      suite.addTest(SimpleExceptionNotificationListenerTestCase.suite());
       
       return suite;
    }

Deleted: 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	2009-07-20 18:47:56 UTC (rev 91436)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionHandler.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -1,33 +0,0 @@
-/*
- * 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

Copied: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionNotificationListener.java (from rev 91162, 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/AnySimpleExceptionNotificationListener.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/AnySimpleExceptionNotificationListener.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -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 AnySimpleExceptionNotificationListener extends SimpleExceptionNotificationListener
+{
+   public boolean matchExactExceptionType()
+   {
+      return false;
+   }
+}
\ No newline at end of file

Deleted: 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	2009-07-20 18:47:56 UTC (rev 91436)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionHandler.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -1,46 +0,0 @@
-/*
- * 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

Copied: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionNotificationListener.java (from rev 91162, 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/SimpleExceptionNotificationListener.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/support/SimpleExceptionNotificationListener.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -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.ExceptionNotificationListener;
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class SimpleExceptionNotificationListener implements ExceptionNotificationListener<SimpleException>
+{
+   public Class<SimpleException> getExceptionType()
+   {
+      return SimpleException.class;
+   }
+
+   public boolean matchExactExceptionType()
+   {
+      return true;
+   }
+
+   public void notify(SimpleException exception, ControllerContext context)
+   {
+      SimpleException.failures.add(context.getName() + "_" + getClass().getSimpleName());
+   }
+}
\ No newline at end of file

Deleted: 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	2009-07-20 18:47:56 UTC (rev 91436)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionHandlerTestCase.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -1,118 +0,0 @@
-/*
- * 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"));
-   }
-}

Copied: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionNotificationListenerTestCase.java (from rev 91162, 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/SimpleExceptionNotificationListenerTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/exceptions/test/SimpleExceptionNotificationListenerTestCase.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -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.AnySimpleExceptionNotificationListener;
+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.SimpleExceptionNotificationListener;
+
+/**
+ * Simple exception handler test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+ at SuppressWarnings({"ThrowableInstanceNeverThrown"})
+public class SimpleExceptionNotificationListenerTestCase extends AbstractDeployerTest
+{
+   public SimpleExceptionNotificationListenerTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(SimpleExceptionNotificationListenerTestCase.class);
+   }
+
+   @Override
+   protected Deployers createDeployers()
+   {
+      Deployers deployers = super.createDeployers();
+      ((DeployersImpl)deployers).addExceptionNotificationListener(new SimpleExceptionNotificationListener());
+      ((DeployersImpl)deployers).addExceptionNotificationListener(new AnySimpleExceptionNotificationListener());
+      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_AnySimpleExceptionNotificationListener"));
+   }
+
+   public void testAnyMatch() throws Throwable
+   {
+      Exception exception = new SimpleException("Failure", null);
+      Set<Object> expected = new HashSet<Object>(Arrays.asList("Test_SimpleExceptionNotificationListener", "Test_AnySimpleExceptionNotificationListener"));
+      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_AnySimpleExceptionNotificationListener"));
+   }
+}

Deleted: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionHandler.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionHandler.java	2009-07-20 18:47:56 UTC (rev 91436)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionHandler.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -1,55 +0,0 @@
-/*
- * 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.deployers.spi.deployer.exceptions;
-
-import org.jboss.dependency.spi.ControllerContext;
-
-/**
- * Deployment exception handler.
- *
- * @param <T> exact exception type
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- */
-public interface ExceptionHandler<T extends Throwable>
-{
-   /**
-    * Get the exception type.
-    *
-    * @return the exception type
-    */
-   Class<T> getExceptionType();
-
-   /**
-    * Do we match exact exception type.
-    *
-    * @return true if we only match T, or false if any super type as well.
-    */
-   boolean matchExactExceptionType();
-
-   /**
-    * Handle exception.
-    *
-    * @param exception the exception to handle
-    * @param context the context the caused the exception
-    */
-   void handleException(T exception, ControllerContext context);
-}

Copied: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionNotificationListener.java (from rev 91160, projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionHandler.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionNotificationListener.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/exceptions/ExceptionNotificationListener.java	2009-07-20 18:54:45 UTC (rev 91437)
@@ -0,0 +1,55 @@
+/*
+ * 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.deployers.spi.deployer.exceptions;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Deployment exception notification listener.
+ *
+ * @param <T> exact exception type
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface ExceptionNotificationListener<T extends Throwable>
+{
+   /**
+    * Get the exception type.
+    *
+    * @return the exception type
+    */
+   Class<T> getExceptionType();
+
+   /**
+    * Do we match exact exception type.
+    *
+    * @return true if we only match T, or false if any super type as well.
+    */
+   boolean matchExactExceptionType();
+
+   /**
+    * Notify.
+    *
+    * @param exception the exception that popped up
+    * @param context the context the caused the exception
+    */
+   void notify(T exception, ControllerContext context);
+}




More information about the jboss-cvs-commits mailing list