-
Notifications
You must be signed in to change notification settings - Fork 2
/
EnableInterceptorTest.java
43 lines (39 loc) · 1.64 KB
/
EnableInterceptorTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package org.jboss.seam.compat.cdi.interceptor;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.spec.cdi.beans.BeansDescriptor;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
/**
* This test checks that an interceptor enabled in beans.xml
* properly intercepts a method to which it is bound.
*
* @author Dan Allen
*/
@RunWith(Arquillian.class)
public class EnableInterceptorTest {
@Deployment
public static WebArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addClasses(Bit.class, FlipBit.class, FlipBitInterceptor.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
BeansDescriptor beansXml = Descriptors.create(BeansDescriptor.class).interceptor(FlipBitInterceptor.class);
return ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(Bean.class)
.addAsLibrary(jar)
.addAsWebInfResource(new StringAsset(beansXml.exportAsString()), beansXml.getDescriptorName());
}
@Test
public void shouldInterceptBeanMethod(Bean bean, Bit bit) {
bit.reset();
bean.operation();
Assert.assertTrue("Method was not intercepted", bit.isFlipped());
}
}