Commit 2e73629ca6ad00df846ca635b496c04b7cb3f3d1
1 parent
7de29276
bugfix: Service-Tests repariert (Konflikt mit dem Weld SE von Jetty)
Showing
2 changed files
with
38 additions
and
0 deletions
src/test/java/net/ziemers/swxercise/lg/user/service/RoleServiceTest.java
... | ... | @@ -3,11 +3,13 @@ package net.ziemers.swxercise.lg.user.service; |
3 | 3 | import net.ziemers.swxercise.db.dao.user.UserDao; |
4 | 4 | import net.ziemers.swxercise.db.utils.JpaTestUtils; |
5 | 5 | import org.jglue.cdiunit.CdiRunner; |
6 | +import org.junit.After; | |
6 | 7 | import org.junit.Before; |
7 | 8 | import org.junit.Test; |
8 | 9 | import org.junit.runner.RunWith; |
9 | 10 | |
10 | 11 | import javax.inject.Inject; |
12 | +import javax.naming.InitialContext; | |
11 | 13 | |
12 | 14 | /** |
13 | 15 | * Testing your Java CDI application with CDI-Unit couldn't be easier. |
... | ... | @@ -33,6 +35,8 @@ public class RoleServiceTest extends JpaTestUtils { |
33 | 35 | |
34 | 36 | @Before |
35 | 37 | public void setUp() throws Exception { |
38 | + // wird vor jedem Test ausgeführt | |
39 | + | |
36 | 40 | if (!dbInitialized) { |
37 | 41 | cleanDb(); |
38 | 42 | initDbWith("RoleServiceTestData.xml"); |
... | ... | @@ -40,6 +44,21 @@ public class RoleServiceTest extends JpaTestUtils { |
40 | 44 | } |
41 | 45 | } |
42 | 46 | |
47 | + @After | |
48 | + public void tearDown() throws Exception { | |
49 | + // wird nach jedem Test ausgeführt | |
50 | + | |
51 | + /* | |
52 | + * java.lang.IllegalStateException: WELD-ENV-002000: Weld SE container STATIC_INSTANCE is already running! | |
53 | + * | |
54 | + * Jetty initialisiert einen eigenen Weld SE Container, der mit demjenigen | |
55 | + * vom CDI-Runner kollidiert. Wir müssen ihn deshalb hier entfernen. | |
56 | + * Quelle: https://groups.google.com/forum/#!topic/cdi-unit/2e-XnyduXcs | |
57 | + */ | |
58 | + InitialContext initialContext = new InitialContext(); | |
59 | + initialContext.unbind("java:comp/BeanManager"); | |
60 | + } | |
61 | + | |
43 | 62 | @Test |
44 | 63 | public void testSomething() { |
45 | 64 | ... | ... |
src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
... | ... | @@ -5,6 +5,7 @@ import java.util.Collection; |
5 | 5 | import java.util.HashSet; |
6 | 6 | import java.util.Set; |
7 | 7 | import javax.inject.Inject; |
8 | +import javax.naming.InitialContext; | |
8 | 9 | |
9 | 10 | import net.ziemers.swxercise.db.dao.user.UserDao; |
10 | 11 | import net.ziemers.swxercise.db.utils.JpaTestUtils; |
... | ... | @@ -16,6 +17,7 @@ import static org.junit.Assert.*; |
16 | 17 | |
17 | 18 | import org.jglue.cdiunit.CdiRunner; |
18 | 19 | import org.jglue.cdiunit.InRequestScope; |
20 | +import org.junit.After; | |
19 | 21 | import org.junit.Before; |
20 | 22 | import org.junit.Test; |
21 | 23 | import org.junit.runner.RunWith; |
... | ... | @@ -60,6 +62,8 @@ public class UserServiceTest extends JpaTestUtils { |
60 | 62 | |
61 | 63 | @Before |
62 | 64 | public void setUp() throws Exception { |
65 | + // wird vor jedem Test ausgeführt | |
66 | + | |
63 | 67 | if (!dbInitialized) { |
64 | 68 | cleanDb(); |
65 | 69 | initDbWith("UserServiceTestData.xml"); |
... | ... | @@ -67,6 +71,21 @@ public class UserServiceTest extends JpaTestUtils { |
67 | 71 | } |
68 | 72 | } |
69 | 73 | |
74 | + @After | |
75 | + public void tearDown() throws Exception { | |
76 | + // wird nach jedem Test ausgeführt | |
77 | + | |
78 | + /* | |
79 | + * java.lang.IllegalStateException: WELD-ENV-002000: Weld SE container STATIC_INSTANCE is already running! | |
80 | + * | |
81 | + * Jetty initialisiert einen eigenen Weld SE Container, der mit demjenigen | |
82 | + * vom CDI-Runner kollidiert. Wir müssen ihn deshalb hier entfernen. | |
83 | + * Quelle: https://groups.google.com/forum/#!topic/cdi-unit/2e-XnyduXcs | |
84 | + */ | |
85 | + InitialContext initialContext = new InitialContext(); | |
86 | + initialContext.unbind("java:comp/BeanManager"); | |
87 | + } | |
88 | + | |
70 | 89 | /* |
71 | 90 | * In order to inject @SessionScoped beans, one has to annotate the function or class with @InRequestScope |
72 | 91 | * as only this annotation guarantees to have the session scope active always. | ... | ... |