forked from wildfly/wildfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
366 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/ActionSequence.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,43 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ActionSequence { | ||
|
||
private static final List<String> actions = Collections.synchronizedList(new ArrayList<String>()); | ||
|
||
public static void addAction(String action) { | ||
actions.add(action); | ||
} | ||
|
||
public static List<String> getActions() { | ||
return Collections.unmodifiableList(actions); | ||
} | ||
|
||
public static void reset() { | ||
actions.clear(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/CdiIntercepted.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,39 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.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 CdiIntercepted { | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/CdiInterceptor.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,56 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@Interceptor | ||
@CdiIntercepted | ||
public class CdiInterceptor implements Serializable { | ||
|
||
private static final long serialVersionUID = -5949866804898740300L; | ||
|
||
@PostConstruct | ||
void postConstruct(InvocationContext ctx) { | ||
try { | ||
ActionSequence.addAction(CdiInterceptor.class.getSimpleName()); | ||
ctx.proceed(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
void preDestroy(InvocationContext ctx) { | ||
try { | ||
ActionSequence.addAction(CdiInterceptor.class.getSimpleName()); | ||
ctx.proceed(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...rg/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/InterceptedBean.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,43 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.ejb.Stateful; | ||
import javax.interceptor.Interceptors; | ||
|
||
@Stateful | ||
@Interceptors(LegacyInterceptor.class) | ||
@CdiIntercepted | ||
public class InterceptedBean extends Superclass { | ||
|
||
@PostConstruct | ||
void postConstruct() { | ||
ActionSequence.addAction(InterceptedBean.class.getSimpleName()); | ||
} | ||
|
||
@PreDestroy | ||
void preDestroy() { | ||
ActionSequence.addAction(InterceptedBean.class.getSimpleName()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
.../jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/LegacyInterceptor.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,53 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; | ||
|
||
import java.io.Serializable; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.interceptor.InvocationContext; | ||
|
||
public class LegacyInterceptor implements Serializable { | ||
|
||
private static final long serialVersionUID = -3142706070329564629L; | ||
|
||
@PostConstruct | ||
void postConstruct(InvocationContext ctx) { | ||
try { | ||
ActionSequence.addAction(LegacyInterceptor.class.getSimpleName()); | ||
ctx.proceed(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
void preDestroy(InvocationContext ctx) { | ||
try { | ||
ActionSequence.addAction(LegacyInterceptor.class.getSimpleName()); | ||
ctx.proceed(); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
.../weld/ejb/interceptor/ordering/lifecycle/SessionBeanLifecycleInterceptorOrderingTest.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,94 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.enterprise.context.spi.CreationalContext; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.inject.Inject; | ||
import javax.interceptor.Interceptors; | ||
|
||
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.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Tests that session bean lifecycle interceptors are executed in the following order: | ||
* | ||
* 1) Interceptors bound using the {@link Interceptors} annotation | ||
* 2) Interceptors bound using CDI interceptor bindings | ||
* 3) Interceptors defined on a superclass of the bean defining class | ||
* 4) Interceptors defined on the bean defining class | ||
* | ||
*@see https://issues.jboss.org/browse/AS7-6739 | ||
* | ||
* @author Jozef Hartinger | ||
* | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class SessionBeanLifecycleInterceptorOrderingTest { | ||
|
||
@Inject | ||
private BeanManager manager; | ||
|
||
@Deployment | ||
public static Archive<?> getDeployment() { | ||
return ShrinkWrap | ||
.create(WebArchive.class) | ||
.addPackage(SessionBeanLifecycleInterceptorOrderingTest.class.getPackage()) | ||
.addAsWebInfResource( | ||
new StringAsset("<beans><interceptors><class>" + CdiInterceptor.class.getName() | ||
+ "</class></interceptors></beans>"), "beans.xml"); | ||
} | ||
|
||
@Test | ||
public void testSessionBeanLifecycleInterceptorOrdering() { | ||
@SuppressWarnings("unchecked") | ||
Bean<InterceptedBean> bean = (Bean<InterceptedBean>) manager.resolve(manager.getBeans(InterceptedBean.class)); | ||
CreationalContext<InterceptedBean> ctx = manager.createCreationalContext(bean); | ||
|
||
List<String> expected = new ArrayList<String>(); | ||
expected.add(LegacyInterceptor.class.getSimpleName()); | ||
expected.add(CdiInterceptor.class.getSimpleName()); | ||
expected.add(Superclass.class.getSimpleName()); | ||
expected.add(InterceptedBean.class.getSimpleName()); | ||
|
||
ActionSequence.reset(); | ||
// create a new instance | ||
InterceptedBean instance = bean.create(ctx); | ||
assertEquals(expected, ActionSequence.getActions()); | ||
|
||
ActionSequence.reset(); | ||
bean.destroy(instance, ctx); | ||
assertEquals(expected, ActionSequence.getActions()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ava/org/jboss/as/test/integration/weld/ejb/interceptor/ordering/lifecycle/Superclass.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,38 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source. | ||
* Copyright (c) 2011, Red Hat, Inc., and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.jboss.as.test.integration.weld.ejb.interceptor.ordering.lifecycle; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
|
||
public class Superclass { | ||
|
||
@PostConstruct | ||
void postConstructSuperclass() { | ||
ActionSequence.addAction(Superclass.class.getSimpleName()); | ||
} | ||
|
||
@PreDestroy | ||
void preDestroySuperclass() { | ||
ActionSequence.addAction(Superclass.class.getSimpleName()); | ||
} | ||
} |