You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ex...@apache.org on 2022/08/08 17:35:39 UTC
[nifi] branch main updated: NIFI-10307 Refactored nifi-standard-processors tests to use JUnit 5
This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 5b9f096143 NIFI-10307 Refactored nifi-standard-processors tests to use JUnit 5
5b9f096143 is described below
commit 5b9f09614383b42ae0b92960445aa63ee9e869b6
Author: Emilio Setiadarma <em...@gmail.com>
AuthorDate: Mon Aug 8 07:48:16 2022 -0700
NIFI-10307 Refactored nifi-standard-processors tests to use JUnit 5
This closes #6272
Signed-off-by: David Handermann <ex...@apache.org>
---
.../processors/standard/AbstractConversionIT.java | 6 +-
.../standard/AbstractTestTailFileScenario.java | 24 +-
.../standard/ConversionWithExplicitSchemaIT.java | 4 +-
.../standard/ITestHandleHttpRequest.java | 47 ++--
.../processors/standard/PutDatabaseRecordTest.java | 1 +
.../standard/QueryDatabaseTableRecordTest.java | 40 ++--
.../standard/QueryDatabaseTableTest.java | 44 ++--
.../standard/TestAbstractExecuteSQL.java | 12 +-
.../processors/standard/TestAttributesToCSV.java | 42 ++--
.../processors/standard/TestAttributesToJSON.java | 26 ++-
.../standard/TestBase64EncodeContent.java | 3 +-
.../processors/standard/TestCompressContent.java | 4 +-
.../nifi/processors/standard/TestControlRate.java | 4 +-
.../standard/TestConvertCharacterSet.java | 20 +-
.../processors/standard/TestConvertJSONToSQL.java | 67 ++++--
.../processors/standard/TestConvertRecord.java | 40 ++--
.../nifi/processors/standard/TestDebugFlow.java | 76 ++++---
.../processors/standard/TestDetectDuplicate.java | 24 +-
.../processors/standard/TestDistributeLoad.java | 59 ++---
.../processors/standard/TestDuplicateFlowFile.java | 2 +-
.../processors/standard/TestEncodeContent.java | 3 +-
.../processors/standard/TestEncryptContent.java | 92 ++++----
.../nifi/processors/standard/TestEnforceOrder.java | 4 +-
.../processors/standard/TestEvaluateJsonPath.java | 51 ++---
.../processors/standard/TestExecuteProcess.java | 58 +++--
.../nifi/processors/standard/TestExecuteSQL.java | 78 ++++---
.../processors/standard/TestExecuteSQLRecord.java | 45 ++--
.../standard/TestExecuteStreamCommand.java | 108 +++------
.../nifi/processors/standard/TestExtractGrok.java | 8 +-
.../nifi/processors/standard/TestExtractText.java | 44 ++--
.../standard/TestExtractTextNamedGroups.java | 50 +++--
.../apache/nifi/processors/standard/TestFTP.java | 30 +--
.../standard/TestFetchDistributedMapCache.java | 24 +-
.../nifi/processors/standard/TestFetchFTP.java | 38 ++--
.../nifi/processors/standard/TestFetchFile.java | 27 +--
.../nifi/processors/standard/TestForkRecord.java | 14 +-
.../processors/standard/TestGenerateFlowFile.java | 10 +-
.../standard/TestGenerateTableFetch.java | 26 ++-
.../nifi/processors/standard/TestGetFile.java | 31 ++-
.../nifi/processors/standard/TestGetJMSQueue.java | 71 ++----
.../nifi/processors/standard/TestGetSFTP.java | 30 +--
.../standard/TestHandleHttpResponse.java | 47 ++--
.../processors/standard/TestHashAttribute.java | 15 +-
.../nifi/processors/standard/TestHashContent.java | 11 +-
.../processors/standard/TestIdentifyMimeType.java | 37 ++--
.../nifi/processors/standard/TestJmsConsumer.java | 49 ++--
.../processors/standard/TestJoinEnrichment.java | 2 +-
.../processors/standard/TestJoltTransformJSON.java | 34 +--
.../standard/TestListDatabaseTables.java | 33 ++-
.../nifi/processors/standard/TestListFile.java | 82 ++-----
.../nifi/processors/standard/TestListenRELP.java | 55 ++---
.../nifi/processors/standard/TestListenSyslog.java | 38 ++--
.../processors/standard/TestListenTCPRecord.java | 88 ++++----
.../nifi/processors/standard/TestListenUDP.java | 26 ++-
.../processors/standard/TestListenUDPRecord.java | 6 +-
.../nifi/processors/standard/TestLogAttribute.java | 16 +-
.../nifi/processors/standard/TestLogMessage.java | 53 ++---
.../processors/standard/TestLookupAttribute.java | 28 +--
.../nifi/processors/standard/TestLookupRecord.java | 16 +-
.../nifi/processors/standard/TestMergeContent.java | 111 +++++-----
.../nifi/processors/standard/TestMergeRecord.java | 28 ++-
.../nifi/processors/standard/TestModifyBytes.java | 13 +-
.../processors/standard/TestMonitorActivity.java | 4 +-
.../nifi/processors/standard/TestNotify.java | 38 ++--
.../nifi/processors/standard/TestParseCEF.java | 72 +++---
.../nifi/processors/standard/TestParseSyslog.java | 2 +-
.../processors/standard/TestParseSyslog5424.java | 12 +-
.../processors/standard/TestPartitionRecord.java | 10 +-
.../standard/TestPutDistributedMapCache.java | 26 +--
.../nifi/processors/standard/TestPutEmail.java | 38 ++--
.../nifi/processors/standard/TestPutFile.java | 87 ++++----
.../nifi/processors/standard/TestPutJMS.java | 71 +++---
.../nifi/processors/standard/TestPutRecord.java | 10 +-
.../nifi/processors/standard/TestPutSQL.java | 246 ++++++++++-----------
.../nifi/processors/standard/TestPutSyslog.java | 24 +-
.../nifi/processors/standard/TestPutTCP.java | 30 ++-
.../nifi/processors/standard/TestQueryRecord.java | 15 +-
.../nifi/processors/standard/TestReplaceText.java | 92 ++++----
.../standard/TestReplaceTextWithMapping.java | 17 +-
.../processors/standard/TestRetryFlowFile.java | 27 +--
.../processors/standard/TestRouteOnAttribute.java | 17 +-
.../processors/standard/TestRouteOnContent.java | 9 +-
.../nifi/processors/standard/TestRouteText.java | 32 ++-
.../nifi/processors/standard/TestSampleRecord.java | 6 +-
.../processors/standard/TestScanAttribute.java | 8 +-
.../nifi/processors/standard/TestScanContent.java | 13 +-
.../processors/standard/TestSegmentContent.java | 11 +-
.../nifi/processors/standard/TestSplitContent.java | 7 +-
.../nifi/processors/standard/TestSplitJson.java | 41 ++--
.../nifi/processors/standard/TestSplitRecord.java | 6 +-
.../nifi/processors/standard/TestSplitText.java | 12 +-
.../nifi/processors/standard/TestSplitXml.java | 33 +--
.../nifi/processors/standard/TestTailFile.java | 42 ++--
.../standard/TestTailFileGeneratedScenarios.java | 106 ++++-----
.../standard/TestTailFileSimpleScenarios.java | 8 +-
.../nifi/processors/standard/TestTransformXml.java | 14 +-
.../processors/standard/TestUnpackContent.java | 45 ++--
.../processors/standard/TestUpdateCounter.java | 14 +-
.../nifi/processors/standard/TestUpdateRecord.java | 22 +-
.../nifi/processors/standard/TestValidateCsv.java | 2 +-
.../processors/standard/TestValidateRecord.java | 10 +-
.../nifi/processors/standard/TestValidateXml.java | 17 +-
.../apache/nifi/processors/standard/TestWait.java | 56 +++--
.../standard/TestWaitNotifyProtocol.java | 24 +-
.../db/impl/TestMSSQL2008DatabaseAdapter.java | 48 ++--
.../standard/db/impl/TestMSSQLDatabaseAdapter.java | 56 ++---
.../standard/db/impl/TestMySQLDatabaseAdapter.java | 38 ++--
.../db/impl/TestOracle12DatabaseAdapter.java | 75 ++++---
.../db/impl/TestOracleDatabaseAdapter.java | 38 ++--
.../db/impl/TestPostgreSQLDatabaseAdapter.java | 40 ++--
.../TestInsertRecordFieldsJoinStrategy.java | 2 +-
.../enrichment/TestWrapperJoinStrategy.java | 2 +-
.../standard/ftp/TestVirtualFileSystem.java | 14 +-
.../standard/ftp/TestVirtualFileSystemView.java | 14 +-
.../processors/standard/ftp/TestVirtualPath.java | 8 +-
.../standard/relp/frame/RELPFrameDecoderTest.java | 2 +-
.../relp/frame/RELPResponseEncoderTest.java | 2 +-
.../standard/relp/frame/TestRELPDecoder.java | 81 +++----
.../standard/relp/frame/TestRELPEncoder.java | 17 +-
.../standard/relp/frame/TestRELPFrame.java | 34 ++-
.../standard/relp/response/TestRELPResponse.java | 74 ++++---
.../processors/standard/util/TestFileInfo.java | 5 +-
.../util/TestFlowFileAttributesSerializer.java | 14 +-
.../processors/standard/util/TestSFTPTransfer.java | 30 +--
124 files changed, 1990 insertions(+), 2155 deletions(-)
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractConversionIT.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractConversionIT.java
index 9b458a228d..7bd2c943fe 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractConversionIT.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractConversionIT.java
@@ -34,8 +34,8 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.xml.XMLReader;
import org.apache.nifi.xml.XMLRecordSetWriter;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -59,7 +59,7 @@ public abstract class AbstractConversionIT {
protected Consumer<MockFlowFile> resultHandler;
protected Consumer<TestRunner> writerConfigurer;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
reader = null;
inputHandler = null;
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractTestTailFileScenario.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractTestTailFileScenario.java
index 8d890be6b8..dfc46a6dc4 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractTestTailFileScenario.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/AbstractTestTailFileScenario.java
@@ -16,14 +16,12 @@
*/
package org.apache.nifi.processors.standard;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Before;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import java.io.File;
import java.io.IOException;
@@ -36,8 +34,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class AbstractTestTailFileScenario {
public static final String TEST_DIRECTORY = "testTailFileScenario";
@@ -63,10 +61,8 @@ public class AbstractTestTailFileScenario {
protected List<String> expected;
private Random random;
- @Before
+ @BeforeEach
public void setUp() throws IOException {
- System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.standard", "TRACE");
-
clean();
File directory = new File("target/" + TEST_DIRECTORY);
@@ -105,7 +101,7 @@ public class AbstractTestTailFileScenario {
random = new Random();
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
if (randomAccessFile != null) {
randomAccessFile.close();
@@ -124,10 +120,6 @@ public class AbstractTestTailFileScenario {
}
public void testScenario(List<Action> actions, boolean stopAfterEachTrigger) throws Exception {
- if (actions.contains(Action.ROLLOVER)) {
- Assume.assumeTrue("Test wants to rename an open file which is not allowed on Windows", !SystemUtils.IS_OS_WINDOWS);
- }
-
// GIVEN
this.stopAfterEachTrigger.set(stopAfterEachTrigger);
@@ -150,9 +142,9 @@ public class AbstractTestTailFileScenario {
.collect(Collectors.toList());
assertEquals(
- stopAfterEachTrigger + " " + actions.toString(),
expected.stream().collect(Collectors.joining()),
- actual.stream().collect(Collectors.joining())
+ actual.stream().collect(Collectors.joining()),
+ stopAfterEachTrigger + " " + actions.toString()
);
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ConversionWithExplicitSchemaIT.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ConversionWithExplicitSchemaIT.java
index 81467e33f9..fa7595c16f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ConversionWithExplicitSchemaIT.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ConversionWithExplicitSchemaIT.java
@@ -25,7 +25,7 @@ import org.apache.nifi.serialization.MalformedRecordException;
import org.apache.nifi.serialization.RecordReader;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.TestRunner;
-import org.junit.Before;
+import org.junit.jupiter.api.BeforeEach;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -37,7 +37,7 @@ import java.util.Map;
public class ConversionWithExplicitSchemaIT extends AbstractConversionIT {
private String schema;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
super.setUp();
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITestHandleHttpRequest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITestHandleHttpRequest.java
index 9e98ef331a..cffcab0242 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITestHandleHttpRequest.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ITestHandleHttpRequest.java
@@ -16,8 +16,9 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -72,11 +73,11 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.web.util.ssl.SslContextUtils;
import org.jetbrains.annotations.NotNull;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito;
public class ITestHandleHttpRequest {
@@ -87,25 +88,26 @@ public class ITestHandleHttpRequest {
private static SSLContext trustStoreSslContext;
- @BeforeClass
+ @BeforeAll
public static void configureServices() throws TlsException {
keyStoreSslContext = SslContextUtils.createKeyStoreSslContext();
trustStoreSslContext = SslContextUtils.createTrustStoreSslContext();
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
}
- @After
+ @AfterEach
public void tearDown() throws Exception {
if (processor != null) {
processor.shutdown();
}
}
- @Test(timeout = 30000)
+ @Test
+ @Timeout(value = 30)
public void testRequestAddedToService() throws InitializationException {
CountDownLatch serverReady = new CountDownLatch(1);
CountDownLatch requestSent = new CountDownLatch(1);
@@ -160,7 +162,8 @@ public class ITestHandleHttpRequest {
mff.assertAttributeEquals("http.headers.header3", "apple=orange");
}
- @Test(timeout = 30000)
+ @Test
+ @Timeout(value = 30)
public void testMultipartFormDataRequest() throws InitializationException {
CountDownLatch serverReady = new CountDownLatch(1);
CountDownLatch requestSent = new CountDownLatch(1);
@@ -273,7 +276,8 @@ public class ITestHandleHttpRequest {
mff.assertAttributeExists("http.headers.multipart.content-disposition");
}
- @Test(timeout = 30000)
+ @Test
+ @Timeout(value = 30)
public void testMultipartFormDataRequestCaptureFormAttributes() throws InitializationException {
CountDownLatch serverReady = new CountDownLatch(1);
CountDownLatch requestSent = new CountDownLatch(1);
@@ -341,7 +345,8 @@ public class ITestHandleHttpRequest {
}
}
- @Test(timeout = 30000)
+ @Test
+ @Timeout(value = 30)
public void testMultipartFormDataRequestFailToRegisterContext() throws InitializationException, InterruptedException {
CountDownLatch serverReady = new CountDownLatch(1);
CountDownLatch requestSent = new CountDownLatch(1);
@@ -413,7 +418,7 @@ public class ITestHandleHttpRequest {
runner.assertAllFlowFilesTransferred(HandleHttpRequest.REL_SUCCESS, 0);
assertEquals(0, contextMap.size());
- Assert.assertEquals(503, responseCode.get());
+ assertEquals(503, responseCode.get());
}
private byte[] generateRandomBinaryData() {
@@ -437,12 +442,13 @@ public class ITestHandleHttpRequest {
protected MockFlowFile findFlowFile(List<MockFlowFile> flowFilesForRelationship, String attributeName, String attributeValue) {
Optional<MockFlowFile> optional = flowFilesForRelationship.stream().filter(ff -> ff.getAttribute(attributeName).equals(attributeValue)).findFirst();
- Assert.assertTrue(optional.isPresent());
+ assertTrue(optional.isPresent());
return optional.get();
}
- @Test(timeout = 30000)
+ @Test
+ @Timeout(value = 30)
public void testFailToRegister() throws InitializationException, InterruptedException {
CountDownLatch serverReady = new CountDownLatch(1);
CountDownLatch requestSent = new CountDownLatch(1);
@@ -594,7 +600,8 @@ public class ITestHandleHttpRequest {
}
}
- @Test(timeout = 15000)
+ @Test
+ @Timeout(value = 15)
public void testOnPrimaryNodeChangePrimaryNodeRevoked() throws Exception {
processor = new HandleHttpRequest();
final TestRunner runner = TestRunners.newTestRunner(processor);
@@ -645,8 +652,8 @@ public class ITestHandleHttpRequest {
processor.onPrimaryNodeChange(PrimaryNodeState.PRIMARY_NODE_REVOKED);
requestCompleted.await();
- assertNull("HTTP Request Exception found", requestException.get());
- assertEquals("HTTP Status not matched", HttpServletResponse.SC_SERVICE_UNAVAILABLE, responseStatus.get());
+ assertNull(requestException.get(), "HTTP Request Exception found");
+ assertEquals(HttpServletResponse.SC_SERVICE_UNAVAILABLE, responseStatus.get(), "HTTP Status not matched");
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java
index 04206f8933..d0d3e1d186 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java
@@ -90,6 +90,7 @@ public class PutDatabaseRecordTest {
} catch (IOException ignore) {
// Do nothing, may not have existed
}
+ System.clearProperty("derby.stream.error.file");
}
@BeforeEach
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java
index f46dcc5eb5..71bb8ba157 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java
@@ -35,11 +35,11 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.util.db.JdbcProperties;
import org.apache.nifi.util.file.FileUtils;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -57,10 +57,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Unit tests for the QueryDatabaseTableRecord processor
@@ -76,7 +77,7 @@ public class QueryDatabaseTableRecordTest {
private final static String MAX_ROWS_KEY = "maxRows";
- @BeforeClass
+ @BeforeAll
public static void setupBeforeClass() {
System.setProperty("derby.stream.error.file", "target/derby.log");
@@ -89,7 +90,7 @@ public class QueryDatabaseTableRecordTest {
}
}
- @AfterClass
+ @AfterAll
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
@@ -103,10 +104,11 @@ public class QueryDatabaseTableRecordTest {
} catch (IOException ioe) {
// Do nothing, may not have existed
}
+ System.clearProperty("derby.stream.error.file");
}
- @Before
+ @BeforeEach
public void setup() throws InitializationException, IOException {
final DBCPService dbcp = new DBCPServiceSimpleImpl();
final Map<String, String> dbcpProperties = new HashMap<>();
@@ -128,7 +130,7 @@ public class QueryDatabaseTableRecordTest {
runner.enableControllerService(recordWriter);
}
- @After
+ @AfterEach
public void teardown() throws IOException {
runner.getStateManager().clear(Scope.CLUSTER);
runner = null;
@@ -222,9 +224,11 @@ public class QueryDatabaseTableRecordTest {
assertEquals("SELECT * FROM myTable WHERE id > 509 AND DATE_CREATED >= '2016-03-07 12:34:56' AND TIME_CREATED >= '12:34:57' AND (type = \"CUSTOMER\")", query);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test
public void testGetQueryNoTable() {
- processor.getQuery(dbAdapter, null, null, null, null, null);
+ assertThrows(IllegalArgumentException.class, () -> {
+ processor.getQuery(dbAdapter, null, null, null, null, null);
+ });
}
@Test
@@ -1323,7 +1327,7 @@ public class QueryDatabaseTableRecordTest {
runner.clearTransferState();
}
- @Test(expected = AssertionError.class)
+ @Test
public void testMissingColumn() throws ProcessException, SQLException {
// load test data to database
final Connection con = ((DBCPService) runner.getControllerService("dbcp")).getConnection();
@@ -1358,7 +1362,9 @@ public class QueryDatabaseTableRecordTest {
runner.setProperty(QueryDatabaseTableRecord.MAX_VALUE_COLUMN_NAMES, "ID");
runner.setProperty(QueryDatabaseTableRecord.MAX_ROWS_PER_FLOW_FILE, "2");
- runner.run();
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
index d7eec018a1..00dfff8309 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
@@ -38,11 +38,11 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.util.file.FileUtils;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -62,10 +62,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Unit tests for the QueryDatabaseTable processor
@@ -81,8 +82,8 @@ public class QueryDatabaseTableTest {
private final static String MAX_ROWS_KEY = "maxRows";
- @BeforeClass
- public static void setupBeforeClass() throws IOException {
+ @BeforeAll
+ public static void setupBeforeClass() {
System.setProperty("derby.stream.error.file", "target/derby.log");
// remove previous test database, if any
@@ -94,7 +95,7 @@ public class QueryDatabaseTableTest {
}
}
- @AfterClass
+ @AfterAll
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
@@ -108,10 +109,11 @@ public class QueryDatabaseTableTest {
} catch (IOException ioe) {
// Do nothing, may not have existed
}
+ System.clearProperty("derby.stream.error.file");
}
- @Before
+ @BeforeEach
public void setup() throws InitializationException, IOException {
final DBCPService dbcp = new DBCPServiceSimpleImpl();
final Map<String, String> dbcpProperties = new HashMap<>();
@@ -127,7 +129,7 @@ public class QueryDatabaseTableTest {
runner.getStateManager().clear(Scope.CLUSTER);
}
- @After
+ @AfterEach
public void teardown() throws IOException {
runner.getStateManager().clear(Scope.CLUSTER);
runner = null;
@@ -221,9 +223,11 @@ public class QueryDatabaseTableTest {
assertEquals("SELECT * FROM myTable WHERE id > 509 AND DATE_CREATED >= '2016-03-07 12:34:56' AND TIME_CREATED >= '12:34:57' AND (type = \"CUSTOMER\")", query);
}
- @Test(expected = IllegalArgumentException.class)
- public void testGetQueryNoTable() throws Exception {
- processor.getQuery(dbAdapter, null, null, null, null, null);
+ @Test
+ public void testGetQueryNoTable() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ processor.getQuery(dbAdapter, null, null, null, null, null);
+ });
}
@Test
@@ -1351,7 +1355,7 @@ public class QueryDatabaseTableTest {
runner.clearTransferState();
}
- @Test(expected = AssertionError.class)
+ @Test
public void testMissingColumn() throws ProcessException, ClassNotFoundException, SQLException, InitializationException, IOException {
// load test data to database
final Connection con = ((DBCPService) runner.getControllerService("dbcp")).getConnection();
@@ -1386,7 +1390,9 @@ public class QueryDatabaseTableTest {
runner.setProperty(QueryDatabaseTable.MAX_VALUE_COLUMN_NAMES, "ID");
runner.setProperty(QueryDatabaseTable.MAX_ROWS_PER_FLOW_FILE, "2");
- runner.run();
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAbstractExecuteSQL.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAbstractExecuteSQL.java
index 762999d7d5..79797605b7 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAbstractExecuteSQL.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAbstractExecuteSQL.java
@@ -21,18 +21,18 @@ import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.processors.standard.sql.SqlWriter;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestAbstractExecuteSQL {
private AbstractExecuteSQL testSubject;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
testSubject = new AbstractExecuteSQL() {
@Override
@@ -43,7 +43,7 @@ public class TestAbstractExecuteSQL {
}
@Test
- public void testGetQueries() throws Exception {
+ public void testGetQueries() {
// GIVEN
String queriesString = "SOME kind of PRE-QUERY statement;\n" +
"AND another PRE-QUERY statment;";
@@ -61,7 +61,7 @@ public class TestAbstractExecuteSQL {
}
@Test
- public void testGetQueriesWithEscapedSemicolon() throws Exception {
+ public void testGetQueriesWithEscapedSemicolon() {
// GIVEN
String queriesString = "SET COMPLEX_KEY = 'KEYPART_1=value1\\;KEYPART_2=<valuePart2>\\;’ FOR SESSION;\n" +
"SOME other PRE-QUERY statement;\n" +
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java
index 206b186375..e98f04a61a 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java
@@ -21,7 +21,7 @@ import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Arrays;
@@ -32,9 +32,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.regex.Pattern;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestAttributesToCSV {
@@ -47,7 +47,7 @@ public class TestAttributesToCSV {
private static final String newline = System.getProperty("line.separator");
@Test
- public void testAttrListNoCoreNullOffNewAttrToAttribute() throws Exception {
+ public void testAttrListNoCoreNullOffNewAttrToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -68,7 +68,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttrListNoCoreNullOffNewAttrToContent() throws Exception {
+ public void testAttrListNoCoreNullOffNewAttrToContent() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
//set the destination of the csv string to be an attribute
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
@@ -91,7 +91,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttrListNoCoreNullOffTwoNewAttrToAttribute() throws Exception {
+ public void testAttrListNoCoreNullOffTwoNewAttrToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -112,7 +112,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttrListNoCoreNullTwoNewAttrToAttribute() throws Exception {
+ public void testAttrListNoCoreNullTwoNewAttrToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -133,7 +133,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testNoAttrListNoCoreNullOffToAttribute() throws Exception {
+ public void testNoAttrListNoCoreNullOffToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
//set the destination of the csv string to be an attribute
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
@@ -152,7 +152,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testNoAttrListNoCoreNullToAttribute() throws Exception {
+ public void testNoAttrListNoCoreNullToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -212,7 +212,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testNoAttrListCoreNullOffToAttribute() throws IOException {
+ public void testNoAttrListCoreNullOffToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -290,7 +290,7 @@ public class TestAttributesToCSV {
@Test
- public void testAttrListNoCoreNullOffToAttribute() throws IOException {
+ public void testAttrListNoCoreNullOffToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -329,7 +329,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttrListCoreNullOffToAttribute() throws IOException {
+ public void testAttrListCoreNullOffToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
@@ -371,7 +371,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttrListNoCoreNullOffOverrideCoreByAttrListToAttribute() throws IOException {
+ public void testAttrListNoCoreNullOffOverrideCoreByAttrListToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -414,7 +414,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttrListFromExpCoreNullOffToAttribute() throws IOException {
+ public void testAttrListFromExpCoreNullOffToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
@@ -478,7 +478,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttrListWithCommasInNameFromExpCoreNullOffToAttribute() throws IOException {
+ public void testAttrListWithCommasInNameFromExpCoreNullOffToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
@@ -544,7 +544,7 @@ public class TestAttributesToCSV {
@Test
- public void testAttrListFromExpNoCoreNullOffOverrideCoreByAttrListToAttribute() throws IOException {
+ public void testAttrListFromExpNoCoreNullOffOverrideCoreByAttrListToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -588,7 +588,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttributesRegex() throws IOException {
+ public void testAttributesRegex() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -632,7 +632,7 @@ public class TestAttributesToCSV {
}
@Test
- public void testAttributesRegexAndList() throws IOException {
+ public void testAttributesRegexAndList() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -681,7 +681,7 @@ public class TestAttributesToCSV {
@Test
- public void testSchemaToAttribute() throws Exception {
+ public void testSchemaToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -746,7 +746,7 @@ public class TestAttributesToCSV {
@Test
- public void testSchemaWithCoreAttribuesToAttribute() throws Exception {
+ public void testSchemaWithCoreAttribuesToAttribute() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
index 40352fe78d..b6de6ec698 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
@@ -24,7 +24,7 @@ import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Arrays;
@@ -34,9 +34,10 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestAttributesToJSON {
@@ -44,22 +45,23 @@ public class TestAttributesToJSON {
private static final String TEST_ATTRIBUTE_KEY = "TestAttribute";
private static final String TEST_ATTRIBUTE_VALUE = "TestValue";
- @Test(expected = AssertionError.class)
- public void testInvalidUserSuppliedAttributeList() throws Exception {
+ @Test
+ public void testInvalidUserSuppliedAttributeList() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToJSON());
//Attribute list CANNOT be empty
testRunner.setProperty(AttributesToJSON.ATTRIBUTES_LIST, "");
-
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
FlowFile ff = session.create();
testRunner.enqueue(ff);
- testRunner.run();
+ assertThrows(AssertionError.class, () -> {
+ testRunner.run();
+ });
}
- @Test(expected = AssertionError.class)
- public void testInvalidIncludeCoreAttributesProperty() throws Exception {
+ @Test
+ public void testInvalidIncludeCoreAttributesProperty() {
final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToJSON());
testRunner.setProperty(AttributesToJSON.ATTRIBUTES_LIST, "val1,val2");
testRunner.setProperty(AttributesToJSON.DESTINATION, AttributesToJSON.DESTINATION_ATTRIBUTE);
@@ -69,7 +71,9 @@ public class TestAttributesToJSON {
FlowFile ff = session.create();
testRunner.enqueue(ff);
- testRunner.run();
+ assertThrows(AssertionError.class, () -> {
+ testRunner.run();
+ });
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestBase64EncodeContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestBase64EncodeContent.java
index eef4dbcc53..b63113d2db 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestBase64EncodeContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestBase64EncodeContent.java
@@ -23,8 +23,7 @@ import java.nio.file.Paths;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestBase64EncodeContent {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java
index a87581dfa4..0445f2bd8b 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCompressContent.java
@@ -20,14 +20,14 @@ import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestCompressContent {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestControlRate.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestControlRate.java
index dea87d97cf..fbecd767c4 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestControlRate.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestControlRate.java
@@ -17,7 +17,7 @@
package org.apache.nifi.processors.standard;
import static org.apache.nifi.processors.standard.ControlRate.MAX_FLOW_FILES_PER_BATCH;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Collections;
import java.util.HashMap;
@@ -27,7 +27,7 @@ import java.util.Map;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestControlRate {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertCharacterSet.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertCharacterSet.java
index fea0a4e4ec..d56bb00c2c 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertCharacterSet.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertCharacterSet.java
@@ -25,9 +25,9 @@ import java.util.Map;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static junit.framework.TestCase.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestConvertCharacterSet {
@@ -84,23 +84,17 @@ public class TestConvertCharacterSet {
runner.setProperty(ConvertCharacterSet.OUTPUT_CHARSET, "UTF-32");
runner.enqueue(Paths.get("src/test/resources/CharacterSetConversionSamples/Original.txt"));
- try {
+ assertThrows(AssertionError.class, () -> {
runner.run();
- fail("Should fail to validate config and fail to run the on trigger");
- } catch (AssertionError e){
- // Expect to fail assertion for passing a date to the character set validator
- }
-
+ });
runner.setProperty(ConvertCharacterSet.INPUT_CHARSET, "UTF-32");
runner.setProperty(ConvertCharacterSet.OUTPUT_CHARSET, "${anyAttribute(\"abc\", \"xyz\"):contains(\"bye\")}");
runner.enqueue(Paths.get("src/test/resources/CharacterSetConversionSamples/Original.txt"));
- try {
+
+ assertThrows(AssertionError.class, () -> {
runner.run();
- fail("Should fail to validate config and fail to run the on trigger");
- } catch (AssertionError e) {
- // Expect to fail assertion for passing a boolean to the character set validator
- }
+ });
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertJSONToSQL.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertJSONToSQL.java
index aa8eccd4c0..96e93080fa 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertJSONToSQL.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertJSONToSQL.java
@@ -16,7 +16,21 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.dbcp.DBCPService;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -30,31 +44,16 @@ import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
-import com.fasterxml.jackson.core.JsonGenerationException;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.nifi.controller.AbstractControllerService;
-import org.apache.nifi.dbcp.DBCPService;
-import org.apache.nifi.processor.exception.ProcessException;
-import org.apache.nifi.reporting.InitializationException;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_COUNT;
import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_ID;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestConvertJSONToSQL {
- @ClassRule
- public static TemporaryFolder folder = new TemporaryFolder();
+ private static final String DERBY_LOG_PROPERTY = "derby.stream.error.file";
/**
* Setting up Connection pooling is expensive operation.
@@ -62,11 +61,17 @@ public class TestConvertJSONToSQL {
*/
static protected DBCPService service;
- @BeforeClass
- public static void setupClass() throws ProcessException, SQLException {
- System.setProperty("derby.stream.error.file", "target/derby.log");
- final File tempDir = folder.getRoot();
- final File dbDir = new File(tempDir, "db");
+ @BeforeAll
+ public static void setupDerbyLog() throws ProcessException {
+ final File derbyLog = new File(getSystemTemporaryDirectory(), "derby.log");
+ derbyLog.deleteOnExit();
+ System.setProperty(DERBY_LOG_PROPERTY, derbyLog.getAbsolutePath());
+ }
+
+ @BeforeEach
+ public void setup() throws SQLException {
+ final File dbDir = new File(getEmptyDirectory(), "db");
+ dbDir.deleteOnExit();
service = new MockDBCPService(dbDir.getAbsolutePath());
final String createPersons = "CREATE TABLE PERSONS (id integer primary key, name varchar(100), code integer)";
try (final Connection conn = service.getConnection()) {
@@ -76,6 +81,11 @@ public class TestConvertJSONToSQL {
}
}
+ @AfterAll
+ public static void cleanupDerbyLog() {
+ System.clearProperty(DERBY_LOG_PROPERTY);
+ }
+
@Test
public void testInsert() throws InitializationException, ProcessException, SQLException, IOException {
final TestRunner runner = TestRunners.newTestRunner(ConvertJSONToSQL.class);
@@ -957,4 +967,13 @@ public class TestConvertJSONToSQL {
}
}
}
+
+ private File getEmptyDirectory() {
+ final String randomDirectory = String.format("%s-%s", getClass().getSimpleName(), UUID.randomUUID());
+ return Paths.get(getSystemTemporaryDirectory(), randomDirectory).toFile();
+ }
+
+ private static String getSystemTemporaryDirectory() {
+ return System.getProperty("java.io.tmpdir");
+ }
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertRecord.java
index 47477b04ca..189caecc98 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestConvertRecord.java
@@ -17,22 +17,8 @@
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.avro.file.DataFileStream;
import org.apache.avro.generic.GenericRecord;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.avro.AvroRecordSetWriter;
import org.apache.nifi.avro.NonCachingDatumReader;
import org.apache.nifi.csv.CSVReader;
@@ -49,18 +35,26 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import org.xerial.snappy.SnappyInputStream;
-public class TestConvertRecord {
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.HashMap;
+import java.util.Map;
- //Apparently pretty printing is not portable as these tests fail on windows
- @BeforeClass
- public static void setUpSuite() {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
- }
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Pretty-printing is not portable across operating systems")
+public class TestConvertRecord {
@Test
public void testSuccessfulConversion() throws InitializationException {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDebugFlow.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDebugFlow.java
index c718942fae..b209724a8a 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDebugFlow.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDebugFlow.java
@@ -21,19 +21,18 @@ import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.hamcrest.CoreMatchers;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestDebugFlow {
@@ -45,10 +44,7 @@ public class TestDebugFlow {
private final Map<Integer, Map<String, String>> attribs = new HashMap<>();
private Map<String, String> namesToContent = new HashMap<>();
- @Rule
- public final ExpectedException exception = ExpectedException.none();
-
- @Before
+ @BeforeEach
public void setup() throws IOException {
for (int n = 0; n < 6; n++) {
String filename = "testFile" + (n + 1) + ".txt";
@@ -207,9 +203,11 @@ public class TestDebugFlow {
runner.enqueue(contents.get(0).getBytes(), attribs.get(0));
- exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow"));
- exception.expectCause(CoreMatchers.isA(RuntimeException.class));
- runner.run(2);
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run(2);
+ });
+ assertInstanceOf(RuntimeException.class, e.getCause());
+ assertTrue(e.getMessage().contains("forced by org.apache.nifi.processors.standard.DebugFlow"));
}
@Test
@@ -220,9 +218,11 @@ public class TestDebugFlow {
runner.enqueue(contents.get(0).getBytes(), attribs.get(0));
- exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow"));
- exception.expectCause(CoreMatchers.isA(RuntimeException.class));
- runner.run(2);
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run(2);
+ });
+ assertInstanceOf(RuntimeException.class, e.getCause());
+ assertTrue(e.getMessage().contains("forced by org.apache.nifi.processors.standard.DebugFlow"));
}
@Test
@@ -233,9 +233,11 @@ public class TestDebugFlow {
runner.enqueue(contents.get(0).getBytes(), attribs.get(0));
- exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow"));
- exception.expectCause(CoreMatchers.isA(NullPointerException.class));
- runner.run(2);
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run(2);
+ });
+ assertInstanceOf(NullPointerException.class, e.getCause());
+ assertTrue(e.getMessage().contains("forced by org.apache.nifi.processors.standard.DebugFlow"));
}
@Test
@@ -254,9 +256,11 @@ public class TestDebugFlow {
runner.enqueue(contents.get(n).getBytes(), attribs.get(n));
}
- exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow"));
- exception.expectCause(CoreMatchers.isA(RuntimeException.class));
- runner.run(8);
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run(8);
+ });
+ assertInstanceOf(RuntimeException.class, e.getCause());
+ assertTrue(e.getMessage().contains("forced by org.apache.nifi.processors.standard.DebugFlow"));
}
@Test
@@ -302,9 +306,11 @@ public class TestDebugFlow {
runner.setProperty(DebugFlow.NO_FF_EXCEPTION_ITERATIONS, "1");
runner.assertValid();
- exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow"));
- exception.expectCause(CoreMatchers.isA(RuntimeException.class));
- runner.run(3);
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run(3);
+ });
+ assertInstanceOf(RuntimeException.class, e.getCause());
+ assertTrue(e.getMessage().contains("forced by org.apache.nifi.processors.standard.DebugFlow"));
}
@Test
@@ -313,9 +319,11 @@ public class TestDebugFlow {
runner.setProperty(DebugFlow.NO_FF_EXCEPTION_CLASS, "java.lang.RuntimeException");
runner.assertValid();
- exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow"));
- exception.expectCause(CoreMatchers.isA(RuntimeException.class));
- runner.run(3);
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run(3);
+ });
+ assertInstanceOf(RuntimeException.class, e.getCause());
+ assertTrue(e.getMessage().contains("forced by org.apache.nifi.processors.standard.DebugFlow"));
}
@Test
@@ -324,9 +332,11 @@ public class TestDebugFlow {
runner.setProperty(DebugFlow.NO_FF_EXCEPTION_CLASS, "java.lang.NullPointerException");
runner.assertValid();
- exception.expectMessage(CoreMatchers.containsString("forced by org.apache.nifi.processors.standard.DebugFlow"));
- exception.expectCause(CoreMatchers.isA(NullPointerException.class));
- runner.run(3);
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run(3);
+ });
+ assertInstanceOf(NullPointerException.class, e.getCause());
+ assertTrue(e.getMessage().contains("forced by org.apache.nifi.processors.standard.DebugFlow"));
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java
index 99c8ef511e..3eb7ace2bc 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDetectDuplicate.java
@@ -16,12 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.distributed.cache.client.Deserializer;
@@ -31,21 +25,19 @@ import org.apache.nifi.distributed.cache.client.Serializer;
import org.apache.nifi.logging.ComponentLog;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.state.MockStateManager;
-import org.apache.nifi.util.MockControllerServiceInitializationContext;
import org.apache.nifi.util.MockComponentLog;
+import org.apache.nifi.util.MockControllerServiceInitializationContext;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class TestDetectDuplicate {
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
- static {
- System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
- System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.io.nio", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.DetectDuplicate", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestDetectDuplicate", "debug");
- }
+public class TestDetectDuplicate {
@Test
public void testDuplicate() throws InitializationException {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDistributeLoad.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDistributeLoad.java
index 8de24e981b..6340f76da2 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDistributeLoad.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDistributeLoad.java
@@ -16,25 +16,16 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-
-import java.util.List;
-
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class TestDistributeLoad {
+import java.util.List;
- @BeforeClass
- public static void before() {
- System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
- System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.DistributeLoad", "debug");
- }
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class TestDistributeLoad {
@Test
public void testDefaultRoundRobin() {
@@ -79,43 +70,23 @@ public class TestDistributeLoad {
testRunner.setProperty("1", "5");
- try {
- testRunner.setProperty("1", "0");
- Assert.fail("Allows property '1' to be set to '0'");
- } catch (final AssertionError e) {
- // expected behavior
- }
+ testRunner.setProperty("1", "0");
+ testRunner.assertNotValid();
- try {
- testRunner.setProperty("1", "-1");
- Assert.fail("Allows property '1' to be set to '-1'");
- } catch (final AssertionError e) {
- // expected behavior
- }
+ testRunner.setProperty("1", "-1");
+ testRunner.assertNotValid();
testRunner.setProperty("1", "101");
testRunner.setProperty("100", "5");
- try {
- testRunner.setProperty("101", "5");
- Assert.fail("Allows property '101' to be set to '5'");
- } catch (final AssertionError e) {
- // expected behavior
- }
+ testRunner.setProperty("101", "5");
+ testRunner.assertNotValid();
- try {
- testRunner.setProperty("0", "5");
- Assert.fail("Allows property '0' to be set to '5'");
- } catch (final AssertionError e) {
- // expected behavior
- }
+ testRunner.setProperty("0", "5");
+ testRunner.assertNotValid();
- try {
- testRunner.setProperty("-1", "5");
- Assert.fail("Allows property '-1' to be set to '5'");
- } catch (final AssertionError e) {
- // expected behavior
- }
+ testRunner.setProperty("-1", "5");
+ testRunner.assertNotValid();
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDuplicateFlowFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDuplicateFlowFile.java
index 8a0b2efe78..963e1ae8af 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDuplicateFlowFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDuplicateFlowFile.java
@@ -19,7 +19,7 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java
index fec411d56f..a0fcb28588 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncodeContent.java
@@ -23,8 +23,7 @@ import java.nio.file.Paths;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestEncodeContent {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java
index 7dc66ce4b5..8cdb3b59b2 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java
@@ -16,25 +16,7 @@
*/
package org.apache.nifi.processors.standard;
-import static org.bouncycastle.openpgp.PGPUtil.getDecoderStream;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Paths;
-import java.security.Security;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.components.AllowableValue;
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.security.util.EncryptionMethod;
@@ -47,14 +29,31 @@ import org.apache.nifi.util.TestRunners;
import org.bouncycastle.bcpg.BCPGInputStream;
import org.bouncycastle.bcpg.SymmetricKeyEncSessionPacket;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Method;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+import static org.bouncycastle.openpgp.PGPUtil.getDecoderStream;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
public class TestEncryptContent {
private static final Logger logger = LoggerFactory.getLogger(TestEncryptContent.class);
@@ -71,12 +70,7 @@ public class TestEncryptContent {
return null;
}
- @BeforeClass
- public static void setUpSuite() {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
- }
-
- @Before
+ @BeforeEach
public void setUp() {
Security.addProvider(new BouncyCastleProvider());
}
@@ -290,8 +284,8 @@ public class TestEncryptContent {
final TestRunner testRunner = TestRunners.newTestRunner(new EncryptContent());
// Assert
- Assert.assertEquals("Decrypt should default to None", testRunner.getProcessor().getPropertyDescriptor(EncryptContent.KEY_DERIVATION_FUNCTION
- .getName()).getDefaultValue(), KeyDerivationFunction.NONE.name());
+ assertEquals(testRunner.getProcessor().getPropertyDescriptor(EncryptContent.KEY_DERIVATION_FUNCTION
+ .getName()).getDefaultValue(), KeyDerivationFunction.NONE.name(), "Decrypt should default to None");
}
@Test
@@ -338,13 +332,13 @@ public class TestEncryptContent {
results = pc.validate();
// Assert
- Assert.assertEquals(1, results.size());
+ assertEquals(1, results.size());
ValidationResult vr = (ValidationResult) results.toArray()[0];
String expectedResult = " encryption without a " + EncryptContent.PASSWORD.getDisplayName() + " requires both "
+ EncryptContent.PUBLIC_KEYRING.getDisplayName() + " and "
+ EncryptContent.PUBLIC_KEY_USERID.getDisplayName();
String message = "'" + vr.toString() + "' contains '" + expectedResult + "'";
- Assert.assertTrue(message, vr.toString().contains(expectedResult));
+ assertTrue(vr.toString().contains(expectedResult), message);
}
@Test
@@ -365,11 +359,11 @@ public class TestEncryptContent {
results = pc.validate();
// Assert
- Assert.assertEquals(1, results.size());
+ assertEquals(1, results.size());
ValidationResult vr = (ValidationResult) results.toArray()[0];
String expectedResult = "java.io.FileNotFoundException";
String message = "'" + vr.toString() + "' contains '" + expectedResult + "'";
- Assert.assertTrue(message, vr.toString().contains(expectedResult));
+ assertTrue(vr.toString().contains(expectedResult), message);
}
@Test
@@ -390,11 +384,11 @@ public class TestEncryptContent {
results = pc.validate();
// Assert
- Assert.assertEquals(1, results.size());
+ assertEquals(1, results.size());
ValidationResult vr = (ValidationResult) results.toArray()[0];
String expectedResult = " java.io.IOException: invalid header encountered";
String message = "'" + vr.toString() + "' contains '" + expectedResult + "'";
- Assert.assertTrue(message, vr.toString().contains(expectedResult));
+ assertTrue(vr.toString().contains(expectedResult), message);
}
@Test
@@ -415,11 +409,11 @@ public class TestEncryptContent {
results = pc.validate();
// Assert
- Assert.assertEquals(1, results.size());
+ assertEquals(1, results.size());
ValidationResult vr = (ValidationResult) results.toArray()[0];
String expectedResult = "PGPException: Could not find a public key with the given userId";
String message = "'" + vr.toString() + "' contains '" + expectedResult + "'";
- Assert.assertTrue(message, vr.toString().contains(expectedResult));
+ assertTrue(vr.toString().contains(expectedResult), message);
}
@Test
@@ -440,7 +434,7 @@ public class TestEncryptContent {
results = pc.validate();
// Assert
- Assert.assertEquals(0, results.size());
+ assertEquals(0, results.size());
}
@Test
@@ -467,9 +461,9 @@ public class TestEncryptContent {
final Set<String> EXPECTED_ERRORS = new HashSet<>();
EXPECTED_ERRORS.add(RAW_KEY_ERROR);
- Assert.assertEquals(results.toString(), EXPECTED_ERRORS.size(), results.size());
+ assertEquals(EXPECTED_ERRORS.size(), results.size(), results.toString());
for (final ValidationResult vr : results) {
- Assert.assertTrue(EXPECTED_ERRORS.contains(vr.toString()));
+ assertTrue(EXPECTED_ERRORS.contains(vr.toString()));
}
runner.enqueue(new byte[0]);
@@ -480,7 +474,7 @@ public class TestEncryptContent {
pc = (MockProcessContext) runner.getProcessContext();
results = pc.validate();
- Assert.assertEquals(results.toString(), 0, results.size());
+ assertEquals(0, results.size(), results.toString());
runner.removeProperty(EncryptContent.PASSWORD);
@@ -489,9 +483,9 @@ public class TestEncryptContent {
runner.enqueue(new byte[0]);
pc = (MockProcessContext) runner.getProcessContext();
results = pc.validate();
- Assert.assertEquals(1, results.size());
+ assertEquals(1, results.size());
for (final ValidationResult vr : results) {
- Assert.assertTrue(vr.toString().contains(
+ assertTrue(vr.toString().contains(
" encryption without a " + EncryptContent.PASSWORD.getDisplayName() + " requires both "
+ EncryptContent.PUBLIC_KEYRING.getDisplayName() + " and "
+ EncryptContent.PUBLIC_KEY_USERID.getDisplayName()));
@@ -509,9 +503,9 @@ public class TestEncryptContent {
runner.enqueue(new byte[0]);
pc = (MockProcessContext) runner.getProcessContext();
results = pc.validate();
- Assert.assertEquals(1, results.size());
+ assertEquals(1, results.size());
for (final ValidationResult vr : results) {
- Assert.assertTrue(vr.toString().contains(
+ assertTrue(vr.toString().contains(
" decryption without a " + EncryptContent.PASSWORD.getDisplayName() + " requires both "
+ EncryptContent.PRIVATE_KEYRING.getDisplayName() + " and "
+ EncryptContent.PRIVATE_KEYRING_PASSPHRASE.getDisplayName()));
@@ -522,9 +516,9 @@ public class TestEncryptContent {
runner.enqueue(new byte[0]);
pc = (MockProcessContext) runner.getProcessContext();
results = pc.validate();
- Assert.assertEquals(1, results.size());
+ assertEquals(1, results.size());
for (final ValidationResult vr : results) {
- Assert.assertTrue(vr.toString().contains(
+ assertTrue(vr.toString().contains(
" could not be opened with the provided " + EncryptContent.PRIVATE_KEYRING_PASSPHRASE.getDisplayName()));
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java
index 0a179a3289..35f57329cc 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java
@@ -22,13 +22,13 @@ import org.apache.nifi.state.MockStateManager;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestEnforceOrder {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java
index 6f11feeb68..79a07a8c5b 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateJsonPath.java
@@ -16,8 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -34,21 +32,23 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.StringUtils;
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.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
public class TestEvaluateJsonPath {
private static final Path JSON_SNIPPET = Paths.get("src/test/resources/TestJson/json-sample.json");
private static final Path XML_SNIPPET = Paths.get("src/test/resources/TestXml/xml-snippet.xml");
- @Test(expected = AssertionError.class)
+ @Test
public void testInvalidJsonPath() {
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE);
testRunner.setProperty("invalid.jsonPath", "$..");
- Assert.fail("An improper JsonPath expression was not detected as being invalid.");
+ testRunner.assertNotValid();
}
@Test
@@ -101,29 +101,22 @@ public class TestEvaluateJsonPath {
final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateJsonPath.REL_FAILURE).get(0);
}
- @Test(expected = AssertionError.class)
+ @Test
public void testInvalidConfiguration_destinationContent_twoPaths() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_CONTENT);
testRunner.setProperty("JsonPath1", "$[0]._id");
testRunner.setProperty("JsonPath2", "$[0].name");
- testRunner.enqueue(JSON_SNIPPET);
- testRunner.run();
-
- Assert.fail("Processor incorrectly ran with an invalid configuration of multiple paths specified as attributes for a destination of content.");
+ testRunner.assertNotValid();
}
- @Test(expected = AssertionError.class)
+ @Test
public void testInvalidConfiguration_invalidJsonPath_space() throws Exception {
final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_CONTENT);
testRunner.setProperty("JsonPath1", "$[0]. _id");
-
- testRunner.enqueue(JSON_SNIPPET);
- testRunner.run();
-
- Assert.fail("Processor incorrectly ran with an invalid configuration of multiple paths specified as attributes for a destination of content.");
+ testRunner.assertNotValid();
}
@Test
@@ -152,7 +145,7 @@ public class TestEvaluateJsonPath {
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
- Assert.assertEquals("Transferred flow file did not have the correct result", "54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathAttrKey));
+ assertEquals("54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathAttrKey), "Transferred flow file did not have the correct result");
}
@Test
@@ -174,8 +167,8 @@ public class TestEvaluateJsonPath {
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
- Assert.assertEquals("Transferred flow file did not have the correct result for id attribute", "54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathIdAttrKey));
- Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", "{\"first\":\"Shaffer\",\"last\":\"Pearson\"}", out.getAttribute(jsonPathNameAttrKey));
+ assertEquals("54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathIdAttrKey), "Transferred flow file did not have the correct result for id attribute");
+ assertEquals("{\"first\":\"Shaffer\",\"last\":\"Pearson\"}", out.getAttribute(jsonPathNameAttrKey), "Transferred flow file did not have the correct result for name attribute");
}
@Test
@@ -196,8 +189,8 @@ public class TestEvaluateJsonPath {
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
- Assert.assertEquals("Transferred flow file did not have the correct result for id attribute", "", out.getAttribute(jsonPathIdAttrKey));
- Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", "", out.getAttribute(jsonPathNameAttrKey));
+ assertEquals("", out.getAttribute(jsonPathIdAttrKey), "Transferred flow file did not have the correct result for id attribute");
+ assertEquals("", out.getAttribute(jsonPathNameAttrKey), "Transferred flow file did not have the correct result for name attribute");
}
@Test
@@ -218,8 +211,8 @@ public class TestEvaluateJsonPath {
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
- Assert.assertEquals("Transferred flow file did not have the correct result for id attribute", "54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathIdAttrKey));
- Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", StringUtils.EMPTY, out.getAttribute(jsonPathNameAttrKey));
+ assertEquals("54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathIdAttrKey), "Transferred flow file did not have the correct result for id attribute");
+ assertEquals(StringUtils.EMPTY, out.getAttribute(jsonPathNameAttrKey), "Transferred flow file did not have the correct result for name attribute");
}
@Test
@@ -338,10 +331,10 @@ public class TestEvaluateJsonPath {
assertEquals("String Value", validFieldValue);
String missingValue = output.getAttribute("missingField");
- assertEquals("Missing Value", "", missingValue);
+ assertEquals("", missingValue, "Missing Value");
String nullValue = output.getAttribute("nullField");
- assertEquals("Null Value", "", nullValue);
+ assertEquals("", nullValue, "Null Value");
}
@Test
@@ -377,10 +370,10 @@ public class TestEvaluateJsonPath {
assertEquals("String Value", validFieldValue);
String missingValue = output.getAttribute("missingField");
- assertEquals("Missing Value", "", missingValue);
+ assertEquals("", missingValue, "Missing Value");
String nullValue = output.getAttribute("nullField");
- assertEquals("Null Value", "null", nullValue);
+ assertEquals("null", nullValue, "Null Value");
}
@Test
@@ -400,6 +393,6 @@ public class TestEvaluateJsonPath {
testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
- Assert.assertNotNull("Transferred flow file did not have the correct result for id attribute", out.getAttribute(jsonPathControlCharKey));
+ assertNotNull(out.getAttribute(jsonPathControlCharKey), "Transferred flow file did not have the correct result for id attribute");
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java
index 5972caf8fc..fea47deaad 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteProcess.java
@@ -16,13 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.File;
import java.lang.reflect.Field;
import java.util.List;
@@ -34,8 +27,15 @@ import org.apache.nifi.util.LogMessage;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestExecuteProcess {
@@ -83,11 +83,9 @@ public class TestExecuteProcess {
assertEquals("", twoArgOneWholeQuotedArgOneEmptyArg.get(3));
}
- @Ignore // won't run under Windows
+ @DisabledOnOs(OS.WINDOWS)
@Test
public void testEcho() {
- System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "TRACE");
-
final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class);
runner.setProperty(ExecuteProcess.COMMAND, "echo");
runner.setProperty(ExecuteProcess.COMMAND_ARGUMENTS, "test-args");
@@ -113,20 +111,16 @@ public class TestExecuteProcess {
runner.run();
Thread.sleep(500);
ExecuteProcess processor = (ExecuteProcess) runner.getProcessor();
- try {
- Field executorF = ExecuteProcess.class.getDeclaredField("executor");
- executorF.setAccessible(true);
- ExecutorService executor = (ExecutorService) executorF.get(processor);
- assertTrue(executor.isShutdown());
- assertTrue(executor.isTerminated());
-
- Field processF = ExecuteProcess.class.getDeclaredField("externalProcess");
- processF.setAccessible(true);
- Process process = (Process) processF.get(processor);
- assertFalse(process.isAlive());
- } catch (Exception e) {
- fail();
- }
+ Field executorF = ExecuteProcess.class.getDeclaredField("executor");
+ executorF.setAccessible(true);
+ ExecutorService executor = (ExecutorService) executorF.get(processor);
+ assertTrue(executor.isShutdown());
+ assertTrue(executor.isTerminated());
+
+ Field processF = ExecuteProcess.class.getDeclaredField("externalProcess");
+ processF.setAccessible(true);
+ Process process = (Process) processF.get(processor);
+ assertFalse(process.isAlive());
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
if(!flowFiles.isEmpty()) {
@@ -242,8 +236,8 @@ public class TestExecuteProcess {
}
}
final List<LogMessage> warnMessages = runner.getLogger().getWarnMessages();
- assertEquals("If redirect error stream is false, " +
- "the output should be logged as a warning so that user can notice on bulletin.", expectedWarningMessages, warnMessages.size());
+ final String errorMsg = "If redirect error stream is false, the output should be logged as a warning so that user can notice on bulletin.";
+ assertEquals(expectedWarningMessages, warnMessages.size(), errorMsg);
final List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
assertEquals(0, succeeded.size());
}
@@ -267,8 +261,8 @@ public class TestExecuteProcess {
if (isCommandFailed(runner)) return;
final List<LogMessage> warnMessages = runner.getLogger().getWarnMessages();
- assertEquals("If redirect error stream is true " +
- "the output should be sent as a content of flow-file.", 0, warnMessages.size());
+ assertEquals(0, warnMessages.size(), "If redirect error stream is true " +
+ "the output should be sent as a content of flow-file.");
final List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
assertEquals(1, succeeded.size());
}
@@ -291,8 +285,8 @@ public class TestExecuteProcess {
if (isCommandFailed(runner)) return;
final List<LogMessage> warnMessages = runner.getLogger().getWarnMessages();
- assertEquals("If redirect error stream is true " +
- "the output should be sent as a content of flow-file.", 0, warnMessages.size());
+ assertEquals(0, warnMessages.size(), "If redirect error stream is true " +
+ "the output should be sent as a content of flow-file.");
final List<MockFlowFile> succeeded = runner.getFlowFilesForRelationship(ExecuteProcess.REL_SUCCESS);
assertEquals(1, succeeded.size());
assertTrue(new String(succeeded.get(0).toByteArray()).contains("DOES-NOT-EXIST"));
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
index 7227ce275f..b993587377 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
@@ -16,26 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.apache.avro.file.DataFileConstants;
import org.apache.avro.file.DataFileStream;
import org.apache.avro.generic.GenericDatumReader;
@@ -53,25 +33,37 @@ import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.util.db.AvroUtil;
import org.apache.nifi.util.db.SimpleCommerceDataSet;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class TestExecuteSQL {
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
- private static final Logger LOGGER;
+public class TestExecuteSQL {
- static {
- System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
- System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.io.nio", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.ExecuteSQL", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestExecuteSQL", "debug");
- LOGGER = LoggerFactory.getLogger(TestExecuteSQL.class);
- }
+ private final Logger LOGGER = LoggerFactory.getLogger(TestExecuteSQL.class);
final static String DB_LOCATION = "target/db";
@@ -99,15 +91,19 @@ public class TestExecuteSQL {
+ " from persons PER, products PRD, relationships REL"
+ " where PER.ID < ? AND REL.ID < ?";
-
- @BeforeClass
+ @BeforeAll
public static void setupClass() {
System.setProperty("derby.stream.error.file", "target/derby.log");
}
+ @AfterAll
+ public static void cleanupClass() {
+ System.clearProperty("derby.stream.error.file");
+ }
+
private TestRunner runner;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
final DBCPService dbcp = new DBCPServiceSimpleImpl();
final Map<String, String> dbcpProperties = new HashMap<>();
@@ -135,10 +131,12 @@ public class TestExecuteSQL {
runner.assertTransferCount(ExecuteSQL.REL_FAILURE, 0);
}
- @Test(expected = AssertionError.class)
+ @Test
public void testNoIncomingConnectionAndNoQuery() throws InitializationException {
runner.setIncomingConnection(false);
- runner.run();
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
@Test
@@ -549,7 +547,7 @@ public class TestExecuteSQL {
// Assert exception message has been put to flow file attribute
MockFlowFile failedFlowFile = runner.getFlowFilesForRelationship(ExecuteSQL.REL_FAILURE).get(0);
- Assert.assertEquals("java.sql.SQLException: test execute statement failed",failedFlowFile.getAttribute(ExecuteSQL.RESULT_ERROR_MESSAGE));
+ assertEquals("java.sql.SQLException: test execute statement failed", failedFlowFile.getAttribute(ExecuteSQL.RESULT_ERROR_MESSAGE));
}
public void invokeOnTrigger(final Integer queryTimeout, final String query, final boolean incomingFlowFile, final Map<String,String> attrs, final boolean setQueryProperty)
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java
index edf013f904..e58c7d744c 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java
@@ -36,10 +36,10 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.util.db.SimpleCommerceDataSet;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,10 +57,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
@@ -68,16 +69,7 @@ import static org.mockito.Mockito.when;
public class TestExecuteSQLRecord {
- private static final Logger LOGGER;
-
- static {
- System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
- System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.io.nio", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.ExecuteSQLRecord", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestExecuteSQLRecord", "debug");
- LOGGER = LoggerFactory.getLogger(TestExecuteSQLRecord.class);
- }
+ private final Logger LOGGER = LoggerFactory.getLogger(TestExecuteSQLRecord.class);;
final static String DB_LOCATION = "target/db";
@@ -106,14 +98,19 @@ public class TestExecuteSQLRecord {
+ " where PER.ID < ? AND REL.ID < ?";
- @BeforeClass
+ @BeforeAll
public static void setupClass() {
System.setProperty("derby.stream.error.file", "target/derby.log");
}
+ @AfterAll
+ public static void cleanupClass() {
+ System.clearProperty("derby.stream.error.file");
+ }
+
private TestRunner runner;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
final DBCPService dbcp = new DBCPServiceSimpleImpl("derby");
final Map<String, String> dbcpProperties = new HashMap<>();
@@ -149,10 +146,12 @@ public class TestExecuteSQLRecord {
runner.assertTransferCount(AbstractExecuteSQL.REL_FAILURE, 0);
}
- @Test(expected = AssertionError.class)
+ @Test
public void testNoIncomingConnectionAndNoQuery() throws InitializationException {
runner.setIncomingConnection(false);
- runner.run();
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
@Test
@@ -633,7 +632,7 @@ public class TestExecuteSQLRecord {
// Assert exception message has been put to flow file attribute
MockFlowFile failedFlowFile = runner.getFlowFilesForRelationship(AbstractExecuteSQL.REL_FAILURE).get(0);
- Assert.assertEquals("java.sql.SQLException: test execute statement failed", failedFlowFile.getAttribute(AbstractExecuteSQL.RESULT_ERROR_MESSAGE));
+ assertEquals("java.sql.SQLException: test execute statement failed", failedFlowFile.getAttribute(AbstractExecuteSQL.RESULT_ERROR_MESSAGE));
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java
index dfa5b811d4..a8a9e181ef 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java
@@ -16,9 +16,18 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.io.FileUtils;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.processors.standard.util.ArgumentUtils;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.io.File;
import java.io.FileOutputStream;
@@ -33,30 +42,12 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.nifi.components.PropertyDescriptor;
-import org.apache.nifi.expression.ExpressionLanguageScope;
-import org.apache.nifi.processors.standard.util.ArgumentUtils;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test only runs on *nix")
public class TestExecuteStreamCommand {
- @BeforeClass
- public static void init() {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
- System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
- System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.ExecuteStreamCommand", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.processors.standard.TestExecuteStreamCommand", "debug");
- }
@Test
public void testExecuteJar() throws Exception {
@@ -383,8 +374,7 @@ public class TestExecuteStreamCommand {
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray);
- assertTrue("TestIngestAndUpdate.jar should not have received anything to modify",
- Pattern.compile("target:ModifiedResult\r?\n$").matcher(result).find());
+ assertTrue(Pattern.compile("target:ModifiedResult\r?\n$").matcher(result).find(), "TestIngestAndUpdate.jar should not have received anything to modify");
}
@Test
@@ -417,33 +407,7 @@ public class TestExecuteStreamCommand {
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray);
- assertTrue("TestIngestAndUpdate.jar should not have received anything to modify",
- Pattern.compile("target:ModifiedResult\r?\n$").matcher(result).find());
- }
-
- // this is dependent on window with cygwin...so it's not enabled
- @Ignore
- @Test
- public void testExecuteTouch() throws Exception {
- File testFile = new File("target/test.txt");
- testFile.delete();
- File dummy = new File("src/test/resources/ExecuteCommand/1000bytes.txt");
- final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
- controller.enqueue(dummy.toPath());
- controller.enqueue(dummy.toPath());
- controller.enqueue(dummy.toPath());
- controller.enqueue(dummy.toPath());
- controller.enqueue(dummy.toPath());
- controller.setProperty(ExecuteStreamCommand.WORKING_DIR, "target/xx1");
- controller.setThreadCount(6);
- controller.setProperty(ExecuteStreamCommand.EXECUTION_COMMAND, "c:\\cygwin\\bin\\touch");
- controller.setProperty(ExecuteStreamCommand.EXECUTION_ARGUMENTS, "test.txt");
- controller.assertValid();
- controller.run(6);
- List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.OUTPUT_STREAM_RELATIONSHIP);
- assertEquals(5, flowFiles.size());
- assertEquals(0, flowFiles.get(0).getSize());
-
+ assertTrue(Pattern.compile("target:ModifiedResult\r?\n$").matcher(result).find(), "TestIngestAndUpdate.jar should not have received anything to modify");
}
@Test
@@ -466,9 +430,9 @@ public class TestExecuteStreamCommand {
byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray);
Set<String> dynamicEnvironmentVariables = new HashSet<>(Arrays.asList(result.split("\r?\n")));
- assertFalse("Should contain at least two environment variables starting with NIFI", dynamicEnvironmentVariables.size() < 2);
- assertTrue("NIFI_TEST_1 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"));
- assertTrue("NIFI_TEST_2 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"));
+ assertFalse(dynamicEnvironmentVariables.size() < 2, "Should contain at least two environment variables starting with NIFI");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"), "NIFI_TEST_1 environment variable is missing");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"), "NIFI_TEST_2 environment variable is missing");
}
@Test
@@ -503,13 +467,13 @@ public class TestExecuteStreamCommand {
byte[] byteArray = flowFiles.get(0).toByteArray();
String result = new String(byteArray);
Set<String> dynamicEnvironmentVariables = new HashSet<>(Arrays.asList(result.split("\r?\n")));
- assertFalse("Should contain at least two environment variables starting with NIFI", dynamicEnvironmentVariables.size() < 2);
- assertTrue("NIFI_TEST_1 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"));
- assertTrue("NIFI_TEST_2 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"));
+ assertFalse(dynamicEnvironmentVariables.size() < 2, "Should contain at least two environment variables starting with NIFI");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"), "NIFI_TEST_1 environment variable is missing");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"), "NIFI_TEST_2 environment variable is missing");
}
@Test
- public void testSmallEchoPutToAttribute() throws Exception {
+ public void testSmallEchoPutToAttribute() {
File dummy = new File("src/test/resources/hello.txt");
assertTrue(dummy.exists());
final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
@@ -540,7 +504,7 @@ public class TestExecuteStreamCommand {
}
@Test
- public void testSmallEchoPutToAttributeDynamicProperties() throws Exception {
+ public void testSmallEchoPutToAttributeDynamicProperties() {
File dummy = new File("src/test/resources/hello.txt");
assertTrue(dummy.exists());
final TestRunner controller = TestRunners.newTestRunner(ExecuteStreamCommand.class);
@@ -1004,8 +968,8 @@ public class TestExecuteStreamCommand {
controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP);
String result = flowFiles.get(0).getAttribute("executeStreamCommand.output");
- assertTrue("TestIngestAndUpdate.jar should not have received anything to modify",
- Pattern.compile("target:ModifiedResult\r?\n?").matcher(result).find());
+ assertTrue(Pattern.compile("target:ModifiedResult\r?\n?").matcher(result).find(),
+ "TestIngestAndUpdate.jar should not have received anything to modify");
}
@Test
@@ -1037,8 +1001,8 @@ public class TestExecuteStreamCommand {
controller.assertTransferCount(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP, 1);
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP);
String result = flowFiles.get(0).getAttribute("executeStreamCommand.output");
- assertTrue("TestIngestAndUpdate.jar should not have received anything to modify",
- Pattern.compile("target:ModifiedResult\r?\n?").matcher(result).find());
+ assertTrue(Pattern.compile("target:ModifiedResult\r?\n?").matcher(result).find(),
+ "TestIngestAndUpdate.jar should not have received anything to modify");
}
@Test
@@ -1060,9 +1024,9 @@ public class TestExecuteStreamCommand {
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP);
String result = flowFiles.get(0).getAttribute("executeStreamCommand.output");
Set<String> dynamicEnvironmentVariables = new HashSet<>(Arrays.asList(result.split("\r?\n")));
- assertFalse("Should contain at least two environment variables starting with NIFI", dynamicEnvironmentVariables.size() < 2);
- assertTrue("NIFI_TEST_1 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"));
- assertTrue("NIFI_TEST_2 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"));
+ assertFalse(dynamicEnvironmentVariables.size() < 2, "Should contain at least two environment variables starting with NIFI");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"), "NIFI_TEST_1 environment variable is missing");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"), "NIFI_TEST_2 environment variable is missing");
}
@Test
@@ -1096,9 +1060,9 @@ public class TestExecuteStreamCommand {
List<MockFlowFile> flowFiles = controller.getFlowFilesForRelationship(ExecuteStreamCommand.ORIGINAL_RELATIONSHIP);
String result = flowFiles.get(0).getAttribute("executeStreamCommand.output");
Set<String> dynamicEnvironmentVariables = new HashSet<>(Arrays.asList(result.split("\r?\n")));
- assertFalse("Should contain at least two environment variables starting with NIFI", dynamicEnvironmentVariables.size() < 2);
- assertTrue("NIFI_TEST_1 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"));
- assertTrue("NIFI_TEST_2 environment variable is missing", dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"));
+ assertFalse(dynamicEnvironmentVariables.size() < 2, "Should contain at least two environment variables starting with NIFI");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_1=testvalue1"), "NIFI_TEST_1 environment variable is missing");
+ assertTrue(dynamicEnvironmentVariables.contains("NIFI_TEST_2=testvalue2"), "NIFI_TEST_2 environment variable is missing");
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java
index 54969150c3..fa5bf5ead7 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java
@@ -20,8 +20,8 @@ package org.apache.nifi.processors.standard;
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.io.IOException;
import java.nio.file.Path;
@@ -34,7 +34,7 @@ public class TestExtractGrok {
private final static Path GROK_LOG_INPUT = Paths.get("src/test/resources/TestExtractGrok/apache.log");
private final static Path GROK_TEXT_INPUT = Paths.get("src/test/resources/TestExtractGrok/simple_text.log");
- @Before
+ @BeforeEach
public void init() {
testRunner = TestRunners.newTestRunner(ExtractGrok.class);
}
@@ -78,7 +78,7 @@ public class TestExtractGrok {
}
@Test
- public void testExtractGrokKeepEmptyCaptures() {
+ public void testExtractGrokKeepEmptyCaptures() {
String expression = "%{NUMBER}|%{NUMBER}";
testRunner.setProperty(ExtractGrok.GROK_EXPRESSION,expression);
testRunner.enqueue("-42");
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java
index 7a1696bd9e..2fe2903160 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractText.java
@@ -16,10 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Set;
import java.util.regex.Pattern;
@@ -27,14 +23,18 @@ import org.apache.nifi.processor.Relationship;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestExtractText {
final String SAMPLE_STRING = "foo\r\nbar1\r\nbar2\r\nbar3\r\nhello\r\nworld\r\n";
@Test
- public void testProcessor() throws Exception {
+ public void testProcessor() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
@@ -86,7 +86,7 @@ public class TestExtractText {
}
@Test
- public void testProcessorWithDotall() throws Exception {
+ public void testProcessorWithDotall() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
@@ -116,7 +116,7 @@ public class TestExtractText {
}
@Test
- public void testProcessorWithMultiline() throws Exception {
+ public void testProcessorWithMultiline() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
@@ -149,7 +149,7 @@ public class TestExtractText {
}
@Test
- public void testProcessorWithMultilineAndDotall() throws Exception {
+ public void testProcessorWithMultilineAndDotall() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
@@ -184,7 +184,7 @@ public class TestExtractText {
}
@Test
- public void testProcessorWithNoMatches() throws Exception {
+ public void testProcessorWithNoMatches() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
@@ -217,7 +217,7 @@ public class TestExtractText {
}
@Test
- public void testNoFlowFile() throws UnsupportedEncodingException {
+ public void testNoFlowFile() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.run();
testRunner.assertAllFlowFilesTransferred(ExtractText.REL_MATCH, 0);
@@ -225,7 +225,7 @@ public class TestExtractText {
}
@Test
- public void testMatchOutsideBuffer() throws Exception {
+ public void testMatchOutsideBuffer() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ExtractText.MAX_BUFFER_SIZE, "3 B");//only read the first 3 chars ("foo")
@@ -308,7 +308,7 @@ public class TestExtractText {
}
@Test
- public void testGetRelationShips() throws Exception {
+ public void testGetRelationShips() {
final ExtractText processor = new ExtractText();
final TestRunner testRunner = TestRunners.newTestRunner(processor);
@@ -323,7 +323,7 @@ public class TestExtractText {
}
@Test
- public void testIncludeZeroCaptureGroupProperty() throws Exception {
+ public void testIncludeZeroCaptureGroupProperty() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
final String attributeKey = "regex.result";
@@ -342,7 +342,7 @@ public class TestExtractText {
}
@Test
- public void testFindAll() throws Exception {
+ public void testFindAll() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ExtractText.ENABLE_REPEATING_CAPTURE_GROUP, "true");
final String attributeKey = "regex.result";
@@ -366,7 +366,7 @@ public class TestExtractText {
}
@Test
- public void testFindAllPair() throws Exception {
+ public void testFindAllPair() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ExtractText.ENABLE_REPEATING_CAPTURE_GROUP, "true");
final String attributeKey = "regex.result";
@@ -395,7 +395,7 @@ public class TestExtractText {
}
@Test
- public void testIgnoreZeroCaptureGroupProperty() throws Exception {
+ public void testIgnoreZeroCaptureGroupProperty() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ExtractText.INCLUDE_CAPTURE_GROUP_ZERO, "false");
@@ -416,7 +416,7 @@ public class TestExtractText {
}
@Test
- public void testShouldAllowNoCaptureGroups() throws Exception {
+ public void testShouldAllowNoCaptureGroups() {
// Arrange
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
final String attributeKey = "regex.result";
@@ -435,8 +435,8 @@ public class TestExtractText {
out.assertAttributeEquals(attributeKey + ".0", SAMPLE_STRING);
}
- @Test(expected = java.lang.AssertionError.class)
- public void testShouldNotAllowNoCaptureGroupsIfZeroDisabled() throws Exception {
+ @Test
+ public void testShouldNotAllowNoCaptureGroupsIfZeroDisabled() {
// Arrange
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ExtractText.INCLUDE_CAPTURE_GROUP_ZERO, "false");
@@ -447,6 +447,8 @@ public class TestExtractText {
testRunner.enqueue(SAMPLE_STRING.getBytes(StandardCharsets.UTF_8));
// Validation should fail because nothing will match
- testRunner.run();
+ assertThrows(AssertionError.class, () -> {
+ testRunner.run();
+ });
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractTextNamedGroups.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractTextNamedGroups.java
index 9be1c471bd..88902d08b2 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractTextNamedGroups.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractTextNamedGroups.java
@@ -16,22 +16,22 @@
*/
package org.apache.nifi.processors.standard;
-import static org.apache.nifi.processors.standard.ExtractText.ENABLE_NAMED_GROUPS;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.apache.nifi.processors.standard.ExtractText.ENABLE_NAMED_GROUPS;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestExtractTextNamedGroups {
final String SAMPLE_STRING = "foo\r\nbar1\r\nbar2\r\nbar3\r\nhello\r\nworld\r\n";
@Test
- public void testProcessor() throws Exception {
+ public void testProcessor() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
@@ -82,7 +82,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testProcessorWithDotall() throws Exception {
+ public void testProcessorWithDotall() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -113,7 +113,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testProcessorWithMultiline() throws Exception {
+ public void testProcessorWithMultiline() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -147,7 +147,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testProcessorWithMultilineAndDotall() throws Exception {
+ public void testProcessorWithMultilineAndDotall() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -183,7 +183,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testProcessorWithNoMatches() throws Exception {
+ public void testProcessorWithNoMatches() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -217,7 +217,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testNoFlowFile() throws UnsupportedEncodingException {
+ public void testNoFlowFile() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
testRunner.run();
@@ -226,7 +226,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testMatchOutsideBuffer() throws Exception {
+ public void testMatchOutsideBuffer() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -246,7 +246,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testIncludeZeroCaptureGroupProperty() throws Exception {
+ public void testIncludeZeroCaptureGroupProperty() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -268,7 +268,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testFindAll() throws Exception {
+ public void testFindAll() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
testRunner.setProperty(ExtractText.ENABLE_REPEATING_CAPTURE_GROUP, "true");
@@ -292,7 +292,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testFindAllPair() throws Exception {
+ public void testFindAllPair() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
testRunner.setProperty(ExtractText.ENABLE_REPEATING_CAPTURE_GROUP, "true");
@@ -322,7 +322,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testIgnoreZeroCaptureGroupProperty() throws Exception {
+ public void testIgnoreZeroCaptureGroupProperty() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -344,7 +344,7 @@ public class TestExtractTextNamedGroups {
}
@Test
- public void testShouldAllowNoCaptureGroups() throws Exception {
+ public void testShouldAllowNoCaptureGroups() {
// Arrange
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -364,8 +364,8 @@ public class TestExtractTextNamedGroups {
out.assertAttributeEquals(attributeKey , SAMPLE_STRING);
}
- @Test(expected = AssertionError.class)
- public void testShouldNotAllowNoCaptureGroupsIfZeroDisabled() throws Exception {
+ @Test
+ public void testShouldNotAllowNoCaptureGroupsIfZeroDisabled() {
// Arrange
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -377,10 +377,12 @@ public class TestExtractTextNamedGroups {
testRunner.enqueue(SAMPLE_STRING.getBytes(StandardCharsets.UTF_8));
// Validation should fail because nothing will match
- testRunner.run();
+ assertThrows(AssertionError.class, () -> {
+ testRunner.run();
+ });
}
- @Test(expected = AssertionError.class)
+ @Test
public void testInvalidIfGroupCountsDoNotMatch() {
final TestRunner testRunner = TestRunners.newTestRunner(new ExtractText());
testRunner.setProperty(ENABLE_NAMED_GROUPS, "true");
@@ -392,6 +394,8 @@ public class TestExtractTextNamedGroups {
testRunner.enqueue("beginning middle end".getBytes(StandardCharsets.UTF_8));
// Validation should fail because number of groups does not match number of named groups
- testRunner.run();
+ assertThrows(AssertionError.class, () -> {
+ testRunner.run();
+ });
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java
index ee8cfe9a40..cb405d31b2 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java
@@ -16,16 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.processor.ProcessContext;
@@ -36,7 +26,6 @@ import org.apache.nifi.util.MockProcessContext;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
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.junit.jupiter.api.condition.EnabledIfSystemProperty;
@@ -48,6 +37,17 @@ import org.mockftpserver.fake.filesystem.FileSystem;
import org.mockftpserver.fake.filesystem.Permissions;
import org.mockftpserver.fake.filesystem.WindowsFakeFileSystem;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class TestFTP {
private static final String LOCALHOST_ADDRESS = "127.0.0.1";
@@ -145,7 +145,7 @@ public class TestFTP {
FileSystem results = fakeFtpServer.getFileSystem();
// Check file was uploaded
- Assertions.assertTrue(results.exists("c:\\data\\randombytes-1"));
+ assertTrue(results.exists("c:\\data\\randombytes-1"));
}
@Test
@@ -208,7 +208,7 @@ public class TestFTP {
results.add(sampleFile);
// Check file exists
- Assertions.assertTrue(results.exists("c:\\data\\randombytes-2"));
+ assertTrue(results.exists("c:\\data\\randombytes-2"));
TestRunner runner = TestRunners.newTestRunner(GetFTP.class);
runner.setProperty(FTPTransfer.HOSTNAME, LOCALHOST_ADDRESS);
@@ -232,7 +232,7 @@ public class TestFTP {
results.add(sampleFile);
// Check file exists
- Assertions.assertTrue(results.exists("c:\\data\\randombytes-2"));
+ assertTrue(results.exists("c:\\data\\randombytes-2"));
TestRunner runner = TestRunners.newTestRunner(FetchFTP.class);
runner.setProperty(FetchFTP.HOSTNAME, "${host}");
@@ -353,7 +353,7 @@ public class TestFTP {
results.add(sampleFile);
// Check file exists
- Assertions.assertTrue(results.exists("c:\\data\\randombytes-2"));
+ assertTrue(results.exists("c:\\data\\randombytes-2"));
TestRunner runner = TestRunners.newTestRunner(ListFTP.class);
runner.setProperty(ListFTP.HOSTNAME, LOCALHOST_ADDRESS);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchDistributedMapCache.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchDistributedMapCache.java
index 4c2d9917b6..686d913754 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchDistributedMapCache.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchDistributedMapCache.java
@@ -24,8 +24,8 @@ import org.apache.nifi.reporting.InitializationException;
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.io.IOException;
import java.util.ArrayList;
@@ -42,10 +42,9 @@ public class TestFetchDistributedMapCache {
private TestRunner runner;
private MockCacheClient service;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(FetchDistributedMapCache.class);
-
service = new MockCacheClient();
runner.addControllerService("service", service);
runner.enableControllerService(service);
@@ -53,7 +52,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testNoCacheKey() throws InitializationException {
+ public void testNoCacheKey() {
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "${cacheKeyAttribute}");
@@ -70,8 +69,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testNoCacheKeyValue() throws InitializationException {
-
+ public void testNoCacheKeyValue() {
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "${cacheKeyAttribute}");
runner.enqueue(new byte[] {});
runner.run();
@@ -83,7 +81,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testFailingCacheService() throws InitializationException, IOException {
+ public void testFailingCacheService() {
service.setFailOnCalls(true);
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "${cacheKeyAttribute}");
@@ -100,7 +98,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testSingleFlowFile() throws InitializationException, IOException {
+ public void testSingleFlowFile() throws IOException {
service.put("key","value", new FetchDistributedMapCache.StringSerializer(), new FetchDistributedMapCache.StringSerializer());
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "${cacheKeyAttribute}");
@@ -121,7 +119,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testSingleFlowFileToAttribute() throws InitializationException, IOException {
+ public void testSingleFlowFileToAttribute() throws IOException {
service.put("key","value", new FetchDistributedMapCache.StringSerializer(), new FetchDistributedMapCache.StringSerializer());
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "${cacheKeyAttribute}");
runner.setProperty(FetchDistributedMapCache.PROP_PUT_CACHE_VALUE_IN_ATTRIBUTE, "test");
@@ -143,7 +141,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testToAttributeTooLong() throws InitializationException, IOException {
+ public void testToAttributeTooLong() throws IOException {
service.put("key","value", new FetchDistributedMapCache.StringSerializer(), new FetchDistributedMapCache.StringSerializer());
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "${cacheKeyAttribute}");
runner.setProperty(FetchDistributedMapCache.PROP_PUT_CACHE_VALUE_IN_ATTRIBUTE, "test");
@@ -165,7 +163,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testMultipleKeysToAttributes() throws InitializationException, IOException {
+ public void testMultipleKeysToAttributes() throws IOException {
service.put("key1","value1", new FetchDistributedMapCache.StringSerializer(), new FetchDistributedMapCache.StringSerializer());
service.put("key2","value2", new FetchDistributedMapCache.StringSerializer(), new FetchDistributedMapCache.StringSerializer());
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "key1, key2");
@@ -188,7 +186,7 @@ public class TestFetchDistributedMapCache {
}
@Test
- public void testMultipleKeysOneNotFound() throws InitializationException, IOException {
+ public void testMultipleKeysOneNotFound() throws IOException {
service.put("key1","value1", new FetchDistributedMapCache.StringSerializer(), new FetchDistributedMapCache.StringSerializer());
runner.setProperty(FetchDistributedMapCache.PROP_CACHE_ENTRY_IDENTIFIER, "key1, key2");
// Not valid to set multiple keys without Put Cache Value In Attribute set
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java
index 5136e64d5b..5f636880ec 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java
@@ -17,22 +17,6 @@
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.Mockito.when;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.commons.net.ftp.FTPClient;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.context.PropertyContext;
@@ -48,17 +32,33 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
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 org.mockito.Mockito;
import org.mockito.stubbing.Answer;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+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.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
public class TestFetchFTP {
private TestableFetchFTP proc;
private TestRunner runner;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
proc = new TestableFetchFTP();
runner = TestRunners.newTestRunner(proc);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
index c50b4f6db8..79641d255a 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFile.java
@@ -17,9 +17,12 @@
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.io.File;
import java.io.IOException;
@@ -27,22 +30,14 @@ import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test only runs on *nix")
public class TestFetchFile {
- @BeforeClass
- public static void setUpSuite() {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
- }
-
- @Before
+ @BeforeEach
public void prepDestDirectory() throws IOException {
final File targetDir = new File("target/move-target");
if (!targetDir.exists()) {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java
index b61bb0ced0..00589d2a08 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java
@@ -17,7 +17,6 @@
package org.apache.nifi.processors.standard;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.json.JsonRecordSetWriter;
@@ -39,9 +38,9 @@ import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assume;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.io.File;
import java.io.IOException;
@@ -52,6 +51,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Pretty printing is not portable as these fail on windows")
public class TestForkRecord {
private final String dateFormat = RecordFieldType.DATE.getDefaultFormat();
@@ -96,12 +96,6 @@ public class TestForkRecord {
return new SimpleRecordSchema(transactionFields);
}
- //Pretty printing is not portable as these fail on windows
- @BeforeClass
- public static void setUpSuite() {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
- }
-
@Test
public void testForkExtractSimpleWithoutParentFields() throws IOException, MalformedRecordException, InitializationException {
TestRunner runner = TestRunners.newTestRunner(new ForkRecord());
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java
index 9a22d61d3e..138cb682a9 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java
@@ -16,12 +16,10 @@
*/
package org.apache.nifi.processors.standard;
-import java.io.IOException;
-
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Unit tests for the GenerateFlowFile processor.
@@ -29,7 +27,7 @@ import org.junit.Test;
public class TestGenerateFlowFile {
@Test
- public void testGenerateCustomText() throws IOException {
+ public void testGenerateCustomText() {
TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "100MB");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_TEXT);
@@ -44,7 +42,7 @@ public class TestGenerateFlowFile {
}
@Test
- public void testInvalidCustomText() throws IOException {
+ public void testInvalidCustomText() {
TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "100MB");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_BINARY);
@@ -57,7 +55,7 @@ public class TestGenerateFlowFile {
}
@Test
- public void testDynamicPropertiesToAttributes() throws IOException {
+ public void testDynamicPropertiesToAttributes() {
TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "1B");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_TEXT);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java
index 1f4494f6fc..11a209997f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java
@@ -30,10 +30,10 @@ import org.apache.nifi.util.MockSessionFactory;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.util.file.FileUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -55,10 +55,10 @@ import static org.apache.nifi.processors.standard.AbstractDatabaseFetchProcessor
import static org.apache.nifi.processors.standard.AbstractDatabaseFetchProcessor.FRAGMENT_ID;
import static org.apache.nifi.processors.standard.AbstractDatabaseFetchProcessor.FRAGMENT_INDEX;
import static org.apache.nifi.processors.standard.AbstractDatabaseFetchProcessor.REL_SUCCESS;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
@@ -77,8 +77,8 @@ public class TestGenerateTableFetch {
private final static String DB_LOCATION = "target/db_gtf";
- @BeforeClass
- public static void setupBeforeClass() throws IOException {
+ @BeforeAll
+ public static void setupBeforeClass() {
System.setProperty("derby.stream.error.file", "target/derby.log");
// remove previous test database, if any
@@ -90,7 +90,7 @@ public class TestGenerateTableFetch {
}
}
- @AfterClass
+ @AfterAll
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
@@ -104,9 +104,11 @@ public class TestGenerateTableFetch {
} catch (IOException ioe) {
// Do nothing, may not have existed
}
+
+ System.clearProperty("derby.stream.error.file");
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
processor = new GenerateTableFetch();
//Mock the DBCP Controller Service so we can control the Results
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java
index bfa075ad0f..7af5b57798 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetFile.java
@@ -20,7 +20,7 @@ import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -33,9 +33,8 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestGetFile {
@@ -43,7 +42,7 @@ public class TestGetFile {
public void testFilePickedUp() throws IOException {
final File directory = new File("target/test/data/in");
deleteDirectory(directory);
- assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs());
+ assertTrue(directory.exists() || directory.mkdirs(), "Unable to create test data directory " + directory.getAbsolutePath());
final File inFile = new File("src/test/resources/hello.txt");
final Path inPath = inFile.toPath();
@@ -67,14 +66,14 @@ public class TestGetFile {
assertEquals(absTargetPathStr, absolutePath);
}
- private void deleteDirectory(final File directory) throws IOException {
+ private void deleteDirectory(final File directory) {
if (directory != null && directory.exists()) {
for (final File file : directory.listFiles()) {
if (file.isDirectory()) {
deleteDirectory(file);
}
- assertTrue("Could not delete " + file.getAbsolutePath(), file.delete());
+ assertTrue(file.delete(), "Could not delete " + file.getAbsolutePath());
}
}
}
@@ -86,7 +85,7 @@ public class TestGetFile {
final File directory = new File("target/test/data/in/" + dirStruc);
deleteDirectory(directory);
- assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs());
+ assertTrue(directory.exists() || directory.mkdirs(), "Unable to create test data directory " + directory.getAbsolutePath());
final File inFile = new File("src/test/resources/hello.txt");
final Path inPath = inFile.toPath();
@@ -110,7 +109,7 @@ public class TestGetFile {
final File directory = new File("target/test/data/in/" + dirStruc);
deleteDirectory(new File("target/test/data/in"));
- assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs());
+ assertTrue(directory.exists() || directory.mkdirs(), "Unable to create test data directory " + directory.getAbsolutePath());
final File inFile = new File("src/test/resources/hello.txt");
final Path inPath = inFile.toPath();
@@ -135,10 +134,10 @@ public class TestGetFile {
}
@Test
- public void testAttributes() throws IOException {
+ public void testAttributes() throws IOException, ParseException {
final File directory = new File("target/test/data/in/");
deleteDirectory(directory);
- assertTrue("Unable to create test data directory " + directory.getAbsolutePath(), directory.exists() || directory.mkdirs());
+ assertTrue(directory.exists() || directory.mkdirs(), "Unable to create test data directory " + directory.getAbsolutePath());
final File inFile = new File("src/test/resources/hello.txt");
final Path inPath = inFile.toPath();
@@ -161,13 +160,9 @@ public class TestGetFile {
final List<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(GetFile.REL_SUCCESS);
if (verifyLastModified) {
- try {
- final DateFormat formatter = new SimpleDateFormat(GetFile.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US);
- final Date fileModifyTime = formatter.parse(successFiles.get(0).getAttribute("file.lastModifiedTime"));
- assertEquals(new Date(1000000000), fileModifyTime);
- } catch (ParseException e) {
- fail();
- }
+ final DateFormat formatter = new SimpleDateFormat(GetFile.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US);
+ final Date fileModifyTime = formatter.parse(successFiles.get(0).getAttribute("file.lastModifiedTime"));
+ assertEquals(new Date(1000000000), fileModifyTime);
}
//permissions are not verified as these are very environmentally specific
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetJMSQueue.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetJMSQueue.java
index 911b74d0b3..2f701d76dd 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetJMSQueue.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetJMSQueue.java
@@ -16,16 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertTrue;
-
-import java.util.List;
-import javax.jms.BytesMessage;
-import javax.jms.MapMessage;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
-import javax.jms.StreamMessage;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processors.standard.util.JmsFactory;
import org.apache.nifi.processors.standard.util.JmsProperties;
@@ -33,8 +23,16 @@ import org.apache.nifi.processors.standard.util.WrappedMessageProducer;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.apache.nifi.web.Revision;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import javax.jms.BytesMessage;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.StreamMessage;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
@SuppressWarnings("deprecation")
public class TestGetJMSQueue {
@@ -69,7 +67,7 @@ public class TestGetJMSQueue {
List<MockFlowFile> flowFiles = runner
.getFlowFilesForRelationship(new Relationship.Builder().name("success").build());
- assertTrue(flowFiles.size() == 1);
+ assertEquals(1, flowFiles.size());
MockFlowFile successFlowFile = flowFiles.get(0);
successFlowFile.assertContentEquals("Hello World");
successFlowFile.assertAttributeEquals("jms.JMSDestination", "queue.testing");
@@ -107,7 +105,7 @@ public class TestGetJMSQueue {
List<MockFlowFile> flowFiles = runner
.getFlowFilesForRelationship(new Relationship.Builder().name("success").build());
- assertTrue(flowFiles.size() == 1);
+ assertEquals(1, flowFiles.size());
MockFlowFile successFlowFile = flowFiles.get(0);
successFlowFile.assertContentEquals("Hello Bytes");
successFlowFile.assertAttributeEquals("jms.JMSDestination", "queue.testing");
@@ -146,7 +144,7 @@ public class TestGetJMSQueue {
List<MockFlowFile> flowFiles = runner
.getFlowFilesForRelationship(new Relationship.Builder().name("success").build());
- assertTrue(flowFiles.size() == 1);
+ assertEquals(1, flowFiles.size());
MockFlowFile successFlowFile = flowFiles.get(0);
successFlowFile.assertContentEquals("Hello Stream");
successFlowFile.assertAttributeEquals("jms.JMSDestination", "queue.testing");
@@ -154,47 +152,4 @@ public class TestGetJMSQueue {
producer.close();
jmsSession.close();
}
-
- @org.junit.Ignore
- public void testSendMapToQueue() throws Exception {
- final TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class);
- runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
- runner.setProperty(JmsProperties.URL, "tcp://localhost:61616");
- runner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE);
- runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
- runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);
- WrappedMessageProducer wrappedProducer = JmsFactory.createMessageProducer(runner.getProcessContext(), true);
- final Session jmsSession = wrappedProducer.getSession();
- final MessageProducer producer = wrappedProducer.getProducer();
-
- final MapMessage message = jmsSession.createMapMessage();
- message.setString("foo!", "bar");
- message.setString("bacon", "meat");
-
- producer.send(message);
- jmsSession.commit();
- producer.close();
- jmsSession.close();
- }
-
- @org.junit.Ignore
- public void testSendObjectToQueue() throws Exception {
- final TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class);
- runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
- runner.setProperty(JmsProperties.URL, "tcp://localhost:61616");
- runner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE);
- runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
- runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);
- WrappedMessageProducer wrappedProducer = JmsFactory.createMessageProducer(runner.getProcessContext(), true);
- final Session jmsSession = wrappedProducer.getSession();
- final MessageProducer producer = wrappedProducer.getProducer();
-
- // Revision class is used because test just needs any Serializable class in core NiFi
- final ObjectMessage message = jmsSession.createObjectMessage(new Revision(1L, "ID", "COMP_ID"));
-
- producer.send(message);
- jmsSession.commit();
- producer.close();
- jmsSession.close();
- }
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetSFTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetSFTP.java
index 79d57cd58a..0e935eadd7 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetSFTP.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGetSFTP.java
@@ -21,34 +21,36 @@ import org.apache.nifi.processors.standard.util.SFTPTransfer;
import org.apache.nifi.processors.standard.util.SSHTestServer;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class TestGetSFTP {
private TestRunner getSFTPRunner;
private static SSHTestServer sshTestServer;
- @BeforeClass
+ @BeforeAll
public static void setupSSHD() throws IOException {
sshTestServer = new SSHTestServer();
sshTestServer.startServer();
}
- @AfterClass
+ @AfterAll
public static void cleanupSSHD() throws IOException {
sshTestServer.stopServer();
}
- @Before
+ @BeforeEach
public void setup(){
getSFTPRunner = TestRunners.newTestRunner(GetSFTP.class);
getSFTPRunner.setProperty(SFTPTransfer.HOSTNAME, "localhost");
@@ -86,7 +88,7 @@ public class TestGetSFTP {
//Verify files deleted
for(int i=1;i<5;i++){
Path file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/testFile" + i + ".txt");
- Assert.assertFalse("File not deleted.", file1.toAbsolutePath().toFile().exists());
+ assertFalse(file1.toAbsolutePath().toFile().exists(), "File not deleted.");
}
getSFTPRunner.clearTransferState();
@@ -110,7 +112,7 @@ public class TestGetSFTP {
// Verify files deleted
for (int i = 1; i < 3; i++) {
Path file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/testFile" + i + ".txt");
- Assert.assertFalse("File not deleted.", file1.toAbsolutePath().toFile().exists());
+ assertFalse(file1.toAbsolutePath().toFile().exists(), "File not deleted.");
}
getSFTPRunner.clearTransferState();
@@ -136,16 +138,16 @@ public class TestGetSFTP {
//Verify non-dotted files were deleted and dotted files were not deleted
Path file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/testFile1.txt");
- Assert.assertFalse("File not deleted.", file1.toAbsolutePath().toFile().exists());
+ assertFalse(file1.toAbsolutePath().toFile().exists(), "File not deleted.");
file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/testFile3.txt");
- Assert.assertFalse("File not deleted.", file1.toAbsolutePath().toFile().exists());
+ assertFalse(file1.toAbsolutePath().toFile().exists(), "File not deleted.");
file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/.testFile2.txt");
- Assert.assertTrue("File deleted.", file1.toAbsolutePath().toFile().exists());
+ assertTrue(file1.toAbsolutePath().toFile().exists(), "File deleted.");
file1 = Paths.get(sshTestServer.getVirtualFileSystemPath() + "/.testFile4.txt");
- Assert.assertTrue("File deleted.", file1.toAbsolutePath().toFile().exists());
+ assertTrue(file1.toAbsolutePath().toFile().exists(), "File deleted.");
getSFTPRunner.clearTransferState();
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java
index a2d6b2816a..a629228ba5 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHandleHttpResponse.java
@@ -16,10 +16,23 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.http.HttpContextMap;
+import org.apache.nifi.processor.exception.FlowFileAccessException;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.standard.util.HTTPUtils;
+import org.apache.nifi.provenance.ProvenanceEventType;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import javax.servlet.AsyncContext;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.WriteListener;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.HashMap;
@@ -31,24 +44,10 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import javax.servlet.AsyncContext;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.WriteListener;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.nifi.controller.AbstractControllerService;
-import org.apache.nifi.http.HttpContextMap;
-import org.apache.nifi.processor.exception.FlowFileAccessException;
-import org.apache.nifi.processor.exception.ProcessException;
-import org.apache.nifi.processors.standard.util.HTTPUtils;
-import org.apache.nifi.provenance.ProvenanceEventType;
-import org.apache.nifi.reporting.InitializationException;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
public class TestHandleHttpResponse {
@@ -261,7 +260,7 @@ public class TestHandleHttpResponse {
@Override
public HttpServletResponse getResponse(final String identifier) {
if (!id.equals(identifier)) {
- Assert.fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier);
+ fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier);
}
try {
@@ -316,7 +315,7 @@ public class TestHandleHttpResponse {
return response;
} catch (final Exception e) {
e.printStackTrace();
- Assert.fail(e.toString());
+ fail(e.toString());
return null;
}
}
@@ -324,7 +323,7 @@ public class TestHandleHttpResponse {
@Override
public void complete(final String identifier) {
if (!id.equals(identifier)) {
- Assert.fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier);
+ fail("attempting to respond to wrong request; should have been " + id + " but was " + identifier);
}
if (completeException != null) {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java
index 2055f42c23..646aae6d05 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashAttribute.java
@@ -16,17 +16,18 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
public class TestHashAttribute {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java
index 2b4d16a61d..b5e0a2e9e6 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestHashContent.java
@@ -16,14 +16,15 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.nio.file.Paths;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
@SuppressWarnings("deprecation")
public class TestHashContent {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java
index c91d40c932..7eba16f16e 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java
@@ -16,7 +16,12 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.flowfile.attributes.StandardFlowFileMediaType;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -25,13 +30,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.nifi.flowfile.attributes.CoreAttributes;
-import org.apache.nifi.flowfile.attributes.StandardFlowFileMediaType;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestIdentifyMimeType {
@@ -107,8 +107,8 @@ public class TestIdentifyMimeType {
final String extension = file.getAttribute("mime.extension");
final String expectedExtension = expectedExtensions.get(filename);
- assertEquals("Expected " + file + " to have MIME Type " + expected + ", but it was " + mimeType, expected, mimeType);
- assertEquals("Expected " + file + " to have extension " + expectedExtension + ", but it was " + extension, expectedExtension, extension);
+ assertEquals(expected, mimeType, "Expected " + file + " to have MIME Type " + expected + ", but it was " + mimeType);
+ assertEquals(expectedExtension, extension, "Expected " + file + " to have extension " + expectedExtension + ", but it was " + extension);
}
}
@@ -220,8 +220,8 @@ public class TestIdentifyMimeType {
final String extension = file.getAttribute("mime.extension");
final String expectedExtension = expectedExtensions.get(filename);
- assertEquals("Expected " + file + " to have MIME Type " + expected + ", but it was " + mimeType, expected, mimeType);
- assertEquals("Expected " + file + " to have extension " + expectedExtension + ", but it was " + extension, expectedExtension, extension);
+ assertEquals(expected, mimeType, "Expected " + file + " to have MIME Type " + expected + ", but it was " + mimeType);
+ assertEquals(expectedExtension, extension, "Expected " + file + " to have extension " + expectedExtension + ", but it was " + extension);
}
}
@@ -303,13 +303,13 @@ public class TestIdentifyMimeType {
final String extension = file.getAttribute("mime.extension");
final String expectedExtension = expectedExtensions.get(filename);
- assertEquals("Expected " + file + " to have MIME Type " + expected + ", but it was " + mimeType, expected, mimeType);
- assertEquals("Expected " + file + " to have extension " + expectedExtension + ", but it was " + extension, expectedExtension, extension);
+ assertEquals(expected, mimeType, "Expected " + file + " to have MIME Type " + expected + ", but it was " + mimeType);
+ assertEquals(expectedExtension, extension, "Expected " + file + " to have extension " + expectedExtension + ", but it was " + extension);
}
}
- @Test(expected=AssertionError.class)
- public void testOnlyOneCustomMimeConfigSpecified() throws IOException {
+ @Test
+ public void testOnlyOneCustomMimeConfigSpecified() {
final TestRunner runner = TestRunners.newTestRunner(new IdentifyMimeType());
String configFile = "src/test/resources/TestIdentifyMimeType/.customConfig.xml";
@@ -319,8 +319,9 @@ public class TestIdentifyMimeType {
runner.setProperty(IdentifyMimeType.MIME_CONFIG_BODY, configBody);
runner.setThreadCount(1);
- runner.run();
-
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java
index 4cd0ac4094..cbf3c11cad 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJmsConsumer.java
@@ -16,15 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-import javax.jms.BytesMessage;
-import javax.jms.JMSException;
-import javax.jms.MapMessage;
-import javax.jms.TextMessage;
import org.apache.activemq.command.ActiveMQBytesMessage;
import org.apache.activemq.command.ActiveMQMapMessage;
import org.apache.activemq.command.ActiveMQTextMessage;
@@ -38,7 +29,17 @@ import org.apache.nifi.util.MockProcessContext;
import org.apache.nifi.util.MockProcessorInitializationContext;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import javax.jms.BytesMessage;
+import javax.jms.JMSException;
+import javax.jms.MapMessage;
+import javax.jms.TextMessage;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
*
@@ -66,11 +67,11 @@ public class TestJmsConsumer {
MapMessage mapMessage = createMapMessage();
Map<String, String> mapMessageValues = JmsConsumer.createMapMessageValues(mapMessage);
- assertEquals("", 4, mapMessageValues.size());
- assertEquals("", "Arnold", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "name"));
- assertEquals("", "97", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "age"));
- assertEquals("", "89686.564", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz"));
- assertEquals("", "true", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "good"));
+ assertEquals(4, mapMessageValues.size());
+ assertEquals("Arnold", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "name"));
+ assertEquals("97", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "age"));
+ assertEquals("89686.564", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz"));
+ assertEquals("true", mapMessageValues.get(JmsConsumer.MAP_MESSAGE_PREFIX + "good"));
}
/**
@@ -90,13 +91,13 @@ public class TestJmsConsumer {
JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, mapMessage, true, pic.getLogger());
- assertEquals("MapMessage should not create FlowFile content", 0, summary.getBytesReceived());
+ assertEquals(0, summary.getBytesReceived(), "MapMessage should not create FlowFile content");
Map<String, String> attributes = summary.getLastFlowFile().getAttributes();
- assertEquals("", "Arnold", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "name"));
- assertEquals("", "97", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "age"));
- assertEquals("", "89686.564", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz"));
- assertEquals("", "true", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "good"));
+ assertEquals("Arnold", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "name"));
+ assertEquals("97", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "age"));
+ assertEquals("89686.564", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "xyz"));
+ assertEquals("true", attributes.get(JmsConsumer.MAP_MESSAGE_PREFIX + "good"));
}
@Test
@@ -114,7 +115,7 @@ public class TestJmsConsumer {
JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, textMessage, true, pic.getLogger());
- assertEquals("TextMessage content length should equal to FlowFile content size", payload.length(), summary.getLastFlowFile().getSize());
+ assertEquals(payload.length(), summary.getLastFlowFile().getSize(), "TextMessage content length should equal to FlowFile content size");
final byte[] buffer = new byte[payload.length()];
runner.clearTransferState();
@@ -127,7 +128,7 @@ public class TestJmsConsumer {
});
String contentString = new String(buffer, "UTF-8");
- assertEquals("", payload, contentString);
+ assertEquals(payload, contentString);
}
/**
@@ -152,7 +153,7 @@ public class TestJmsConsumer {
JmsProcessingSummary summary = JmsConsumer.map2FlowFile(context, session, bytesMessage, true, pic.getLogger());
- assertEquals("BytesMessage content length should equal to FlowFile content size", payload.length, summary.getLastFlowFile().getSize());
+ assertEquals(payload.length, summary.getLastFlowFile().getSize(), "BytesMessage content length should equal to FlowFile content size");
final byte[] buffer = new byte[payload.length];
runner.clearTransferState();
@@ -165,7 +166,7 @@ public class TestJmsConsumer {
});
String contentString = new String(buffer, "UTF-8");
- assertEquals("", sourceString, contentString);
+ assertEquals(sourceString, contentString);
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoinEnrichment.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoinEnrichment.java
index 70568ec733..0f24c99255 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoinEnrichment.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoinEnrichment.java
@@ -33,7 +33,7 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.BufferedInputStream;
import java.io.File;
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java
index 7e68c6b74a..d79690c877 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestJoltTransformJSON.java
@@ -16,7 +16,16 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertTrue;
+import com.bazaarvoice.jolt.Diffy;
+import com.bazaarvoice.jolt.JsonUtils;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.StringUtils;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -28,17 +37,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import org.apache.nifi.flowfile.attributes.CoreAttributes;
-import org.apache.nifi.processor.Processor;
-import org.apache.nifi.processor.Relationship;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.StringUtils;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
-
-import com.bazaarvoice.jolt.Diffy;
-import com.bazaarvoice.jolt.JsonUtils;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestJoltTransformJSON {
@@ -55,11 +55,11 @@ public class TestJoltTransformJSON {
Set<Relationship> relationships = processor.getRelationships();
assertTrue(relationships.contains(JoltTransformJSON.REL_FAILURE));
assertTrue(relationships.contains(JoltTransformJSON.REL_SUCCESS));
- assertTrue(relationships.size() == 2);
+ assertEquals(2, relationships.size());
}
@Test
- public void testInvalidJOLTSpec() throws IOException {
+ public void testInvalidJOLTSpec() {
final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
final String spec = "[{}]";
runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
@@ -76,14 +76,14 @@ public class TestJoltTransformJSON {
}
@Test
- public void testSpecIsNotSet() throws IOException {
+ public void testSpecIsNotSet() {
final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR);
runner.assertNotValid();
}
@Test
- public void testSpecIsEmpty() throws IOException {
+ public void testSpecIsEmpty() {
final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
runner.setProperty(JoltTransformJSON.JOLT_SPEC, StringUtils.EMPTY);
runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SHIFTR);
@@ -91,7 +91,7 @@ public class TestJoltTransformJSON {
}
@Test
- public void testSpecNotRequired() throws IOException {
+ public void testSpecNotRequired() {
final TestRunner runner = TestRunners.newTestRunner(new JoltTransformJSON());
runner.setProperty(JoltTransformJSON.JOLT_TRANSFORM, JoltTransformJSON.SORTR);
runner.assertValid();
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java
index 21bbf3e07d..ff6692bf17 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java
@@ -24,10 +24,12 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.util.file.FileUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.io.File;
import java.io.IOException;
@@ -40,9 +42,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeFalse;
-
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Unit tests for ListDatabaseTables processor.
@@ -54,8 +54,8 @@ public class TestListDatabaseTables {
private final static String DB_LOCATION = "target/db_ldt";
- @BeforeClass
- public static void setupBeforeClass() throws IOException {
+ @BeforeAll
+ public static void setupBeforeClass() {
System.setProperty("derby.stream.error.file", "target/derby.log");
// remove previous test database, if any
@@ -67,7 +67,7 @@ public class TestListDatabaseTables {
}
}
- @AfterClass
+ @AfterAll
public static void cleanUpAfterClass() throws Exception {
try {
DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";shutdown=true");
@@ -81,9 +81,10 @@ public class TestListDatabaseTables {
} catch (IOException ioe) {
// Do nothing, may not have existed
}
+ System.clearProperty("derby.stream.error.file");
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
processor = new ListDatabaseTables();
final DBCPService dbcp = new DBCPServiceSimpleImpl();
@@ -181,9 +182,9 @@ public class TestListDatabaseTables {
"TEST_TABLE2,,APP,APP.TEST_TABLE2,TABLE,,0\n");
}
+ @DisabledOnOs(OS.WINDOWS)
@Test
public void testListTablesAfterRefresh() throws Exception {
- assumeFalse(isWindowsEnvironment());
// load test data to database
final Connection con = ((DBCPService) runner.getControllerService("dbcp")).getConnection();
Statement stmt = con.createStatement();
@@ -218,10 +219,9 @@ public class TestListDatabaseTables {
runner.assertTransferCount(ListDatabaseTables.REL_SUCCESS, 2);
}
+ @DisabledOnOs(OS.WINDOWS)
@Test
public void testListTablesMultipleRefresh() throws Exception {
- assumeFalse(isWindowsEnvironment());
-
// load test data to database
final Connection con = ((DBCPService) runner.getControllerService("dbcp")).getConnection();
Statement stmt = con.createStatement();
@@ -283,9 +283,4 @@ public class TestListDatabaseTables {
}
}
}
-
- private boolean isWindowsEnvironment() {
- return System.getProperty("os.name").toLowerCase().startsWith("windows");
- }
-
}
\ No newline at end of file
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java
index e10d23cd2c..6fba4bf4a5 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java
@@ -17,7 +17,6 @@
package org.apache.nifi.processors.standard;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.components.ConfigVerificationResult;
import org.apache.nifi.components.ConfigVerificationResult.Outcome;
import org.apache.nifi.components.PropertyDescriptor;
@@ -31,12 +30,11 @@ import org.apache.nifi.processors.standard.util.FileInfo;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import org.junit.runner.Description;
import java.io.File;
@@ -60,10 +58,12 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test only runs on *nix")
public class TestListFile {
private static boolean isMillisecondSupported = false;
@@ -83,7 +83,6 @@ public class TestListFile {
private Long age0millis, age1millis, age2millis, age3millis, age4millis, age5millis;
private String age0, age1, age2, age3, age4, age5;
- @Rule
public ListProcessorTestWatcher dumpState = new ListProcessorTestWatcher(
() -> {
try {
@@ -108,24 +107,22 @@ public class TestListFile {
}
};
- @BeforeClass
+ @BeforeAll
public static void setupClass() throws Exception {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
-
// This only has to be done once.
final File file = Files.createTempFile(Paths.get("target/"), "TestListFile", null).toFile();
file.setLastModified(325990917351L);
isMillisecondSupported = file.lastModified() % 1_000 > 0;
}
- @Before
+ @BeforeEach
public void setUp() throws Exception {
processor = new ListFile();
runner = TestRunners.newTestRunner(processor);
runner.setProperty(AbstractListProcessor.TARGET_SYSTEM_TIMESTAMP_PRECISION, AbstractListProcessor.PRECISION_SECONDS.getValue());
context = runner.getProcessContext();
deleteDirectory(testDir);
- assertTrue("Unable to create test data directory " + testDir.getAbsolutePath(), testDir.exists() || testDir.mkdirs());
+ assertTrue(testDir.exists() || testDir.mkdirs(), "Unable to create test data directory " + testDir.getAbsolutePath());
resetAges();
}
@@ -176,45 +173,6 @@ public class TestListFile {
}
- @Test
- @Ignore("Intended only for manual testing, as is very expensive to run as a unit test. Performs listing of 1,000,000 files (doesn't actually create the files, though - injects them in) to " +
- "ensure performance is not harmed")
- public void testPerformanceOnLargeListing() {
- final List<Path> paths = new ArrayList<>(1_000_000);
- final File base = new File("target");
-
- for (int firstLevel=0; firstLevel < 1000; firstLevel++) {
- final File dir = new File(base, String.valueOf(firstLevel));
-
- for (int secondLevel = 0; secondLevel < 1000; secondLevel++) {
- final File file = new File(dir, String.valueOf(secondLevel));
- paths.add(file.toPath());
- }
- }
-
- processor = new ListFile();
-
- runner = TestRunners.newTestRunner(processor);
- runner.setProperty(AbstractListProcessor.TARGET_SYSTEM_TIMESTAMP_PRECISION, AbstractListProcessor.PRECISION_SECONDS.getValue());
- runner.setProperty(ListFile.TRACK_PERFORMANCE, "true");
- runner.setProperty(ListFile.MAX_TRACKED_FILES, "100000");
- runner.setProperty(ListFile.DIRECTORY, "target");
-
- runner.run();
-
- final ListFile.PerformanceTracker tracker = processor.getPerformanceTracker();
- assertEquals(100_000, tracker.getTrackedFileCount());
-
- final ListFile.MonitorActiveTasks monitorActiveTasks = new ListFile.MonitorActiveTasks(tracker, runner.getLogger(), 1000, 1000, 1);
-
- while (tracker.getTrackedFileCount() > 0) {
- monitorActiveTasks.run();
- }
-
- assertEquals(0, tracker.getTrackedFileCount());
- }
-
-
@Test
public void testGetPath() {
runner.setProperty(ListFile.DIRECTORY, "/dir/test1");
@@ -862,8 +820,8 @@ public class TestListFile {
assertTrue(mock1.getAttribute(ListFile.FILE_OWNER_ATTRIBUTE).contains(userName));
}
if (store.supportsFileAttributeView("posix")) {
- assertNotNull("Group name should be set", mock1.getAttribute(ListFile.FILE_GROUP_ATTRIBUTE));
- assertNotNull("File permissions should be set", mock1.getAttribute(ListFile.FILE_PERMISSIONS_ATTRIBUTE));
+ assertNotNull(mock1.getAttribute(ListFile.FILE_GROUP_ATTRIBUTE), "Group name should be set");
+ assertNotNull(mock1.getAttribute(ListFile.FILE_PERMISSIONS_ATTRIBUTE), "File permissions should be set");
}
}
@@ -877,8 +835,8 @@ public class TestListFile {
assertTrue(processor.isListingResetNecessary(ListFile.MAX_AGE));
assertTrue(processor.isListingResetNecessary(ListFile.MIN_SIZE));
assertTrue(processor.isListingResetNecessary(ListFile.MAX_SIZE));
- assertEquals(true, processor.isListingResetNecessary(ListFile.IGNORE_HIDDEN_FILES));
- assertEquals(false, processor.isListingResetNecessary(new PropertyDescriptor.Builder().name("x").build()));
+ assertTrue(processor.isListingResetNecessary(ListFile.IGNORE_HIDDEN_FILES));
+ assertFalse(processor.isListingResetNecessary(new PropertyDescriptor.Builder().name("x").build()));
}
private void makeTestFile(final String name, final long millis, final Map<String, Long> fileTimes) throws IOException {
@@ -974,7 +932,7 @@ public class TestListFile {
if (file.isDirectory()) {
deleteDirectory(file);
}
- assertTrue("Could not delete " + file.getAbsolutePath(), file.delete());
+ assertTrue(file.delete(), "Could not delete " + file.getAbsolutePath());
}
}
}
@@ -986,7 +944,7 @@ public class TestListFile {
assertEquals(1, results.size());
final ConfigVerificationResult result = results.get(0);
assertEquals(expectedOutcome, result.getOutcome());
- assertTrue(String.format("Expected verification result to match pattern [%s]. Actual explanation was: %s", expectedExplanationRegex, result.getExplanation()),
- result.getExplanation().matches(expectedExplanationRegex));
+ assertTrue(result.getExplanation().matches(expectedExplanationRegex),
+ String.format("Expected verification result to match pattern [%s]. Actual explanation was: %s", expectedExplanationRegex, result.getExplanation()));
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenRELP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenRELP.java
index 5ebbc40cea..692b632aff 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenRELP.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenRELP.java
@@ -38,13 +38,12 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.web.util.ssl.SslContextUtils;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import javax.net.ssl.SSLContext;
import java.io.ByteArrayOutputStream;
@@ -55,9 +54,13 @@ import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
+@ExtendWith(MockitoExtension.class)
public class TestListenRELP {
public static final String OPEN_FRAME_DATA = "relp_version=0\nrelp_software=librelp,1.2.7,http://librelp.adiscon.com\ncommands=syslog";
@@ -95,14 +98,14 @@ public class TestListenRELP {
private TestRunner runner;
- @Before
+ @BeforeEach
public void setup() {
encoder = new RELPEncoder(CHARSET);
ListenRELP mockRELP = new MockListenRELP();
runner = TestRunners.newTestRunner(mockRELP);
}
- @After
+ @AfterEach
public void shutdown() {
runner.shutdown();
}
@@ -116,21 +119,21 @@ public class TestListenRELP {
run(frames, relpFrames, null);
final List<ProvenanceEventRecord> events = runner.getProvenanceEvents();
- Assert.assertNotNull(events);
- Assert.assertEquals(relpFrames, events.size());
+ assertNotNull(events);
+ assertEquals(relpFrames, events.size());
final ProvenanceEventRecord event = events.get(0);
- Assert.assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
- Assert.assertTrue("transit uri must be set and start with proper protocol", event.getTransitUri().toLowerCase().startsWith("relp"));
+ assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
+ assertTrue(event.getTransitUri().toLowerCase().startsWith("relp"), "transit uri must be set and start with proper protocol");
final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenRELP.REL_SUCCESS);
- Assert.assertEquals(relpFrames, mockFlowFiles.size());
+ assertEquals(relpFrames, mockFlowFiles.size());
final MockFlowFile mockFlowFile = mockFlowFiles.get(0);
- Assert.assertEquals(String.valueOf(RELP_FRAME.getTxnr()), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.TXNR.key()));
- Assert.assertEquals(RELP_FRAME.getCommand(), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.COMMAND.key()));
- Assert.assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.PORT.key())));
- Assert.assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.SENDER.key())));
+ assertEquals(String.valueOf(RELP_FRAME.getTxnr()), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.TXNR.key()));
+ assertEquals(RELP_FRAME.getCommand(), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.COMMAND.key()));
+ assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.PORT.key())));
+ assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.SENDER.key())));
}
@Test
@@ -146,20 +149,20 @@ public class TestListenRELP {
run(frames, expectedFlowFiles, null);
final List<ProvenanceEventRecord> events = runner.getProvenanceEvents();
- Assert.assertNotNull(events);
- Assert.assertEquals(expectedFlowFiles, events.size());
+ assertNotNull(events);
+ assertEquals(expectedFlowFiles, events.size());
final ProvenanceEventRecord event = events.get(0);
- Assert.assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
- Assert.assertTrue("transit uri must be set and start with proper protocol", event.getTransitUri().toLowerCase().startsWith("relp"));
+ assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
+ assertTrue(event.getTransitUri().toLowerCase().startsWith("relp"), "transit uri must be set and start with proper protocol");
final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenRELP.REL_SUCCESS);
- Assert.assertEquals(expectedFlowFiles, mockFlowFiles.size());
+ assertEquals(expectedFlowFiles, mockFlowFiles.size());
final MockFlowFile mockFlowFile = mockFlowFiles.get(0);
- Assert.assertEquals(RELP_FRAME.getCommand(), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.COMMAND.key()));
- Assert.assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.PORT.key())));
- Assert.assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.SENDER.key())));
+ assertEquals(RELP_FRAME.getCommand(), mockFlowFile.getAttribute(ListenRELP.RELPAttributes.COMMAND.key()));
+ assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.PORT.key())));
+ assertFalse(StringUtils.isBlank(mockFlowFile.getAttribute(ListenRELP.RELPAttributes.SENDER.key())));
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java
index 57f494db73..603e4192f0 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenSyslog.java
@@ -30,18 +30,18 @@ import org.apache.nifi.syslog.attributes.SyslogAttributes;
import org.apache.nifi.util.MockFlowFile;
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.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.List;
-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.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -64,14 +64,14 @@ public class TestListenSyslog {
private ListenSyslog processor;
- @Before
+ @BeforeEach
public void setRunner() {
processor = new ListenSyslog();
runner = TestRunners.newTestRunner(processor);
runner.setProperty(ListenSyslog.CHARSET, CHARSET.name());
}
- @After
+ @AfterEach
public void closeEventSender() {
processor.shutdownEventServer();
}
@@ -130,12 +130,12 @@ public class TestListenSyslog {
runner.run(1, STOP_ON_FINISH_ENABLED, INITIALIZE_DISABLED);
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship(ListenSyslog.REL_SUCCESS);
- assertEquals("Success FlowFiles not matched", 1, successFlowFiles.size());
+ assertEquals(1, successFlowFiles.size(), "Success FlowFiles not matched");
final Long receivedCounter = runner.getCounterValue(ListenSyslog.RECEIVED_COUNTER);
- assertEquals("Received Counter not matched", Long.valueOf(messages.length), receivedCounter);
+ assertEquals(Long.valueOf(messages.length), receivedCounter, "Received Counter not matched");
final Long successCounter = runner.getCounterValue(ListenSyslog.SUCCESS_COUNTER);
- assertEquals("Success Counter not matched", Long.valueOf(1), successCounter);
+ assertEquals(Long.valueOf(1), successCounter, "Success Counter not matched");
}
@Test
@@ -150,7 +150,7 @@ public class TestListenSyslog {
runner.run(1, STOP_ON_FINISH_ENABLED, INITIALIZE_DISABLED);
final List<MockFlowFile> invalidFlowFiles = runner.getFlowFilesForRelationship(ListenSyslog.REL_INVALID);
- assertEquals("Invalid FlowFiles not matched", 1, invalidFlowFiles.size());
+ assertEquals(1, invalidFlowFiles.size(), "Invalid FlowFiles not matched");
final MockFlowFile flowFile = invalidFlowFiles.iterator().next();
flowFile.assertAttributeEquals(SyslogAttributes.SYSLOG_SENDER.key(), LOCALHOST_ADDRESS);
@@ -158,7 +158,7 @@ public class TestListenSyslog {
flowFile.assertAttributeEquals(SyslogAttributes.SYSLOG_PORT.key(), Integer.toString(port));
final String content = flowFile.getContent();
- assertEquals("FlowFile content not matched", TIMESTAMP, content);
+ assertEquals(TIMESTAMP, content, "FlowFile content not matched");
}
private void assertSendSuccess(final TransportProtocol protocol, final int port) throws Exception {
@@ -168,10 +168,10 @@ public class TestListenSyslog {
runner.run(1, STOP_ON_FINISH_ENABLED, INITIALIZE_DISABLED);
final List<MockFlowFile> invalidFlowFiles = runner.getFlowFilesForRelationship(ListenSyslog.REL_INVALID);
- assertTrue("Invalid FlowFiles found", invalidFlowFiles.isEmpty());
+ assertTrue(invalidFlowFiles.isEmpty(), "Invalid FlowFiles found");
final List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship(ListenSyslog.REL_SUCCESS);
- assertEquals("Success FlowFiles not matched", 1, successFlowFiles.size());
+ assertEquals(1, successFlowFiles.size(), "Success FlowFiles not matched");
final MockFlowFile flowFile = successFlowFiles.iterator().next();
flowFile.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), MIME_TYPE);
@@ -187,16 +187,16 @@ public class TestListenSyslog {
flowFile.assertAttributeExists(SyslogAttributes.SYSLOG_SEVERITY.key());
final Long receivedCounter = runner.getCounterValue(ListenSyslog.RECEIVED_COUNTER);
- assertEquals("Received Counter not matched", Long.valueOf(1), receivedCounter);
+ assertEquals(Long.valueOf(1), receivedCounter, "Received Counter not matched");
final Long successCounter = runner.getCounterValue(ListenSyslog.SUCCESS_COUNTER);
- assertEquals("Success Counter not matched", Long.valueOf(1), successCounter);
+ assertEquals(Long.valueOf(1), successCounter, "Success Counter not matched");
final List<ProvenanceEventRecord> events = runner.getProvenanceEvents();
- assertFalse("Provenance Events not found", events.isEmpty());
+ assertFalse(events.isEmpty(), "Provenance Events not found");
final ProvenanceEventRecord eventRecord = events.iterator().next();
assertEquals(ProvenanceEventType.RECEIVE, eventRecord.getEventType());
final String transitUri = String.format("%s://%s:%d", protocol.toString().toLowerCase(), LOCALHOST_ADDRESS, port);
- assertEquals("Provenance Transit URI not matched", transitUri, eventRecord.getTransitUri());
+ assertEquals(transitUri, eventRecord.getTransitUri(), "Provenance Transit URI not matched");
}
private void sendMessages(final TransportProtocol protocol, final int port, final LineEnding lineEnding, final String... messages) throws Exception {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCPRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCPRecord.java
index 731902d936..2d4e283847 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCPRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCPRecord.java
@@ -16,14 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Optional;
-import javax.net.ssl.SSLContext;
-
import org.apache.nifi.json.JsonTreeReader;
import org.apache.nifi.remote.io.socket.NetworkUtils;
import org.apache.nifi.reporting.InitializationException;
@@ -40,14 +32,27 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.web.util.ssl.SslContextUtils;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import javax.net.ssl.SSLContext;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class TestListenTCPRecord {
static final String SCHEMA_TEXT = "{\n" +
" \"name\": \"syslogRecord\",\n" +
@@ -68,7 +73,7 @@ public class TestListenTCPRecord {
private static final Logger LOGGER = LoggerFactory.getLogger(TestListenTCPRecord.class);
- private static final long TEST_TIMEOUT = 30000;
+ private static final long TEST_TIMEOUT = 30;
private static final String LOCALHOST = "localhost";
@@ -80,13 +85,13 @@ public class TestListenTCPRecord {
private TestRunner runner;
- @BeforeClass
+ @BeforeAll
public static void configureServices() throws TlsException {
keyStoreSslContext = SslContextUtils.createKeyStoreSslContext();
trustStoreSslContext = SslContextUtils.createTrustStoreSslContext();
}
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(ListenTCPRecord.class);
@@ -119,7 +124,8 @@ public class TestListenTCPRecord {
runner.assertValid();
}
- @Test(timeout = TEST_TIMEOUT)
+ @Test
+ @Timeout(TEST_TIMEOUT)
public void testRunOneRecordPerFlowFile() throws IOException, InterruptedException {
runner.setProperty(ListenTCPRecord.RECORD_BATCH_SIZE, "1");
@@ -131,31 +137,33 @@ public class TestListenTCPRecord {
flowFile.assertAttributeEquals("record.count", "1");
final String content = new String(flowFile.toByteArray(), StandardCharsets.UTF_8);
- Assert.assertNotNull(content);
- Assert.assertTrue(content.contains("This is a test " + (i + 1)));
+ assertNotNull(content);
+ assertTrue(content.contains("This is a test " + (i + 1)));
}
}
- @Test(timeout = TEST_TIMEOUT)
+ @Test
+ @Timeout(TEST_TIMEOUT)
public void testRunMultipleRecordsPerFlowFileLessThanBatchSize() throws IOException, InterruptedException {
runner.setProperty(ListenTCPRecord.RECORD_BATCH_SIZE, "5");
run(1, null);
final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenTCPRecord.REL_SUCCESS);
- Assert.assertEquals(1, mockFlowFiles.size());
+ assertEquals(1, mockFlowFiles.size());
final MockFlowFile flowFile = mockFlowFiles.get(0);
flowFile.assertAttributeEquals("record.count", "3");
final String content = new String(flowFile.toByteArray(), StandardCharsets.UTF_8);
- Assert.assertNotNull(content);
- Assert.assertTrue(content.contains("This is a test " + 1));
- Assert.assertTrue(content.contains("This is a test " + 2));
- Assert.assertTrue(content.contains("This is a test " + 3));
+ assertNotNull(content);
+ assertTrue(content.contains("This is a test " + 1));
+ assertTrue(content.contains("This is a test " + 2));
+ assertTrue(content.contains("This is a test " + 3));
}
- @Test(timeout = TEST_TIMEOUT)
+ @Test
+ @Timeout(TEST_TIMEOUT)
public void testRunClientAuthRequired() throws InitializationException, IOException, InterruptedException {
runner.setProperty(ListenTCPRecord.CLIENT_AUTH, ClientAuth.REQUIRED.name());
enableSslContextService(keyStoreSslContext);
@@ -163,16 +171,17 @@ public class TestListenTCPRecord {
run(1, keyStoreSslContext);
final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenTCPRecord.REL_SUCCESS);
- Assert.assertEquals(1, mockFlowFiles.size());
+ assertEquals(1, mockFlowFiles.size());
final String content = new String(mockFlowFiles.get(0).toByteArray(), StandardCharsets.UTF_8);
- Assert.assertNotNull(content);
- Assert.assertTrue(content.contains("This is a test " + 1));
- Assert.assertTrue(content.contains("This is a test " + 2));
- Assert.assertTrue(content.contains("This is a test " + 3));
+ assertNotNull(content);
+ assertTrue(content.contains("This is a test " + 1));
+ assertTrue(content.contains("This is a test " + 2));
+ assertTrue(content.contains("This is a test " + 3));
}
- @Test(timeout = TEST_TIMEOUT)
+ @Test
+ @Timeout(TEST_TIMEOUT)
public void testRunSSLClientDNsAddedAsAttributes() throws InitializationException, IOException, InterruptedException {
runner.setProperty(ListenTCPRecord.CLIENT_AUTH, ClientAuth.REQUIRED.name());
enableSslContextService(keyStoreSslContext);
@@ -180,14 +189,15 @@ public class TestListenTCPRecord {
run(1, keyStoreSslContext);
final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenTCPRecord.REL_SUCCESS);
- Assert.assertEquals(1, mockFlowFiles.size());
+ assertEquals(1, mockFlowFiles.size());
final MockFlowFile flowFile = mockFlowFiles.get(0);
flowFile.assertAttributeEquals("client.certificate.subject.dn", "CN=localhost");
flowFile.assertAttributeEquals("client.certificate.issuer.dn", "CN=localhost");
}
- @Test(timeout = TEST_TIMEOUT)
+ @Test
+ @Timeout(TEST_TIMEOUT)
public void testRunClientAuthNone() throws InitializationException, IOException, InterruptedException {
runner.setProperty(ListenTCPRecord.CLIENT_AUTH, ClientAuth.NONE.name());
enableSslContextService(keyStoreSslContext);
@@ -195,13 +205,13 @@ public class TestListenTCPRecord {
run(1, trustStoreSslContext);
final List<MockFlowFile> mockFlowFiles = runner.getFlowFilesForRelationship(ListenTCPRecord.REL_SUCCESS);
- Assert.assertEquals(1, mockFlowFiles.size());
+ assertEquals(1, mockFlowFiles.size());
final String content = new String(mockFlowFiles.get(0).toByteArray(), StandardCharsets.UTF_8);
- Assert.assertNotNull(content);
- Assert.assertTrue(content.contains("This is a test " + 1));
- Assert.assertTrue(content.contains("This is a test " + 2));
- Assert.assertTrue(content.contains("This is a test " + 3));
+ assertNotNull(content);
+ assertTrue(content.contains("This is a test " + 1));
+ assertTrue(content.contains("This is a test " + 2));
+ assertTrue(content.contains("This is a test " + 3));
}
protected void run(final int expectedTransferred, final SSLContext sslContext) throws IOException, InterruptedException {
@@ -229,7 +239,7 @@ public class TestListenTCPRecord {
iterations++;
final Optional<LogMessage> firstErrorMessage = runner.getLogger().getErrorMessages().stream().findFirst();
- Assert.assertNull(firstErrorMessage.orElse(null));
+ assertNull(firstErrorMessage.orElse(null));
}
LOGGER.info("Completed after iterations [{}]", iterations);
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java
index 0513db6d26..ec49fe5c68 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDP.java
@@ -29,13 +29,12 @@ import org.apache.nifi.remote.io.socket.NetworkUtils;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.io.IOException;
import java.net.DatagramPacket;
@@ -47,7 +46,10 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
-@RunWith(MockitoJUnitRunner.class)
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@ExtendWith(MockitoExtension.class)
public class TestListenUDP {
private static final String LOCALHOST = "localhost";
@@ -59,7 +61,7 @@ public class TestListenUDP {
@Mock
private ChannelResponder<DatagramChannel> responder;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
runner = TestRunners.newTestRunner(ListenUDP.class);
port = NetworkUtils.getAvailableUdpPort();
@@ -201,18 +203,18 @@ public class TestListenUDP {
for (int i = 0; i < mockFlowFiles.size(); i++) {
MockFlowFile flowFile = mockFlowFiles.get(i);
flowFile.assertContentEquals("This is message " + (i + 1));
- Assert.assertEquals(String.valueOf(port), flowFile.getAttribute(ListenUDP.UDP_PORT_ATTR));
- Assert.assertTrue(StringUtils.isNotEmpty(flowFile.getAttribute(ListenUDP.UDP_SENDER_ATTR)));
+ assertEquals(String.valueOf(port), flowFile.getAttribute(ListenUDP.UDP_PORT_ATTR));
+ assertTrue(StringUtils.isNotEmpty(flowFile.getAttribute(ListenUDP.UDP_SENDER_ATTR)));
}
}
private void verifyProvenance(int expectedNumEvents) {
List<ProvenanceEventRecord> provEvents = runner.getProvenanceEvents();
- Assert.assertEquals(expectedNumEvents, provEvents.size());
+ assertEquals(expectedNumEvents, provEvents.size());
for (ProvenanceEventRecord event : provEvents) {
- Assert.assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
- Assert.assertTrue(event.getTransitUri().startsWith("udp://"));
+ assertEquals(ProvenanceEventType.RECEIVE, event.getEventType());
+ assertTrue(event.getTransitUri().startsWith("udp://"));
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java
index 459df9e2b8..82797035df 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java
@@ -28,8 +28,8 @@ import org.apache.nifi.serialization.record.MockRecordWriter;
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 org.mockito.Mockito;
import java.io.IOException;
@@ -71,7 +71,7 @@ public class TestListenUDPRecord {
private TestRunner runner;
private MockRecordWriter mockRecordWriter;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
proc = new TestableListenUDPRecord();
runner = TestRunners.newTestRunner(proc);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java
index aa6f496e8c..6d452130b7 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java
@@ -16,20 +16,20 @@
*/
package org.apache.nifi.processors.standard;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsNot.not;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNot.not;
public class TestLogAttribute {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java
index a07bfb1b95..f0fa64356d 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java
@@ -17,20 +17,21 @@
package org.apache.nifi.processors.standard;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-
import org.apache.nifi.logging.ComponentLog;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-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.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestLogMessage {
@@ -53,20 +54,20 @@ public class TestLogMessage {
}
- @Before
+ @BeforeEach
public void before() throws InitializationException {
testableLogMessage = new TestableLogMessage();
runner = TestRunners.newTestRunner(testableLogMessage);
}
- @After
+ @AfterEach
public void after() throws InitializationException {
runner.shutdown();
}
@Test
- public void testInfoMessageLogged() throws InitializationException, IOException {
+ public void testInfoMessageLogged() {
runner.setProperty(LogMessage.LOG_MESSAGE, "This should help the operator to follow the flow: ${foobar}");
runner.setProperty(LogMessage.LOG_LEVEL, LogMessage.MessageLogLevel.info.toString());
@@ -78,23 +79,23 @@ public class TestLogMessage {
runner.run();
List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship(LogMessage.REL_SUCCESS);
- Assert.assertEquals(1, successFlowFiles.size());
+ assertEquals(1, successFlowFiles.size());
MockComponentLog mockComponentLog = testableLogMessage.getMockComponentLog();
List<org.apache.nifi.util.LogMessage> infoMessages = mockComponentLog.getInfoMessages();
- Assert.assertEquals(1, infoMessages.size());
- Assert.assertTrue(infoMessages.get(0).getMsg()
+ assertEquals(1, infoMessages.size());
+ assertTrue(infoMessages.get(0).getMsg()
.endsWith("This should help the operator to follow the flow: baz"));
- Assert.assertTrue(mockComponentLog.getTraceMessages().isEmpty());
- Assert.assertTrue(mockComponentLog.getDebugMessages().isEmpty());
- Assert.assertTrue(mockComponentLog.getWarnMessages().isEmpty());
- Assert.assertTrue(mockComponentLog.getErrorMessages().isEmpty());
+ assertTrue(mockComponentLog.getTraceMessages().isEmpty());
+ assertTrue(mockComponentLog.getDebugMessages().isEmpty());
+ assertTrue(mockComponentLog.getWarnMessages().isEmpty());
+ assertTrue(mockComponentLog.getErrorMessages().isEmpty());
}
@Test
- public void testInfoMessageWithPrefixLogged() throws InitializationException, IOException {
+ public void testInfoMessageWithPrefixLogged() {
runner.setProperty(LogMessage.LOG_PREFIX, "FOOBAR>>>");
runner.setProperty(LogMessage.LOG_MESSAGE, "This should help the operator to follow the flow: ${foobar}");
@@ -107,20 +108,20 @@ public class TestLogMessage {
runner.run();
List<MockFlowFile> successFlowFiles = runner.getFlowFilesForRelationship(LogMessage.REL_SUCCESS);
- Assert.assertEquals(1, successFlowFiles.size());
+ assertEquals(1, successFlowFiles.size());
MockComponentLog mockComponentLog = testableLogMessage.getMockComponentLog();
List<org.apache.nifi.util.LogMessage> infoMessages = mockComponentLog.getInfoMessages();
- Assert.assertEquals(1, infoMessages.size());
- Assert.assertTrue(infoMessages.get(0).getMsg()
+ assertEquals(1, infoMessages.size());
+ assertTrue(infoMessages.get(0).getMsg()
.endsWith("FOOBAR>>>This should help the operator to follow the flow: baz"));
- Assert.assertTrue(mockComponentLog.getTraceMessages().isEmpty());
- Assert.assertTrue(mockComponentLog.getDebugMessages().isEmpty());
- Assert.assertTrue(mockComponentLog.getWarnMessages().isEmpty());
- Assert.assertTrue(mockComponentLog.getErrorMessages().isEmpty());
+ assertTrue(mockComponentLog.getTraceMessages().isEmpty());
+ assertTrue(mockComponentLog.getDebugMessages().isEmpty());
+ assertTrue(mockComponentLog.getWarnMessages().isEmpty());
+ assertTrue(mockComponentLog.getErrorMessages().isEmpty());
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java
index 3f9d2fa2f0..1ccb1a2af5 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java
@@ -16,13 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.lookup.LookupFailureException;
import org.apache.nifi.lookup.LookupService;
@@ -32,11 +25,18 @@ import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
-import org.junit.Assert;
-import org.junit.Test;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestLookupAttribute {
@@ -182,10 +182,10 @@ public class TestLookupAttribute {
static class TestService extends AbstractControllerService implements StringLookupService {
@Override
public Optional<String> lookup(Map<String, Object> coordinates, Map<String, String> context) throws LookupFailureException {
- Assert.assertNotNull(coordinates);
- Assert.assertNotNull(context);
- Assert.assertEquals(1, coordinates.size());
- Assert.assertTrue(context.containsKey("user_defined"));
+ assertNotNull(coordinates);
+ assertNotNull(context);
+ assertEquals(1, coordinates.size());
+ assertTrue(context.containsKey("user_defined"));
return Optional.of("Test!");
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java
index 2b15dfe2da..66b498be46 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java
@@ -37,9 +37,8 @@ import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -52,7 +51,8 @@ import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestLookupRecord {
@@ -61,7 +61,7 @@ public class TestLookupRecord {
private MockRecordParser recordReader;
private MockRecordWriter recordWriter;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
recordReader = new MockRecordParser();
recordWriter = new MockRecordWriter(null, false);
@@ -627,9 +627,9 @@ public class TestLookupRecord {
private void validateContext(Map<String, String> context) {
if (expectedContext != null) {
for (Map.Entry<String, Object> entry : expectedContext.entrySet()) {
- Assert.assertTrue(String.format("%s was not in coordinates.", entry.getKey()),
- context.containsKey(entry.getKey()));
- Assert.assertEquals("Wrong value", entry.getValue(), context.get(entry.getKey()));
+ assertTrue(context.containsKey(entry.getKey()),
+ String.format("%s was not in coordinates.", entry.getKey()));
+ assertEquals(entry.getValue(), context.get(entry.getKey()), "Wrong value");
}
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java
index 0489ad2922..3bfa55ff15 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java
@@ -38,9 +38,7 @@ import org.apache.nifi.util.MockFlowFile;
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.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -48,7 +46,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -57,15 +54,13 @@ import java.util.Map;
import java.util.Set;
import java.util.zip.ZipInputStream;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestMergeContent {
- @BeforeClass
- public static void setup() {
- System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.standard", "DEBUG");
- }
-
/**
* This test will verify that if we have a FlowFile larger than the Max Size for a Bin, it will go into its
* own bin and immediately be processed as its own bin.
@@ -98,7 +93,7 @@ public class TestMergeContent {
}
@Test
- public void testSimpleAvroConcat() throws IOException, InterruptedException {
+ public void testSimpleAvroConcat() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_ENTRIES, "3");
runner.setProperty(MergeContent.MIN_ENTRIES, "3");
@@ -142,14 +137,14 @@ public class TestMergeContent {
byte[] data = runner.getContentAsByteArray(bundle);
final Map<String, GenericRecord> users = getGenericRecordMap(data, schema, "name");
- Assert.assertEquals(3, users.size());
- Assert.assertTrue(users.containsKey("Alyssa"));
- Assert.assertTrue(users.containsKey("Ben"));
- Assert.assertTrue(users.containsKey("John"));
+ assertEquals(3, users.size());
+ assertTrue(users.containsKey("Alyssa"));
+ assertTrue(users.containsKey("Ben"));
+ assertTrue(users.containsKey("John"));
}
@Test
- public void testAvroConcatWithDifferentSchemas() throws IOException, InterruptedException {
+ public void testAvroConcatWithDifferentSchemas() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_ENTRIES, "3");
runner.setProperty(MergeContent.MIN_ENTRIES, "3");
@@ -190,19 +185,19 @@ public class TestMergeContent {
final byte[] data = runner.getContentAsByteArray(bundle);
final Map<String, GenericRecord> users = getGenericRecordMap(data, schema1, "name");
- Assert.assertEquals(2, users.size());
- Assert.assertTrue(users.containsKey("Alyssa"));
- Assert.assertTrue(users.containsKey("John"));
+ assertEquals(2, users.size());
+ assertTrue(users.containsKey("Alyssa"));
+ assertTrue(users.containsKey("John"));
final MockFlowFile failure = runner.getFlowFilesForRelationship(MergeContent.REL_FAILURE).get(0);
final byte[] failureData = runner.getContentAsByteArray(failure);
final Map<String, GenericRecord> places = getGenericRecordMap(failureData, schema2, "name");
- Assert.assertEquals(1, places.size());
- Assert.assertTrue(places.containsKey("Some Place"));
+ assertEquals(1, places.size());
+ assertTrue(places.containsKey("Some Place"));
}
@Test
- public void testAvroConcatWithDifferentMetadataDoNotMerge() throws IOException, InterruptedException {
+ public void testAvroConcatWithDifferentMetadataDoNotMerge() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_ENTRIES, "3");
runner.setProperty(MergeContent.MIN_ENTRIES, "3");
@@ -257,12 +252,12 @@ public class TestMergeContent {
byte[] data = runner.getContentAsByteArray(bundle);
final Map<String, GenericRecord> users = getGenericRecordMap(data, schema, "name");
- Assert.assertEquals(1, users.size());
- Assert.assertTrue(users.containsKey("Alyssa"));
+ assertEquals(1, users.size());
+ assertTrue(users.containsKey("Alyssa"));
}
@Test
- public void testAvroConcatWithDifferentMetadataIgnore() throws IOException, InterruptedException {
+ public void testAvroConcatWithDifferentMetadataIgnore() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_ENTRIES, "3");
runner.setProperty(MergeContent.MIN_ENTRIES, "3");
@@ -317,14 +312,14 @@ public class TestMergeContent {
byte[] data = runner.getContentAsByteArray(bundle);
final Map<String, GenericRecord> users = getGenericRecordMap(data, schema, "name");
- Assert.assertEquals(3, users.size());
- Assert.assertTrue(users.containsKey("Alyssa"));
- Assert.assertTrue(users.containsKey("Ben"));
- Assert.assertTrue(users.containsKey("John"));
+ assertEquals(3, users.size());
+ assertTrue(users.containsKey("Alyssa"));
+ assertTrue(users.containsKey("Ben"));
+ assertTrue(users.containsKey("John"));
}
@Test
- public void testAvroConcatWithDifferentMetadataUseFirst() throws IOException, InterruptedException {
+ public void testAvroConcatWithDifferentMetadataUseFirst() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_ENTRIES, "3");
runner.setProperty(MergeContent.MIN_ENTRIES, "3");
@@ -379,14 +374,14 @@ public class TestMergeContent {
byte[] data = runner.getContentAsByteArray(bundle);
final Map<String, GenericRecord> users = getGenericRecordMap(data, schema, "name");
- Assert.assertEquals(3, users.size());
- Assert.assertTrue(users.containsKey("Alyssa"));
- Assert.assertTrue(users.containsKey("Ben"));
- Assert.assertTrue(users.containsKey("John"));
+ assertEquals(3, users.size());
+ assertTrue(users.containsKey("Alyssa"));
+ assertTrue(users.containsKey("Ben"));
+ assertTrue(users.containsKey("John"));
}
@Test
- public void testAvroConcatWithDifferentMetadataKeepCommon() throws IOException, InterruptedException {
+ public void testAvroConcatWithDifferentMetadataKeepCommon() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_ENTRIES, "3");
runner.setProperty(MergeContent.MIN_ENTRIES, "3");
@@ -441,9 +436,9 @@ public class TestMergeContent {
byte[] data = runner.getContentAsByteArray(bundle);
final Map<String, GenericRecord> users = getGenericRecordMap(data, schema, "name");
- Assert.assertEquals(2, users.size());
- Assert.assertTrue(users.containsKey("Alyssa"));
- Assert.assertTrue(users.containsKey("John"));
+ assertEquals(2, users.size());
+ assertTrue(users.containsKey("Alyssa"));
+ assertTrue(users.containsKey("John"));
}
private Map<String, GenericRecord> getGenericRecordMap(byte[] data, Schema schema, String key) throws IOException {
@@ -478,7 +473,7 @@ public class TestMergeContent {
}
@Test
- public void testSimpleBinaryConcat() throws IOException, InterruptedException {
+ public void testSimpleBinaryConcat() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec");
runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT);
@@ -520,7 +515,7 @@ public class TestMergeContent {
}
@Test
- public void testSimpleBinaryConcatWithTextDelimiters() throws IOException, InterruptedException {
+ public void testSimpleBinaryConcatWithTextDelimiters() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec");
runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT);
@@ -596,7 +591,7 @@ public class TestMergeContent {
}
@Test
- public void testTextDelimitersValidation() throws IOException, InterruptedException {
+ public void testTextDelimitersValidation() {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec");
runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT);
@@ -612,14 +607,14 @@ public class TestMergeContent {
results = mockContext.validate();
}
- Assert.assertEquals(3, results.size());
+ assertEquals(3, results.size());
for (ValidationResult vr : results) {
- Assert.assertTrue(vr.toString().contains("cannot be empty"));
+ assertTrue(vr.toString().contains("cannot be empty"));
}
}
@Test
- public void testFileDelimitersValidation() throws IOException, InterruptedException {
+ public void testFileDelimitersValidation() {
final String doesNotExistFile = "src/test/resources/TestMergeContent/does_not_exist";
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec");
@@ -636,14 +631,14 @@ public class TestMergeContent {
results = mockContext.validate();
}
- Assert.assertEquals(3, results.size());
+ assertEquals(3, results.size());
for (ValidationResult vr : results) {
- Assert.assertTrue(vr.toString().contains("is invalid because File " + new File(doesNotExistFile).toString() + " does not exist"));
+ assertTrue(vr.toString().contains("is invalid because File " + new File(doesNotExistFile).toString() + " does not exist"));
}
}
@Test
- public void testMimeTypeIsOctetStreamIfConflictingWithBinaryConcat() throws IOException, InterruptedException {
+ public void testMimeTypeIsOctetStreamIfConflictingWithBinaryConcat() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec");
runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT);
@@ -717,7 +712,7 @@ public class TestMergeContent {
}
@Test
- public void testSimpleBinaryConcatWaitsForMin() throws IOException, InterruptedException {
+ public void testSimpleBinaryConcatWaitsForMin() {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT);
runner.setProperty(MergeContent.MIN_SIZE, "20 KB");
@@ -746,17 +741,17 @@ public class TestMergeContent {
final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0);
try (final InputStream rawIn = new ByteArrayInputStream(runner.getContentAsByteArray(bundle)); final ZipInputStream in = new ZipInputStream(rawIn)) {
- Assert.assertNotNull(in.getNextEntry());
+ assertNotNull(in.getNextEntry());
final byte[] part1 = IOUtils.toByteArray(in);
- Assert.assertTrue(Arrays.equals("Hello".getBytes("UTF-8"), part1));
+ assertArrayEquals("Hello".getBytes("UTF-8"), part1);
in.getNextEntry();
final byte[] part2 = IOUtils.toByteArray(in);
- Assert.assertTrue(Arrays.equals(", ".getBytes("UTF-8"), part2));
+ assertArrayEquals(", ".getBytes("UTF-8"), part2);
in.getNextEntry();
final byte[] part3 = IOUtils.toByteArray(in);
- Assert.assertTrue(Arrays.equals("World!".getBytes("UTF-8"), part3));
+ assertArrayEquals("World!".getBytes("UTF-8"), part3);
}
bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/zip");
}
@@ -807,20 +802,20 @@ public class TestMergeContent {
final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0);
try (final InputStream rawIn = new ByteArrayInputStream(runner.getContentAsByteArray(bundle)); final TarArchiveInputStream in = new TarArchiveInputStream(rawIn)) {
ArchiveEntry entry = in.getNextEntry();
- Assert.assertNotNull(entry);
+ assertNotNull(entry);
assertEquals("AShortFileName", entry.getName());
final byte[] part1 = IOUtils.toByteArray(in);
- Assert.assertTrue(Arrays.equals("Hello".getBytes("UTF-8"), part1));
+ assertArrayEquals("Hello".getBytes("UTF-8"), part1);
entry = in.getNextEntry();
assertEquals("ALongerrrFileName", entry.getName());
final byte[] part2 = IOUtils.toByteArray(in);
- Assert.assertTrue(Arrays.equals(", ".getBytes("UTF-8"), part2));
+ assertArrayEquals(", ".getBytes("UTF-8"), part2);
entry = in.getNextEntry();
assertEquals("AReallyLongggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggFileName", entry.getName());
final byte[] part3 = IOUtils.toByteArray(in);
- Assert.assertTrue(Arrays.equals("World!".getBytes("UTF-8"), part3));
+ assertArrayEquals("World!".getBytes("UTF-8"), part3);
}
bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/tar");
}
@@ -1124,7 +1119,7 @@ public class TestMergeContent {
final String attr2 = merged2.getAttribute("attr");
if ("c".equals(attr1)) {
- Assert.assertEquals("b", attr2);
+ assertEquals("b", attr2);
merged1.assertContentEquals("A Canal ", "UTF-8");
merged2.assertContentEquals("A Man A Plan Panama", "UTF-8");
} else {
@@ -1229,7 +1224,7 @@ public class TestMergeContent {
}
@Test
- public void testCountAttribute() throws IOException, InterruptedException {
+ public void testCountAttribute() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new MergeContent());
runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec");
runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java
index e330577516..4efdd7ec32 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java
@@ -28,23 +28,23 @@ import org.apache.nifi.serialization.record.RecordSchema;
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.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestMergeRecord {
private TestRunner runner;
private CommaSeparatedRecordReader readerService;
private MockRecordWriter writerService;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(new MergeRecord());
@@ -219,7 +219,7 @@ public class TestMergeRecord {
runner.run(1);
- assertEquals("Fragment id=2 should remain in the incoming connection", 1, runner.getQueueSize().getObjectCount());
+ assertEquals(1, runner.getQueueSize().getObjectCount(), "Fragment id=2 should remain in the incoming connection");
runner.assertTransferCount(MergeRecord.REL_MERGED, 2);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 4);
@@ -247,7 +247,7 @@ public class TestMergeRecord {
runner.enqueue("Name, Age\nJohn, 35", attr1);
runner.run(2);
- assertEquals("Fragment should remain in the incoming connection", 1, runner.getQueueSize().getObjectCount());
+ assertEquals(1, runner.getQueueSize().getObjectCount(), "Fragment should remain in the incoming connection");
runner.assertTransferCount(MergeRecord.REL_MERGED, 0);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 0);
runner.assertTransferCount(MergeRecord.REL_FAILURE, 0);
@@ -260,7 +260,7 @@ public class TestMergeRecord {
runner.enqueue("Name, Age\nJane, 34", attr2);
runner.run(1);
- assertEquals("Fragments should merge", 0, runner.getQueueSize().getObjectCount());
+ assertEquals(0, runner.getQueueSize().getObjectCount(), "Fragments should merge");
runner.assertTransferCount(MergeRecord.REL_MERGED, 1);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 2);
runner.assertTransferCount(MergeRecord.REL_FAILURE, 0);
@@ -302,7 +302,7 @@ public class TestMergeRecord {
runner.run(1);
- assertEquals("Fragment id=2 should remain in the incoming connection", 1, runner.getQueueSize().getObjectCount());
+ assertEquals(1, runner.getQueueSize().getObjectCount(), "Fragment id=2 should remain in the incoming connection");
runner.assertTransferCount(MergeRecord.REL_MERGED, 1);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 2);
@@ -334,7 +334,7 @@ public class TestMergeRecord {
runner.run(2);
- assertEquals("Fragment id=1 should remain in the incoming connection", 1, runner.getQueueSize().getObjectCount());
+ assertEquals(1, runner.getQueueSize().getObjectCount(), "Fragment id=1 should remain in the incoming connection");
runner.assertTransferCount(MergeRecord.REL_MERGED, 0);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 0);
@@ -342,7 +342,7 @@ public class TestMergeRecord {
runner.run(1);
- assertEquals("Fragment id=1 should be merged", 0, runner.getQueueSize().getObjectCount());
+ assertEquals(0, runner.getQueueSize().getObjectCount(), "Fragment id=1 should be merged");
runner.assertTransferCount(MergeRecord.REL_MERGED, 1);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 2);
@@ -451,7 +451,11 @@ public class TestMergeRecord {
}
@Test
- @Ignore("This unit test depends on timing and could potentially cause problems in an automated build environment. However, it can be useful for manual testing")
+ @EnabledIfSystemProperty(
+ named = "nifi.test.performance",
+ matches = "true",
+ disabledReason = "This unit test depends on timing and could potentially cause problems in an automated build environment. However, it can be useful for manual testing"
+ )
public void testTimeout() throws InterruptedException {
runner.setProperty(MergeRecord.MIN_RECORDS, "500");
runner.setProperty(MergeRecord.MAX_BIN_AGE, "500 millis");
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java
index 91f08531b5..b94ed6374f 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestModifyBytes.java
@@ -16,6 +16,11 @@
*/
package org.apache.nifi.processors.standard;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -23,13 +28,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestModifyBytes {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java
index c0382b8663..606c8d17da 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMonitorActivity.java
@@ -449,7 +449,7 @@ public class TestMonitorActivity {
final StateMap postProcessedState = runner.getStateManager().getState(Scope.CLUSTER);
assertTrue( existingTimestamp < Long.parseLong(postProcessedState.get(
- MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER)));
+ MonitorActivity.STATE_KEY_LATEST_SUCCESS_TRANSFER)));
// State should be updated. Null in this case.
assertNull(postProcessedState.get("key1"));
assertNull(postProcessedState.get("key2"));
@@ -853,4 +853,4 @@ public class TestMonitorActivity {
}
-}
+}
\ No newline at end of file
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java
index ab99af9316..a4613b1206 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java
@@ -25,8 +25,8 @@ import org.apache.nifi.processors.standard.WaitNotifyProtocol.Signal;
import org.apache.nifi.reporting.InitializationException;
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.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -39,17 +39,17 @@ import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestNotify {
private TestRunner runner;
private MockCacheClient service;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(Notify.class);
@@ -113,7 +113,7 @@ public class TestNotify {
final Signal signal = new WaitNotifyProtocol(service).getSignal("someDataProcessing");
Map<String, String> cachedAttributes = signal.getAttributes();
- assertEquals("Same attribute key will be overwritten by the latest signal", "data3", cachedAttributes.get("key"));
+ assertEquals("data3", cachedAttributes.get("key"), "Same attribute key will be overwritten by the latest signal");
assertTrue(signal.isTotalCountReached(3));
assertEquals(2, signal.getCount("success"));
assertEquals(1, signal.getCount("failure"));
@@ -153,7 +153,7 @@ public class TestNotify {
Signal signal = new WaitNotifyProtocol(service).getSignal("someDataProcessing");
Map<String, String> cachedAttributes = signal.getAttributes();
- assertEquals("Same attribute key will be overwritten by the latest signal", "data2", cachedAttributes.get("key"));
+ assertEquals("data2", cachedAttributes.get("key"), "Same attribute key will be overwritten by the latest signal");
assertTrue(signal.isTotalCountReached(2));
assertEquals(2, signal.getCount("success"));
assertEquals(0, signal.getCount("failure"));
@@ -166,7 +166,7 @@ public class TestNotify {
signal = new WaitNotifyProtocol(service).getSignal("someDataProcessing");
cachedAttributes = signal.getAttributes();
- assertEquals("Same attribute key will be overwritten by the latest signal", "data3", cachedAttributes.get("key"));
+ assertEquals("data3", cachedAttributes.get("key"), "Same attribute key will be overwritten by the latest signal");
assertTrue(signal.isTotalCountReached(3));
assertEquals(2, signal.getCount("success"));
assertEquals(1, signal.getCount("failure"));
@@ -210,7 +210,7 @@ public class TestNotify {
final Signal signal = new WaitNotifyProtocol(service).getSignal("someDataProcessing");
Map<String, String> cachedAttributes = signal.getAttributes();
- assertEquals("Same attribute key will be overwritten by the latest signal", "data3", cachedAttributes.get("key"));
+ assertEquals("data3", cachedAttributes.get("key"), "Same attribute key will be overwritten by the latest signal");
assertTrue(signal.isTotalCountReached(3584));
assertEquals(3072, signal.getCount("success"));
assertEquals(512, signal.getCount("failure"));
@@ -256,7 +256,7 @@ public class TestNotify {
final Signal signal = new WaitNotifyProtocol(service).getSignal("someDataProcessing");
Map<String, String> cachedAttributes = signal.getAttributes();
- assertEquals("Same attribute key will be overwritten by the latest signal", "data3", cachedAttributes.get("key"));
+ assertEquals("data3", cachedAttributes.get("key"), "Same attribute key will be overwritten by the latest signal");
assertTrue(signal.isTotalCountReached(1536));
assertEquals(1024, signal.getCount("success"));
assertEquals(512, signal.getCount("failure"));
@@ -264,7 +264,7 @@ public class TestNotify {
}
@Test
- public void testRegex() throws InitializationException, IOException {
+ public void testRegex() throws IOException {
runner.setProperty(Notify.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
runner.setProperty(Notify.ATTRIBUTE_CACHE_REGEX, "key[0-9]*");
@@ -287,7 +287,7 @@ public class TestNotify {
}
@Test
- public void testEmptyReleaseSignal() throws InitializationException, InterruptedException {
+ public void testEmptyReleaseSignal() {
runner.setProperty(Notify.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
final Map<String, String> props = new HashMap<>();
@@ -300,19 +300,17 @@ public class TestNotify {
}
@Test
- public void testFailingCacheService() throws InitializationException, IOException {
+ public void testFailingCacheService() {
service.setFailOnCalls(true);
runner.setProperty(Notify.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
final Map<String, String> props = new HashMap<>();
props.put("releaseSignalAttribute", "2");
runner.enqueue(new byte[] {}, props);
- try {
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
runner.run();
- fail("Processor should throw RuntimeException in case it receives an IO exception from the cache service and yield for a while.");
- } catch (final AssertionError e) {
- assertTrue(e.getCause() instanceof RuntimeException);
- }
+ });
+ assertTrue(e.getCause() instanceof RuntimeException);
service.setFailOnCalls(false);
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseCEF.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseCEF.java
index 3e1945da84..b809cbf942 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseCEF.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseCEF.java
@@ -19,12 +19,10 @@ package org.apache.nifi.processors.standard;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import org.apache.nifi.util.MockFlowFile;
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.Test;
import java.io.IOException;
import java.text.SimpleDateFormat;
@@ -32,6 +30,8 @@ import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestParseCEF {
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
@@ -157,19 +157,19 @@ public class TestParseCEF {
JsonNode header = results.get("header");
JsonNode extension = results.get("extension");
- Assert.assertEquals("TestVendor", header.get("deviceVendor").asText());
- Assert.assertEquals(sdf.format(new Date(1423441663000L)),
+ assertEquals("TestVendor", header.get("deviceVendor").asText());
+ assertEquals(sdf.format(new Date(1423441663000L)),
extension.get("rt").asText());
- Assert.assertEquals("Test Long", extension.get("cn3Label").asText());
- Assert.assertEquals( 9223372036854775807L, extension.get("cn3").asLong());
- Assert.assertTrue(extension.get("cfp1").floatValue() == 1.234F);
- Assert.assertEquals("Test FP Number", extension.get("cfp1Label").asText());
- Assert.assertEquals("00:00:0c:07:ac:00", extension.get("smac").asText());
- Assert.assertEquals("2001:cdba:0:0:0:0:3257:9652", extension.get("c6a3").asText());
- Assert.assertEquals("Test IPv6", extension.get("c6a3Label").asText());
- Assert.assertEquals("123.123.123.123", extension.get("destinationTranslatedAddress").asText());
- Assert.assertEquals("Test String", extension.get("cs1Label").asText());
- Assert.assertEquals("test test test chocolate", extension.get("cs1").asText());
+ assertEquals("Test Long", extension.get("cn3Label").asText());
+ assertEquals( 9223372036854775807L, extension.get("cn3").asLong());
+ assertEquals(extension.get("cfp1").floatValue(), 1.234F);
+ assertEquals("Test FP Number", extension.get("cfp1Label").asText());
+ assertEquals("00:00:0c:07:ac:00", extension.get("smac").asText());
+ assertEquals("2001:cdba:0:0:0:0:3257:9652", extension.get("c6a3").asText());
+ assertEquals("Test IPv6", extension.get("c6a3Label").asText());
+ assertEquals("123.123.123.123", extension.get("destinationTranslatedAddress").asText());
+ assertEquals("Test String", extension.get("cs1Label").asText());
+ assertEquals("test test test chocolate", extension.get("cs1").asText());
}
@Test
@@ -189,22 +189,22 @@ public class TestParseCEF {
JsonNode header = results.get("header");
JsonNode extension = results.get("extension");
- Assert.assertEquals("TestVendor", header.get("deviceVendor").asText());
- Assert.assertEquals(sdf.format(new Date(1423441663000L)),
+ assertEquals("TestVendor", header.get("deviceVendor").asText());
+ assertEquals(sdf.format(new Date(1423441663000L)),
extension.get("rt").asText());
- Assert.assertEquals("Test Long", extension.get("cn3Label").asText());
- Assert.assertEquals( 9223372036854775807L, extension.get("cn3").asLong());
- Assert.assertTrue(extension.get("cfp1").floatValue() == 1.234F);
- Assert.assertEquals("Test FP Number", extension.get("cfp1Label").asText());
- Assert.assertEquals("00:00:0c:07:ac:00", extension.get("smac").asText());
- Assert.assertEquals("2001:cdba:0:0:0:0:3257:9652", extension.get("c6a3").asText());
- Assert.assertEquals("Test IPv6", extension.get("c6a3Label").asText());
- Assert.assertEquals("Test String", extension.get("cs1Label").asText());
- Assert.assertEquals("test test test chocolate", extension.get("cs1").asText());
- Assert.assertEquals("123.123.123.123", extension.get("destinationTranslatedAddress").asText());
+ assertEquals("Test Long", extension.get("cn3Label").asText());
+ assertEquals( 9223372036854775807L, extension.get("cn3").asLong());
+ assertEquals(extension.get("cfp1").floatValue(), 1.234F);
+ assertEquals("Test FP Number", extension.get("cfp1Label").asText());
+ assertEquals("00:00:0c:07:ac:00", extension.get("smac").asText());
+ assertEquals("2001:cdba:0:0:0:0:3257:9652", extension.get("c6a3").asText());
+ assertEquals("Test IPv6", extension.get("c6a3Label").asText());
+ assertEquals("Test String", extension.get("cs1Label").asText());
+ assertEquals("test test test chocolate", extension.get("cs1").asText());
+ assertEquals("123.123.123.123", extension.get("destinationTranslatedAddress").asText());
JsonNode inner = new ObjectMapper().readTree(extension.get("cs2").asText());
- Assert.assertEquals("chocolate!", inner.get("test_test_test").asText());
+ assertEquals("chocolate!", inner.get("test_test_test").asText());
}
@Test
@@ -225,7 +225,7 @@ public class TestParseCEF {
JsonNode extension = results.get("extension");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
- Assert.assertEquals(sdf.format(new Date(1423441663000L)),
+ assertEquals(sdf.format(new Date(1423441663000L)),
extension.get("rt").asText());
// Converting a field without timezone will always result on render time being dependent
@@ -237,7 +237,7 @@ public class TestParseCEF {
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
String prettyEvent = sdf.format(new Date(eventTime - offset));
- Assert.assertEquals(prettyEvent, extension.get("deviceCustomDate1").asText());
+ assertEquals(prettyEvent, extension.get("deviceCustomDate1").asText());
}
@Test
@@ -340,7 +340,7 @@ public class TestParseCEF {
JsonNode results = new ObjectMapper().readTree(rawJson);
JsonNode extension = results.get("extension");
- Assert.assertEquals(200, extension.get("http_response").asInt());
+ assertEquals(200, extension.get("http_response").asInt());
}
@Test
@@ -370,11 +370,11 @@ public class TestParseCEF {
JsonNode results = new ObjectMapper().readTree(rawJson);
JsonNode extensions = results.get("extension");
- Assert.assertTrue(extensions.has("cn3"));
- Assert.assertTrue(extensions.get("cn3").isNull());
+ assertTrue(extensions.has("cn3"));
+ assertTrue(extensions.get("cn3").isNull());
- Assert.assertTrue(extensions.has("cn3Label"));
- Assert.assertTrue(extensions.get("cn3Label").asText().isEmpty());
+ assertTrue(extensions.has("cn3Label"));
+ assertTrue(extensions.get("cn3Label").asText().isEmpty());
}
@Test
@@ -403,7 +403,7 @@ public class TestParseCEF {
JsonNode results = new ObjectMapper().readTree(rawJson);
JsonNode extension = results.get("extension");
- Assert.assertEquals("ICMP", extension.get("proto").asText());
+ assertEquals("ICMP", extension.get("proto").asText());
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java
index 79d4c09cea..ad22454f43 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog.java
@@ -21,7 +21,7 @@ import org.apache.nifi.syslog.attributes.SyslogAttributes;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestParseSyslog {
static final String PRI = "34";
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java
index 86cc102205..2631a28263 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java
@@ -22,11 +22,13 @@ import org.apache.nifi.syslog.attributes.SyslogAttributes;
import org.apache.nifi.util.MockFlowFile;
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.Test;
import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
public class TestParseSyslog5424 {
private static final String SYSLOG_LINE_ALL = "<14>1 2014-06-20T09:14:07+00:00 loggregator"
+ " d0602076-b14a-4c55-852a-981e7afeed38 DEA MSG-01"
@@ -73,7 +75,7 @@ public class TestParseSyslog5424 {
runner.run();
runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS,1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS);
- Assert.assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
+ assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
}
@Test
@@ -85,7 +87,7 @@ public class TestParseSyslog5424 {
runner.run();
runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS,1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS);
- Assert.assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
+ assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
}
@Test
@@ -97,6 +99,6 @@ public class TestParseSyslog5424 {
runner.run();
runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS,1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS);
- Assert.assertNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
+ assertNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java
index 933ad47087..429163ddcd 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java
@@ -24,15 +24,15 @@ import org.apache.nifi.serialization.record.RecordFieldType;
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.io.IOException;
import java.util.List;
import java.util.stream.IntStream;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestPartitionRecord {
@@ -40,7 +40,7 @@ public class TestPartitionRecord {
private MockRecordParser readerService;
private MockRecordWriter writerService;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
readerService = new MockRecordParser();
writerService = new MockRecordWriter(null, false);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutDistributedMapCache.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutDistributedMapCache.java
index b6a9be1644..04c2e18799 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutDistributedMapCache.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutDistributedMapCache.java
@@ -16,7 +16,16 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.distributed.cache.client.Deserializer;
+import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient;
+import org.apache.nifi.distributed.cache.client.Serializer;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
@@ -28,23 +37,14 @@ import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.nifi.controller.AbstractControllerService;
-import org.apache.nifi.distributed.cache.client.Deserializer;
-import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient;
-import org.apache.nifi.distributed.cache.client.Serializer;
-import org.apache.nifi.reporting.InitializationException;
-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 static org.junit.jupiter.api.Assertions.assertEquals;
public class TestPutDistributedMapCache {
private TestRunner runner;
private MockCacheClient service;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(PutDistributedMapCache.class);
@@ -55,7 +55,7 @@ public class TestPutDistributedMapCache {
}
@Test
- public void testNoCacheKey() throws InitializationException {
+ public void testNoCacheKey() {
runner.setProperty(PutDistributedMapCache.CACHE_ENTRY_IDENTIFIER, "${cacheKeyAttribute}");
runner.enqueue(new byte[] {});
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
index 464526d2e1..05f8b1b4da 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
@@ -28,8 +28,8 @@ import org.apache.commons.io.IOUtils;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
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.io.InputStream;
import java.nio.charset.StandardCharsets;
@@ -38,10 +38,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-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.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class TestPutEmail {
@@ -81,7 +81,7 @@ public class TestPutEmail {
PutEmailExtension processor;
TestRunner runner;
- @Before
+ @BeforeEach
public void setup() {
processor = new PutEmailExtension();
runner = TestRunners.newTestRunner(processor);
@@ -104,7 +104,7 @@ public class TestPutEmail {
runner.assertQueueEmpty();
runner.assertAllFlowFilesTransferred(PutEmail.REL_FAILURE);
- assertEquals("Expected an attempt to send a single message", 1, processor.getMessages().size());
+ assertEquals(1, processor.getMessages().size(), "Expected an attempt to send a single message");
}
@Test
@@ -124,10 +124,10 @@ public class TestPutEmail {
runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
// Verify that the Message was populated correctly
- assertEquals("Expected a single message to be sent", 1, processor.getMessages().size());
+ assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
Message message = processor.getMessages().get(0);
assertEquals("test@apache.org", message.getFrom()[0].toString());
- assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
+ assertEquals("TestingNiFi", message.getHeader("X-Mailer")[0], "X-Mailer Header");
assertEquals("Message Body", message.getContent());
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertNull(message.getRecipients(RecipientType.BCC));
@@ -162,10 +162,10 @@ public class TestPutEmail {
runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
// Verify that the Message was populated correctly
- assertEquals("Expected a single message to be sent", 1, processor.getMessages().size());
+ assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
Message message = processor.getMessages().get(0);
assertEquals("\"test@apache.org\" <NiFi>", message.getFrom()[0].toString());
- assertEquals("X-Mailer Header", "TestingNíFiNonASCII", MimeUtility.decodeText(message.getHeader("X-Mailer")[0]));
+ assertEquals("TestingNíFiNonASCII", MimeUtility.decodeText(message.getHeader("X-Mailer")[0]), "X-Mailer Header");
assertEquals("the message body", message.getContent());
assertEquals(1, message.getRecipients(RecipientType.TO).length);
assertEquals("to@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
@@ -191,7 +191,7 @@ public class TestPutEmail {
runner.assertQueueEmpty();
runner.assertAllFlowFilesTransferred(PutEmail.REL_FAILURE);
- assertEquals("Expected no messages to be sent", 0, processor.getMessages().size());
+ assertEquals(0, processor.getMessages().size(), "Expected no messages to be sent");
}
@Test
@@ -209,7 +209,7 @@ public class TestPutEmail {
runner.assertQueueEmpty();
runner.assertAllFlowFilesTransferred(PutEmail.REL_FAILURE);
- assertEquals("Expected no messages to be sent", 0, processor.getMessages().size());
+ assertEquals(0, processor.getMessages().size(), "Expected no messages to be sent");
assertFalse(runner.getLogger().getErrorMessages().isEmpty());
}
@@ -231,13 +231,13 @@ public class TestPutEmail {
runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
// Verify that the Message was populated correctly
- assertEquals("Expected a single message to be sent", 1, processor.getMessages().size());
+ assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
Message message = processor.getMessages().get(0);
assertEquals("test@apache.org", message.getFrom()[0].toString());
- assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
+ assertEquals("TestingNiFi", message.getHeader("X-Mailer")[0], "X-Mailer Header");
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
- assertTrue(message.getContent() instanceof MimeMultipart);
+ assertInstanceOf(MimeMultipart.class, message.getContent());
final MimeMultipart multipart = (MimeMultipart) message.getContent();
final BodyPart part = multipart.getBodyPart(0);
@@ -275,11 +275,11 @@ public class TestPutEmail {
runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
// Verify that the Message was populated correctly
- assertEquals("Expected a single message to be sent", 1, processor.getMessages().size());
+ assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
Message message = processor.getMessages().get(0);
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("from@apache.org", message.getFrom()[1].toString());
- assertEquals("X-Mailer Header", "TestingNiFi", message.getHeader("X-Mailer")[0]);
+ assertEquals("TestingNiFi", message.getHeader("X-Mailer")[0], "X-Mailer Header");
assertEquals("Some Text", message.getContent());
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
assertEquals("another@apache.org", message.getRecipients(RecipientType.TO)[1].toString());
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java
index a6ea1cec8c..93812afbd0 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutFile.java
@@ -16,16 +16,14 @@
*/
package org.apache.nifi.processors.standard;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.io.File;
import java.io.IOException;
@@ -41,19 +39,17 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test only runs on *nix")
public class TestPutFile {
public static final String TARGET_DIRECTORY = "target/put-file";
private File targetDir;
- @BeforeClass
- public static void setUpSuite() {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
- }
-
- @Before
+ @BeforeEach
public void prepDestDirectory() throws IOException {
targetDir = new File(TARGET_DIRECTORY);
if (!targetDir.exists()) {
@@ -109,21 +105,14 @@ public class TestPutFile {
assertEquals("Hello world!!", new String(content));
}
- @Test(expected = AssertionError.class)
- public void testCreateEmptyStringDirectory() throws IOException {
+ @Test
+ public void testCreateEmptyStringDirectory() {
final TestRunner runner = TestRunners.newTestRunner(new PutFile());
String newDir = "";
runner.setProperty(PutFile.DIRECTORY, newDir);
runner.setProperty(PutFile.CONFLICT_RESOLUTION, PutFile.REPLACE_RESOLUTION);
- Map<String, String> attributes = new HashMap<>();
- attributes.put(CoreAttributes.FILENAME.key(), "targetFile.txt");
- runner.enqueue("Hello world!!".getBytes(), attributes);
- runner.run();
- runner.assertAllFlowFilesTransferred(FetchFile.REL_SUCCESS, 1);
- Path targetPath = Paths.get(newDir + "/targetFile.txt");
- byte[] content = Files.readAllBytes(targetPath);
- assertEquals("Hello world!!", new String(content));
+ runner.assertNotValid();
}
@Test
@@ -260,8 +249,8 @@ public class TestPutFile {
private final String testFile = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "hello.txt";
- @Before
- public void setup() throws IOException{
+ @BeforeEach
+ public void setup() throws IOException {
putFileRunner = TestRunners.newTestRunner(PutFile.class);
putFileRunner.setProperty(PutFile.CHANGE_OWNER, System.getProperty("user.name"));
@@ -272,7 +261,7 @@ public class TestPutFile {
putFileRunner.setValidateExpressionUsage(false);
}
- @After
+ @AfterEach
public void tearDown() throws IOException {
emptyTestDirectory();
}
@@ -292,34 +281,34 @@ public class TestPutFile {
//verify directory exists
Path newDirectory = Paths.get("target/test/data/out/PutFile/1/2/3/4/5");
Path newFile = newDirectory.resolve("testfile.txt");
- Assert.assertTrue("New directory not created.", newDirectory.toAbsolutePath().toFile().exists());
- Assert.assertTrue("New File not created.", newFile.toAbsolutePath().toFile().exists());
+ assertTrue(newDirectory.toAbsolutePath().toFile().exists(), "New directory not created.");
+ assertTrue(newFile.toAbsolutePath().toFile().exists(), "New File not created.");
PosixFileAttributeView filePosixAttributeView = Files.getFileAttributeView(newFile.toAbsolutePath(), PosixFileAttributeView.class);
- Assert.assertEquals(System.getProperty("user.name"), filePosixAttributeView.getOwner().getName());
+ assertEquals(System.getProperty("user.name"), filePosixAttributeView.getOwner().getName());
Set<PosixFilePermission> filePermissions = filePosixAttributeView.readAttributes().permissions();
- Assert.assertTrue(filePermissions.contains(PosixFilePermission.OWNER_READ));
- Assert.assertTrue(filePermissions.contains(PosixFilePermission.OWNER_WRITE));
- Assert.assertFalse(filePermissions.contains(PosixFilePermission.OWNER_EXECUTE));
- Assert.assertTrue(filePermissions.contains(PosixFilePermission.GROUP_READ));
- Assert.assertFalse(filePermissions.contains(PosixFilePermission.GROUP_WRITE));
- Assert.assertFalse(filePermissions.contains(PosixFilePermission.GROUP_EXECUTE));
- Assert.assertFalse(filePermissions.contains(PosixFilePermission.OTHERS_READ));
- Assert.assertFalse(filePermissions.contains(PosixFilePermission.OTHERS_WRITE));
- Assert.assertFalse(filePermissions.contains(PosixFilePermission.OTHERS_EXECUTE));
+ assertTrue(filePermissions.contains(PosixFilePermission.OWNER_READ));
+ assertTrue(filePermissions.contains(PosixFilePermission.OWNER_WRITE));
+ assertFalse(filePermissions.contains(PosixFilePermission.OWNER_EXECUTE));
+ assertTrue(filePermissions.contains(PosixFilePermission.GROUP_READ));
+ assertFalse(filePermissions.contains(PosixFilePermission.GROUP_WRITE));
+ assertFalse(filePermissions.contains(PosixFilePermission.GROUP_EXECUTE));
+ assertFalse(filePermissions.contains(PosixFilePermission.OTHERS_READ));
+ assertFalse(filePermissions.contains(PosixFilePermission.OTHERS_WRITE));
+ assertFalse(filePermissions.contains(PosixFilePermission.OTHERS_EXECUTE));
PosixFileAttributeView dirPosixAttributeView = Files.getFileAttributeView(newDirectory.toAbsolutePath(), PosixFileAttributeView.class);
- Assert.assertEquals(System.getProperty("user.name"), dirPosixAttributeView.getOwner().getName());
+ assertEquals(System.getProperty("user.name"), dirPosixAttributeView.getOwner().getName());
Set<PosixFilePermission> dirPermissions = dirPosixAttributeView.readAttributes().permissions();
- Assert.assertTrue(dirPermissions.contains(PosixFilePermission.OWNER_READ));
- Assert.assertTrue(dirPermissions.contains(PosixFilePermission.OWNER_WRITE));
- Assert.assertTrue(dirPermissions.contains(PosixFilePermission.OWNER_EXECUTE));
- Assert.assertTrue(dirPermissions.contains(PosixFilePermission.GROUP_READ));
- Assert.assertFalse(dirPermissions.contains(PosixFilePermission.GROUP_WRITE));
- Assert.assertTrue(dirPermissions.contains(PosixFilePermission.GROUP_EXECUTE));
- Assert.assertFalse(dirPermissions.contains(PosixFilePermission.OTHERS_READ));
- Assert.assertFalse(dirPermissions.contains(PosixFilePermission.OTHERS_WRITE));
- Assert.assertFalse(dirPermissions.contains(PosixFilePermission.OTHERS_EXECUTE));
+ assertTrue(dirPermissions.contains(PosixFilePermission.OWNER_READ));
+ assertTrue(dirPermissions.contains(PosixFilePermission.OWNER_WRITE));
+ assertTrue(dirPermissions.contains(PosixFilePermission.OWNER_EXECUTE));
+ assertTrue(dirPermissions.contains(PosixFilePermission.GROUP_READ));
+ assertFalse(dirPermissions.contains(PosixFilePermission.GROUP_WRITE));
+ assertTrue(dirPermissions.contains(PosixFilePermission.GROUP_EXECUTE));
+ assertFalse(dirPermissions.contains(PosixFilePermission.OTHERS_READ));
+ assertFalse(dirPermissions.contains(PosixFilePermission.OTHERS_WRITE));
+ assertFalse(dirPermissions.contains(PosixFilePermission.OTHERS_EXECUTE));
putFileRunner.clearTransferState();
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutJMS.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutJMS.java
index dd591855f4..1a8005577b 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutJMS.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutJMS.java
@@ -16,27 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doThrow;
-import static org.mockito.Mockito.spy;
-
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
-import java.util.concurrent.LinkedBlockingQueue;
-import javax.jms.Connection;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.processors.standard.util.JmsFactory;
@@ -46,13 +25,36 @@ import org.apache.nifi.provenance.ProvenanceEventRecord;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+import java.util.Set;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.spy;
+
@SuppressWarnings("deprecation")
-@Ignore("Processor requires updates to work with Mockito 2.x, but is deprecated.")
+@Disabled("Processor requires updates to work with Mockito 2.x, but is deprecated.")
public class TestPutJMS {
private final String TEST_PROVIDER = JmsProperties.ACTIVEMQ_PROVIDER;
@@ -141,7 +143,7 @@ public class TestPutJMS {
}
@Test
- public void testPutGetAttributesAndProps() throws JMSException {
+ public void testPutGetAttributesAndProps() {
final PutJMS putJMS = spy(new PutJMS());
final TestRunner runnerPut = TestRunners.newTestRunner(putJMS);
runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
@@ -217,7 +219,7 @@ public class TestPutJMS {
}
@Test
- public void testPutGetMessageTypes() throws JMSException {
+ public void testPutGetMessageTypes() {
final GetJMSQueue getJmsQueue = new GetJMSQueue();
final TestRunner runnerGet = TestRunners.newTestRunner(getJmsQueue);
runnerGet.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
@@ -357,7 +359,7 @@ public class TestPutJMS {
}
@Test
- public void testTTL() throws JMSException, InterruptedException {
+ public void testTTL() throws InterruptedException {
final PutJMS putJMS = spy(new PutJMS());
final TestRunner runnerPut = TestRunners.newTestRunner(putJMS);
runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
@@ -409,7 +411,7 @@ public class TestPutJMS {
}
@Test
- public void testFailureOnFileExceedsBufferSize() throws JMSException {
+ public void testFailureOnFileExceedsBufferSize() {
final PutJMS putJMS = spy(new PutJMS());
final TestRunner runnerPut = TestRunners.newTestRunner(putJMS);
runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
@@ -428,8 +430,8 @@ public class TestPutJMS {
assertEquals(0, runnerPut.getFlowFilesForRelationship(PutJMS.REL_SUCCESS).size());
}
- @Test(expected = NumberFormatException.class)
- public void testBadMessagePriorityValueFails() throws JMSException {
+ @Test
+ public void testBadMessagePriorityValueFails() {
final PutJMS putJMS = spy(new PutJMS());
final TestRunner runnerPut = TestRunners.newTestRunner(putJMS);
runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
@@ -437,11 +439,14 @@ public class TestPutJMS {
runnerPut.setProperty(JmsProperties.DESTINATION_TYPE, TEST_DEST_TYPE);
runnerPut.setProperty(JmsProperties.DESTINATION_NAME, TEST_DEST_NAME + testQueueSuffix());
runnerPut.setProperty(JmsProperties.MESSAGE_PRIORITY, "negative one");
- assertEquals(PutJMS.DEFAULT_MESSAGE_PRIORITY, runnerPut.getProcessContext().getProperty(JmsProperties.MESSAGE_PRIORITY).asInteger().intValue());
+ assertThrows(NumberFormatException.class, () -> {
+ assertEquals(PutJMS.DEFAULT_MESSAGE_PRIORITY, runnerPut.getProcessContext().getProperty(JmsProperties.MESSAGE_PRIORITY).asInteger().intValue());
+ });
+
}
@Test
- public void testBadMessagePriorityRunSucceeds() throws JMSException {
+ public void testBadMessagePriorityRunSucceeds() {
final PutJMS putJMS = spy(new PutJMS());
final TestRunner runnerPut = TestRunners.newTestRunner(putJMS);
runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
@@ -566,7 +571,7 @@ public class TestPutJMS {
}
@Test
- public void testPutProvenanceSendEventTransitUri() throws JMSException {
+ public void testPutProvenanceSendEventTransitUri() {
final PutJMS putJMS = spy(new PutJMS());
final TestRunner runnerPut = TestRunners.newTestRunner(putJMS);
runnerPut.setProperty(JmsProperties.JMS_PROVIDER, TEST_PROVIDER);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java
index 3a3c8395c2..07b302a283 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java
@@ -21,11 +21,11 @@ import org.apache.nifi.serialization.record.MockRecordParser;
import org.apache.nifi.serialization.record.RecordFieldType;
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 static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestPutRecord {
@@ -33,7 +33,7 @@ public class TestPutRecord {
private MockRecordParser recordReader;
private MockRecordSinkService mockRecordSinkService;
- @Before
+ @BeforeEach
public void setup() {
PutRecord processor = new PutRecord();
testRunner = TestRunners.newTestRunner(processor);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java
index b1dce43e92..640c5c638c 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java
@@ -16,17 +16,28 @@
*/
package org.apache.nifi.processors.standard;
-import static org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult.ACCEPT_AND_CONTINUE;
-import static org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult.ACCEPT_AND_TERMINATE;
-import static org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult.REJECT_AND_CONTINUE;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.nifi.controller.AbstractControllerService;
+import org.apache.nifi.dbcp.DBCPService;
+import org.apache.nifi.processor.FlowFileFilter;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.pattern.RollbackOnFailure;
+import org.apache.nifi.provenance.ProvenanceEventRecord;
+import org.apache.nifi.provenance.ProvenanceEventType;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+import javax.xml.bind.DatatypeConverter;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@@ -41,40 +52,29 @@ import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import java.util.function.Function;
-import javax.xml.bind.DatatypeConverter;
-
-import org.apache.commons.lang3.RandomUtils;
-import org.apache.nifi.controller.AbstractControllerService;
-import org.apache.nifi.dbcp.DBCPService;
-import org.apache.nifi.processor.FlowFileFilter;
-import org.apache.nifi.processor.exception.ProcessException;
-import org.apache.nifi.processor.util.pattern.RollbackOnFailure;
-import org.apache.nifi.provenance.ProvenanceEventRecord;
-import org.apache.nifi.provenance.ProvenanceEventType;
-import org.apache.nifi.reporting.InitializationException;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.mockito.Mockito;
+import static org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult.ACCEPT_AND_CONTINUE;
+import static org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult.ACCEPT_AND_TERMINATE;
+import static org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult.REJECT_AND_CONTINUE;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestPutSQL {
private static final String createPersons = "CREATE TABLE PERSONS (id integer primary key, name varchar(100), code integer)";
private static final String createPersonsAutoId = "CREATE TABLE PERSONS_AI (id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1), name VARCHAR(100), code INTEGER check(code <= 100))";
- @ClassRule
- public static TemporaryFolder folder = new TemporaryFolder();
+ private static final String DERBY_LOG_PROPERTY = "derby.stream.error.file";
/**
* Setting up Connection pooling is expensive operation.
@@ -82,11 +82,11 @@ public class TestPutSQL {
*/
static protected DBCPService service;
- @BeforeClass
- public static void setupClass() throws ProcessException, SQLException {
- System.setProperty("derby.stream.error.file", "target/derby.log");
- final File tempDir = folder.getRoot();
- final File dbDir = new File(tempDir, "db");
+ @BeforeAll
+ public static void setupDerbyLog() throws ProcessException, SQLException {
+ System.setProperty(DERBY_LOG_PROPERTY, "target/derby.log");
+ final File dbDir = new File(getEmptyDirectory(), "db");
+ dbDir.deleteOnExit();
service = new MockDBCPService(dbDir.getAbsolutePath());
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -96,8 +96,13 @@ public class TestPutSQL {
}
}
+ @AfterAll
+ public static void cleanupDerbyLog() {
+ System.clearProperty(DERBY_LOG_PROPERTY);
+ }
+
@Test
- public void testDirectStatements() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testDirectStatements() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
recreateTable("PERSONS", createPersons);
@@ -338,14 +343,12 @@ public class TestPutSQL {
runner.enqueue("INSERT INTO PERSONS_AI (NAME, CODE) VALUES ('Tom', 3)".getBytes());
runner.enqueue("INSERT INTO PERSONS_AI (NAME, CODE) VALUES ('Harry', 44)".getBytes());
- try {
- runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- runner.assertTransferCount(PutSQL.REL_FAILURE, 0);
- runner.assertTransferCount(PutSQL.REL_SUCCESS, 0);
- }
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
+ runner.assertTransferCount(PutSQL.REL_FAILURE, 0);
+ runner.assertTransferCount(PutSQL.REL_SUCCESS, 0);
}
@Test
@@ -369,7 +372,7 @@ public class TestPutSQL {
runner.assertTransferCount(PutSQL.REL_SUCCESS, 0);
}
- private void testFailInMiddleWithBadParameterType(final TestRunner runner) throws InitializationException, ProcessException, SQLException, IOException {
+ private void testFailInMiddleWithBadParameterType(final TestRunner runner) throws InitializationException, ProcessException {
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
final Map<String, String> goodAttributes = new HashMap<>();
@@ -388,7 +391,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterTypeRollbackOnFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testFailInMiddleWithBadParameterTypeRollbackOnFailure() throws InitializationException, ProcessException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
@@ -407,14 +410,12 @@ public class TestPutSQL {
runner.enqueue(data, goodAttributes);
runner.enqueue(data, goodAttributes);
- try {
- runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- runner.assertTransferCount(PutSQL.REL_FAILURE, 0);
- runner.assertTransferCount(PutSQL.REL_SUCCESS, 0);
- }
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
+ runner.assertTransferCount(PutSQL.REL_FAILURE, 0);
+ runner.assertTransferCount(PutSQL.REL_SUCCESS, 0);
}
@Test
@@ -436,7 +437,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterValueAndNotSupportTransaction() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testFailInMiddleWithBadParameterValueAndNotSupportTransaction() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
testFailInMiddleWithBadParameterValue(runner);
@@ -458,7 +459,7 @@ public class TestPutSQL {
}
}
- private void testFailInMiddleWithBadParameterValue(final TestRunner runner) throws InitializationException, ProcessException, SQLException, IOException {
+ private void testFailInMiddleWithBadParameterValue(final TestRunner runner) throws ProcessException, SQLException {
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
recreateTable("PERSONS_AI",createPersonsAutoId);
final Map<String, String> goodAttributes = new HashMap<>();
@@ -477,7 +478,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterValueRollbackOnFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testFailInMiddleWithBadParameterValueRollbackOnFailure() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
@@ -498,14 +499,12 @@ public class TestPutSQL {
runner.enqueue(data, goodAttributes);
runner.enqueue(data, goodAttributes);
- try {
- runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- runner.assertTransferCount(PutSQL.REL_FAILURE, 0);
- runner.assertTransferCount(PutSQL.REL_SUCCESS, 0);
- }
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
+ runner.assertTransferCount(PutSQL.REL_FAILURE, 0);
+ runner.assertTransferCount(PutSQL.REL_SUCCESS, 0);
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -517,7 +516,7 @@ public class TestPutSQL {
@Test
- public void testUsingSqlDataTypesWithNegativeValues() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testUsingSqlDataTypesWithNegativeValues() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -547,7 +546,7 @@ public class TestPutSQL {
// Not specifying a format for the date fields here to continue to test backwards compatibility
@Test
- public void testUsingTimestampValuesEpochAndString() throws InitializationException, ProcessException, SQLException, IOException, ParseException {
+ public void testUsingTimestampValuesEpochAndString() throws InitializationException, ProcessException, SQLException, ParseException {
final TestRunner runner = initTestRunner();
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -584,7 +583,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingTimestampValuesWithFormatAttribute() throws InitializationException, ProcessException, SQLException, IOException, ParseException {
+ public void testUsingTimestampValuesWithFormatAttribute() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -628,7 +627,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingDateTimeValuesWithFormatAttribute() throws InitializationException, ProcessException, SQLException, IOException, ParseException {
+ public void testUsingDateTimeValuesWithFormatAttribute() throws InitializationException, ProcessException, SQLException, ParseException {
final TestRunner runner = initTestRunner();
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -833,7 +832,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingTimeValuesEpochAndString() throws InitializationException, ProcessException, SQLException, IOException, ParseException {
+ public void testUsingTimeValuesEpochAndString() throws InitializationException, ProcessException, SQLException, ParseException {
final TestRunner runner = initTestRunner();
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -874,7 +873,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingDateValuesEpochAndString() throws InitializationException, ProcessException, SQLException, IOException, ParseException {
+ public void testUsingDateValuesEpochAndString() throws InitializationException, ProcessException, SQLException, ParseException {
final TestRunner runner = initTestRunner();
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -911,7 +910,7 @@ public class TestPutSQL {
}
@Test
- public void testBinaryColumnTypes() throws InitializationException, ProcessException, SQLException, IOException, ParseException {
+ public void testBinaryColumnTypes() throws InitializationException, ProcessException, SQLException, IOException {
final TestRunner runner = initTestRunner();
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -1006,30 +1005,30 @@ public class TestPutSQL {
//First Batch
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
- assertTrue(Arrays.equals(arg2BIN.getBytes("ASCII"), rs.getBytes(2)));
- assertTrue(Arrays.equals(art3VARBIN.getBytes("ASCII"), rs.getBytes(3)));
- assertTrue(Arrays.equals(art4LongBin.getBytes("ASCII"), rs.getBytes(4)));
+ assertArrayEquals(arg2BIN.getBytes("ASCII"), rs.getBytes(2));
+ assertArrayEquals(art3VARBIN.getBytes("ASCII"), rs.getBytes(3));
+ assertArrayEquals(art4LongBin.getBytes("ASCII"), rs.getBytes(4));
//Second batch
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
- assertTrue(Arrays.equals(arg2BIN.getBytes("ASCII"), rs.getBytes(2)));
- assertTrue(Arrays.equals(art3VARBIN.getBytes("ASCII"), rs.getBytes(3)));
- assertTrue(Arrays.equals(art4LongBin.getBytes("ASCII"), rs.getBytes(4)));
+ assertArrayEquals(arg2BIN.getBytes("ASCII"), rs.getBytes(2));
+ assertArrayEquals(art3VARBIN.getBytes("ASCII"), rs.getBytes(3));
+ assertArrayEquals(art4LongBin.getBytes("ASCII"), rs.getBytes(4));
//Third Batch (Hex)
assertTrue(rs.next());
assertEquals(3, rs.getInt(1));
- assertTrue(Arrays.equals(DatatypeConverter.parseHexBinary(arg2HexBIN), rs.getBytes(2)));
- assertTrue(Arrays.equals(DatatypeConverter.parseHexBinary(art3HexVARBIN), rs.getBytes(3)));
- assertTrue(Arrays.equals(DatatypeConverter.parseHexBinary(art4HexLongBin), rs.getBytes(4)));
+ assertArrayEquals(DatatypeConverter.parseHexBinary(arg2HexBIN), rs.getBytes(2));
+ assertArrayEquals(DatatypeConverter.parseHexBinary(art3HexVARBIN), rs.getBytes(3));
+ assertArrayEquals(DatatypeConverter.parseHexBinary(art4HexLongBin), rs.getBytes(4));
//Fourth Batch (Base64)
assertTrue(rs.next());
assertEquals(4, rs.getInt(1));
- assertTrue(Arrays.equals(DatatypeConverter.parseBase64Binary(arg2Base64BIN), rs.getBytes(2)));
- assertTrue(Arrays.equals(DatatypeConverter.parseBase64Binary(art3Base64VARBIN), rs.getBytes(3)));
- assertTrue(Arrays.equals(DatatypeConverter.parseBase64Binary(art4Base64LongBin), rs.getBytes(4)));
+ assertArrayEquals(DatatypeConverter.parseBase64Binary(arg2Base64BIN), rs.getBytes(2));
+ assertArrayEquals(DatatypeConverter.parseBase64Binary(art3Base64VARBIN), rs.getBytes(3));
+ assertArrayEquals(DatatypeConverter.parseBase64Binary(art4Base64LongBin), rs.getBytes(4));
assertFalse(rs.next());
}
@@ -1037,7 +1036,7 @@ public class TestPutSQL {
}
@Test
- public void testStatementsWithPreparedParameters() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testStatementsWithPreparedParameters() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
recreateTable("PERSONS", createPersons);
@@ -1152,12 +1151,10 @@ public class TestPutSQL {
attributes.put("sql.args.4.value", "1");
runner.enqueue(sql.getBytes(), attributes);
- try {
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- }
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -1169,7 +1166,7 @@ public class TestPutSQL {
@Test
- public void testWithNullParameter() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testWithNullParameter() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
final Map<String, String> attributes = new HashMap<>();
attributes.put("sql.args.1.type", String.valueOf(Types.INTEGER));
@@ -1198,7 +1195,7 @@ public class TestPutSQL {
}
@Test
- public void testInvalidStatement() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testInvalidStatement() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
recreateTable("PERSONS", createPersons);
@@ -1233,7 +1230,7 @@ public class TestPutSQL {
}
@Test
- public void testInvalidStatementRollbackOnFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testInvalidStatementRollbackOnFailure() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
@@ -1255,12 +1252,10 @@ public class TestPutSQL {
attributes.put("sql.args.4.value", "1");
runner.enqueue(sql.getBytes(), attributes);
- try {
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- }
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
@@ -1272,7 +1267,7 @@ public class TestPutSQL {
@Test
- public void testRetryableFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testRetryableFailure() throws InitializationException, ProcessException {
final TestRunner runner = TestRunners.newTestRunner(PutSQL.class);
final DBCPService service = new SQLExceptionService(null);
runner.addControllerService("dbcp", service);
@@ -1303,7 +1298,7 @@ public class TestPutSQL {
}
@Test
- public void testRetryableFailureRollbackOnFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testRetryableFailureRollbackOnFailure() throws InitializationException, ProcessException {
final TestRunner runner = TestRunners.newTestRunner(PutSQL.class);
final DBCPService service = new SQLExceptionService(null);
runner.addControllerService("dbcp", service);
@@ -1328,19 +1323,15 @@ public class TestPutSQL {
attributes.put("sql.args.4.value", "1");
runner.enqueue(sql.getBytes(), attributes);
- try {
- runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- // Should not be routed to retry.
- runner.assertAllFlowFilesTransferred(PutSQL.REL_RETRY, 0);
- }
-
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
+ runner.assertAllFlowFilesTransferred(PutSQL.REL_RETRY, 0);
}
@Test
- public void testMultipleFlowFilesSuccessfulInTransaction() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testMultipleFlowFilesSuccessfulInTransaction() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.BATCH_SIZE, "1");
@@ -1395,7 +1386,7 @@ public class TestPutSQL {
}
@Test
- public void testMultipleFlowFilesSuccessfulInTransactionRollBackOnFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testMultipleFlowFilesSuccessfulInTransactionRollBackOnFailure() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.BATCH_SIZE, "1");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
@@ -1425,7 +1416,7 @@ public class TestPutSQL {
}
@Test
- public void testTransactionTimeout() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testTransactionTimeout() throws InitializationException, ProcessException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.TRANSACTION_TIMEOUT, "5 secs");
@@ -1459,7 +1450,7 @@ public class TestPutSQL {
}
@Test
- public void testTransactionTimeoutRollbackOnFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testTransactionTimeoutRollbackOnFailure() throws InitializationException, ProcessException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.TRANSACTION_TIMEOUT, "5 secs");
@@ -1487,18 +1478,16 @@ public class TestPutSQL {
};
runner.enqueue(mff);
- try {
- runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- }
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
runner.assertAllFlowFilesTransferred(PutSQL.REL_FAILURE, 0);
}
@Test
- public void testNullFragmentCountRollbackOnFailure() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testNullFragmentCountRollbackOnFailure() throws InitializationException, ProcessException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.TRANSACTION_TIMEOUT, "5 secs");
@@ -1516,19 +1505,16 @@ public class TestPutSQL {
runner.enqueue(new byte[]{}, attribute1);
runner.enqueue(new byte[]{}, attribute2);
-
- try {
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
runner.run();
- fail("ProcessException should be thrown");
- } catch (AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- }
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
runner.assertAllFlowFilesTransferred(PutSQL.REL_FAILURE, 0);
}
@Test
- public void testStatementsFromProperty() throws InitializationException, ProcessException, SQLException, IOException {
+ public void testStatementsFromProperty() throws InitializationException, ProcessException, SQLException {
final TestRunner runner = initTestRunner();
runner.setProperty(PutSQL.SQL_STATEMENT, "INSERT INTO PERSONS (ID, NAME, CODE) VALUES (${row.id}, 'Mark', 84)");
@@ -1737,4 +1723,12 @@ public class TestPutSQL {
return runner;
}
+ private static File getEmptyDirectory() {
+ final String randomDirectory = String.format("%s-%s", TestPutSQL.class.getSimpleName(), UUID.randomUUID());
+ return Paths.get(getSystemTemporaryDirectory(), randomDirectory).toFile();
+ }
+
+ private static String getSystemTemporaryDirectory() {
+ return System.getProperty("java.io.tmpdir");
+ }
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSyslog.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSyslog.java
index 03d15aba63..d3fdc112de 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSyslog.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSyslog.java
@@ -28,8 +28,8 @@ import org.apache.nifi.provenance.ProvenanceEventType;
import org.apache.nifi.remote.io.socket.NetworkUtils;
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.net.InetAddress;
import java.net.UnknownHostException;
@@ -42,10 +42,10 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestPutSyslog {
private static final String ADDRESS = "127.0.0.1";
@@ -82,7 +82,7 @@ public class TestPutSyslog {
private int port;
- @Before
+ @BeforeEach
public void setRunner() throws UnknownHostException {
address = InetAddress.getByName(ADDRESS);
port = NetworkUtils.getAvailableUdpPort();
@@ -159,14 +159,14 @@ public class TestPutSyslog {
private void assertProvenanceRecordTransitUriFound() {
final List<ProvenanceEventRecord> provenanceEvents = runner.getProvenanceEvents();
- assertFalse("Provenance Events not found", provenanceEvents.isEmpty());
+ assertFalse(provenanceEvents.isEmpty(), "Provenance Events not found");
final ProvenanceEventRecord provenanceEventRecord = provenanceEvents.iterator().next();
assertEquals(ProvenanceEventType.SEND, provenanceEventRecord.getEventType());
final String transitUri = provenanceEventRecord.getTransitUri();
- assertNotNull("Transit URI not found", transitUri);
- assertTrue("Transit URI Protocol not found", transitUri.contains(DEFAULT_PROTOCOL));
- assertTrue("Transit URI Hostname not found", transitUri.contains(ADDRESS));
- assertTrue("Transit URI Port not found", transitUri.contains(Integer.toString(port)));
+ assertNotNull(transitUri, "Transit URI not found");
+ assertTrue(transitUri.contains(DEFAULT_PROTOCOL), "Transit URI Protocol not found");
+ assertTrue(transitUri.contains(ADDRESS), "Transit URI Hostname not found");
+ assertTrue(transitUri.contains(Integer.toString(port)), "Transit URI Port not found");
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutTCP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutTCP.java
index 549c3a0d58..9a0eceaa09 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutTCP.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutTCP.java
@@ -31,11 +31,10 @@ import org.apache.nifi.ssl.SSLContextService;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.web.util.ssl.SslContextUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.Timeout;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito;
import javax.net.ssl.SSLContext;
@@ -43,12 +42,12 @@ import java.net.InetAddress;
import java.util.Arrays;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+@Timeout(30)
public class TestPutTCP {
private final static String TCP_SERVER_ADDRESS = "127.0.0.1";
private final static String SERVER_VARIABLE = "server.address";
@@ -69,22 +68,19 @@ public class TestPutTCP {
private final static String[] EMPTY_FILE = { "" };
private final static String[] VALID_FILES = { "abcdefghijklmnopqrstuvwxyz", "zyxwvutsrqponmlkjihgfedcba", "12345678", "343424222", "!@£$%^&*()_+:|{}[];\\" };
- @Rule
- public Timeout timeout = new Timeout(30, TimeUnit.SECONDS);
-
private EventServer eventServer;
private int port;
private TestRunner runner;
private BlockingQueue<ByteArrayMessage> messages;
- @Before
+ @BeforeEach
public void setup() throws Exception {
runner = TestRunners.newTestRunner(PutTCP.class);
runner.setVariable(SERVER_VARIABLE, TCP_SERVER_ADDRESS);
port = NetworkUtils.getAvailableTcpPort();
}
- @After
+ @AfterEach
public void cleanup() {
runner.shutdown();
shutdownServer();
@@ -118,7 +114,7 @@ public class TestPutTCP {
final TlsConfiguration tlsConfiguration = new TemporaryKeyStoreBuilder().build();
final SSLContext sslContext = SslContextUtils.createSslContext(tlsConfiguration);
- assertNotNull("SSLContext not found", sslContext);
+ assertNotNull(sslContext, "SSLContext not found");
final String identifier = SSLContextService.class.getName();
final SSLContextService sslContextService = Mockito.mock(SSLContextService.class);
Mockito.when(sslContextService.getIdentifier()).thenReturn(identifier);
@@ -279,7 +275,7 @@ public class TestPutTCP {
for (int i = 0; i < iterations; i++) {
for (String item : sentData) {
final ByteArrayMessage message = messages.take();
- assertNotNull(String.format("Message [%d] not found", i), message);
+ assertNotNull(message, String.format("Message [%d] not found", i));
assertTrue(Arrays.asList(sentData).contains(new String(message.getMessage())));
}
}
@@ -287,7 +283,7 @@ public class TestPutTCP {
runner.assertTransferCount(PutTCP.REL_SUCCESS, sentData.length * iterations);
runner.clearTransferState();
- assertNull("Unexpected extra messages found", messages.poll());
+ assertNull(messages.poll(), "Unexpected extra messages found");
}
private String[] createContent(final int size) {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java
index 341487b89a..20f6dca199 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java
@@ -41,7 +41,7 @@ import org.apache.nifi.serialization.record.RecordSet;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.OutputStream;
@@ -50,8 +50,8 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -59,18 +59,11 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestQueryRecord {
- static {
- System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
- System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
- System.setProperty("org.slf4j.simpleLogger.log.nifi.io.nio", "debug");
- System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.standard.SQLTransform", "debug");
- }
-
private static final String REL_NAME = "success";
private static final String ISO_DATE = "2018-02-04";
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
index ad92319865..1b5b6e53e5 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
@@ -19,10 +19,7 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assert;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@@ -36,10 +33,12 @@ import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
-public class TestReplaceText {
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
- @Rule
- public ExpectedException exception = ExpectedException.none();
+public class TestReplaceText {
public TestRunner getRunner() {
TestRunner runner = TestRunners.newTestRunner(ReplaceText.class);
@@ -307,7 +306,7 @@ public class TestReplaceText {
}
@Test
- public void testAppendWithCarriageReturn() throws IOException {
+ public void testAppendWithCarriageReturn() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -323,7 +322,7 @@ public class TestReplaceText {
@Test
- public void testAppendFirstLineWithCarriageReturn() throws IOException {
+ public void testAppendFirstLineWithCarriageReturn() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -339,7 +338,7 @@ public class TestReplaceText {
}
@Test
- public void testAppendExceptFirstLineWithCarriageReturn() throws IOException {
+ public void testAppendExceptFirstLineWithCarriageReturn() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -355,7 +354,7 @@ public class TestReplaceText {
}
@Test
- public void testAppendLastLineWithCarriageReturn() throws IOException {
+ public void testAppendLastLineWithCarriageReturn() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -371,7 +370,7 @@ public class TestReplaceText {
}
@Test
- public void testAppendExceptLastLineWithCarriageReturn() throws IOException {
+ public void testAppendExceptLastLineWithCarriageReturn() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -387,7 +386,7 @@ public class TestReplaceText {
}
@Test
- public void testAppendWithNewLine() throws IOException {
+ public void testAppendWithNewLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -402,7 +401,7 @@ public class TestReplaceText {
}
@Test
- public void testAppendWithCarriageReturnNewLine() throws IOException {
+ public void testAppendWithCarriageReturnNewLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -417,7 +416,7 @@ public class TestReplaceText {
}
@Test
- public void testAppendFirstLineWithCarriageReturnNewLine() throws IOException {
+ public void testAppendFirstLineWithCarriageReturnNewLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -434,7 +433,7 @@ public class TestReplaceText {
@Test
- public void testAppendLastLineWithCarriageReturnNewLine() throws IOException {
+ public void testAppendLastLineWithCarriageReturnNewLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -451,7 +450,7 @@ public class TestReplaceText {
@Test
- public void testAppendExceptFistLineWithCarriageReturnNewLine() throws IOException {
+ public void testAppendExceptFistLineWithCarriageReturnNewLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -468,7 +467,7 @@ public class TestReplaceText {
@Test
- public void testAppendExceptLastLineWithCarriageReturnNewLine() throws IOException {
+ public void testAppendExceptLastLineWithCarriageReturnNewLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -562,7 +561,7 @@ public class TestReplaceText {
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
final String actual = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(actual);
- Assert.assertEquals(expected, actual);
+ assertEquals(expected, actual);
}
@Test
@@ -578,7 +577,7 @@ public class TestReplaceText {
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
final String actual = new String(out.toByteArray(), StandardCharsets.UTF_8);
- Assert.assertEquals("Hell123o, World!", actual);
+ assertEquals("Hell123o, World!", actual);
}
@Test
@@ -831,13 +830,13 @@ public class TestReplaceText {
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
- Assert.assertTrue(outContent.startsWith("abc.txt\t"));
+ assertTrue(outContent.startsWith("abc.txt\t"));
System.out.println(outContent);
- Assert.assertTrue(outContent.endsWith("13\n"));
+ assertTrue(outContent.endsWith("13\n"));
}
@Test
- public void testGetExistingContent() throws IOException {
+ public void testGetExistingContent() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "attribute header\n\n${filename}\n\ndata header\n\n$1\n\nfooter");
@@ -852,12 +851,12 @@ public class TestReplaceText {
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
- Assert.assertTrue(outContent.equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\nWorld!\n\nfooter"));
+ assertTrue(outContent.equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\nWorld!\n\nfooter"));
System.out.println(outContent);
}
@Test
- public void testReplaceWithinCurlyBraces() throws IOException {
+ public void testReplaceWithinCurlyBraces() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, ".+");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "{ ${filename} }");
@@ -874,7 +873,7 @@ public class TestReplaceText {
}
@Test
- public void testDefaultReplacement() throws Exception {
+ public void testDefaultReplacement() {
final String defaultValue = "default-replacement-value";
// leave the default regex settings
@@ -892,7 +891,7 @@ public class TestReplaceText {
}
@Test
- public void testDefaultMultilineReplacement() throws Exception {
+ public void testDefaultMultilineReplacement() {
final String defaultValue = "default-replacement-value";
// leave the default regex settings
@@ -1039,7 +1038,7 @@ public class TestReplaceText {
}
@Test
- public void testLiteralLineByLine() throws IOException {
+ public void testLiteralLineByLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, ".ell.");
@@ -1404,7 +1403,7 @@ public class TestReplaceText {
}
@Test
- public void testAttributeToContentWindows() throws IOException {
+ public void testAttributeToContentWindows() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
@@ -1437,13 +1436,13 @@ public class TestReplaceText {
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
final String outContent = translateNewLines(new String(out.toByteArray(), StandardCharsets.UTF_8));
- Assert.assertTrue(outContent.startsWith("abc.txt\t"));
+ assertTrue(outContent.startsWith("abc.txt\t"));
System.out.println(outContent);
- Assert.assertTrue(outContent.endsWith("193\n") || outContent.endsWith("203\r\n"));
+ assertTrue(outContent.endsWith("193\n") || outContent.endsWith("203\r\n"));
}
@Test
- public void testGetExistingContentLineByLine() throws IOException {
+ public void testGetExistingContentLineByLine() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*)");
@@ -1459,8 +1458,9 @@ public class TestReplaceText {
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
System.out.println(outContent);
- Assert.assertTrue(outContent.equals("attribute header\n\nabc.txt\n\ndata header\n\nHello\n\n\nfooter\n"
- + "attribute header\n\nabc.txt\n\ndata header\n\nWorld!\n\nfooter\n"));
+ final String expectedContent = "attribute header\n\nabc.txt\n\ndata header\n\nHello\n\n\nfooter\n"
+ + "attribute header\n\nabc.txt\n\ndata header\n\nWorld!\n\nfooter\n";
+ assertEquals(expectedContent, outContent);
}
@Test
@@ -1550,7 +1550,7 @@ public class TestReplaceText {
}
@Test
- public void testRegexWithBadCaptureGroup() throws IOException {
+ public void testRegexWithBadCaptureGroup() {
// Test the old Default Regex and with a custom Replacement Value that should fail because the
// Perl regex "(?s:^.*$)" must be written "(?s)(^.*$)" in Java for there to be a capture group.
// private static final String DEFAULT_REGEX = "(?s:^.*$)";
@@ -1569,7 +1569,7 @@ public class TestReplaceText {
}
@Test
- public void testRegexWithGoodCaptureGroup() throws IOException {
+ public void testRegexWithGoodCaptureGroup() {
// Test the new Default Regex and with a custom Replacement Values that should succeed.
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*$)");
@@ -1586,7 +1586,7 @@ public class TestReplaceText {
}
@Test
- public void testRegexNoCaptureDefaultReplacement() throws IOException {
+ public void testRegexNoCaptureDefaultReplacement() {
// Test the old Default Regex and new Default Regex with the default replacement. This should fail
// because the regex does not create a capture group.
final TestRunner runner = getRunner();
@@ -1595,14 +1595,16 @@ public class TestReplaceText {
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.ENTIRE_TEXT);
- exception.expect(AssertionError.class);
- exception.expectMessage("java.lang.IndexOutOfBoundsException: No group 1");
runner.enqueue("testing\n123".getBytes());
- runner.run();
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
+ assertInstanceOf(IndexOutOfBoundsException.class, e.getCause());
+ assertTrue(e.getMessage().contains("java.lang.IndexOutOfBoundsException: No group 1"));
}
@Test
- public void testProcessorConfigurationRegexNotValid() throws IOException {
+ public void testProcessorConfigurationRegexNotValid() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?<!\\),*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "hello");
@@ -1630,7 +1632,7 @@ public class TestReplaceText {
}
@Test
- public void testBackReferenceEscapeWithRegexReplaceUsingEL() throws Exception {
+ public void testBackReferenceEscapeWithRegexReplaceUsingEL() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*$)");
@@ -1707,7 +1709,7 @@ public class TestReplaceText {
* on large input strings.
*/
@Test
- public void testForStackOverflow() throws Exception {
+ public void testForStackOverflow() {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "New text");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
@@ -1748,7 +1750,7 @@ public class TestReplaceText {
runner.assertAllFlowFilesTransferred(ReplaceText.REL_FAILURE, 1);
final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_FAILURE).get(0);
final String outContent = translateNewLines(new String(out.toByteArray(), StandardCharsets.UTF_8));
- Assert.assertTrue(outContent.equals("hi"));
+ assertEquals("hi", outContent);
}
private String translateNewLines(final File file) throws IOException {
@@ -1767,4 +1769,4 @@ public class TestReplaceText {
final String translated = pattern.matcher(text).replaceAll(lineSeparator);
return translated;
}
-}
+}
\ No newline at end of file
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java
index fad370a87e..309491bed1 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceTextWithMapping.java
@@ -16,7 +16,10 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
@@ -25,10 +28,8 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestReplaceTextWithMapping {
@@ -329,7 +330,7 @@ public class TestReplaceTextWithMapping {
assertEquals(expected, outputString);
}
- @Test(expected = java.lang.AssertionError.class)
+ @Test
public void testMatchingGroupForLookupKeyTooLarge() throws IOException {
final TestRunner runner = getRunner();
runner.setProperty(ReplaceTextWithMapping.REGEX, "-(.*?)-");
@@ -338,7 +339,9 @@ public class TestReplaceTextWithMapping {
final Path path = Paths.get("src/test/resources/TestReplaceTextWithMapping/colors.txt");
runner.enqueue(path);
- runner.run();
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java
index 227e6852df..8a6f3341fa 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java
@@ -18,24 +18,26 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-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.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public class TestRetryFlowFile {
TestRunner runner;
- @Before
+ @BeforeEach
public void before() {
runner = TestRunners.newTestRunner(new RetryFlowFile());
}
- @After
+ @AfterEach
public void after() {
runner.shutdown();
}
@@ -70,7 +72,7 @@ public class TestRetryFlowFile {
mff.assertAttributeExists("flowfile.retries");
mff.assertAttributeExists("flowfile.retries.uuid");
mff.assertAttributeEquals("flowfile.retries", "3");
- Assert.assertTrue("FlowFile was not penalized!", mff.isPenalized());
+ assertTrue(mff.isPenalized(), "FlowFile was not penalized!");
return true;
});
}
@@ -92,7 +94,7 @@ public class TestRetryFlowFile {
mff.assertAttributeExists("flowfile.retries");
mff.assertAttributeExists("flowfile.retries.uuid");
mff.assertAttributeEquals("flowfile.retries", "3");
- Assert.assertTrue("FlowFile was not penalized!", mff.isPenalized());
+ assertTrue(mff.isPenalized(), "FlowFile was not penalized!");
return true;
});
}
@@ -111,7 +113,7 @@ public class TestRetryFlowFile {
mff.assertAttributeExists("flowfile.retries.uuid");
mff.assertAttributeExists("flowfile.retries");
mff.assertAttributeEquals("flowfile.retries", "3");
- Assert.assertFalse("FlowFile was not penalized!", mff.isPenalized());
+ assertFalse(mff.isPenalized(), "FlowFile was not penalized!");
return true;
});
}
@@ -129,7 +131,7 @@ public class TestRetryFlowFile {
mff.assertAttributeExists("flowfile.retries.uuid");
mff.assertAttributeExists("flowfile.retries");
mff.assertAttributeEquals("flowfile.retries", "1");
- Assert.assertTrue("FlowFile was not penalized!", mff.isPenalized());
+ assertTrue(mff.isPenalized(), "FlowFile was not penalized!");
return true;
});
}
@@ -159,8 +161,7 @@ public class TestRetryFlowFile {
runner.assertAllConditionsMet(RetryFlowFile.RETRIES_EXCEEDED, mff -> {
mff.assertAttributeExists("exceeded.time");
mff.assertAttributeExists("reason");
- Assert.assertFalse("Expression language not evaluated!",
- mff.getAttribute("reason").contains("${uuid}"));
+ assertFalse(mff.getAttribute("reason").contains("${uuid}"), "Expression language not evaluated!");
return true;
});
}
@@ -236,7 +237,7 @@ public class TestRetryFlowFile {
mff.assertAttributeExists("flowfile.retries");
mff.assertAttributeExists("flowfile.retries.uuid");
mff.assertAttributeEquals("flowfile.retries", "3");
- Assert.assertTrue("FlowFile was not penalized!", mff.isPenalized());
+ assertTrue(mff.isPenalized(), "FlowFile was not penalized!");
return true;
});
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java
index 2eac3f2b24..c5cc656064 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnAttribute.java
@@ -16,22 +16,21 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.processor.Relationship;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
public class TestRouteOnAttribute {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java
index fb89d86749..374cb67479 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteOnContent.java
@@ -16,16 +16,15 @@
*/
package org.apache.nifi.processors.standard;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+
import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-
-import org.junit.Test;
-
public class TestRouteOnContent {
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java
index 698cc43cb2..3b753f5f0b 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRouteText.java
@@ -17,9 +17,11 @@
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import org.apache.nifi.processor.Relationship;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Paths;
@@ -29,16 +31,14 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import org.apache.nifi.processor.Relationship;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestRouteText {
@Test
- public void testRelationships() throws IOException {
+ public void testRelationships() {
final TestRunner runner = TestRunners.newTestRunner(new RouteText());
runner.setProperty(RouteText.MATCH_STRATEGY, RouteText.STARTS_WITH);
runner.setProperty(RouteText.ROUTE_STRATEGY, RouteText.ROUTE_TO_MATCHED_WHEN_ANY_PROPERTY_MATCHES);
@@ -69,7 +69,7 @@ public class TestRouteText {
}
@Test
- public void testSeparationStrategyNotKnown() throws IOException {
+ public void testSeparationStrategyNotKnown() {
final TestRunner runner = TestRunners.newTestRunner(new RouteText());
runner.setProperty(RouteText.MATCH_STRATEGY, RouteText.STARTS_WITH);
@@ -106,13 +106,9 @@ public class TestRouteText {
runner.setProperty("simple", "[");
runner.enqueue("start middle end\nnot match".getBytes("UTF-8"));
- try {
+ assertThrows(AssertionError.class, () -> {
runner.run();
- fail();
- } catch (AssertionError e) {
- // Expect to catch error asserting 'simple' as invalid
- }
-
+ });
}
@Test
@@ -765,7 +761,7 @@ public class TestRouteText {
}
@Test
- public void testPatternCache() throws IOException {
+ public void testPatternCache() {
final RouteText routeText = new RouteText();
final TestRunner runner = TestRunners.newTestRunner(routeText);
runner.setProperty(RouteText.MATCH_STRATEGY, RouteText.MATCHES_REGULAR_EXPRESSION);
@@ -793,7 +789,7 @@ public class TestRouteText {
runner.assertTransferCount(RouteText.REL_ORIGINAL, iterations * 2);
runner.setProperty(RouteText.IGNORE_CASE, "true");
- assertEquals("Pattern cache is not cleared after changing IGNORE_CASE", 0, routeText.patternsCache.size());
+ assertEquals(0, routeText.patternsCache.size(), "Pattern cache is not cleared after changing IGNORE_CASE");
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java
index 9c98ca6ac7..115189a1c1 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java
@@ -28,7 +28,7 @@ import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
@@ -37,8 +37,8 @@ import java.util.List;
import java.util.Random;
import java.util.UUID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestSampleRecord {
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java
index 07677a97b6..41468a902d 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanAttribute.java
@@ -16,12 +16,12 @@
*/
package org.apache.nifi.processors.standard;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
public class TestScanAttribute {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java
index 0e972fda25..243494e693 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java
@@ -16,6 +16,12 @@
*/
package org.apache.nifi.processors.standard;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -24,11 +30,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.List;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Ignore;
-import org.junit.Test;
public class TestScanContent {
@@ -50,7 +51,7 @@ public class TestScanContent {
}
- @Ignore("This test has a race condition/ordering problem")
+ @Disabled("This test has a race condition/ordering problem")
@Test
public void testBinaryScan() throws IOException {
// Create dictionary file.
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java
index 74fad06952..178b43ca82 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSegmentContent.java
@@ -16,16 +16,15 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.util.List;
-
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.util.List;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestSegmentContent {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java
index dce8f43c64..cc314096a7 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitContent.java
@@ -16,14 +16,13 @@
*/
package org.apache.nifi.processors.standard;
-import java.io.IOException;
-import java.util.List;
-
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
+import java.io.IOException;
+import java.util.List;
import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_COUNT;
import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_ID;
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java
index c4627b2164..4ad847cbef 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitJson.java
@@ -16,18 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_COUNT;
-import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_ID;
-import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_INDEX;
-import static org.apache.nifi.flowfile.attributes.FragmentAttributes.SEGMENT_ORIGINAL_FILENAME;
-
-import java.io.BufferedOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.HashMap;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.processor.ProcessSession;
@@ -36,20 +24,31 @@ import org.apache.nifi.processor.io.OutputStreamCallback;
import org.apache.nifi.util.MockFlowFile;
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.Test;
+
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashMap;
+
+import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_COUNT;
+import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_ID;
+import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_INDEX;
+import static org.apache.nifi.flowfile.attributes.FragmentAttributes.SEGMENT_ORIGINAL_FILENAME;
public class TestSplitJson {
private static final Path JSON_SNIPPET = Paths.get("src/test/resources/TestJson/json-sample.json");
private static final Path XML_SNIPPET = Paths.get("src/test/resources/TestXml/xml-snippet.xml");
- @Test(expected = AssertionError.class)
+ @Test
public void testInvalidJsonPath() {
final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$..");
-
- Assert.fail("An improper JsonPath expression was not detected as being invalid.");
+ testRunner.assertNotValid();
}
@Test
@@ -156,7 +155,7 @@ public class TestSplitJson {
}
@Test
- public void testSplit_pathToNullValue() throws Exception {
+ public void testSplit_pathToNullValue() {
final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.nullField");
@@ -179,7 +178,7 @@ public class TestSplitJson {
}
@Test
- public void testSplit_pathToArrayWithNulls_emptyStringRepresentation() throws Exception {
+ public void testSplit_pathToArrayWithNulls_emptyStringRepresentation() {
final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.arrayOfNulls");
@@ -207,7 +206,7 @@ public class TestSplitJson {
}
@Test
- public void testSplit_pathToArrayWithNulls_nullStringRepresentation() throws Exception {
+ public void testSplit_pathToArrayWithNulls_nullStringRepresentation() {
final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.arrayOfNulls");
testRunner.setProperty(SplitJson.NULL_VALUE_DEFAULT_REPRESENTATION,
@@ -237,7 +236,7 @@ public class TestSplitJson {
}
@Test
- public void testSplit_pathToInputStringNullValue() throws Exception {
+ public void testSplit_pathToInputStringNullValue() {
final TestRunner testRunner = TestRunners.newTestRunner(new SplitJson());
testRunner.setProperty(SplitJson.ARRAY_JSON_PATH_EXPRESSION, "$.*");
ProcessSession session = testRunner.getProcessSessionFactory().createSession();
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java
index ee8f30219c..b59e985d6d 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitRecord.java
@@ -25,12 +25,12 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestSplitRecord {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitText.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitText.java
index f42b1d3c15..c76a49fc97 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitText.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitText.java
@@ -16,7 +16,11 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
@@ -24,11 +28,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
-import org.apache.nifi.flowfile.attributes.CoreAttributes;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestSplitText {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitXml.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitXml.java
index 281212f3bd..a653f54486 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitXml.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSplitXml.java
@@ -16,50 +16,51 @@
*/
package org.apache.nifi.processors.standard;
-import java.io.IOException;
-import java.io.StringReader;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
import org.apache.nifi.flowfile.attributes.CoreAttributes;
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 org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.IOException;
+import java.io.StringReader;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_COUNT;
import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_ID;
import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_INDEX;
import static org.apache.nifi.flowfile.attributes.FragmentAttributes.SEGMENT_ORIGINAL_FILENAME;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestSplitXml {
SAXParserFactory factory;
SAXParser saxParser;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
factory = SAXParserFactory.newInstance();
saxParser = factory.newSAXParser();
}
- @Test(expected = java.lang.AssertionError.class)
+ @Test
public void testDepthOf0() throws IOException {
final TestRunner runner = TestRunners.newTestRunner(new SplitXml());
runner.setProperty(SplitXml.SPLIT_DEPTH, "0");
runner.enqueue(Paths.get("src/test/resources/TestXml/xml-bundle-1"));
- runner.run();
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
index 806988ebb2..ab0ae577f9 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
@@ -16,7 +16,6 @@
*/
package org.apache.nifi.processors.standard;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.components.state.Scope;
import org.apache.nifi.components.state.StateMap;
import org.apache.nifi.processors.standard.TailFile.TailFileState;
@@ -25,11 +24,11 @@ import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Assume;
-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.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,12 +52,11 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
public class TestTailFile {
private static final Logger logger = LoggerFactory.getLogger(TestTailFile.class);
@@ -73,7 +71,7 @@ public class TestTailFile {
private TailFile processor;
private TestRunner runner;
- @Before
+ @BeforeEach
public void setup() throws IOException {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.standard", "TRACE");
clean();
@@ -112,7 +110,7 @@ public class TestTailFile {
otherRaf = new RandomAccessFile(otherFile, "rw");
}
- @After
+ @AfterEach
public void cleanup() throws IOException {
if (raf != null) {
raf.close();
@@ -132,6 +130,7 @@ public class TestTailFile {
}
}
}
+ System.clearProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.standard");
}
@Test
@@ -317,10 +316,9 @@ public class TestTailFile {
}
+ @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test requires renaming a file while a file handle is still open to it, so it won't run on Windows")
@Test
public void testFileWrittenToAfterRollover() throws IOException, InterruptedException {
- Assume.assumeTrue("Test requires renaming a file while a file handle is still open to it, so it won't run on Windows", !SystemUtils.IS_OS_WINDOWS);
-
runner.setProperty(TailFile.ROLLING_FILENAME_PATTERN, "log.*");
runner.setProperty(TailFile.START_POSITION, TailFile.START_BEGINNING_OF_TIME.getValue());
runner.setProperty(TailFile.REREAD_ON_NUL, "true");
@@ -520,7 +518,7 @@ public class TestTailFile {
} else if ("hello".equals(content)) {
hello = true;
} else {
- Assert.fail("Got unexpected content: " + content);
+ fail("Got unexpected content: " + content);
}
}
@@ -1271,13 +1269,9 @@ public class TestTailFile {
runner.clearTransferState();
}
- private boolean isWindowsEnvironment() {
- return System.getProperty("os.name").toLowerCase().startsWith("windows");
- }
-
+ @DisabledOnOs(OS.WINDOWS)
@Test
public void testMigrateFrom100To110() throws IOException {
- assumeFalse(isWindowsEnvironment());
runner.setProperty(TailFile.FILENAME, "target/existing-log.txt");
final MockStateManager stateManager = runner.getStateManager();
@@ -1322,11 +1316,9 @@ public class TestTailFile {
runner.assertAllFlowFilesTransferred(TailFile.REL_SUCCESS, 0);
}
-
+ @DisabledOnOs(OS.WINDOWS)
@Test
public void testMigrateFrom100To110FileNotFound() throws IOException {
- assumeFalse(isWindowsEnvironment());
-
runner.setProperty(TailFile.FILENAME, "target/not-existing-log.txt");
final MockStateManager stateManager = runner.getStateManager();
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileGeneratedScenarios.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileGeneratedScenarios.java
index 6622169f98..8f052a5fbd 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileGeneratedScenarios.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileGeneratedScenarios.java
@@ -16,33 +16,29 @@
*/
package org.apache.nifi.processors.standard;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
+import org.junit.jupiter.api.condition.OS;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import java.util.stream.Stream;
-@Ignore("Stress test - longrunning. For manual testing.")
-@RunWith(Parameterized.class)
+@EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true", disabledReason = "Stress test - longrunning. For manual testing.")
public class TestTailFileGeneratedScenarios extends AbstractTestTailFileScenario {
- private final List<Action> actions;
-
- public TestTailFileGeneratedScenarios(List<Action> actions) {
- this.actions = actions;
- }
-
- @Parameterized.Parameters
- public static Collection parameters() {
- Collection<Object[]> parameters = new ArrayList();
+ private static List<Arguments> parameters = new ArrayList<>();
+ @BeforeAll
+ public static final void createParameters() {
// Uncomment the portion for which to run the scenarios.
// They cannot be added to a single large batch because it opens too many files.
-// List<Action> baseActions = Arrays.asList(
+// final List<Action> baseActions = Arrays.asList(
// Action.WRITE_WORD,
// Action.WRITE_NUL,
// Action.WRITE_NEW_LINE,
@@ -60,7 +56,7 @@ public class TestTailFileGeneratedScenarios extends AbstractTestTailFileScenario
// new ArrayList<>(parameters).forEach(anActionList -> addAction(parameters, Action.ROLLOVER, (List<Action>)anActionList[0], 0, 0));
// new ArrayList<>(parameters).forEach(anActionList -> addAction(parameters, Action.SWITCH_FILE, (List<Action>)anActionList[0], 0, 0));
-// List<Action> baseActions = Arrays.asList(
+// final List<Action> baseActions = Arrays.asList(
// Action.WRITE_WORD,
// Action.WRITE_NEW_LINE,
// Action.WRITE_NUL,
@@ -90,48 +86,50 @@ public class TestTailFileGeneratedScenarios extends AbstractTestTailFileScenario
// );
// addAction(parameters, Action.TRIGGER, baseActions, 0, 1);
- List<Action> baseActions = Arrays.asList(
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.WRITE_NUL, Action.WRITE_NUL,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.OVERWRITE_NUL, Action.OVERWRITE_NUL,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.ROLLOVER,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.WRITE_NUL, Action.WRITE_NUL,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.OVERWRITE_NUL, Action.OVERWRITE_NUL,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.SWITCH_FILE,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.WRITE_NUL, Action.WRITE_NUL,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.OVERWRITE_NUL, Action.OVERWRITE_NUL,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
- Action.WRITE_WORD, Action.WRITE_WORD,
- Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE
+ final List<Action> baseActions = Arrays.asList(
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.WRITE_NUL, Action.WRITE_NUL,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.OVERWRITE_NUL, Action.OVERWRITE_NUL,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.ROLLOVER,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.WRITE_NUL, Action.WRITE_NUL,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.OVERWRITE_NUL, Action.OVERWRITE_NUL,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.SWITCH_FILE,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.WRITE_NUL, Action.WRITE_NUL,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.OVERWRITE_NUL, Action.OVERWRITE_NUL,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE,
+ Action.WRITE_WORD, Action.WRITE_WORD,
+ Action.WRITE_NEW_LINE, Action.WRITE_NEW_LINE
);
addAction(parameters, Action.TRIGGER, baseActions, 0, 1);
+ }
- return parameters;
+ private static Stream<Arguments> provideActionsForTestScenario() {
+ return parameters.stream();
}
- private static void addAction(Collection<Object[]> parameters, Action action, List<Action> baseActions, int currentDepth, int recursiveDepth) {
+ private static void addAction(List<Arguments> parameters, Action action, List<Action> baseActions, int currentDepth, int recursiveDepth) {
for (int triggerIndex = 0; triggerIndex < baseActions.size(); triggerIndex++) {
List<Action> actions = new LinkedList<>(baseActions);
actions.add(triggerIndex, action);
- parameters.add(new Object[]{ actions});
+ parameters.add(Arguments.of(actions));
if (currentDepth < recursiveDepth) {
addAction(parameters, action, actions, currentDepth+1, recursiveDepth);
@@ -139,8 +137,10 @@ public class TestTailFileGeneratedScenarios extends AbstractTestTailFileScenario
}
}
- @Test
- public void testScenario() throws Exception {
+ @ParameterizedTest
+ @MethodSource("provideActionsForTestScenario")
+ @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test wants to rename an open file which is not allowed on Windows")
+ public void testParameterizedScenario(List<Action> actions) throws Exception {
testScenario(actions);
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileSimpleScenarios.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileSimpleScenarios.java
index 83da792f36..732f886929 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileSimpleScenarios.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFileSimpleScenarios.java
@@ -16,13 +16,17 @@
*/
package org.apache.nifi.processors.standard;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.util.Arrays;
import java.util.List;
public class TestTailFileSimpleScenarios extends AbstractTestTailFileScenario {
+
@Test
+ @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test wants to rename an open file which is not allowed on Windows")
public void testSimpleScenario() throws Exception {
// GIVEN
List<Action> actions = Arrays.asList(
@@ -77,6 +81,7 @@ public class TestTailFileSimpleScenarios extends AbstractTestTailFileScenario {
}
@Test
+ @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test wants to rename an open file which is not allowed on Windows")
public void testSimpleScenario4() throws Exception {
// GIVEN
List<Action> actions = Arrays.asList(
@@ -94,6 +99,7 @@ public class TestTailFileSimpleScenarios extends AbstractTestTailFileScenario {
}
@Test
+ @DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test wants to rename an open file which is not allowed on Windows")
public void testSimpleScenario5() throws Exception {
// GIVEN
List<Action> actions = Arrays.asList(
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java
index 8bcef7adcb..2962007a64 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java
@@ -16,6 +16,13 @@
*/
package org.apache.nifi.processors.standard;
+import org.apache.nifi.lookup.SimpleKeyValueLookupService;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
@@ -25,13 +32,6 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
-import org.apache.nifi.lookup.SimpleKeyValueLookupService;
-import org.apache.nifi.reporting.InitializationException;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
-
public class TestTransformXml {
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
index f545f07a2a..14053e5f8c 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
@@ -16,11 +16,14 @@
*/
package org.apache.nifi.processors.standard;
-import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_COUNT;
-import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_ID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import net.lingala.zip4j.io.outputstream.ZipOutputStream;
+import net.lingala.zip4j.model.ZipParameters;
+import net.lingala.zip4j.model.enums.EncryptionMethod;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -28,21 +31,15 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.format.DateTimeFormatter;
-import java.time.format.DateTimeParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import net.lingala.zip4j.io.outputstream.ZipOutputStream;
-import net.lingala.zip4j.model.ZipParameters;
-import net.lingala.zip4j.model.enums.EncryptionMethod;
-import org.apache.nifi.flowfile.attributes.CoreAttributes;
-import org.apache.nifi.util.MockFlowFile;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-
-import org.junit.Test;
+import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_COUNT;
+import static org.apache.nifi.processors.standard.SplitContent.FRAGMENT_ID;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestUnpackContent {
@@ -89,17 +86,13 @@ public class TestUnpackContent {
assertEquals("jmcarey", flowFile.getAttribute("file.owner"));
assertEquals("mkpasswd", flowFile.getAttribute("file.group"));
String modifiedTimeAsString = flowFile.getAttribute("file.lastModifiedTime");
- try {
- DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ").parse(modifiedTimeAsString);
- } catch (DateTimeParseException e) {
- fail();
- }
+
+ DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ").parse(modifiedTimeAsString);
+
String creationTimeAsString = flowFile.getAttribute("file.creationTime");
- try {
- DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ").parse(creationTimeAsString);
- } catch (DateTimeParseException e) {
- fail();
- }
+
+ DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ").parse(creationTimeAsString);
+
assertTrue(Files.exists(path));
flowFile.assertContentEquals(path.toFile());
@@ -507,7 +500,7 @@ public class TestUnpackContent {
final byte[] unpackedBytes = runner.getContentAsByteArray(unpacked);
final String unpackedContents = new String(unpackedBytes);
- assertEquals("Unpacked Contents not matched", contents, unpackedContents);
+ assertEquals(contents, unpackedContents, "Unpacked Contents not matched");
}
private byte[] createZipEncrypted(final EncryptionMethod encryptionMethod, final char[] password, final String contents) throws IOException {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java
index ce0ebf85c1..b5a295dc73 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java
@@ -16,20 +16,20 @@
*/
package org.apache.nifi.processors.standard;
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestUpdateCounter {
@Test
- public void testwithFileName() throws Exception {
+ public void testwithFileName() {
final TestRunner firstrunner = TestRunners.newTestRunner(new UpdateCounter());
firstrunner.setProperty(UpdateCounter.COUNTER_NAME,"firewall");
firstrunner.setProperty(UpdateCounter.DELTA,"1");
@@ -40,7 +40,7 @@ public class TestUpdateCounter {
}
@Test
- public void testExpressionLanguage() throws Exception {
+ public void testExpressionLanguage() {
final TestRunner firstrunner = TestRunners.newTestRunner(new UpdateCounter());
firstrunner.setProperty(UpdateCounter.COUNTER_NAME,"${filename}");
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateRecord.java
index 068047d13f..9893833e14 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateRecord.java
@@ -18,7 +18,6 @@
package org.apache.nifi.processors.standard;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.nifi.json.JsonRecordSetWriter;
import org.apache.nifi.json.JsonTreeReader;
import org.apache.nifi.reporting.InitializationException;
@@ -30,32 +29,27 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+@DisabledOnOs(value = OS.WINDOWS, disabledReason = "Test only runs on *nix")
public class TestUpdateRecord {
private TestRunner runner;
private MockRecordParser readerService;
private MockRecordWriter writerService;
- //Apparently pretty printing is not portable as these tests fail on windows
- @BeforeClass
- public static void setUpSuite() {
- Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
- }
-
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
readerService = new MockRecordParser();
writerService = new MockRecordWriter("header", false);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java
index c694ab1c8f..128a39f607 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java
@@ -18,7 +18,7 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
public class TestValidateCsv {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java
index 728f8d8230..c94667ebb3 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java
@@ -41,8 +41,8 @@ import org.apache.nifi.serialization.record.RecordSchema;
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.io.ByteArrayInputStream;
import java.io.File;
@@ -55,13 +55,13 @@ import java.nio.file.Paths;
import java.util.Map;
import java.util.Optional;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestValidateRecord {
private TestRunner runner;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(ValidateRecord.class);
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateXml.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateXml.java
index 3a03b229d9..a4a66e1287 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateXml.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateXml.java
@@ -16,14 +16,16 @@
*/
package org.apache.nifi.processors.standard;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.Test;
+
import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
-import org.apache.nifi.util.TestRunner;
-import org.apache.nifi.util.TestRunners;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestValidateXml {
@@ -77,16 +79,15 @@ public class TestValidateXml {
runner.assertAllFlowFilesTransferred(ValidateXml.REL_VALID, 1);
}
- @Test(expected = AssertionError.class)
+ @Test
public void testInvalidEL() {
final TestRunner runner = TestRunners.newTestRunner(new ValidateXml());
runner.setProperty(ValidateXml.SCHEMA_FILE, "${my.schema}");
runner.enqueue(INVALID_XML);
- runner.run();
-
- runner.assertAllFlowFilesTransferred(ValidateXml.REL_INVALID, 1);
- runner.assertAllFlowFilesContainAttribute(ValidateXml.REL_INVALID, ValidateXml.ERROR_ATTRIBUTE_KEY);
+ assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
}
@Test
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java
index d8fffdc218..5e3ccaba58 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java
@@ -16,11 +16,14 @@
*/
package org.apache.nifi.processors.standard;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processors.standard.TestNotify.MockCacheClient;
+import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
@@ -33,21 +36,19 @@ import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.stream.IntStream;
-import org.apache.nifi.processor.exception.ProcessException;
-import org.apache.nifi.processors.standard.TestNotify.MockCacheClient;
-import org.apache.nifi.reporting.InitializationException;
-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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestWait {
private TestRunner runner;
private MockCacheClient service;
- @Before
+ @BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(Wait.class);
@@ -158,7 +159,7 @@ public class TestWait {
}
@Test
- public void testBadWaitStartTimestamp() throws InitializationException, InterruptedException {
+ public void testBadWaitStartTimestamp() {
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
runner.setProperty(Wait.EXPIRATION_DURATION, "100 ms");
@@ -176,7 +177,7 @@ public class TestWait {
}
@Test
- public void testEmptyReleaseSignal() throws InitializationException, InterruptedException {
+ public void testEmptyReleaseSignal() {
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
final Map<String, String> props = new HashMap<>();
@@ -193,26 +194,23 @@ public class TestWait {
}
@Test
- public void testFailingCacheService() throws InitializationException, IOException {
+ public void testFailingCacheService() {
service.setFailOnCalls(true);
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
final Map<String, String> props = new HashMap<>();
props.put("releaseSignalAttribute", "2");
runner.enqueue(new byte[]{}, props);
- try {
- runner.run();
- fail("Expect the processor to receive an IO exception from the cache service and throws ProcessException.");
- } catch (final AssertionError e) {
- assertTrue(e.getCause() instanceof ProcessException);
- assertTrue(e.getCause().getCause() instanceof IOException);
- } finally {
- service.setFailOnCalls(false);
- }
+ final AssertionError e = assertThrows(AssertionError.class, () -> {
+ runner.run();
+ });
+ assertInstanceOf(ProcessException.class, e.getCause());
+ assertInstanceOf(IOException.class, e.getCause().getCause());
+ service.setFailOnCalls(false);
}
@Test
- public void testWaitPenaltyDuration() throws InitializationException {
+ public void testWaitPenaltyDuration() {
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
runner.setProperty(Wait.WAIT_PENALTY_DURATION, "1 hour");
@@ -409,7 +407,7 @@ public class TestWait {
assertEquals("waitValue", outputFlowFile.getAttribute("both"));
runner.clearTransferState();
- assertNull("The key no longer exist", protocol.getSignal("key"));
+ assertNull(protocol.getSignal("key"), "The key no longer exist");
}
@Test
@@ -565,7 +563,7 @@ public class TestWait {
// All counters are consumed.
outputFlowFile.assertAttributeEquals("wait.counter.counter", "0");
- assertNull("The key no longer exist", protocol.getSignal("key"));
+ assertNull(protocol.getSignal("key"), "The key no longer exist");
runner.clearTransferState();
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWaitNotifyProtocol.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWaitNotifyProtocol.java
index 2b97b588eb..f6bd53d31e 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWaitNotifyProtocol.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWaitNotifyProtocol.java
@@ -22,8 +22,8 @@ import org.apache.nifi.distributed.cache.client.AtomicDistributedMapCacheClient;
import org.apache.nifi.distributed.cache.client.exception.DeserializationException;
import org.apache.nifi.processors.standard.WaitNotifyProtocol.Signal;
import org.apache.nifi.processors.standard.util.FlowFileAttributesSerializer;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.stubbing.Answer;
import java.lang.reflect.Field;
@@ -39,12 +39,12 @@ import java.util.stream.IntStream;
import static org.apache.nifi.processors.standard.WaitNotifyProtocol.CONSUMED_COUNT_NAME;
import static org.apache.nifi.processors.standard.WaitNotifyProtocol.DEFAULT_COUNT_NAME;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -61,7 +61,7 @@ public class TestWaitNotifyProtocol {
return true;
};
- @Before
+ @BeforeEach
@SuppressWarnings("unchecked")
public void before() throws Exception {
cacheEntries.clear();
@@ -181,8 +181,8 @@ public class TestWaitNotifyProtocol {
cacheEntry = cacheEntries.get("signal-id");
assertEquals(2L, cacheEntry.getRevision().orElse(-1L).longValue());
- assertEquals("Updated attributes should be merged correctly",
- "{\"counts\":{\"a\":2},\"attributes\":{\"p1\":\"a1\",\"p2\":\"a2\",\"p3\":\"a2\"},\"releasableCount\":0}", cacheEntry.getValue());
+ assertEquals("{\"counts\":{\"a\":2},\"attributes\":{\"p1\":\"a1\",\"p2\":\"a2\",\"p3\":\"a2\"},\"releasableCount\":0}", cacheEntry.getValue(),
+ "Updated attributes should be merged correctly");
}
@@ -195,7 +195,7 @@ public class TestWaitNotifyProtocol {
final String signalId = "signal-id";
Signal signal = protocol.getSignal(signalId);
- assertNull("Should be null since there's no signal yet", signal);
+ assertNull(signal, "Should be null since there's no signal yet");
// First notification.
protocol.notify(signalId, "success", 1, null);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQL2008DatabaseAdapter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQL2008DatabaseAdapter.java
index 912a720a1c..5ed921b06b 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQL2008DatabaseAdapter.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQL2008DatabaseAdapter.java
@@ -17,67 +17,71 @@
package org.apache.nifi.processors.standard.db.impl;
import org.apache.nifi.processors.standard.db.DatabaseAdapter;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestMSSQL2008DatabaseAdapter {
private final DatabaseAdapter db = new MSSQL2008DatabaseAdapter();
@Test
- public void testGeneration() throws Exception {
+ public void testGeneration() {
String sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(expected1, sql);
+ assertEquals(expected1, sql);
sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "that=\'some\"\' value\'", "", null, null);
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\'";
- Assert.assertEquals(expected2, sql);
+ assertEquals(expected2, sql);
sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "that=\'some\"\' value\'", "might DESC", null, null);
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(expected3, sql);
+ assertEquals(expected3, sql);
sql = db.getSelectStatement("database.tablename", "", "that=\'some\"\' value\'", "might DESC", null, null);
String expected4 = "SELECT * FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(expected4, sql);
+ assertEquals(expected4, sql);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNoTableName() throws Exception {
- db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
+ @Test
+ public void testNoTableName() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
+ });
}
@Test
- public void testTOPQuery() throws Exception {
+ public void testTOPQuery() {
String sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "", 100L, null);
String expected1 = "SELECT TOP 100 some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(expected1, sql);
+ assertEquals(expected1, sql);
sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "contain", 100L, null);
String expected2 = "SELECT TOP 100 some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename ORDER BY contain";
- Assert.assertEquals(expected2, sql);
+ assertEquals(expected2, sql);
sql = db.getSelectStatement("database.tablename", "", "that=\'some\"\' value\'", "might DESC", 123456L, null);
String expected4 = "SELECT TOP 123456 * FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(expected4, sql);
+ assertEquals(expected4, sql);
}
@Test
- public void testPagingQuery() throws Exception {
+ public void testPagingQuery() {
String sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "contain", 100L, 0L);
String expected1 = "SELECT * FROM (SELECT TOP 100 some(set),of(columns),that,might,contain,methods,a.*, ROW_NUMBER() OVER(ORDER BY contain asc) "
+ "rnum FROM database.tablename ORDER BY contain) A WHERE rnum > 0 AND rnum <= 100";
- Assert.assertEquals(expected1, sql);
+ assertEquals(expected1, sql);
sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "contain", 10000L, 123456L);
String expected2 = "SELECT * FROM (SELECT TOP 133456 some(set),of(columns),that,might,contain,methods,a.*, ROW_NUMBER() OVER(ORDER BY contain asc) "
+ "rnum FROM database.tablename ORDER BY contain) A WHERE rnum > 123456 AND rnum <= 133456";
- Assert.assertEquals(expected2, sql);
+ assertEquals(expected2, sql);
sql = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "methods='strange'", "contain", 10000L, 123456L);
String expected3 = "SELECT * FROM (SELECT TOP 133456 some(set),of(columns),that,might,contain,methods,a.*, ROW_NUMBER() OVER(ORDER BY contain asc) rnum FROM database.tablename "
+ "WHERE methods='strange' ORDER BY contain) A WHERE rnum > 123456 AND rnum <= 133456";
- Assert.assertEquals(expected3, sql);
+ assertEquals(expected3, sql);
}
@Test
@@ -85,22 +89,22 @@ public class TestMSSQL2008DatabaseAdapter {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain",
100L, 0L, "contain");
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 0 AND contain < 100";
- Assert.assertEquals(expected1, sql1);
+ assertEquals(expected1, sql1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain",
10000L, 123456L, "contain");
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected2, sql2);
+ assertEquals(expected2, sql2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "methods='strange'",
"contain", 10000L, 123456L, "contain");
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE methods='strange' AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected3, sql3);
+ assertEquals(expected3, sql3);
// Paging (limit/offset) is only supported when an orderByClause is supplied, note that it is not honored here
String sql4 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "",
100L, null, "contain");
String expected4 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(expected4, sql4);
+ assertEquals(expected4, sql4);
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQLDatabaseAdapter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQLDatabaseAdapter.java
index de33753797..ffe643cefa 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQLDatabaseAdapter.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMSSQLDatabaseAdapter.java
@@ -17,69 +17,75 @@
package org.apache.nifi.processors.standard.db.impl;
import org.apache.nifi.processors.standard.db.DatabaseAdapter;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestMSSQLDatabaseAdapter {
final DatabaseAdapter db = new MSSQLDatabaseAdapter();
@Test
- public void testGeneration() throws Exception {
+ public void testGeneration() {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","","",null,null);
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(sql1,expected1);
+ assertEquals(sql1,expected1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","that=\'some\"\' value\'","",null,null);
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\'";
- Assert.assertEquals(sql2,expected2);
+ assertEquals(sql2,expected2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","that=\'some\"\' value\'","might DESC",null,null);
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(sql3,expected3);
+ assertEquals(sql3,expected3);
String sql4 = db.getSelectStatement("database.tablename", "","that=\'some\"\' value\'","might DESC",null,null);
String expected4 = "SELECT * FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(sql4,expected4);
+ assertEquals(sql4,expected4);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNoTableName() throws Exception {
- db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*","","",null,null);
+ @Test
+ public void testNoTableName() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*","","",null,null);
+ });
}
- @Test(expected = IllegalArgumentException.class)
- public void testPagingNoOrderBy() throws Exception {
- db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","","",10L,0L);
+ @Test
+ public void testPagingNoOrderBy() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","","",10L,0L);
+ });
}
@Test
- public void testTOPQuery() throws Exception {
+ public void testTOPQuery() {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","","",100L,null);
String expected1 = "SELECT TOP 100 some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(sql1,expected1);
+ assertEquals(sql1,expected1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","","contain",100L,null);
String expected2 = "SELECT TOP 100 some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename ORDER BY contain";
- Assert.assertEquals(sql2,expected2);
+ assertEquals(sql2,expected2);
String sql4 = db.getSelectStatement("database.tablename", "","that=\'some\"\' value\'","might DESC",123456L,null);
String expected4 = "SELECT TOP 123456 * FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(sql4,expected4);
+ assertEquals(sql4,expected4);
}
@Test
- public void testPagingQuery() throws Exception {
+ public void testPagingQuery() {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","","contain",100L,0L);
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename ORDER BY contain OFFSET 0 ROWS FETCH NEXT 100 ROWS ONLY";
- Assert.assertEquals(sql1,expected1);
+ assertEquals(sql1,expected1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","","contain",10000L,123456L);
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename ORDER BY contain OFFSET 123456 ROWS FETCH NEXT 10000 ROWS ONLY";
- Assert.assertEquals(sql2,expected2);
+ assertEquals(sql2,expected2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*","methods='strange'","contain",10000L,123456L);
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE methods='strange' ORDER BY contain OFFSET 123456 ROWS FETCH NEXT 10000 ROWS ONLY";
- Assert.assertEquals(sql3,expected3);
+ assertEquals(sql3,expected3);
}
@Test
@@ -87,22 +93,22 @@ public class TestMSSQLDatabaseAdapter {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain",
100L, 0L, "contain");
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 0 AND contain < 100";
- Assert.assertEquals(expected1, sql1);
+ assertEquals(expected1, sql1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain",
10000L, 123456L, "contain");
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected2, sql2);
+ assertEquals(expected2, sql2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "methods='strange'",
"contain", 10000L, 123456L, "contain");
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE methods='strange' AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected3, sql3);
+ assertEquals(expected3, sql3);
// Paging (limit/offset) is only supported when an orderByClause is supplied, note that it is not honored here
String sql4 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "",
100L, null, "contain");
String expected4 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(expected4, sql4);
+ assertEquals(expected4, sql4);
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMySQLDatabaseAdapter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMySQLDatabaseAdapter.java
index f4e8a0a307..5719cfe0a7 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMySQLDatabaseAdapter.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestMySQLDatabaseAdapter.java
@@ -16,59 +16,59 @@
*/
package org.apache.nifi.processors.standard.db.impl;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestMySQLDatabaseAdapter {
private MySQLDatabaseAdapter testSubject;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
testSubject = new MySQLDatabaseAdapter();
}
@Test
- public void testSupportsUpsert() throws Exception {
- assertTrue(testSubject.getClass().getSimpleName() + " should support upsert", testSubject.supportsUpsert());
+ public void testSupportsUpsert() {
+ assertTrue(testSubject.supportsUpsert(), testSubject.getClass().getSimpleName() + " should support upsert");
}
@Test
- public void testGetUpsertStatementWithNullTableName() throws Exception {
+ public void testGetUpsertStatementWithNullTableName() {
testGetUpsertStatement(null, Collections.singletonList("notEmpty"), Collections.singletonList("notEmpty"), new IllegalArgumentException("Table name cannot be null or blank"));
}
@Test
- public void testGetUpsertStatementWithBlankTableName() throws Exception {
+ public void testGetUpsertStatementWithBlankTableName() {
testGetUpsertStatement("", Collections.singletonList("notEmpty"), Collections.singletonList("notEmpty"), new IllegalArgumentException("Table name cannot be null or blank"));
}
@Test
- public void testGetUpsertStatementWithNullColumnNames() throws Exception {
+ public void testGetUpsertStatementWithNullColumnNames() {
testGetUpsertStatement("notEmpty", null, Collections.singletonList("notEmpty"), new IllegalArgumentException("Column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithEmptyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithEmptyColumnNames() {
testGetUpsertStatement("notEmpty", Collections.emptyList(), Collections.singletonList("notEmpty"), new IllegalArgumentException("Column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithNullKeyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithNullKeyColumnNames() {
testGetUpsertStatement("notEmpty", Collections.singletonList("notEmpty"), null, new IllegalArgumentException("Key column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithEmptyKeyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithEmptyKeyColumnNames() {
testGetUpsertStatement("notEmpty", Collections.singletonList("notEmpty"), Collections.emptyList(), new IllegalArgumentException("Key column names cannot be null or empty"));
}
@@ -90,7 +90,7 @@ public class TestMySQLDatabaseAdapter {
}
@Test
- public void testGetInsertIgnoreStatement() throws Exception {
+ public void testGetInsertIgnoreStatement() {
// GIVEN
String tableName = "table";
List<String> columnNames = Arrays.asList("column1", "column2", "column3", "column4");
@@ -105,12 +105,10 @@ public class TestMySQLDatabaseAdapter {
}
private void testGetUpsertStatement(String tableName, List<String> columnNames, Collection<String> uniqueKeyColumnNames, IllegalArgumentException expected) {
- try {
+ final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {
testGetUpsertStatement(tableName, columnNames, uniqueKeyColumnNames, (String) null);
- fail();
- } catch (IllegalArgumentException e) {
- assertEquals(expected.getMessage(), e.getMessage());
- }
+ });
+ assertEquals(expected.getMessage(), e.getMessage());
}
private void testGetUpsertStatement(String tableName, List<String> columnNames, Collection<String> uniqueKeyColumnNames, String expected) {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracle12DatabaseAdapter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracle12DatabaseAdapter.java
index 99d625a52b..dcc17254ec 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracle12DatabaseAdapter.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracle12DatabaseAdapter.java
@@ -16,123 +16,124 @@
*/
package org.apache.nifi.processors.standard.db.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.apache.nifi.processors.standard.db.DatabaseAdapter;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestOracle12DatabaseAdapter {
private final DatabaseAdapter db = new Oracle12DatabaseAdapter();
@Test
- public void testGeneration() throws Exception {
+ public void testGeneration() {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(sql1, expected1);
+ assertEquals(sql1, expected1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "that=\'some\"\' value\'", "", null, null);
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\'";
- Assert.assertEquals(sql2, expected2);
+ assertEquals(sql2, expected2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "that=\'some\"\' value\'", "might DESC", null, null);
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(sql3, expected3);
+ assertEquals(sql3, expected3);
String sql4 = db.getSelectStatement("database.tablename", "", "that=\'some\"\' value\'", "might DESC", null, null);
String expected4 = "SELECT * FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(sql4, expected4);
+ assertEquals(sql4, expected4);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNoTableName() throws Exception {
- db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
+ @Test
+ public void testNoTableName() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
+ });
}
@Test
- public void testPagingQuery() throws Exception {
+ public void testPagingQuery() {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "contain", 100L, 0L);
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename ORDER BY contain FETCH NEXT 100 ROWS ONLY";
- Assert.assertEquals(sql1, expected1);
+ assertEquals(sql1, expected1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "contain", 10000L, 123456L);
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename ORDER BY contain OFFSET 123456 ROWS FETCH NEXT 10000 ROWS ONLY";
- Assert.assertEquals(sql2, expected2);
+ assertEquals(sql2, expected2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "methods='strange'", "contain", 10000L, 123456L);
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE methods='strange' ORDER BY contain OFFSET 123456 ROWS FETCH NEXT 10000 ROWS ONLY";
- Assert.assertEquals(sql3, expected3);
+ assertEquals(sql3, expected3);
String sql4 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "", 100L, null);
String expected4 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename FETCH NEXT 100 ROWS ONLY";
- Assert.assertEquals(sql4, expected4);
+ assertEquals(sql4, expected4);
}
@Test
- public void testPagingQueryUsingColumnValuesForPartitioning() throws Exception {
+ public void testPagingQueryUsingColumnValuesForPartitioning() {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain", 100L, 0L, "contain");
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 0 AND contain < 100";
- Assert.assertEquals(expected1, sql1);
+ assertEquals(expected1, sql1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain", 10000L, 123456L, "contain");
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected2, sql2);
+ assertEquals(expected2, sql2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "methods='strange'", "contain", 10000L, 123456L, "contain");
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE methods='strange' AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected3, sql3);
+ assertEquals(expected3, sql3);
// Paging (limit/offset) is only supported when an orderByClause is supplied, note that it is not honored here
String sql4 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "", 100L, null, "contain");
String expected4 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(expected4, sql4);
+ assertEquals(expected4, sql4);
}
@Test
- public void testSupportsUpsert() throws Exception {
- assertTrue(db.getClass().getSimpleName() + " should support upsert", db.supportsUpsert());
+ public void testSupportsUpsert() {
+ assertTrue(db.supportsUpsert(), db.getClass().getSimpleName() + " should support upsert");
}
@Test
- public void testGetUpsertStatementWithNullTableName() throws Exception {
+ public void testGetUpsertStatementWithNullTableName() {
testGetUpsertStatement(null, Arrays.asList("notEmpty"), Arrays.asList("notEmpty"), new IllegalArgumentException("Table name cannot be null or blank"));
}
@Test
- public void testGetUpsertStatementWithBlankTableName() throws Exception {
+ public void testGetUpsertStatementWithBlankTableName() {
testGetUpsertStatement("", Arrays.asList("notEmpty"), Arrays.asList("notEmpty"), new IllegalArgumentException("Table name cannot be null or blank"));
}
@Test
- public void testGetUpsertStatementWithNullColumnNames() throws Exception {
+ public void testGetUpsertStatementWithNullColumnNames() {
testGetUpsertStatement("notEmpty", null, Arrays.asList("notEmpty"), new IllegalArgumentException("Column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithEmptyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithEmptyColumnNames() {
testGetUpsertStatement("notEmpty", Collections.emptyList(), Arrays.asList("notEmpty"), new IllegalArgumentException("Column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithNullKeyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithNullKeyColumnNames() {
testGetUpsertStatement("notEmpty", Arrays.asList("notEmpty"), null, new IllegalArgumentException("Key column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithEmptyKeyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithEmptyKeyColumnNames() {
testGetUpsertStatement("notEmpty", Arrays.asList("notEmpty"), Collections.emptyList(), new IllegalArgumentException("Key column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatement() throws Exception {
+ public void testGetUpsertStatement() {
// GIVEN
String tableName = "table";
List<String> columnNames = Arrays.asList("column1","column2", "column3", "column4");
@@ -149,12 +150,10 @@ public class TestOracle12DatabaseAdapter {
}
private void testGetUpsertStatement(String tableName, List<String> columnNames, Collection<String> uniqueKeyColumnNames, IllegalArgumentException expected) {
- try {
+ final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {
testGetUpsertStatement(tableName, columnNames, uniqueKeyColumnNames, (String)null);
- fail();
- } catch (IllegalArgumentException e) {
- assertEquals(expected.getMessage(), e.getMessage());
- }
+ });
+ assertEquals(expected.getMessage(), e.getMessage());
}
private void testGetUpsertStatement(String tableName, List<String> columnNames, Collection<String> uniqueKeyColumnNames, String expected) {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracleDatabaseAdapter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracleDatabaseAdapter.java
index d33b03c308..b0bf2d50b5 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracleDatabaseAdapter.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestOracleDatabaseAdapter.java
@@ -17,8 +17,10 @@
package org.apache.nifi.processors.standard.db.impl;
import org.apache.nifi.processors.standard.db.DatabaseAdapter;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestOracleDatabaseAdapter {
@@ -28,24 +30,26 @@ public class TestOracleDatabaseAdapter {
public void testGeneration() {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(expected1, sql1);
+ assertEquals(expected1, sql1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "that=\'some\"\' value\'", "", null, null);
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\'";
- Assert.assertEquals(expected2, sql2);
+ assertEquals(expected2, sql2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "that=\'some\"\' value\'", "might DESC", null, null);
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(expected3, sql3);
+ assertEquals(expected3, sql3);
String sql4 = db.getSelectStatement("database.tablename", "", "that=\'some\"\' value\'", "might DESC", null, null);
String expected4 = "SELECT * FROM database.tablename WHERE that=\'some\"\' value\' ORDER BY might DESC";
- Assert.assertEquals(expected4, sql4);
+ assertEquals(expected4, sql4);
}
- @Test(expected = IllegalArgumentException.class)
- public void testNoTableName() throws IllegalArgumentException {
- db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
+ @Test
+ public void testNoTableName() {
+ assertThrows(IllegalArgumentException.class, () -> {
+ db.getSelectStatement("", "some(set),of(columns),that,might,contain,methods,a.*", "", "", null, null);
+ });
}
@Test
@@ -54,25 +58,25 @@ public class TestOracleDatabaseAdapter {
100L, 0L);
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM (SELECT a.*, ROWNUM rnum FROM (SELECT some(set),of(columns),that,might,contain,methods,a.* "
+ "FROM database.tablename ORDER BY contain) a WHERE ROWNUM <= 100) WHERE rnum > 0";
- Assert.assertEquals(expected1, sql1);
+ assertEquals(expected1, sql1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "contain",
10000L, 123456L);
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM (SELECT a.*, ROWNUM rnum FROM (SELECT some(set),of(columns),that,might,contain,methods,a.* "
+ "FROM database.tablename ORDER BY contain) a WHERE ROWNUM <= 133456) WHERE rnum > 123456";
- Assert.assertEquals(expected2, sql2);
+ assertEquals(expected2, sql2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "methods='strange'",
"contain", 10000L, 123456L);
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM (SELECT a.*, ROWNUM rnum FROM (SELECT some(set),of(columns),that,might,contain,methods,a.* "
+ "FROM database.tablename WHERE methods='strange' ORDER BY contain) a WHERE ROWNUM <= 133456) WHERE rnum > 123456";
- Assert.assertEquals(expected3, sql3);
+ assertEquals(expected3, sql3);
String sql4 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "",
100L, null);
String expected4 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM (SELECT a.*, ROWNUM rnum FROM (SELECT some(set),of(columns),that,might,contain,methods,a.* "
+ "FROM database.tablename) a WHERE ROWNUM <= 100) WHERE rnum > 0";
- Assert.assertEquals(expected4, sql4);
+ assertEquals(expected4, sql4);
}
@Test
@@ -80,22 +84,22 @@ public class TestOracleDatabaseAdapter {
String sql1 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain",
100L, 0L, "contain");
String expected1 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 0 AND contain < 100";
- Assert.assertEquals(expected1, sql1);
+ assertEquals(expected1, sql1);
String sql2 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "1=1", "contain",
10000L, 123456L, "contain");
String expected2 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE 1=1 AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected2, sql2);
+ assertEquals(expected2, sql2);
String sql3 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "methods='strange'",
"contain", 10000L, 123456L, "contain");
String expected3 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename WHERE methods='strange' AND contain >= 123456 AND contain < 133456";
- Assert.assertEquals(expected3, sql3);
+ assertEquals(expected3, sql3);
// Paging (limit/offset) is only supported when an orderByClause is supplied, note that it is not honored here
String sql4 = db.getSelectStatement("database.tablename", "some(set),of(columns),that,might,contain,methods,a.*", "", "",
100L, null, "contain");
String expected4 = "SELECT some(set),of(columns),that,might,contain,methods,a.* FROM database.tablename";
- Assert.assertEquals(expected4, sql4);
+ assertEquals(expected4, sql4);
}
}
\ No newline at end of file
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestPostgreSQLDatabaseAdapter.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestPostgreSQLDatabaseAdapter.java
index c9da1910c7..ea10621867 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestPostgreSQLDatabaseAdapter.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/db/impl/TestPostgreSQLDatabaseAdapter.java
@@ -16,63 +16,63 @@
*/
package org.apache.nifi.processors.standard.db.impl;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestPostgreSQLDatabaseAdapter {
private PostgreSQLDatabaseAdapter testSubject;
- @Before
+ @BeforeEach
public void setUp() throws Exception {
testSubject = new PostgreSQLDatabaseAdapter();
}
@Test
- public void testSupportsUpsert() throws Exception {
- assertTrue(testSubject.getClass().getSimpleName() + " should support upsert", testSubject.supportsUpsert());
+ public void testSupportsUpsert() {
+ assertTrue(testSubject.supportsUpsert(), testSubject.getClass().getSimpleName() + " should support upsert");
}
@Test
- public void testGetUpsertStatementWithNullTableName() throws Exception {
+ public void testGetUpsertStatementWithNullTableName() {
testGetUpsertStatement(null, Arrays.asList("notEmpty"), Arrays.asList("notEmpty"), new IllegalArgumentException("Table name cannot be null or blank"));
}
@Test
- public void testGetUpsertStatementWithBlankTableName() throws Exception {
+ public void testGetUpsertStatementWithBlankTableName() {
testGetUpsertStatement("", Arrays.asList("notEmpty"), Arrays.asList("notEmpty"), new IllegalArgumentException("Table name cannot be null or blank"));
}
@Test
- public void testGetUpsertStatementWithNullColumnNames() throws Exception {
+ public void testGetUpsertStatementWithNullColumnNames() {
testGetUpsertStatement("notEmpty", null, Arrays.asList("notEmpty"), new IllegalArgumentException("Column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithEmptyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithEmptyColumnNames() {
testGetUpsertStatement("notEmpty", Collections.emptyList(), Arrays.asList("notEmpty"), new IllegalArgumentException("Column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithNullKeyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithNullKeyColumnNames() {
testGetUpsertStatement("notEmpty", Arrays.asList("notEmpty"), null, new IllegalArgumentException("Key column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatementWithEmptyKeyColumnNames() throws Exception {
+ public void testGetUpsertStatementWithEmptyKeyColumnNames() {
testGetUpsertStatement("notEmpty", Arrays.asList("notEmpty"), Collections.emptyList(), new IllegalArgumentException("Key column names cannot be null or empty"));
}
@Test
- public void testGetUpsertStatement() throws Exception {
+ public void testGetUpsertStatement() {
// GIVEN
String tableName = "table";
List<String> columnNames = Arrays.asList("column1","column2", "column3", "column4");
@@ -90,7 +90,7 @@ public class TestPostgreSQLDatabaseAdapter {
}
@Test
- public void testGetInsertIgnoreStatement() throws Exception {
+ public void testGetInsertIgnoreStatement() {
// GIVEN
String tableName = "table";
List<String> columnNames = Arrays.asList("column1","column2", "column3", "column4");
@@ -107,12 +107,10 @@ public class TestPostgreSQLDatabaseAdapter {
}
private void testGetUpsertStatement(String tableName, List<String> columnNames, Collection<String> uniqueKeyColumnNames, IllegalArgumentException expected) {
- try {
+ final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> {
testGetUpsertStatement(tableName, columnNames, uniqueKeyColumnNames, (String)null);
- fail();
- } catch (IllegalArgumentException e) {
- assertEquals(expected.getMessage(), e.getMessage());
- }
+ });
+ assertEquals(expected.getMessage(), e.getMessage());
}
private void testGetUpsertStatement(String tableName, List<String> columnNames, Collection<String> uniqueKeyColumnNames, String expected) {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java
index 446fbab0d5..851a8e658a 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestInsertRecordFieldsJoinStrategy.java
@@ -26,7 +26,7 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.serialization.record.type.RecordDataType;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Collections;
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestWrapperJoinStrategy.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestWrapperJoinStrategy.java
index 7a5e37dd12..5d13a4276a 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestWrapperJoinStrategy.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/enrichment/TestWrapperJoinStrategy.java
@@ -22,7 +22,7 @@ import org.apache.nifi.serialization.record.Record;
import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.serialization.record.type.RecordDataType;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.List;
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystem.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystem.java
index 538106e9ff..6e3d4b65a7 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystem.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystem.java
@@ -20,18 +20,18 @@ package org.apache.nifi.processors.standard.ftp;
import org.apache.nifi.processors.standard.ftp.filesystem.DefaultVirtualFileSystem;
import org.apache.nifi.processors.standard.ftp.filesystem.VirtualFileSystem;
import org.apache.nifi.processors.standard.ftp.filesystem.VirtualPath;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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.fail;
public class TestVirtualFileSystem {
@@ -47,7 +47,7 @@ public class TestVirtualFileSystem {
new VirtualPath("/Directory2/SubDirectory4")
);
- @Before
+ @BeforeEach
public void setup() {
setupVirtualDirectoryStructure();
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystemView.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystemView.java
index f4ebf22574..e61c9a680a 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystemView.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualFileSystemView.java
@@ -27,22 +27,22 @@ import org.apache.nifi.processors.standard.ftp.filesystem.DefaultVirtualFileSyst
import org.apache.nifi.processors.standard.ftp.filesystem.VirtualFileSystem;
import org.apache.nifi.processors.standard.ftp.filesystem.VirtualFileSystemFactory;
import org.apache.nifi.processors.standard.ftp.filesystem.VirtualPath;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.Collections;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
public class TestVirtualFileSystemView {
private FileSystemView fileSystemView;
private static VirtualFileSystem fileSystem;
- @BeforeClass
+ @BeforeAll
public static void setupVirtualFileSystem() {
fileSystem = new DefaultVirtualFileSystem();
fileSystem.mkdir(new VirtualPath("/Directory1"));
@@ -54,7 +54,7 @@ public class TestVirtualFileSystemView {
fileSystem.mkdir(new VirtualPath("/Directory2/SubDirectory4"));
}
- @Before
+ @BeforeEach
public void setup() throws FtpException {
User user = createUser();
FileSystemFactory fileSystemFactory = new VirtualFileSystemFactory(fileSystem);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualPath.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualPath.java
index b655d951df..a57ba28874 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualPath.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/ftp/TestVirtualPath.java
@@ -17,13 +17,13 @@
package org.apache.nifi.processors.standard.ftp;
import org.apache.nifi.processors.standard.ftp.filesystem.VirtualPath;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class TestVirtualPath {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPFrameDecoderTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPFrameDecoderTest.java
index 8ee2b9329d..b3b8019912 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPFrameDecoderTest.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPFrameDecoderTest.java
@@ -30,7 +30,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
class RELPFrameDecoderTest {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPResponseEncoderTest.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPResponseEncoderTest.java
index eaf4a9deef..3c2e7381f5 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPResponseEncoderTest.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/RELPResponseEncoderTest.java
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.Charset;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
class RELPResponseEncoderTest {
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPDecoder.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPDecoder.java
index ecd3921b8a..b1ac49698b 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPDecoder.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPDecoder.java
@@ -16,14 +16,17 @@
*/
package org.apache.nifi.processors.standard.relp.frame;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
public class TestRELPDecoder {
public static final String OPEN_FRAME_DATA = "relp_version=0\nrelp_software=librelp,1.2.7,http://librelp.adiscon.com\ncommands=syslog";
@@ -36,7 +39,7 @@ public class TestRELPDecoder {
private RELPDecoder decoder;
- @Before
+ @BeforeEach
public void setup() {
this.decoder = new RELPDecoder(StandardCharsets.UTF_8);
}
@@ -53,13 +56,13 @@ public class TestRELPDecoder {
}
}
- Assert.assertNotNull(frame);
- Assert.assertEquals(1, frame.getTxnr());
- Assert.assertEquals("open", frame.getCommand());
- Assert.assertEquals(85, frame.getDataLength());
+ assertNotNull(frame);
+ assertEquals(1, frame.getTxnr());
+ assertEquals("open", frame.getCommand());
+ assertEquals(85, frame.getDataLength());
- Assert.assertNotNull(frame.getData());
- Assert.assertEquals(OPEN_FRAME_DATA, new String(frame.getData(), StandardCharsets.UTF_8));
+ assertNotNull(frame.getData());
+ assertEquals(OPEN_FRAME_DATA, new String(frame.getData(), StandardCharsets.UTF_8));
}
@Test
@@ -73,31 +76,31 @@ public class TestRELPDecoder {
}
}
- Assert.assertEquals(3, frames.size());
+ assertEquals(3, frames.size());
final RELPFrame frame1 = frames.get(0);
- Assert.assertNotNull(frame1);
- Assert.assertEquals(1, frame1.getTxnr());
- Assert.assertEquals("open", frame1.getCommand());
- Assert.assertEquals(85, frame1.getDataLength());
+ assertNotNull(frame1);
+ assertEquals(1, frame1.getTxnr());
+ assertEquals("open", frame1.getCommand());
+ assertEquals(85, frame1.getDataLength());
- Assert.assertNotNull(frame1.getData());
- Assert.assertEquals(OPEN_FRAME_DATA, new String(frame1.getData(), StandardCharsets.UTF_8));
+ assertNotNull(frame1.getData());
+ assertEquals(OPEN_FRAME_DATA, new String(frame1.getData(), StandardCharsets.UTF_8));
final RELPFrame frame2 = frames.get(1);
- Assert.assertNotNull(frame2);
- Assert.assertEquals(2, frame2.getTxnr());
- Assert.assertEquals("syslog", frame2.getCommand());
- Assert.assertEquals(29, frame2.getDataLength());
+ assertNotNull(frame2);
+ assertEquals(2, frame2.getTxnr());
+ assertEquals("syslog", frame2.getCommand());
+ assertEquals(29, frame2.getDataLength());
- Assert.assertNotNull(frame2.getData());
- Assert.assertEquals(SYSLOG_FRAME_DATA, new String(frame2.getData(), StandardCharsets.UTF_8));
+ assertNotNull(frame2.getData());
+ assertEquals(SYSLOG_FRAME_DATA, new String(frame2.getData(), StandardCharsets.UTF_8));
final RELPFrame frame3 = frames.get(2);
- Assert.assertNotNull(frame3);
- Assert.assertEquals(3, frame3.getTxnr());
- Assert.assertEquals("close", frame3.getCommand());
- Assert.assertEquals(0, frame3.getDataLength());
+ assertNotNull(frame3);
+ assertEquals(3, frame3.getTxnr());
+ assertEquals("close", frame3.getCommand());
+ assertEquals(0, frame3.getDataLength());
}
@Test
@@ -117,22 +120,22 @@ public class TestRELPDecoder {
}
}
- Assert.assertEquals(3, frames.size());
+ assertEquals(3, frames.size());
}
- @Test(expected = RELPFrameException.class)
- public void testBadDataShouldThrowException() throws RELPFrameException {
- final String msg = "NAN syslog 20 this is message 1234\n";
- final byte[] input = msg.getBytes(StandardCharsets.UTF_8);
+ @Test
+ public void testBadDataShouldThrowException() {
+ assertThrows(RELPFrameException.class, () -> {
+ final String msg = "NAN syslog 20 this is message 1234\n";
+ final byte[] input = msg.getBytes(StandardCharsets.UTF_8);
- List<RELPFrame> frames = new ArrayList<>();
+ List<RELPFrame> frames = new ArrayList<>();
- for (byte b : input) {
- if (decoder.process(b)) {
- frames.add(decoder.getFrame());
+ for (byte b : input) {
+ if (decoder.process(b)) {
+ frames.add(decoder.getFrame());
+ }
}
- }
-
- Assert.fail("Should have thrown exception");
+ });
}
}
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPEncoder.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPEncoder.java
index 94cfe39762..f2b0523906 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPEncoder.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPEncoder.java
@@ -17,17 +17,18 @@
package org.apache.nifi.processors.standard.relp.frame;
import org.apache.nifi.processors.standard.relp.response.RELPResponse;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
public class TestRELPEncoder {
@Test
- public void testEncodingWithData() throws IOException {
+ public void testEncodingWithData() {
final RELPFrame frame = new RELPFrame.Builder()
.txnr(1)
.command("rsp")
@@ -40,11 +41,11 @@ public class TestRELPEncoder {
final byte[] result = encoder.encode(frame);
final String expected = "1 rsp 5 12345\n";
- Assert.assertEquals(expected, new String(result, StandardCharsets.UTF_8));
+ assertEquals(expected, new String(result, StandardCharsets.UTF_8));
}
@Test
- public void testEncodingNoData() throws IOException {
+ public void testEncodingNoData() {
final RELPFrame frame = new RELPFrame.Builder()
.txnr(1)
.command("rsp")
@@ -57,7 +58,7 @@ public class TestRELPEncoder {
final byte[] result = encoder.encode(frame);
final String expected = "1 rsp 0\n";
- Assert.assertEquals(expected, new String(result, StandardCharsets.UTF_8));
+ assertEquals(expected, new String(result, StandardCharsets.UTF_8));
}
@Test
@@ -77,7 +78,7 @@ public class TestRELPEncoder {
}
}
- Assert.assertNotNull(frame);
+ assertNotNull(frame);
final Map<String,String> offers = RELPResponse.parseOffers(frame.getData(), StandardCharsets.UTF_8);
final RELPFrame responseFrame = RELPResponse.open(frame.getTxnr(), offers).toFrame(StandardCharsets.UTF_8);
diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPFrame.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPFrame.java
index 6c3eddbd63..7481ccdcae 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPFrame.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/relp/frame/TestRELPFrame.java
@@ -16,32 +16,44 @@
*/
package org.apache.nifi.processors.standard.relp.frame;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestRELPFrame {
- @Test(expected = RELPFrameException.class)
+ @Test
public void testInvalidTxnr() {
- new RELPFrame.Builder().command("command").dataLength(5).data(new byte[5]).build();
+ assertThrows(RELPFrameException.class, () -> {
+ new RELPFrame.Builder().command("command").dataLength(5).data(new byte[5]).build();
+ });
}
- @Test(expected = RELPFrameException.class)
+ @Test
public void testInvalidCommand() {
- new RELPFrame.Builder().txnr(1).dataLength(5).data(new byte[5]).build();
+ assertThrows(RELPFrameException.class, () -> {
+ new RELPFrame.Builder().txnr(1).dataLength(5).data(new byte[5]).build();
+ });
}
- @Test(expected = RELPFrameException.class)
+ @Test
public void testBlankCommand() {
- new RELPFrame.Builder().txnr(1).command(" ").dataLength(5).data(new byte[5]).build();
+ assertThrows(RELPFrameException.class, () -> {
+ new RELPFrame.Builder().txnr(1).command(" ").dataLength(5).data(new byte[5]).build();
+ });
}
- @Test(expected = RELPFrameException.class)
+ @Test
public void testInvalidDataLength() {
... 327 lines suppressed ...