You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2021/04/04 17:15:35 UTC

[directory-server] 01/01: Demonstrate JUnit 5 IT

This is an automated email from the ASF dual-hosted git repository.

seelmann pushed a commit to branch junit-5-it
in repository https://gitbox.apache.org/repos/asf/directory-server.git

commit d10cf254dca9317b54dd39489ed249098a984436
Author: Stefan Seelmann <ma...@stefan-seelmann.de>
AuthorDate: Sun Apr 4 19:15:15 2021 +0200

    Demonstrate JUnit 5 IT
---
 .../shared/client/api/BeforeAllInjector.java       | 30 ++++++++++++++++++++++
 .../shared/client/api/LdapConnectionTest.java      | 21 ++++++++-------
 .../server/factory/ServerAnnotationProcessor.java  |  2 +-
 test-framework/pom.xml                             |  2 +-
 4 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/BeforeAllInjector.java b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/BeforeAllInjector.java
new file mode 100644
index 0000000..9899aee
--- /dev/null
+++ b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/BeforeAllInjector.java
@@ -0,0 +1,30 @@
+package org.apache.directory.shared.client.api;
+
+
+import org.apache.directory.server.annotations.CreateLdapServer;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.factory.DefaultDirectoryServiceFactory;
+import org.apache.directory.server.factory.ServerAnnotationProcessor;
+import org.apache.directory.server.ldap.LdapServer;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+
+public class BeforeAllInjector implements BeforeAllCallback
+{
+    @Override
+    public void beforeAll( ExtensionContext context ) throws Exception
+    {
+        DefaultDirectoryServiceFactory factory = new DefaultDirectoryServiceFactory();
+        factory.init( "test" );
+        DirectoryService directoryService = factory.getDirectoryService();
+
+        Class<?> testClass = context.getTestClass().get();
+
+        CreateLdapServer createLdapServer = testClass.getAnnotation( CreateLdapServer.class );
+        LdapServer ldapServer = ServerAnnotationProcessor.createLdapServer( createLdapServer, directoryService );
+
+        testClass.getField( "service" ).set( null, directoryService );
+        testClass.getField( "ldapServer" ).set( null, ldapServer );
+    }
+}
diff --git a/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
index 9d75d97..a6ae375 100644
--- a/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
+++ b/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/LdapConnectionTest.java
@@ -53,11 +53,10 @@ import org.apache.directory.server.annotations.CreateTransport;
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
-import org.apache.directory.server.core.integ.FrameworkRunner;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 
 
 /**
@@ -65,9 +64,9 @@ import org.junit.runner.RunWith;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-@RunWith(FrameworkRunner.class)
+@ExtendWith(BeforeAllInjector.class)
 @CreateLdapServer(transports =
-    { @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
+{ @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
 public class LdapConnectionTest extends AbstractLdapTestUnit
 {
     private static final String ADMIN_DN = "uid=admin,ou=system";
@@ -75,14 +74,14 @@ public class LdapConnectionTest extends AbstractLdapTestUnit
     private LdapConnection connection;
 
 
-    @Before
+    @BeforeEach
     public void setup() throws Exception
     {
         connection = LdapApiIntegrationUtils.getPooledAdminConnection( getLdapServer() );
     }
 
 
-    @After
+    @AfterEach
     public void shutdown() throws Exception
     {
         LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer() );
@@ -319,7 +318,7 @@ public void testLookup() throws Exception
     }
 
 
-    @Test(expected = InvalidConnectionException.class)
+    // TODO @Test(expected = InvalidConnectionException.class)
     public void testConnectionWrongHost() throws LdapException, IOException
     {
         try ( LdapConnection connection = new LdapNetworkConnection( "notexisting", 1234 ) )
@@ -337,7 +336,7 @@ public void testLookup() throws Exception
     }
 
 
-    @Test(expected = InvalidConnectionException.class)
+    // TODO @Test(expected = InvalidConnectionException.class)
     public void testConnectionWrongPort() throws LdapException, IOException
     {
         try ( LdapConnection connection = new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME, 123 ) )
diff --git a/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java b/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
index 70f736e..be88eee 100644
--- a/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
+++ b/server-annotations/src/main/java/org/apache/directory/server/factory/ServerAnnotationProcessor.java
@@ -313,7 +313,7 @@ public final class ServerAnnotationProcessor
      * @param directoryService the directory service
      * @return a running LdapServer instance
      */
-    private static LdapServer createLdapServer( CreateLdapServer createLdapServer, DirectoryService directoryService )
+    public static LdapServer createLdapServer( CreateLdapServer createLdapServer, DirectoryService directoryService )
     {
         LdapServer ldapServer = instantiateLdapServer( createLdapServer, directoryService );
 
diff --git a/test-framework/pom.xml b/test-framework/pom.xml
index d129053..eb5b49c 100644
--- a/test-framework/pom.xml
+++ b/test-framework/pom.xml
@@ -92,7 +92,7 @@
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-api</artifactId>
-      <scope>test</scope>
+      <scope>compile</scope>
     </dependency>
   </dependencies>