|
7 | 7 | import org.mockito.Mockito;
|
8 | 8 |
|
9 | 9 | import javax.naming.directory.SearchControls;
|
| 10 | +import javax.naming.ldap.LdapContext; |
10 | 11 |
|
11 | 12 | import java.net.InetAddress;
|
12 | 13 | import java.net.UnknownHostException;
|
@@ -45,19 +46,38 @@ public void testConnectTimeoutInheritance() {
|
45 | 46 | }
|
46 | 47 |
|
47 | 48 | @Test
|
48 |
| - public void testToString() { |
| 49 | + public void testToStringNegative() throws UnknownHostException { |
49 | 50 | Configuration config = new Configuration();
|
50 |
| - config.setServers(Arrays.asList(new LdapServer("http://foo.foo"), |
51 |
| - new LdapServer("http://bar.bar", |
52 |
| - "cn=FOOBAR,l=amer,dc=example,dc=com", "MySecretPassword"))); |
| 51 | + LdapServer server1 = new LdapServer("ldap://foo.com"); |
| 52 | + LdapServer serverSpy1 = Mockito.spy(server1); |
| 53 | + Mockito.when(serverSpy1.getAddresses(any())).thenReturn(new InetAddress[]{InetAddress.getLocalHost()}); |
| 54 | + Mockito.when(serverSpy1.isReachable()).thenReturn(false); |
| 55 | + |
| 56 | + config.setServers(Collections.singletonList(serverSpy1)); |
53 | 57 | config.setSearchBase("dc=foo,dc=com");
|
54 |
| - int timeoutValue = 42; |
| 58 | + int timeoutValue = 3; |
55 | 59 | config.setConnectTimeout(timeoutValue);
|
56 | 60 | LdapFacade facade = new LdapFacade(config);
|
57 | 61 | assertEquals("{server=no active server, searchBase=dc=foo,dc=com}",
|
58 | 62 | facade.toString());
|
59 | 63 | }
|
60 | 64 |
|
| 65 | + @Test |
| 66 | + public void testToStringPositive() throws UnknownHostException { |
| 67 | + Configuration config = new Configuration(); |
| 68 | + LdapServer server1 = new LdapServer("ldap://foo.com"); |
| 69 | + LdapServer serverSpy1 = Mockito.spy(server1); |
| 70 | + Mockito.doReturn(true).when(serverSpy1).isWorking(); |
| 71 | + |
| 72 | + config.setServers(Collections.singletonList(serverSpy1)); |
| 73 | + config.setSearchBase("dc=foo,dc=com"); |
| 74 | + int timeoutValue = 3; |
| 75 | + config.setConnectTimeout(timeoutValue); |
| 76 | + LdapFacade facade = new LdapFacade(config); |
| 77 | + assertEquals("{server=ldap://foo.com timeout: 3, searchBase=dc=foo,dc=com}", |
| 78 | + facade.toString()); |
| 79 | + } |
| 80 | + |
61 | 81 | @Test
|
62 | 82 | public void testPrepareServersNegative() throws UnknownHostException {
|
63 | 83 | Configuration config = new Configuration();
|
|
0 commit comments