This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new 1dcdfdb [OPENMEETINGS-2044] ldap tests are migrated to junit5
1dcdfdb is described below
commit 1dcdfdbbee6a61982a4d1fc7c6dd3ddfaa147ca9
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Mon Apr 22 14:40:05 2019 +0700
[OPENMEETINGS-2044] ldap tests are migrated to junit5
---
openmeetings-web/pom.xml | 6 --
.../ldap/CreateLdapServerExtension.java | 67 ++++++++++++++++++++++
.../org/apache/openmeetings/ldap/TestLdap.java | 28 ++++-----
3 files changed, 81 insertions(+), 20 deletions(-)
diff --git a/openmeetings-web/pom.xml b/openmeetings-web/pom.xml
index ce401b6..6cc8f1b 100644
--- a/openmeetings-web/pom.xml
+++ b/openmeetings-web/pom.xml
@@ -741,11 +741,5 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
- <dependency> <!-- temporary, DIRAPI doesn't support junit5 -->
- <groupId>org.junit.vintage</groupId>
- <artifactId>junit-vintage-engine</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
diff --git
a/openmeetings-web/src/test/java/org/apache/openmeetings/ldap/CreateLdapServerExtension.java
b/openmeetings-web/src/test/java/org/apache/openmeetings/ldap/CreateLdapServerExtension.java
new file mode 100644
index 0000000..5d35c22
--- /dev/null
+++
b/openmeetings-web/src/test/java/org/apache/openmeetings/ldap/CreateLdapServerExtension.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") + you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.ldap;
+
+import java.lang.reflect.AnnotatedElement;
+
+import org.apache.directory.api.util.FileUtils;
+import org.apache.directory.server.core.api.DirectoryService;
+import org.apache.directory.server.core.factory.DSAnnotationProcessor;
+import org.apache.directory.server.factory.ServerAnnotationProcessor;
+import org.apache.directory.server.ldap.LdapServer;
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.BeforeAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.runner.Description;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CreateLdapServerExtension implements BeforeAllCallback,
AfterAllCallback {
+ private static final Logger log =
LoggerFactory.getLogger(CreateLdapServerExtension.class);
+ private DirectoryService directoryService;
+ private LdapServer ldapServer;
+
+ @Override
+ public void afterAll(ExtensionContext context) throws Exception {
+ log.trace("Stopping ldap server");
+ ldapServer.stop();
+
+ log.trace("Shutting down directory service");
+ directoryService.shutdown();
+
FileUtils.deleteDirectory(directoryService.getInstanceLayout().getInstanceDirectory());
+ }
+
+ @Override
+ public void beforeAll(ExtensionContext context) throws Exception {
+ if (context.getElement().isPresent()) {
+ AnnotatedElement e = context.getElement().get();
+ Description description =
Description.createSuiteDescription("LDAP", e.getAnnotations());
+ log.trace("Creating directory service");
+ directoryService =
DSAnnotationProcessor.getDirectoryService(description);
+ DSAnnotationProcessor.applyLdifs(description,
directoryService);
+
+ log.trace("Creating ldap server");
+ ldapServer =
ServerAnnotationProcessor.createLdapServer(description, directoryService);
+ }
+ }
+
+ public LdapServer getLdapServer() {
+ return ldapServer;
+ }
+}
diff --git
a/openmeetings-web/src/test/java/org/apache/openmeetings/ldap/TestLdap.java
b/openmeetings-web/src/test/java/org/apache/openmeetings/ldap/TestLdap.java
index 9bd01a0..6ac218b 100644
--- a/openmeetings-web/src/test/java/org/apache/openmeetings/ldap/TestLdap.java
+++ b/openmeetings-web/src/test/java/org/apache/openmeetings/ldap/TestLdap.java
@@ -29,7 +29,8 @@ import static
org.apache.openmeetings.core.ldap.LdapOptions.CONFIGKEY_LDAP_SEARC
import static
org.apache.openmeetings.core.ldap.LdapOptions.CONFIGKEY_LDAP_SEARCH_SCOPE;
import static org.apache.openmeetings.util.OmFileHelper.getLdapConf;
import static org.apache.openmeetings.util.OmFileHelper.loadLdapConf;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -46,7 +47,6 @@ import
org.apache.directory.server.annotations.CreateTransport;
import org.apache.directory.server.core.annotations.ApplyLdifFiles;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.annotations.CreatePartition;
-import org.apache.directory.server.core.integ.CreateLdapServerRule;
import org.apache.directory.server.protocol.shared.transport.Transport;
import org.apache.openmeetings.AbstractWicketTester;
import org.apache.openmeetings.core.ldap.LdapLoginManager;
@@ -55,10 +55,10 @@ import org.apache.openmeetings.db.entity.server.LdapConfig;
import org.apache.openmeetings.db.entity.user.User;
import org.apache.openmeetings.util.OmException;
import org.apache.openmeetings.web.app.WebSession;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
@CreateDS(name = "omDS",
@@ -76,13 +76,13 @@ public class TestLdap extends AbstractWicketTester {
@Autowired
private LdapConfigDao ldapDao;
- @ClassRule
- public static CreateLdapServerRule serverRule = new
CreateLdapServerRule();
+ @RegisterExtension
+ public static CreateLdapServerExtension serverExtension = new
CreateLdapServerExtension();
- @BeforeClass
+ @BeforeAll
public static void prepare() {
loadLdapConf("om_ldap.cfg", PROPS);
- Transport t = serverRule.getLdapServer().getTransports()[0];
+ Transport t =
serverExtension.getLdapServer().getTransports()[0];
PROPS.put(CONFIGKEY_LDAP_HOST, t.getAddress());
PROPS.put(CONFIGKEY_LDAP_PORT, String.valueOf(t.getPort()));
PROPS.put(CONFIGKEY_LDAP_ADMIN_DN, ADMIN_SYSTEM_DN);
@@ -106,7 +106,7 @@ public class TestLdap extends AbstractWicketTester {
CFG_MAP.put(CFG_SEARCH_BIND, cfg);
}
- @Before
+ @BeforeEach
public void clean() throws FileNotFoundException, IOException {
if (CFG_MAP.isEmpty()) {
createSbnd();
@@ -124,12 +124,12 @@ public class TestLdap extends AbstractWicketTester {
@Test
public void testSbndSessionLogin() throws OmException {
LdapConfig cfg = CFG_MAP.get(CFG_SEARCH_BIND);
- assertTrue("Login should be successful",
WebSession.get().signIn(USER1, userpass, User.Type.ldap, cfg.getId()));
+ assertTrue(WebSession.get().signIn(USER1, userpass,
User.Type.ldap, cfg.getId()), "Login should be successful");
}
- @Test(expected = OmException.class)
+ @Test
public void testSbndSessionLoginBadPassword() throws OmException {
LdapConfig cfg = CFG_MAP.get(CFG_SEARCH_BIND);
- WebSession.get().signIn(USER1, BAD_PASSWORD, User.Type.ldap,
cfg.getId());
+ assertThrows(OmException.class, () ->
WebSession.get().signIn(USER1, BAD_PASSWORD, User.Type.ldap, cfg.getId()));
}
}