From 4c6bd856c010253df3a14084a5e0f8dfde70b190 Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Wed, 11 Aug 2021 14:20:35 -0400 Subject: [PATCH] NIFI-9041 Replaced JUnit 4 only testing configuration with a combination of JUnit 5 and JUnit Vintage. - Updated nifi-mock to be exclusively JUnit 5 - Updated a few modules to demonstrate a successful conversion to all JUnit 5 This closes #5304 Signed-off-by: David Handermann --- nifi-mock/pom.xml | 4 +- .../apache/nifi/state/MockStateManager.java | 20 ++--- .../org/apache/nifi/util/MockFlowFile.java | 22 ++--- .../apache/nifi/util/MockProcessContext.java | 4 +- .../apache/nifi/util/MockProcessSession.java | 22 ++--- .../util/StandardProcessorTestRunner.java | 48 +++++----- .../java/org/apache/nifi/util/TestRunner.java | 6 +- ...urrentTestStandardProcessorTestRunner.java | 2 +- .../nifi/util/TestMockProcessContext.java | 2 +- .../nifi/util/TestMockProcessSession.java | 23 ++--- .../util/TestStandardProcessorTestRunner.java | 16 ++-- .../nifi-email-processors/pom.xml | 6 ++ .../processors/graph/ExecuteGraphQueryIT.java | 6 +- .../graph/ExecuteGraphQueryRecordTest.java | 6 +- .../graph/TestExecuteGraphQuery.java | 11 +-- .../nifi/graph/ITNeo4JCypherExecutor.java | 10 +-- .../nifi/graph/OpenCypherClientServiceIT.java | 14 +-- .../mongodb/GetMongoRecordIT.groovy | 38 ++++---- .../mongodb/AbstractMongoProcessorTest.java | 6 +- .../processors/mongodb/DeleteMongoIT.java | 28 +++--- .../nifi/processors/mongodb/GetMongoIT.java | 74 +++++++-------- .../nifi/processors/mongodb/PutMongoIT.java | 68 +++++++------- .../processors/mongodb/PutMongoRecordIT.java | 28 +++--- .../nifi/processors/mongodb/PutMongoTest.java | 16 ++-- .../mongodb/RunMongoAggregationIT.java | 28 +++--- .../mongodb/gridfs/DeleteGridFSIT.java | 18 ++-- .../mongodb/gridfs/FetchGridFSIT.java | 34 +++---- .../mongodb/gridfs/PutGridFSIT.java | 20 ++--- .../nifi/mongodb/MongoDBLookupService.java | 9 +- .../mongodb/MongoDBControllerServiceIT.java | 10 +-- .../nifi/mongodb/MongoDBLookupServiceIT.java | 90 ++++++++----------- .../nifi-registry-test/pom.xml | 1 + nifi-registry/pom.xml | 2 +- pom.xml | 30 ++++--- 34 files changed, 361 insertions(+), 361 deletions(-) diff --git a/nifi-mock/pom.xml b/nifi-mock/pom.xml index 8688dff6d1e5..08ea3e2840f6 100644 --- a/nifi-mock/pom.xml +++ b/nifi-mock/pom.xml @@ -66,8 +66,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api compile diff --git a/nifi-mock/src/main/java/org/apache/nifi/state/MockStateManager.java b/nifi-mock/src/main/java/org/apache/nifi/state/MockStateManager.java index 1cc8a393b30d..ad8686406218 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/state/MockStateManager.java +++ b/nifi-mock/src/main/java/org/apache/nifi/state/MockStateManager.java @@ -21,7 +21,7 @@ import org.apache.nifi.components.state.Scope; import org.apache.nifi.components.state.StateManager; import org.apache.nifi.components.state.StateMap; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.util.Collections; @@ -170,7 +170,7 @@ private void verifyAnnotation(final Scope scope) { // ensure that the @Stateful annotation is present with the appropriate Scope if ((scope == Scope.LOCAL && !usesLocalState) || (scope == Scope.CLUSTER && !usesClusterState)) { - Assert.fail("Component is attempting to set or retrieve state with a scope of " + scope + " but does not declare that it will use " + Assertions.fail("Component is attempting to set or retrieve state with a scope of " + scope + " but does not declare that it will use " + scope + " state. A @Stateful annotation should be added to the component with a scope of " + scope); } } @@ -197,7 +197,7 @@ private String getValue(final String key, final Scope scope) { * @param scope the scope */ public void assertStateEquals(final String key, final String value, final Scope scope) { - Assert.assertEquals(value, getValue(key, scope)); + Assertions.assertEquals(value, getValue(key, scope)); } /** @@ -208,7 +208,7 @@ public void assertStateEquals(final String key, final String value, final Scope */ public void assertStateEquals(final Map stateValues, final Scope scope) { final StateMap stateMap = retrieveState(scope); - Assert.assertEquals(stateValues, stateMap.toMap()); + Assertions.assertEquals(stateValues, stateMap.toMap()); } /** @@ -219,7 +219,7 @@ public void assertStateEquals(final Map stateValues, final Scope */ public void assertStateNotEquals(final Map stateValues, final Scope scope) { final StateMap stateMap = retrieveState(scope); - Assert.assertNotSame(stateValues, stateMap.toMap()); + Assertions.assertNotSame(stateValues, stateMap.toMap()); } /** @@ -230,7 +230,7 @@ public void assertStateNotEquals(final Map stateValues, final Sc * @param scope the scope */ public void assertStateNotEquals(final String key, final String value, final Scope scope) { - Assert.assertNotEquals(value, getValue(key, scope)); + Assertions.assertNotEquals(value, getValue(key, scope)); } /** @@ -240,7 +240,7 @@ public void assertStateNotEquals(final String key, final String value, final Sco * @param scope the scope */ public void assertStateSet(final String key, final Scope scope) { - Assert.assertNotNull("Expected state to be set for key " + key + " and scope " + scope + ", but it was not set", getValue(key, scope)); + Assertions.assertNotNull(getValue(key, scope), "Expected state to be set for key " + key + " and scope " + scope + ", but it was not set"); } /** @@ -250,7 +250,7 @@ public void assertStateSet(final String key, final Scope scope) { * @param scope the scope */ public void assertStateNotSet(final String key, final Scope scope) { - Assert.assertNull("Expected state not to be set for key " + key + " and scope " + scope + ", but it was set", getValue(key, scope)); + Assertions.assertNull(getValue(key, scope), "Expected state not to be set for key " + key + " and scope " + scope + ", but it was set"); } /** @@ -260,7 +260,7 @@ public void assertStateNotSet(final String key, final Scope scope) { */ public void assertStateSet(final Scope scope) { final StateMap stateMap = (scope == Scope.CLUSTER) ? clusterStateMap : localStateMap; - Assert.assertNotSame("Expected state to be set for Scope " + scope + ", but it was not set", -1L, stateMap.getVersion()); + Assertions.assertNotSame(-1L, stateMap.getVersion(), "Expected state to be set for Scope " + scope + ", but it was not set"); } /** @@ -278,7 +278,7 @@ public void assertStateNotSet() { */ public void assertStateNotSet(final Scope scope) { final StateMap stateMap = (scope == Scope.CLUSTER) ? clusterStateMap : localStateMap; - Assert.assertEquals("Expected state not to be set for Scope " + scope + ", but it was set", -1L, stateMap.getVersion()); + Assertions.assertEquals(-1L, stateMap.getVersion(), "Expected state not to be set for Scope " + scope + ", but it was set"); } /** diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java b/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java index 254320edd5ef..7ee30a7c0054 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java @@ -38,7 +38,7 @@ import org.apache.nifi.controller.repository.claim.ContentClaim; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.flowfile.attributes.CoreAttributes; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; public class MockFlowFile implements FlowFileRecord { @@ -217,21 +217,21 @@ public boolean equals(final Object obj) { } public void assertAttributeExists(final String attributeName) { - Assert.assertTrue("Attribute " + attributeName + " does not exist", attributes.containsKey(attributeName)); + Assertions.assertTrue(attributes.containsKey(attributeName), "Attribute " + attributeName + " does not exist"); } public void assertAttributeNotExists(final String attributeName) { - Assert.assertFalse("Attribute " + attributeName + " should not exist on FlowFile, but exists with value " - + attributes.get(attributeName), attributes.containsKey(attributeName)); + Assertions.assertFalse(attributes.containsKey(attributeName), "Attribute " + attributeName + " should not exist on FlowFile, but exists with value " + + attributes.get(attributeName)); } public void assertAttributeEquals(final String attributeName, final String expectedValue) { - Assert.assertEquals("Expected attribute " + attributeName + " to be " + expectedValue + " but instead it was " + attributes.get(attributeName), - expectedValue, attributes.get(attributeName)); + Assertions.assertEquals(expectedValue, attributes.get(attributeName), "Expected attribute " + attributeName + " to be " + + expectedValue + " but instead it was " + attributes.get(attributeName)); } public void assertAttributeNotEquals(final String attributeName, final String expectedValue) { - Assert.assertNotSame(expectedValue, attributes.get(attributeName)); + Assertions.assertNotSame(expectedValue, attributes.get(attributeName)); } /** @@ -281,7 +281,7 @@ public void assertContentEquals(final String data, final String charset) { public void assertContentEquals(final String data, final Charset charset) { final String value = new String(this.data, charset); - Assert.assertEquals(data, value); + Assertions.assertEquals(data, value); } /** @@ -298,11 +298,11 @@ public void assertContentEquals(final InputStream in) throws IOException { for (int i = 0; i < data.length; i++) { final int fromStream = buffered.read(); if (fromStream < 0) { - Assert.fail("FlowFile content is " + data.length + " bytes but provided input is only " + bytesRead + " bytes"); + Assertions.fail("FlowFile content is " + data.length + " bytes but provided input is only " + bytesRead + " bytes"); } if ((fromStream & 0xFF) != (data[i] & 0xFF)) { - Assert.fail("FlowFile content differs from input at byte " + bytesRead + " with input having value " + Assertions.fail("FlowFile content differs from input at byte " + bytesRead + " with input having value " + (fromStream & 0xFF) + " and FlowFile having value " + (data[i] & 0xFF)); } @@ -311,7 +311,7 @@ public void assertContentEquals(final InputStream in) throws IOException { final int nextByte = buffered.read(); if (nextByte >= 0) { - Assert.fail("Contents of input and FlowFile were the same through byte " + data.length + "; however, FlowFile's content ended at this point, and input has more data"); + Assertions.fail("Contents of input and FlowFile were the same through byte " + data.length + "; however, FlowFile's content ended at this point, and input has more data"); } } } diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java b/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java index e2199f44d7a1..5c8a8e8bdcb4 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessContext.java @@ -34,7 +34,7 @@ import org.apache.nifi.registry.VariableRegistry; import org.apache.nifi.scheduling.ExecutionNode; import org.apache.nifi.state.MockStateManager; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.util.ArrayList; import java.util.Collection; @@ -412,7 +412,7 @@ public void assertValid() { } if (failureCount > 0) { - Assert.fail("Processor has " + failureCount + " validation failures:\n" + sb.toString()); + Assertions.fail("Processor has " + failureCount + " validation failures:\n" + sb.toString()); } } diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java b/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java index a4a967bce81b..163fc7804470 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/MockProcessSession.java @@ -34,7 +34,7 @@ import org.apache.nifi.processor.io.StreamCallback; import org.apache.nifi.provenance.ProvenanceReporter; import org.apache.nifi.state.MockStateManager; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -565,7 +565,7 @@ public MockFlowFile putAttribute(FlowFile flowFile, final String attrName, final } if ("uuid".equals(attrName)) { - Assert.fail("Should not be attempting to set FlowFile UUID via putAttribute. This will be ignored in production"); + Assertions.fail("Should not be attempting to set FlowFile UUID via putAttribute. This will be ignored in production"); } final MockFlowFile mock = (MockFlowFile) flowFile; @@ -1203,28 +1203,28 @@ private static Map intersectAttributes(final Collection flowFiles = entry.getValue(); if (!rel.equals(relationship) && flowFiles != null && !flowFiles.isEmpty()) { - Assert.fail("Expected all Transferred FlowFiles to go to " + relationship + " but " + flowFiles.size() + " were routed to " + rel); + Assertions.fail("Expected all Transferred FlowFiles to go to " + relationship + " but " + flowFiles.size() + " were routed to " + rel); } } } diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java b/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java index 27de55dec887..d489177e799a 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/StandardProcessorTestRunner.java @@ -43,7 +43,7 @@ import org.apache.nifi.registry.VariableDescriptor; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.state.MockStateManager; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -131,7 +131,7 @@ public class StandardProcessorTestRunner implements TestRunner { try { ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, processor); } catch (final Exception e) { - Assert.fail("Could not invoke methods annotated with @OnAdded annotation due to: " + e); + Assertions.fail("Could not invoke methods annotated with @OnAdded annotation due to: " + e); } triggerSerially = null != processor.getClass().getAnnotation(TriggerSerially.class); @@ -201,7 +201,7 @@ public void run(final int iterations, final boolean stopOnFinish, final boolean ReflectionUtils.invokeMethodsWithAnnotation(OnScheduled.class, processor, context); } catch (final Exception e) { e.printStackTrace(); - Assert.fail("Could not invoke methods annotated with @OnScheduled annotation due to: " + e); + Assertions.fail("Could not invoke methods annotated with @OnScheduled annotation due to: " + e); } } @@ -252,7 +252,7 @@ public void unSchedule() { try { ReflectionUtils.invokeMethodsWithAnnotation(OnUnscheduled.class, processor, context); } catch (final Exception e) { - Assert.fail("Could not invoke methods annotated with @OnUnscheduled annotation due to: " + e); + Assertions.fail("Could not invoke methods annotated with @OnUnscheduled annotation due to: " + e); } } @@ -260,7 +260,7 @@ public void stop() { try { ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, processor, context); } catch (final Exception e) { - Assert.fail("Could not invoke methods annotated with @OnStopped annotation due to: " + e); + Assertions.fail("Could not invoke methods annotated with @OnStopped annotation due to: " + e); } } @@ -269,7 +269,7 @@ public void shutdown() { try { ReflectionUtils.invokeMethodsWithAnnotation(OnShutdown.class, processor); } catch (final Exception e) { - Assert.fail("Could not invoke methods annotated with @OnShutdown annotation due to: " + e); + Assertions.fail("Could not invoke methods annotated with @OnShutdown annotation due to: " + e); } } @@ -318,7 +318,7 @@ public void assertAllFlowFilesContainAttribute(final String attributeName) { assertAllFlowFiles(new FlowFileValidator() { @Override public void assertFlowFile(FlowFile f) { - Assert.assertTrue(f.getAttribute(attributeName) != null); + Assertions.assertTrue(f.getAttribute(attributeName) != null); } }); } @@ -328,7 +328,7 @@ public void assertAllFlowFilesContainAttribute(final Relationship relationship, assertAllFlowFiles(relationship, new FlowFileValidator() { @Override public void assertFlowFile(FlowFile f) { - Assert.assertTrue(f.getAttribute(attributeName) != null); + Assertions.assertTrue(f.getAttribute(attributeName) != null); } }); } @@ -355,17 +355,17 @@ public void assertAllFlowFilesTransferred(final Relationship relationship, final @Override public void assertTransferCount(final Relationship relationship, final int count) { - Assert.assertEquals(count, getFlowFilesForRelationship(relationship).size()); + Assertions.assertEquals(count, getFlowFilesForRelationship(relationship).size()); } @Override public void assertTransferCount(final String relationship, final int count) { - Assert.assertEquals(count, getFlowFilesForRelationship(relationship).size()); + Assertions.assertEquals(count, getFlowFilesForRelationship(relationship).size()); } @Override public void assertPenalizeCount(final int count) { - Assert.assertEquals(count, getPenalizedFlowFiles().size()); + Assertions.assertEquals(count, getPenalizedFlowFiles().size()); } @Override @@ -375,7 +375,7 @@ public void assertValid() { @Override public void assertNotValid() { - Assert.assertFalse("Processor appears to be valid but expected it to be invalid", context.isValid()); + Assertions.assertFalse(context.isValid(), "Processor appears to be valid but expected it to be invalid"); } @Override @@ -385,12 +385,12 @@ public boolean isQueueEmpty() { @Override public void assertQueueEmpty() { - Assert.assertTrue(flowFileQueue.isEmpty()); + Assertions.assertTrue(flowFileQueue.isEmpty()); } @Override public void assertQueueNotEmpty() { - Assert.assertFalse(flowFileQueue.isEmpty()); + Assertions.assertFalse(flowFileQueue.isEmpty()); } @Override @@ -540,7 +540,7 @@ public ValidationResult setProperty(final PropertyDescriptor descriptor, final A @Override public void setThreadCount(final int threadCount) { if (threadCount > 1 && triggerSerially) { - Assert.fail("Cannot set thread-count higher than 1 because the processor is triggered serially"); + Assertions.fail("Cannot set thread-count higher than 1 because the processor is triggered serially"); } this.numThreads = threadCount; @@ -652,7 +652,7 @@ public void assertNotValid(final ControllerService service) { } } - Assert.fail("Expected Controller Service " + service + " to be invalid but it is valid"); + Assertions.fail("Expected Controller Service " + service + " to be invalid but it is valid"); } @Override @@ -667,7 +667,7 @@ public void assertValid(final ControllerService service) { for (final ValidationResult result : results) { if (!result.isValid()) { - Assert.fail("Expected Controller Service to be valid but it is invalid due to: " + result.toString()); + Assertions.fail("Expected Controller Service to be valid but it is invalid due to: " + result.toString()); } } } @@ -687,7 +687,7 @@ public void disableControllerService(final ControllerService service) { ReflectionUtils.invokeMethodsWithAnnotation(OnDisabled.class, service); } catch (final Exception e) { e.printStackTrace(); - Assert.fail("Failed to disable Controller Service " + service + " due to " + e); + Assertions.fail("Failed to disable Controller Service " + service + " due to " + e); } configuration.setEnabled(false); @@ -723,10 +723,10 @@ public void enableControllerService(final ControllerService service) { ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, service, configContext); } catch (final InvocationTargetException ite) { ite.getCause().printStackTrace(); - Assert.fail("Failed to enable Controller Service " + service + " due to " + ite.getCause()); + Assertions.fail("Failed to enable Controller Service " + service + " due to " + ite.getCause()); } catch (final Exception e) { e.printStackTrace(); - Assert.fail("Failed to enable Controller Service " + service + " due to " + e); + Assertions.fail("Failed to enable Controller Service " + service + " due to " + e); } configuration.setEnabled(true); @@ -752,7 +752,7 @@ public void removeControllerService(final ControllerService service) { ReflectionUtils.invokeMethodsWithAnnotation(OnRemoved.class, service); } catch (final Exception e) { e.printStackTrace(); - Assert.fail("Failed to remove Controller Service " + service + " due to " + e); + Assertions.fail("Failed to remove Controller Service " + service + " due to " + e); } context.removeControllerService(service); @@ -989,18 +989,18 @@ public void assertAllConditionsMet(final String relationshipName, Predicate predicate) { if (predicate==null) { - Assert.fail("predicate cannot be null"); + Assertions.fail("predicate cannot be null"); } final List flowFiles = getFlowFilesForRelationship(relationship); if (flowFiles.isEmpty()) { - Assert.fail("Relationship " + relationship.getName() + " does not contain any FlowFile"); + Assertions.fail("Relationship " + relationship.getName() + " does not contain any FlowFile"); } for (MockFlowFile flowFile : flowFiles) { if (predicate.test(flowFile)==false) { - Assert.fail("FlowFile " + flowFile + " does not meet all condition"); + Assertions.fail("FlowFile " + flowFile + " does not meet all condition"); } } } diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java b/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java index f16fb7999cc8..fde8c6a8b195 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/TestRunner.java @@ -211,7 +211,7 @@ public interface TestRunner { /** * Updates the value of the property with the given PropertyDescriptor to * the specified value IF and ONLY IF the value is valid according to the - * descriptor's validator. Otherwise, Assert.fail() is called, causing the + * descriptor's validator. Otherwise, Assertions.fail() is called, causing the * unit test to fail * * @param propertyName name @@ -223,7 +223,7 @@ public interface TestRunner { /** * Updates the value of the property with the given PropertyDescriptor to * the specified value IF and ONLY IF the value is valid according to the - * descriptor's validator. Otherwise, Assert.fail() is called, causing the + * descriptor's validator. Otherwise, Assertions.fail() is called, causing the * unit test to fail * * @param descriptor descriptor @@ -235,7 +235,7 @@ public interface TestRunner { /** * Updates the value of the property with the given PropertyDescriptor to * the specified value IF and ONLY IF the value is valid according to the - * descriptor's validator. Otherwise, Assert.fail() is called, causing the + * descriptor's validator. Otherwise, Assertions.fail() is called, causing the * unit test to fail * * @param descriptor descriptor diff --git a/nifi-mock/src/test/java/org/apache/nifi/util/CurrentTestStandardProcessorTestRunner.java b/nifi-mock/src/test/java/org/apache/nifi/util/CurrentTestStandardProcessorTestRunner.java index 6b403af25c21..cde947e15986 100644 --- a/nifi-mock/src/test/java/org/apache/nifi/util/CurrentTestStandardProcessorTestRunner.java +++ b/nifi-mock/src/test/java/org/apache/nifi/util/CurrentTestStandardProcessorTestRunner.java @@ -21,7 +21,7 @@ import org.apache.nifi.processor.ProcessSession; import org.apache.nifi.processor.exception.ProcessException; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CurrentTestStandardProcessorTestRunner { diff --git a/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessContext.java b/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessContext.java index f83db9f9464e..241394ae73f8 100644 --- a/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessContext.java +++ b/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessContext.java @@ -31,7 +31,7 @@ import org.apache.nifi.processor.ProcessSession; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.processor.util.StandardValidators; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestMockProcessContext { diff --git a/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessSession.java b/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessSession.java index 8e649881197b..eefd4a39ddab 100644 --- a/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessSession.java +++ b/nifi-mock/src/test/java/org/apache/nifi/util/TestMockProcessSession.java @@ -26,8 +26,7 @@ import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.state.MockStateManager; import org.apache.nifi.stream.io.StreamUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; @@ -35,9 +34,11 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicLong; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; public class TestMockProcessSession { @@ -54,7 +55,7 @@ public void testReadWithoutCloseThrowsExceptionOnCommit() throws IOException { try { session.commit(); - Assert.fail("Was able to commit session without closing InputStream"); + fail("Was able to commit session without closing InputStream"); } catch (final FlowFileHandlingException | IllegalStateException e) { System.out.println(e.toString()); } @@ -73,7 +74,7 @@ public void testReadWithoutCloseThrowsExceptionOnCommitAsync() throws IOExceptio try { session.commitAsync(); - Assert.fail("Was able to commit session without closing InputStream"); + fail("Was able to commit session without closing InputStream"); } catch (final FlowFileHandlingException | IllegalStateException e) { System.out.println(e.toString()); } @@ -87,26 +88,26 @@ public void testTransferUnknownRelationship() { final Relationship fakeRel = new Relationship.Builder().name("FAKE").build(); try { session.transfer(ff1, fakeRel); - Assert.fail("Should have thrown IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (final IllegalArgumentException ie) { } try { session.transfer(Collections.singleton(ff1), fakeRel); - Assert.fail("Should have thrown IllegalArgumentException"); + fail("Should have thrown IllegalArgumentException"); } catch (final IllegalArgumentException ie) { } } - @Test(expected = IllegalArgumentException.class) + @Test public void testRejectTransferNewlyCreatedFileToSelf() { final Processor processor = new PoorlyBehavedProcessor(); final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, new AtomicLong(0L)), processor, new MockStateManager(processor)); final FlowFile ff1 = session.createFlowFile("hello, world".getBytes()); // this should throw an exception because we shouldn't allow a newly created flowfile to get routed back to self - session.transfer(ff1); + assertThrows(IllegalArgumentException.class, () -> session.transfer(ff1)); } @Test diff --git a/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java b/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java index f2febb48f522..b7025f8473e4 100644 --- a/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java +++ b/nifi-mock/src/test/java/org/apache/nifi/util/TestStandardProcessorTestRunner.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -43,7 +44,7 @@ import org.apache.nifi.processor.Relationship; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.reporting.InitializationException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestStandardProcessorTestRunner { @@ -131,27 +132,24 @@ public void assertFlowFile(FlowFile f) { }); } - @Test(expected = AssertionError.class) + @Test public void testFailFlowFileValidator() { final AddAttributeProcessor proc = new AddAttributeProcessor(); final TestRunner runner = TestRunners.newTestRunner(proc); runner.run(5, true); - runner.assertAllFlowFiles(new FlowFileValidator() { - @Override - public void assertFlowFile(FlowFile f) { - assertEquals("value", f.getAttribute(AddAttributeProcessor.KEY)); - } + assertThrows(AssertionError.class, () -> { + runner.assertAllFlowFiles(f -> assertEquals("value", f.getAttribute(AddAttributeProcessor.KEY))); }); } - @Test(expected = AssertionError.class) + @Test public void testFailAllFlowFilesContainAttribute() { final AddAttributeProcessor proc = new AddAttributeProcessor(); final TestRunner runner = TestRunners.newTestRunner(proc); runner.run(5, true); - runner.assertAllFlowFilesContainAttribute(AddAttributeProcessor.KEY); + assertThrows(AssertionError.class, () -> runner.assertAllFlowFilesContainAttribute(AddAttributeProcessor.KEY)); } @Test diff --git a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/pom.xml b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/pom.xml index cdc936bc4192..75423b96be85 100644 --- a/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/pom.xml +++ b/nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/pom.xml @@ -121,5 +121,11 @@ 1.5.11 test + + org.hamcrest + hamcrest-core + 2.2 + test + diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryIT.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryIT.java index 7f9e2efa1090..769fd4a45fca 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryIT.java +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryIT.java @@ -22,8 +22,8 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; @@ -37,7 +37,7 @@ public class ExecuteGraphQueryIT { "}\n" + "g.V().hasLabel(\"test\").count().next()"; - @Before + @BeforeEach public void setUp() throws Exception { InMemoryJanusGraphClientService service = new InMemoryJanusGraphClientService(); runner = TestRunners.newTestRunner(ExecuteGraphQuery.class); diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryRecordTest.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryRecordTest.java index b83242333bd2..668da174e296 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryRecordTest.java +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/ExecuteGraphQueryRecordTest.java @@ -26,8 +26,8 @@ import org.apache.nifi.util.TestRunners; import org.apache.nifi.json.JsonTreeReader; import org.apache.nifi.serialization.record.MockRecordWriter; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.InputStream; @@ -44,7 +44,7 @@ public class ExecuteGraphQueryRecordTest { private TestRunner runner; Map enqueProperties = new HashMap<>(); - @Before + @BeforeEach public void setup() throws InitializationException { MockRecordWriter writer = new MockRecordWriter(); JsonTreeReader reader = new JsonTreeReader(); diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/TestExecuteGraphQuery.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/TestExecuteGraphQuery.java index cdcd112249dd..85be6282b91a 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/TestExecuteGraphQuery.java +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-graph-processors/src/test/java/org/apache/nifi/processors/graph/TestExecuteGraphQuery.java @@ -21,11 +21,8 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.List; @@ -41,9 +38,7 @@ public class TestExecuteGraphQuery { protected TestRunner runner; - @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Before + @BeforeEach public void setUp() throws Exception { MockCypherClientService service = new MockCypherClientService(); runner = TestRunners.newTestRunner(ExecuteGraphQuery.class); diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-neo4j-cypher-service/src/test/java/org/apache/nifi/graph/ITNeo4JCypherExecutor.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-neo4j-cypher-service/src/test/java/org/apache/nifi/graph/ITNeo4JCypherExecutor.java index b2fa2c9c018a..fd3566dcba7b 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-neo4j-cypher-service/src/test/java/org/apache/nifi/graph/ITNeo4JCypherExecutor.java +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-neo4j-cypher-service/src/test/java/org/apache/nifi/graph/ITNeo4JCypherExecutor.java @@ -18,9 +18,9 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.neo4j.driver.v1.AuthTokens; import org.neo4j.driver.v1.Driver; import org.neo4j.driver.v1.GraphDatabase; @@ -47,7 +47,7 @@ public class ITNeo4JCypherExecutor { private GraphClientService clientService; private GraphQueryResultCallback EMPTY_CALLBACK = (record, hasMore) -> {}; - @Before + @BeforeEach public void setUp() throws Exception { clientService = new Neo4JCypherClientService(); runner = TestRunners.newTestRunner(MockProcessor.class); @@ -70,7 +70,7 @@ protected StatementResult executeSession(String statement) { } } - @After + @AfterEach public void tearDown() { runner = null; if (driver != null) { diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java index 340b81a3cc0d..6397d3f1a0df 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java @@ -23,10 +23,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.neo4j.driver.v1.Driver; import org.neo4j.driver.v1.Session; import org.neo4j.driver.v1.StatementResult; @@ -54,7 +54,7 @@ public class OpenCypherClientServiceIT { GraphClientService service; private Driver driver; - @Before + @BeforeEach public void before() throws Exception { service = new OpenCypherClientService(); runner = TestRunners.newTestRunner(MockProcessor.class); @@ -64,7 +64,7 @@ public void before() throws Exception { runner.enableControllerService(service); runner.assertValid(); - Assert.assertEquals("gremlin://localhost:8182/gremlin", service.getTransitUrl()); + Assertions.assertEquals("gremlin://localhost:8182/gremlin", service.getTransitUrl()); driver = GremlinDatabase.driver("//localhost:8182"); executeSession("MATCH (n) detach delete n"); @@ -75,7 +75,7 @@ public void before() throws Exception { "CREATE (rover)-[:chases]->(fido)"); } - @After + @AfterEach public void after() { executeSession("MATCH (n) DETACH DELETE n"); } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy index 61a99a954d4e..510222b17091 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/groovy/org/apache/nifi/processors/mongodb/GetMongoRecordIT.groovy @@ -31,10 +31,10 @@ import org.apache.nifi.serialization.record.* import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners import org.bson.Document -import org.junit.After -import org.junit.Assert -import org.junit.Before -import org.junit.Test +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import static groovy.json.JsonOutput.* @@ -62,7 +62,7 @@ class GetMongoRecordIT { [ name: "John Brown", failedLogins: 4, lastLogin: new Date(Calendar.instance.time.time - 10000) ] ].collect { new Document(it) } - @Before + @BeforeEach void setup() { runner = TestRunners.newTestRunner(GetMongoRecord.class) service = new MongoDBControllerService() @@ -90,7 +90,7 @@ class GetMongoRecordIT { service.getDatabase(DB_NAME).getCollection(COL_NAME).insertMany(SAMPLES) } - @After + @AfterEach void after() { service.getDatabase(DB_NAME).drop() } @@ -99,13 +99,13 @@ class GetMongoRecordIT { void testLookup() { def ffValidator = { TestRunner runner -> def ffs = runner.getFlowFilesForRelationship(GetMongoRecord.REL_SUCCESS) - Assert.assertNotNull(ffs) - Assert.assertTrue(ffs.size() == 1) - Assert.assertEquals("3", ffs[0].getAttribute("record.count")) - Assert.assertEquals("application/json", ffs[0].getAttribute(CoreAttributes.MIME_TYPE.key())) - Assert.assertEquals(COL_NAME, ffs[0].getAttribute(GetMongoRecord.COL_NAME)) - Assert.assertEquals(DB_NAME, ffs[0].getAttribute(GetMongoRecord.DB_NAME)) - Assert.assertEquals(Document.parse("{}"), Document.parse(ffs[0].getAttribute("executed.query"))) + Assertions.assertNotNull(ffs) + Assertions.assertTrue(ffs.size() == 1) + Assertions.assertEquals("3", ffs[0].getAttribute("record.count")) + Assertions.assertEquals("application/json", ffs[0].getAttribute(CoreAttributes.MIME_TYPE.key())) + Assertions.assertEquals(COL_NAME, ffs[0].getAttribute(GetMongoRecord.COL_NAME)) + Assertions.assertEquals(DB_NAME, ffs[0].getAttribute(GetMongoRecord.DB_NAME)) + Assertions.assertEquals(Document.parse("{}"), Document.parse(ffs[0].getAttribute("executed.query"))) } runner.setProperty(GetMongoRecord.QUERY_ATTRIBUTE, "executed.query") @@ -141,13 +141,13 @@ class GetMongoRecordIT { runner.run() def parsed = sharedTest() - Assert.assertEquals(3, parsed.size()) + Assertions.assertEquals(3, parsed.size()) def values = [1, 2, 4] int index = 0 parsed.each { - Assert.assertEquals(values[index++], it["failedLogins"]) - Assert.assertNull(it["name"]) - Assert.assertNull(it["lastLogin"]) + Assertions.assertEquals(values[index++], it["failedLogins"]) + Assertions.assertNull(it["name"]) + Assertions.assertNull(it["lastLogin"]) } } @@ -159,7 +159,7 @@ class GetMongoRecordIT { def raw = runner.getContentAsByteArray(ff) String content = new String(raw) def parsed = new JsonSlurper().parseText(content) - Assert.assertNotNull(parsed) + Assertions.assertNotNull(parsed) parsed } @@ -173,7 +173,7 @@ class GetMongoRecordIT { runner.run() def parsed = sharedTest() - Assert.assertEquals(1, parsed.size()) + Assertions.assertEquals(1, parsed.size()) } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessorTest.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessorTest.java index ee4a4ec5d320..32b789910c17 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessorTest.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/AbstractMongoProcessorTest.java @@ -25,8 +25,8 @@ import org.apache.nifi.ssl.SSLContextService; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.net.ssl.SSLContext; @@ -41,7 +41,7 @@ public class AbstractMongoProcessorTest { MockAbstractMongoProcessor processor; private TestRunner testRunner; - @Before + @BeforeEach public void setUp() throws Exception { processor = new MockAbstractMongoProcessor(); testRunner = TestRunners.newTestRunner(processor); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java index 9f3c0164159d..9cd6add2cf9d 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java @@ -23,22 +23,22 @@ import org.apache.nifi.mongodb.MongoDBControllerService; import org.apache.nifi.util.TestRunner; import org.bson.Document; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; public class DeleteMongoIT extends MongoWriteTestBase { - @Before + @BeforeEach public void setup() { super.setup(DeleteMongo.class); collection.insertMany(DOCUMENTS); } - @After + @AfterEach public void teardown() { super.teardown(); } @@ -49,8 +49,8 @@ private void testOne(TestRunner runner, String query, Map attrs) runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); - Assert.assertEquals("Found a document that should have been deleted.", - 0, collection.count(Document.parse(query))); + Assertions.assertEquals(0, collection.count(Document.parse(query)), + "Found a document that should have been deleted."); } @Test @@ -73,10 +73,8 @@ private void manyTest(TestRunner runner, String query, Map attrs runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); - Assert.assertEquals("Found a document that should have been deleted.", - 0, collection.count(Document.parse(query))); - Assert.assertEquals("One document should have been left.", - 1, collection.count(Document.parse("{}"))); + Assertions.assertEquals(0, collection.count(Document.parse(query)), "Found a document that should have been deleted."); + Assertions.assertEquals(1, collection.count(Document.parse("{}")), "One document should have been left."); } @Test @@ -108,7 +106,7 @@ public void testFailOnNoDeleteOptions() { runner.assertTransferCount(DeleteMongo.REL_FAILURE, 1); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 0); - Assert.assertEquals("A document was deleted", 3, collection.count(Document.parse("{}"))); + Assertions.assertEquals(3, collection.count(Document.parse("{}")), "A document was deleted"); runner.setProperty(DeleteMongo.FAIL_ON_NO_DELETE, DeleteMongo.NO_FAIL); runner.clearTransferState(); @@ -119,7 +117,7 @@ public void testFailOnNoDeleteOptions() { runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); - Assert.assertEquals("A document was deleted", 3, collection.count(Document.parse("{}"))); + Assertions.assertEquals(3, collection.count(Document.parse("{}")), "A document was deleted"); } @Test @@ -139,6 +137,6 @@ public void testClientService() throws Exception { runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); - Assert.assertEquals(0, collection.count()); + Assertions.assertEquals(0, collection.count()); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java index 7ec724cb3f93..a304f5a22e48 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java @@ -35,10 +35,10 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -70,7 +70,7 @@ public class GetMongoIT { private TestRunner runner; private MongoClient mongoClient; - @Before + @BeforeEach public void setup() { runner = TestRunners.newTestRunner(GetMongo.class); runner.setVariable("uri", MONGO_URI); @@ -88,7 +88,7 @@ public void setup() { collection.insertMany(DOCUMENTS); } - @After + @AfterEach public void teardown() { runner = null; @@ -109,10 +109,10 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(2, results.size()); + Assertions.assertEquals(2, results.size()); Iterator it = results.iterator(); - Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); - Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); + Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); + Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); // missing query - is ok runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); @@ -124,7 +124,7 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(0, results.size()); + Assertions.assertEquals(0, results.size()); // invalid query runner.setProperty(GetMongo.QUERY, "{a: x,y,z}"); @@ -134,8 +134,8 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(1, results.size()); - Assert.assertTrue(results.iterator().next().toString().contains("is invalid because")); + Assertions.assertEquals(1, results.size()); + Assertions.assertTrue(results.iterator().next().toString().contains("is invalid because")); // invalid projection runner.setVariable("projection", "{a: x,y,z}"); @@ -147,8 +147,8 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(1, results.size()); - Assert.assertTrue(results.iterator().next().toString().contains("is invalid")); + Assertions.assertEquals(1, results.size()); + Assertions.assertTrue(results.iterator().next().toString().contains("is invalid")); // invalid sort runner.removeProperty(GetMongo.PROJECTION); @@ -159,8 +159,8 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(1, results.size()); - Assert.assertTrue(results.iterator().next().toString().contains("is invalid")); + Assertions.assertEquals(1, results.size()); + Assertions.assertTrue(results.iterator().next().toString().contains("is invalid")); } @Test @@ -177,8 +177,8 @@ public void testCleanJson() throws Exception { Map parsed = mapper.readValue(raw, Map.class); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - Assert.assertTrue(parsed.get("date_field").getClass() == String.class); - Assert.assertTrue(((String)parsed.get("date_field")).startsWith(format.format(CAL.getTime()))); + Assertions.assertTrue(parsed.get("date_field").getClass() == String.class); + Assertions.assertTrue(((String)parsed.get("date_field")).startsWith(format.format(CAL.getTime()))); } @Test @@ -252,8 +252,8 @@ public void testResultsPerFlowfile() throws Exception { runner.assertTransferCount(GetMongo.REL_SUCCESS, 2); runner.assertTransferCount(GetMongo.REL_ORIGINAL, 1); List results = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); - Assert.assertTrue("Flowfile was empty", results.get(0).getSize() > 0); - Assert.assertEquals("Wrong mime type", results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json"); + Assertions.assertTrue(results.get(0).getSize() > 0, "Flowfile was empty"); + Assertions.assertEquals(results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json", "Wrong mime type"); } @Test @@ -267,8 +267,8 @@ public void testBatchSize() throws Exception { runner.assertTransferCount(GetMongo.REL_SUCCESS, 2); runner.assertTransferCount(GetMongo.REL_ORIGINAL, 1); List results = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); - Assert.assertTrue("Flowfile was empty", results.get(0).getSize() > 0); - Assert.assertEquals("Wrong mime type", results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json"); + Assertions.assertTrue(results.get(0).getSize() > 0, "Flowfile was empty"); + Assertions.assertEquals(results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json", "Wrong mime type"); } @Test @@ -283,7 +283,7 @@ public void testConfigurablePrettyPrint() { List flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); byte[] raw = runner.getContentAsByteArray(flowFiles.get(0)); String json = new String(raw); - Assert.assertTrue("JSON did not have new lines.", json.contains("\n")); + Assertions.assertTrue(json.contains("\n"), "JSON did not have new lines."); runner.clearTransferState(); runner.setProperty(GetMongo.USE_PRETTY_PRINTING, GetMongo.NO_PP); runner.enqueue("{}"); @@ -293,15 +293,15 @@ public void testConfigurablePrettyPrint() { flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); raw = runner.getContentAsByteArray(flowFiles.get(0)); json = new String(raw); - Assert.assertFalse("New lines detected", json.contains("\n")); + Assertions.assertFalse(json.contains("\n"), "New lines detected"); } private void testQueryAttribute(String attr, String expected) { List flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); for (MockFlowFile mff : flowFiles) { String val = mff.getAttribute(attr); - Assert.assertNotNull("Missing query attribute", val); - Assert.assertEquals("Value was wrong", expected, val); + Assertions.assertNotNull(val, "Missing query attribute"); + Assertions.assertEquals(expected, val, "Value was wrong"); } } @@ -426,7 +426,7 @@ public void testQueryParamMissingWithNoFlowfile() { ex = pe; } - Assert.assertNull("An exception was thrown!", ex); + Assertions.assertNull(ex, "An exception was thrown!"); runner.assertTransferCount(GetMongo.REL_FAILURE, 0); runner.assertTransferCount(GetMongo.REL_ORIGINAL, 0); runner.assertTransferCount(GetMongo.REL_SUCCESS, 3); @@ -467,7 +467,7 @@ public void testKeepOriginalAttributes() { runner.assertTransferCount(GetMongo.REL_SUCCESS, 1); MockFlowFile flowFile = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS).get(0); - Assert.assertTrue(flowFile.getAttributes().containsKey("property.1")); + Assertions.assertTrue(flowFile.getAttributes().containsKey("property.1")); flowFile.assertAttributeEquals("property.1", "value-1"); } /* @@ -536,8 +536,8 @@ public void testDatabaseEL() { tmpRunner.run(); } catch (Throwable ex) { Throwable cause = ex.getCause(); - Assert.assertTrue(cause instanceof ProcessException); - Assert.assertTrue(entry.getKey(), ex.getMessage().contains(entry.getKey())); + Assertions.assertTrue(cause instanceof ProcessException); + Assertions.assertTrue(ex.getMessage().contains(entry.getKey()), entry.getKey()); } tmpRunner.clearTransferState(); @@ -553,10 +553,10 @@ public void testDBAttributes() { for (MockFlowFile ff : ffs) { String db = ff.getAttribute(GetMongo.DB_NAME); String col = ff.getAttribute(GetMongo.COL_NAME); - Assert.assertNotNull(db); - Assert.assertNotNull(col); - Assert.assertEquals(DB_NAME, db); - Assert.assertEquals(COLLECTION_NAME, col); + Assertions.assertNotNull(db); + Assertions.assertNotNull(col); + Assertions.assertEquals(DB_NAME, db); + Assertions.assertEquals(COLLECTION_NAME, col); } } @@ -578,8 +578,8 @@ public void testDateFormat() throws Exception { Pattern format = Pattern.compile("([\\d]{4})-([\\d]{2})-([\\d]{2})"); - Assert.assertTrue(result.containsKey("date_field")); - Assert.assertTrue(format.matcher((String) result.get("date_field")).matches()); + Assertions.assertTrue(result.containsKey("date_field")); + Assertions.assertTrue(format.matcher((String) result.get("date_field")).matches()); } @Test @@ -667,6 +667,6 @@ public void testSendEmpty() throws Exception { List flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); MockFlowFile flowFile = flowFiles.get(0); - Assert.assertEquals(0, flowFile.getSize()); + Assertions.assertEquals(0, flowFile.getSize()); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java index cb78f97b4e2f..1666a4e66300 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java @@ -27,10 +27,10 @@ import org.apache.nifi.util.TestRunners; import org.bson.Document; import org.bson.types.ObjectId; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.Collection; @@ -40,16 +40,16 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class PutMongoIT extends MongoWriteTestBase { - @Before + @BeforeEach public void setup() { super.setup(PutMongo.class); } @Override - @After + @AfterEach public void teardown() { super.teardown(); } @@ -71,10 +71,10 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(2, results.size()); + assertEquals(2, results.size()); Iterator it = results.iterator(); - Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); - Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); + Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); + Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); // invalid write concern runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); @@ -88,8 +88,8 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(1, results.size()); - Assert.assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); + assertEquals(1, results.size()); + Assertions.assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); // valid write concern runner.setProperty(PutMongo.WRITE_CONCERN, PutMongo.WRITE_CONCERN_UNACKNOWLEDGED); @@ -99,7 +99,7 @@ public void testValidators() { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(0, results.size()); + assertEquals(0, results.size()); } @Test @@ -218,14 +218,14 @@ private void testUpdateFullDocument(TestRunner runner) { MongoCursor cursor = collection.find(document).iterator(); Document found = cursor.next(); - Assert.assertEquals(found.get("name"), document.get("name")); - Assert.assertEquals(found.get("department"), document.get("department")); + assertEquals(found.get("name"), document.get("name")); + assertEquals(found.get("department"), document.get("department")); Document contacts = (Document)found.get("contacts"); - Assert.assertNotNull(contacts); - Assert.assertEquals(contacts.get("twitter"), "@JohnSmith"); - Assert.assertEquals(contacts.get("email"), "john.smith@test.com"); - Assert.assertEquals(contacts.get("phone"), "555-555-5555"); - Assert.assertEquals(collection.count(document), 1); + Assertions.assertNotNull(contacts); + assertEquals(contacts.get("twitter"), "@JohnSmith"); + assertEquals(contacts.get("email"), "john.smith@test.com"); + assertEquals(contacts.get("phone"), "555-555-5555"); + assertEquals(collection.count(document), 1); } @Test @@ -257,12 +257,12 @@ public void testUpdateByComplexKey() { runner.assertTransferCount(PutMongo.REL_SUCCESS, 1); MongoCursor iterator = collection.find(new Document("name", "John Smith")).iterator(); - Assert.assertTrue("Document did not come back.", iterator.hasNext()); + Assertions.assertTrue(iterator.hasNext(), "Document did not come back."); Document val = iterator.next(); Map contacts = (Map)val.get("contacts"); - Assert.assertNotNull(contacts); - Assert.assertTrue(contacts.containsKey("twitter") && contacts.get("twitter").equals("@JohnSmith")); - Assert.assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); + Assertions.assertNotNull(contacts); + Assertions.assertTrue(contacts.containsKey("twitter") && contacts.get("twitter").equals("@JohnSmith")); + Assertions.assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); } private void updateTests(TestRunner runner, Document document) { @@ -271,11 +271,11 @@ private void updateTests(TestRunner runner, Document document) { runner.assertTransferCount(PutMongo.REL_SUCCESS, 1); MongoCursor iterator = collection.find(document).iterator(); - Assert.assertTrue("Document did not come back.", iterator.hasNext()); + Assertions.assertTrue(iterator.hasNext(), "Document did not come back."); Document val = iterator.next(); - Assert.assertTrue(val.containsKey("email") && val.get("email").equals("john.smith@test.com")); - Assert.assertTrue(val.containsKey("grade") && val.get("grade").equals("Sr. Principle Eng.")); - Assert.assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); + Assertions.assertTrue(val.containsKey("email") && val.get("email").equals("john.smith@test.com")); + Assertions.assertTrue(val.containsKey("grade") && val.get("grade").equals("Sr. Principle Eng.")); + Assertions.assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); } @Test @@ -462,13 +462,13 @@ public void testUpsertWithOperators() throws Exception { Document query = new Document("_id", "Test"); Document result = collection.find(query).first(); List array = (List)result.get("testArr"); - Assert.assertNotNull("Array was empty", array); - Assert.assertEquals("Wrong size", array.size(), 3); + Assertions.assertNotNull(array, "Array was empty"); + assertEquals(3, array.size(), "Wrong size"); for (int index = 0; index < array.size(); index++) { Document doc = (Document)array.get(index); String msg = doc.getString("msg"); - Assert.assertNotNull("Msg was null", msg); - Assert.assertEquals("Msg had wrong value", msg, "Hi"); + Assertions.assertNotNull("Msg was null", msg); + assertEquals(msg, "Hi", "Msg had wrong value"); } } @@ -517,8 +517,8 @@ public void testNiFi_4759_Regressions() { Document query = new Document(updateKeyProps[index], updateKeys[index]); Document result = collection.find(query).first(); - Assert.assertNotNull("Result was null", result); - Assert.assertEquals("Count was wrong", 1, collection.count(query)); + Assertions.assertNotNull(result, "Result was null"); + assertEquals(1, collection.count(query), "Count was wrong"); runner.clearTransferState(); index++; } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java index 371f38c15af9..a8e3319fc957 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java @@ -38,10 +38,10 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -52,19 +52,19 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class PutMongoRecordIT extends MongoWriteTestBase { private MockRecordParser recordReader; - @Before + @BeforeEach public void setup() throws Exception { super.setup(PutMongoRecord.class); recordReader = new MockRecordParser(); } - @After + @AfterEach public void teardown() { super.teardown(); } @@ -96,11 +96,11 @@ public void testValidators() throws Exception { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(3, results.size()); + assertEquals(3, results.size()); Iterator it = results.iterator(); - Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); - Assert.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); - Assert.assertTrue(it.next().toString().contains("is invalid because Record Reader is required")); + Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); + Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); + Assertions.assertTrue(it.next().toString().contains("is invalid because Record Reader is required")); // invalid write concern runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); @@ -114,8 +114,8 @@ public void testValidators() throws Exception { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(1, results.size()); - Assert.assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); + assertEquals(1, results.size()); + Assertions.assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); // valid write concern runner.setProperty(PutMongoRecord.WRITE_CONCERN, PutMongoRecord.WRITE_CONCERN_UNACKNOWLEDGED); @@ -125,7 +125,7 @@ public void testValidators() throws Exception { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assert.assertEquals(0, results.size()); + assertEquals(0, results.size()); } @Test diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java index 10e2922a1157..a878d5f1c2df 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java @@ -21,8 +21,8 @@ import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.Iterator; @@ -50,10 +50,10 @@ public void testQueryKeyValidation() { if (runner.getProcessContext() instanceof MockProcessContext) { results = ((MockProcessContext) runner.getProcessContext()).validate(); } - Assert.assertNotNull(results); - Assert.assertEquals(1, results.size()); + Assertions.assertNotNull(results); + Assertions.assertEquals(1, results.size()); Iterator it = results.iterator(); - Assert.assertTrue(it.next().toString().endsWith("Both update query key and update query cannot be set at the same time.")); + Assertions.assertTrue(it.next().toString().endsWith("Both update query key and update query cannot be set at the same time.")); runner.removeProperty(PutMongo.UPDATE_QUERY); runner.removeProperty(PutMongo.UPDATE_QUERY_KEY); @@ -65,9 +65,9 @@ public void testQueryKeyValidation() { results = ((MockProcessContext) runner.getProcessContext()).validate(); } - Assert.assertNotNull(results); - Assert.assertEquals(1, results.size()); + Assertions.assertNotNull(results); + Assertions.assertEquals(1, results.size()); it = results.iterator(); - Assert.assertTrue(it.next().toString().endsWith("Either the update query key or the update query field must be set.")); + Assertions.assertTrue(it.next().toString().endsWith("Either the update query key or the update query field must be set.")); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java index 24c130fad9b6..9da63958cd21 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java @@ -29,10 +29,10 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.text.SimpleDateFormat; @@ -54,7 +54,7 @@ public class RunMongoAggregationIT { private Map mappings; private Calendar now = Calendar.getInstance(); - @Before + @BeforeEach public void setup() { runner = TestRunners.newTestRunner(RunMongoAggregation.class); runner.setVariable("uri", MONGO_URI); @@ -80,7 +80,7 @@ public void setup() { } } - @After + @AfterEach public void teardown() { runner = null; mongoClient.getDatabase(DB_NAME).drop(); @@ -120,8 +120,8 @@ public void testAggregation() throws Exception { List flowFiles = runner.getFlowFilesForRelationship(RunMongoAggregation.REL_RESULTS); for (MockFlowFile mff : flowFiles) { String val = mff.getAttribute(AGG_ATTR); - Assert.assertNotNull("Missing query attribute", val); - Assert.assertEquals("Value was wrong", val, queryInput); + Assertions.assertNotNull("Missing query attribute", val); + Assertions.assertEquals(val, queryInput, "Value was wrong"); } } @@ -182,7 +182,7 @@ public void testJsonTypes() throws IOException { for (MockFlowFile mockFlowFile : flowFiles) { byte[] raw = runner.getContentAsByteArray(mockFlowFile); Map> read = mapper.readValue(raw, Map.class); - Assert.assertTrue(read.get("myArray").get(1).equalsIgnoreCase( format.format(now.getTime()))); + Assertions.assertTrue(read.get("myArray").get(1).equalsIgnoreCase( format.format(now.getTime()))); } runner.clearTransferState(); @@ -195,7 +195,7 @@ public void testJsonTypes() throws IOException { for (MockFlowFile mockFlowFile : flowFiles) { byte[] raw = runner.getContentAsByteArray(mockFlowFile); Map> read = mapper.readValue(raw, Map.class); - Assert.assertTrue(read.get("myArray").get(1) == now.getTimeInMillis()); + Assertions.assertTrue(read.get("myArray").get(1) == now.getTimeInMillis()); } } @@ -207,12 +207,12 @@ private void evaluateRunner(int original) throws IOException { for (MockFlowFile mockFlowFile : flowFiles) { byte[] raw = runner.getContentAsByteArray(mockFlowFile); Map read = mapper.readValue(raw, Map.class); - Assert.assertTrue("Value was not found", mappings.containsKey(read.get("_id"))); + Assertions.assertTrue(mappings.containsKey(read.get("_id")), "Value was not found"); String queryAttr = mockFlowFile.getAttribute(AGG_ATTR); - Assert.assertNotNull("Query attribute was null.", queryAttr); - Assert.assertTrue("Missing $project", queryAttr.contains("$project")); - Assert.assertTrue("Missing $group", queryAttr.contains("$group")); + Assertions.assertNotNull("Query attribute was null.", queryAttr); + Assertions.assertTrue(queryAttr.contains("$project"), "Missing $project"); + Assertions.assertTrue(queryAttr.contains("$group"), "Missing $group"); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java index e006ecbb0db2..2a7d01d6d499 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java @@ -25,10 +25,10 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.types.ObjectId; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.List; @@ -38,13 +38,13 @@ public class DeleteGridFSIT extends GridFSITTestBase { private TestRunner runner; private static final String BUCKET = "delete_test_bucket"; - @Before + @BeforeEach public void setup() throws Exception { runner = TestRunners.newTestRunner(DeleteGridFS.class); super.setup(runner, BUCKET, false); } - @After + @AfterEach public void tearDown() { super.tearDown(); } @@ -83,13 +83,13 @@ public void testQueryAttribute() { private void testForQueryAttribute(String mustContain, String attrName) { List flowFiles = runner.getFlowFilesForRelationship(DeleteGridFS.REL_SUCCESS); String attribute = flowFiles.get(0).getAttribute(attrName); - Assert.assertTrue(attribute.contains(mustContain)); + Assertions.assertTrue(attribute.contains(mustContain)); } private String setupTestFile() { String fileName = "simple-delete-test.txt"; ObjectId id = writeTestFile(fileName, "Hello, world!", BUCKET, new HashMap<>()); - Assert.assertNotNull(id); + Assertions.assertNotNull(id); return fileName; } @@ -105,6 +105,6 @@ private void testDeleteByProperty(PropertyDescriptor descriptor, String value, S runner.assertTransferCount(DeleteGridFS.REL_FAILURE, 0); runner.assertTransferCount(DeleteGridFS.REL_SUCCESS, 1); - Assert.assertFalse(String.format("File %s still exists.", fileName), fileExists(fileName, BUCKET)); + Assertions.assertFalse(fileExists(fileName, BUCKET), String.format("File %s still exists.", fileName)); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java index 5ce4ff3358dc..8e285f05cb34 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java @@ -26,10 +26,10 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.types.ObjectId; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.List; @@ -40,13 +40,13 @@ public class FetchGridFSIT extends GridFSITTestBase { static final String BUCKET = "get_test_bucket"; - @Before + @BeforeEach public void setup() throws Exception { runner = TestRunners.newTestRunner(FetchGridFS.class); super.setup(runner, BUCKET, false); } - @After + @AfterEach public void tearDown() { super.tearDown(); } @@ -56,7 +56,7 @@ public void testGetOneByName() { final String fileName = "get_by_name.txt"; final String content = "Hello, world"; ObjectId id = writeTestFile(fileName, content, BUCKET, new HashMap<>()); - Assert.assertNotNull(id); + Assertions.assertNotNull(id); String query = String.format("{\"filename\": \"%s\"}", fileName); runner.enqueue(query); @@ -66,7 +66,7 @@ public void testGetOneByName() { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); List flowFiles = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS); byte[] rawData = runner.getContentAsByteArray(flowFiles.get(0)); - Assert.assertEquals("Data did not match for the file", new String(rawData), content); + Assertions.assertEquals(new String(rawData), content, "Data did not match for the file"); runner.clearTransferState(); runner.setProperty(FetchGridFS.QUERY, query); @@ -78,7 +78,7 @@ public void testGetOneByName() { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); flowFiles = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS); rawData = runner.getContentAsByteArray(flowFiles.get(0)); - Assert.assertEquals("Data did not match for the file", new String(rawData), content); + Assertions.assertEquals(new String(rawData), content, "Data did not match for the file"); } @Test @@ -87,7 +87,7 @@ public void testGetMany() { String content = "Hello, world take %d"; for (int index = 0; index < 5; index++) { ObjectId id = writeTestFile(String.format(baseName, index), String.format(content, index), BUCKET, new HashMap<>()); - Assert.assertNotNull(id); + Assertions.assertNotNull(id); } AllowableValue[] values = new AllowableValue[] { QueryHelper.MODE_MANY_COMMITS, QueryHelper.MODE_ONE_COMMIT }; @@ -110,7 +110,7 @@ public void testQueryAttribute() { final String fileName = "get_by_name.txt"; final String content = "Hello, world"; ObjectId id = writeTestFile(fileName, content, BUCKET, new HashMap<>()); - Assert.assertNotNull(id); + Assertions.assertNotNull(id); final String queryAttr = "gridfs.query.used"; final Map attrs = new HashMap<>(); @@ -125,15 +125,15 @@ public void testQueryAttribute() { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); MockFlowFile mff = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS).get(0); String attr = mff.getAttribute(queryAttr); - Assert.assertNotNull("Query attribute was null.", attr); - Assert.assertTrue("Wrong content.", attr.contains("filename")); + Assertions.assertNotNull("Query attribute was null.", attr); + Assertions.assertTrue(attr.contains("filename"), "Wrong content."); runner.clearTransferState(); id = writeTestFile(fileName, content, BUCKET, new HashMap(){{ put("lookupKey", "xyz"); }}); - Assert.assertNotNull(id); + Assertions.assertNotNull(id); String query = "{ \"metadata\": { \"lookupKey\": \"xyz\" }}"; @@ -146,8 +146,8 @@ public void testQueryAttribute() { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); mff = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS).get(0); attr = mff.getAttribute(queryAttr); - Assert.assertNotNull("Query attribute was null.", attr); - Assert.assertTrue("Wrong content.", attr.contains("metadata")); + Assertions.assertNotNull("Query attribute was null.", attr); + Assertions.assertTrue(attr.contains("metadata"), "Wrong content."); } @Test @@ -176,7 +176,7 @@ private void testQueryFromSource(int failure, int original, int success) { final String fileName = "get_by_name.txt"; final String content = "Hello, world"; ObjectId id = writeTestFile(fileName, content, BUCKET, new HashMap<>()); - Assert.assertNotNull(id); + Assertions.assertNotNull(id); runner.run(); runner.assertTransferCount(FetchGridFS.REL_FAILURE, failure); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java index dfd7ae093d77..40a95f49e76a 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java @@ -26,10 +26,10 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; @@ -39,14 +39,14 @@ public class PutGridFSIT extends GridFSITTestBase { static final String BUCKET = "put_test_bucket"; - @Before + @BeforeEach public void setup() throws Exception { runner = TestRunners.newTestRunner(PutGridFS.class); runner.setProperty(PutGridFS.FILE_NAME, String.format("${%s}", CoreAttributes.FILENAME.key())); super.setup(runner, BUCKET); } - @After + @AfterEach public void tearDown() { super.tearDown(); } @@ -61,7 +61,7 @@ public void testSimplePut() { runner.run(); runner.assertAllFlowFilesTransferred(PutGridFS.REL_SUCCESS); - Assert.assertTrue("File does not exist", fileExists(fileName, BUCKET)); + Assertions.assertTrue(fileExists(fileName, BUCKET), "File does not exist"); } @Test @@ -86,8 +86,8 @@ public void testWithProperties() { put("department", "Accounting"); }}; - Assert.assertTrue("File does not exist", fileExists(fileName, BUCKET)); - Assert.assertTrue("File is missing PARENT_PROPERTIES", fileHasProperties(fileName, BUCKET, attrs)); + Assertions.assertTrue(fileExists(fileName, BUCKET), "File does not exist"); + Assertions.assertTrue(fileHasProperties(fileName, BUCKET, attrs), "File is missing PARENT_PROPERTIES"); } @Test @@ -107,7 +107,7 @@ public void testNoUniqueness() { MongoCollection files = client.getDatabase(DB).getCollection(bucketName); Document query = Document.parse(String.format("{\"filename\": \"%s\"}", fileName)); long count = files.count(query); - Assert.assertTrue("Wrong count", count == 10); + Assertions.assertTrue(count == 10, "Wrong count"); } @Test diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java index be8aa89f1ccf..d97c5decf8a3 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/main/java/org/apache/nifi/mongodb/MongoDBLookupService.java @@ -31,7 +31,6 @@ import org.apache.nifi.lookup.LookupService; import org.apache.nifi.processor.util.JsonValidator; import org.apache.nifi.processor.util.StandardValidators; -import org.apache.nifi.schema.access.SchemaAccessUtils; import org.apache.nifi.serialization.JsonInferenceSchemaRegistryService; import org.apache.nifi.serialization.record.MapRecord; import org.apache.nifi.serialization.record.Record; @@ -67,6 +66,10 @@ "then the entire MongoDB result document minus the _id field will be returned as a record." ) public class MongoDBLookupService extends JsonInferenceSchemaRegistryService implements LookupService { + public static final PropertyDescriptor LOCAL_SCHEMA_NAME = new PropertyDescriptor.Builder() + .fromPropertyDescriptor(SCHEMA_NAME) + .expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY) + .build(); private volatile String databaseName; private volatile String collection; @@ -169,7 +172,7 @@ public void onEnabled(final ConfigurationContext context) { this.lookupValueField = context.getProperty(LOOKUP_VALUE_FIELD).getValue(); this.controllerService = context.getProperty(CONTROLLER_SERVICE).asControllerService(MongoDBClientService.class); - this.schemaNameProperty = context.getProperty(SchemaAccessUtils.SCHEMA_NAME).getValue(); + this.schemaNameProperty = context.getProperty(LOCAL_SCHEMA_NAME).evaluateAttributeExpressions().getValue(); this.databaseName = context.getProperty(DATABASE_NAME).evaluateAttributeExpressions().getValue(); this.collection = context.getProperty(COLLECTION_NAME).evaluateAttributeExpressions().getValue(); @@ -207,7 +210,7 @@ protected List getSupportedPropertyDescriptors() { .build()); _temp.add(SCHEMA_REGISTRY); - _temp.add(SCHEMA_NAME); + _temp.add(LOCAL_SCHEMA_NAME); _temp.add(SCHEMA_VERSION); _temp.add(SCHEMA_BRANCH_NAME); _temp.add(SCHEMA_TEXT); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java index cd306f95cfd7..32d4e86b4a3d 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBControllerServiceIT.java @@ -19,9 +19,9 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Calendar; @@ -32,7 +32,7 @@ public class MongoDBControllerServiceIT { private TestRunner runner; private MongoDBControllerService service; - @Before + @BeforeEach public void before() throws Exception { runner = TestRunners.newTestRunner(TestControllerServiceProcessor.class); service = new MongoDBControllerService(); @@ -41,7 +41,7 @@ public void before() throws Exception { runner.enableControllerService(service); } - @After + @AfterEach public void after() throws Exception { service.onDisable(); } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java index c3ae9057de7f..0944061571ba 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java @@ -30,10 +30,10 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.sql.Timestamp; import java.util.Arrays; @@ -44,6 +44,9 @@ import java.util.Map; import java.util.Optional; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class MongoDBLookupServiceIT { private static final String DB_NAME = String.format("nifi_test-%d", Calendar.getInstance().getTimeInMillis()); private static final String COL_NAME = String.format("nifi_test-%d", Calendar.getInstance().getTimeInMillis()); @@ -54,7 +57,7 @@ public class MongoDBLookupServiceIT { private MongoDatabase db; private MongoCollection col; - @Before + @BeforeEach public void before() throws Exception { runner = TestRunners.newTestRunner(TestLookupServiceProcessor.class); service = new MongoDBLookupService(); @@ -79,7 +82,7 @@ public void before() throws Exception { col = db.getCollection(COL_NAME); } - @After + @AfterEach public void after() { db.drop(); controllerService.onDisable(); @@ -103,8 +106,8 @@ public void testLookupSingle() throws Exception { criteria.put("uuid", "x-y-z"); Optional result = service.lookup(criteria); - Assert.assertNotNull("The value was null.", result.get()); - Assert.assertEquals("The value was wrong.", "Hello, world", result.get()); + Assertions.assertNotNull(result.get(), "The value was null."); + Assertions.assertEquals("Hello, world", result.get(), "The value was wrong."); Map clean = new HashMap<>(); clean.putAll(criteria); @@ -113,10 +116,10 @@ public void testLookupSingle() throws Exception { try { result = service.lookup(criteria); } catch (LookupFailureException ex) { - Assert.fail(); + Assertions.fail(); } - Assert.assertTrue(!result.isPresent()); + Assertions.assertTrue(!result.isPresent()); } @Test @@ -133,23 +136,23 @@ public void testWithSchemaRegistry() throws Exception { Map context = new HashMap<>(); context.put("schema.name", "user"); Optional result = service.lookup(criteria, context); - Assert.assertTrue(result.isPresent()); - Assert.assertNotNull(result.get()); + Assertions.assertTrue(result.isPresent()); + Assertions.assertNotNull(result.get()); MapRecord record = (MapRecord)result.get(); - Assert.assertEquals("john.smith", record.getAsString("username")); - Assert.assertEquals("testing1234", record.getAsString("password")); + Assertions.assertEquals("john.smith", record.getAsString("username")); + Assertions.assertEquals("testing1234", record.getAsString("password")); /* * Test falling back on schema detection if a user doesn't specify the context argument */ result = service.lookup(criteria); - Assert.assertTrue(result.isPresent()); - Assert.assertNotNull(result.get()); + Assertions.assertTrue(result.isPresent()); + Assertions.assertNotNull(result.get()); record = (MapRecord)result.get(); - Assert.assertEquals("john.smith", record.getAsString("username")); - Assert.assertEquals("testing1234", record.getAsString("password")); + Assertions.assertEquals("john.smith", record.getAsString("username")); + Assertions.assertEquals("testing1234", record.getAsString("password")); } @Test @@ -172,8 +175,8 @@ public void testSchemaTextStrategy() throws Exception { attrs.put("schema.text", new String(contents)); Optional results = service.lookup(criteria, attrs); - Assert.assertNotNull(results); - Assert.assertTrue(results.isPresent()); + Assertions.assertNotNull(results); + Assertions.assertTrue(results.isPresent()); } @Test @@ -204,23 +207,23 @@ public void testLookupRecord() throws Exception { criteria.put("uuid", "x-y-z"); Optional result = service.lookup(criteria); - Assert.assertNotNull("The value was null.", result.get()); - Assert.assertTrue("The value was wrong.", result.get() instanceof MapRecord); + Assertions.assertNotNull(result.get(), "The value was null."); + Assertions.assertTrue(result.get() instanceof MapRecord, "The value was wrong."); MapRecord record = (MapRecord)result.get(); RecordSchema subSchema = ((RecordDataType)record.getSchema().getField("subrecordField").get().getDataType()).getChildSchema(); - Assert.assertEquals("The value was wrong.", "Hello, world", record.getValue("stringField")); - Assert.assertEquals("The value was wrong.", "x-y-z", record.getValue("uuid")); - Assert.assertEquals(new Long(10000), record.getValue("longField")); - Assert.assertEquals((Double.MAX_VALUE / 2.0), record.getValue("decimalField")); - Assert.assertEquals(d, record.getValue("dateField")); - Assert.assertEquals(ts.getTime(), ((Date)record.getValue("timestampField")).getTime()); + Assertions.assertEquals("Hello, world", record.getValue("stringField"), "The value was wrong."); + Assertions.assertEquals("x-y-z", record.getValue("uuid"), "The value was wrong."); + Assertions.assertEquals(new Long(10000), record.getValue("longField")); + Assertions.assertEquals((Double.MAX_VALUE / 2.0), record.getValue("decimalField")); + Assertions.assertEquals(d, record.getValue("dateField")); + Assertions.assertEquals(ts.getTime(), ((Date)record.getValue("timestampField")).getTime()); Record subRecord = record.getAsRecord("subrecordField", subSchema); - Assert.assertNotNull(subRecord); - Assert.assertEquals("test", subRecord.getValue("nestedString")); - Assert.assertEquals(new Long(1000), subRecord.getValue("nestedLong")); - Assert.assertEquals(list, record.getValue("arrayField")); + Assertions.assertNotNull(subRecord); + Assertions.assertEquals("test", subRecord.getValue("nestedString")); + Assertions.assertEquals(new Long(1000), subRecord.getValue("nestedLong")); + Assertions.assertEquals(list, record.getValue("arrayField")); Map clean = new HashMap<>(); clean.putAll(criteria); @@ -229,10 +232,10 @@ public void testLookupRecord() throws Exception { try { result = service.lookup(criteria); } catch (LookupFailureException ex) { - Assert.fail(); + Assertions.fail(); } - Assert.assertTrue(!result.isPresent()); + Assertions.assertTrue(!result.isPresent()); } @Test @@ -243,23 +246,8 @@ public void testServiceParameters() { Map criteria = new HashMap<>(); criteria.put("uuid", "x-y-z"); - boolean error = false; - try { - service.lookup(criteria); - } catch(Exception ex) { - error = true; - } - - Assert.assertFalse("An error was thrown when no error should have been thrown.", error); - error = false; - - try { - service.lookup(new HashMap()); - } catch (Exception ex) { - error = true; - Assert.assertTrue("The exception was the wrong type", ex instanceof LookupFailureException); - } + assertDoesNotThrow(() -> service.lookup(criteria)); - Assert.assertTrue("An error was not thrown when the input was empty", error); + assertThrows(LookupFailureException.class, () -> service.lookup(new HashMap<>())); } } diff --git a/nifi-registry/nifi-registry-core/nifi-registry-test/pom.xml b/nifi-registry/nifi-registry-core/nifi-registry-test/pom.xml index e5b18781127e..4ff4bc5fb644 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-test/pom.xml +++ b/nifi-registry/nifi-registry-core/nifi-registry-test/pom.xml @@ -83,6 +83,7 @@ junit junit 4.13.1 + compile diff --git a/nifi-registry/pom.xml b/nifi-registry/pom.xml index 255286ac545b..fdf9a12bde6c 100644 --- a/nifi-registry/pom.xml +++ b/nifi-registry/pom.xml @@ -43,7 +43,7 @@ 6.5.7 6.4.0 3.12.0 - 1.15.1 + 1.16.0 1.4.199 3.4.0-01 2.3.2 diff --git a/pom.xml b/pom.xml index 95df3fcbbaa3..17dc60ef17dd 100644 --- a/pom.xml +++ b/pom.xml @@ -267,10 +267,18 @@ + + org.junit + junit-bom + 5.7.2 + pom + import + junit junit 4.13.2 + test org.mockito @@ -455,8 +463,18 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.vintage + junit-vintage-engine test @@ -525,14 +543,6 @@ -Duser.timezone=${user.timezone} -Dfile.encoding=UTF-8 - - - - org.apache.maven.surefire - surefire-junit4 - ${surefire.version} - - org.apache.maven.plugins