Skip to content

Commit 487fa86

Browse files
author
Vladimir Kotal
committed
add positive test
1 parent cbd2aaf commit 487fa86

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

plugins/src/test/java/opengrok/auth/plugin/ldap/LdapFacadeTest.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.mockito.Mockito;
88

99
import javax.naming.directory.SearchControls;
10+
import javax.naming.ldap.LdapContext;
1011

1112
import java.net.InetAddress;
1213
import java.net.UnknownHostException;
@@ -45,19 +46,38 @@ public void testConnectTimeoutInheritance() {
4546
}
4647

4748
@Test
48-
public void testToString() {
49+
public void testToStringNegative() throws UnknownHostException {
4950
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));
5357
config.setSearchBase("dc=foo,dc=com");
54-
int timeoutValue = 42;
58+
int timeoutValue = 3;
5559
config.setConnectTimeout(timeoutValue);
5660
LdapFacade facade = new LdapFacade(config);
5761
assertEquals("{server=no active server, searchBase=dc=foo,dc=com}",
5862
facade.toString());
5963
}
6064

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+
6181
@Test
6282
public void testPrepareServersNegative() throws UnknownHostException {
6383
Configuration config = new Configuration();

0 commit comments

Comments
 (0)