Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for lifecycle event interceptor ordering
- Loading branch information
Showing
8 changed files
with
468 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/lifecycle/Bar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.interceptors.lifecycle; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
|
||
@InterceptorBinding | ||
@Inherited | ||
@Target({ TYPE }) | ||
@Retention(RUNTIME) | ||
public @interface Bar { | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...-arquillian/src/test/java/org/jboss/weld/tests/interceptors/lifecycle/BarInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.interceptors.lifecycle; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@Bar | ||
public class BarInterceptor { | ||
|
||
private static boolean postConstructCalled; | ||
private static boolean preDestroyCalled; | ||
|
||
@PostConstruct | ||
public void postConstruct(InvocationContext ctx) { | ||
assertTrue(FooInterceptor.isPostConstructCalled()); | ||
assertFalse(BarInterceptor.isPostConstructCalled()); | ||
assertFalse(BazInterceptor.isPostConstructCalled()); | ||
assertFalse(Donkey.isPostConstructCalled()); | ||
postConstructCalled = true; | ||
try { | ||
ctx.proceed(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void preDestroy(InvocationContext ctx) { | ||
assertTrue(FooInterceptor.isPreDestroyCalled()); | ||
assertFalse(BarInterceptor.isPreDestroyCalled()); | ||
assertFalse(BazInterceptor.isPreDestroyCalled()); | ||
assertFalse(Donkey.isPreDestroyCalled()); | ||
preDestroyCalled = true; | ||
try { | ||
ctx.proceed(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static boolean isPostConstructCalled() { | ||
return postConstructCalled; | ||
} | ||
|
||
public static boolean isPreDestroyCalled() { | ||
return preDestroyCalled; | ||
} | ||
|
||
public static void reset() { | ||
postConstructCalled = false; | ||
preDestroyCalled = false; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/lifecycle/Baz.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.interceptors.lifecycle; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
|
||
@InterceptorBinding | ||
@Inherited | ||
@Target({ TYPE }) | ||
@Retention(RUNTIME) | ||
public @interface Baz { | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...-arquillian/src/test/java/org/jboss/weld/tests/interceptors/lifecycle/BazInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.interceptors.lifecycle; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@Baz | ||
public class BazInterceptor { | ||
|
||
private static boolean postConstructCalled; | ||
private static boolean preDestroyCalled; | ||
|
||
@PostConstruct | ||
public void postConstruct(InvocationContext ctx) { | ||
assertTrue(FooInterceptor.isPostConstructCalled()); | ||
assertTrue(BarInterceptor.isPostConstructCalled()); | ||
assertFalse(BazInterceptor.isPostConstructCalled()); | ||
assertFalse(Donkey.isPostConstructCalled()); | ||
postConstructCalled = true; | ||
try { | ||
ctx.proceed(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void preDestroy(InvocationContext ctx) { | ||
assertTrue(FooInterceptor.isPreDestroyCalled()); | ||
assertTrue(BarInterceptor.isPreDestroyCalled()); | ||
assertFalse(BazInterceptor.isPreDestroyCalled()); | ||
assertFalse(Donkey.isPreDestroyCalled()); | ||
preDestroyCalled = true; | ||
try { | ||
ctx.proceed(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static boolean isPostConstructCalled() { | ||
return postConstructCalled; | ||
} | ||
|
||
public static boolean isPreDestroyCalled() { | ||
return preDestroyCalled; | ||
} | ||
|
||
public static void reset() { | ||
postConstructCalled = false; | ||
preDestroyCalled = false; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/lifecycle/Donkey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.interceptors.lifecycle; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
|
||
@Foo | ||
@Bar | ||
@Baz | ||
public class Donkey { | ||
|
||
private static boolean postConstructCalled; | ||
private static boolean preDestroyCalled; | ||
|
||
@PostConstruct | ||
public void postConstruct() { | ||
assertTrue(FooInterceptor.isPostConstructCalled()); | ||
assertTrue(BarInterceptor.isPostConstructCalled()); | ||
assertTrue(BazInterceptor.isPostConstructCalled()); | ||
assertFalse(Donkey.isPostConstructCalled()); | ||
postConstructCalled = true; | ||
} | ||
|
||
@PreDestroy | ||
public void preDestroy() { | ||
assertTrue(FooInterceptor.isPreDestroyCalled()); | ||
assertTrue(BarInterceptor.isPreDestroyCalled()); | ||
assertTrue(BazInterceptor.isPreDestroyCalled()); | ||
assertFalse(Donkey.isPreDestroyCalled()); | ||
preDestroyCalled = true; | ||
} | ||
|
||
public static boolean isPostConstructCalled() { | ||
return postConstructCalled; | ||
} | ||
|
||
public static boolean isPreDestroyCalled() { | ||
return preDestroyCalled; | ||
} | ||
|
||
public static void reset() { | ||
postConstructCalled = false; | ||
preDestroyCalled = false; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests-arquillian/src/test/java/org/jboss/weld/tests/interceptors/lifecycle/Foo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.interceptors.lifecycle; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import javax.interceptor.InterceptorBinding; | ||
|
||
@InterceptorBinding | ||
@Inherited | ||
@Target({ TYPE }) | ||
@Retention(RUNTIME) | ||
public @interface Foo { | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...-arquillian/src/test/java/org/jboss/weld/tests/interceptors/lifecycle/FooInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2012, Red Hat, Inc., and individual contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* Licensed 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.jboss.weld.tests.interceptors.lifecycle; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@Foo | ||
public class FooInterceptor { | ||
|
||
private static boolean postConstructCalled; | ||
private static boolean preDestroyCalled; | ||
|
||
@PostConstruct | ||
public void postConstruct(InvocationContext ctx) { | ||
assertFalse(FooInterceptor.isPostConstructCalled()); | ||
assertFalse(BarInterceptor.isPostConstructCalled()); | ||
assertFalse(BazInterceptor.isPostConstructCalled()); | ||
assertFalse(Donkey.isPostConstructCalled()); | ||
postConstructCalled = true; | ||
try { | ||
ctx.proceed(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void preDestroy(InvocationContext ctx) { | ||
assertFalse(FooInterceptor.isPreDestroyCalled()); | ||
assertFalse(BarInterceptor.isPreDestroyCalled()); | ||
assertFalse(BazInterceptor.isPreDestroyCalled()); | ||
assertFalse(Donkey.isPreDestroyCalled()); | ||
preDestroyCalled = true; | ||
try { | ||
ctx.proceed(); | ||
} catch (Throwable e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static boolean isPostConstructCalled() { | ||
return postConstructCalled; | ||
} | ||
|
||
public static boolean isPreDestroyCalled() { | ||
return preDestroyCalled; | ||
} | ||
|
||
public static void reset() { | ||
postConstructCalled = false; | ||
preDestroyCalled = false; | ||
} | ||
} |
Oops, something went wrong.