From 553b4c1bbb109c411a200c50512a5f06fc9f22b1 Mon Sep 17 00:00:00 2001 From: David Venable Date: Tue, 23 Jan 2024 08:11:00 -0800 Subject: [PATCH] Updates the common plugin and mapdb-processor-state projects to JUnit 5. (#3949) Signed-off-by: David Venable --- data-prepper-plugins/common/build.gradle | 1 - .../acm/ACMCertificateProviderTest.java | 2 +- .../processor/state/ProcessorStateTest.java | 33 ++++++++++--------- .../s3keyindex/S3ObjectIndexUtilityTest.java | 5 +-- .../plugins/source/StdInSourceTests.java | 32 +++++++++--------- .../mapdb-processor-state/build.gradle | 2 -- .../state/MapDbProcessorStateTest.java | 33 ++++++++++--------- 7 files changed, 55 insertions(+), 53 deletions(-) diff --git a/data-prepper-plugins/common/build.gradle b/data-prepper-plugins/common/build.gradle index 2744f9c998..634379fffb 100644 --- a/data-prepper-plugins/common/build.gradle +++ b/data-prepper-plugins/common/build.gradle @@ -19,7 +19,6 @@ dependencies { implementation libs.bouncycastle.bcpkix implementation libs.reflections.core implementation 'io.micrometer:micrometer-core' - testImplementation testLibs.junit.vintage implementation 'org.apache.parquet:parquet-common:1.13.1' implementation 'org.xerial.snappy:snappy-java:1.1.10.5' testImplementation project(':data-prepper-plugins:blocking-buffer') diff --git a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/certificate/acm/ACMCertificateProviderTest.java b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/certificate/acm/ACMCertificateProviderTest.java index ee2d126ca2..e9f0850e51 100644 --- a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/certificate/acm/ACMCertificateProviderTest.java +++ b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/certificate/acm/ACMCertificateProviderTest.java @@ -25,7 +25,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/processor/state/ProcessorStateTest.java b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/processor/state/ProcessorStateTest.java index c1a1618132..45c1d788e5 100644 --- a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/processor/state/ProcessorStateTest.java +++ b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/processor/state/ProcessorStateTest.java @@ -5,11 +5,9 @@ package org.opensearch.dataprepper.plugins.processor.state; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.opensearch.dataprepper.processor.state.ProcessorState; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; import java.io.Serializable; import java.util.Collection; @@ -20,13 +18,16 @@ import java.util.function.BiFunction; import java.util.stream.Collectors; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public abstract class ProcessorStateTest { protected static final Random random = new Random(); protected ProcessorState processorState; - @Before public abstract void setProcessorState() throws Exception; @Test @@ -41,7 +42,7 @@ public void testSize() { processorState.put(key1, data1); processorState.put(key2, data2); - Assert.assertEquals(2, processorState.size()); + assertEquals(2, processorState.size()); } @Test @@ -57,9 +58,9 @@ public void testPutAndGet() { processorState.put(key2, data2); //Read them and assert that they are correctly read, and assert incorrect key gives back null value - Assert.assertEquals(data1, processorState.get(key1)); - Assert.assertEquals(data2, processorState.get(key2)); - Assert.assertNull(processorState.get(UUID.randomUUID().toString().getBytes())); + assertEquals(data1, processorState.get(key1)); + assertEquals(data2, processorState.get(key2)); + assertNull(processorState.get(UUID.randomUUID().toString().getBytes())); } @Test @@ -79,12 +80,12 @@ public void testPutAndGetAll() { .entrySet() .stream() .collect(Collectors.toMap( dataClassEntry -> new String(dataClassEntry.getKey()), dataClassEntry -> dataClassEntry.getValue())); - Assert.assertEquals(2, stateMap.size()); - Assert.assertEquals(data1, stateMap.get(new String(key1))); - Assert.assertEquals(data2, stateMap.get(new String(key2))); + assertEquals(2, stateMap.size()); + assertEquals(data1, stateMap.get(new String(key1))); + assertEquals(data2, stateMap.get(new String(key2))); } - @After + @AfterEach public void teardown() { processorState.delete(); } @@ -108,9 +109,9 @@ public String apply(byte[] s, DataClass dataClass) { } }); - Assert.assertEquals(2, iterateResult.size()); - Assert.assertTrue(iterateResult.contains(data1.stringVal)); - Assert.assertTrue(iterateResult.contains(data2.stringVal)); + assertEquals(2, iterateResult.size()); + assertTrue(iterateResult.contains(data1.stringVal)); + assertTrue(iterateResult.contains(data2.stringVal)); } public static class DataClass implements Serializable { diff --git a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/s3keyindex/S3ObjectIndexUtilityTest.java b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/s3keyindex/S3ObjectIndexUtilityTest.java index 070b7ec53c..0299227f8d 100644 --- a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/s3keyindex/S3ObjectIndexUtilityTest.java +++ b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/s3keyindex/S3ObjectIndexUtilityTest.java @@ -5,13 +5,14 @@ package org.opensearch.dataprepper.plugins.s3keyindex; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import org.junit.jupiter.api.Test; diff --git a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/source/StdInSourceTests.java b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/source/StdInSourceTests.java index bbfd617ffc..d4a42751ad 100644 --- a/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/source/StdInSourceTests.java +++ b/data-prepper-plugins/common/src/test/java/org/opensearch/dataprepper/plugins/source/StdInSourceTests.java @@ -5,14 +5,14 @@ package org.opensearch.dataprepper.plugins.source; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.opensearch.dataprepper.model.CheckpointState; import org.opensearch.dataprepper.model.configuration.PluginSetting; import org.opensearch.dataprepper.model.event.Event; import org.opensearch.dataprepper.model.record.Record; import org.opensearch.dataprepper.plugins.buffer.TestBuffer; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -28,7 +28,7 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.MatcherAssert.assertThat; -public class StdInSourceTests { +class StdInSourceTests { private static final String SOURCE_CONTENT = "THIS IS A TEST\nexit"; private static final String READ_CONTENT = "THIS IS A TEST"; private static final String TEST_PIPELINE_NAME = "test-pipeline"; @@ -36,27 +36,27 @@ public class StdInSourceTests { private InputStream defaultInputStream; - @Before - public void setup() { + @BeforeEach + void setup() { defaultInputStream = System.in; final ByteArrayInputStream streamForTests = new ByteArrayInputStream( SOURCE_CONTENT.getBytes(StandardCharsets.UTF_8)); System.setIn(streamForTests); } - @After - public void tearDown() { + @AfterEach + void tearDown() { System.setIn(defaultInputStream); } @Test - public void testStdInSourceCreationUsingParameters() { + void testStdInSourceCreationUsingParameters() { final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME); assertThat(stdInSource, notNullValue()); } @Test - public void testStdInSourceCreationUsingPluginSetting() { + void testStdInSourceCreationUsingPluginSetting() { final PluginSetting pluginSetting = new PluginSetting("stdin", null); pluginSetting.setPipelineName(TEST_PIPELINE_NAME); final StdInSource stdInSource = new StdInSource(pluginSetting); @@ -64,7 +64,7 @@ public void testStdInSourceCreationUsingPluginSetting() { } @Test - public void testStdInSourceCreationWithNullPipelineName() { + void testStdInSourceCreationWithNullPipelineName() { try { new StdInSource(TEST_WRITE_TIMEOUT, null); } catch (NullPointerException ex) { @@ -73,7 +73,7 @@ public void testStdInSourceCreationWithNullPipelineName() { } @Test - public void testStdInSourceCreationWithNullPluginSetting() { + void testStdInSourceCreationWithNullPluginSetting() { try { new StdInSource(null); } catch (NullPointerException ex) { @@ -82,7 +82,7 @@ public void testStdInSourceCreationWithNullPluginSetting() { } @Test - public void testStdInSourceWithNullBuffer() { + void testStdInSourceWithNullBuffer() { final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME); try { stdInSource.start(null); @@ -93,7 +93,7 @@ public void testStdInSourceWithNullBuffer() { } @Test - public void testStdInSourceSuccessfulWriteToBuffer() { + void testStdInSourceSuccessfulWriteToBuffer() { final Queue> bufferQueue = new LinkedList<>(); final TestBuffer buffer = new TestBuffer(bufferQueue, 1); final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME); @@ -108,7 +108,7 @@ public void testStdInSourceSuccessfulWriteToBuffer() { } @Test - public void testStdInSourceWhenStopped() { + void testStdInSourceWhenStopped() { final Queue> bufferQueue = new LinkedList<>(); final TestBuffer buffer = new TestBuffer(bufferQueue, 1); final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME); @@ -119,7 +119,7 @@ public void testStdInSourceWhenStopped() { } @Test - public void testStdInSourceWhenBufferTimesout() { + void testStdInSourceWhenBufferTimesout() { final Queue> bufferQueue = new LinkedList<>(); final TestBuffer buffer = new TestBuffer(bufferQueue, 1, true); final StdInSource stdInSource = new StdInSource(TEST_WRITE_TIMEOUT, TEST_PIPELINE_NAME); diff --git a/data-prepper-plugins/mapdb-processor-state/build.gradle b/data-prepper-plugins/mapdb-processor-state/build.gradle index fcc4588dde..56d216fb17 100644 --- a/data-prepper-plugins/mapdb-processor-state/build.gradle +++ b/data-prepper-plugins/mapdb-processor-state/build.gradle @@ -17,9 +17,7 @@ dependencies { implementation 'org.mapdb:mapdb:3.0.10' implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.21' implementation 'org.jetbrains.kotlin:kotlin-stdlib-common:1.8.21' - testImplementation testLibs.junit.vintage testImplementation project(':data-prepper-plugins:common').sourceSets.test.output - testImplementation testLibs.junit.vintage } jacocoTestCoverageVerification { diff --git a/data-prepper-plugins/mapdb-processor-state/src/test/java/org/opensearch/dataprepper/plugins/processor/state/MapDbProcessorStateTest.java b/data-prepper-plugins/mapdb-processor-state/src/test/java/org/opensearch/dataprepper/plugins/processor/state/MapDbProcessorStateTest.java index 47704b30b1..e8819e5389 100644 --- a/data-prepper-plugins/mapdb-processor-state/src/test/java/org/opensearch/dataprepper/plugins/processor/state/MapDbProcessorStateTest.java +++ b/data-prepper-plugins/mapdb-processor-state/src/test/java/org/opensearch/dataprepper/plugins/processor/state/MapDbProcessorStateTest.java @@ -5,29 +5,32 @@ package org.opensearch.dataprepper.plugins.processor.state; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.UUID; import java.util.function.BiFunction; -public class MapDbProcessorStateTest extends ProcessorStateTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); +class MapDbProcessorStateTest extends ProcessorStateTest { - @Override - public void setProcessorState() throws Exception { - this.processorState = new MapDbProcessorState<>(temporaryFolder.newFolder(), "testDb", 16); + @TempDir + File temporaryFile; + + @BeforeEach + public void setProcessorState() { + this.processorState = new MapDbProcessorState<>(temporaryFile, "testDb", 16); } @Test - public void testIterateSegment() throws IOException { + void testIterateSegment() throws IOException { final byte[] key1 = new byte[]{-64, 0, -64, 0}; final byte[] key2 = new byte[]{0}; final byte[] key3 = new byte[]{64, 64, 64, 64}; @@ -57,13 +60,13 @@ public String apply(byte[] bytes, DataClass s) { } }, 2, 1); - Assert.assertEquals(2, values.size()); - Assert.assertEquals(2, values2.size()); - Assert.assertTrue(values.containsAll(Arrays.asList( + assertEquals(2, values.size()); + assertEquals(2, values2.size()); + assertTrue(values.containsAll(Arrays.asList( data1.stringVal, data2.stringVal ))); - Assert.assertTrue(values2.containsAll(Arrays.asList( + assertTrue(values2.containsAll(Arrays.asList( data3.stringVal, data4.stringVal )));