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
[3/6] Adding tests
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/UnMuteHandlerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/UnMuteHandlerTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/UnMuteHandlerTest.java
new file mode 100644
index 0000000..f67b098
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/handler/UnMuteHandlerTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.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 UnMuteHandlerTest
+{
+ @Deployment(name = "UnMuteHandlerTest")
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "unMuteHandler.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addClasses(UnMuteHandler.class);
+ }
+
+ @Inject
+ private BeanManager bm;
+
+ @Test
+ public void assertCorrectNumberOfCallsForUnMute()
+ {
+ bm.fireEvent(new ExceptionToCatch(new Exception(new NullPointerException())));
+
+ assertEquals(2, UnMuteHandler.DEPTH_FIRST_NUMBER_CALLED);
+ assertEquals(2, UnMuteHandler.BREADTH_FIRST_NUMBER_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/traversal/ExceptionHandlerMethods.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/ExceptionHandlerMethods.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/ExceptionHandlerMethods.java
new file mode 100644
index 0000000..50cbeaa
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/ExceptionHandlerMethods.java
@@ -0,0 +1,79 @@
+/*
+ * 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.traversal;
+
+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 java.util.ArrayList;
+import java.util.List;
+
+@ExceptionHandler
+public class ExceptionHandlerMethods
+{
+ private static final List<Integer> executionOrder = new ArrayList<Integer>();
+
+ public void handleException1BF(@BeforeHandles CaughtException<Exceptions.Exception1> event)
+ {
+ executionOrder.add(7);
+ }
+
+ public void handleException2BF(@BeforeHandles CaughtException<Exceptions.Exception2> event)
+ {
+ executionOrder.add(5);
+ }
+
+ public void handleException3DF(@Handles CaughtException<Exceptions.Exception3> event)
+ {
+ executionOrder.add(3);
+ }
+
+ public void handleException3BF(@BeforeHandles CaughtException<Exceptions.Exception3> event)
+ {
+ executionOrder.add(2);
+ }
+
+ public void handleException3SuperclassBF(@BeforeHandles CaughtException<Exceptions.Exception3Super> event)
+ {
+ executionOrder.add(1);
+ }
+
+ public void handleException3SuperclassDF(@Handles CaughtException<Exceptions.Exception3Super> event)
+ {
+ executionOrder.add(4);
+ }
+
+ public void handleException2DF(@Handles CaughtException<Exceptions.Exception2> event)
+ {
+ executionOrder.add(6);
+ }
+
+ public void handleException1DF(@Handles CaughtException<Exceptions.Exception1> event)
+ {
+ executionOrder.add(8);
+ }
+
+ public static List<Integer> getExecutionorder()
+ {
+ return executionOrder;
+ }
+}
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/traversal/Exceptions.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/Exceptions.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/Exceptions.java
new file mode 100644
index 0000000..b670a97
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/Exceptions.java
@@ -0,0 +1,53 @@
+/*
+ * 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.traversal;
+
+public class Exceptions
+{
+ public static class Exception1 extends Exception
+ {
+ private static final long serialVersionUID = 3748419159086636984L;
+
+ public Exception1(Throwable cause)
+ {
+ super(cause);
+ }
+ }
+
+ public static class Exception2 extends Exception
+ {
+ private static final long serialVersionUID = 7151417049655860515L;
+
+ public Exception2(Throwable cause)
+ {
+ super(cause);
+ }
+ }
+
+ public static class Exception3Super extends Exception
+ {
+ private static final long serialVersionUID = 1886009541068471679L;
+ }
+
+ public static class Exception3 extends Exception3Super
+ {
+ private static final long serialVersionUID = -7924704072611802705L;
+ }
+}
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/traversal/TraversalPathTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/TraversalPathTest.java b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/TraversalPathTest.java
new file mode 100644
index 0000000..51633c7
--- /dev/null
+++ b/deltaspike/core/impl/src/test/java/org/apache/deltaspike/test/core/impl/exception/control/traversal/TraversalPathTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.traversal;
+
+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.assertArrayEquals;
+
+@RunWith(Arquillian.class)
+public class TraversalPathTest
+{
+ @Inject
+ private BeanManager manager;
+
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ new BeanManagerProvider()
+ {
+ @Override
+ public void setTestMode()
+ {
+ super.setTestMode();
+ }
+ }.setTestMode();
+
+ return ShrinkWrap
+ .create(WebArchive.class, "traversalPath.war")
+ .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
+ .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
+ .addPackage(TraversalPathTest.class.getPackage());
+ }
+
+ /**
+ * Tests SEAMCATCH-32, see JIRA for more information about this test. https://issues.jboss.org/browse/SEAMCATCH-32
+ */
+ @Test
+ public void testTraversalPathOrder()
+ {
+ // create an exception stack E1 -> E2 -> E3
+ Exceptions.Exception1 exception = new Exceptions.Exception1(new
+ Exceptions.Exception2(new Exceptions.Exception3()));
+
+ manager.fireEvent(new ExceptionToCatch(exception));
+
+ /*
+ handleException3SuperclassBF
+ handleException3BF
+ handleException3DF
+ handleException3SuperclassDF
+ handleException2BF
+ handleException2DF
+ handleException1BF
+ handleException1DF
+ */
+ Object[] expectedOrder = {1, 2, 3, 4, 5, 6, 7, 8};
+ assertArrayEquals(expectedOrder, ExceptionHandlerMethods.getExecutionorder().toArray());
+ }
+}