Skip to content

Commit 4eb57d1

Browse files
committed
add more LdapServerExternalResource testing
1 parent 6267830 commit 4eb57d1

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

lightblue-ldap-test/src/test/java/com/redhat/lightblue/ldap/test/LdapServerExternalResourceTest.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,63 @@
1818
*/
1919
package com.redhat.lightblue.ldap.test;
2020

21+
import static org.junit.Assert.assertNotNull;
2122
import static org.mockito.Mockito.mock;
2223

24+
import org.junit.ClassRule;
25+
import org.junit.Rule;
2326
import org.junit.Test;
2427
import org.junit.runner.Description;
2528
import org.junit.runners.model.Statement;
2629

30+
import com.redhat.lightblue.ldap.test.LdapServerExternalResource.InMemoryLdapServer;
31+
import com.unboundid.ldap.sdk.LDAPConnection;
32+
import com.unboundid.ldap.sdk.LDAPException;
33+
2734
public class LdapServerExternalResourceTest {
2835

29-
@Test(expected = IllegalStateException.class)
30-
public void testApply_WithoutAnnotation_onTestLevel(){
31-
new LdapServerExternalResource().apply(mock(Statement.class), mock(Description.class));
36+
public static class SimpleTests{
37+
38+
@Test(expected = IllegalStateException.class)
39+
public void testApply_WithoutAnnotation_onTestLevel(){
40+
new LdapServerExternalResource().apply(mock(Statement.class), mock(Description.class));
41+
}
42+
43+
@Test(expected = IllegalStateException.class)
44+
public void testApply_WithoutAnnotation_onClassLevel(){
45+
new LdapServerExternalResource().apply(
46+
mock(Statement.class),
47+
Description.createSuiteDescription(Object.class));
48+
}
49+
50+
}
51+
52+
@InMemoryLdapServer
53+
public static class AnnotationOnClassRule{
54+
55+
@ClassRule
56+
public static final LdapServerExternalResource ldapServer = LdapServerExternalResource.createDefaultInstance();
57+
58+
@Test
59+
public void testConnection() throws LDAPException{
60+
LDAPConnection conn = new LDAPConnection("localhost", LdapServerExternalResource.DEFAULT_PORT);
61+
assertNotNull(conn.getEntry("dc=example,dc=com"));
62+
}
63+
3264
}
3365

34-
@Test(expected = IllegalStateException.class)
35-
public void testApply_WithoutAnnotation_onClassLevel(){
36-
new LdapServerExternalResource().apply(
37-
mock(Statement.class),
38-
Description.createSuiteDescription(Object.class));
66+
@InMemoryLdapServer
67+
public static class AnnotationOnRule{
68+
69+
@Rule
70+
public LdapServerExternalResource ldapServer = LdapServerExternalResource.createDefaultInstance();
71+
72+
@Test
73+
public void testConnection() throws LDAPException{
74+
LDAPConnection conn = new LDAPConnection("localhost", LdapServerExternalResource.DEFAULT_PORT);
75+
assertNotNull(conn.getEntry("dc=example,dc=com"));
76+
}
77+
3978
}
4079

4180
}

0 commit comments

Comments
 (0)