|
1 | | -package com.baeldung.ldap.client; |
2 | | - |
3 | | -import com.baeldung.ldap.data.service.UserService; |
4 | | -import com.baeldung.ldap.javaconfig.TestConfig; |
5 | | -import org.hamcrest.Matchers; |
6 | | -import org.junit.Test; |
7 | | -import org.junit.runner.RunWith; |
8 | | -import org.springframework.beans.factory.annotation.Autowired; |
9 | | -import org.springframework.test.context.ActiveProfiles; |
10 | | -import org.springframework.test.context.ContextConfiguration; |
11 | | -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
12 | | -import org.springframework.test.context.support.AnnotationConfigContextLoader; |
13 | | - |
14 | | -import java.util.List; |
15 | | - |
16 | | -import static org.junit.Assert.assertEquals; |
17 | | -import static org.junit.Assert.assertThat; |
18 | | - |
19 | | -@RunWith(SpringJUnit4ClassRunner.class) |
20 | | -@ActiveProfiles("testlive") |
21 | | -@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class) |
22 | | -public class LdapDataRepositoryTest { |
23 | | - |
24 | | - private static final String USER2 = "TEST02"; |
25 | | - private static final String USER3 = "TEST03"; |
26 | | - private static final String USER4 = "TEST04"; |
27 | | - |
28 | | - private static final String USER2_PWD = "TEST02"; |
29 | | - private static final String USER3_PWD = "TEST03"; |
30 | | - private static final String USER4_PWD = "TEST04"; |
31 | | - |
32 | | - private static final String SEARCH_STRING = "TEST*"; |
33 | | - |
34 | | - @Autowired |
35 | | - private UserService userService; |
36 | | - |
37 | | - @Test |
38 | | - public void givenLdapClient_whenCorrectCredentials_thenSuccessfulLogin() { |
39 | | - Boolean isValid = userService.authenticate(USER3, USER3_PWD); |
40 | | - assertEquals(true, isValid); |
41 | | - } |
42 | | - |
43 | | - @Test |
44 | | - public void givenLdapClient_whenIncorrectCredentials_thenFailedLogin() { |
45 | | - Boolean isValid = userService.authenticate(USER3, USER2_PWD); |
46 | | - assertEquals(false, isValid); |
47 | | - } |
48 | | - |
49 | | - @Test |
50 | | - public void givenLdapClient_whenCorrectSearchFilter_thenEntriesReturned() { |
51 | | - List<String> userList = userService.search(SEARCH_STRING); |
52 | | - assertThat(userList, Matchers.containsInAnyOrder(USER2, USER3)); |
53 | | - } |
54 | | - |
55 | | - @Test |
56 | | - public void givenLdapClientNotExists_whenDataProvided_thenNewUserCreated() { |
57 | | - userService.create(USER4, USER4_PWD); |
58 | | - userService.authenticate(USER4, USER4_PWD); |
59 | | - } |
60 | | - |
61 | | - @Test |
62 | | - public void givenLdapClientExists_whenDataProvided_thenExistingUserModified() { |
63 | | - userService.modify(USER2, USER3_PWD); |
64 | | - userService.authenticate(USER2, USER3_PWD); |
65 | | - } |
66 | | - |
67 | | -} |
| 1 | +package com.baeldung.ldap.client; |
| 2 | + |
| 3 | +import com.baeldung.ldap.data.service.UserService; |
| 4 | +import com.baeldung.ldap.javaconfig.TestConfig; |
| 5 | +import org.hamcrest.Matchers; |
| 6 | +import org.junit.Test; |
| 7 | +import org.junit.runner.RunWith; |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.test.context.ActiveProfiles; |
| 10 | +import org.springframework.test.context.ContextConfiguration; |
| 11 | +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
| 12 | +import org.springframework.test.context.support.AnnotationConfigContextLoader; |
| 13 | + |
| 14 | +import java.util.List; |
| 15 | + |
| 16 | +import static org.junit.Assert.assertEquals; |
| 17 | +import static org.junit.Assert.assertThat; |
| 18 | + |
| 19 | +@RunWith(SpringJUnit4ClassRunner.class) |
| 20 | +@ActiveProfiles("testlive") |
| 21 | +@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class) |
| 22 | +public class LdapDataRepositoryIntegrationTest { |
| 23 | + |
| 24 | + private static final String USER2 = "TEST02"; |
| 25 | + private static final String USER3 = "TEST03"; |
| 26 | + private static final String USER4 = "TEST04"; |
| 27 | + |
| 28 | + private static final String USER2_PWD = "TEST02"; |
| 29 | + private static final String USER3_PWD = "TEST03"; |
| 30 | + private static final String USER4_PWD = "TEST04"; |
| 31 | + |
| 32 | + private static final String SEARCH_STRING = "TEST*"; |
| 33 | + |
| 34 | + @Autowired |
| 35 | + private UserService userService; |
| 36 | + |
| 37 | + @Test |
| 38 | + public void givenLdapClient_whenCorrectCredentials_thenSuccessfulLogin() { |
| 39 | + Boolean isValid = userService.authenticate(USER3, USER3_PWD); |
| 40 | + assertEquals(true, isValid); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void givenLdapClient_whenIncorrectCredentials_thenFailedLogin() { |
| 45 | + Boolean isValid = userService.authenticate(USER3, USER2_PWD); |
| 46 | + assertEquals(false, isValid); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void givenLdapClient_whenCorrectSearchFilter_thenEntriesReturned() { |
| 51 | + List<String> userList = userService.search(SEARCH_STRING); |
| 52 | + assertThat(userList, Matchers.containsInAnyOrder(USER2, USER3)); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void givenLdapClientNotExists_whenDataProvided_thenNewUserCreated() { |
| 57 | + userService.create(USER4, USER4_PWD); |
| 58 | + userService.authenticate(USER4, USER4_PWD); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void givenLdapClientExists_whenDataProvided_thenExistingUserModified() { |
| 63 | + userService.modify(USER2, USER3_PWD); |
| 64 | + userService.authenticate(USER2, USER3_PWD); |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments