|
18 | 18 | */
|
19 | 19 | package com.redhat.lightblue.ldap.test;
|
20 | 20 |
|
| 21 | +import static org.junit.Assert.assertNotNull; |
21 | 22 | import static org.mockito.Mockito.mock;
|
22 | 23 |
|
| 24 | +import org.junit.ClassRule; |
| 25 | +import org.junit.Rule; |
23 | 26 | import org.junit.Test;
|
24 | 27 | import org.junit.runner.Description;
|
25 | 28 | import org.junit.runners.model.Statement;
|
26 | 29 |
|
| 30 | +import com.redhat.lightblue.ldap.test.LdapServerExternalResource.InMemoryLdapServer; |
| 31 | +import com.unboundid.ldap.sdk.LDAPConnection; |
| 32 | +import com.unboundid.ldap.sdk.LDAPException; |
| 33 | + |
27 | 34 | public class LdapServerExternalResourceTest {
|
28 | 35 |
|
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 | + |
32 | 64 | }
|
33 | 65 |
|
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 | + |
39 | 78 | }
|
40 | 79 |
|
41 | 80 | }
|
0 commit comments