-
Notifications
You must be signed in to change notification settings - Fork 45
/
BuiltinBeanPassivationDependencyTest.java
115 lines (90 loc) · 4.61 KB
/
BuiltinBeanPassivationDependencyTest.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package org.jboss.cdi.tck.tests.full.context.passivating.dependency.builtin;
import static org.jboss.cdi.tck.TestGroups.CDI_FULL;
import static org.jboss.cdi.tck.cdi.Sections.PASSIVATION_CAPABLE_DEPENDENCY;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import java.io.IOException;
import jakarta.enterprise.inject.spi.Annotated;
import jakarta.enterprise.inject.spi.AnnotatedMember;
import jakarta.enterprise.inject.spi.AnnotatedParameter;
import jakarta.enterprise.inject.spi.AnnotatedType;
import jakarta.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.cdi.tck.AbstractTest;
import org.jboss.cdi.tck.shrinkwrap.WebArchiveBuilder;
import org.jboss.cdi.tck.util.Assert;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecVersion;
import org.testng.annotations.Test;
/**
*
* @author Martin Kouba
* @author Kirill Gaevskii
*/
@SpecVersion(spec = "cdi", version = "2.0")
@Test(groups = CDI_FULL)
public class BuiltinBeanPassivationDependencyTest extends AbstractTest {
@Deployment
public static WebArchive createTestArchive() {
return new WebArchiveBuilder().withTestClassPackage(BuiltinBeanPassivationDependencyTest.class).build();
}
@Inject
Worker worker;
@Inject
Boss boss;
@Inject
InspectorAssistant inspectorAssist;
@Test
@SpecAssertion(section = PASSIVATION_CAPABLE_DEPENDENCY, id = "ea")
public void testInstance() throws IOException, ClassNotFoundException {
assertNotNull(worker);
assertNotNull(worker.getInstance());
Hammer hammer = worker.getInstance().get();
assertNotNull(hammer);
String workerId = worker.getId();
String hammerId = hammer.getId();
byte[] serializedWorker = passivate(worker);
Worker workerCopy = (Worker) activate(serializedWorker);
assertNotNull(workerCopy);
assertNotNull(workerCopy.getInstance());
assertEquals(workerCopy.getId(), workerId);
assertEquals(workerCopy.getInstance().get().getId(), hammerId);
}
@Test
@SpecAssertion(section = PASSIVATION_CAPABLE_DEPENDENCY, id = "ed")
public void testBeanManager() throws IOException, ClassNotFoundException {
assertNotNull(boss);
assertNotNull(boss.getBeanManager());
String bossId = boss.getId();
byte[] serializedBoss = passivate(boss);
Boss bossCopy = (Boss) activate(serializedBoss);
assertNotNull(bossCopy);
assertNotNull(bossCopy.getBeanManager());
assertEquals(bossCopy.getId(), bossId);
assertEquals(bossCopy.getBeanManager().getBeans(Boss.class).size(), 1);
}
@Test
@SpecAssertion(section = PASSIVATION_CAPABLE_DEPENDENCY, id = "ec")
public void testInjectionPoint() throws IOException, ClassNotFoundException {
Inspector inspector = inspectorAssist.getInspector();
assertNotNull(inspector);
assertNotNull(inspector.getInjectionPoint());
String inspectorId = inspector.getId();
byte[] serializedInspector = passivate(inspector);
Inspector inspectorCopy = (Inspector) activate(serializedInspector);
assertNotNull(inspectorCopy);
assertNotNull(inspectorCopy.getInjectionPoint());
assertEquals(inspectorCopy.getId(), inspectorId);
assertEquals(inspectorCopy.getInjectionPoint().getType(), inspector.getInjectionPoint().getType());
assertEquals(inspectorCopy.getInjectionPoint().getQualifiers(), inspector.getInjectionPoint().getQualifiers());
assertEquals(inspectorCopy.getInjectionPoint().getBean(), inspector.getInjectionPoint().getBean());
assertEquals(inspectorCopy.getInjectionPoint().getMember(), inspector.getInjectionPoint().getMember());
// Annotated does not necessarily implement equals()/hashcode() so we need to test the underlying Java reflection object
Assert.assertAnnotated(inspectorCopy.getInjectionPoint().getAnnotated(), inspector.getInjectionPoint().getAnnotated());
assertEquals(inspectorCopy.getInjectionPoint().getAnnotated().getBaseType(), inspector.getInjectionPoint().getAnnotated().getBaseType());
assertEquals(inspectorCopy.getInjectionPoint().getAnnotated().getAnnotations(), inspector.getInjectionPoint().getAnnotated().getAnnotations());
assertEquals(inspectorCopy.getInjectionPoint().isDelegate(), inspector.getInjectionPoint().isDelegate());
assertEquals(inspectorCopy.getInjectionPoint().isTransient(), inspector.getInjectionPoint().isTransient());
}
}