Skip to content

Commit

Permalink
NIFI-9041 Replaced JUnit 4 only testing configuration with a combinat…
Browse files Browse the repository at this point in the history
…ion 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 apache#5304

Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
MikeThomsen authored and exceptionfactory committed Aug 12, 2021
1 parent fb4edfa commit 4c6bd85
Show file tree
Hide file tree
Showing 34 changed files with 361 additions and 361 deletions.
4 changes: 2 additions & 2 deletions nifi-mock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
<dependency>
<!-- Dependency marked as compile, not test, because we have assertion
methods in our MockSession & MockFlowFile -->
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
20 changes: 10 additions & 10 deletions nifi-mock/src/main/java/org/apache/nifi/state/MockStateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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));
}

/**
Expand All @@ -208,7 +208,7 @@ public void assertStateEquals(final String key, final String value, final Scope
*/
public void assertStateEquals(final Map<String, String> stateValues, final Scope scope) {
final StateMap stateMap = retrieveState(scope);
Assert.assertEquals(stateValues, stateMap.toMap());
Assertions.assertEquals(stateValues, stateMap.toMap());
}

/**
Expand All @@ -219,7 +219,7 @@ public void assertStateEquals(final Map<String, String> stateValues, final Scope
*/
public void assertStateNotEquals(final Map<String, String> stateValues, final Scope scope) {
final StateMap stateMap = retrieveState(scope);
Assert.assertNotSame(stateValues, stateMap.toMap());
Assertions.assertNotSame(stateValues, stateMap.toMap());
}

/**
Expand All @@ -230,7 +230,7 @@ public void assertStateNotEquals(final Map<String, String> 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));
}

/**
Expand All @@ -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");
}

/**
Expand All @@ -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");
}

/**
Expand All @@ -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");
}

/**
Expand All @@ -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");
}

/**
Expand Down
22 changes: 11 additions & 11 deletions nifi-mock/src/main/java/org/apache/nifi/util/MockFlowFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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));
}

Expand All @@ -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");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1203,28 +1203,28 @@ private static Map<String, String> intersectAttributes(final Collection<FlowFile
* Assert that the session has been committed
*/
public void assertCommitted() {
Assert.assertTrue("Session was not committed", committed);
Assertions.assertTrue(committed, "Session was not committed");
}

/**
* Assert that the session has not been committed
*/
public void assertNotCommitted() {
Assert.assertFalse("Session was committed", committed);
Assertions.assertFalse(committed, "Session was committed");
}

/**
* Assert that {@link #rollback()} has been called
*/
public void assertRolledBack() {
Assert.assertTrue("Session was not rolled back", rolledback);
Assertions.assertTrue(rolledback, "Session was not rolled back");
}

/**
* Assert that {@link #rollback()} has not been called
*/
public void assertNotRolledBack() {
Assert.assertFalse("Session was rolled back", rolledback);
Assertions.assertFalse(rolledback, "Session was rolled back");
}

/**
Expand All @@ -1236,8 +1236,8 @@ public void assertNotRolledBack() {
*/
public void assertTransferCount(final Relationship relationship, final int count) {
final int transferCount = getFlowFilesForRelationship(relationship).size();
Assert.assertEquals("Expected " + count + " FlowFiles to be transferred to "
+ relationship + " but actual transfer count was " + transferCount, count, transferCount);
Assertions.assertEquals(count, transferCount, "Expected " + count + " FlowFiles to be transferred to "
+ relationship + " but actual transfer count was " + transferCount);
}

/**
Expand All @@ -1255,14 +1255,14 @@ public void assertTransferCount(final String relationship, final int count) {
* Assert that there are no FlowFiles left on the input queue.
*/
public void assertQueueEmpty() {
Assert.assertTrue("FlowFile Queue has " + this.processorQueue.size() + " items", this.processorQueue.isEmpty());
Assertions.assertTrue(this.processorQueue.isEmpty(), "FlowFile Queue has " + this.processorQueue.size() + " items");
}

/**
* Assert that at least one FlowFile is on the input queue
*/
public void assertQueueNotEmpty() {
Assert.assertFalse("FlowFile Queue is empty", this.processorQueue.isEmpty());
Assertions.assertFalse(this.processorQueue.isEmpty(), "FlowFile Queue is empty");
}

/**
Expand All @@ -1287,7 +1287,7 @@ public void assertAllFlowFilesTransferred(final Relationship relationship) {
final List<MockFlowFile> 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);
}
}
}
Expand Down
Loading

0 comments on commit 4c6bd85

Please sign in to comment.