Commit 360c7bde678a56f964010e69d574e33bb1258a29
1 parent
e807d225
test: loginUser()-Test
Showing
1 changed file
with
18 additions
and
16 deletions
src/test/java/net/ziemers/swxercise/lg/user/service/UserServiceTest.java
... | ... | @@ -10,9 +10,8 @@ import net.ziemers.swxercise.lg.user.dto.UserDto; |
10 | 10 | |
11 | 11 | import static org.junit.Assert.*; |
12 | 12 | |
13 | -import org.jglue.cdiunit.AdditionalClasses; | |
14 | 13 | import org.jglue.cdiunit.CdiRunner; |
15 | -import org.jglue.cdiunit.InSessionScope; | |
14 | +import org.jglue.cdiunit.InRequestScope; | |
16 | 15 | import org.junit.Before; |
17 | 16 | import org.junit.Test; |
18 | 17 | import org.junit.runner.RunWith; |
... | ... | @@ -27,7 +26,6 @@ import org.junit.runner.RunWith; |
27 | 26 | * there, however CDI-Unit has extra support for Mockito @Mock annotations. |
28 | 27 | */ |
29 | 28 | @RunWith(CdiRunner.class) |
30 | -@AdditionalClasses(SessionContext.class) | |
31 | 29 | public class UserServiceTest extends JpaTestUtils { |
32 | 30 | |
33 | 31 | private static String USERNAME_TEST = "username_test"; |
... | ... | @@ -56,19 +54,23 @@ public class UserServiceTest extends JpaTestUtils { |
56 | 54 | } |
57 | 55 | } |
58 | 56 | |
59 | -// @Test | |
60 | -// @InSessionScope | |
61 | -// public void testLoginUserReturnsSuccess() { | |
62 | -// | |
63 | -// given() | |
64 | -// .userDto(EXISTING_USERNAME_TEST); | |
65 | -// | |
66 | -// when() | |
67 | -// .loginUser(EXISTING_PASSWORD_TEST); | |
68 | -// | |
69 | -// then() | |
70 | -// .assertLoginSuccess(); | |
71 | -// } | |
57 | + /* | |
58 | + * In order to inject @SessionScoped beans, one has to annotate the function or class with @InRequestScope | |
59 | + * as only this annotation guarantees to have the session scope active always. | |
60 | + */ | |
61 | + @Test | |
62 | + @InRequestScope | |
63 | + public void testLoginUserReturnsSuccess() { | |
64 | + | |
65 | + given() | |
66 | + .userDto(EXISTING_USERNAME_TEST); | |
67 | + | |
68 | + when() | |
69 | + .loginUser(EXISTING_PASSWORD_TEST); | |
70 | + | |
71 | + then() | |
72 | + .assertLoginSuccess(); | |
73 | + } | |
72 | 74 | |
73 | 75 | @Test |
74 | 76 | public void testCreateUserReturnsSuccess() { | ... | ... |