01: package org.vraptor.plugin.jpa;
02:
03: import java.util.List;
04:
05: import org.vraptor.AbstractTest;
06: import org.vraptor.component.BeanConstructor;
07: import org.vraptor.component.ComponentType;
08: import org.vraptor.interceptor.InterceptorType;
09:
10: /**
11: * @author Fabio Correia Kung
12: *
13: */
14: public class JavaPersistenceComponentTest extends AbstractTest {
15:
16: private ComponentType dependentType;
17:
18: private EntityManagerIntrospector introspector;
19:
20: private ComponentType wrongDependentType;
21:
22: private ComponentType independentType;
23:
24: @Override
25: protected void setUp() throws Exception {
26: super .setUp();
27: this .dependentType = createComponentType(EntityManagerDependent.class);
28: this .wrongDependentType = createComponentType(EntityManagerWrongDependent.class);
29: this .independentType = createComponentType(EntityManagerIndependent.class);
30: this .introspector = new EntityManagerIntrospector();
31: }
32:
33: /**
34: * Test method for
35: * {@link org.vraptor.plugin.jpa.JavaPersistenceComponent#getInterceptors()}.
36: */
37: public void testAddsJavaPersistenceInterceptor() {
38: InterceptorType expected = InterceptorType
39: .getType(JavaPersistenceInterceptor.class);
40: JavaPersistenceComponent component = new JavaPersistenceComponent(
41: this .dependentType, this .introspector);
42: List<InterceptorType> interceptors = component
43: .getInterceptors();
44: assertTrue("added", interceptors.contains(expected));
45: }
46:
47: /**
48: * Test method for
49: * {@link org.vraptor.plugin.jpa.JavaPersistenceComponent#getConstructor()}.
50: */
51: public void testReturnEntityManagerInjectorForDependentComponent() {
52: JavaPersistenceComponent component = new JavaPersistenceComponent(
53: this .dependentType, this .introspector);
54: BeanConstructor constructor = component.getConstructor();
55: assertTrue("must be an EntityInjector",
56: constructor instanceof EntityManagerInjector);
57: }
58:
59: /**
60: * Test method for
61: * {@link org.vraptor.plugin.jpa.JavaPersistenceComponent#getConstructor()}.
62: */
63: public void testNotReturnEntityManagerInjectorForMissingPersistenceContextAnnotation() {
64: JavaPersistenceComponent component = new JavaPersistenceComponent(
65: this .wrongDependentType, this .introspector);
66: BeanConstructor constructor = component.getConstructor();
67: assertFalse("must not be an EntityInjector",
68: constructor instanceof EntityManagerInjector);
69: }
70:
71: /**
72: * Test method for
73: * {@link org.vraptor.plugin.jpa.JavaPersistenceComponent#getConstructor()}.
74: */
75: public void testNotReturnEntityManagerInjectorForIndependentComponent() {
76: JavaPersistenceComponent component = new JavaPersistenceComponent(
77: this .independentType, this .introspector);
78: BeanConstructor constructor = component.getConstructor();
79: assertFalse("must not be an EntityInjector",
80: constructor instanceof EntityManagerInjector);
81:
82: }
83: }
|