You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by li...@apache.org on 2012/04/11 17:38:20 UTC
[2/6] git commit: Adding tests
Adding tests
Also some small fixes for the tests on things I missed
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/290d85d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/290d85d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/290d85d6
Branch: refs/heads/master
Commit: 290d85d6007e286e50733b3409363fae21a51564
Parents: 2625715
Author: Jason Porter <li...@apache.org>
Authored: Tue Apr 10 15:51:35 2012 -0600
Committer: Jason Porter <li...@apache.org>
Committed: Tue Apr 10 16:31:06 2012 -0600
----------------------------------------------------------------------
.../core/api/exception/control/BeforeHandles.java | 2 +-
.../api/exception/control/CaughtException.java | 7 +-
.../control/ExceptionHandlerComparator.java | 4 +-
.../control/ExceptionHandlerDispatch.java | 4 +-
.../impl/exception/control/HandlerMethodImpl.java | 11 ++-
.../control/HandlerMethodStorageImpl.java | 17 ++-
.../services/javax.enterprise.inject.spi.Extension | 3 +-
.../exception/control/event/EventQualifier.java | 27 ++++
.../impl/exception/control/event/EventTest.java | 104 ++++++++++++++
.../event/literal/EventQualifierLiteral.java | 29 ++++
.../impl/exception/control/extension/Account.java | 27 ++++
.../exception/control/extension/Arquillian.java | 33 +++++
.../control/extension/CatchQualifier.java | 33 +++++
.../control/flow/AbortingBreadthFirstHandler.java | 45 ++++++
.../control/flow/AbortingDepthHandler.java | 44 ++++++
.../control/flow/BreadthFirstAbortControlTest.java | 74 ++++++++++
.../control/flow/DepthAbortControlTest.java | 72 ++++++++++
.../control/flow/ExceptionHandledHandler.java | 50 +++++++
.../control/flow/HandledExceptionHandlerTest.java | 85 +++++++++++
.../control/flow/ProceedCauseHandler.java | 61 ++++++++
.../control/flow/ProceedCauseHandlerTest.java | 74 ++++++++++
.../exception/control/flow/RethrowHandler.java | 40 ++++++
.../impl/exception/control/flow/RethrowTest.java | 73 ++++++++++
.../control/flow/ThrowingNewExceptionTest.java | 73 ++++++++++
.../exception/control/flow/ThrowingNewHandler.java | 40 ++++++
.../control/handler/BadInjectionPointHandler.java | 35 +++++
.../control/handler/CalledExceptionHandler.java | 78 ++++++++++
.../control/handler/CallingHandlersTest.java | 110 +++++++++++++++
.../control/handler/ExtensionExceptionHandler.java | 110 +++++++++++++++
.../control/handler/HandlerComparatorTest.java | 100 +++++++++++++
.../handler/HandlerWhichThrowsExceptions.java | 35 +++++
.../exception/control/handler/UnMuteHandler.java | 44 ++++++
.../control/handler/UnMuteHandlerTest.java | 70 +++++++++
.../control/traversal/ExceptionHandlerMethods.java | 79 +++++++++++
.../exception/control/traversal/Exceptions.java | 53 +++++++
.../control/traversal/TraversalPathTest.java | 89 ++++++++++++
36 files changed, 1825 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/BeforeHandles.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/BeforeHandles.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/BeforeHandles.java
index d30756e..8e7078a 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/BeforeHandles.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/BeforeHandles.java
@@ -33,7 +33,7 @@ import java.lang.annotation.Target;
* If a method has a return type, it is ignored.
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
+@Target(ElementType.PARAMETER)
@Documented
public @interface BeforeHandles
{
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/CaughtException.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/CaughtException.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/CaughtException.java
index 3f7bc95..4f57410 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/CaughtException.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/api/exception/control/CaughtException.java
@@ -142,7 +142,12 @@ public class CaughtException<T extends Throwable>
public boolean isMarkedHandled()
{
- return this.isMarkedHandled();
+ return this.markedHandled;
+ }
+
+ public boolean isBeforeTraversal()
+ {
+ return beforeTraversal;
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
index c9dd39a..b209673 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerComparator.java
@@ -32,7 +32,7 @@ import java.util.Set;
* ({@link org.apache.deltaspike.core.api.exception.control.BeforeHandles} first), ordinal
* (highest to lowest) and finally hierarchy (least to most specific).
*/
-@SuppressWarnings({ "MethodWithMoreThanThreeNegations" })
+@SuppressWarnings({"MethodWithMoreThanThreeNegations"})
public final class ExceptionHandlerComparator implements Comparator<HandlerMethod<?>>
{
/**
@@ -92,7 +92,7 @@ public final class ExceptionHandlerComparator implements Comparator<HandlerMetho
private int comparePrecedence(final int lhs, final int rhs, final boolean isBefore)
{
- if (isBefore)
+ if (!isBefore)
{
return (lhs - rhs);
}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
index a1e9333..d7d8c77 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/ExceptionHandlerDispatch.java
@@ -57,9 +57,7 @@ public class ExceptionHandlerDispatch implements java.io.Serializable
* @param bm active bean manager
* @throws Throwable If a handler requests the exception to be re-thrown.
*/
- // CHECKSTYLE:OFF
@SuppressWarnings({"unchecked", "MethodWithMultipleLoops", "ThrowableResultOfMethodCallIgnored"})
- // CHECKSTYLE:ON
public void executeHandlers(@Observes @Any ExceptionToCatch eventException, final BeanManager bm) throws Throwable
{
log.entering(ExceptionHandlerDispatch.class.getName(), "executeHandlers", eventException.getException());
@@ -81,7 +79,7 @@ public class ExceptionHandlerDispatch implements java.io.Serializable
bm.fireEvent(stack); // Allow for modifying the exception stack
- inbound_cause:
+ inbound_cause:
while (stack.getCurrent() != null)
{
this.exceptionStack = stack;
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
index a2ac057..1997a32 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodImpl.java
@@ -93,7 +93,16 @@ public class HandlerMethodImpl<T extends Throwable> implements HandlerMethod<T>
}
this.before = this.handlerParameter.getAnnotation(BeforeHandles.class) != null;
- this.ordinal = this.handlerParameter.getAnnotation(Handles.class).ordinal();
+
+ if (this.before)
+ {
+ this.ordinal = this.handlerParameter.getAnnotation(BeforeHandles.class).ordinal();
+ }
+ else
+ {
+ this.ordinal = this.handlerParameter.getAnnotation(Handles.class).ordinal();
+ }
+
tmpQualifiers.addAll(BeanUtils.getQualifiers(bm, this.handlerParameter.getAnnotations()));
if (tmpQualifiers.isEmpty())
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java
index 6d75b81..29162c4 100644
--- a/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java
+++ b/deltaspike/core/impl/src/main/java/org/apache/deltaspike/core/impl/exception/control/HandlerMethodStorageImpl.java
@@ -90,7 +90,22 @@ public class HandlerMethodStorageImpl implements HandlerMethodStorage
{
for (HandlerMethod<?> handler : this.allHandlers.get(hierarchyType))
{
- if (handler.isBefore())
+ if (handler.isBefore() && isBefore)
+ {
+ if (handler.getQualifiers().contains(new AnyLiteral()))
+ {
+ returningHandlers.add(handler);
+ }
+ else
+ {
+ if (!handlerQualifiers.isEmpty() && this.containsAny(handler.getQualifiers(),
+ handlerQualifiers))
+ {
+ returningHandlers.add(handler);
+ }
+ }
+ }
+ else if (!handler.isBefore() && !isBefore)
{
if (handler.getQualifiers().contains(new AnyLiteral()))
{
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
index 21051db..1ad276d 100644
--- a/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
+++ b/deltaspike/core/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
@@ -19,4 +19,5 @@
org.apache.deltaspike.core.impl.exclude.ExcludeExtension
org.apache.deltaspike.core.impl.config.injectable.ConfigPropertyExtension
-org.apache.deltaspike.core.impl.message.MessageBundleExtension
\ No newline at end of file
+org.apache.deltaspike.core.impl.message.MessageBundleExtension
+org.apache.deltaspike.core.impl.exception.control.extension.CatchExtension
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventQualifier.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventQualifier.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventQualifier.java
new file mode 100644
index 0000000..d30293e
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventQualifier.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.event;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+public @interface EventQualifier
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventTest.java
new file mode 100644
index 0000000..4031224
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/EventTest.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.event;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.core.impl.exception.control.event.literal.EventQualifierLiteral;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+@ExceptionHandler
+public class EventTest
+{
+ @Deployment(name = "EventTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "eventTest.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(EventTest.class, EventQualifier.class, EventQualifierLiteral.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ private int qualiferCalledCount = 0;
+
+ @Test
+ public void assertEventIsCreatedCorrectly()
+ {
+ bm.fireEvent(new ExceptionToCatch(new NullPointerException()));
+ }
+
+ @Test
+ public void assertEventWithQualifiersIsCreatedCorrectly()
+ {
+ this.bm.fireEvent(new ExceptionToCatch(new NullPointerException(), new EventQualifierLiteral()));
+ }
+
+ public void verifyDescEvent(@BeforeHandles CaughtException<NullPointerException> event)
+ {
+ this.qualiferCalledCount++;
+ assertTrue(event.isBeforeTraversal());
+ }
+
+ public void verifyAscEvent(@Handles CaughtException<NullPointerException> event)
+ {
+ this.qualiferCalledCount++;
+ assertFalse(event.isBeforeTraversal());
+ }
+
+ public void verifyQualifierEvent(@Handles @EventQualifier CaughtException<NullPointerException> event)
+ {
+ this.qualiferCalledCount++;
+ assertThat(this.qualiferCalledCount, is(1));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/literal/EventQualifierLiteral.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/literal/EventQualifierLiteral.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/literal/EventQualifierLiteral.java
new file mode 100644
index 0000000..7963c27
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/event/literal/EventQualifierLiteral.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.event.literal;
+
+import org.apache.deltaspike.test.core.impl.exception.control.event.EventQualifier;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+public class EventQualifierLiteral extends AnnotationLiteral<EventQualifier> implements EventQualifier
+{
+ private static final long serialVersionUID = -7287578336564561662L;
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Account.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Account.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Account.java
new file mode 100644
index 0000000..cc3d45b
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Account.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.extension;
+
+/**
+ *
+ */
+public class Account
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Arquillian.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Arquillian.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Arquillian.java
new file mode 100644
index 0000000..4ca96f4
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/Arquillian.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.extension;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
+public @interface Arquillian
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/CatchQualifier.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/CatchQualifier.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/CatchQualifier.java
new file mode 100644
index 0000000..1670277
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/extension/CatchQualifier.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.extension;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Qualifier
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
+public @interface CatchQualifier
+{
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingBreadthFirstHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingBreadthFirstHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingBreadthFirstHandler.java
new file mode 100644
index 0000000..047d5ed
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingBreadthFirstHandler.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod"})
+@ExceptionHandler
+public class AbortingBreadthFirstHandler
+{
+ public static boolean abortCalled = false;
+ public static boolean proceedCalled = false;
+
+ public void abortHandler(@BeforeHandles CaughtException<Exception> event)
+ {
+ abortCalled = true;
+ event.abort();
+ }
+
+ public void proceedHandler(@Handles CaughtException<NullPointerException> event)
+ {
+ proceedCalled = true;
+ event.handledAndContinue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingDepthHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingDepthHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingDepthHandler.java
new file mode 100644
index 0000000..0cbed6e
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/AbortingDepthHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod"})
+@ExceptionHandler
+public class AbortingDepthHandler
+{
+ public static boolean abortCalled = false;
+ public static boolean proceedCalled = false;
+
+ public void abortHandler(@Handles CaughtException<Exception> event)
+ {
+ abortCalled = true;
+ event.abort();
+ }
+
+ public void proceedHandler(@Handles CaughtException<Throwable> event)
+ {
+ proceedCalled = true;
+ event.handledAndContinue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/BreadthFirstAbortControlTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/BreadthFirstAbortControlTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/BreadthFirstAbortControlTest.java
new file mode 100644
index 0000000..7cf6755
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/BreadthFirstAbortControlTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.core.impl.exception.control.handler.CalledExceptionHandler;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class BreadthFirstAbortControlTest
+{
+ @Deployment(name = "BreadthFirstAbortControlTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "breadthFirstAbortControl.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addClasses(CalledExceptionHandler.class)
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(AbortingBreadthFirstHandler.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test
+ public void assertNoOtherHandlersCalledAfterAbort()
+ {
+ bm.fireEvent(new ExceptionToCatch(new NullPointerException()));
+ assertTrue(AbortingBreadthFirstHandler.abortCalled);
+ assertFalse(AbortingBreadthFirstHandler.proceedCalled);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/DepthAbortControlTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/DepthAbortControlTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/DepthAbortControlTest.java
new file mode 100644
index 0000000..db1ccec
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/DepthAbortControlTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class DepthAbortControlTest
+{
+ @Deployment(name = "DepthAbortControlTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "depthAbortControl.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(AbortingDepthHandler.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test
+ public void assertNoOtherHandlersCalledAfterAbort()
+ {
+ bm.fireEvent(new ExceptionToCatch(new NullPointerException()));
+ assertTrue(AbortingDepthHandler.abortCalled);
+ assertFalse(AbortingDepthHandler.proceedCalled);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ExceptionHandledHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ExceptionHandledHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ExceptionHandledHandler.java
new file mode 100644
index 0000000..072923e
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ExceptionHandledHandler.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+@ExceptionHandler
+public class ExceptionHandledHandler
+{
+ public static boolean EX_ASC_CALLED = false;
+ public static boolean IAE_ASC_CALLED = false;
+ public static boolean NPE_DESC_CALLED = false;
+
+ public void exHandler(@Handles CaughtException<Exception> event)
+ {
+ EX_ASC_CALLED = true;
+ }
+
+ public void npeHandler(@Handles CaughtException<IllegalArgumentException> event)
+ {
+ IAE_ASC_CALLED = true;
+ event.handled();
+ }
+
+ public void npeDescHandler(@BeforeHandles CaughtException<NullPointerException> event)
+ {
+ NPE_DESC_CALLED = true;
+ event.handled();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/HandledExceptionHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/HandledExceptionHandlerTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/HandledExceptionHandlerTest.java
new file mode 100644
index 0000000..12c1c05
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/HandledExceptionHandlerTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class HandledExceptionHandlerTest
+{
+ @Deployment(name = "HandledExceptionHandlerTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "handledExceptionHandler.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(ExceptionHandledHandler.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test
+ public void assertNoHandlersAfterHandledAreCalled()
+ {
+ final ExceptionToCatch catchEntry = new ExceptionToCatch(new Exception(
+ new NullPointerException()));
+ bm.fireEvent(catchEntry);
+ assertTrue(ExceptionHandledHandler.NPE_DESC_CALLED);
+ assertFalse(ExceptionHandledHandler.EX_ASC_CALLED);
+ assertTrue(catchEntry.isHandled());
+ }
+
+ @Test
+ public void assertNoHandlersAfterHandledAreCalledDesc()
+ {
+ final ExceptionToCatch event = new ExceptionToCatch(new Exception(new IllegalArgumentException()));
+ bm.fireEvent(event);
+ assertTrue(ExceptionHandledHandler.IAE_ASC_CALLED);
+ assertFalse(ExceptionHandledHandler.EX_ASC_CALLED);
+ assertTrue(event.isHandled());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandler.java
new file mode 100644
index 0000000..c9f49c6
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandler.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+@ExceptionHandler
+public class ProceedCauseHandler
+{
+ public static int BREADTH_FIRST_NPE_CALLED = 0;
+ public static int BREADTH_FIRST_NPE_LOWER_PRECEDENCE_CALLED = 0;
+
+ public static int DEPTH_FIRST_NPE_CALLED = 0;
+ public static int DEPTH_FIRST_NPE_HIGHER_PRECEDENCE_CALLED = 0;
+
+ public void npeInboundHandler(
+ @BeforeHandles CaughtException<NullPointerException> event)
+ {
+ BREADTH_FIRST_NPE_CALLED++;
+ event.skipCause();
+ }
+
+ public void npeLowerPrecedenceInboundHandler(
+ @BeforeHandles(ordinal = -50) CaughtException<NullPointerException> event)
+ {
+ BREADTH_FIRST_NPE_LOWER_PRECEDENCE_CALLED++;
+ event.handledAndContinue();
+ }
+
+ public void npeOutboundHandler(@Handles CaughtException<NullPointerException> event)
+ {
+ DEPTH_FIRST_NPE_CALLED++;
+ event.skipCause();
+ }
+
+ public void npeHigherPrecedenceOutboundHandler(@Handles(ordinal = -10) CaughtException<NullPointerException> event)
+ {
+ DEPTH_FIRST_NPE_HIGHER_PRECEDENCE_CALLED++;
+ event.handledAndContinue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandlerTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandlerTest.java
new file mode 100644
index 0000000..e43857b
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ProceedCauseHandlerTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import static junit.framework.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class ProceedCauseHandlerTest
+{
+ @Deployment(name = "ProceedCauseHandlerTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "proceedCauseHandler.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(ProceedCauseHandler.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test
+ public void assertCorrectNumberOfHandlerCallsForProceedCause()
+ {
+ bm.fireEvent(new ExceptionToCatch(new Exception(new IllegalArgumentException(new NullPointerException()))));
+ assertEquals(0, ProceedCauseHandler.BREADTH_FIRST_NPE_LOWER_PRECEDENCE_CALLED);
+ assertEquals(1, ProceedCauseHandler.BREADTH_FIRST_NPE_CALLED);
+
+ assertEquals(0, ProceedCauseHandler.DEPTH_FIRST_NPE_HIGHER_PRECEDENCE_CALLED);
+ assertEquals(0, ProceedCauseHandler.DEPTH_FIRST_NPE_CALLED);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowHandler.java
new file mode 100644
index 0000000..2413c28
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowHandler.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+@ExceptionHandler
+public class RethrowHandler
+{
+ public void rethrow(@Handles CaughtException<NullPointerException> event)
+ {
+ event.throwOriginal();
+ }
+
+ public void rethrowInbound(
+ @BeforeHandles CaughtException<IllegalArgumentException> event)
+ {
+ event.throwOriginal();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowTest.java
new file mode 100644
index 0000000..43ea066
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/RethrowTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class RethrowTest
+{
+ @Deployment(name = "RethrowTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "rethrow.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(RethrowHandler.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test(expected = NullPointerException.class)
+ public void assertOutboundRethrow()
+ {
+ bm.fireEvent(new ExceptionToCatch(new NullPointerException()));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void assertInboundRethrow()
+ {
+ bm.fireEvent(new ExceptionToCatch(new IllegalArgumentException()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewExceptionTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewExceptionTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewExceptionTest.java
new file mode 100644
index 0000000..e80dc95
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewExceptionTest.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+@RunWith(Arquillian.class)
+public class ThrowingNewExceptionTest
+{
+ @Deployment(name = "ThrowingNewExceptionTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "throwingNew.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(ThrowingNewHandler.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void assertOutboundRethrow()
+ {
+ bm.fireEvent(new ExceptionToCatch(new NullPointerException()));
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void assertInboundRethrow()
+ {
+ bm.fireEvent(new ExceptionToCatch(new IllegalArgumentException()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewHandler.java
new file mode 100644
index 0000000..0d09f77
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/flow/ThrowingNewHandler.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.flow;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+@ExceptionHandler
+public class ThrowingNewHandler
+{
+ public void rethrow(@Handles CaughtException<NullPointerException> event)
+ {
+ event.rethrow(new UnsupportedOperationException());
+ }
+
+ public void rethrowInbound(
+ @BeforeHandles CaughtException<IllegalArgumentException> event)
+ {
+ event.rethrow(new UnsupportedOperationException());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/BadInjectionPointHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/BadInjectionPointHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/BadInjectionPointHandler.java
new file mode 100644
index 0000000..d6cff38
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/BadInjectionPointHandler.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.handler;
+
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+/**
+ * This handler is not valid as the injection point firstParam is not valid.
+ */
+@ExceptionHandler
+public class BadInjectionPointHandler
+{
+ void handleException(int firstParam, @Handles CaughtException<Exception> event)
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CalledExceptionHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CalledExceptionHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CalledExceptionHandler.java
new file mode 100644
index 0000000..cd78920
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CalledExceptionHandler.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.handler;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+import javax.enterprise.inject.spi.BeanManager;
+import java.sql.SQLException;
+
+@ExceptionHandler
+public class CalledExceptionHandler
+{
+ public static boolean OUTBOUND_HANDLER_CALLED = false;
+ public static int OUTBOUND_HANDLER_TIMES_CALLED = 0;
+ public static boolean PROTECTED_HANDLER_CALLED = false;
+ public static int INBOUND_HANDLER_TIMES_CALLED = 0;
+ public static boolean BEANMANAGER_INJECTED = false;
+ public static boolean LOCATION_DIFFER_BEANMANAGER_INJECTED = false;
+
+ public void basicHandler(@Handles CaughtException<Exception> event)
+ {
+ OUTBOUND_HANDLER_CALLED = true;
+ OUTBOUND_HANDLER_TIMES_CALLED++;
+ }
+
+ public void basicInboundHandler(@BeforeHandles CaughtException<Exception> event)
+ {
+ INBOUND_HANDLER_TIMES_CALLED++;
+ event.handledAndContinue();
+ }
+
+ public void extraInjections(@Handles CaughtException<IllegalArgumentException> event, BeanManager bm)
+ {
+ if (bm != null)
+ {
+ BEANMANAGER_INJECTED = true;
+ }
+ }
+
+ void protectedHandler(@Handles CaughtException<IllegalStateException> event)
+ {
+ PROTECTED_HANDLER_CALLED = true;
+
+ if (!event.isMarkedHandled())
+ {
+ event.handledAndContinue();
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private void handlerLocationInjections(BeanManager bm, @Handles CaughtException<SQLException> event)
+ {
+ if (bm != null)
+ {
+ LOCATION_DIFFER_BEANMANAGER_INJECTED = true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CallingHandlersTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CallingHandlersTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CallingHandlersTest.java
new file mode 100644
index 0000000..950a862
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/CallingHandlersTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.handler;
+
+import org.apache.deltaspike.core.api.exception.control.ExceptionToCatch;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import java.sql.SQLException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class CallingHandlersTest
+{
+ @Deployment(name = "CallingHandlersTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "callingHandlers.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addClasses(CalledExceptionHandler.class)
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test
+ public void assertOutboundHanldersAreCalled()
+ {
+ bm.fireEvent(new ExceptionToCatch(new IllegalArgumentException()));
+
+ assertTrue(CalledExceptionHandler.OUTBOUND_HANDLER_CALLED);
+ }
+
+ @Test
+ public void assertOutboundHanldersAreCalledOnce()
+ {
+ CalledExceptionHandler.OUTBOUND_HANDLER_TIMES_CALLED = 0;
+ bm.fireEvent(new ExceptionToCatch(new IllegalArgumentException()));
+ assertEquals(1, CalledExceptionHandler.OUTBOUND_HANDLER_TIMES_CALLED);
+ }
+
+ @Test
+ public void assertInboundHanldersAreCalledOnce()
+ {
+ CalledExceptionHandler.INBOUND_HANDLER_TIMES_CALLED = 0;
+ bm.fireEvent(new ExceptionToCatch(new IllegalArgumentException()));
+ assertEquals(1, CalledExceptionHandler.INBOUND_HANDLER_TIMES_CALLED);
+ }
+
+ @Test
+ public void assertAdditionalParamsAreInjected()
+ {
+ bm.fireEvent(new ExceptionToCatch(new RuntimeException(new IllegalArgumentException())));
+ assertTrue(CalledExceptionHandler.BEANMANAGER_INJECTED);
+ }
+
+ @Test
+ public void assertAdditionalParamsAreInjectedWithDifferentHandlerLocation()
+ {
+ bm.fireEvent(new ExceptionToCatch(new SQLException()));
+ assertTrue(CalledExceptionHandler.LOCATION_DIFFER_BEANMANAGER_INJECTED);
+ }
+
+ @Test
+ public void assertProtectedHandlersAreCalled()
+ {
+ bm.fireEvent(new ExceptionToCatch(new IllegalStateException()));
+ assertTrue(CalledExceptionHandler.PROTECTED_HANDLER_CALLED);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/ExtensionExceptionHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/ExtensionExceptionHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/ExtensionExceptionHandler.java
new file mode 100644
index 0000000..791c66e
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/ExtensionExceptionHandler.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.handler;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+import org.apache.deltaspike.test.core.impl.exception.control.extension.Account;
+import org.apache.deltaspike.test.core.impl.exception.control.extension.Arquillian;
+import org.apache.deltaspike.test.core.impl.exception.control.extension.CatchQualifier;
+
+import javax.enterprise.inject.spi.BeanManager;
+import java.sql.SQLException;
+
+@ExceptionHandler
+public class ExtensionExceptionHandler
+{
+ public void catchDescException(@BeforeHandles CaughtException<Exception> event)
+ {
+ // Nothing to do currently
+ }
+
+ public void catchFrameworkDescException(@BeforeHandles(ordinal = -50) CaughtException<Exception> event)
+ {
+ // Nothing to do here
+ }
+
+ public void catchRuntime(@Handles CaughtException<RuntimeException> event)
+ {
+ // Nothing to do currently
+ }
+
+ public void catchThrowableBreadthFirst(
+ @BeforeHandles(ordinal = 10) CaughtException<Throwable> event)
+ {
+ // Nothing to do currently
+ }
+
+ public void catchThrowableP20BreadthFirst(
+ @BeforeHandles(ordinal = 20) CaughtException<Throwable> event)
+ {
+ // Nothing to do currently
+ }
+
+ public void catchThrowable(
+ @Handles(ordinal = 10) CaughtException<Throwable> event)
+ {
+ // Nothing to do currently
+ }
+
+ public void catchThrowableP20(
+ @Handles(ordinal = 20) CaughtException<Throwable> event)
+ {
+ // Nothing to do currently
+ }
+
+ public void catchIAE(@Handles CaughtException<IllegalArgumentException> event)
+ {
+ // Nothing to do currently
+ }
+
+ public void qualifiedHandler(@Handles @CatchQualifier CaughtException<Exception> event)
+ {
+ // Method to verify the qualifiers are working correctly for handlers
+ }
+
+ public void arqHandler(@Handles @Arquillian CaughtException<Throwable> event)
+ {
+ // Method to verify the qualifiers are working correctly for handlers
+ }
+
+ public void arqTestingHandler(@Handles @Arquillian @CatchQualifier CaughtException<Throwable> event)
+ {
+ // Method to verify the qualifiers are working correctly for handlers
+ }
+
+ public void differentParamHandlerLocationHandler(Account act, BeanManager bm,
+ @Handles CaughtException<SQLException> event)
+ {
+ // Nothing here, just need to make sure this handler is picked up
+ }
+
+ public void doNothingMethod()
+ {
+ // Method to make sure only @Handles methods are found
+ }
+
+ public void doNothingTwo(String p1, String p2, int p3)
+ {
+ // Same as above
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerComparatorTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerComparatorTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerComparatorTest.java
new file mode 100644
index 0000000..175efb5
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerComparatorTest.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.handler;
+
+import org.apache.deltaspike.core.api.exception.control.HandlerMethod;
+import org.apache.deltaspike.core.api.provider.BeanManagerProvider;
+import org.apache.deltaspike.core.impl.exception.control.HandlerMethodImpl;
+import org.apache.deltaspike.core.impl.exception.control.extension.CatchExtension;
+import org.apache.deltaspike.test.core.impl.exception.control.extension.Account;
+import org.apache.deltaspike.test.core.impl.exception.control.extension.CatchQualifier;
+import org.apache.deltaspike.test.util.ArchiveUtils;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+@RunWith(Arquillian.class)
+public class HandlerComparatorTest
+{
+ @Deployment(name = "HandlerComparatorTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "handlerComparator.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addClasses(ExtensionExceptionHandler.class, Account.class,
+ org.apache.deltaspike.test.core.impl.exception.control.extension.Arquillian.class,
+ CatchQualifier.class);
+ }
+
+ @Inject
+ BeanManager bm;
+
+ @Test
+ public void assertOrderIsCorrectDepthFirst()
+ {
+ List<HandlerMethod<? extends Throwable>> handlers = new ArrayList<HandlerMethod<? extends Throwable>>(
+ CatchExtension.createStorage().getHandlersForException(
+ IllegalArgumentException.class, bm, Collections.<Annotation>emptySet(), false));
+
+ System.out.println(handlers);
+
+ assertEquals("catchThrowable", ((HandlerMethodImpl<?>) handlers.get(0)).getJavaMethod().getName());
+ assertEquals("catchThrowableP20", ((HandlerMethodImpl<?>) handlers.get(1)).getJavaMethod().getName());
+ assertEquals("catchRuntime", ((HandlerMethodImpl<?>) handlers.get(2)).getJavaMethod().getName());
+ assertEquals("catchIAE", ((HandlerMethodImpl<?>) handlers.get(3)).getJavaMethod().getName());
+ }
+
+ @Test
+ public void assertOrderIsCorrectBreadthFirst()
+ {
+ List<HandlerMethod<? extends Throwable>> handlers = new ArrayList<HandlerMethod<? extends Throwable>>(
+ CatchExtension.createStorage().getHandlersForException(
+ Exception.class, bm, Collections.<Annotation>emptySet(), true));
+
+ assertThat(handlers.size(), is(4));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerWhichThrowsExceptions.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerWhichThrowsExceptions.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerWhichThrowsExceptions.java
new file mode 100644
index 0000000..e616b0f
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/HandlerWhichThrowsExceptions.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.handler;
+
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+/**
+ * ExceptionHandler which is not valid.
+ */
+@ExceptionHandler
+public class HandlerWhichThrowsExceptions
+{
+ public void throwsAnException(@Handles CaughtException<Throwable> evt) throws Exception
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/290d85d6/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/UnMuteHandler.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/UnMuteHandler.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/UnMuteHandler.java
new file mode 100644
index 0000000..9d10523
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/UnMuteHandler.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.test.core.impl.exception.control.handler;
+
+import org.apache.deltaspike.core.api.exception.control.BeforeHandles;
+import org.apache.deltaspike.core.api.exception.control.CaughtException;
+import org.apache.deltaspike.core.api.exception.control.ExceptionHandler;
+import org.apache.deltaspike.core.api.exception.control.Handles;
+
+@ExceptionHandler
+public class UnMuteHandler
+{
+ public static int DEPTH_FIRST_NUMBER_CALLED = 0;
+ public static int BREADTH_FIRST_NUMBER_CALLED = 0;
+
+ public void unMuteHandlerAsc(@Handles CaughtException<Exception> event)
+ {
+ DEPTH_FIRST_NUMBER_CALLED++;
+ event.unmute();
+ }
+
+ public void unMuteHandlerDesc(@BeforeHandles CaughtException<Exception> event)
+ {
+ BREADTH_FIRST_NUMBER_CALLED++;
+ event.unmute();
+ }
+}