From c0e825e71369fddcd2dc8d8c3bcb71a4a80944a2 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Wed, 25 Mar 2020 17:59:45 +0100 Subject: [PATCH] dhp-aggregation workflow tests upgraded to junit5 --- dhp-workflows/dhp-aggregation/pom.xml | 7 ---- .../dhp/collection/CollectionJobTest.java | 6 ++- .../MigrateDbEntitiesApplicationTest.java | 32 ++++++--------- .../transformation/TransformationJobTest.java | 41 ++++++------------- 4 files changed, 29 insertions(+), 57 deletions(-) diff --git a/dhp-workflows/dhp-aggregation/pom.xml b/dhp-workflows/dhp-aggregation/pom.xml index 2890d55a8..925b4bbb3 100644 --- a/dhp-workflows/dhp-aggregation/pom.xml +++ b/dhp-workflows/dhp-aggregation/pom.xml @@ -116,13 +116,6 @@ 42.2.10 - - org.mockito - mockito-core - ${mockito.version} - test - - diff --git a/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/collection/CollectionJobTest.java b/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/collection/CollectionJobTest.java index e0e69382d..fde928a8b 100644 --- a/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/collection/CollectionJobTest.java +++ b/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/collection/CollectionJobTest.java @@ -7,7 +7,7 @@ import java.nio.file.Path; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.AfterEach; -import org.junit.Assert; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,6 +16,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.dnetlib.dhp.model.mdstore.MetadataRecord; import eu.dnetlib.dhp.model.mdstore.Provenance; +import static org.junit.jupiter.api.Assertions.*; + public class CollectionJobTest { private Path testDir; @@ -80,7 +82,7 @@ public class CollectionJobTest { record.setBody("ciao"); assert record1 != null; record1.setBody("mondo"); - Assert.assertEquals(record, record1); + assertEquals(record, record1); } diff --git a/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplicationTest.java b/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplicationTest.java index 5f0e1b5b1..d63bb3ee3 100644 --- a/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplicationTest.java +++ b/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplicationTest.java @@ -1,6 +1,15 @@ package eu.dnetlib.dhp.migration.step1; -import static org.junit.jupiter.api.Assertions.assertEquals; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import eu.dnetlib.dhp.schema.oaf.*; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.IOException; import java.sql.Array; @@ -10,24 +19,9 @@ import java.sql.SQLException; import java.util.List; import java.util.Objects; -import org.apache.commons.io.IOUtils; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import static org.junit.jupiter.api.Assertions.assertEquals; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -import eu.dnetlib.dhp.schema.oaf.Datasource; -import eu.dnetlib.dhp.schema.oaf.Oaf; -import eu.dnetlib.dhp.schema.oaf.Organization; -import eu.dnetlib.dhp.schema.oaf.Project; -import eu.dnetlib.dhp.schema.oaf.Relation; - -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class MigrateDbEntitiesApplicationTest { private MigrateDbEntitiesApplication app; @@ -36,7 +30,7 @@ public class MigrateDbEntitiesApplicationTest { private ResultSet rs; @BeforeEach - public void setUp() throws Exception { + public void setUp() { this.app = new MigrateDbEntitiesApplication(); } diff --git a/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/transformation/TransformationJobTest.java b/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/transformation/TransformationJobTest.java index d02bbec3a..dfa0c3720 100644 --- a/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/transformation/TransformationJobTest.java +++ b/dhp-workflows/dhp-aggregation/src/test/java/eu/dnetlib/dhp/transformation/TransformationJobTest.java @@ -6,47 +6,32 @@ import eu.dnetlib.dhp.transformation.vocabulary.Vocabulary; import eu.dnetlib.dhp.transformation.vocabulary.VocabularyHelper; import eu.dnetlib.dhp.utils.DHPUtils; import net.sf.saxon.s9api.*; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.spark.util.LongAccumulator; import org.dom4j.Document; import org.dom4j.Node; import org.dom4j.io.SAXReader; -import org.junit.*; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import javax.xml.transform.stream.StreamSource; -import java.io.File; -import java.io.IOException; import java.io.StringWriter; import java.nio.file.Files; import java.nio.file.Path; -import java.util.Comparator; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@ExtendWith(MockitoExtension.class) public class TransformationJobTest { @Mock - LongAccumulator accumulator; - - @Rule - public MockitoRule mockitoRule = MockitoJUnit.rule(); - - private Path testDir; - - @BeforeEach - public void setup() throws IOException { - testDir = Files.createTempDirectory("dhp-collection"); - } - - @AfterEach - public void tearDown() throws IOException { - FileUtils.deleteDirectory(testDir.toFile()); - } - + private LongAccumulator accumulator; @Test public void testTransformSaxonHE() throws Exception { @@ -70,9 +55,9 @@ public class TransformationJobTest { System.out.println(output.toString()); } - + @DisplayName("Test TransformSparkJobNode.main") @Test - public void transformTest() throws Exception { + public void transformTest(@TempDir Path testDir) throws Exception { final String mdstore_input = this.getClass().getResource("/eu/dnetlib/dhp/transform/mdstorenative").getFile(); final String mdstore_output = testDir.toString()+"/version"; final String xslt = DHPUtils.compressString(IOUtils.toString(this.getClass().getResourceAsStream("/eu/dnetlib/dhp/transform/tr.xml"))); @@ -89,8 +74,6 @@ public class TransformationJobTest { "-rh", "", "-ro", "", "-rr", ""}); - - } @Test @@ -121,7 +104,7 @@ public class TransformationJobTest { record.setBody(IOUtils.toString(this.getClass().getResourceAsStream("/eu/dnetlib/dhp/transform/input.xml"))); final MetadataRecord result = tf.call(record); - Assert.assertNotNull(result.getBody()); + assertNotNull(result.getBody()); System.out.println(result.getBody()); }