|
| 1 | +package org.javaee7.cdi.interceptors.priority; |
| 2 | + |
| 3 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 4 | +import org.jboss.arquillian.junit.Arquillian; |
| 5 | +import org.jboss.shrinkwrap.api.Archive; |
| 6 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 7 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.runner.RunWith; |
| 10 | + |
| 11 | +import javax.inject.Inject; |
| 12 | + |
| 13 | +import static org.hamcrest.CoreMatchers.*; |
| 14 | +import static org.junit.Assert.assertEquals; |
| 15 | +import static org.junit.Assert.assertThat; |
| 16 | + |
| 17 | +/** |
| 18 | + * Note that beans.xml doesn't define any interceptor. Interceptors declared using interceptor bindings |
| 19 | + * are enabled for the entire application and ordered using the Priority annotation. |
| 20 | + * |
| 21 | + * @author Radim Hanus |
| 22 | + */ |
| 23 | +@RunWith(Arquillian.class) |
| 24 | +public class GreetingTest { |
| 25 | + @Deployment |
| 26 | + public static Archive<?> deploy() { |
| 27 | + return ShrinkWrap.create(JavaArchive.class) |
| 28 | + .addClasses(Greeting.class, SimpleGreeting.class, MyInterceptorBinding.class, LowPriorityInterceptor.class, HighPriorityInterceptor.class) |
| 29 | + .addAsManifestResource("beans.xml"); |
| 30 | + } |
| 31 | + |
| 32 | + @Inject |
| 33 | + Greeting bean; |
| 34 | + |
| 35 | + @Test |
| 36 | + public void test() throws Exception { |
| 37 | + assertThat(bean, is(notNullValue())); |
| 38 | + assertThat(bean, instanceOf(SimpleGreeting.class)); |
| 39 | + |
| 40 | + bean.setGreet("Arun"); |
| 41 | + assertEquals(bean.getGreet(), "Hi Arun ! Nice to meet you."); |
| 42 | + } |
| 43 | +} |
0 commit comments