From 3d3de670d74c5b6f1be7a07b836cf8417117cdf8 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Mon, 1 Aug 2022 14:26:18 +0200 Subject: [PATCH] TST: fix unit tests (after update to JUnit5) --- src/test/java/org/caosdb/CaosDBTestClass.java | 43 ------------------- .../TestServerSideScriptingCaller.java | 15 ++++--- .../caosdb/server/utils/mail/TestMail.java | 19 ++++++-- 3 files changed, 24 insertions(+), 53 deletions(-) delete mode 100644 src/test/java/org/caosdb/CaosDBTestClass.java diff --git a/src/test/java/org/caosdb/CaosDBTestClass.java b/src/test/java/org/caosdb/CaosDBTestClass.java deleted file mode 100644 index 06133b3d..00000000 --- a/src/test/java/org/caosdb/CaosDBTestClass.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ** header v3.0 - * This file is a part of the CaosDB Project. - * - * Copyright (C) 2018 Research Group Biomedical Physics, - * Max-Planck-Institute for Dynamics and Self-Organization Göttingen - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - * ** end header - */ -package org.caosdb; - -import java.io.File; -import java.io.IOException; -import org.apache.commons.io.FileUtils; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; - -public class CaosDBTestClass { - - public static final File TEST_DIR = new File(".TEST_DIR"); - - @BeforeAll - public static final void setupAll() throws IOException { - TEST_DIR.mkdirs(); - FileUtils.forceDeleteOnExit(TEST_DIR); - } - - @AfterAll - public static final void teardownAll() {} -} diff --git a/src/test/java/org/caosdb/server/scripting/TestServerSideScriptingCaller.java b/src/test/java/org/caosdb/server/scripting/TestServerSideScriptingCaller.java index da6ecb1c..0d379282 100644 --- a/src/test/java/org/caosdb/server/scripting/TestServerSideScriptingCaller.java +++ b/src/test/java/org/caosdb/server/scripting/TestServerSideScriptingCaller.java @@ -32,13 +32,13 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FileUtils; -import org.caosdb.CaosDBTestClass; import org.caosdb.server.CaosDBException; import org.caosdb.server.CaosDBServer; import org.caosdb.server.ServerProperties; @@ -53,26 +53,27 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; -public class TestServerSideScriptingCaller extends CaosDBTestClass { +public class TestServerSideScriptingCaller { - public static File testFolder = - TEST_DIR.toPath().resolve("serverSideScriptingCallerTestFolder").toFile(); - public static File testFile = testFolder.toPath().resolve("TestFile").toFile(); - public static File testExecutable = testFolder.toPath().resolve("TestScript").toFile(); + public static File testFolder = null; + public static File testFile = null; + public static File testExecutable = null; final Map<String, String> emptyEnv = new HashMap<String, String>(); @BeforeAll public static void setupTestFolder() throws IOException { + testFolder = Files.createTempDirectory(".TestDir_ServerSideScripting").toFile(); CaosDBServer.initServerProperties(); CaosDBServer.getServerProperties() .setProperty( ServerProperties.KEY_SERVER_SIDE_SCRIPTING_BIN_DIRS, testFolder.getAbsolutePath()); + testFile = testFolder.toPath().resolve("TestFile").toFile(); + testExecutable = testFolder.toPath().resolve("TestScript").toFile(); FileUtils.forceDeleteOnExit(testFolder); FileUtils.forceDeleteOnExit(testFile); FileUtils.forceDeleteOnExit(testExecutable); - assertFalse(testFolder.exists()); assertFalse(testFile.exists()); assertFalse(testExecutable.exists()); testFolder.mkdirs(); diff --git a/src/test/java/org/caosdb/server/utils/mail/TestMail.java b/src/test/java/org/caosdb/server/utils/mail/TestMail.java index 0156f9ca..05cf5bf5 100644 --- a/src/test/java/org/caosdb/server/utils/mail/TestMail.java +++ b/src/test/java/org/caosdb/server/utils/mail/TestMail.java @@ -22,20 +22,33 @@ */ package org.caosdb.server.utils.mail; +import java.io.File; import java.io.IOException; -import org.caosdb.CaosDBTestClass; +import java.nio.file.Files; +import org.apache.commons.io.FileUtils; import org.caosdb.server.CaosDBServer; import org.caosdb.server.ServerProperties; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -public class TestMail extends CaosDBTestClass { +public class TestMail { + + public static File testDir = null; + @BeforeAll public static void setupUp() throws IOException { + testDir = Files.createTempDirectory(".TestDir_Mail").toFile(); + CaosDBServer.initServerProperties(); // output mails to the test dir CaosDBServer.setProperty( - ServerProperties.KEY_MAIL_TO_FILE_HANDLER_LOC, TEST_DIR.getAbsolutePath()); + ServerProperties.KEY_MAIL_TO_FILE_HANDLER_LOC, testDir.getAbsolutePath()); + } + + @AfterAll + public static void tearDown() throws IOException { + FileUtils.deleteDirectory(testDir); } @Test -- GitLab