From f35f010deb069bb050bfc3a6061b0eef6a01f68e Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Wed, 25 Aug 2021 07:50:52 -0400 Subject: [PATCH] NIFI-9085 Refactored the Elasticsearch bundle to use JUnit 5 - NIFI-9086 Refactored nifi-accumulo-bundle to use JUnit 5 - NIFI-9087 Updated nifi-ambari-bundle to use JUnit 5 - NIFI-9088 Refactored nifi-amqp-bundle to use JUnit 5 - NIFI-9089 Updated nifi-asn1-bundle to use JUnit 5 - NIFI-9090 Refactored nifi-atlas-bundle to use JUnit 5 - NIFI-9091 Refactored nifi-avro-bundle to use JUnit 5 - NIFI-9092 Refactored nifi-aws-bundle to use JUnit 5 - NIFI-9095 Refactored nifi-azure-bundle to use JUnit 5 - NIFI-9145 Refactored nifi-rethinkdb-bundle to use JUnit 5 - NIFI-9143 Refactored nifi-redis-bundle to use JUnit 5 This closes #5350 Signed-off-by: David Handermann --- .../nifi/accumulo/processors/PutRecordIT.java | 26 +- .../accumulo/processors/ScanAccumuloIT.java | 83 ++-- .../TestAccumuloService.java | 6 +- .../ambari/TestAmbariReportingTask.java | 6 +- .../ambari/api/TestMetricsBuilder.java | 22 +- .../ambari/metrics/TestMetricsService.java | 51 +- .../amqp/processors/AMQPConsumerTest.java | 57 ++- .../amqp/processors/AMQPPublisherTest.java | 41 +- .../processors/AbstractAMQPProcessorTest.java | 6 +- .../nifi/amqp/processors/ConsumeAMQPTest.java | 18 +- .../nifi/amqp/processors/PublishAMQPTest.java | 12 +- .../apache/nifi/jasn1/JASN1ReaderTest.java | 18 +- .../nifi/jasn1/TestJASN1RecordReader.java | 14 +- ...TestJASN1RecordReaderWithComplexTypes.java | 2 +- .../TestJASN1RecordReaderWithSimpleTypes.java | 6 +- .../nifi/jasn1/TestRecordSchemaProvider.java | 7 +- .../apache/nifi/atlas/ITNiFiAtlasClient.java | 6 +- .../nifi/atlas/TestNiFiFlowAnalyzer.java | 18 +- .../nifi/atlas/hook/TestNiFiAtlasHook.java | 10 +- .../atlas/hook/TestNotificationSender.java | 12 +- .../analyzer/TestAwsS3DirectoryV1.java | 6 +- .../analyzer/TestAwsS3DirectoryV2.java | 6 +- .../analyzer/TestAzureADLSDirectory.java | 6 +- .../provenance/analyzer/TestFilePath.java | 6 +- .../provenance/analyzer/TestHBaseTable.java | 4 +- .../provenance/analyzer/TestHDFSPath.java | 6 +- .../provenance/analyzer/TestHive2JDBC.java | 8 +- .../provenance/analyzer/TestKafkaTopic.java | 6 +- .../analyzer/TestNiFiRemotePort.java | 8 +- .../analyzer/TestNiFiRootGroupPort.java | 8 +- .../analyzer/TestPutHiveStreaming.java | 6 +- .../analyzer/TestUnknownDataSet.java | 11 +- .../reporting/ITReportLineageToAtlas.java | 10 +- .../reporting/TestReportLineageToAtlas.java | 35 +- .../resolver/TestRegexNamespaceResolver.java | 60 ++- .../avro/TestConvertAvroToJSON.java | 9 +- .../avro/TestExtractAvroMetadata.java | 11 +- .../nifi/processors/avro/TestSplitAvro.java | 67 +-- .../processors/aws/TestAWSCredentials.java | 30 +- .../aws/cloudwatch/ITPutCloudWatchMetric.java | 6 +- .../cloudwatch/MockPutCloudWatchMetric.java | 4 +- .../cloudwatch/TestPutCloudWatchMetric.java | 76 +-- .../provider/factory/MockAWSProcessor.java | 30 +- .../TestCredentialsProviderFactory.java | 67 ++- ...dentialsProviderControllerServiceTest.java | 77 ++-- .../service/AWSProcessorProxyTest.java | 10 +- .../aws/dynamodb/DeleteDynamoDBTest.java | 38 +- .../aws/dynamodb/GetDynamoDBTest.java | 28 +- .../aws/dynamodb/ITAbstractDynamoDBTest.java | 21 +- .../ITPutGetDeleteGetDynamoDBTest.java | 435 ------------------ .../processors/aws/dynamodb/ItemKeysTest.java | 6 +- .../aws/dynamodb/PutDynamoDBTest.java | 37 +- .../firehose/ITPutKinesisFirehose.java | 20 +- ...utKinesisFirehoseWithEndpointOverride.java | 18 +- .../firehose/TestPutKinesisFirehose.java | 18 +- .../stream/ITConsumeKinesisStream.java | 6 +- .../ITConsumeKinesisStreamConnectAWS.java | 4 +- ...TConsumeKinesisStreamEndpointOverride.java | 4 +- .../kinesis/stream/ITPutKinesisStream.java | 14 +- ...TPutKinesisStreamWithEndpointOverride.java | 10 +- .../stream/TestConsumeKinesisStream.java | 10 +- .../kinesis/stream/TestPutKinesisStream.java | 12 +- .../TestAbstractKinesisRecordProcessor.java | 10 +- .../record/TestKinesisRecordProcessorRaw.java | 14 +- .../TestKinesisRecordProcessorRecord.java | 16 +- .../processors/aws/lambda/ITPutLambda.java | 67 ++- .../processors/aws/lambda/TestPutLambda.java | 24 +- .../nifi/processors/aws/s3/AbstractS3IT.java | 16 +- .../processors/aws/s3/ITDeleteS3Object.java | 2 +- .../processors/aws/s3/ITFetchS3Object.java | 2 +- .../nifi/processors/aws/s3/ITListS3.java | 2 +- .../nifi/processors/aws/s3/ITPutS3Object.java | 278 ++++++----- .../nifi/processors/aws/s3/ITTagS3Object.java | 22 +- .../processors/aws/s3/TestDeleteS3Object.java | 37 +- .../processors/aws/s3/TestFetchS3Object.java | 40 +- .../nifi/processors/aws/s3/TestListS3.java | 12 +- .../processors/aws/s3/TestPutS3Object.java | 58 ++- .../processors/aws/s3/TestTagS3Object.java | 36 +- ...tSideCEncryptionStrategyKeyValidation.java | 10 +- .../TestS3EncryptionStrategies.java | 99 ++-- ...rSideCEncryptionStrategyKeyValidation.java | 10 +- .../TestStandardS3EncryptionService.java | 41 +- ...StandardS3EncryptionServiceValidation.java | 6 +- .../nifi/processors/aws/sns/ITPutSNS.java | 12 +- .../nifi/processors/aws/sns/TestPutSNS.java | 45 +- .../nifi/processors/aws/sqs/ITDeleteSQS.java | 30 +- .../nifi/processors/aws/sqs/ITGetSQS.java | 8 +- .../nifi/processors/aws/sqs/ITPutSQS.java | 19 +- .../processors/aws/sqs/TestDeleteSQS.java | 22 +- .../nifi/processors/aws/sqs/TestGetSQS.java | 22 +- .../nifi/processors/aws/sqs/TestPutSQS.java | 39 +- .../wag/TestInvokeAWSGatewayApiCommon.java | 62 ++- .../wag/TestInvokeAmazonGatewayApiMock.java | 6 +- .../wag/TestInvokeInvokeAmazonGatewayApi.java | 10 +- .../azure/AzureGraphUserGroupProviderIT.java | 82 ++-- .../ITAbstractAzureCosmosDBDocument.java | 48 +- .../document/ITPutAzureCosmosDBRecord.java | 28 +- .../azure/cosmos/document/MockTestBase.java | 9 +- .../document/PutAzureCosmosDBRecordTest.java | 35 +- .../azure/eventhub/GetAzureEventHubTest.java | 23 +- .../azure/eventhub/PutAzureEventHubTest.java | 70 +-- .../eventhub/TestConsumeAzureEventHub.java | 12 +- .../storage/AbstractAzureBlobStorageIT.java | 8 +- .../AbstractAzureDataLakeStorageIT.java | 8 +- .../azure/storage/AbstractAzureStorageIT.java | 22 +- .../azure/storage/ITAzureBlobStorageE2E.java | 32 +- .../storage/ITDeleteAzureBlobStorage.java | 8 +- .../storage/ITDeleteAzureDataLakeStorage.java | 8 +- .../storage/ITFetchAzureBlobStorage.java | 6 +- .../storage/ITFetchAzureDataLakeStorage.java | 4 +- .../azure/storage/ITListAzureBlobStorage.java | 7 +- .../storage/ITListAzureDataLakeStorage.java | 13 +- .../azure/storage/ITPutAzureBlobStorage.java | 8 +- .../storage/ITPutAzureDataLakeStorage.java | 15 +- .../TestAbstractAzureDataLakeStorage.java | 14 +- .../storage/TestPutAzureBlobStorage.java | 2 +- .../queue/AbstractAzureQueueStorageIT.java | 8 +- .../storage/queue/GetAzureQueueStorageIT.java | 24 +- .../storage/queue/PutAzureQueueStorageIT.java | 13 +- .../queue/TestGetAzureQueueStorage.java | 13 +- .../queue/TestPutAzureQueueStorage.java | 16 +- ...estAzureBlobClientSideEncryptionUtils.java | 15 +- ...rageUtilsGetStorageCredentialsDetails.java | 27 +- ...rageUtilsValidateCredentialProperties.java | 15 +- .../TestAzureCosmosDBClientService.java | 6 +- .../TestADLSCredentialsControllerService.java | 16 +- ...reStorageCredentialsControllerService.java | 6 +- ...ageCredentialsControllerServiceLookup.java | 29 +- ...eEmulatorCredentialsControllerService.java | 6 +- ...reLogAnalyticsProvenanceReportingTask.java | 24 +- .../TestAzureLogAnalyticsReportingTask.java | 29 +- .../loganalytics/TestMetricsFactory.java | 17 +- .../azure/loganalytics/TestVerification.java | 4 +- .../elasticsearch/SearchResponseTest.groovy | 39 +- .../ElasticSearchClientService_IT.groovy | 356 +++++++------- .../ElasticSearchLookupServiceTest.groovy | 23 +- .../ElasticSearchLookupService_IT.groovy | 75 +-- ...lasticSearchStringLookupServiceTest.groovy | 17 +- .../TestFetchElasticsearchHttp.java | 121 +++-- .../TestPutElasticsearchHttp.java | 167 +++---- .../TestPutElasticsearchHttpRecord.java | 28 +- .../TestQueryElasticsearchHttp.java | 115 +++-- .../TestQueryElasticsearchHttpNoHits.java | 69 ++- .../TestScrollElasticsearchHttp.java | 90 ++-- .../AbstractByQueryElasticsearchTest.groovy | 33 +- .../AbstractJsonQueryElasticsearchTest.groovy | 21 +- .../elasticsearch/GetElasticsearchTest.groovy | 13 +- .../JsonQueryElasticsearchTest.groovy | 2 +- .../PutElasticsearchJsonTest.groovy | 51 +- .../PutElasticsearchRecordTest.groovy | 165 +++---- .../nifi/graph/OpenCypherClientServiceIT.java | 10 +- .../processors/mongodb/DeleteMongoIT.java | 15 +- .../nifi/processors/mongodb/GetMongoIT.java | 69 +-- .../nifi/processors/mongodb/PutMongoIT.java | 34 +- .../processors/mongodb/PutMongoRecordIT.java | 10 +- .../nifi/processors/mongodb/PutMongoTest.java | 17 +- .../mongodb/RunMongoAggregationIT.java | 21 +- .../mongodb/gridfs/DeleteGridFSIT.java | 11 +- .../mongodb/gridfs/FetchGridFSIT.java | 27 +- .../mongodb/gridfs/PutGridFSIT.java | 12 +- .../nifi/mongodb/MongoDBLookupServiceIT.java | 61 +-- ...RedisDistributedMapCacheClientService.java | 75 +-- .../TestRedisConnectionPoolService.java | 22 +- .../redis/state/ITRedisStateProvider.java | 18 +- .../state/TestRedisStateMapJsonSerDe.java | 37 +- .../redis/state/TestRedisStateProvider.java | 23 +- .../rethinkdb/ITAbstractRethinkDBTest.java | 55 --- .../rethinkdb/ITDeleteRethinkDBTest.java | 207 --------- .../rethinkdb/ITGetRethinkDBTest.java | 165 ------- .../rethinkdb/ITPutRethinkDBTest.java | 199 -------- .../rethinkdb/TestDeleteRethinkDB.java | 15 +- .../rethinkdb/TestGetRethinkDB.java | 25 +- .../rethinkdb/TestPutRethinkDB.java | 31 +- 173 files changed, 2472 insertions(+), 3554 deletions(-) delete mode 100644 nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITPutGetDeleteGetDynamoDBTest.java delete mode 100644 nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITAbstractRethinkDBTest.java delete mode 100644 nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITDeleteRethinkDBTest.java delete mode 100644 nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITGetRethinkDBTest.java delete mode 100644 nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITPutRethinkDBTest.java diff --git a/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/PutRecordIT.java b/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/PutRecordIT.java index 452071ef46..f8dab0475b 100644 --- a/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/PutRecordIT.java +++ b/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/PutRecordIT.java @@ -29,20 +29,19 @@ import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.Authorizations; import org.apache.accumulo.core.security.ColumnVisibility; import org.apache.accumulo.minicluster.MiniAccumuloCluster; -import org.apache.commons.lang3.SystemUtils; import org.apache.hadoop.io.Text; +import org.apache.nifi.accumulo.controllerservices.AccumuloService; +import org.apache.nifi.accumulo.controllerservices.MockAccumuloService; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.serialization.record.MockRecordParser; 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.Assert; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; -import org.apache.nifi.accumulo.controllerservices.AccumuloService; -import org.apache.nifi.accumulo.controllerservices.MockAccumuloService; +import org.junit.jupiter.api.BeforeAll; +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; @@ -55,6 +54,10 @@ import java.util.Random; import java.util.Set; import java.util.UUID; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@DisabledOnOs(OS.WINDOWS) public class PutRecordIT { public static final String DEFAULT_COLUMN_FAMILY = "family1"; @@ -75,9 +78,8 @@ public class PutRecordIT { - @BeforeClass + @BeforeAll public static void setupInstance() throws IOException, InterruptedException, AccumuloSecurityException, AccumuloException, TableExistsException { - Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS); Path tempDirectory = Files.createTempDirectory("acc"); // JUnit and Guava supply mechanisms for creating temp directories accumulo = new MiniAccumuloCluster(tempDirectory.toFile(), "password"); accumulo.start(); @@ -139,10 +141,10 @@ public class PutRecordIT { ranges.add(new Range()); scanner.setRanges(ranges); for (Map.Entry kv : scanner) { - Assert.assertTrue(kv.getKey() + " not in expected keys",expectedKeys.remove(kv.getKey())); + assertTrue(expectedKeys.remove(kv.getKey()), kv.getKey() + " not in expected keys"); } } - Assert.assertEquals(0, expectedKeys.size()); + assertEquals(0, expectedKeys.size()); } @@ -180,7 +182,7 @@ public class PutRecordIT { runner.run(); List results = runner.getFlowFilesForRelationship(PutAccumuloRecord.REL_SUCCESS); - Assert.assertTrue("Wrong count", results.size() == 1); + assertTrue(results.size() == 1, "Wrong count"); verifyKey(tableName, expectedKeys, defaultVis); if (deletes){ runner.setProperty(PutAccumuloRecord.DELETE_KEY, "true"); diff --git a/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/ScanAccumuloIT.java b/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/ScanAccumuloIT.java index 08659f3d9c..ce46a9879f 100644 --- a/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/ScanAccumuloIT.java +++ b/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-processors/src/test/java/org/apache/nifi/accumulo/processors/ScanAccumuloIT.java @@ -28,7 +28,6 @@ import org.apache.accumulo.core.data.Value; import org.apache.accumulo.core.security.Authorizations; import org.apache.accumulo.core.security.ColumnVisibility; import org.apache.accumulo.minicluster.MiniAccumuloCluster; -import org.apache.commons.lang3.SystemUtils; import org.apache.hadoop.io.Text; import org.apache.nifi.accumulo.controllerservices.MockAccumuloService; import org.apache.nifi.reporting.InitializationException; @@ -36,10 +35,10 @@ 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.Assert; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +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.charset.StandardCharsets; @@ -48,6 +47,10 @@ import java.nio.file.Path; import java.util.List; import java.util.UUID; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@DisabledOnOs(OS.WINDOWS) public class ScanAccumuloIT { public static final String DEFAULT_COLUMN_FAMILY = "family1"; @@ -58,9 +61,8 @@ public class ScanAccumuloIT { */ private static MiniAccumuloCluster accumulo; - @BeforeClass + @BeforeAll public static void setupInstance() throws IOException, InterruptedException { - Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS); Path tempDirectory = Files.createTempDirectory("acc"); // JUnit and Guava supply mechanisms for creating temp directories accumulo = new MiniAccumuloCluster(tempDirectory.toFile(), "password"); accumulo.start(); @@ -75,7 +77,7 @@ public class ScanAccumuloIT { runner.run(); List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); assertRecordCount(results, 5); } @@ -86,7 +88,7 @@ public class ScanAccumuloIT { runner.run(); List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); assertRecordCount(results, 5); } @@ -97,7 +99,7 @@ public class ScanAccumuloIT { runner.run(); List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); assertRecordCount(results, 1); } @@ -108,7 +110,7 @@ public class ScanAccumuloIT { runner.run(); List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); assertRecordCount(results, 5); } @@ -119,41 +121,48 @@ public class ScanAccumuloIT { runner.run(); List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); assertRecordCount(results, 5); } - @Test(expected = AssertionError.class) - public void testSameRowCfValueInCqErrorCfEnd() throws Exception { - TestRunner runner = createTestEnvironment("2019","2019","family1","",true,"",null); + @Test + public void testSameRowCfValueInCqErrorCfEnd() { + assertThrows(AssertionError.class, () -> { + TestRunner runner = createTestEnvironment("2019","2019","family1","",true,"",null); - runner.run(); - List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); + runner.run(); + List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); - assertRecordCount(results, 5); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); + assertRecordCount(results, 5); + }); } - @Test(expected = AssertionError.class) - public void testSameRowCfValueInCqErrorCf() throws Exception { - TestRunner runner = createTestEnvironment("2019","2019","","family2",true,"",null); + @Test + public void testSameRowCfValueInCqErrorCf() { + assertThrows(AssertionError.class, () -> { + TestRunner runner = createTestEnvironment("2019", "2019", "", "family2", true, "", null); - runner.run(); - List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); - assertRecordCount(results, 5); + runner.run(); + List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); + + assertEquals(1, results.size(), "Wrong count, received " + results.size()); + assertRecordCount(results, 5); + }); } - @Test(expected = AssertionError.class) - public void testSameRowCfValueInCqErrorNotLess() throws Exception { - TestRunner runner = createTestEnvironment("2019","2019","family1","family1",true,"",null); + @Test + public void testSameRowCfValueInCqErrorNotLess() { + assertThrows(AssertionError.class, () -> { + TestRunner runner = createTestEnvironment("2019", "2019", "family1", "family1", true, "", null); - runner.run(); - List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); + runner.run(); + List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); - assertRecordCount(results, 5); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); + assertRecordCount(results, 5); + }); } @Test @@ -163,7 +172,7 @@ public class ScanAccumuloIT { runner.run(); List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); assertValueInResult(results, "\"Test\"\n"); } @@ -175,7 +184,7 @@ public class ScanAccumuloIT { runner.run(); List results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS); - Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size()); + assertEquals(1, results.size(), "Wrong count, received " + results.size()); assertValueInResult(results, "\n"); } @@ -251,13 +260,13 @@ public class ScanAccumuloIT { private void assertRecordCount(List results, int expected) { for (MockFlowFile ff : results){ String attr = ff.getAttribute("record.count"); - Assert.assertEquals(expected, Integer.valueOf(attr).intValue()); + assertEquals(expected, Integer.valueOf(attr).intValue()); } } private void assertValueInResult(List results, String expected) { for (MockFlowFile ff : results) { - Assert.assertEquals(expected, ff.getContent()); + assertEquals(expected, ff.getContent()); } } } diff --git a/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-services/src/test/java/org/apache/nifi/accumulo/controllerservices/TestAccumuloService.java b/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-services/src/test/java/org/apache/nifi/accumulo/controllerservices/TestAccumuloService.java index 0feb3f26dc..2b903aab58 100644 --- a/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-services/src/test/java/org/apache/nifi/accumulo/controllerservices/TestAccumuloService.java +++ b/nifi-nar-bundles/nifi-accumulo-bundle/nifi-accumulo-services/src/test/java/org/apache/nifi/accumulo/controllerservices/TestAccumuloService.java @@ -21,10 +21,10 @@ import org.apache.nifi.kerberos.KerberosCredentialsService; import org.apache.nifi.kerberos.KerberosUserService; import org.apache.nifi.processor.Processor; import org.apache.nifi.reporting.InitializationException; -import org.junit.Before; -import org.junit.Test; 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.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -54,7 +54,7 @@ public class TestAccumuloService { @Mock private Processor dummyProcessor; - @Before + @BeforeEach public void init() { MockitoAnnotations.initMocks(this); diff --git a/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/TestAmbariReportingTask.java b/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/TestAmbariReportingTask.java index 0032276787..ed49e9ca00 100644 --- a/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/TestAmbariReportingTask.java +++ b/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/TestAmbariReportingTask.java @@ -25,8 +25,8 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.ReportingContext; import org.apache.nifi.reporting.ReportingInitializationContext; import org.apache.nifi.util.MockPropertyValue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -44,7 +44,7 @@ public class TestAmbariReportingTask { private ProcessGroupStatus status; - @Before + @BeforeEach public void setup() { status = new ProcessGroupStatus(); status.setId("1234"); diff --git a/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/api/TestMetricsBuilder.java b/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/api/TestMetricsBuilder.java index 9b96eb9626..ce3c689c8a 100644 --- a/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/api/TestMetricsBuilder.java +++ b/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/api/TestMetricsBuilder.java @@ -18,8 +18,7 @@ package org.apache.nifi.reporting.ambari.api; import org.apache.nifi.reporting.util.metrics.api.MetricFields; import org.apache.nifi.reporting.util.metrics.api.MetricsBuilder; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.json.Json; import javax.json.JsonArray; @@ -29,6 +28,9 @@ 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.assertNotNull; + public class TestMetricsBuilder { @Test @@ -55,22 +57,22 @@ public class TestMetricsBuilder { .build(); final JsonArray metricsArray = metricsObject.getJsonArray("metrics"); - Assert.assertNotNull(metricsArray); - Assert.assertEquals(2, metricsArray.size()); + assertNotNull(metricsArray); + assertEquals(2, metricsArray.size()); JsonObject firstMetric = metricsArray.getJsonObject(0); if (!"a".equals(firstMetric.getString(MetricFields.METRIC_NAME))) { firstMetric = metricsArray.getJsonObject(1); } - Assert.assertEquals("a", firstMetric.getString(MetricFields.METRIC_NAME)); - Assert.assertEquals(applicationId, firstMetric.getString(MetricFields.APP_ID)); - Assert.assertEquals(instanceId, firstMetric.getString(MetricFields.INSTANCE_ID)); - Assert.assertEquals(hostname, firstMetric.getString(MetricFields.HOSTNAME)); - Assert.assertEquals(String.valueOf(timestamp), firstMetric.getString(MetricFields.TIMESTAMP)); + assertEquals("a", firstMetric.getString(MetricFields.METRIC_NAME)); + assertEquals(applicationId, firstMetric.getString(MetricFields.APP_ID)); + assertEquals(instanceId, firstMetric.getString(MetricFields.INSTANCE_ID)); + assertEquals(hostname, firstMetric.getString(MetricFields.HOSTNAME)); + assertEquals(String.valueOf(timestamp), firstMetric.getString(MetricFields.TIMESTAMP)); final JsonObject firstMetricValues = firstMetric.getJsonObject("metrics"); - Assert.assertEquals("1", firstMetricValues.getString("" + timestamp)); + assertEquals("1", firstMetricValues.getString("" + timestamp)); } } diff --git a/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/metrics/TestMetricsService.java b/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/metrics/TestMetricsService.java index 32f68819e1..80fc1b194b 100644 --- a/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/metrics/TestMetricsService.java +++ b/nifi-nar-bundles/nifi-ambari-bundle/nifi-ambari-reporting-task/src/test/java/org/apache/nifi/reporting/ambari/metrics/TestMetricsService.java @@ -22,13 +22,14 @@ import org.apache.nifi.metrics.jvm.JmxJvmMetrics; import org.apache.nifi.metrics.jvm.JvmMetrics; import org.apache.nifi.reporting.util.metrics.MetricNames; import org.apache.nifi.reporting.util.metrics.MetricsService; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collection; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestMetricsService { @Test @@ -65,17 +66,17 @@ public class TestMetricsService { final Map metrics = service.getMetrics(status, false); - Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED)); - Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED)); - Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT)); - Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_SENT)); - Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED)); - Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED)); - Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ)); - Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN)); - Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS)); - Assert.assertTrue(metrics.containsKey(MetricNames.TOTAL_TASK_DURATION_SECONDS)); - Assert.assertTrue(metrics.containsKey(MetricNames.TOTAL_TASK_DURATION_NANOS)); + assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED)); + assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED)); + assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT)); + assertTrue(metrics.containsKey(MetricNames.BYTES_SENT)); + assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED)); + assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED)); + assertTrue(metrics.containsKey(MetricNames.BYTES_READ)); + assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN)); + assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS)); + assertTrue(metrics.containsKey(MetricNames.TOTAL_TASK_DURATION_SECONDS)); + assertTrue(metrics.containsKey(MetricNames.TOTAL_TASK_DURATION_NANOS)); } @Test @@ -113,7 +114,7 @@ public class TestMetricsService { final Map metrics = service.getMetrics(status, true); - Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED + MetricNames.METRIC_NAME_SEPARATOR + id)); + assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED + MetricNames.METRIC_NAME_SEPARATOR + id)); } @Test @@ -122,17 +123,17 @@ public class TestMetricsService { final MetricsService service = new MetricsService(); final Map metrics = service.getMetrics(virtualMachineMetrics); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_UPTIME)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USED)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USAGE)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_NON_HEAP_USAGE)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_RUNNABLE)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_BLOCKED)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TIMED_WAITING)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TERMINATED)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_COUNT)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_DAEMON_THREAD_COUNT)); - Assert.assertTrue(metrics.containsKey(MetricNames.JVM_FILE_DESCRIPTOR_USAGE)); + assertTrue(metrics.containsKey(MetricNames.JVM_UPTIME)); + assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USED)); + assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USAGE)); + assertTrue(metrics.containsKey(MetricNames.JVM_NON_HEAP_USAGE)); + assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_RUNNABLE)); + assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_BLOCKED)); + assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TIMED_WAITING)); + assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TERMINATED)); + assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_COUNT)); + assertTrue(metrics.containsKey(MetricNames.JVM_DAEMON_THREAD_COUNT)); + assertTrue(metrics.containsKey(MetricNames.JVM_FILE_DESCRIPTOR_USAGE)); } } diff --git a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPConsumerTest.java b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPConsumerTest.java index 323b0b174d..e4d7b1d162 100644 --- a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPConsumerTest.java +++ b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPConsumerTest.java @@ -16,11 +16,12 @@ */ package org.apache.nifi.amqp.processors; -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.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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import java.io.IOException; @@ -32,18 +33,18 @@ import java.util.Map; import java.util.concurrent.TimeoutException; import org.apache.nifi.logging.ComponentLog; -import org.junit.Before; -import org.junit.Test; import com.rabbitmq.client.AMQP.BasicProperties; import com.rabbitmq.client.Connection; import com.rabbitmq.client.GetResponse; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class AMQPConsumerTest { private ComponentLog processorLog; - @Before + @BeforeEach public void setUp() { processorLog = mock(ComponentLog.class); } @@ -77,29 +78,35 @@ public class AMQPConsumerTest { assertTrue(consumer.closed); } - @Test(expected = IllegalArgumentException.class) - public void failOnNullConnection() throws IOException { - new AMQPConsumer(null, null, true, processorLog); + @Test + public void failOnNullConnection() { + assertThrows(IllegalArgumentException.class, () -> new AMQPConsumer(null, null, true, processorLog)); } - @Test(expected = IllegalArgumentException.class) - public void failOnNullQueueName() throws Exception { - Connection conn = new TestConnection(null, null); - new AMQPConsumer(conn, null, true, processorLog); + @Test + public void failOnNullQueueName() { + assertThrows(IllegalArgumentException.class, () -> { + Connection conn = new TestConnection(null, null); + new AMQPConsumer(conn, null, true, processorLog); + }); } - @Test(expected = IllegalArgumentException.class) - public void failOnEmptyQueueName() throws Exception { - Connection conn = new TestConnection(null, null); - new AMQPConsumer(conn, " ", true, processorLog); + @Test + public void failOnEmptyQueueName() { + assertThrows(IllegalArgumentException.class, () -> { + Connection conn = new TestConnection(null, null); + new AMQPConsumer(conn, " ", true, processorLog); + }); } - @Test(expected = IOException.class) - public void failOnNonExistingQueue() throws Exception { - Connection conn = new TestConnection(null, null); - try (AMQPConsumer consumer = new AMQPConsumer(conn, "hello", true, processorLog)) { - consumer.consume(); - } + @Test + public void failOnNonExistingQueue() { + assertThrows(IOException.class, () -> { + Connection conn = new TestConnection(null, null); + try (AMQPConsumer consumer = new AMQPConsumer(conn, "hello", true, processorLog)) { + consumer.consume(); + } + }); } @Test diff --git a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPPublisherTest.java b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPPublisherTest.java index db3acd0708..1429078d85 100644 --- a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPPublisherTest.java +++ b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AMQPPublisherTest.java @@ -16,7 +16,8 @@ */ package org.apache.nifi.amqp.processors; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -28,7 +29,7 @@ import java.util.Map; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.util.MockComponentLog; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import com.rabbitmq.client.AMQP.BasicProperties; @@ -38,27 +39,31 @@ import com.rabbitmq.client.ReturnListener; public class AMQPPublisherTest { @SuppressWarnings("resource") - @Test(expected = IllegalArgumentException.class) + @Test public void failOnNullConnection() { - new AMQPPublisher(null, null); + assertThrows(IllegalArgumentException.class, () -> new AMQPPublisher(null, null)); } - @Test(expected = AMQPRollbackException.class) - public void failPublishIfChannelClosed() throws Exception { - Connection conn = new TestConnection(null, null); - try (AMQPPublisher sender = new AMQPPublisher(conn, mock(ComponentLog.class))) { - conn.close(); - sender.publish("oleg".getBytes(), null, "foo", ""); - } + @Test + public void failPublishIfChannelClosed() { + assertThrows(AMQPRollbackException.class, () -> { + Connection conn = new TestConnection(null, null); + try (AMQPPublisher sender = new AMQPPublisher(conn, mock(ComponentLog.class))) { + conn.close(); + sender.publish("oleg".getBytes(), null, "foo", ""); + } + }); } - @Test(expected = AMQPException.class) - public void failPublishIfChannelFails() throws Exception { - TestConnection conn = new TestConnection(null, null); - try (AMQPPublisher sender = new AMQPPublisher(conn, mock(ComponentLog.class))) { - ((TestChannel) conn.createChannel()).corruptChannel(); - sender.publish("oleg".getBytes(), null, "foo", ""); - } + @Test + public void failPublishIfChannelFails() { + assertThrows(AMQPException.class, () -> { + TestConnection conn = new TestConnection(null, null); + try (AMQPPublisher sender = new AMQPPublisher(conn, mock(ComponentLog.class))) { + ((TestChannel) conn.createChannel()).corruptChannel(); + sender.publish("oleg".getBytes(), null, "foo", ""); + } + }); } @Test diff --git a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AbstractAMQPProcessorTest.java b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AbstractAMQPProcessorTest.java index 2273b56a15..75fe218b4e 100644 --- a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AbstractAMQPProcessorTest.java +++ b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/AbstractAMQPProcessorTest.java @@ -20,8 +20,8 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.ssl.SSLContextService; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -34,7 +34,7 @@ public class AbstractAMQPProcessorTest { private TestRunner testRunner; - @Before + @BeforeEach public void setUp() { testRunner = TestRunners.newTestRunner(ConsumeAMQP.class); diff --git a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/ConsumeAMQPTest.java b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/ConsumeAMQPTest.java index 3704c9e429..6daf5d979c 100644 --- a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/ConsumeAMQPTest.java +++ b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/ConsumeAMQPTest.java @@ -16,9 +16,10 @@ */ package org.apache.nifi.amqp.processors; -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; import static org.mockito.Mockito.mock; import java.io.IOException; @@ -37,12 +38,11 @@ import org.apache.nifi.processor.exception.ProcessException; 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 com.rabbitmq.client.AMQP; import com.rabbitmq.client.Connection; import com.rabbitmq.client.MessageProperties; +import org.junit.jupiter.api.Test; public class ConsumeAMQPTest { @@ -191,7 +191,7 @@ public class ConsumeAMQPTest { successFF.assertAttributeEquals("amqp$exchange", "myExchange"); String headers = successFF.getAttribute("amqp$headers"); Map properties = convertStringToMap(headers.substring(1,headers.length()-1),"|"); - Assert.assertEquals(headersMap,properties); + assertEquals(headersMap,properties); } } @Test @@ -260,7 +260,7 @@ public class ConsumeAMQPTest { successFF.assertAttributeEquals("amqp$exchange", "myExchange"); String headers = successFF.getAttribute("amqp$headers"); Map properties = convertStringToMap(headers,"|"); - Assert.assertEquals(headersMap,properties); + assertEquals(headersMap,properties); } } @@ -290,7 +290,7 @@ public class ConsumeAMQPTest { successFF.assertAttributeEquals("amqp$exchange", "myExchange"); String headers = successFF.getAttribute("amqp$headers"); Map properties = convertStringToMap(headers.substring(1,headers.length()-1),","); - Assert.assertEquals(headersMap,properties); + assertEquals(headersMap,properties); } } @@ -300,7 +300,7 @@ public class ConsumeAMQPTest { String[] pairs = map.split(Pattern.quote(String.valueOf(splitCharacter))); for (String pair : pairs) { String[] keyValue = pair.split("=", 2); - Assert.assertEquals(2,keyValue.length); + assertEquals(2,keyValue.length); headers.put(keyValue[0].trim(), keyValue[1].trim()); } return headers; diff --git a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/PublishAMQPTest.java b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/PublishAMQPTest.java index 3d7e8f7b81..664862576f 100644 --- a/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/PublishAMQPTest.java +++ b/nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/test/java/org/apache/nifi/amqp/processors/PublishAMQPTest.java @@ -16,11 +16,6 @@ */ package org.apache.nifi.amqp.processors; -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 java.util.Arrays; import java.util.Collections; import java.util.Date; @@ -33,11 +28,16 @@ import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Test; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.GetResponse; +import org.junit.jupiter.api.Test; + +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 PublishAMQPTest { diff --git a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/JASN1ReaderTest.java b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/JASN1ReaderTest.java index d23514df18..987d01e592 100644 --- a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/JASN1ReaderTest.java +++ b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/JASN1ReaderTest.java @@ -19,16 +19,16 @@ package org.apache.nifi.jasn1; import org.apache.nifi.controller.ConfigurationContext; import org.apache.nifi.controller.ControllerServiceInitializationContext; import org.apache.nifi.logging.ComponentLog; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static org.apache.nifi.jasn1.JASN1Reader.ASN_FILES; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -41,7 +41,7 @@ public class JASN1ReaderTest { @Mock private ComponentLog logger; - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this); @@ -52,8 +52,8 @@ public class JASN1ReaderTest { testSubject.initialize(context); } - @After - public void tearDown() throws Exception { + @AfterEach + public void tearDown() { assertTrue(testSubject.asnOutDir.toFile().exists()); testSubject.deleteAsnOutDir(); diff --git a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java index 2db35a3ec3..dda8d593c2 100644 --- a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java +++ b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReader.java @@ -22,21 +22,21 @@ import org.apache.nifi.serialization.record.RecordField; import org.apache.nifi.serialization.record.RecordSchema; import org.apache.nifi.serialization.record.type.RecordDataType; import org.apache.nifi.util.MockComponentLog; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.InputStream; import java.math.BigInteger; import java.util.Optional; -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.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 TestJASN1RecordReader implements JASN1ReadRecordTester { - @BeforeClass + @BeforeAll public static void setup() { System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.jasn1", "DEBUG"); } diff --git a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithComplexTypes.java b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithComplexTypes.java index 5fb2575254..b438998530 100644 --- a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithComplexTypes.java +++ b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithComplexTypes.java @@ -36,7 +36,7 @@ import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordSchema; import org.apache.nifi.serialization.record.type.ArrayDataType; import org.apache.nifi.serialization.record.type.RecordDataType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigInteger; import java.util.Arrays; diff --git a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithSimpleTypes.java b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithSimpleTypes.java index 1444a529de..c6cb13a638 100644 --- a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithSimpleTypes.java +++ b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestJASN1RecordReaderWithSimpleTypes.java @@ -43,7 +43,7 @@ import org.apache.nifi.serialization.SimpleRecordSchema; import org.apache.nifi.serialization.record.RecordField; import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordSchema; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigInteger; import java.time.LocalDate; @@ -54,8 +54,8 @@ import java.util.HashMap; import java.util.Map; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; /** * Depends on generated test classes diff --git a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestRecordSchemaProvider.java b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestRecordSchemaProvider.java index 15e57ab1ed..412cd53d0f 100644 --- a/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestRecordSchemaProvider.java +++ b/nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/TestRecordSchemaProvider.java @@ -25,12 +25,13 @@ import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordSchema; import org.apache.nifi.serialization.record.type.ArrayDataType; import org.apache.nifi.serialization.record.type.RecordDataType; -import org.junit.Test; +import org.junit.jupiter.api.Test; 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; + /** * Depends on generated test classes diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/ITNiFiAtlasClient.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/ITNiFiAtlasClient.java index 69a3042cf4..5cdd3f4544 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/ITNiFiAtlasClient.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/ITNiFiAtlasClient.java @@ -23,8 +23,8 @@ import org.apache.nifi.atlas.security.AtlasAuthN; import org.apache.nifi.atlas.security.Basic; import org.apache.nifi.context.PropertyContext; import org.apache.nifi.util.MockPropertyValue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,7 +37,7 @@ public class ITNiFiAtlasClient { private static final Logger logger = LoggerFactory.getLogger(ITNiFiAtlasClient.class); private NiFiAtlasClient atlasClient; - @Before + @BeforeEach public void setup() { // Add your atlas server ip address into /etc/hosts as atlas.example.com PropertyContext propertyContext = mock(PropertyContext.class); diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/TestNiFiFlowAnalyzer.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/TestNiFiFlowAnalyzer.java index 33efe45b24..5b42c4dac7 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/TestNiFiFlowAnalyzer.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/TestNiFiFlowAnalyzer.java @@ -23,8 +23,8 @@ import org.apache.nifi.controller.status.PortStatus; import org.apache.nifi.controller.status.ProcessGroupStatus; import org.apache.nifi.controller.status.ProcessorStatus; import org.apache.nifi.util.Tuple; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.function.Function; @@ -32,7 +32,7 @@ import java.util.function.Function; import static org.apache.nifi.atlas.AtlasUtils.toQualifiedName; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_QUEUE; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Test {@link NiFiFlowAnalyzer} with simple mock code. @@ -42,8 +42,8 @@ public class TestNiFiFlowAnalyzer { private int componentId = 0; - @Before - public void before() throws Exception { + @BeforeEach + public void before() { componentId = 0; } @@ -57,7 +57,7 @@ public class TestNiFiFlowAnalyzer { } @Test - public void testEmptyFlow() throws Exception { + public void testEmptyFlow() { ProcessGroupStatus rootPG = createEmptyProcessGroupStatus(); final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer(); @@ -145,7 +145,7 @@ public class TestNiFiFlowAnalyzer { @Test - public void testProcessorsWithinSinglePath() throws Exception { + public void testProcessorsWithinSinglePath() { ProcessGroupStatus rootPG = createEmptyProcessGroupStatus(); @@ -175,7 +175,7 @@ public class TestNiFiFlowAnalyzer { } @Test - public void testMultiPaths() throws Exception { + public void testMultiPaths() { ProcessGroupStatus rootPG = createEmptyProcessGroupStatus(); @@ -217,7 +217,7 @@ public class TestNiFiFlowAnalyzer { } @Test - public void testMultiPathsJoint() throws Exception { + public void testMultiPathsJoint() { ProcessGroupStatus rootPG = createEmptyProcessGroupStatus(); diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNiFiAtlasHook.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNiFiAtlasHook.java index bd7dca63cc..a5c82ad75b 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNiFiAtlasHook.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNiFiAtlasHook.java @@ -17,18 +17,18 @@ package org.apache.nifi.atlas.hook; import org.apache.atlas.model.notification.HookNotification; -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.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; public class TestNiFiAtlasHook { private NiFiAtlasHook hook; - @Before + @BeforeEach public void setUp() { hook = new NiFiAtlasHook() { @Override diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNotificationSender.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNotificationSender.java index 2a9e7688d3..1fae81f193 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNotificationSender.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/hook/TestNotificationSender.java @@ -25,7 +25,7 @@ import org.apache.atlas.v1.model.notification.HookNotificationV1; import org.apache.hadoop.security.UserGroupInformation; import org.apache.nifi.atlas.AtlasUtils; import org.apache.nifi.atlas.NiFiAtlasClient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,10 +50,10 @@ import static org.apache.nifi.atlas.NiFiTypes.TYPE_DATASET; import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_FLOW_PATH; import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_QUEUE; import static org.apache.nifi.atlas.hook.NiFiAtlasHook.NIFI_USER; -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; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -114,7 +114,7 @@ public class TestNotificationSender { assertIOReferences(expect, actual, ATTR_OUTPUTS); hasFlowPathSeen = true; } else { - assertFalse("Types other than nifi_flow_path should be created before any nifi_flow_path entity.", hasFlowPathSeen); + assertFalse(hasFlowPathSeen, "Types other than nifi_flow_path should be created before any nifi_flow_path entity."); } } } diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV1.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV1.java index 69f5d886c9..c56a61f1ec 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV1.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV1.java @@ -18,7 +18,7 @@ package org.apache.nifi.atlas.provenance.analyzer; import org.apache.atlas.v1.model.instance.Referenceable; import org.apache.nifi.atlas.provenance.DataSetRefs; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; @@ -26,8 +26,8 @@ import static org.apache.nifi.atlas.provenance.analyzer.AwsS3Directory.ATTR_BUCK import static org.apache.nifi.atlas.provenance.analyzer.AwsS3Directory.ATTR_OBJECT_PREFIX_V1; import static org.apache.nifi.atlas.provenance.analyzer.AwsS3Directory.TYPE_BUCKET_V1; import static org.apache.nifi.atlas.provenance.analyzer.AwsS3Directory.TYPE_DIRECTORY_V1; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TestAwsS3DirectoryV1 extends AbstractTestAwsS3Directory { diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV2.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV2.java index 8b0b73c763..77cfae74d8 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV2.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAwsS3DirectoryV2.java @@ -20,15 +20,15 @@ import org.apache.atlas.utils.AtlasPathExtractorUtil; import org.apache.atlas.v1.model.instance.Referenceable; import org.apache.commons.lang3.StringUtils; import org.apache.nifi.atlas.provenance.DataSetRefs; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; import static org.apache.nifi.atlas.provenance.analyzer.AwsS3Directory.ATTR_CONTAINER_V2; import static org.apache.nifi.atlas.provenance.analyzer.AwsS3Directory.ATTR_OBJECT_PREFIX_V2; import static org.apache.nifi.atlas.provenance.analyzer.AwsS3Directory.TYPE_BUCKET_V2; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TestAwsS3DirectoryV2 extends AbstractTestAwsS3Directory { diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAzureADLSDirectory.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAzureADLSDirectory.java index aad8448dcd..d7c44169ec 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAzureADLSDirectory.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestAzureADLSDirectory.java @@ -25,7 +25,7 @@ import org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzerFactory; import org.apache.nifi.atlas.resolver.NamespaceResolver; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; @@ -35,8 +35,8 @@ import static org.apache.nifi.atlas.provenance.analyzer.AzureADLSDirectory.ATTR_ import static org.apache.nifi.atlas.provenance.analyzer.AzureADLSDirectory.TYPE_ACCOUNT; import static org.apache.nifi.atlas.provenance.analyzer.AzureADLSDirectory.TYPE_CONTAINER; import static org.apache.nifi.atlas.provenance.analyzer.AzureADLSDirectory.TYPE_DIRECTORY; -import static org.junit.Assert.assertEquals; -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.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestFilePath.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestFilePath.java index 485f76193d..7a54db0d4f 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestFilePath.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestFilePath.java @@ -25,13 +25,13 @@ import org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzerFactory; import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; -import static org.junit.Assert.assertEquals; -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.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHBaseTable.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHBaseTable.java index 019b7f59d4..9d21c7e66d 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHBaseTable.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHBaseTable.java @@ -24,7 +24,7 @@ import org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzerFactory; import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.nifi.atlas.NiFiTypes.ATTR_CLUSTER_NAME; @@ -34,7 +34,7 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_URI; import static org.apache.nifi.atlas.provenance.analyzer.HBaseTable.ATTR_NAMESPACE; import static org.apache.nifi.atlas.provenance.analyzer.HBaseTable.TYPE_HBASE_NAMESPACE; import static org.apache.nifi.atlas.provenance.analyzer.HBaseTable.TYPE_HBASE_TABLE; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHDFSPath.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHDFSPath.java index d8ae13da2e..6d25c5419e 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHDFSPath.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHDFSPath.java @@ -25,13 +25,13 @@ import org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzerFactory; import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; -import static org.junit.Assert.assertEquals; -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.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHive2JDBC.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHive2JDBC.java index 82f4e1e294..f6f32a8b81 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHive2JDBC.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestHive2JDBC.java @@ -24,7 +24,7 @@ import org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzerFactory; import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.HashMap; @@ -34,9 +34,9 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATTR_INPUT_TABLES; import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATTR_OUTPUT_TABLES; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestKafkaTopic.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestKafkaTopic.java index 1b16c8b861..c26d4d67bc 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestKafkaTopic.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestKafkaTopic.java @@ -24,13 +24,13 @@ import org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzerFactory; import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; -import static org.junit.Assert.assertEquals; -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.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRemotePort.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRemotePort.java index 71b02841e4..b789427a29 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRemotePort.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRemotePort.java @@ -27,7 +27,7 @@ import org.apache.nifi.controller.status.ConnectionStatus; import org.apache.nifi.flowfile.attributes.SiteToSiteAttributes; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -37,9 +37,9 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_INPUT_PORT; import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRootGroupPort.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRootGroupPort.java index d5a9541e61..b5f7dba585 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRootGroupPort.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestNiFiRootGroupPort.java @@ -26,7 +26,7 @@ import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.controller.status.ConnectionStatus; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -36,9 +36,9 @@ import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_INPUT_PORT; import static org.apache.nifi.atlas.NiFiTypes.TYPE_NIFI_OUTPUT_PORT; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestPutHiveStreaming.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestPutHiveStreaming.java index d84751a2a2..4482eb3bc6 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestPutHiveStreaming.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestPutHiveStreaming.java @@ -24,14 +24,14 @@ import org.apache.nifi.atlas.provenance.NiFiProvenanceEventAnalyzerFactory; import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; import static org.apache.nifi.atlas.provenance.analyzer.DatabaseAnalyzerUtil.ATTR_OUTPUT_TABLES; -import static org.junit.Assert.assertEquals; -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.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestUnknownDataSet.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestUnknownDataSet.java index b984d0a18c..884fbca23b 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestUnknownDataSet.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/provenance/analyzer/TestUnknownDataSet.java @@ -25,7 +25,7 @@ import org.apache.nifi.atlas.resolver.NamespaceResolvers; import org.apache.nifi.controller.status.ConnectionStatus; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -33,9 +33,9 @@ import java.util.List; import static org.apache.nifi.atlas.NiFiTypes.ATTR_NAME; import static org.apache.nifi.atlas.NiFiTypes.ATTR_QUALIFIED_NAME; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +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.mockito.ArgumentMatchers.matches; import static org.mockito.Mockito.when; @@ -96,7 +96,6 @@ public class TestUnknownDataSet { assertNotNull(analyzer); final DataSetRefs refs = analyzer.analyze(context, record); - assertNull("If the processor has incoming connections, no refs should be created", refs); + assertNull(refs, "If the processor has incoming connections, no refs should be created"); } - } diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/ITReportLineageToAtlas.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/ITReportLineageToAtlas.java index 12205755b6..57c139417b 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/ITReportLineageToAtlas.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/ITReportLineageToAtlas.java @@ -44,9 +44,9 @@ import org.apache.nifi.util.MockComponentLog; import org.apache.nifi.util.MockConfigurationContext; import org.apache.nifi.util.MockPropertyValue; import org.codehaus.jackson.map.ObjectMapper; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.Attributes; @@ -487,7 +487,7 @@ public class ITReportLineageToAtlas { } } - @Before + @BeforeEach public void startEmulator() throws Exception { if (useEmbeddedEmulator) { atlasAPIServer.start(); @@ -503,7 +503,7 @@ public class ITReportLineageToAtlas { } } - @After + @AfterEach public void stopEmulator() throws Exception { if (useEmbeddedEmulator) { atlasAPIServer.stop(); diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/TestReportLineageToAtlas.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/TestReportLineageToAtlas.java index 507660a825..7044a2c949 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/TestReportLineageToAtlas.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/reporting/TestReportLineageToAtlas.java @@ -37,9 +37,9 @@ import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.MockPropertyValue; import org.apache.nifi.util.MockValidationContext; import org.apache.nifi.util.file.FileUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Node; @@ -73,10 +73,11 @@ import static org.apache.nifi.atlas.reporting.ReportLineageToAtlas.ATLAS_URLS; import static org.apache.nifi.atlas.reporting.ReportLineageToAtlas.ATLAS_USER; import static org.apache.nifi.atlas.reporting.ReportLineageToAtlas.KAFKA_BOOTSTRAP_SERVERS; import static org.apache.nifi.atlas.reporting.ReportLineageToAtlas.SSL_CONTEXT_SERVICE; -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.assertThrows; +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.mock; import static org.mockito.Mockito.when; @@ -93,7 +94,7 @@ public class TestReportLineageToAtlas { private ReportingContext reportingContext; private String atlasConfDir; - @Before + @BeforeEach public void setUp() throws Exception { testSubject = new ReportLineageToAtlas(); componentLogger = new MockComponentLog("reporting-task-id", testSubject); @@ -104,7 +105,7 @@ public class TestReportLineageToAtlas { atlasConfDir = createAtlasConfDir(); } - @After + @AfterEach public void tearDown() throws Exception { cleanUpAtlasConfDir(); } @@ -122,7 +123,7 @@ public class TestReportLineageToAtlas { } @Test - public void validateAtlasUrlsFromProperty() throws Exception { + public void validateAtlasUrlsFromProperty() { final MockProcessContext processContext = new MockProcessContext(testSubject); final MockValidationContext validationContext = new MockValidationContext(processContext); @@ -150,7 +151,7 @@ public class TestReportLineageToAtlas { // Invalid URL. processContext.setProperty(ATLAS_URLS, "invalid"); assertResults.accept(testSubject.validate(validationContext), - r -> assertTrue("Atlas URLs is invalid", !r.isValid())); + r -> assertTrue(!r.isValid(), "Atlas URLs is invalid")); // Valid URL processContext.setProperty(ATLAS_URLS, "http://atlas.example.com:21000"); @@ -167,7 +168,7 @@ public class TestReportLineageToAtlas { // Invalid and Valid URLs processContext.setProperty(ATLAS_URLS, "invalid, http://atlas2.example.com:21000"); assertResults.accept(testSubject.validate(validationContext), - r -> assertTrue("Atlas URLs is invalid", !r.isValid())); + r -> assertTrue(!r.isValid(), "Atlas URLs is invalid")); } @Test @@ -194,8 +195,8 @@ public class TestReportLineageToAtlas { atlasConf.setProperty("atlas.rest.address", atlasUrls); Consumer assertion = e -> assertTrue( - "Expected " + MalformedURLException.class.getSimpleName() + " for " + atlasUrls + ", got " + e, - e.getCause() instanceof MalformedURLException + e.getCause() instanceof MalformedURLException, + "Expected " + MalformedURLException.class.getSimpleName() + " for " + atlasUrls + ", got " + e ); // WHEN @@ -217,7 +218,7 @@ public class TestReportLineageToAtlas { propertiesAdjustment, () -> fail(), e -> { - assertTrue("Expected a " + ProcessException.class.getSimpleName() + ", got " + e, e instanceof ProcessException); + assertTrue(e instanceof ProcessException, "Expected a " + ProcessException.class.getSimpleName() + ", got " + e); exceptionConsumer.accept(e); } ); @@ -496,7 +497,7 @@ public class TestReportLineageToAtlas { assertFalse(isAsync); } - @Test(expected = ProcessException.class) + @Test public void testThrowExceptionWhenAtlasConfIsProvidedButSynchronousModeHasNotBeenSet() throws Exception { Properties atlasConf = new Properties(); saveAtlasConf(atlasConf); @@ -507,7 +508,7 @@ public class TestReportLineageToAtlas { ConfigurationContext configurationContext = new MockConfigurationContext(properties, null); testSubject.initialize(initializationContext); - testSubject.setup(configurationContext); + assertThrows(ProcessException.class, () -> testSubject.setup(configurationContext)); } private void saveAtlasConf(Properties atlasConf) throws IOException { diff --git a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/resolver/TestRegexNamespaceResolver.java b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/resolver/TestRegexNamespaceResolver.java index 5bc9492f69..4361d671a9 100644 --- a/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/resolver/TestRegexNamespaceResolver.java +++ b/nifi-nar-bundles/nifi-atlas-bundle/nifi-atlas-reporting-task/src/test/java/org/apache/nifi/atlas/resolver/TestRegexNamespaceResolver.java @@ -19,8 +19,7 @@ package org.apache.nifi.atlas.resolver; import org.apache.nifi.components.ValidationContext; import org.apache.nifi.components.ValidationResult; import org.apache.nifi.context.PropertyContext; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.Collection; @@ -28,6 +27,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import static junit.framework.TestCase.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; public class TestRegexNamespaceResolver { @@ -49,10 +51,10 @@ public class TestRegexNamespaceResolver { // It should be valid final Collection validationResults = resolver.validate(validationContext); - Assert.assertEquals(0, validationResults.size()); + assertEquals(0, validationResults.size()); resolver.configure(context); - Assert.assertNull(resolver.fromHostNames("example.com")); + assertNull(resolver.fromHostNames("example.com")); } @Test @@ -63,15 +65,11 @@ public class TestRegexNamespaceResolver { final RegexNamespaceResolver resolver = new RegexNamespaceResolver(); final Collection validationResults = resolver.validate(validationContext); - Assert.assertEquals(1, validationResults.size()); + assertEquals(1, validationResults.size()); final ValidationResult validationResult = validationResults.iterator().next(); - Assert.assertEquals(RegexNamespaceResolver.PATTERN_PROPERTY_PREFIX, validationResult.getSubject()); + assertEquals(RegexNamespaceResolver.PATTERN_PROPERTY_PREFIX, validationResult.getSubject()); - try { - resolver.configure(context); - Assert.fail("Configure method should fail, too"); - } catch (IllegalArgumentException e) { - } + assertThrows(IllegalArgumentException.class, () -> resolver.configure(context)); } @Test @@ -83,15 +81,11 @@ public class TestRegexNamespaceResolver { final RegexNamespaceResolver resolver = new RegexNamespaceResolver(); final Collection validationResults = resolver.validate(validationContext); - Assert.assertEquals(1, validationResults.size()); + assertEquals(1, validationResults.size()); final ValidationResult validationResult = validationResults.iterator().next(); - Assert.assertEquals(propertyName, validationResult.getSubject()); + assertEquals(propertyName, validationResult.getSubject()); - try { - resolver.configure(context); - Assert.fail("Configure method should fail, too"); - } catch (IllegalArgumentException e) { - } + assertThrows(IllegalArgumentException.class, () -> resolver.configure(context)); } @Test @@ -103,11 +97,11 @@ public class TestRegexNamespaceResolver { final RegexNamespaceResolver resolver = new RegexNamespaceResolver(); final Collection validationResults = resolver.validate(validationContext); - Assert.assertEquals(0, validationResults.size()); + assertEquals(0, validationResults.size()); resolver.configure(context); - Assert.assertEquals("Namespace1", resolver.fromHostNames("host1.example.com")); + assertEquals("Namespace1", resolver.fromHostNames("host1.example.com")); } @Test @@ -120,14 +114,14 @@ public class TestRegexNamespaceResolver { final RegexNamespaceResolver resolver = new RegexNamespaceResolver(); final Collection validationResults = resolver.validate(validationContext); - Assert.assertEquals(0, validationResults.size()); + assertEquals(0, validationResults.size()); resolver.configure(context); - Assert.assertEquals("Namespace1", resolver.fromHostNames("host1.example.com")); - Assert.assertEquals("Namespace1", resolver.fromHostNames("192.168.1.10")); - Assert.assertEquals("Namespace1", resolver.fromHostNames("192.168.1.22")); - Assert.assertNull(resolver.fromHostNames("192.168.2.30")); + assertEquals("Namespace1", resolver.fromHostNames("host1.example.com")); + assertEquals("Namespace1", resolver.fromHostNames("192.168.1.10")); + assertEquals("Namespace1", resolver.fromHostNames("192.168.1.22")); + assertNull(resolver.fromHostNames("192.168.2.30")); } @Test @@ -145,17 +139,17 @@ public class TestRegexNamespaceResolver { final RegexNamespaceResolver resolver = new RegexNamespaceResolver(); final Collection validationResults = resolver.validate(validationContext); - Assert.assertEquals(0, validationResults.size()); + assertEquals(0, validationResults.size()); resolver.configure(context); - Assert.assertEquals(namespace1, resolver.fromHostNames("host1.c1.example.com")); - Assert.assertEquals(namespace1, resolver.fromHostNames("192.168.1.10")); - Assert.assertEquals(namespace1, resolver.fromHostNames("192.168.1.22")); - Assert.assertEquals(namespace2, resolver.fromHostNames("host2.c2.example.com")); - Assert.assertEquals(namespace2, resolver.fromHostNames("192.168.2.10")); - Assert.assertEquals(namespace2, resolver.fromHostNames("192.168.2.22")); - Assert.assertNull(resolver.fromHostNames("192.168.3.30")); + assertEquals(namespace1, resolver.fromHostNames("host1.c1.example.com")); + assertEquals(namespace1, resolver.fromHostNames("192.168.1.10")); + assertEquals(namespace1, resolver.fromHostNames("192.168.1.22")); + assertEquals(namespace2, resolver.fromHostNames("host2.c2.example.com")); + assertEquals(namespace2, resolver.fromHostNames("192.168.2.10")); + assertEquals(namespace2, resolver.fromHostNames("192.168.2.22")); + assertNull(resolver.fromHostNames("192.168.3.30")); } } diff --git a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestConvertAvroToJSON.java b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestConvertAvroToJSON.java index 4e302bdac1..57ba39d197 100644 --- a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestConvertAvroToJSON.java +++ b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestConvertAvroToJSON.java @@ -16,9 +16,6 @@ */ package org.apache.nifi.processors.avro; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; import org.apache.avro.Schema; import org.apache.avro.file.DataFileWriter; import org.apache.avro.generic.GenericData; @@ -30,7 +27,11 @@ import org.apache.avro.io.EncoderFactory; 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.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; public class TestConvertAvroToJSON { diff --git a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestExtractAvroMetadata.java b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestExtractAvroMetadata.java index b4a68e6fff..88b3027102 100644 --- a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestExtractAvroMetadata.java +++ b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestExtractAvroMetadata.java @@ -16,10 +16,6 @@ */ package org.apache.nifi.processors.avro; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; import org.apache.avro.Schema; import org.apache.avro.file.CodecFactory; import org.apache.avro.file.DataFileWriter; @@ -30,7 +26,12 @@ import org.apache.avro.io.DatumWriter; 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.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; public class TestExtractAvroMetadata { diff --git a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestSplitAvro.java b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestSplitAvro.java index a0d351edae..d7f9b90e4b 100644 --- a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestSplitAvro.java +++ b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestSplitAvro.java @@ -16,19 +16,6 @@ */ package org.apache.nifi.processors.avro; -import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_COUNT; -import static org.apache.nifi.flowfile.attributes.FragmentAttributes.FRAGMENT_ID; -import static org.junit.Assert.assertEquals; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.EOFException; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.stream.IntStream; import org.apache.avro.Schema; import org.apache.avro.file.DataFileStream; import org.apache.avro.file.DataFileWriter; @@ -43,9 +30,25 @@ 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.Assert; -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.ByteArrayOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.stream.IntStream; + +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; +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 TestSplitAvro { @@ -60,7 +63,7 @@ public class TestSplitAvro { private Schema schema; private ByteArrayOutputStream users; - @Before + @BeforeEach public void setup() throws IOException { this.users = new ByteArrayOutputStream(); this.schema = new Schema.Parser().parse(new File("src/test/resources/user.avsc")); @@ -185,9 +188,9 @@ public class TestSplitAvro { for (final MockFlowFile flowFile : flowFiles) { try (final ByteArrayInputStream in = new ByteArrayInputStream(flowFile.toByteArray()); final DataFileStream reader = new DataFileStream<>(in, new GenericDatumReader())) { - Assert.assertFalse(reader.getMetaKeys().contains(META_KEY1)); - Assert.assertFalse(reader.getMetaKeys().contains(META_KEY2)); - Assert.assertFalse(reader.getMetaKeys().contains(META_KEY3)); + assertFalse(reader.getMetaKeys().contains(META_KEY1)); + assertFalse(reader.getMetaKeys().contains(META_KEY2)); + assertFalse(reader.getMetaKeys().contains(META_KEY3)); } } } @@ -249,9 +252,9 @@ public class TestSplitAvro { checkBareRecordsSplitSize(flowFiles, 20, false); for (final MockFlowFile flowFile : flowFiles) { - Assert.assertFalse(flowFile.getAttributes().containsKey(META_KEY1)); - Assert.assertFalse(flowFile.getAttributes().containsKey(META_KEY2)); - Assert.assertFalse(flowFile.getAttributes().containsKey(META_KEY3)); + assertFalse(flowFile.getAttributes().containsKey(META_KEY1)); + assertFalse(flowFile.getAttributes().containsKey(META_KEY2)); + assertFalse(flowFile.getAttributes().containsKey(META_KEY3)); } } @@ -278,8 +281,8 @@ public class TestSplitAvro { GenericRecord record = reader.read(null, decoder); try { while (record != null) { - Assert.assertNotNull(record.get("name")); - Assert.assertNotNull(record.get("favorite_number")); + assertNotNull(record.get("name")); + assertNotNull(record.get("favorite_number")); count++; record = reader.read(record, decoder); } @@ -290,9 +293,9 @@ public class TestSplitAvro { } if (checkMetadata) { - Assert.assertTrue(flowFile.getAttributes().containsKey(META_KEY1)); - Assert.assertTrue(flowFile.getAttributes().containsKey(META_KEY2)); - Assert.assertTrue(flowFile.getAttributes().containsKey(META_KEY3)); + assertTrue(flowFile.getAttributes().containsKey(META_KEY1)); + assertTrue(flowFile.getAttributes().containsKey(META_KEY2)); + assertTrue(flowFile.getAttributes().containsKey(META_KEY3)); } } } @@ -306,8 +309,8 @@ public class TestSplitAvro { GenericRecord record = null; while (reader.hasNext()) { record = reader.next(record); - Assert.assertNotNull(record.get("name")); - Assert.assertNotNull(record.get("favorite_number")); + assertNotNull(record.get("name")); + assertNotNull(record.get("favorite_number")); count++; } assertEquals(expectedRecordsPerSplit, count); @@ -330,8 +333,8 @@ public class TestSplitAvro { GenericRecord record = null; while (reader.hasNext()) { record = reader.next(record); - Assert.assertNotNull(record.get("name")); - Assert.assertNotNull(record.get("favorite_number")); + assertNotNull(record.get("name")); + assertNotNull(record.get("favorite_number")); count++; } } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/TestAWSCredentials.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/TestAWSCredentials.java index 3a456e8786..c3e5ded59e 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/TestAWSCredentials.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/TestAWSCredentials.java @@ -16,17 +16,6 @@ */ package org.apache.nifi.processors.aws; -import java.util.Arrays; -import java.util.List; - -import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.processor.ProcessContext; -import org.apache.nifi.processor.ProcessSession; -import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; -import org.apache.nifi.reporting.InitializationException; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentialsProvider; @@ -35,12 +24,21 @@ import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.internal.StaticCredentialsProvider; import com.amazonaws.services.s3.AmazonS3Client; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; +import org.apache.nifi.reporting.InitializationException; +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.Before; -import org.junit.Test; +import java.util.Arrays; +import java.util.List; -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; /** @@ -55,7 +53,7 @@ public class TestAWSCredentials { private AWSCredentialsProvider awsCredentialsProvider = null; private ClientConfiguration clientConfiguration = null; - @Before + @BeforeEach public void setUp() { mockAwsProcessor = new AbstractAWSCredentialsProviderProcessor() { diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/ITPutCloudWatchMetric.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/ITPutCloudWatchMetric.java index 31fcb871b1..a0610e8ee5 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/ITPutCloudWatchMetric.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/ITPutCloudWatchMetric.java @@ -16,14 +16,14 @@ */ package org.apache.nifi.processors.aws.cloudwatch; -import java.io.IOException; - import org.apache.nifi.processors.aws.AbstractAWSCredentialsProviderProcessor; import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; import org.apache.nifi.processors.aws.sns.PutSNS; 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; /** * Provides integration level testing with actual AWS CloudWatch resources for {@link PutCloudWatchMetric} and requires additional configuration and resources to work. diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/MockPutCloudWatchMetric.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/MockPutCloudWatchMetric.java index 839c4d6bc6..2482922624 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/MockPutCloudWatchMetric.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/MockPutCloudWatchMetric.java @@ -16,13 +16,13 @@ */ package org.apache.nifi.processors.aws.cloudwatch; -import java.util.List; - import com.amazonaws.AmazonClientException; import com.amazonaws.services.cloudwatch.model.MetricDatum; import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest; import com.amazonaws.services.cloudwatch.model.PutMetricDataResult; +import java.util.List; + /** * Simple mock {@link PutCloudWatchMetric} processor for testing. diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/TestPutCloudWatchMetric.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/TestPutCloudWatchMetric.java index 28bb4e42a6..868b0d59da 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/TestPutCloudWatchMetric.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/cloudwatch/TestPutCloudWatchMetric.java @@ -16,20 +16,20 @@ */ package org.apache.nifi.processors.aws.cloudwatch; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - import com.amazonaws.services.cloudwatch.model.Dimension; import com.amazonaws.services.cloudwatch.model.InvalidParameterValueException; import com.amazonaws.services.cloudwatch.model.MetricDatum; -import org.junit.Test; -import org.junit.Assert; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Unit tests for {@link PutCloudWatchMetric}. @@ -52,11 +52,11 @@ public class TestPutCloudWatchMetric { runner.run(); runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1); - Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); - Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); + assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); + assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0); - Assert.assertEquals("TestMetric", datum.getMetricName()); - Assert.assertEquals(1d, datum.getValue(), 0.0001d); + assertEquals("TestMetric", datum.getMetricName()); + assertEquals(1d, datum.getValue(), 0.0001d); } @Test @@ -143,11 +143,11 @@ public class TestPutCloudWatchMetric { runner.run(); runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1); - Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); - Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); + assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); + assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0); - Assert.assertEquals("TestMetric", datum.getMetricName()); - Assert.assertEquals(1.23d, datum.getValue(), 0.0001d); + assertEquals("TestMetric", datum.getMetricName()); + assertEquals(1.23d, datum.getValue(), 0.0001d); } @Test @@ -172,14 +172,14 @@ public class TestPutCloudWatchMetric { runner.run(); runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1); - Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); - Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); + assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); + assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0); - Assert.assertEquals("TestMetric", datum.getMetricName()); - Assert.assertEquals(1.0d, datum.getStatisticValues().getMinimum(), 0.0001d); - Assert.assertEquals(2.0d, datum.getStatisticValues().getMaximum(), 0.0001d); - Assert.assertEquals(3.0d, datum.getStatisticValues().getSum(), 0.0001d); - Assert.assertEquals(2.0d, datum.getStatisticValues().getSampleCount(), 0.0001d); + assertEquals("TestMetric", datum.getMetricName()); + assertEquals(1.0d, datum.getStatisticValues().getMinimum(), 0.0001d); + assertEquals(2.0d, datum.getStatisticValues().getMaximum(), 0.0001d); + assertEquals(3.0d, datum.getStatisticValues().getSum(), 0.0001d); + assertEquals(2.0d, datum.getStatisticValues().getSampleCount(), 0.0001d); } @Test @@ -202,19 +202,19 @@ public class TestPutCloudWatchMetric { runner.run(); runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1); - Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); - Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); + assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); + assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace); MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0); - Assert.assertEquals("TestMetric", datum.getMetricName()); - Assert.assertEquals(1d, datum.getValue(), 0.0001d); + assertEquals("TestMetric", datum.getMetricName()); + assertEquals(1d, datum.getValue(), 0.0001d); List dimensions = datum.getDimensions(); Collections.sort(dimensions, (d1, d2) -> d1.getName().compareTo(d2.getName())); - Assert.assertEquals(2, dimensions.size()); - Assert.assertEquals("dim1", dimensions.get(0).getName()); - Assert.assertEquals("1", dimensions.get(0).getValue()); - Assert.assertEquals("dim2", dimensions.get(1).getName()); - Assert.assertEquals("val2", dimensions.get(1).getValue()); + assertEquals(2, dimensions.size()); + assertEquals("dim1", dimensions.get(0).getName()); + assertEquals("1", dimensions.get(0).getValue()); + assertEquals("dim2", dimensions.get(1).getName()); + assertEquals("val2", dimensions.get(1).getValue()); } @Test @@ -264,7 +264,7 @@ public class TestPutCloudWatchMetric { runner.enqueue(new byte[] {}, attributes); runner.run(); - Assert.assertEquals(0, mockPutCloudWatchMetric.putMetricDataCallCount); + assertEquals(0, mockPutCloudWatchMetric.putMetricDataCallCount); runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_FAILURE, 1); } @@ -283,7 +283,7 @@ public class TestPutCloudWatchMetric { runner.enqueue(new byte[] {}); runner.run(); - Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); + assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount); runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_FAILURE, 1); } @@ -304,7 +304,7 @@ public class TestPutCloudWatchMetric { runner.enqueue(new byte[] {}, attributes); runner.run(); - Assert.assertEquals(0, mockPutCloudWatchMetric.putMetricDataCallCount); + assertEquals(0, mockPutCloudWatchMetric.putMetricDataCallCount); runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_FAILURE, 1); } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/MockAWSProcessor.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/MockAWSProcessor.java index 81ccb92f43..700c99ad49 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/MockAWSProcessor.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/MockAWSProcessor.java @@ -16,33 +16,31 @@ */ package org.apache.nifi.processors.aws.credentials.provider.factory; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - - import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.services.s3.AmazonS3Client; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.ValidationContext; import org.apache.nifi.components.ValidationResult; import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processors.aws.AbstractAWSCredentialsProviderProcessor; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.USE_DEFAULT_CREDENTIALS; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_ARN; +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_EXTERNAL_ID; +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_NAME; +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_PROXY_HOST; +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_PROXY_PORT; +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_STS_ENDPOINT; +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.MAX_SESSION_TIME; import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.PROFILE_NAME; import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.USE_ANONYMOUS_CREDENTIALS; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_ARN; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_PROXY_PORT; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_PROXY_HOST; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_NAME; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.MAX_SESSION_TIME; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_EXTERNAL_ID; -import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.ASSUME_ROLE_STS_ENDPOINT; - -import com.amazonaws.auth.AWSCredentialsProvider; -import org.apache.nifi.processors.aws.AbstractAWSCredentialsProviderProcessor; +import static org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors.USE_DEFAULT_CREDENTIALS; /** diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/TestCredentialsProviderFactory.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/TestCredentialsProviderFactory.java index e44b14384b..479dc66f36 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/TestCredentialsProviderFactory.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/factory/TestCredentialsProviderFactory.java @@ -16,25 +16,24 @@ */ package org.apache.nifi.processors.aws.credentials.provider.factory; -import java.util.Map; - -import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.processors.aws.s3.FetchS3Object; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - -import com.amazonaws.auth.AnonymousAWSCredentials; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSCredentialsProvider; +import com.amazonaws.auth.AnonymousAWSCredentials; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; import com.amazonaws.auth.PropertiesFileCredentialsProvider; import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.internal.StaticCredentialsProvider; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.processors.aws.s3.FetchS3Object; +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 static org.junit.Assert.assertEquals; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Tests of the validation and credentials provider capabilities of CredentialsProviderFactory. @@ -49,9 +48,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", DefaultAWSCredentialsProviderChain.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(DefaultAWSCredentialsProviderChain.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -63,9 +62,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", DefaultAWSCredentialsProviderChain.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(DefaultAWSCredentialsProviderChain.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -87,9 +86,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", StaticCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(StaticCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -115,9 +114,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", PropertiesFileCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(PropertiesFileCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -131,9 +130,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", STSAssumeRoleSessionCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(STSAssumeRoleSessionCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -179,9 +178,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); + assertNotNull(credentialsProvider); final AWSCredentials creds = credentialsProvider.getCredentials(); - assertEquals("credentials should be equal", AnonymousAWSCredentials.class, creds.getClass()); + assertEquals(AnonymousAWSCredentials.class, creds.getClass(), "credentials should be equal"); } @Test @@ -202,9 +201,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", ProfileCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(ProfileCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -220,9 +219,9 @@ public class TestCredentialsProviderFactory { Map properties = runner.getProcessContext().getProperties(); final CredentialsProviderFactory factory = new CredentialsProviderFactory(); final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", STSAssumeRoleSessionCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(STSAssumeRoleSessionCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSCredentialsProviderControllerServiceTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSCredentialsProviderControllerServiceTest.java index c61240d41a..f2a3e3459b 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSCredentialsProviderControllerServiceTest.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSCredentialsProviderControllerServiceTest.java @@ -16,21 +16,20 @@ */ package org.apache.nifi.processors.aws.credentials.provider.service; -import static org.junit.Assert.assertEquals; - -import org.apache.nifi.processors.aws.AbstractAWSProcessor; -import org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors; -import org.apache.nifi.processors.aws.s3.FetchS3Object; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.Assert; -import org.junit.Test; - import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; import com.amazonaws.auth.PropertiesFileCredentialsProvider; import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; import com.amazonaws.internal.StaticCredentialsProvider; +import org.apache.nifi.processors.aws.AbstractAWSProcessor; +import org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors; +import org.apache.nifi.processors.aws.s3.FetchS3Object; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class AWSCredentialsProviderControllerServiceTest { @@ -45,11 +44,11 @@ public class AWSCredentialsProviderControllerServiceTest { runner.assertValid(serviceImpl); final AWSCredentialsProviderService service = (AWSCredentialsProviderService) runner.getProcessContext() .getControllerServiceLookup().getControllerService("awsCredentialsProvider"); - Assert.assertNotNull(service); + assertNotNull(service); final AWSCredentialsProvider credentialsProvider = service.getCredentialsProvider(); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", DefaultAWSCredentialsProviderChain.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(DefaultAWSCredentialsProviderChain.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -64,11 +63,11 @@ public class AWSCredentialsProviderControllerServiceTest { runner.assertValid(serviceImpl); final AWSCredentialsProviderService service = (AWSCredentialsProviderService) runner.getProcessContext() .getControllerServiceLookup().getControllerService("awsCredentialsProvider"); - Assert.assertNotNull(service); + assertNotNull(service); final AWSCredentialsProvider credentialsProvider = service.getCredentialsProvider(); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", StaticCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(StaticCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -85,11 +84,11 @@ public class AWSCredentialsProviderControllerServiceTest { runner.assertValid(serviceImpl); final AWSCredentialsProviderService service = (AWSCredentialsProviderService) runner.getProcessContext() .getControllerServiceLookup().getControllerService("awsCredentialsProvider"); - Assert.assertNotNull(service); + assertNotNull(service); final AWSCredentialsProvider credentialsProvider = service.getCredentialsProvider(); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", STSAssumeRoleSessionCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(STSAssumeRoleSessionCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -107,11 +106,11 @@ public class AWSCredentialsProviderControllerServiceTest { runner.assertValid(serviceImpl); final AWSCredentialsProviderService service = (AWSCredentialsProviderService) runner.getProcessContext() .getControllerServiceLookup().getControllerService("awsCredentialsProvider"); - Assert.assertNotNull(service); + assertNotNull(service); final AWSCredentialsProvider credentialsProvider = service.getCredentialsProvider(); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", STSAssumeRoleSessionCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(STSAssumeRoleSessionCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -208,11 +207,11 @@ public class AWSCredentialsProviderControllerServiceTest { runner.assertValid(serviceImpl); final AWSCredentialsProviderService service = (AWSCredentialsProviderService) runner.getProcessContext() .getControllerServiceLookup().getControllerService("awsCredentialsProvider"); - Assert.assertNotNull(service); + assertNotNull(service); final AWSCredentialsProvider credentialsProvider = service.getCredentialsProvider(); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", STSAssumeRoleSessionCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(STSAssumeRoleSessionCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -227,11 +226,11 @@ public class AWSCredentialsProviderControllerServiceTest { runner.assertValid(serviceImpl); final AWSCredentialsProviderService service = (AWSCredentialsProviderService) runner.getProcessContext() .getControllerServiceLookup().getControllerService("awsCredentialsProvider"); - Assert.assertNotNull(service); + assertNotNull(service); final AWSCredentialsProvider credentialsProvider = service.getCredentialsProvider(); - Assert.assertNotNull(credentialsProvider); - assertEquals("credentials provider should be equal", PropertiesFileCredentialsProvider.class, - credentialsProvider.getClass()); + assertNotNull(credentialsProvider); + assertEquals(PropertiesFileCredentialsProvider.class, + credentialsProvider.getClass(), "credentials provider should be equal"); } @Test @@ -316,9 +315,11 @@ public class AWSCredentialsProviderControllerServiceTest { final AWSCredentialsProviderService service = (AWSCredentialsProviderService) runner.getProcessContext() .getControllerServiceLookup().getControllerService("awsCredentialsProvider"); - assertEquals("Expression language should be supported for " + CredentialPropertyDescriptors.ACCESS_KEY.getName(), - "awsAccessKey", service.getCredentialsProvider().getCredentials().getAWSAccessKeyId()); - assertEquals("Expression language should be supported for " + CredentialPropertyDescriptors.SECRET_KEY.getName(), - "awsSecretKey", service.getCredentialsProvider().getCredentials().getAWSSecretKey()); + assertEquals( + "awsAccessKey", service.getCredentialsProvider().getCredentials().getAWSAccessKeyId(), + "Expression language should be supported for " + CredentialPropertyDescriptors.ACCESS_KEY.getName()); + assertEquals( + "awsSecretKey", service.getCredentialsProvider().getCredentials().getAWSSecretKey(), + "Expression language should be supported for " + CredentialPropertyDescriptors.SECRET_KEY.getName()); } } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSProcessorProxyTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSProcessorProxyTest.java index ccc95db956..c587e3d1ea 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSProcessorProxyTest.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/credentials/provider/service/AWSProcessorProxyTest.java @@ -20,22 +20,22 @@ import org.apache.nifi.processors.aws.AbstractAWSProcessor; import org.apache.nifi.processors.aws.s3.FetchS3Object; 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; public class AWSProcessorProxyTest { private TestRunner runner; - @Before + @BeforeEach public void testSetup() throws Throwable { runner = TestRunners.newTestRunner(FetchS3Object.class); runner.setProperty(FetchS3Object.BUCKET, "bucket"); runner.assertValid(); } - @After + @AfterEach public void testTearDown() throws Throwable { runner = null; } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java index ec2d897d65..874c9cd099 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/DeleteDynamoDBTest.java @@ -16,24 +16,6 @@ */ package org.apache.nifi.processors.aws.dynamodb; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.REGION; -import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.stringHashStringRangeTableName; - -import java.util.ArrayList; -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.Before; -import org.junit.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.Mockito; - import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; import com.amazonaws.regions.Regions; @@ -44,6 +26,23 @@ import com.amazonaws.services.dynamodbv2.model.AttributeValue; import com.amazonaws.services.dynamodbv2.model.BatchWriteItemResult; import com.amazonaws.services.dynamodbv2.model.DeleteRequest; import com.amazonaws.services.dynamodbv2.model.WriteRequest; +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 org.mockito.ArgumentMatchers; +import org.mockito.Mockito; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.REGION; +import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.stringHashStringRangeTableName; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class DeleteDynamoDBTest extends AbstractDynamoDBTest { @@ -51,7 +50,7 @@ public class DeleteDynamoDBTest extends AbstractDynamoDBTest { protected BatchWriteItemResult result = new BatchWriteItemResult(); BatchWriteItemOutcome outcome; - @Before + @BeforeEach public void setUp() { outcome = new BatchWriteItemOutcome(result); result.setUnprocessedItems(new HashMap>()); @@ -379,6 +378,5 @@ public class DeleteDynamoDBTest extends AbstractDynamoDBTest { for (MockFlowFile flowFile : flowFiles) { assertEquals("runtimeException", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE)); } - } } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java index c380248126..10e958f8cd 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/GetDynamoDBTest.java @@ -27,31 +27,33 @@ import com.amazonaws.services.dynamodbv2.model.AttributeValue; import com.amazonaws.services.dynamodbv2.model.BatchGetItemResult; import com.amazonaws.services.dynamodbv2.model.KeysAndAttributes; import org.apache.nifi.components.ConfigVerificationResult; -import org.apache.nifi.components.ConfigVerificationResult.Outcome; import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processor.VerifiableProcessor; import org.apache.nifi.processors.aws.AbstractAWSProcessor; 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.ArgumentMatchers; import org.mockito.Mockito; import java.io.IOException; import java.util.ArrayList; + import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.apache.nifi.components.ConfigVerificationResult.Outcome.FAILED; +import static org.apache.nifi.components.ConfigVerificationResult.Outcome.SUCCESSFUL; import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.REGION; import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.stringHashStringRangeTableName; -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.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 GetDynamoDBTest extends AbstractDynamoDBTest { protected GetDynamoDB getDynamoDB; @@ -59,7 +61,7 @@ public class GetDynamoDBTest extends AbstractDynamoDBTest { protected BatchGetItemResult result = new BatchGetItemResult(); private HashMap unprocessed; - @Before + @BeforeEach public void setUp() { outcome = new BatchGetItemOutcome(result); KeysAndAttributes kaa = new KeysAndAttributes(); @@ -78,12 +80,10 @@ public class GetDynamoDBTest extends AbstractDynamoDBTest { result.withResponses(responses); final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) { - @Override public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) { return outcome; } - }; getDynamoDB = mockDynamoDB(mockDynamoDB); @@ -545,16 +545,16 @@ public class GetDynamoDBTest extends AbstractDynamoDBTest { final List results = ((VerifiableProcessor) runner.getProcessor()) .verify(runner.getProcessContext(), runner.getLogger(), Collections.emptyMap()); assertEquals(3, results.size()); - assertEquals(Outcome.SUCCESSFUL, results.get(0).getOutcome()); - assertEquals(Outcome.SUCCESSFUL, results.get(1).getOutcome()); - assertEquals(Outcome.FAILED, results.get(2).getOutcome()); + assertEquals(SUCCESSFUL, results.get(0).getOutcome()); + assertEquals(SUCCESSFUL, results.get(1).getOutcome()); + assertEquals(FAILED, results.get(2).getOutcome()); } private void assertVerificationResults(final TestRunner runner, final int expectedTotalCount, final int expectedJsonDocumentCount) { final List results = ((VerifiableProcessor) runner.getProcessor()) .verify(runner.getProcessContext(), runner.getLogger(), Collections.emptyMap()); assertEquals(3, results.size()); - results.forEach(result -> assertEquals(Outcome.SUCCESSFUL, result.getOutcome())); + results.forEach(result -> assertEquals(SUCCESSFUL, result.getOutcome())); assertTrue(results.get(2).getExplanation().contains("retrieved " + expectedTotalCount + " items")); assertTrue(results.get(2).getExplanation().contains(expectedJsonDocumentCount + " JSON")); } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITAbstractDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITAbstractDynamoDBTest.java index 238e2e7343..4f835d04f1 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITAbstractDynamoDBTest.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITAbstractDynamoDBTest.java @@ -16,15 +16,6 @@ */ package org.apache.nifi.processors.aws.dynamodb; -import static org.junit.Assert.assertNotNull; - -import java.io.FileInputStream; -import java.util.ArrayList; - -import org.apache.nifi.flowfile.FlowFile; -import org.junit.AfterClass; -import org.junit.BeforeClass; - import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.regions.Region; import com.amazonaws.regions.Regions; @@ -37,6 +28,14 @@ import com.amazonaws.services.dynamodbv2.model.DeleteTableResult; import com.amazonaws.services.dynamodbv2.model.KeySchemaElement; import com.amazonaws.services.dynamodbv2.model.KeyType; import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; +import org.apache.nifi.flowfile.FlowFile; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; + +import java.io.FileInputStream; +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ITAbstractDynamoDBTest { @@ -48,7 +47,7 @@ public class ITAbstractDynamoDBTest { protected static String numberHashOnlyTableName = "NumberHashOnlyTable"; protected final static String REGION = "us-west-2"; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { FileInputStream fis = new FileInputStream(CREDENTIALS_FILE); final PropertiesCredentials credentials = new PropertiesCredentials(fis); @@ -128,7 +127,7 @@ public class ITAbstractDynamoDBTest { assertNotNull(flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_RETRYABLE)); } - @AfterClass + @AfterAll public static void afterClass() { DeleteTableResult result = amazonDynamoDBClient.deleteTable(stringHashStringRangeTableName); result = amazonDynamoDBClient.deleteTable(numberHashNumberRangeTableName); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITPutGetDeleteGetDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITPutGetDeleteGetDynamoDBTest.java deleted file mode 100644 index e98fc553eb..0000000000 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ITPutGetDeleteGetDynamoDBTest.java +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.aws.dynamodb; - -import static org.junit.Assert.assertEquals; - -import static org.junit.Assert.assertTrue; - -import java.util.Collections; -import java.util.List; - -import org.apache.nifi.components.ConfigVerificationResult; -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; - -@Ignore -public class ITPutGetDeleteGetDynamoDBTest extends ITAbstractDynamoDBTest { - - - @Test - public void testStringHashStringRangePutGetDeleteGetSuccess() { - final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class); - - putRunner.setProperty(AbstractWriteDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.REGION, REGION); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.TABLE, stringHashStringRangeTableName); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_NAME, "hashS"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_NAME, "rangeS"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE, "h1"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE, "r1"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document"); - String document = "{\"name\":\"john\"}"; - putRunner.enqueue(document.getBytes()); - - putRunner.run(1); - - putRunner.assertAllFlowFilesTransferred(AbstractWriteDynamoDBProcessor.REL_SUCCESS, 1); - - List flowFiles = putRunner.getFlowFilesForRelationship(AbstractWriteDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunner.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS"); - getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS"); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1"); - getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1"); - getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunner.enqueue(new byte[] {}); - - getRunner.run(1); - - getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1); - - flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals(document, new String(flowFile.toByteArray())); - } - - final GetDynamoDB getDynamoDB = (GetDynamoDB) getRunner.getProcessor(); - final List results = getDynamoDB.verify(getRunner.getProcessContext(), getRunner.getLogger(), Collections.emptyMap()); - assertEquals(2, results.size()); - assertEquals("Successfully retrieved 1 items, including 1 JSON documents, from DynamoDB", results.get(1).getExplanation()); - - final TestRunner deleteRunner = TestRunners.newTestRunner(DeleteDynamoDB.class); - - deleteRunner.setProperty(DeleteDynamoDB.CREDENTIALS_FILE, CREDENTIALS_FILE); - deleteRunner.setProperty(DeleteDynamoDB.REGION, REGION); - deleteRunner.setProperty(DeleteDynamoDB.TABLE, stringHashStringRangeTableName); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_NAME, "hashS"); - deleteRunner.setProperty(DeleteDynamoDB.RANGE_KEY_NAME, "rangeS"); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_VALUE, "h1"); - deleteRunner.setProperty(DeleteDynamoDB.RANGE_KEY_VALUE, "r1"); - deleteRunner.enqueue(new byte[] {}); - - deleteRunner.run(1); - - deleteRunner.assertAllFlowFilesTransferred(DeleteDynamoDB.REL_SUCCESS, 1); - - flowFiles = deleteRunner.getFlowFilesForRelationship(DeleteDynamoDB.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals("", new String(flowFile.toByteArray())); - } - - // Final check after delete - final TestRunner getRunnerAfterDelete = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunnerAfterDelete.enqueue(new byte[] {}); - - getRunnerAfterDelete.run(1); - getRunnerAfterDelete.assertAllFlowFilesTransferred(GetDynamoDB.REL_NOT_FOUND, 1); - - flowFiles = getRunnerAfterDelete.getFlowFilesForRelationship(GetDynamoDB.REL_NOT_FOUND); - for (MockFlowFile flowFile : flowFiles) { - String error = flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND); - assertTrue(error.startsWith(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND_MESSAGE)); - } - - } - - @Test - public void testStringHashStringRangePutDeleteWithHashOnlyFailure() { - final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class); - - putRunner.setProperty(AbstractWriteDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.REGION, REGION); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.TABLE, stringHashStringRangeTableName); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_NAME, "hashS"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_NAME, "rangeS"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE, "h1"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE, "r1"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document"); - String document = "{\"name\":\"john\"}"; - putRunner.enqueue(document.getBytes()); - - putRunner.run(1); - - putRunner.assertAllFlowFilesTransferred(AbstractWriteDynamoDBProcessor.REL_SUCCESS, 1); - - List flowFiles = putRunner.getFlowFilesForRelationship(AbstractWriteDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunner.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS"); - getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS"); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1"); - getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1"); - getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunner.enqueue(new byte[] {}); - - getRunner.run(1); - - getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1); - - flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner deleteRunner = TestRunners.newTestRunner(DeleteDynamoDB.class); - - deleteRunner.setProperty(DeleteDynamoDB.CREDENTIALS_FILE, CREDENTIALS_FILE); - deleteRunner.setProperty(DeleteDynamoDB.REGION, REGION); - deleteRunner.setProperty(DeleteDynamoDB.TABLE, stringHashStringRangeTableName); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_NAME, "hashS"); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_VALUE, "h1"); - deleteRunner.enqueue(new byte[] {}); - - deleteRunner.run(1); - - deleteRunner.assertAllFlowFilesTransferred(DeleteDynamoDB.REL_FAILURE, 1); - - flowFiles = deleteRunner.getFlowFilesForRelationship(DeleteDynamoDB.REL_FAILURE); - for (MockFlowFile flowFile : flowFiles) { - validateServiceExceptionAttribute(flowFile); - assertEquals("", new String(flowFile.toByteArray())); - } - - } - - @Test - public void testStringHashStringRangePutGetWithHashOnlyKeyFailure() { - final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class); - - putRunner.setProperty(AbstractWriteDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.REGION, REGION); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.TABLE, stringHashStringRangeTableName); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_NAME, "hashS"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_NAME, "rangeS"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE, "h1"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE, "r1"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document"); - String document = "{\"name\":\"john\"}"; - putRunner.enqueue(document.getBytes()); - - putRunner.run(1); - - putRunner.assertAllFlowFilesTransferred(AbstractWriteDynamoDBProcessor.REL_SUCCESS, 1); - - List flowFiles = putRunner.getFlowFilesForRelationship(AbstractWriteDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunner.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS"); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1"); - getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunner.enqueue(new byte[] {}); - - getRunner.run(1); - - getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_FAILURE, 1); - - flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE); - for (MockFlowFile flowFile : flowFiles) { - validateServiceExceptionAttribute(flowFile); - assertEquals("", new String(flowFile.toByteArray())); - } - - - } - - @Test - public void testNumberHashOnlyPutGetDeleteGetSuccess() { - final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class); - - putRunner.setProperty(AbstractWriteDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.REGION, REGION); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.TABLE, numberHashOnlyTableName); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_NAME, "hashN"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE, "40"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document"); - String document = "{\"age\":40}"; - putRunner.enqueue(document.getBytes()); - - putRunner.run(1); - - putRunner.assertAllFlowFilesTransferred(AbstractWriteDynamoDBProcessor.REL_SUCCESS, 1); - - List flowFiles = putRunner.getFlowFilesForRelationship(AbstractWriteDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunner.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, numberHashOnlyTableName); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashN"); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "40"); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunner.enqueue(new byte[] {}); - - getRunner.run(1); - - getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1); - - flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner deleteRunner = TestRunners.newTestRunner(DeleteDynamoDB.class); - - deleteRunner.setProperty(DeleteDynamoDB.CREDENTIALS_FILE, CREDENTIALS_FILE); - deleteRunner.setProperty(DeleteDynamoDB.REGION, REGION); - deleteRunner.setProperty(DeleteDynamoDB.TABLE, numberHashOnlyTableName); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_NAME, "hashN"); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_VALUE, "40"); - deleteRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - deleteRunner.enqueue(new byte[] {}); - - deleteRunner.run(1); - - deleteRunner.assertAllFlowFilesTransferred(DeleteDynamoDB.REL_SUCCESS, 1); - - flowFiles = deleteRunner.getFlowFilesForRelationship(DeleteDynamoDB.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals("", new String(flowFile.toByteArray())); - } - - // Final check after delete - final TestRunner getRunnerAfterDelete = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.TABLE, numberHashOnlyTableName); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashN"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "40"); - getRunnerAfterDelete.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunnerAfterDelete.enqueue(new byte[] {}); - - getRunnerAfterDelete.run(1); - getRunnerAfterDelete.assertAllFlowFilesTransferred(GetDynamoDB.REL_NOT_FOUND, 1); - - flowFiles = getRunnerAfterDelete.getFlowFilesForRelationship(GetDynamoDB.REL_NOT_FOUND); - for (MockFlowFile flowFile : flowFiles) { - String error = flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND); - assertTrue(error.startsWith(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND_MESSAGE)); - } - - } - - @Test - public void testNumberHashNumberRangePutGetDeleteGetSuccess() { - final TestRunner putRunner = TestRunners.newTestRunner(PutDynamoDB.class); - - putRunner.setProperty(AbstractWriteDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.REGION, REGION); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.TABLE, numberHashNumberRangeTableName); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_NAME, "hashN"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_NAME, "rangeN"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE, "40"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE, "50"); - putRunner.setProperty(AbstractWriteDynamoDBProcessor.JSON_DOCUMENT, "document"); - String document = "{\"40\":\"50\"}"; - putRunner.enqueue(document.getBytes()); - - putRunner.run(1); - - putRunner.assertAllFlowFilesTransferred(AbstractWriteDynamoDBProcessor.REL_SUCCESS, 1); - - List flowFiles = putRunner.getFlowFilesForRelationship(AbstractWriteDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner getRunner = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunner.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, numberHashNumberRangeTableName); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashN"); - getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeN"); - getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "40"); - getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "50"); - getRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - getRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunner.enqueue(new byte[] {}); - - getRunner.run(1); - - getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1); - - flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - assertEquals(document, new String(flowFile.toByteArray())); - } - - final TestRunner deleteRunner = TestRunners.newTestRunner(DeleteDynamoDB.class); - - deleteRunner.setProperty(DeleteDynamoDB.CREDENTIALS_FILE, CREDENTIALS_FILE); - deleteRunner.setProperty(DeleteDynamoDB.REGION, REGION); - deleteRunner.setProperty(DeleteDynamoDB.TABLE, numberHashNumberRangeTableName); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_NAME, "hashN"); - deleteRunner.setProperty(DeleteDynamoDB.RANGE_KEY_NAME, "rangeN"); - deleteRunner.setProperty(DeleteDynamoDB.HASH_KEY_VALUE, "40"); - deleteRunner.setProperty(DeleteDynamoDB.RANGE_KEY_VALUE, "50"); - deleteRunner.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - deleteRunner.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - deleteRunner.enqueue(new byte[] {}); - - deleteRunner.run(1); - - deleteRunner.assertAllFlowFilesTransferred(DeleteDynamoDB.REL_SUCCESS, 1); - - flowFiles = deleteRunner.getFlowFilesForRelationship(DeleteDynamoDB.REL_SUCCESS); - for (MockFlowFile flowFile : flowFiles) { - System.out.println(flowFile.getAttributes()); - assertEquals("", new String(flowFile.toByteArray())); - } - - // Final check after delete - final TestRunner getRunnerAfterDelete = TestRunners.newTestRunner(GetDynamoDB.class); - - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.CREDENTIALS_FILE, CREDENTIALS_FILE); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.REGION, REGION); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.TABLE, numberHashNumberRangeTableName); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashN"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeN"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "40"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "50"); - getRunnerAfterDelete.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "document"); - getRunnerAfterDelete.setProperty(AbstractWriteDynamoDBProcessor.HASH_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - getRunnerAfterDelete.setProperty(AbstractWriteDynamoDBProcessor.RANGE_KEY_VALUE_TYPE, AbstractWriteDynamoDBProcessor.ALLOWABLE_VALUE_NUMBER); - getRunnerAfterDelete.enqueue(new byte[] {}); - - getRunnerAfterDelete.run(1); - getRunnerAfterDelete.assertAllFlowFilesTransferred(GetDynamoDB.REL_NOT_FOUND, 1); - - flowFiles = getRunnerAfterDelete.getFlowFilesForRelationship(GetDynamoDB.REL_NOT_FOUND); - for (MockFlowFile flowFile : flowFiles) { - String error = flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND); - assertTrue(error.startsWith(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_NOT_FOUND_MESSAGE)); - } - - } -} diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java index 62b970b7b0..1b5ce86ac0 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/ItemKeysTest.java @@ -16,10 +16,10 @@ */ package org.apache.nifi.processors.aws.dynamodb; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; public class ItemKeysTest { diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java index cce9f28686..c71858d3e0 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/dynamodb/PutDynamoDBTest.java @@ -16,24 +16,6 @@ */ package org.apache.nifi.processors.aws.dynamodb; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.REGION; -import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.stringHashStringRangeTableName; - -import java.util.ArrayList; -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.Before; -import org.junit.Test; -import org.mockito.ArgumentMatchers; -import org.mockito.Mockito; - import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; import com.amazonaws.regions.Regions; @@ -44,6 +26,23 @@ import com.amazonaws.services.dynamodbv2.model.AttributeValue; import com.amazonaws.services.dynamodbv2.model.BatchWriteItemResult; import com.amazonaws.services.dynamodbv2.model.PutRequest; import com.amazonaws.services.dynamodbv2.model.WriteRequest; +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 org.mockito.ArgumentMatchers; +import org.mockito.Mockito; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.REGION; +import static org.apache.nifi.processors.aws.dynamodb.ITAbstractDynamoDBTest.stringHashStringRangeTableName; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class PutDynamoDBTest extends AbstractDynamoDBTest { @@ -51,7 +50,7 @@ public class PutDynamoDBTest extends AbstractDynamoDBTest { protected BatchWriteItemResult result = new BatchWriteItemResult(); BatchWriteItemOutcome outcome; - @Before + @BeforeEach public void setUp() { outcome = new BatchWriteItemOutcome(result); result.setUnprocessedItems(new HashMap>()); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehose.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehose.java index 32e42b1ebf..eb3e317520 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehose.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehose.java @@ -16,18 +16,18 @@ */ package org.apache.nifi.processors.aws.kinesis.firehose; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.List; - import org.apache.nifi.processors.aws.s3.FetchS3Object; 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.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * This test contains both unit and integration test (integration tests are ignored by default) @@ -37,7 +37,7 @@ public class ITPutKinesisFirehose { private TestRunner runner; protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - @Before + @BeforeEach public void setUp() throws Exception { runner = TestRunners.newTestRunner(PutKinesisFirehose.class); runner.setProperty(PutKinesisFirehose.ACCESS_KEY, "abcd"); @@ -46,7 +46,7 @@ public class ITPutKinesisFirehose { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehoseWithEndpointOverride.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehoseWithEndpointOverride.java index f12b44ea42..839d439a8c 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehoseWithEndpointOverride.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/ITPutKinesisFirehoseWithEndpointOverride.java @@ -16,17 +16,17 @@ */ package org.apache.nifi.processors.aws.kinesis.firehose; -import static com.amazonaws.SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY; - -import java.util.List; - import org.apache.nifi.processors.aws.s3.FetchS3Object; 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.util.List; + +import static com.amazonaws.SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY; // This integration test can be run against a mock Kenesis Firehose such as // https://github.com/localstack/localstack @@ -34,7 +34,7 @@ public class ITPutKinesisFirehoseWithEndpointOverride { private TestRunner runner; - @Before + @BeforeEach public void setUp() throws Exception { runner = TestRunners.newTestRunner(PutKinesisFirehose.class); runner.setProperty(PutKinesisFirehose.ACCESS_KEY, "access key"); @@ -44,7 +44,7 @@ public class ITPutKinesisFirehoseWithEndpointOverride { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/TestPutKinesisFirehose.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/TestPutKinesisFirehose.java index cb3f3e8228..fb2ed5178e 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/TestPutKinesisFirehose.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/firehose/TestPutKinesisFirehose.java @@ -16,22 +16,22 @@ */ package org.apache.nifi.processors.aws.kinesis.firehose; -import static org.junit.Assert.assertNotNull; - -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.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TestPutKinesisFirehose { private TestRunner runner; protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - @Before + @BeforeEach public void setUp() throws Exception { runner = TestRunners.newTestRunner(PutKinesisFirehose.class); runner.setProperty(PutKinesisFirehose.ACCESS_KEY, "abcd"); @@ -40,7 +40,7 @@ public class TestPutKinesisFirehose { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStream.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStream.java index 2fcdda702d..814efc1968 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStream.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStream.java @@ -26,8 +26,8 @@ import com.amazonaws.services.kinesis.model.ListStreamsResult; import org.apache.nifi.processors.aws.kinesis.stream.record.AbstractKinesisRecordProcessor; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.ByteBuffer; @@ -101,7 +101,7 @@ public abstract class ITConsumeKinesisStream { Thread.sleep(30_000); } - @After + @AfterEach public void tearDown() throws InterruptedException { cleanupKinesis(); cleanupDynamoDB(); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamConnectAWS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamConnectAWS.java index fcdb725983..90e52242bf 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamConnectAWS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamConnectAWS.java @@ -20,7 +20,7 @@ import com.amazonaws.auth.PropertiesFileCredentialsProvider; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.kinesis.AmazonKinesisClient; import org.apache.nifi.util.TestRunners; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import static com.amazonaws.SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY; @@ -29,7 +29,7 @@ public class ITConsumeKinesisStreamConnectAWS extends ITConsumeKinesisStream { private final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - @Before + @BeforeEach public void setUp() throws InterruptedException { System.setProperty(AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true"); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamEndpointOverride.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamEndpointOverride.java index fdad9f9de7..7d5a907029 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamEndpointOverride.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITConsumeKinesisStreamEndpointOverride.java @@ -23,7 +23,7 @@ import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.kinesis.AmazonKinesisClient; import org.apache.nifi.util.TestRunners; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import static com.amazonaws.SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY; @@ -45,7 +45,7 @@ public class ITConsumeKinesisStreamEndpointOverride extends ITConsumeKinesisStre private final AwsClientBuilder.EndpointConfiguration dynamoDBEndpointConfig = new AwsClientBuilder.EndpointConfiguration(LOCAL_STACK_DYNAMODB_ENDPOINT_OVERRIDE, REGION); - @Before + @BeforeEach public void setUp() throws InterruptedException { System.setProperty(AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true"); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStream.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStream.java index d3aeb0759f..eaa2c2428c 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStream.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStream.java @@ -19,16 +19,16 @@ package org.apache.nifi.processors.aws.kinesis.stream; 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.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * This test contains both unit and integration test (integration tests are ignored by default). @@ -41,7 +41,7 @@ public class ITPutKinesisStream { private TestRunner runner; protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - @Before + @BeforeEach public void setUp() throws Exception { runner = TestRunners.newTestRunner(PutKinesisStream.class); runner.setProperty(PutKinesisStream.KINESIS_STREAM_NAME, "kstream"); @@ -49,7 +49,7 @@ public class ITPutKinesisStream { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStreamWithEndpointOverride.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStreamWithEndpointOverride.java index d66cd3b640..3290b13276 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStreamWithEndpointOverride.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/ITPutKinesisStreamWithEndpointOverride.java @@ -19,9 +19,9 @@ package org.apache.nifi.processors.aws.kinesis.stream; 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.util.List; @@ -33,7 +33,7 @@ public class ITPutKinesisStreamWithEndpointOverride { private TestRunner runner; - @Before + @BeforeEach public void setUp() throws Exception { System.setProperty(AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true"); @@ -45,7 +45,7 @@ public class ITPutKinesisStreamWithEndpointOverride { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestConsumeKinesisStream.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestConsumeKinesisStream.java index 1088580e44..82317a8b66 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestConsumeKinesisStream.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestConsumeKinesisStream.java @@ -36,8 +36,8 @@ import org.apache.nifi.serialization.record.RecordFieldType; 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 java.net.InetAddress; import java.net.UnknownHostException; @@ -49,13 +49,13 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestConsumeKinesisStream { private final TestRunner runner = TestRunners.newTestRunner(ConsumeKinesisStream.class); - @Before + @BeforeEach public void setUp() throws InitializationException { runner.setProperty(ConsumeKinesisStream.KINESIS_STREAM_NAME, "test-stream"); runner.setProperty(ConsumeKinesisStream.APPLICATION_NAME, "test-application"); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestPutKinesisStream.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestPutKinesisStream.java index c2f9bd1016..2f94266b58 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestPutKinesisStream.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/TestPutKinesisStream.java @@ -19,19 +19,19 @@ package org.apache.nifi.processors.aws.kinesis.stream; 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.util.List; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class TestPutKinesisStream { private TestRunner runner; protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - @Before + @BeforeEach public void setUp() throws Exception { runner = TestRunners.newTestRunner(PutKinesisStream.class); runner.setProperty(PutKinesisStream.ACCESS_KEY, "abcd"); @@ -40,7 +40,7 @@ public class TestPutKinesisStream { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestAbstractKinesisRecordProcessor.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestAbstractKinesisRecordProcessor.java index 91e2b54bed..26facdd914 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestAbstractKinesisRecordProcessor.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestAbstractKinesisRecordProcessor.java @@ -35,9 +35,9 @@ import org.apache.nifi.util.SharedSessionState; import org.apache.nifi.util.StopWatch; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -75,7 +75,7 @@ public class TestAbstractKinesisRecordProcessor { @Mock private Record kinesisRecord; - @Before + @BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); @@ -91,7 +91,7 @@ public class TestAbstractKinesisRecordProcessor { }; } - @After + @AfterEach public void tearDown() { verifyNoMoreInteractions(checkpointer, kinesisRecord, processSessionFactory); reset(checkpointer, kinesisRecord, processSessionFactory); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRaw.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRaw.java index 4cdddc0026..a1e86d0c5e 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRaw.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRaw.java @@ -28,9 +28,9 @@ import org.apache.nifi.util.MockProcessSession; import org.apache.nifi.util.SharedSessionState; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -49,8 +49,8 @@ import java.util.concurrent.atomic.AtomicLong; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -76,7 +76,7 @@ public class TestKinesisRecordProcessorRaw { @Mock private Record kinesisRecord; - @Before + @BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); @@ -85,7 +85,7 @@ public class TestKinesisRecordProcessorRaw { "endpoint-prefix", null, 10_000L, 1L, 2, DATE_TIME_FORMATTER); } - @After + @AfterEach public void tearDown() { verifyNoMoreInteractions(checkpointer, kinesisRecord, processSessionFactory); reset(checkpointer, kinesisRecord, processSessionFactory); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRecord.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRecord.java index 4d5215f17a..974dfc1cbb 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRecord.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/kinesis/stream/record/TestKinesisRecordProcessorRecord.java @@ -36,9 +36,9 @@ import org.apache.nifi.util.MockProcessSession; import org.apache.nifi.util.SharedSessionState; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -57,9 +57,9 @@ import java.util.concurrent.atomic.AtomicLong; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +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.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -87,7 +87,7 @@ public class TestKinesisRecordProcessorRecord { @Mock private Record kinesisRecord; - @Before + @BeforeEach public void setUp() throws InitializationException { MockitoAnnotations.initMocks(this); @@ -108,7 +108,7 @@ public class TestKinesisRecordProcessorRecord { reader, writer); } - @After + @AfterEach public void tearDown() { verifyNoMoreInteractions(checkpointer, kinesisRecord, processSessionFactory); reset(checkpointer, kinesisRecord, processSessionFactory); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java index 841c15700a..59b1d64aa9 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/ITPutLambda.java @@ -15,20 +15,20 @@ * limitations under the License. */ package org.apache.nifi.processors.aws.lambda; -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 java.util.List; 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.Ignore; -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.List; + +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; /** * This test contains both unit and integration test (integration tests are ignored by default) @@ -38,7 +38,7 @@ public class ITPutLambda { private TestRunner runner; protected final static String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; - @Before + @BeforeEach public void setUp() throws Exception { runner = TestRunners.newTestRunner(PutLambda.class); runner.setProperty(PutLambda.ACCESS_KEY, "abcd"); @@ -47,13 +47,13 @@ public class ITPutLambda { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } @Test - public void testSizeGreaterThan6MB() throws Exception { + public void testSizeGreaterThan6MB() { runner = TestRunners.newTestRunner(PutLambda.class); runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); @@ -72,8 +72,7 @@ public class ITPutLambda { * Comment out ignore for integration tests (requires creds files) */ @Test - @Ignore - public void testIntegrationSuccess() throws Exception { + public void testIntegrationSuccess() { runner = TestRunners.newTestRunner(PutLambda.class); runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); @@ -86,17 +85,16 @@ public class ITPutLambda { final List ffs = runner.getFlowFilesForRelationship(PutLambda.REL_SUCCESS); final MockFlowFile out = ffs.iterator().next(); - assertNull("Function error should be null " + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); - assertNotNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); - assertEquals("Status should be equal", "200",out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); + assertNull(out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), "Function error should be null " + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); + assertNotNull(out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG), "log should not be null"); + assertEquals("200",out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE), "Status should be equal"); } /** * Comment out ignore for integration tests (requires creds files) */ @Test - @Ignore - public void testIntegrationClientErrorBadMessageBody() throws Exception { + public void testIntegrationClientErrorBadMessageBody() { runner = TestRunners.newTestRunner(PutLambda.class); runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "hello"); @@ -108,23 +106,22 @@ public class ITPutLambda { runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); final List ffs = runner.getFlowFilesForRelationship(PutLambda.REL_FAILURE); final MockFlowFile out = ffs.iterator().next(); - assertNull("Function error should be null since there is exception" - + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); - assertNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); - assertEquals("Status should be equal", null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); - assertEquals("exception error code should be equal", "InvalidRequestContentException",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_CODE)); - assertEquals("exception exception error type should be equal", "Client",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_TYPE)); - assertEquals("exception exception error code should be equal", "400",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_STATUS_CODE)); - assertTrue("exception exception error message should be start with",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_MESSAGE) - .startsWith("Could not parse request body into json: Unrecognized token 'badbod': was expecting ('true', 'false' or 'null')")); + assertNull(out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), "Function error should be null since there is exception" + + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); + assertNull(out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG), "log should not be null"); + assertEquals(null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE), "Status should be equal"); + assertEquals("InvalidRequestContentException",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_CODE), "exception error code should be equal"); + assertEquals("Client",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_ERROR_TYPE), "exception exception error type should be equal"); + assertEquals("400",out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_STATUS_CODE), "exception exception error code should be equal"); + assertTrue(out.getAttribute(PutLambda.AWS_LAMBDA_EXCEPTION_MESSAGE) + .startsWith("Could not parse request body into json: Unrecognized token 'badbod': was expecting ('true', 'false' or 'null')"), "exception exception error message should be start with"); } /** * Comment out ignore for integration tests (requires creds files) */ @Test - @Ignore - public void testIntegrationFailedBadStreamName() throws Exception { + public void testIntegrationFailedBadStreamName() { runner = TestRunners.newTestRunner(PutLambda.class); runner.setProperty(PutLambda.CREDENTIALS_FILE, CREDENTIALS_FILE); runner.setProperty(PutLambda.AWS_LAMBDA_FUNCTION_NAME, "bad-function-name"); @@ -136,10 +133,10 @@ public class ITPutLambda { runner.assertAllFlowFilesTransferred(PutLambda.REL_FAILURE, 1); final List ffs = runner.getFlowFilesForRelationship(PutLambda.REL_FAILURE); final MockFlowFile out = ffs.iterator().next(); - assertNull("Function error should be null since there is exception" - + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); - assertNull("log should not be null", out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG)); - assertEquals("Status should be equal", null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE)); + assertNull(out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR), "Function error should be null since there is exception" + + out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_FUNCTION_ERROR)); + assertNull(out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_LOG), "log should not be null"); + assertEquals(null,out.getAttribute(PutLambda.AWS_LAMBDA_RESULT_STATUS_CODE), "Status should be equal"); } } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/TestPutLambda.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/TestPutLambda.java index a8a3a9b414..e301397775 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/TestPutLambda.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/lambda/TestPutLambda.java @@ -16,13 +16,6 @@ */ package org.apache.nifi.processors.aws.lambda; -import java.nio.ByteBuffer; -import java.util.List; - -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - import com.amazonaws.AmazonServiceException; import com.amazonaws.services.lambda.AWSLambdaClient; import com.amazonaws.services.lambda.model.InvalidParameterValueException; @@ -30,14 +23,19 @@ import com.amazonaws.services.lambda.model.InvokeRequest; import com.amazonaws.services.lambda.model.InvokeResult; import com.amazonaws.services.lambda.model.TooManyRequestsException; import com.amazonaws.util.Base64; - -import org.junit.Before; -import org.junit.Test; +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 org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import java.nio.ByteBuffer; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestPutLambda { @@ -47,7 +45,7 @@ public class TestPutLambda { private AWSLambdaClient actualLambdaClient = null; private AWSLambdaClient mockLambdaClient = null; - @Before + @BeforeEach public void setUp() { mockLambdaClient = Mockito.mock(AWSLambdaClient.class); mockPutLambda = new PutLambda() { diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java index 83ebb454a5..bd4cf836b4 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/AbstractS3IT.java @@ -38,9 +38,8 @@ import com.amazonaws.services.s3.model.PutObjectResult; import com.amazonaws.services.s3.model.S3ObjectSummary; import com.amazonaws.services.s3.model.Tag; import org.apache.nifi.util.file.FileUtils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; import java.io.File; import java.io.FileInputStream; @@ -78,7 +77,7 @@ public abstract class AbstractS3IT { protected static AmazonS3Client client; protected static AWSKMS kmsClient; - @BeforeClass + @BeforeAll public static void oneTimeSetup() { // Creates a client and bucket for this test @@ -117,7 +116,7 @@ public abstract class AbstractS3IT { } } - @AfterClass + @AfterAll public static void oneTimeTearDown() { // Empty the bucket before deleting it. try { @@ -146,9 +145,8 @@ public abstract class AbstractS3IT { } if (client.doesBucketExist(BUCKET_NAME)) { - Assert.fail("Incomplete teardown, subsequent tests might fail"); + fail("Incomplete teardown, subsequent tests might fail"); } - } protected void putTestFile(String key, File file) throws AmazonS3Exception { @@ -185,7 +183,7 @@ public abstract class AbstractS3IT { try { path = Paths.get(getClass().getResource(resourceName).toURI()); } catch (URISyntaxException e) { - Assert.fail("Resource: " + resourceName + " does not exist" + e.getLocalizedMessage()); + fail("Resource: " + resourceName + " does not exist" + e.getLocalizedMessage()); } return path; @@ -196,7 +194,7 @@ public abstract class AbstractS3IT { try { uri = this.getClass().getResource(resourceName).toURI(); } catch (URISyntaxException e) { - Assert.fail("Cannot proceed without File : " + resourceName); + fail("Cannot proceed without File : " + resourceName); } return new File(uri); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java index dc52c6b3d8..b3553e6387 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITDeleteS3Object.java @@ -20,7 +20,7 @@ import org.apache.nifi.processors.aws.AbstractAWSProcessor; import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; 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.HashMap; diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java index 8bbc1f152c..fd94ddc96f 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITFetchS3Object.java @@ -22,7 +22,7 @@ import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredential 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.Files; diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITListS3.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITListS3.java index 3a47283df5..bb16e3a522 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITListS3.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITListS3.java @@ -22,7 +22,7 @@ import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredential 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.FileNotFoundException; import java.io.IOException; diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java index 7d2fd0e70f..c999a4e002 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITPutS3Object.java @@ -16,23 +16,19 @@ */ package org.apache.nifi.processors.aws.s3; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - +import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; +import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.GetObjectTaggingRequest; import com.amazonaws.services.s3.model.GetObjectTaggingResult; +import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest; import com.amazonaws.services.s3.model.ListMultipartUploadsRequest; +import com.amazonaws.services.s3.model.MultipartUpload; +import com.amazonaws.services.s3.model.MultipartUploadListing; import com.amazonaws.services.s3.model.ObjectMetadata; +import com.amazonaws.services.s3.model.PartETag; +import com.amazonaws.services.s3.model.Region; +import com.amazonaws.services.s3.model.StorageClass; import com.amazonaws.services.s3.model.Tag; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; @@ -53,23 +49,28 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.MockPropertyValue; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import com.amazonaws.AmazonClientException; -import com.amazonaws.services.s3.AmazonS3Client; -import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest; -import com.amazonaws.services.s3.model.MultipartUpload; -import com.amazonaws.services.s3.model.MultipartUploadListing; -import com.amazonaws.services.s3.model.PartETag; -import com.amazonaws.services.s3.model.Region; -import com.amazonaws.services.s3.model.StorageClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.security.SecureRandom; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +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.when; @@ -94,7 +95,7 @@ public class ITPutS3Object extends AbstractS3IT { private static String randomKeyMaterial = ""; - @BeforeClass + @BeforeAll public static void setupClass() { byte[] keyRawBytes = new byte[32]; SecureRandom secureRandom = new SecureRandom(); @@ -104,7 +105,7 @@ public class ITPutS3Object extends AbstractS3IT { kmsKeyId = getKMSKey(); } - @AfterClass + @AfterAll public static void teardownClass() { if (StringUtils.isNotEmpty(kmsKeyId)) { deleteKMSKey(kmsKeyId); @@ -115,7 +116,7 @@ public class ITPutS3Object extends AbstractS3IT { public void testSimplePut() throws IOException { TestRunner runner = initTestRunner(); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); for (int i = 0; i < 3; i++) { final Map attrs = new HashMap<>(); @@ -133,7 +134,7 @@ public class ITPutS3Object extends AbstractS3IT { runner.setProperty(PutS3Object.SERVER_SIDE_ENCRYPTION, ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); for (int i = 0; i < 3; i++) { final Map attrs = new HashMap<>(); @@ -236,7 +237,7 @@ public class ITPutS3Object extends AbstractS3IT { runner.setProperty(PutS3Object.REGION, REGION); runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); for (int i = 0; i < 3; i++) { final Map attrs = new HashMap<>(); @@ -374,7 +375,7 @@ public class ITPutS3Object extends AbstractS3IT { public void testPutInFolder() throws IOException { TestRunner runner = initTestRunner(); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); runner.assertValid(); final Map attrs = new HashMap<>(); @@ -390,7 +391,7 @@ public class ITPutS3Object extends AbstractS3IT { public void testStorageClasses() throws IOException { TestRunner runner = initTestRunner(); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); for (StorageClass storageClass : StorageClass.values()) { if (storageClass == StorageClass.Outposts) { @@ -408,7 +409,7 @@ public class ITPutS3Object extends AbstractS3IT { runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); FlowFile file = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS).get(0); - Assert.assertEquals(storageClass.toString(), file.getAttribute(PutS3Object.S3_STORAGECLASS_ATTR_KEY)); + assertEquals(storageClass.toString(), file.getAttribute(PutS3Object.S3_STORAGECLASS_ATTR_KEY)); runner.clearTransferState(); } @@ -421,7 +422,7 @@ public class ITPutS3Object extends AbstractS3IT { runner.setProperty(PutS3Object.MULTIPART_THRESHOLD, "50 MB"); runner.setProperty(PutS3Object.MULTIPART_PART_SIZE, "50 MB"); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); for (StorageClass storageClass : StorageClass.values()) { if (storageClass == StorageClass.Outposts) { @@ -439,7 +440,7 @@ public class ITPutS3Object extends AbstractS3IT { runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS, 1); FlowFile file = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS).get(0); - Assert.assertEquals(storageClass.toString(), file.getAttribute(PutS3Object.S3_STORAGECLASS_ATTR_KEY)); + assertEquals(storageClass.toString(), file.getAttribute(PutS3Object.S3_STORAGECLASS_ATTR_KEY)); runner.clearTransferState(); } @@ -485,7 +486,7 @@ public class ITPutS3Object extends AbstractS3IT { runner.run(); runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); final List successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, successFiles.size()); + assertEquals(1, successFiles.size()); MockFlowFile ff1 = successFiles.get(0); Long now = System.currentTimeMillis(); @@ -495,8 +496,8 @@ public class ITPutS3Object extends AbstractS3IT { String[] usermetaLine0 = usermeta.split(System.lineSeparator())[0].split("="); String usermetaKey0 = usermetaLine0[0]; String usermetaValue0 = usermetaLine0[1]; - Assert.assertEquals(DYNAMIC_ATTRIB_KEY, usermetaKey0); - Assert.assertTrue(usermetaValue0.compareTo(millisOneSecAgo) >=0 && usermetaValue0.compareTo(millisNow) <= 0); + assertEquals(DYNAMIC_ATTRIB_KEY, usermetaKey0); + assertTrue(usermetaValue0.compareTo(millisOneSecAgo) >=0 && usermetaValue0.compareTo(millisNow) <= 0); } @Test @@ -519,29 +520,29 @@ public class ITPutS3Object extends AbstractS3IT { runner.run(); runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); final List successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, successFiles.size()); + assertEquals(1, successFiles.size()); final List provenanceEvents = runner.getProvenanceEvents(); - Assert.assertEquals(1, provenanceEvents.size()); + assertEquals(1, provenanceEvents.size()); ProvenanceEventRecord provRec1 = provenanceEvents.get(0); - Assert.assertEquals(ProvenanceEventType.SEND, provRec1.getEventType()); - Assert.assertEquals(processor.getIdentifier(), provRec1.getComponentId()); + assertEquals(ProvenanceEventType.SEND, provRec1.getEventType()); + assertEquals(processor.getIdentifier(), provRec1.getComponentId()); client.setRegion(Region.fromValue(REGION).toAWSRegion()); String targetUri = client.getUrl(BUCKET_NAME, PROV1_FILE).toString(); - Assert.assertEquals(targetUri, provRec1.getTransitUri()); - Assert.assertEquals(8, provRec1.getUpdatedAttributes().size()); - Assert.assertEquals(BUCKET_NAME, provRec1.getUpdatedAttributes().get(PutS3Object.S3_BUCKET_KEY)); + assertEquals(targetUri, provRec1.getTransitUri()); + assertEquals(8, provRec1.getUpdatedAttributes().size()); + assertEquals(BUCKET_NAME, provRec1.getUpdatedAttributes().get(PutS3Object.S3_BUCKET_KEY)); } @Test public void testStateDefaults() { PutS3Object.MultipartState state1 = new PutS3Object.MultipartState(); - Assert.assertEquals(state1.getUploadId(), ""); - Assert.assertEquals(state1.getFilePosition(), (Long) 0L); - Assert.assertEquals(state1.getPartETags().size(), 0L); - Assert.assertEquals(state1.getPartSize(), (Long) 0L); - Assert.assertEquals(state1.getStorageClass().toString(), StorageClass.Standard.toString()); - Assert.assertEquals(state1.getContentLength(), (Long) 0L); + assertEquals(state1.getUploadId(), ""); + assertEquals(state1.getFilePosition(), (Long) 0L); + assertEquals(state1.getPartETags().size(), 0L); + assertEquals(state1.getPartSize(), (Long) 0L); + assertEquals(state1.getStorageClass().toString(), StorageClass.Standard.toString()); + assertEquals(state1.getContentLength(), (Long) 0L); } @Test @@ -557,7 +558,7 @@ public class ITPutS3Object extends AbstractS3IT { state2.setPartSize(20002L); state2.setStorageClass(StorageClass.ReducedRedundancy); state2.setContentLength(30003L); - Assert.assertEquals(target, state2.toString()); + assertEquals(target, state2.toString()); } @Test @@ -575,12 +576,12 @@ public class ITPutS3Object extends AbstractS3IT { runner.run(); - Assert.assertEquals(BUCKET_NAME, context.getProperty(PutS3Object.BUCKET).toString()); - Assert.assertEquals(TESTKEY, context.getProperty(PutS3Object.KEY).evaluateAttributeExpressions().toString()); - Assert.assertEquals(TEST_ENDPOINT, context.getProperty(PutS3Object.ENDPOINT_OVERRIDE).toString()); + assertEquals(BUCKET_NAME, context.getProperty(PutS3Object.BUCKET).toString()); + assertEquals(TESTKEY, context.getProperty(PutS3Object.KEY).evaluateAttributeExpressions().toString()); + assertEquals(TEST_ENDPOINT, context.getProperty(PutS3Object.ENDPOINT_OVERRIDE).toString()); String s3url = ((TestablePutS3Object)processor).testable_getClient().getResourceUrl(BUCKET_NAME, TESTKEY); - Assert.assertEquals(TEST_ENDPOINT + "/" + BUCKET_NAME + "/" + TESTKEY, s3url); + assertEquals(TEST_ENDPOINT + "/" + BUCKET_NAME + "/" + TESTKEY, s3url); } @Test @@ -596,9 +597,9 @@ public class ITPutS3Object extends AbstractS3IT { runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME); runner.setProperty(PutS3Object.KEY, AbstractS3IT.SAMPLE_FILE_RESOURCE_NAME); - Assert.assertEquals(BUCKET_NAME, context.getProperty(PutS3Object.BUCKET).toString()); - Assert.assertEquals(SAMPLE_FILE_RESOURCE_NAME, context.getProperty(PutS3Object.KEY).evaluateAttributeExpressions().toString()); - Assert.assertEquals(TEST_PARTSIZE_LONG.longValue(), + assertEquals(BUCKET_NAME, context.getProperty(PutS3Object.BUCKET).toString()); + assertEquals(SAMPLE_FILE_RESOURCE_NAME, context.getProperty(PutS3Object.KEY).evaluateAttributeExpressions().toString()); + assertEquals(TEST_PARTSIZE_LONG.longValue(), context.getProperty(PutS3Object.MULTIPART_PART_SIZE).asDataSize(DataUnit.B).longValue()); } @@ -651,28 +652,28 @@ public class ITPutS3Object extends AbstractS3IT { * reload and validate stored state */ final PutS3Object.MultipartState state1new = processor.getLocalStateIfInS3(mockClient, bucket, cacheKey1); - Assert.assertEquals("", state1new.getUploadId()); - Assert.assertEquals(0L, state1new.getFilePosition().longValue()); - Assert.assertEquals(new ArrayList(), state1new.getPartETags()); - Assert.assertEquals(0L, state1new.getPartSize().longValue()); - Assert.assertEquals(StorageClass.fromValue(StorageClass.Standard.toString()), state1new.getStorageClass()); - Assert.assertEquals(0L, state1new.getContentLength().longValue()); + assertEquals("", state1new.getUploadId()); + assertEquals(0L, state1new.getFilePosition().longValue()); + assertEquals(new ArrayList(), state1new.getPartETags()); + assertEquals(0L, state1new.getPartSize().longValue()); + assertEquals(StorageClass.fromValue(StorageClass.Standard.toString()), state1new.getStorageClass()); + assertEquals(0L, state1new.getContentLength().longValue()); final PutS3Object.MultipartState state2new = processor.getLocalStateIfInS3(mockClient, bucket, cacheKey2); - Assert.assertEquals("1234", state2new.getUploadId()); - Assert.assertEquals(0L, state2new.getFilePosition().longValue()); - Assert.assertEquals(new ArrayList(), state2new.getPartETags()); - Assert.assertEquals(0L, state2new.getPartSize().longValue()); - Assert.assertEquals(StorageClass.fromValue(StorageClass.Standard.toString()), state2new.getStorageClass()); - Assert.assertEquals(1234L, state2new.getContentLength().longValue()); + assertEquals("1234", state2new.getUploadId()); + assertEquals(0L, state2new.getFilePosition().longValue()); + assertEquals(new ArrayList(), state2new.getPartETags()); + assertEquals(0L, state2new.getPartSize().longValue()); + assertEquals(StorageClass.fromValue(StorageClass.Standard.toString()), state2new.getStorageClass()); + assertEquals(1234L, state2new.getContentLength().longValue()); final PutS3Object.MultipartState state3new = processor.getLocalStateIfInS3(mockClient, bucket, cacheKey3); - Assert.assertEquals("5678", state3new.getUploadId()); - Assert.assertEquals(0L, state3new.getFilePosition().longValue()); - Assert.assertEquals(new ArrayList(), state3new.getPartETags()); - Assert.assertEquals(0L, state3new.getPartSize().longValue()); - Assert.assertEquals(StorageClass.fromValue(StorageClass.Standard.toString()), state3new.getStorageClass()); - Assert.assertEquals(5678L, state3new.getContentLength().longValue()); + assertEquals("5678", state3new.getUploadId()); + assertEquals(0L, state3new.getFilePosition().longValue()); + assertEquals(new ArrayList(), state3new.getPartETags()); + assertEquals(0L, state3new.getPartSize().longValue()); + assertEquals(StorageClass.fromValue(StorageClass.Standard.toString()), state3new.getStorageClass()); + assertEquals(5678L, state3new.getContentLength().longValue()); } @Test @@ -743,12 +744,12 @@ public class ITPutS3Object extends AbstractS3IT { * 2. v3 restore shows 2 tags */ final PutS3Object.MultipartState state2new = processor.getLocalStateIfInS3(mockClient, bucket, cacheKey2); - Assert.assertEquals("1234", state2new.getUploadId()); - Assert.assertEquals(4, state2new.getPartETags().size()); + assertEquals("1234", state2new.getUploadId()); + assertEquals(4, state2new.getPartETags().size()); final PutS3Object.MultipartState state3new = processor.getLocalStateIfInS3(mockClient, bucket, cacheKey3); - Assert.assertEquals("5678", state3new.getUploadId()); - Assert.assertEquals(2, state3new.getPartETags().size()); + assertEquals("5678", state3new.getUploadId()); + assertEquals(2, state3new.getPartETags().size()); } @Test @@ -779,12 +780,12 @@ public class ITPutS3Object extends AbstractS3IT { processor.persistLocalState(cacheKey, stateOrig); PutS3Object.MultipartState state1 = processor.getLocalStateIfInS3(mockClient, bucket, cacheKey); - Assert.assertEquals("1234", state1.getUploadId()); - Assert.assertEquals(1234L, state1.getContentLength().longValue()); + assertEquals("1234", state1.getUploadId()); + assertEquals(1234L, state1.getContentLength().longValue()); processor.persistLocalState(cacheKey, null); PutS3Object.MultipartState state2 = processor.getLocalStateIfInS3(mockClient, bucket, cacheKey); - Assert.assertNull(state2); + assertNull(state2); } @Test @@ -801,10 +802,10 @@ public class ITPutS3Object extends AbstractS3IT { } tempOut.close(); System.out.println("file size: " + tempByteCount); - Assert.assertTrue(tempByteCount < S3_MINIMUM_PART_SIZE); + assertTrue(tempByteCount < S3_MINIMUM_PART_SIZE); - Assert.assertTrue(megabyte.length < S3_MINIMUM_PART_SIZE); - Assert.assertTrue(TEST_PARTSIZE_LONG >= S3_MINIMUM_PART_SIZE && TEST_PARTSIZE_LONG <= S3_MAXIMUM_OBJECT_SIZE); + assertTrue(megabyte.length < S3_MINIMUM_PART_SIZE); + assertTrue(TEST_PARTSIZE_LONG >= S3_MINIMUM_PART_SIZE && TEST_PARTSIZE_LONG <= S3_MAXIMUM_OBJECT_SIZE); final PutS3Object processor = new PutS3Object(); final TestRunner runner = TestRunners.newTestRunner(processor); @@ -822,16 +823,16 @@ public class ITPutS3Object extends AbstractS3IT { runner.run(); runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); final List successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, successFiles.size()); + assertEquals(1, successFiles.size()); final List failureFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE); - Assert.assertEquals(0, failureFiles.size()); + assertEquals(0, failureFiles.size()); MockFlowFile ff1 = successFiles.get(0); - Assert.assertEquals(PutS3Object.S3_API_METHOD_PUTOBJECT, ff1.getAttribute(PutS3Object.S3_API_METHOD_ATTR_KEY)); - Assert.assertEquals(FILE1_NAME, ff1.getAttribute(CoreAttributes.FILENAME.key())); - Assert.assertEquals(BUCKET_NAME, ff1.getAttribute(PutS3Object.S3_BUCKET_KEY)); - Assert.assertEquals(FILE1_NAME, ff1.getAttribute(PutS3Object.S3_OBJECT_KEY)); - Assert.assertTrue(reS3ETag.matcher(ff1.getAttribute(PutS3Object.S3_ETAG_ATTR_KEY)).matches()); - Assert.assertEquals(tempByteCount, ff1.getSize()); + assertEquals(PutS3Object.S3_API_METHOD_PUTOBJECT, ff1.getAttribute(PutS3Object.S3_API_METHOD_ATTR_KEY)); + assertEquals(FILE1_NAME, ff1.getAttribute(CoreAttributes.FILENAME.key())); + assertEquals(BUCKET_NAME, ff1.getAttribute(PutS3Object.S3_BUCKET_KEY)); + assertEquals(FILE1_NAME, ff1.getAttribute(PutS3Object.S3_OBJECT_KEY)); + assertTrue(reS3ETag.matcher(ff1.getAttribute(PutS3Object.S3_ETAG_ATTR_KEY)).matches()); + assertEquals(tempByteCount, ff1.getSize()); } @Test @@ -848,8 +849,8 @@ public class ITPutS3Object extends AbstractS3IT { } tempOut.close(); System.out.println("file size: " + tempByteCount); - Assert.assertTrue(tempByteCount > S3_MINIMUM_PART_SIZE && tempByteCount < S3_MAXIMUM_OBJECT_SIZE); - Assert.assertTrue(tempByteCount > TEST_PARTSIZE_LONG); + assertTrue(tempByteCount > S3_MINIMUM_PART_SIZE && tempByteCount < S3_MAXIMUM_OBJECT_SIZE); + assertTrue(tempByteCount > TEST_PARTSIZE_LONG); final PutS3Object processor = new PutS3Object(); final TestRunner runner = TestRunners.newTestRunner(processor); @@ -868,19 +869,18 @@ public class ITPutS3Object extends AbstractS3IT { runner.run(); runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); final List successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, successFiles.size()); + assertEquals(1, successFiles.size()); final List failureFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE); - Assert.assertEquals(0, failureFiles.size()); + assertEquals(0, failureFiles.size()); MockFlowFile ff1 = successFiles.get(0); - Assert.assertEquals(PutS3Object.S3_API_METHOD_MULTIPARTUPLOAD, ff1.getAttribute(PutS3Object.S3_API_METHOD_ATTR_KEY)); - Assert.assertEquals(FILE1_NAME, ff1.getAttribute(CoreAttributes.FILENAME.key())); - Assert.assertEquals(BUCKET_NAME, ff1.getAttribute(PutS3Object.S3_BUCKET_KEY)); - Assert.assertEquals(FILE1_NAME, ff1.getAttribute(PutS3Object.S3_OBJECT_KEY)); - Assert.assertTrue(reS3ETag.matcher(ff1.getAttribute(PutS3Object.S3_ETAG_ATTR_KEY)).matches()); - Assert.assertEquals(tempByteCount, ff1.getSize()); + assertEquals(PutS3Object.S3_API_METHOD_MULTIPARTUPLOAD, ff1.getAttribute(PutS3Object.S3_API_METHOD_ATTR_KEY)); + assertEquals(FILE1_NAME, ff1.getAttribute(CoreAttributes.FILENAME.key())); + assertEquals(BUCKET_NAME, ff1.getAttribute(PutS3Object.S3_BUCKET_KEY)); + assertEquals(FILE1_NAME, ff1.getAttribute(PutS3Object.S3_OBJECT_KEY)); + assertTrue(reS3ETag.matcher(ff1.getAttribute(PutS3Object.S3_ETAG_ATTR_KEY)).matches()); + assertEquals(tempByteCount, ff1.getSize()); } - @Ignore @Test public void testMultipartLargerThanObjectMaximum() throws IOException { final String FILE1_NAME = "file1"; @@ -909,15 +909,15 @@ public class ITPutS3Object extends AbstractS3IT { runner.run(); runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); final List successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, successFiles.size()); + assertEquals(1, successFiles.size()); final List failureFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE); - Assert.assertEquals(0, failureFiles.size()); + assertEquals(0, failureFiles.size()); MockFlowFile ff1 = successFiles.get(0); - Assert.assertEquals(FILE1_NAME, ff1.getAttribute(CoreAttributes.FILENAME.key())); - Assert.assertEquals(BUCKET_NAME, ff1.getAttribute(PutS3Object.S3_BUCKET_KEY)); - Assert.assertEquals(FILE1_NAME, ff1.getAttribute(PutS3Object.S3_OBJECT_KEY)); - Assert.assertTrue(reS3ETag.matcher(ff1.getAttribute(PutS3Object.S3_ETAG_ATTR_KEY)).matches()); - Assert.assertTrue(ff1.getSize() > S3_MAXIMUM_OBJECT_SIZE); + assertEquals(FILE1_NAME, ff1.getAttribute(CoreAttributes.FILENAME.key())); + assertEquals(BUCKET_NAME, ff1.getAttribute(PutS3Object.S3_BUCKET_KEY)); + assertEquals(FILE1_NAME, ff1.getAttribute(PutS3Object.S3_OBJECT_KEY)); + assertTrue(reS3ETag.matcher(ff1.getAttribute(PutS3Object.S3_ETAG_ATTR_KEY)).matches()); + assertTrue(ff1.getSize() > S3_MAXIMUM_OBJECT_SIZE); } @Test @@ -937,12 +937,8 @@ public class ITPutS3Object extends AbstractS3IT { // create some dummy uploads for (Integer i = 0; i < 3; i++) { final InitiateMultipartUploadRequest initiateRequest = new InitiateMultipartUploadRequest( - BUCKET_NAME, "file" + i.toString() + ".txt"); - try { - client.initiateMultipartUpload(initiateRequest); - } catch (AmazonClientException e) { - Assert.fail("Failed to initiate upload: " + e.getMessage()); - } + BUCKET_NAME, "file" + i + ".txt"); + assertDoesNotThrow(() -> client.initiateMultipartUpload(initiateRequest)); } // Age off is time dependent, so test has some timing constraints. This @@ -956,13 +952,13 @@ public class ITPutS3Object extends AbstractS3IT { Long now = System.currentTimeMillis(); MultipartUploadListing uploadList = processor.getS3AgeoffListAndAgeoffLocalState(context, client, now, BUCKET_NAME); - Assert.assertEquals(3, uploadList.getMultipartUploads().size()); + assertEquals(3, uploadList.getMultipartUploads().size()); MultipartUpload upload0 = uploadList.getMultipartUploads().get(0); processor.abortS3MultipartUpload(client, BUCKET_NAME, upload0); uploadList = processor.getS3AgeoffListAndAgeoffLocalState(context, client, now+1000, BUCKET_NAME); - Assert.assertEquals(2, uploadList.getMultipartUploads().size()); + assertEquals(2, uploadList.getMultipartUploads().size()); final Map attrs = new HashMap<>(); attrs.put("filename", "test-upload.txt"); @@ -970,7 +966,7 @@ public class ITPutS3Object extends AbstractS3IT { runner.run(); uploadList = processor.getS3AgeoffListAndAgeoffLocalState(context, client, now+2000, BUCKET_NAME); - Assert.assertEquals(0, uploadList.getMultipartUploads().size()); + assertEquals(0, uploadList.getMultipartUploads().size()); } @Test @@ -995,9 +991,9 @@ public class ITPutS3Object extends AbstractS3IT { System.out.println("Tag Key : " + tag.getKey() + ", Tag Value : " + tag.getValue()); } - Assert.assertTrue(objectTags.size() == 1); - Assert.assertEquals("PII", objectTags.get(0).getKey()); - Assert.assertEquals("true", objectTags.get(0).getValue()); + assertTrue(objectTags.size() == 1); + assertEquals("PII", objectTags.get(0).getKey()); + assertEquals("true", objectTags.get(0).getValue()); } @Test @@ -1023,10 +1019,10 @@ public class ITPutS3Object extends AbstractS3IT { runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); List flowFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, flowFiles.size()); - Assert.assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); + assertEquals(1, flowFiles.size()); + assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); MockFlowFile putSuccess = flowFiles.get(0); - Assert.assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_SSE_S3); + assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_SSE_S3); MockFlowFile flowFile = fetchEncryptedFlowFile(attrs, AmazonS3EncryptionService.STRATEGY_NAME_SSE_S3, null); flowFile.assertContentEquals(data); @@ -1057,10 +1053,10 @@ public class ITPutS3Object extends AbstractS3IT { runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); List flowFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, flowFiles.size()); - Assert.assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); + assertEquals(1, flowFiles.size()); + assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); MockFlowFile putSuccess = flowFiles.get(0); - Assert.assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_SSE_KMS); + assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_SSE_KMS); MockFlowFile flowFile = fetchEncryptedFlowFile(attrs, AmazonS3EncryptionService.STRATEGY_NAME_SSE_KMS, kmsKeyId); flowFile.assertContentEquals(data); @@ -1091,10 +1087,10 @@ public class ITPutS3Object extends AbstractS3IT { runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); List flowFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, flowFiles.size()); - Assert.assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); + assertEquals(1, flowFiles.size()); + assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); MockFlowFile putSuccess = flowFiles.get(0); - Assert.assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_SSE_C); + assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_SSE_C); MockFlowFile flowFile = fetchEncryptedFlowFile(attrs, AmazonS3EncryptionService.STRATEGY_NAME_SSE_C, randomKeyMaterial); flowFile.assertContentEquals(data); @@ -1127,10 +1123,10 @@ public class ITPutS3Object extends AbstractS3IT { runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); List flowFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, flowFiles.size()); - Assert.assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); + assertEquals(1, flowFiles.size()); + assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); MockFlowFile putSuccess = flowFiles.get(0); - Assert.assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_CSE_KMS); + assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_CSE_KMS); MockFlowFile flowFile = fetchEncryptedFlowFile(attrs, AmazonS3EncryptionService.STRATEGY_NAME_CSE_KMS, kmsKeyId); flowFile.assertContentEquals(data); @@ -1161,10 +1157,10 @@ public class ITPutS3Object extends AbstractS3IT { runner.assertAllFlowFilesTransferred(PutS3Object.REL_SUCCESS); List flowFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS); - Assert.assertEquals(1, flowFiles.size()); - Assert.assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); + assertEquals(1, flowFiles.size()); + assertEquals(0, runner.getFlowFilesForRelationship(PutS3Object.REL_FAILURE).size()); MockFlowFile putSuccess = flowFiles.get(0); - Assert.assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_CSE_C); + assertEquals(putSuccess.getAttribute(PutS3Object.S3_ENCRYPTION_STRATEGY), AmazonS3EncryptionService.STRATEGY_NAME_CSE_C); MockFlowFile flowFile = fetchEncryptedFlowFile(attrs, AmazonS3EncryptionService.STRATEGY_NAME_CSE_C, randomKeyMaterial); flowFile.assertAttributeEquals(PutS3Object.S3_ENCRYPTION_STRATEGY, AmazonS3EncryptionService.STRATEGY_NAME_CSE_C); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITTagS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITTagS3Object.java index b1b42c0889..2d6c4573b9 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITTagS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/ITTagS3Object.java @@ -22,14 +22,14 @@ import com.amazonaws.services.s3.model.Tag; 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.Arrays; import java.util.HashMap; import java.util.Map; -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; /** @@ -39,7 +39,7 @@ import static org.junit.Assert.assertTrue; public class ITTagS3Object extends AbstractS3IT { @Test - public void testSimpleTag() throws Exception { + public void testSimpleTag() { String objectKey = "test-file"; String tagKey = "nifi-key"; String tagValue = "nifi-val"; @@ -67,11 +67,11 @@ public class ITTagS3Object extends AbstractS3IT { // Verify tag exists on S3 object GetObjectTaggingResult res = client.getObjectTagging(new GetObjectTaggingRequest(BUCKET_NAME, objectKey)); - assertTrue("Expected tag not found on S3 object", res.getTagSet().contains(new Tag(tagKey, tagValue))); + assertTrue(res.getTagSet().contains(new Tag(tagKey, tagValue)), "Expected tag not found on S3 object"); } @Test - public void testAppendTag() throws Exception { + public void testAppendTag() { String objectKey = "test-file"; String tagKey = "nifi-key"; String tagValue = "nifi-val"; @@ -101,12 +101,12 @@ public class ITTagS3Object extends AbstractS3IT { // Verify new tag and existing exist on S3 object GetObjectTaggingResult res = client.getObjectTagging(new GetObjectTaggingRequest(BUCKET_NAME, objectKey)); - assertTrue("Expected new tag not found on S3 object", res.getTagSet().contains(new Tag(tagKey, tagValue))); - assertTrue("Expected existing tag not found on S3 object", res.getTagSet().contains(existingTag)); + assertTrue(res.getTagSet().contains(new Tag(tagKey, tagValue)), "Expected new tag not found on S3 object"); + assertTrue(res.getTagSet().contains(existingTag), "Expected existing tag not found on S3 object"); } @Test - public void testReplaceTags() throws Exception { + public void testReplaceTags() { String objectKey = "test-file"; String tagKey = "nifi-key"; String tagValue = "nifi-val"; @@ -143,8 +143,8 @@ public class ITTagS3Object extends AbstractS3IT { // Verify new tag exists on S3 object and prior tag removed GetObjectTaggingResult res = client.getObjectTagging(new GetObjectTaggingRequest(BUCKET_NAME, objectKey)); - assertTrue("Expected new tag not found on S3 object", res.getTagSet().contains(new Tag(tagKey, tagValue))); - assertFalse("Existing tag not replaced on S3 object", res.getTagSet().contains(existingTag)); + assertTrue(res.getTagSet().contains(new Tag(tagKey, tagValue)), "Expected new tag not found on S3 object"); + assertFalse(res.getTagSet().contains(existingTag), "Existing tag not replaced on S3 object"); } } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java index 2bde4e162e..f5c266bc43 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestDeleteS3Object.java @@ -16,43 +16,38 @@ */ package org.apache.nifi.processors.aws.s3; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.proxy.ProxyConfigurationService; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.AmazonS3Exception; import com.amazonaws.services.s3.model.DeleteObjectRequest; import com.amazonaws.services.s3.model.DeleteVersionRequest; - -import org.junit.Before; -import org.junit.Test; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.proxy.ProxyConfigurationService; +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.mockito.ArgumentCaptor; import org.mockito.Mockito; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +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.assertTrue; public class TestDeleteS3Object { private TestRunner runner = null; private DeleteS3Object mockDeleteS3Object = null; - private AmazonS3Client actualS3Client = null; private AmazonS3Client mockS3Client = null; - @Before + @BeforeEach public void setUp() { mockS3Client = Mockito.mock(AmazonS3Client.class); mockDeleteS3Object = new DeleteS3Object() { protected AmazonS3Client getClient() { - actualS3Client = client; return mockS3Client; } }; @@ -60,7 +55,7 @@ public class TestDeleteS3Object { } @Test - public void testDeleteObjectSimple() throws IOException { + public void testDeleteObjectSimple() { runner.setProperty(DeleteS3Object.REGION, "us-west-2"); runner.setProperty(DeleteS3Object.BUCKET, "test-bucket"); final Map attrs = new HashMap<>(); @@ -139,10 +134,10 @@ public class TestDeleteS3Object { } @Test - public void testGetPropertyDescriptors() throws Exception { + public void testGetPropertyDescriptors() { DeleteS3Object processor = new DeleteS3Object(); List pd = processor.getSupportedPropertyDescriptors(); - assertEquals("size should be eq", 23, pd.size()); + assertEquals(23, pd.size(), "size should be eq"); assertTrue(pd.contains(processor.ACCESS_KEY)); assertTrue(pd.contains(processor.AWS_CREDENTIALS_PROVIDER_SERVICE)); assertTrue(pd.contains(processor.BUCKET)); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java index 81e45d7292..815fcfd98d 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestFetchS3Object.java @@ -16,16 +16,13 @@ */ package org.apache.nifi.processors.aws.s3; -import java.io.IOException; -import java.net.HttpURLConnection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - import com.amazonaws.SdkClientException; +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.AmazonS3Exception; +import com.amazonaws.services.s3.model.GetObjectRequest; +import com.amazonaws.services.s3.model.ObjectMetadata; +import com.amazonaws.services.s3.model.S3Object; +import com.amazonaws.util.StringInputStream; import org.apache.nifi.components.ConfigVerificationResult; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.flowfile.attributes.CoreAttributes; @@ -35,22 +32,23 @@ import org.apache.nifi.processors.aws.AbstractAWSProcessor; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; - -import com.amazonaws.services.s3.AmazonS3Client; -import com.amazonaws.services.s3.model.AmazonS3Exception; -import com.amazonaws.services.s3.model.GetObjectRequest; -import com.amazonaws.services.s3.model.ObjectMetadata; -import com.amazonaws.services.s3.model.S3Object; -import com.amazonaws.util.StringInputStream; - -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -64,7 +62,7 @@ public class TestFetchS3Object { private AmazonS3Client actualS3Client = null; private AmazonS3Client mockS3Client = null; - @Before + @BeforeEach public void setUp() { mockS3Client = mock(AmazonS3Client.class); mockFetchS3Object = new FetchS3Object() { diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestListS3.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestListS3.java index 275f0cc73e..410cf9370f 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestListS3.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestListS3.java @@ -40,8 +40,8 @@ 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.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -55,9 +55,9 @@ 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.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; public class TestListS3 { @@ -65,7 +65,7 @@ public class TestListS3 { private TestRunner runner = null; private AmazonS3Client mockS3Client = null; - @Before + @BeforeEach public void setUp() { mockS3Client = Mockito.mock(AmazonS3Client.class); final ListS3 mockListS3 = new ListS3() { diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java index 4fc2440231..ac1bac58b1 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestPutS3Object.java @@ -16,25 +16,6 @@ */ package org.apache.nifi.processors.aws.s3; -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.amazonaws.services.s3.model.StorageClass; -import com.amazonaws.services.s3.model.Tag; -import org.apache.commons.lang3.StringUtils; -import org.apache.nifi.components.AllowableValue; -import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.flowfile.attributes.CoreAttributes; -import org.apache.nifi.processor.ProcessContext; -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - import com.amazonaws.ClientConfiguration; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; @@ -45,15 +26,32 @@ import com.amazonaws.services.s3.model.MultipartUploadListing; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; import com.amazonaws.services.s3.model.PutObjectResult; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import com.amazonaws.services.s3.model.StorageClass; +import com.amazonaws.services.s3.model.Tag; +import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.components.AllowableValue; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.flowfile.attributes.CoreAttributes; +import org.apache.nifi.processor.ProcessContext; +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 org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestPutS3Object { @@ -62,7 +60,7 @@ public class TestPutS3Object { private PutS3Object putS3Object; private AmazonS3Client mockS3Client; - @Before + @BeforeEach public void setUp() { mockS3Client = Mockito.mock(AmazonS3Client.class); putS3Object = new PutS3Object() { @@ -125,11 +123,7 @@ public class TestPutS3Object { if (!signerType.equals(defaultSignerValue)) { runner.setProperty(PutS3Object.SIGNER_OVERRIDE, signerType); ProcessContext context = runner.getProcessContext(); - try { - processor.createClient(context, credentialsProvider, config); - } catch (IllegalArgumentException argEx) { - Assert.fail(argEx.getMessage()); - } + assertDoesNotThrow(() -> processor.createClient(context, credentialsProvider, config)); } } } @@ -247,7 +241,7 @@ public class TestPutS3Object { public void testGetPropertyDescriptors() { PutS3Object processor = new PutS3Object(); List pd = processor.getSupportedPropertyDescriptors(); - assertEquals("size should be eq", 39, pd.size()); + assertEquals(39, pd.size(), "size should be eq"); assertTrue(pd.contains(PutS3Object.ACCESS_KEY)); assertTrue(pd.contains(PutS3Object.AWS_CREDENTIALS_PROVIDER_SERVICE)); assertTrue(pd.contains(PutS3Object.BUCKET)); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestTagS3Object.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestTagS3Object.java index 58586b2ad6..0dfd9b2706 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestTagS3Object.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/TestTagS3Object.java @@ -26,8 +26,8 @@ import org.apache.nifi.proxy.ProxyConfigurationService; 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.ArgumentCaptor; import org.mockito.Mockito; @@ -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestTagS3Object { @@ -51,7 +51,7 @@ public class TestTagS3Object { private AmazonS3Client actualS3Client = null; private AmazonS3Client mockS3Client = null; - @Before + @BeforeEach public void setUp() { mockS3Client = Mockito.mock(AmazonS3Client.class); mockTagS3Object = new TagS3Object() { @@ -84,8 +84,8 @@ public class TestTagS3Object { SetObjectTaggingRequest request = captureRequest.getValue(); assertEquals("test-bucket", request.getBucketName()); assertEquals("object-key", request.getKey()); - assertNull("test-version", request.getVersionId()); - assertTrue("Expected tag not found in request", request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal))); + assertNull(request.getVersionId(), "test-version"); + assertTrue(request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal)), "Expected tag not found in request"); List flowFiles = runner.getFlowFilesForRelationship(ListS3.REL_SUCCESS); MockFlowFile ff0 = flowFiles.get(0); @@ -115,7 +115,7 @@ public class TestTagS3Object { assertEquals("test-bucket", request.getBucketName()); assertEquals("object-key", request.getKey()); assertEquals("test-version", request.getVersionId()); - assertTrue("Expected tag not found in request", request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal))); + assertTrue(request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal)), "Expected tag not found in request"); } @Test @@ -143,8 +143,8 @@ public class TestTagS3Object { SetObjectTaggingRequest request = captureRequest.getValue(); assertEquals("test-bucket", request.getBucketName()); assertEquals("object-key", request.getKey()); - assertTrue("New tag not found in request", request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal))); - assertTrue("Existing tag not found in request", request.getTagging().getTagSet().contains(currentTag)); + assertTrue(request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal)), "New tag not found in request"); + assertTrue(request.getTagging().getTagSet().contains(currentTag), "Existing tag not found in request"); List flowFiles = runner.getFlowFilesForRelationship(ListS3.REL_SUCCESS); MockFlowFile ff0 = flowFiles.get(0); @@ -177,9 +177,9 @@ public class TestTagS3Object { SetObjectTaggingRequest request = captureRequest.getValue(); assertEquals("test-bucket", request.getBucketName()); assertEquals("object-key", request.getKey()); - assertTrue("New tag not found in request", request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal))); - assertTrue("Existing tag not found in request", request.getTagging().getTagSet().contains(currentTag1)); - assertFalse("Existing tag should be excluded from request", request.getTagging().getTagSet().contains(currentTag2)); + assertTrue(request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal)), "New tag not found in request"); + assertTrue(request.getTagging().getTagSet().contains(currentTag1), "Existing tag not found in request"); + assertFalse(request.getTagging().getTagSet().contains(currentTag2), "Existing tag should be excluded from request"); } @Test @@ -208,8 +208,8 @@ public class TestTagS3Object { SetObjectTaggingRequest request = captureRequest.getValue(); assertEquals("test-bucket", request.getBucketName()); assertEquals("object-key", request.getKey()); - assertTrue("New tag not found in request", request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal))); - assertFalse("Existing tag should be excluded from request", request.getTagging().getTagSet().contains(currentTag)); + assertTrue(request.getTagging().getTagSet().contains(new Tag(tagKey, tagVal)), "New tag not found in request"); + assertFalse(request.getTagging().getTagSet().contains(currentTag), "Existing tag should be excluded from request"); List flowFiles = runner.getFlowFilesForRelationship(ListS3.REL_SUCCESS); MockFlowFile ff0 = flowFiles.get(0); @@ -244,7 +244,7 @@ public class TestTagS3Object { public void testGetPropertyDescriptors() throws Exception { TagS3Object processor = new TagS3Object(); List pd = processor.getSupportedPropertyDescriptors(); - assertEquals("size should be eq", 20, pd.size()); + assertEquals(20, pd.size(), "size should be eq"); assertTrue(pd.contains(TagS3Object.ACCESS_KEY)); assertTrue(pd.contains(TagS3Object.AWS_CREDENTIALS_PROVIDER_SERVICE)); assertTrue(pd.contains(TagS3Object.BUCKET)); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestClientSideCEncryptionStrategyKeyValidation.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestClientSideCEncryptionStrategyKeyValidation.java index 5d716f5e97..04c1fb0643 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestClientSideCEncryptionStrategyKeyValidation.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestClientSideCEncryptionStrategyKeyValidation.java @@ -17,18 +17,18 @@ package org.apache.nifi.processors.aws.s3.encryption; import org.apache.nifi.components.ValidationResult; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.apache.nifi.processors.aws.s3.encryption.S3EncryptionTestUtil.createKey; -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 TestClientSideCEncryptionStrategyKeyValidation { private ClientSideCEncryptionStrategy strategy; - @Before + @BeforeEach public void setUp() { strategy = new ClientSideCEncryptionStrategy(); } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestS3EncryptionStrategies.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestS3EncryptionStrategies.java index ec12230f80..77bde9c2b7 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestS3EncryptionStrategies.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestS3EncryptionStrategies.java @@ -22,12 +22,15 @@ import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; import com.amazonaws.services.s3.model.UploadPartRequest; import org.apache.commons.codec.binary.Base64; -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.security.SecureRandom; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + public class TestS3EncryptionStrategies { @@ -41,7 +44,7 @@ public class TestS3EncryptionStrategies { private GetObjectRequest getObjectRequest = null; private UploadPartRequest uploadPartRequest = null; - @Before + @BeforeEach public void setup() { byte[] keyRawBytes = new byte[32]; SecureRandom secureRandom = new SecureRandom(); @@ -60,19 +63,19 @@ public class TestS3EncryptionStrategies { S3EncryptionStrategy strategy = new ClientSideKMSEncryptionStrategy(); // This shows that the strategy builds a client: - Assert.assertNotNull(strategy.createEncryptionClient(null, null, kmsRegion, randomKeyMaterial)); + assertNotNull(strategy.createEncryptionClient(null, null, kmsRegion, randomKeyMaterial)); // This shows that the strategy does not modify the metadata or any of the requests: - Assert.assertNull(metadata.getSSEAlgorithm()); - Assert.assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(putObjectRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); + assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); + assertNull(putObjectRequest.getSSECustomerKey()); - Assert.assertNull(initUploadRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(initUploadRequest.getSSECustomerKey()); + assertNull(initUploadRequest.getSSEAwsKeyManagementParams()); + assertNull(initUploadRequest.getSSECustomerKey()); - Assert.assertNull(getObjectRequest.getSSECustomerKey()); + assertNull(getObjectRequest.getSSECustomerKey()); - Assert.assertNull(uploadPartRequest.getSSECustomerKey()); + assertNull(uploadPartRequest.getSSECustomerKey()); } @Test @@ -80,19 +83,19 @@ public class TestS3EncryptionStrategies { S3EncryptionStrategy strategy = new ClientSideCEncryptionStrategy(); // This shows that the strategy builds a client: - Assert.assertNotNull(strategy.createEncryptionClient(null, null, null, randomKeyMaterial)); + assertNotNull(strategy.createEncryptionClient(null, null, null, randomKeyMaterial)); // This shows that the strategy does not modify the metadata or any of the requests: - Assert.assertNull(metadata.getSSEAlgorithm()); - Assert.assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(putObjectRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); + assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); + assertNull(putObjectRequest.getSSECustomerKey()); - Assert.assertNull(initUploadRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(initUploadRequest.getSSECustomerKey()); + assertNull(initUploadRequest.getSSEAwsKeyManagementParams()); + assertNull(initUploadRequest.getSSECustomerKey()); - Assert.assertNull(getObjectRequest.getSSECustomerKey()); + assertNull(getObjectRequest.getSSECustomerKey()); - Assert.assertNull(uploadPartRequest.getSSECustomerKey()); + assertNull(uploadPartRequest.getSSECustomerKey()); } @Test @@ -100,29 +103,29 @@ public class TestS3EncryptionStrategies { S3EncryptionStrategy strategy = new ServerSideCEncryptionStrategy(); // This shows that the strategy does *not* build a client: - Assert.assertNull(strategy.createEncryptionClient(null, null, null, "")); + assertNull(strategy.createEncryptionClient(null, null, null, "")); // This shows that the strategy sets the SSE customer key as expected: strategy.configurePutObjectRequest(putObjectRequest, metadata, randomKeyMaterial); - Assert.assertEquals(randomKeyMaterial, putObjectRequest.getSSECustomerKey().getKey()); - Assert.assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertEquals(randomKeyMaterial, putObjectRequest.getSSECustomerKey().getKey()); + assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); + assertNull(metadata.getSSEAlgorithm()); // Same for InitiateMultipartUploadRequest: strategy.configureInitiateMultipartUploadRequest(initUploadRequest, metadata, randomKeyMaterial); - Assert.assertEquals(randomKeyMaterial, initUploadRequest.getSSECustomerKey().getKey()); - Assert.assertNull(initUploadRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertEquals(randomKeyMaterial, initUploadRequest.getSSECustomerKey().getKey()); + assertNull(initUploadRequest.getSSEAwsKeyManagementParams()); + assertNull(metadata.getSSEAlgorithm()); // Same for GetObjectRequest: strategy.configureGetObjectRequest(getObjectRequest, metadata, randomKeyMaterial); - Assert.assertEquals(randomKeyMaterial, initUploadRequest.getSSECustomerKey().getKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertEquals(randomKeyMaterial, initUploadRequest.getSSECustomerKey().getKey()); + assertNull(metadata.getSSEAlgorithm()); // Same for UploadPartRequest: strategy.configureUploadPartRequest(uploadPartRequest, metadata, randomKeyMaterial); - Assert.assertEquals(randomKeyMaterial, uploadPartRequest.getSSECustomerKey().getKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertEquals(randomKeyMaterial, uploadPartRequest.getSSECustomerKey().getKey()); + assertNull(metadata.getSSEAlgorithm()); } @Test @@ -130,19 +133,19 @@ public class TestS3EncryptionStrategies { S3EncryptionStrategy strategy = new ServerSideKMSEncryptionStrategy(); // This shows that the strategy does *not* build a client: - Assert.assertNull(strategy.createEncryptionClient(null, null, null, null)); + assertNull(strategy.createEncryptionClient(null, null, null, null)); // This shows that the strategy sets the SSE KMS key id as expected: strategy.configurePutObjectRequest(putObjectRequest, metadata, randomKeyId); - Assert.assertEquals(randomKeyId, putObjectRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId()); - Assert.assertNull(putObjectRequest.getSSECustomerKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertEquals(randomKeyId, putObjectRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId()); + assertNull(putObjectRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); // Same for InitiateMultipartUploadRequest: strategy.configureInitiateMultipartUploadRequest(initUploadRequest, metadata, randomKeyId); - Assert.assertEquals(randomKeyId, initUploadRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId()); - Assert.assertNull(initUploadRequest.getSSECustomerKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertEquals(randomKeyId, initUploadRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId()); + assertNull(initUploadRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); } @Test @@ -150,15 +153,15 @@ public class TestS3EncryptionStrategies { S3EncryptionStrategy strategy = new ServerSideS3EncryptionStrategy(); // This shows that the strategy does *not* build a client: - Assert.assertNull(strategy.createEncryptionClient(null, null, null, null)); + assertNull(strategy.createEncryptionClient(null, null, null, null)); // This shows that the strategy sets the SSE algorithm field as expected: strategy.configurePutObjectRequest(putObjectRequest, metadata, null); - Assert.assertEquals(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION, metadata.getSSEAlgorithm()); + assertEquals(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION, metadata.getSSEAlgorithm()); // Same for InitiateMultipartUploadRequest: strategy.configureInitiateMultipartUploadRequest(initUploadRequest, metadata, null); - Assert.assertEquals(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION, metadata.getSSEAlgorithm()); + assertEquals(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION, metadata.getSSEAlgorithm()); } @Test @@ -166,19 +169,19 @@ public class TestS3EncryptionStrategies { S3EncryptionStrategy strategy = new NoOpEncryptionStrategy(); // This shows that the strategy does *not* build a client: - Assert.assertNull(strategy.createEncryptionClient(null, null, "", "")); + assertNull(strategy.createEncryptionClient(null, null, "", "")); // This shows the request and metadata start with various null objects: - Assert.assertNull(metadata.getSSEAlgorithm()); - Assert.assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(putObjectRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); + assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); + assertNull(putObjectRequest.getSSECustomerKey()); // Act: strategy.configurePutObjectRequest(putObjectRequest, metadata, ""); // This shows that the request and metadata were not changed: - Assert.assertNull(metadata.getSSEAlgorithm()); - Assert.assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); - Assert.assertNull(putObjectRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); + assertNull(putObjectRequest.getSSEAwsKeyManagementParams()); + assertNull(putObjectRequest.getSSECustomerKey()); } } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestServerSideCEncryptionStrategyKeyValidation.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestServerSideCEncryptionStrategyKeyValidation.java index 77d64ce77d..071b433481 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestServerSideCEncryptionStrategyKeyValidation.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestServerSideCEncryptionStrategyKeyValidation.java @@ -17,18 +17,18 @@ package org.apache.nifi.processors.aws.s3.encryption; import org.apache.nifi.components.ValidationResult; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.apache.nifi.processors.aws.s3.encryption.S3EncryptionTestUtil.createKey; -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 TestServerSideCEncryptionStrategyKeyValidation { private ServerSideCEncryptionStrategy strategy; - @Before + @BeforeEach public void setUp() { strategy = new ServerSideCEncryptionStrategy(); } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionService.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionService.java index 1a6c02ec4b..d63db09c01 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionService.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionService.java @@ -26,12 +26,15 @@ import org.apache.nifi.controller.ConfigurationContext; import org.apache.nifi.processors.aws.s3.AmazonS3EncryptionService; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.MockPropertyValue; -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 org.mockito.Mockito; + import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + public class TestStandardS3EncryptionService { private StandardS3EncryptionService service; @@ -40,7 +43,7 @@ public class TestStandardS3EncryptionService { private String keyIdOrMaterial; private String kmsRegion; - @Before + @BeforeEach public void setup() throws InitializationException { service = new StandardS3EncryptionService(); context = Mockito.mock(ConfigurationContext.class); @@ -57,13 +60,13 @@ public class TestStandardS3EncryptionService { @Test public void testServiceProperties() { - Assert.assertEquals(service.getKmsRegion(), kmsRegion); - Assert.assertEquals(service.getStrategyName(), strategyName); + assertEquals(service.getKmsRegion(), kmsRegion); + assertEquals(service.getStrategyName(), strategyName); } @Test public void testCreateClientReturnsNull() { - Assert.assertNull(service.createEncryptionClient(null, null)); + assertNull(service.createEncryptionClient(null, null)); } @Test @@ -75,29 +78,29 @@ public class TestStandardS3EncryptionService { final UploadPartRequest uploadPartRequest = new UploadPartRequest(); service.configureGetObjectRequest(getObjectRequest, metadata); - Assert.assertNull(getObjectRequest.getSSECustomerKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertNull(getObjectRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); service.configureUploadPartRequest(uploadPartRequest, metadata); - Assert.assertNull(uploadPartRequest.getSSECustomerKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertNull(uploadPartRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); service.configurePutObjectRequest(putObjectRequest, metadata); - Assert.assertNull(putObjectRequest.getSSECustomerKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertNull(putObjectRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); service.configureInitiateMultipartUploadRequest(initUploadRequest, metadata); - Assert.assertNull(initUploadRequest.getSSECustomerKey()); - Assert.assertNull(metadata.getSSEAlgorithm()); + assertNull(initUploadRequest.getSSECustomerKey()); + assertNull(metadata.getSSEAlgorithm()); } @Test public void testProperties() { List properties = service.getSupportedPropertyDescriptors(); - Assert.assertEquals(3, properties.size()); + assertEquals(3, properties.size()); - Assert.assertEquals(properties.get(0).getName(), StandardS3EncryptionService.ENCRYPTION_STRATEGY.getName()); - Assert.assertEquals(properties.get(1).getName(), StandardS3EncryptionService.ENCRYPTION_VALUE.getName()); - Assert.assertEquals(properties.get(2).getName(), StandardS3EncryptionService.KMS_REGION.getName()); + assertEquals(properties.get(0).getName(), StandardS3EncryptionService.ENCRYPTION_STRATEGY.getName()); + assertEquals(properties.get(1).getName(), StandardS3EncryptionService.ENCRYPTION_VALUE.getName()); + assertEquals(properties.get(2).getName(), StandardS3EncryptionService.KMS_REGION.getName()); } } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionServiceValidation.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionServiceValidation.java index 2bccc17cdb..e1b066a952 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionServiceValidation.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/s3/encryption/TestStandardS3EncryptionServiceValidation.java @@ -20,8 +20,8 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.NoOpProcessor; 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.apache.nifi.processors.aws.s3.AmazonS3EncryptionService.STRATEGY_NAME_CSE_C; import static org.apache.nifi.processors.aws.s3.AmazonS3EncryptionService.STRATEGY_NAME_CSE_KMS; @@ -36,7 +36,7 @@ public class TestStandardS3EncryptionServiceValidation { private TestRunner runner; private StandardS3EncryptionService service; - @Before + @BeforeEach public void setUp() throws InitializationException { runner = TestRunners.newTestRunner(NoOpProcessor.class); service = new StandardS3EncryptionService(); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java index 2c8fe79923..4d5e5763fd 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/ITPutSNS.java @@ -16,18 +16,18 @@ */ package org.apache.nifi.processors.aws.sns; -import static org.junit.Assert.assertTrue; +import org.apache.nifi.processors.aws.AbstractAWSCredentialsProviderProcessor; +import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; +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.processors.aws.AbstractAWSCredentialsProviderProcessor; -import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Provides integration level testing with actual AWS S3 resources for {@link PutSNS} and requires additional configuration and resources to work. diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java index 25cbde4bef..129e475825 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sns/TestPutSNS.java @@ -16,43 +16,39 @@ */ package org.apache.nifi.processors.aws.sns; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -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.mockito.ArgumentCaptor; -import org.mockito.Mockito; - import com.amazonaws.services.sns.AmazonSNSClient; import com.amazonaws.services.sns.model.AmazonSNSException; import com.amazonaws.services.sns.model.PublishRequest; import com.amazonaws.services.sns.model.PublishResult; +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.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Mockito; + +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.assertTrue; public class TestPutSNS { private TestRunner runner = null; private PutSNS mockPutSNS = null; - private AmazonSNSClient actualSNSClient = null; private AmazonSNSClient mockSNSClient = null; - @Before + @BeforeEach public void setUp() { mockSNSClient = Mockito.mock(AmazonSNSClient.class); mockPutSNS = new PutSNS() { @Override protected AmazonSNSClient getClient() { - actualSNSClient = client; return mockSNSClient; } }; @@ -60,7 +56,7 @@ public class TestPutSNS { } @Test - public void testPublish() throws IOException { + public void testPublish() { runner.setProperty(PutSNS.CREDENTIALS_FILE, "src/test/resources/mock-aws-credentials.properties"); runner.setProperty(PutSNS.ARN, "arn:aws:sns:us-west-2:123456789012:test-topic-1"); runner.setProperty(PutSNS.SUBJECT, "${eval.subject}"); @@ -90,7 +86,7 @@ public class TestPutSNS { } @Test - public void testPublishFIFO() throws IOException { + public void testPublishFIFO() { runner.setProperty(PutSNS.CREDENTIALS_FILE, "src/test/resources/mock-aws-credentials.properties"); runner.setProperty(PutSNS.ARN, "arn:aws:sns:us-west-2:123456789012:test-topic-1.fifo"); runner.setProperty(PutSNS.SUBJECT, "${eval.subject}"); @@ -125,7 +121,7 @@ public class TestPutSNS { } @Test - public void testPublishFailure() throws IOException { + public void testPublishFailure() { runner.setProperty(PutSNS.ARN, "arn:aws:sns:us-west-2:123456789012:test-topic-1"); final Map ffAttributes = new HashMap<>(); ffAttributes.put("filename", "1.txt"); @@ -138,5 +134,4 @@ public class TestPutSNS { Mockito.verify(mockSNSClient, Mockito.times(1)).publish(captureRequest.capture()); runner.assertAllFlowFilesTransferred(PutSNS.REL_FAILURE, 1); } - -} +} \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITDeleteSQS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITDeleteSQS.java index 04fa676661..301222488c 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITDeleteSQS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITDeleteSQS.java @@ -16,29 +16,24 @@ */ package org.apache.nifi.processors.aws.sqs; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - +import com.amazonaws.auth.PropertiesCredentials; import com.amazonaws.regions.Regions; +import com.amazonaws.services.sqs.AmazonSQSClient; import com.amazonaws.services.sqs.model.Message; import com.amazonaws.services.sqs.model.ReceiveMessageResult; import com.amazonaws.services.sqs.model.SendMessageResult; 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 com.amazonaws.auth.PropertiesCredentials; -import com.amazonaws.services.sqs.AmazonSQSClient; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.Assert.assertEquals; - - -@Ignore("For local testing only - interacts with S3 so the credentials file must be configured and all necessary queues created") public class ITDeleteSQS { private final String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; @@ -46,7 +41,7 @@ public class ITDeleteSQS { private final String TEST_REGION = "us-west-2"; AmazonSQSClient sqsClient = null; - @Before + @BeforeEach public void setUp() throws IOException { PropertiesCredentials credentials = new PropertiesCredentials(new File(CREDENTIALS_FILE)); sqsClient = new AmazonSQSClient(credentials); @@ -54,7 +49,7 @@ public class ITDeleteSQS { } @Test - public void testSimpleDelete() throws IOException { + public void testSimpleDelete() { // Setup - put one message in queue SendMessageResult sendMessageResult = sqsClient.sendMessage(TEST_QUEUE_URL, "Test message"); assertEquals(200, sendMessageResult.getSdkHttpMetadata().getHttpStatusCode()); @@ -79,5 +74,4 @@ public class ITDeleteSQS { runner.assertAllFlowFilesTransferred(DeleteSQS.REL_SUCCESS, 1); } - -} +} \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITGetSQS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITGetSQS.java index f59dfb4f24..7239feeb14 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITGetSQS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITGetSQS.java @@ -16,18 +16,16 @@ */ package org.apache.nifi.processors.aws.sqs; -import java.util.List; - import org.apache.nifi.processors.aws.AbstractAWSProcessor; import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; import org.apache.nifi.processors.aws.sns.PutSNS; 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 java.util.List; -@Ignore("For local testing only - interacts with S3 so the credentials file must be configured and all necessary buckets created") public class ITGetSQS { private final String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITPutSQS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITPutSQS.java index c7421aab51..2b54350c43 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITPutSQS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/ITPutSQS.java @@ -16,21 +16,20 @@ */ package org.apache.nifi.processors.aws.sqs; -import java.io.IOException; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - import com.amazonaws.regions.Regions; import org.apache.nifi.processors.aws.credentials.provider.factory.CredentialPropertyDescriptors; import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Assert; -import org.junit.Ignore; -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.jupiter.api.Assertions.assertTrue; -@Ignore("For local testing only - interacts with SQS so the credentials file must be configured and all necessary queues created") public class ITPutSQS { private final String CREDENTIALS_FILE = System.getProperty("user.home") + "/aws-credentials.properties"; @@ -46,7 +45,7 @@ public class ITPutSQS { runner.setProperty(PutSQS.CREDENTIALS_FILE, CREDENTIALS_FILE); runner.setProperty(PutSQS.REGION, REGION); runner.setProperty(PutSQS.QUEUE_URL, QUEUE_URL); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); final Map attrs = new HashMap<>(); attrs.put("filename", "1.txt"); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestDeleteSQS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestDeleteSQS.java index 2bd769e397..5ec7cffbac 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestDeleteSQS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestDeleteSQS.java @@ -16,24 +16,22 @@ */ package org.apache.nifi.processors.aws.sqs; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - import com.amazonaws.services.sqs.AmazonSQSClient; import com.amazonaws.services.sqs.model.AmazonSQSException; import com.amazonaws.services.sqs.model.DeleteMessageBatchRequest; import com.amazonaws.services.sqs.model.DeleteMessageBatchResult; - -import org.junit.Before; -import org.junit.Test; +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.mockito.ArgumentCaptor; import org.mockito.Mockito; -import static org.junit.Assert.assertEquals; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestDeleteSQS { @@ -42,7 +40,7 @@ public class TestDeleteSQS { private DeleteSQS mockDeleteSQS = null; private AmazonSQSClient mockSQSClient = null; - @Before + @BeforeEach public void setUp() { mockSQSClient = Mockito.mock(AmazonSQSClient.class); DeleteMessageBatchResult mockResponse = Mockito.mock(DeleteMessageBatchResult.class); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestGetSQS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestGetSQS.java index 1253e737ac..601318dd3c 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestGetSQS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestGetSQS.java @@ -16,40 +16,36 @@ */ package org.apache.nifi.processors.aws.sqs; -import java.util.List; - -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; - import com.amazonaws.services.sqs.AmazonSQSClient; import com.amazonaws.services.sqs.model.DeleteMessageBatchRequest; import com.amazonaws.services.sqs.model.Message; import com.amazonaws.services.sqs.model.MessageAttributeValue; import com.amazonaws.services.sqs.model.ReceiveMessageRequest; import com.amazonaws.services.sqs.model.ReceiveMessageResult; - -import org.junit.Before; -import org.junit.Test; +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 org.mockito.ArgumentCaptor; import org.mockito.Mockito; -import static org.junit.Assert.assertEquals; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestGetSQS { private TestRunner runner = null; private GetSQS mockGetSQS = null; - private AmazonSQSClient actualSQSClient = null; private AmazonSQSClient mockSQSClient = null; - @Before + @BeforeEach public void setUp() { mockSQSClient = Mockito.mock(AmazonSQSClient.class); mockGetSQS = new GetSQS() { protected AmazonSQSClient getClient() { - actualSQSClient = client; return mockSQSClient; } }; diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestPutSQS.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestPutSQS.java index 4226d5267d..257611fa18 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestPutSQS.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/sqs/TestPutSQS.java @@ -16,24 +16,22 @@ */ package org.apache.nifi.processors.aws.sqs; -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -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.mockito.ArgumentCaptor; -import org.mockito.Mockito; - import com.amazonaws.services.sqs.AmazonSQSClient; import com.amazonaws.services.sqs.model.AmazonSQSException; import com.amazonaws.services.sqs.model.SendMessageBatchRequest; import com.amazonaws.services.sqs.model.SendMessageBatchResult; +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.mockito.ArgumentCaptor; +import org.mockito.Mockito; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestPutSQS { @@ -43,7 +41,7 @@ public class TestPutSQS { private AmazonSQSClient actualSQSClient = null; private AmazonSQSClient mockSQSClient = null; - @Before + @BeforeEach public void setUp() { mockSQSClient = Mockito.mock(AmazonSQSClient.class); mockPutSQS = new PutSQS() { @@ -57,9 +55,9 @@ public class TestPutSQS { } @Test - public void testSimplePut() throws IOException { + public void testSimplePut() { runner.setProperty(PutSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000"); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); final Map attrs = new HashMap<>(); attrs.put("filename", "1.txt"); @@ -81,7 +79,7 @@ public class TestPutSQS { } @Test - public void testPutException() throws IOException { + public void testPutException() { runner.setProperty(PutSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000"); final Map attrs = new HashMap<>(); @@ -102,11 +100,11 @@ public class TestPutSQS { } @Test - public void testFIFOPut() throws IOException { + public void testFIFOPut() { runner.setProperty(PutSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000"); runner.setProperty(PutSQS.MESSAGEDEDUPLICATIONID, "${myuuid}"); runner.setProperty(PutSQS.MESSAGEGROUPID, "test1234"); - Assert.assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); + assertTrue(runner.setProperty("x-custom-prop", "hello").isValid()); final Map attrs = new HashMap<>(); attrs.put("filename", "1.txt"); @@ -129,5 +127,4 @@ public class TestPutSQS { runner.assertAllFlowFilesTransferred(PutSQS.REL_SUCCESS, 1); } - } diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAWSGatewayApiCommon.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAWSGatewayApiCommon.java index 4bcb0b2f93..ceb2eac4bd 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAWSGatewayApiCommon.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAWSGatewayApiCommon.java @@ -17,9 +17,18 @@ package org.apache.nifi.processors.aws.wag; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import okhttp3.mockwebserver.MockResponse; +import okhttp3.mockwebserver.MockWebServer; +import okhttp3.mockwebserver.RecordedRequest; +import org.apache.nifi.flowfile.attributes.CoreAttributes; +import org.apache.nifi.processors.aws.AbstractAWSCredentialsProviderProcessor; +import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; +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.junit.jupiter.api.Test; import java.io.IOException; import java.net.URL; @@ -29,21 +38,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import okhttp3.mockwebserver.MockResponse; -import okhttp3.mockwebserver.MockWebServer; -import okhttp3.mockwebserver.RecordedRequest; - -import org.apache.nifi.flowfile.attributes.CoreAttributes; -import org.apache.nifi.processors.aws.AbstractAWSCredentialsProviderProcessor; -import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderControllerService; -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.junit.Assert; -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 abstract class TestInvokeAWSGatewayApiCommon { @@ -555,7 +552,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_MESSAGE, "Internal Server Error"); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -586,7 +583,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_CODE, "302"); bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_MESSAGE, "Moved Temporarily"); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -617,7 +614,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_CODE, "304"); bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_MESSAGE, "Not Modified"); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -647,7 +644,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_CODE, "400"); bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_MESSAGE, "Bad Request"); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -678,7 +675,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_CODE, "400"); bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_MESSAGE, "Bad Request"); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -708,7 +705,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_CODE, "412"); bundle.assertAttributeEquals(InvokeAWSGatewayApi.STATUS_MESSAGE, "Precondition Failed"); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -747,7 +744,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle1.assertAttributeEquals("Foo", "Bar"); final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8); final String expected1 = ""; - Assert.assertEquals(expected1, actual1); + assertEquals(expected1, actual1); } @Test @@ -786,7 +783,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8); final String expected1 = ""; - Assert.assertEquals(expected1, actual1); + assertEquals(expected1, actual1); } @Test @@ -959,7 +956,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8); final String expected1 = ""; - Assert.assertEquals(expected1, actual1); + assertEquals(expected1, actual1); } @Test @@ -996,7 +993,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8); final String expected1 = ""; - Assert.assertEquals(expected1, actual1); + assertEquals(expected1, actual1); } @Test @@ -1088,7 +1085,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { bundle1.assertAttributeEquals("Foo", "Bar"); final String actual1 = new String(bundle1.toByteArray(), StandardCharsets.UTF_8); final String expected1 = ""; - Assert.assertEquals(expected1, actual1); + assertEquals(expected1, actual1); } @Test @@ -1191,7 +1188,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -1219,7 +1216,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -1246,7 +1243,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { final String actual = new String(bundle.toByteArray(), StandardCharsets.UTF_8); final String expected = "Hello"; - Assert.assertEquals(expected, actual); + assertEquals(expected, actual); bundle.assertAttributeEquals("Foo", "Bar"); } @@ -1278,6 +1275,7 @@ public abstract class TestInvokeAWSGatewayApiCommon { runner.setProperty(InvokeAWSGatewayApi.PROP_AWS_GATEWAY_API_ENDPOINT, "http://nifi.apache.org/"); runner.setProperty(InvokeAWSGatewayApi.PROP_RESOURCE_NAME, "/status/200"); runner.setProperty(InvokeAWSGatewayApi.PROXY_HOST, "${proxy.host}"); + runner.setProperty(InvokeAWSGatewayApi.PROXY_HOST_PORT, "${proxy.port}"); runner.setProperty(InvokeAWSGatewayApi.PROXY_USERNAME, "${proxy.username}"); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAmazonGatewayApiMock.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAmazonGatewayApiMock.java index 4ecd98f781..5b7927dd31 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAmazonGatewayApiMock.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAmazonGatewayApiMock.java @@ -33,8 +33,8 @@ import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredential 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.ByteArrayInputStream; @@ -52,7 +52,7 @@ public class TestInvokeAmazonGatewayApiMock { private TestRunner runner = null; private SdkHttpClient mockSdkClient = null; - @Before + @BeforeEach public void setUp() throws Exception { mockSdkClient = Mockito.mock(SdkHttpClient.class); ClientConfiguration clientConfig = new ClientConfiguration(); diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeInvokeAmazonGatewayApi.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeInvokeAmazonGatewayApi.java index 79b1249abd..9e80feeb10 100644 --- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeInvokeAmazonGatewayApi.java +++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeInvokeAmazonGatewayApi.java @@ -18,13 +18,13 @@ package org.apache.nifi.processors.aws.wag; import okhttp3.mockwebserver.MockWebServer; 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; public class TestInvokeInvokeAmazonGatewayApi extends TestInvokeAWSGatewayApiCommon { - @Before + @BeforeEach public void before() throws Exception { runner = TestRunners.newTestRunner(InvokeAWSGatewayApi.class); runner.setValidateExpressionUsage(false); @@ -32,7 +32,7 @@ public class TestInvokeInvokeAmazonGatewayApi extends TestInvokeAWSGatewayApiCom mockWebServer = new MockWebServer(); } - @After + @AfterEach public void after() { runner.shutdown(); } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-graph-authorizer/src/test/java/org/apache/nifi/authorization/azure/AzureGraphUserGroupProviderIT.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-graph-authorizer/src/test/java/org/apache/nifi/authorization/azure/AzureGraphUserGroupProviderIT.java index 8be6b30ff1..7049bc4cd5 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-graph-authorizer/src/test/java/org/apache/nifi/authorization/azure/AzureGraphUserGroupProviderIT.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-graph-authorizer/src/test/java/org/apache/nifi/authorization/azure/AzureGraphUserGroupProviderIT.java @@ -17,30 +17,31 @@ package org.apache.nifi.authorization.azure; -import static org.junit.Assert.fail; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.stream.Collectors; - import org.apache.nifi.authorization.AuthorizerConfigurationContext; import org.apache.nifi.authorization.Group; import org.apache.nifi.authorization.UserAndGroups; import org.apache.nifi.authorization.UserGroupProviderInitializationContext; import org.apache.nifi.util.MockPropertyValue; import org.apache.nifi.util.file.FileUtils; -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 org.mockito.Mockito; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +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 AzureGraphUserGroupProviderIT { private static final Logger logger = LoggerFactory.getLogger(AzureGraphUserGroupProviderIT.class); @@ -50,18 +51,11 @@ public class AzureGraphUserGroupProviderIT { static { CONFIG = new Properties(); - try { + assertDoesNotThrow(() -> { final FileInputStream fis = new FileInputStream(CREDENTIALS_FILE); - try { - CONFIG.load(fis); - } catch (IOException e) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); - } finally { - FileUtils.closeQuietly(fis); - } - } catch (FileNotFoundException e) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); - } + assertDoesNotThrow(() -> CONFIG.load(fis)); + FileUtils.closeQuietly(fis); + }); } protected static String getAuthorityEndpoint() { @@ -97,7 +91,7 @@ public class AzureGraphUserGroupProviderIT { private AzureGraphUserGroupProvider testingProvider; private UserGroupProviderInitializationContext initContext; - @Before + @BeforeEach public void setup() throws IOException { authContext = Mockito.mock(AuthorizerConfigurationContext.class); initContext = Mockito.mock(UserGroupProviderInitializationContext.class); @@ -126,7 +120,7 @@ public class AzureGraphUserGroupProviderIT { } - @After + @AfterEach public void tearDown() { testingProvider.preDestruction(); } @@ -138,11 +132,11 @@ public class AzureGraphUserGroupProviderIT { setupTestingProvider(); - Assert.assertTrue(testingProvider.getGroups().size() > 0); - Assert.assertTrue(testingProvider.getUsers().size() > 0); + assertTrue(testingProvider.getGroups().size() > 0); + assertTrue(testingProvider.getUsers().size() > 0); UserAndGroups uag = testingProvider.getUserAndGroups(getKnownTestUserName()); - Assert.assertNotNull(uag.getUser()); - Assert.assertTrue(uag.getGroups().size() > 0); + assertNotNull(uag.getUser()); + assertTrue(uag.getGroups().size() > 0); } @@ -155,15 +149,15 @@ public class AzureGraphUserGroupProviderIT { setupTestingProvider(); - Assert.assertTrue(testingProvider.getGroups().size() > 0); - Assert.assertTrue(testingProvider.getUsers().size() > 0); + assertTrue(testingProvider.getGroups().size() > 0); + assertTrue(testingProvider.getUsers().size() > 0); UserAndGroups uag = testingProvider.getUserAndGroups(getKnownTestUserName()); - Assert.assertNotNull(uag.getUser()); - Assert.assertTrue(uag.getGroups().size() > 0); + assertNotNull(uag.getUser()); + assertTrue(uag.getGroups().size() > 0); String knownGroupName = getKnownTestGroupName(); List search = testingProvider.getGroups().stream().filter(g-> g.getName().equals(knownGroupName)).collect(Collectors.toList()); - Assert.assertTrue(search.size() > 0); + assertTrue(search.size() > 0); } @Test @@ -175,9 +169,9 @@ public class AzureGraphUserGroupProviderIT { .thenReturn(new MockPropertyValue(prefix)); setupTestingProvider(); - Assert.assertTrue(testingProvider.getGroups().size() > 0); + assertTrue(testingProvider.getGroups().size() > 0); List search = testingProvider.getGroups().stream().filter(g-> g.getName().equals(knownGroupName)).collect(Collectors.toList()); - Assert.assertTrue(search.size() > 0); + assertTrue(search.size() > 0); } @Test @@ -189,9 +183,9 @@ public class AzureGraphUserGroupProviderIT { .thenReturn(new MockPropertyValue(suffix)); setupTestingProvider(); - Assert.assertTrue(testingProvider.getGroups().size() > 0); + assertTrue(testingProvider.getGroups().size() > 0); List search = testingProvider.getGroups().stream().filter(g-> g.getName().equals(knownGroupName)).collect(Collectors.toList()); - Assert.assertTrue(search.size() > 0); + assertTrue(search.size() > 0); } @Test @@ -203,9 +197,9 @@ public class AzureGraphUserGroupProviderIT { .thenReturn(new MockPropertyValue(substring)); setupTestingProvider(); - Assert.assertTrue(testingProvider.getGroups().size() > 0); + assertTrue(testingProvider.getGroups().size() > 0); List search = testingProvider.getGroups().stream().filter( g-> g.getName().equals(knownGroupName)).collect(Collectors.toList()); - Assert.assertTrue(search.size() > 0); + assertTrue(search.size() > 0); } @Test @@ -219,9 +213,9 @@ public class AzureGraphUserGroupProviderIT { .thenReturn(new MockPropertyValue(getGroupListInclusion())); setupTestingProvider(); - Assert.assertTrue(testingProvider.getGroups().size() > 0); + assertTrue(testingProvider.getGroups().size() > 0); Set search = testingProvider.getGroups().stream().collect(Collectors.toSet()); // check there is no duplicate group - Assert.assertEquals(search.size(), testingProvider.getGroups().size()); + assertEquals(search.size(), testingProvider.getGroups().size()); } } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITAbstractAzureCosmosDBDocument.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITAbstractAzureCosmosDBDocument.java index 06bc335681..e2165a2a01 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITAbstractAzureCosmosDBDocument.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITAbstractAzureCosmosDBDocument.java @@ -16,15 +16,6 @@ */ package org.apache.nifi.processors.azure.cosmos.document; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; -import java.util.logging.Logger; - import com.azure.cosmos.CosmosClient; import com.azure.cosmos.CosmosClientBuilder; import com.azure.cosmos.CosmosContainer; @@ -38,15 +29,21 @@ import com.azure.cosmos.models.CosmosQueryRequestOptions; import com.azure.cosmos.models.PartitionKey; import com.azure.cosmos.util.CosmosPagedIterable; import com.fasterxml.jackson.databind.JsonNode; - import org.apache.nifi.processor.Processor; import org.apache.nifi.services.azure.cosmos.document.AzureCosmosDBClientService; 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.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; + +import java.io.FileInputStream; +import java.util.Properties; +import java.util.logging.Logger; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertNotNull; public abstract class ITAbstractAzureCosmosDBDocument { static Logger logger = Logger.getLogger(ITAbstractAzureCosmosDBDocument.class.getName()); @@ -62,20 +59,13 @@ public abstract class ITAbstractAzureCosmosDBDocument { protected static CosmosContainer container; static { - final FileInputStream fis; + CONFIG = new Properties(); - try { - fis = new FileInputStream(CREDENTIALS_FILE); - try { - CONFIG.load(fis); - } catch (IOException e) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); - } finally { - FileUtils.closeQuietly(fis); - } - } catch (FileNotFoundException e) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); - } + assertDoesNotThrow(() -> { + final FileInputStream fis = new FileInputStream(CREDENTIALS_FILE); + assertDoesNotThrow(() -> CONFIG.load(fis)); + FileUtils.closeQuietly(fis); + }); } protected static String getComosURI() { @@ -88,7 +78,7 @@ public abstract class ITAbstractAzureCosmosDBDocument { protected TestRunner runner; - @BeforeClass + @BeforeAll public static void createTestDBContainerIfNeeded() throws CosmosException { final String testDBURI = getComosURI(); final String testDBContainer = getCosmosKey(); @@ -107,7 +97,7 @@ public abstract class ITAbstractAzureCosmosDBDocument { assertNotNull(container); } - @AfterClass + @AfterAll public static void dropTestDBAndContainer() throws CosmosException { resetTestCosmosConnection(); if (container != null) { @@ -139,7 +129,7 @@ public abstract class ITAbstractAzureCosmosDBDocument { } } - @Before + @BeforeEach public void setUpCosmosIT() { final String testDBURI = getComosURI(); final String testDBContainer = getCosmosKey(); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITPutAzureCosmosDBRecord.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITPutAzureCosmosDBRecord.java index 242827c09e..3b80b87a4e 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITPutAzureCosmosDBRecord.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/ITPutAzureCosmosDBRecord.java @@ -16,17 +16,9 @@ */ package org.apache.nifi.processors.azure.cosmos.document; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.logging.Logger; - import com.azure.cosmos.models.CosmosQueryRequestOptions; import com.azure.cosmos.util.CosmosPagedIterable; import com.fasterxml.jackson.databind.JsonNode; - import org.apache.nifi.processor.Processor; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.serialization.SimpleRecordSchema; @@ -35,9 +27,16 @@ import org.apache.nifi.serialization.record.MockRecordParser; import org.apache.nifi.serialization.record.RecordField; import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordSchema; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.logging.Logger; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ITPutAzureCosmosDBRecord extends ITAbstractAzureCosmosDBDocument { static Logger logger = Logger.getLogger(ITPutAzureCosmosDBRecord.class.getName()); @@ -47,12 +46,12 @@ public class ITPutAzureCosmosDBRecord extends ITAbstractAzureCosmosDBDocument { return PutAzureCosmosDBRecord.class; } - @Before + @BeforeEach public void setUp() throws Exception { resetTestCosmosConnection(); } - @After + @AfterEach public void cleanupTestCase() { try{ clearTestData(); @@ -159,7 +158,4 @@ public class ITPutAzureCosmosDBRecord extends ITAbstractAzureCosmosDBDocument { runner.assertAllFlowFilesTransferred(PutAzureCosmosDBRecord.REL_SUCCESS, 1); assertEquals(5, getDataFromTestDB().size()); } - - - } \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/MockTestBase.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/MockTestBase.java index ca1414b261..c09fdca2f2 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/MockTestBase.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/MockTestBase.java @@ -17,17 +17,16 @@ package org.apache.nifi.processors.azure.cosmos.document; -import static org.mockito.Mockito.mock; - -import java.util.Random; - import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosClient; - import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.services.azure.cosmos.document.AzureCosmosDBClientService; import org.apache.nifi.util.TestRunner; +import java.util.Random; + +import static org.mockito.Mockito.mock; + public class MockTestBase { protected static final String MOCK_DB_NAME = "MOCK_DB_NAME"; diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/PutAzureCosmosDBRecordTest.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/PutAzureCosmosDBRecordTest.java index 4a6b8a8ef8..55ead1ad00 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/PutAzureCosmosDBRecordTest.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/cosmos/document/PutAzureCosmosDBRecordTest.java @@ -16,17 +16,6 @@ */ package org.apache.nifi.processors.azure.cosmos.document; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.mock; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - import com.azure.cosmos.ConsistencyLevel; import com.azure.cosmos.CosmosClient; import com.azure.cosmos.CosmosContainer; @@ -35,7 +24,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - +import net.minidev.json.JSONObject; import org.apache.avro.Schema; import org.apache.nifi.avro.AvroTypeUtil; import org.apache.nifi.json.JsonTreeReader; @@ -50,10 +39,20 @@ 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.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +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.mockito.Mockito.mock; -import net.minidev.json.JSONObject; public class PutAzureCosmosDBRecordTest extends MockTestBase { private MockPutAzureCosmosDBRecord processor; @@ -69,7 +68,7 @@ public class PutAzureCosmosDBRecordTest extends MockTestBase { } - @Before + @BeforeEach public void setUp() throws Exception { processor = new MockPutAzureCosmosDBRecord(); testRunner = TestRunners.newTestRunner(processor); @@ -287,8 +286,4 @@ class MockPutAzureCosmosDBRecord extends PutAzureCosmosDBRecord { public CosmosContainer getMockConainer() { return mockContainer; } - - - - } \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/GetAzureEventHubTest.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/GetAzureEventHubTest.java index b33bc6f4fd..a581f9155e 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/GetAzureEventHubTest.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/GetAzureEventHubTest.java @@ -18,9 +18,16 @@ package org.apache.nifi.processors.azure.eventhub; import com.microsoft.azure.eventhubs.EventData; import com.microsoft.azure.eventhubs.EventData.SystemProperties; -import com.microsoft.azure.eventhubs.PartitionReceiver; import com.microsoft.azure.eventhubs.EventHubException; +import com.microsoft.azure.eventhubs.PartitionReceiver; import com.microsoft.azure.eventhubs.impl.AmqpConstants; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.exception.ProcessException; +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.time.Clock; @@ -32,13 +39,7 @@ import java.util.LinkedList; import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledExecutorService; -import org.apache.nifi.processor.ProcessContext; -import org.apache.nifi.processor.exception.ProcessException; -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.assertThrows; public class GetAzureEventHubTest { private static final String namespaceName = "nifi-azure-hub"; @@ -53,7 +54,7 @@ public class GetAzureEventHubTest { private TestRunner testRunner; private MockGetAzureEventHub processor; - @Before + @BeforeEach public void setUp() throws Exception { processor = new MockGetAzureEventHub(); testRunner = TestRunners.newTestRunner(processor); @@ -119,11 +120,11 @@ public class GetAzureEventHubTest { testRunner.clearTransferState(); } - @Test(expected = AssertionError.class) + @Test//(expected = AssertionError.class) public void testThrowGetReceiver(){ setUpStandardTestConfig(); processor.getReceiverThrow = true; - testRunner.run(1, true); + assertThrows(AssertionError.class, () -> testRunner.run(1, true)); testRunner.assertAllFlowFilesTransferred(GetAzureEventHub.REL_SUCCESS, 0); testRunner.clearTransferState(); } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/PutAzureEventHubTest.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/PutAzureEventHubTest.java index 3b7b04f186..d83aae4813 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/PutAzureEventHubTest.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/PutAzureEventHubTest.java @@ -16,19 +16,24 @@ */ package org.apache.nifi.processors.azure.eventhub; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import com.microsoft.azure.eventhubs.EventData; +import com.microsoft.azure.eventhubs.EventHubClient; +import org.apache.nifi.flowfile.FlowFile; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.ProcessSession; +import org.apache.nifi.processor.Relationship; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.processors.azure.storage.utils.FlowFileResultCarrier; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.StopWatch; +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.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.Collections; @@ -41,25 +46,20 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; -import org.apache.nifi.flowfile.FlowFile; -import org.apache.nifi.processor.ProcessContext; -import org.apache.nifi.processor.ProcessSession; -import org.apache.nifi.processor.Relationship; -import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.processors.azure.storage.utils.FlowFileResultCarrier; -import org.apache.nifi.util.StopWatch; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; - -import com.microsoft.azure.eventhubs.EventData; -import com.microsoft.azure.eventhubs.EventHubClient; +import static org.junit.jupiter.api.Assertions.assertFalse; +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.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class PutAzureEventHubTest { private static final String namespaceName = "nifi-azure-hub"; @@ -73,7 +73,7 @@ public class PutAzureEventHubTest { private TestRunner testRunner; private PutAzureEventHubTest.MockPutAzureEventHub processor; - @Before + @BeforeEach public void setUp() throws Exception { processor = new PutAzureEventHubTest.MockPutAzureEventHub(); testRunner = TestRunners.newTestRunner(processor); @@ -131,12 +131,12 @@ public class PutAzureEventHubTest { testRunner.clearTransferState(); } - @Test(expected = AssertionError.class) + @Test public void testBadConnectionString() { PutAzureEventHubTest.BogusConnectionStringMockPutAzureEventHub badConnectionStringProcessor = new PutAzureEventHubTest.BogusConnectionStringMockPutAzureEventHub(); testRunner = TestRunners.newTestRunner(badConnectionStringProcessor); setUpStandardTestConfig(); - testRunner.run(1, true); + assertThrows(AssertionError.class, () -> testRunner.run(1, true)); } @Test diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java index aef8b4a091..659e9a6f9a 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/eventhub/TestConsumeAzureEventHub.java @@ -33,6 +33,8 @@ import org.apache.nifi.serialization.RecordSetWriterFactory; import org.apache.nifi.serialization.SimpleRecordSchema; import org.apache.nifi.serialization.WriteResult; import org.apache.nifi.serialization.record.MapRecord; +import org.apache.nifi.serialization.record.MockRecordParser; +import org.apache.nifi.serialization.record.MockRecordWriter; import org.apache.nifi.serialization.record.Record; import org.apache.nifi.serialization.record.RecordField; import org.apache.nifi.serialization.record.RecordFieldType; @@ -42,8 +44,8 @@ import org.apache.nifi.util.MockProcessSession; import org.apache.nifi.util.SharedSessionState; 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; @@ -60,15 +62,13 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.apache.nifi.serialization.record.MockRecordParser; -import org.apache.nifi.serialization.record.MockRecordWriter; public class TestConsumeAzureEventHub { private static final String namespaceName = "nifi-azure-hub"; @@ -85,7 +85,7 @@ public class TestConsumeAzureEventHub { private PartitionContext partitionContext; private ConsumeAzureEventHub processor; - @Before + @BeforeEach public void setupProcessor() { processor = new ConsumeAzureEventHub(); final ProcessorInitializationContext initContext = Mockito.mock(ProcessorInitializationContext.class); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureBlobStorageIT.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureBlobStorageIT.java index 8e0facaa66..93cd8bd206 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureBlobStorageIT.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureBlobStorageIT.java @@ -20,8 +20,8 @@ import com.microsoft.azure.storage.blob.CloudBlob; import com.microsoft.azure.storage.blob.CloudBlobClient; import com.microsoft.azure.storage.blob.CloudBlobContainer; import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -43,7 +43,7 @@ public abstract class AbstractAzureBlobStorageIT extends AbstractAzureStorageIT return DEFAULT_BLOB_ENDPOINT_SUFFIX; } - @Before + @BeforeEach public void setUpAzureBlobStorageIT() throws Exception { String containerName = String.format("%s-%s", TEST_CONTAINER_NAME_PREFIX, UUID.randomUUID()); CloudBlobClient blobClient = getStorageAccount().createCloudBlobClient(); @@ -53,7 +53,7 @@ public abstract class AbstractAzureBlobStorageIT extends AbstractAzureStorageIT runner.setProperty(AzureStorageUtils.CONTAINER, containerName); } - @After + @AfterEach public void tearDownAzureBlobStorageIT() throws Exception { container.deleteIfExists(); } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureDataLakeStorageIT.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureDataLakeStorageIT.java index 383ab1686f..6240a5cce7 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureDataLakeStorageIT.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureDataLakeStorageIT.java @@ -27,8 +27,8 @@ import org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor; import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; import org.apache.nifi.services.azure.storage.ADLSCredentialsControllerService; import org.apache.nifi.services.azure.storage.ADLSCredentialsService; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.io.ByteArrayInputStream; import java.util.UUID; @@ -60,7 +60,7 @@ public abstract class AbstractAzureDataLakeStorageIT extends AbstractAzureStorag runner.setProperty(AbstractAzureDataLakeStorageProcessor.ADLS_CREDENTIALS_SERVICE, "ADLSCredentials"); } - @Before + @BeforeEach public void setUpAzureDataLakeStorageIT() { fileSystemName = String.format("%s-%s", FILESYSTEM_NAME_PREFIX, UUID.randomUUID()); @@ -70,7 +70,7 @@ public abstract class AbstractAzureDataLakeStorageIT extends AbstractAzureStorag fileSystemClient = storageClient.createFileSystem(fileSystemName); } - @After + @AfterEach public void tearDownAzureDataLakeStorageIT() { fileSystemClient.delete(); } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureStorageIT.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureStorageIT.java index be37c04b59..6dc3bd873a 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureStorageIT.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/AbstractAzureStorageIT.java @@ -26,15 +26,13 @@ import org.apache.nifi.services.azure.storage.AzureStorageCredentialsService; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.file.FileUtils; -import org.junit.Before; + import org.junit.jupiter.api.BeforeEach; import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; import java.util.Properties; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; public abstract class AbstractAzureStorageIT { @@ -44,18 +42,11 @@ public abstract class AbstractAzureStorageIT { static { CONFIG = new Properties(); - try { + assertDoesNotThrow(() -> { final FileInputStream fis = new FileInputStream(CREDENTIALS_FILE); - try { - CONFIG.load(fis); - } catch (IOException e) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); - } finally { - FileUtils.closeQuietly(fis); - } - } catch (FileNotFoundException e) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); - } + assertDoesNotThrow(() -> CONFIG.load(fis)); + FileUtils.closeQuietly(fis); + }); } protected String getAccountName() { @@ -75,7 +66,6 @@ public abstract class AbstractAzureStorageIT { protected TestRunner runner; - @Before @BeforeEach public void setUpAzureStorageIT() throws Exception { runner = TestRunners.newTestRunner(getProcessorClass()); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITAzureBlobStorageE2E.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITAzureBlobStorageE2E.java index bdf768783a..ce1600ba4b 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITAzureBlobStorageE2E.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITAzureBlobStorageE2E.java @@ -29,19 +29,19 @@ 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.Before; -import org.junit.ComparisonFailure; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.IOException; import java.util.Properties; import java.util.UUID; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; public class ITAzureBlobStorageE2E { @@ -53,13 +53,9 @@ public class ITAzureBlobStorageE2E { CONFIG = new Properties(); try { final FileInputStream fis = new FileInputStream(CREDENTIALS_FILE); - try { - CONFIG.load(fis); - } catch (IOException e) { - fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); - } finally { - FileUtils.closeQuietly(fis); - } + assertDoesNotThrow(() -> CONFIG.load(fis), + "Could not open credentials file " + CREDENTIALS_FILE); + FileUtils.closeQuietly(fis); } catch (FileNotFoundException e) { fail("Could not open credentials file " + CREDENTIALS_FILE + ": " + e.getLocalizedMessage()); } @@ -91,7 +87,7 @@ public class ITAzureBlobStorageE2E { protected CloudBlobContainer container; - @Before + @BeforeEach public void setupRunners() throws Exception { putRunner = TestRunners.newTestRunner(new PutAzureBlobStorage()); listRunner = TestRunners.newTestRunner(new ListAzureBlobStorage()); @@ -117,7 +113,7 @@ public class ITAzureBlobStorageE2E { runner.setProperty(AzureStorageUtils.CONTAINER, containerName); } - @After + @AfterEach public void tearDownAzureContainer() throws Exception { container.deleteIfExists(); } @@ -188,15 +184,15 @@ public class ITAzureBlobStorageE2E { ); } - @Test(expected = ComparisonFailure.class) - public void AzureBlobStorageE2E128BCSENoDecryption() throws Exception { - testE2E(AzureBlobClientSideEncryptionMethod.SYMMETRIC.name(), + @Test + public void AzureBlobStorageE2E128BCSENoDecryption() { + assertThrows(Exception.class, () -> testE2E(AzureBlobClientSideEncryptionMethod.SYMMETRIC.name(), KEY_ID_VALUE, KEY_128B_VALUE, AzureBlobClientSideEncryptionMethod.NONE.name(), KEY_ID_VALUE, KEY_128B_VALUE - ); + )); } private void testE2E(String encryptionKeyType, String encryptionKeyId, String encryptionKeyHex, String decryptionKeyType, String decryptionKeyId, String decryptionKeyHex) throws Exception { diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureBlobStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureBlobStorage.java index 0143b41c7e..26b8fea1bf 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureBlobStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureBlobStorage.java @@ -18,10 +18,10 @@ package org.apache.nifi.processors.azure.storage; import com.microsoft.azure.storage.blob.ListBlobItem; import org.apache.nifi.processor.Processor; -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.jupiter.api.Assertions.assertFalse; public class ITDeleteAzureBlobStorage extends AbstractAzureBlobStorageIT { @@ -30,7 +30,7 @@ public class ITDeleteAzureBlobStorage extends AbstractAzureBlobStorageIT { return DeleteAzureBlobStorage.class; } - @Before + @BeforeEach public void setUp() throws Exception { runner.setProperty(DeleteAzureBlobStorage.BLOB, TEST_BLOB_NAME); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureDataLakeStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureDataLakeStorage.java index 3b032372ab..ac6c75a29d 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureDataLakeStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITDeleteAzureDataLakeStorage.java @@ -23,7 +23,7 @@ import org.apache.nifi.processor.Processor; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.provenance.ProvenanceEventType; import org.apache.nifi.util.MockFlowFile; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; @@ -31,9 +31,9 @@ import java.util.Map; import static org.apache.nifi.processors.azure.storage.DeleteAzureDataLakeStorage.FS_TYPE_DIRECTORY; import static org.apache.nifi.processors.azure.storage.DeleteAzureDataLakeStorage.FS_TYPE_FILE; -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; public class ITDeleteAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureBlobStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureBlobStorage.java index 2acda67b86..cd7e062901 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureBlobStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureBlobStorage.java @@ -19,8 +19,8 @@ package org.apache.nifi.processors.azure.storage; import org.apache.nifi.processor.Processor; import org.apache.nifi.processors.azure.AbstractAzureBlobProcessor; import org.apache.nifi.util.MockFlowFile; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; @@ -31,7 +31,7 @@ public class ITFetchAzureBlobStorage extends AbstractAzureBlobStorageIT { return FetchAzureBlobStorage.class; } - @Before + @BeforeEach public void setUp() throws Exception { runner.setProperty(FetchAzureBlobStorage.BLOB, TEST_BLOB_NAME); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureDataLakeStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureDataLakeStorage.java index c7c4b9dbf4..1b665d4109 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureDataLakeStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITFetchAzureDataLakeStorage.java @@ -22,7 +22,7 @@ import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; import org.apache.nifi.util.MockFlowFile; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -33,7 +33,7 @@ import java.util.Random; import java.util.Set; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ITFetchAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureBlobStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureBlobStorage.java index 49365b5535..484d4953a4 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureBlobStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureBlobStorage.java @@ -18,8 +18,9 @@ package org.apache.nifi.processors.azure.storage; import org.apache.nifi.processor.Processor; import org.apache.nifi.util.MockFlowFile; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import java.util.concurrent.TimeUnit; public class ITListAzureBlobStorage extends AbstractAzureBlobStorageIT { @@ -29,7 +30,7 @@ public class ITListAzureBlobStorage extends AbstractAzureBlobStorageIT { return ListAzureBlobStorage.class; } - @Before + @BeforeEach public void setUp() throws Exception { uploadTestBlob(); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureDataLakeStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureDataLakeStorage.java index fd308bc331..a60403b48f 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureDataLakeStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITListAzureDataLakeStorage.java @@ -21,8 +21,8 @@ import org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.serialization.record.MockRecordWriter; import org.apache.nifi.util.MockFlowFile; -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.HashMap; @@ -36,8 +36,8 @@ import static org.apache.nifi.processors.azure.storage.utils.ADLSAttributes.ATTR import static org.apache.nifi.processors.azure.storage.utils.ADLSAttributes.ATTR_NAME_FILE_PATH; import static org.apache.nifi.processors.azure.storage.utils.ADLSAttributes.ATTR_NAME_LAST_MODIFIED; import static org.apache.nifi.processors.azure.storage.utils.ADLSAttributes.ATTR_NAME_LENGTH; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ITListAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { @@ -48,7 +48,7 @@ public class ITListAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { return ListAzureDataLakeStorage.class; } - @Before + @BeforeEach public void setUp() { testFiles = new HashMap<>(); @@ -241,7 +241,7 @@ public class ITListAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { for (MockFlowFile flowFile : flowFiles) { String filePath = flowFile.getAttribute("azure.filePath"); TestFile testFile = expectedFiles.remove(filePath); - assertNotNull("File path not found in the expected map", testFile); + assertNotNull(testFile, "File path not found in the expected map"); assertFlowFile(testFile, flowFile); } } @@ -263,5 +263,4 @@ public class ITListAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { assertFalse(runner.getLogger().getErrorMessages().isEmpty()); runner.assertTransferCount(ListAzureDataLakeStorage.REL_SUCCESS, 0); } - } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureBlobStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureBlobStorage.java index 85644d48a8..8a1a2190c8 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureBlobStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureBlobStorage.java @@ -22,12 +22,12 @@ import org.apache.nifi.processors.azure.storage.utils.AzureBlobClientSideEncrypt import org.apache.nifi.processors.azure.storage.utils.AzureBlobClientSideEncryptionUtils; import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; import org.apache.nifi.util.MockFlowFile; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ITPutAzureBlobStorage extends AbstractAzureBlobStorageIT { @@ -46,7 +46,7 @@ public class ITPutAzureBlobStorage extends AbstractAzureBlobStorageIT { return PutAzureBlobStorage.class; } - @Before + @BeforeEach public void setUp() { runner.setProperty(PutAzureBlobStorage.BLOB, TEST_BLOB_NAME); } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureDataLakeStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureDataLakeStorage.java index 093a82b30c..81d7245dd5 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureDataLakeStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/ITPutAzureDataLakeStorage.java @@ -23,8 +23,8 @@ import org.apache.nifi.processor.Processor; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventType; import org.apache.nifi.util.MockFlowFile; -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.util.Collections; @@ -40,6 +40,7 @@ import static org.apache.nifi.processors.azure.storage.utils.ADLSAttributes.ATTR import static org.apache.nifi.processors.azure.storage.utils.ADLSAttributes.ATTR_NAME_LENGTH; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doThrow; @@ -61,7 +62,7 @@ public class ITPutAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { return PutAzureDataLakeStorage.class; } - @Before + @BeforeEach public void setUp() { runner.setProperty(PutAzureDataLakeStorage.DIRECTORY, DIRECTORY); runner.setProperty(PutAzureDataLakeStorage.FILE, FILE_NAME); @@ -241,15 +242,17 @@ public class ITPutAzureDataLakeStorage extends AbstractAzureDataLakeStorageIT { assertFailure(); } - @Test(expected = NullPointerException.class) + @Test public void testPutFileButFailedToAppend() { DataLakeFileClient fileClient = mock(DataLakeFileClient.class); InputStream stream = mock(InputStream.class); doThrow(NullPointerException.class).when(fileClient).append(any(InputStream.class), anyLong(), anyLong()); - PutAzureDataLakeStorage.uploadContent(fileClient, stream, FILE_DATA.length); + assertThrows(NullPointerException.class, () -> { + PutAzureDataLakeStorage.uploadContent(fileClient, stream, FILE_DATA.length); - verify(fileClient).delete(); + verify(fileClient).delete(); + }); } private Map createAttributesMap() { diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestAbstractAzureDataLakeStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestAbstractAzureDataLakeStorage.java index a4a4c64788..4bf683fb20 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestAbstractAzureDataLakeStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestAbstractAzureDataLakeStorage.java @@ -16,6 +16,12 @@ */ package org.apache.nifi.processors.azure.storage; +import org.apache.nifi.services.azure.storage.ADLSCredentialsService; +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 static org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.ADLS_CREDENTIALS_SERVICE; import static org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.DIRECTORY; import static org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProcessor.FILE; @@ -23,17 +29,11 @@ import static org.apache.nifi.processors.azure.AbstractAzureDataLakeStorageProce import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import org.apache.nifi.services.azure.storage.ADLSCredentialsService; -import org.apache.nifi.util.TestRunner; -import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; - public class TestAbstractAzureDataLakeStorage { private TestRunner runner; - @Before + @BeforeEach public void setUp() throws Exception { // test the property validation in the abstract class via the put processor runner = TestRunners.newTestRunner(PutAzureDataLakeStorage.class); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestPutAzureBlobStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestPutAzureBlobStorage.java index bd3f22277e..c139b04460 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestPutAzureBlobStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/TestPutAzureBlobStorage.java @@ -19,7 +19,7 @@ package org.apache.nifi.processors.azure.storage; import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/AbstractAzureQueueStorageIT.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/AbstractAzureQueueStorageIT.java index d1e3937431..418ce45d80 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/AbstractAzureQueueStorageIT.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/AbstractAzureQueueStorageIT.java @@ -20,8 +20,8 @@ import com.microsoft.azure.storage.queue.CloudQueue; import com.microsoft.azure.storage.queue.CloudQueueClient; import com.microsoft.azure.storage.queue.CloudQueueMessage; import org.apache.nifi.processors.azure.storage.AbstractAzureStorageIT; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.util.Iterator; import java.util.UUID; @@ -39,7 +39,7 @@ public abstract class AbstractAzureQueueStorageIT extends AbstractAzureStorageIT return DEFAULT_QUEUE_ENDPOINT_SUFFIX; } - @Before + @BeforeEach public void setUpAzureQueueStorageIT() throws Exception { String queueName = String.format("%s-%s", TEST_QUEUE_NAME_PREFIX, UUID.randomUUID()); CloudQueueClient cloudQueueClient = getStorageAccount().createCloudQueueClient(); @@ -49,7 +49,7 @@ public abstract class AbstractAzureQueueStorageIT extends AbstractAzureStorageIT runner.setProperty(AbstractAzureQueueStorage.QUEUE, queueName); } - @After + @AfterEach public void tearDownAzureQueueStorageIT() throws Exception { cloudQueue.deleteIfExists(); } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/GetAzureQueueStorageIT.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/GetAzureQueueStorageIT.java index 0890e74c56..e85e0cdbb3 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/GetAzureQueueStorageIT.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/GetAzureQueueStorageIT.java @@ -16,17 +16,17 @@ */ package org.apache.nifi.processors.azure.storage.queue; -import java.util.List; - import com.microsoft.azure.storage.StorageException; import com.microsoft.azure.storage.queue.CloudQueueMessage; - import org.apache.nifi.processor.Processor; import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; import org.apache.nifi.util.MockFlowFile; -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.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class GetAzureQueueStorageIT extends AbstractAzureQueueStorageIT { @@ -35,7 +35,7 @@ public class GetAzureQueueStorageIT extends AbstractAzureQueueStorageIT { return GetAzureQueueStorage.class; } - @Before + @BeforeEach public void setUp() throws StorageException { cloudQueue.addMessage(new CloudQueueMessage("Dummy Message 1"), 604800, 0, null, null); cloudQueue.addMessage(new CloudQueueMessage("Dummy Message 2"), 604800, 0, null, null); @@ -105,10 +105,10 @@ public class GetAzureQueueStorageIT extends AbstractAzureQueueStorageIT { runner.run(1); runner.assertAllFlowFilesTransferred(GetAzureQueueStorage.REL_SUCCESS, 3); - Assert.assertEquals(0, getMessageCount()); + assertEquals(0, getMessageCount()); Thread.sleep(1500); - Assert.assertEquals(3, getMessageCount()); + assertEquals(3, getMessageCount()); } @Test @@ -120,13 +120,13 @@ public class GetAzureQueueStorageIT extends AbstractAzureQueueStorageIT { runner.assertAllFlowFilesTransferred(GetAzureQueueStorage.REL_SUCCESS, 2); cloudQueue.downloadAttributes(); - Assert.assertEquals(1, cloudQueue.getApproximateMessageCount()); + assertEquals(1, cloudQueue.getApproximateMessageCount()); runner.run(1); runner.assertAllFlowFilesTransferred(GetAzureQueueStorage.REL_SUCCESS, 3); cloudQueue.downloadAttributes(); - Assert.assertEquals(0, cloudQueue.getApproximateMessageCount()); + assertEquals(0, cloudQueue.getApproximateMessageCount()); } private void assertResult(int expectedMessageCountInQueue) throws Exception { @@ -139,6 +139,6 @@ public class GetAzureQueueStorageIT extends AbstractAzureQueueStorageIT { } cloudQueue.downloadAttributes(); - Assert.assertEquals(expectedMessageCountInQueue, cloudQueue.getApproximateMessageCount()); + assertEquals(expectedMessageCountInQueue, cloudQueue.getApproximateMessageCount()); } } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/PutAzureQueueStorageIT.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/PutAzureQueueStorageIT.java index 7d6fe9d9cc..8e553651bc 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/PutAzureQueueStorageIT.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/PutAzureQueueStorageIT.java @@ -18,8 +18,9 @@ package org.apache.nifi.processors.azure.storage.queue; import org.apache.nifi.processor.Processor; import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class PutAzureQueueStorageIT extends AbstractAzureQueueStorageIT { @@ -76,10 +77,10 @@ public class PutAzureQueueStorageIT extends AbstractAzureQueueStorageIT { runner.run(1); runner.assertAllFlowFilesTransferred(PutAzureQueueStorage.REL_SUCCESS, 1); - Assert.assertEquals(1, getMessageCount()); + assertEquals(1, getMessageCount()); Thread.sleep(2400); - Assert.assertEquals(0, getMessageCount()); + assertEquals(0, getMessageCount()); } @Test @@ -91,9 +92,9 @@ public class PutAzureQueueStorageIT extends AbstractAzureQueueStorageIT { runner.run(1); runner.assertAllFlowFilesTransferred(PutAzureQueueStorage.REL_SUCCESS, 1); - Assert.assertEquals(0, getMessageCount()); + assertEquals(0, getMessageCount()); Thread.sleep(2400); - Assert.assertEquals(1, getMessageCount()); + assertEquals(1, getMessageCount()); } } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestGetAzureQueueStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestGetAzureQueueStorage.java index aba779cce3..169f5720e9 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestGetAzureQueueStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestGetAzureQueueStorage.java @@ -22,13 +22,15 @@ import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestGetAzureQueueStorage { private final TestRunner runner = TestRunners.newTestRunner(GetAzureQueueStorage.class); @@ -47,7 +49,7 @@ public class TestGetAzureQueueStorage { results = ((MockProcessContext) processContext).validate(); } - Assert.assertEquals(0, results.size()); + assertEquals(0, results.size()); } @Test @@ -64,9 +66,8 @@ public class TestGetAzureQueueStorage { results = ((MockProcessContext) processContext).validate(); } - Assert.assertEquals(1, results.size()); + assertEquals(1, results.size()); Iterator iterator = results.iterator(); - Assert.assertTrue(iterator.next().getExplanation().contains("should be greater than 0 secs")); + assertTrue(iterator.next().getExplanation().contains("should be greater than 0 secs")); } - } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestPutAzureQueueStorage.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestPutAzureQueueStorage.java index d1e552e805..f54cb08fae 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestPutAzureQueueStorage.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/queue/TestPutAzureQueueStorage.java @@ -17,15 +17,13 @@ package org.apache.nifi.processors.azure.storage.queue; import com.microsoft.azure.storage.StorageException; - import org.apache.nifi.components.ValidationResult; import org.apache.nifi.processor.ProcessContext; import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.URISyntaxException; import java.security.InvalidKeyException; @@ -33,6 +31,9 @@ import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestPutAzureQueueStorage { private final TestRunner runner = TestRunners.newTestRunner(PutAzureQueueStorage.class); @@ -52,11 +53,11 @@ public class TestPutAzureQueueStorage { results = ((MockProcessContext) processContext).validate(); } - Assert.assertEquals(2, results.size()); + assertEquals(2, results.size()); Iterator iterator = results.iterator(); - Assert.assertTrue(iterator.next().toString().contains(PutAzureQueueStorage.TTL.getDisplayName() + " exceeds the allowed limit of 7 days. Set a value less than 7 days")); - Assert.assertTrue(iterator.next().toString().contains(PutAzureQueueStorage.VISIBILITY_DELAY.getDisplayName() + " should be greater than or equal to 0 and less than")); + assertTrue(iterator.next().toString().contains(PutAzureQueueStorage.TTL.getDisplayName() + " exceeds the allowed limit of 7 days. Set a value less than 7 days")); + assertTrue(iterator.next().toString().contains(PutAzureQueueStorage.VISIBILITY_DELAY.getDisplayName() + " should be greater than or equal to 0 and less than")); } @Test @@ -73,7 +74,6 @@ public class TestPutAzureQueueStorage { results = ((MockProcessContext) processContext).validate(); } - Assert.assertEquals(0, results.size()); + assertEquals(0, results.size()); } - } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureBlobClientSideEncryptionUtils.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureBlobClientSideEncryptionUtils.java index ba7b2ca362..5c338f226f 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureBlobClientSideEncryptionUtils.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureBlobClientSideEncryptionUtils.java @@ -21,13 +21,13 @@ import org.apache.nifi.processor.Processor; import org.apache.nifi.processors.azure.storage.PutAzureBlobStorage; import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.MockValidationContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collection; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestAzureBlobClientSideEncryptionUtils { private static final String KEY_ID_VALUE = "key:id"; @@ -41,7 +41,7 @@ public class TestAzureBlobClientSideEncryptionUtils { private MockProcessContext processContext; private MockValidationContext validationContext; - @Before + @BeforeEach public void setUp() { Processor processor = new PutAzureBlobStorage(); processContext = new MockProcessContext(processor); @@ -151,11 +151,10 @@ public class TestAzureBlobClientSideEncryptionUtils { } private void assertValid(Collection result) { - assertTrue("There should be no validation error", result.isEmpty()); + assertTrue(result.isEmpty(), "There should be no validation error"); } private void assertNotValid(Collection result) { - assertFalse("There should be validation error", result.isEmpty()); + assertFalse(result.isEmpty(), "There should be validation error"); } - } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsGetStorageCredentialsDetails.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsGetStorageCredentialsDetails.java index 3ec70853e3..56b973a2a3 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsGetStorageCredentialsDetails.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsGetStorageCredentialsDetails.java @@ -26,14 +26,15 @@ import org.apache.nifi.services.azure.storage.AzureStorageCredentialsControllerS import org.apache.nifi.services.azure.storage.AzureStorageCredentialsDetails; import org.apache.nifi.util.MockConfigurationContext; import org.apache.nifi.util.MockProcessContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestAzureStorageUtilsGetStorageCredentialsDetails { @@ -44,7 +45,7 @@ public class TestAzureStorageUtilsGetStorageCredentialsDetails { private MockProcessContext processContext; - @Before + @BeforeEach public void setUp() { Processor processor = new ListAzureBlobStorage(); processContext = new MockProcessContext(processor); @@ -86,32 +87,32 @@ public class TestAzureStorageUtilsGetStorageCredentialsDetails { assertStorageCredentialsDetailsAccountNameAndSasToken(storageCredentialsDetails); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAccountNameMissingConfiguredOnProcessor() { configureProcessorProperties(null, ACCOUNT_KEY_VALUE, null); - AzureStorageUtils.getStorageCredentialsDetails(processContext, null); + assertThrows(IllegalArgumentException.class, () -> AzureStorageUtils.getStorageCredentialsDetails(processContext, null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAccountKeyAndSasTokenMissingConfiguredOnProcessor() { configureProcessorProperties(ACCOUNT_NAME_VALUE, null, null); - AzureStorageUtils.getStorageCredentialsDetails(processContext, null); + assertThrows(IllegalArgumentException.class, () -> AzureStorageUtils.getStorageCredentialsDetails(processContext, null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAccountNameMissingConfiguredOnControllerService() { configureControllerService(null, ACCOUNT_KEY_VALUE, null); - AzureStorageUtils.getStorageCredentialsDetails(processContext, null); + assertThrows(IllegalArgumentException.class, () -> AzureStorageUtils.getStorageCredentialsDetails(processContext, null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testAccountKeyAndSasTokenMissingConfiguredOnControllerService() { configureControllerService(ACCOUNT_NAME_VALUE, null, null); - AzureStorageUtils.getStorageCredentialsDetails(processContext, null); + assertThrows(IllegalArgumentException.class, () -> AzureStorageUtils.getStorageCredentialsDetails(processContext, null)); } private void configureProcessorProperties(String accountName, String accountKey, String sasToken) { diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsValidateCredentialProperties.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsValidateCredentialProperties.java index 95bd130a18..be956eb2c8 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsValidateCredentialProperties.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/azure/storage/utils/TestAzureStorageUtilsValidateCredentialProperties.java @@ -21,13 +21,13 @@ import org.apache.nifi.processor.Processor; import org.apache.nifi.processors.azure.storage.ListAzureBlobStorage; import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.MockValidationContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collection; -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 TestAzureStorageUtilsValidateCredentialProperties { @@ -39,7 +39,7 @@ public class TestAzureStorageUtilsValidateCredentialProperties { private MockProcessContext processContext; private MockValidationContext validationContext; - @Before + @BeforeEach public void setUp() { Processor processor = new ListAzureBlobStorage(); processContext = new MockProcessContext(processor); @@ -149,11 +149,10 @@ public class TestAzureStorageUtilsValidateCredentialProperties { } private void assertValid(Collection result) { - assertTrue("There should be no validation error", result.isEmpty()); + assertTrue(result.isEmpty(), "There should be no validation error"); } private void assertNotValid(Collection result) { - assertFalse("There should be validation error", result.isEmpty()); + assertFalse(result.isEmpty(), "There should be validation error"); } - } diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/cosmos/document/TestAzureCosmosDBClientService.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/cosmos/document/TestAzureCosmosDBClientService.java index 64e7cce8ca..0ab7072397 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/cosmos/document/TestAzureCosmosDBClientService.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/cosmos/document/TestAzureCosmosDBClientService.java @@ -21,8 +21,8 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.NoOpProcessor; 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; public class TestAzureCosmosDBClientService { @@ -32,7 +32,7 @@ public class TestAzureCosmosDBClientService { private TestRunner runner; private AzureCosmosDBClientService service; - @Before + @BeforeEach public void setUp() throws InitializationException { runner = TestRunners.newTestRunner(NoOpProcessor.class); service = new AzureCosmosDBClientService(); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java index 043dbf6a06..69e2b2dadf 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java @@ -22,16 +22,16 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.NoOpProcessor; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; -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.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; public class TestADLSCredentialsControllerService { @@ -48,7 +48,7 @@ public class TestADLSCredentialsControllerService { private TestRunner runner; private ADLSCredentialsControllerService credentialsService; - @Before + @BeforeEach public void setUp() throws InitializationException { runner = TestRunners.newTestRunner(NoOpProcessor.class); credentialsService = new ADLSCredentialsControllerService(); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerService.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerService.java index 27ba61493e..490c5152d7 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerService.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerService.java @@ -21,8 +21,8 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.NoOpProcessor; 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; public class TestAzureStorageCredentialsControllerService { @@ -33,7 +33,7 @@ public class TestAzureStorageCredentialsControllerService { private TestRunner runner; private AzureStorageCredentialsService credentialsService; - @Before + @BeforeEach public void setUp() throws InitializationException { runner = TestRunners.newTestRunner(NoOpProcessor.class); credentialsService = new AzureStorageCredentialsControllerService(); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerServiceLookup.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerServiceLookup.java index 3470b99912..4c3f1e3141 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerServiceLookup.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageCredentialsControllerServiceLookup.java @@ -16,21 +16,22 @@ */ package org.apache.nifi.services.azure.storage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.HashMap; -import java.util.Map; - import org.apache.nifi.controller.AbstractControllerService; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.NoOpProcessor; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +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; public class TestAzureStorageCredentialsControllerServiceLookup { @@ -40,7 +41,7 @@ public class TestAzureStorageCredentialsControllerServiceLookup { private AzureStorageCredentialsControllerServiceLookup lookupService; private TestRunner runner; - @Before + @BeforeEach public void setup() throws InitializationException { serviceA = new MockAzureStorageCredentialsService( new AzureStorageCredentialsDetails("Account_A", "core.windows.net", null)); @@ -88,18 +89,18 @@ public class TestAzureStorageCredentialsControllerServiceLookup { assertNull(storageCredentialsDetails.getStorageSuffix()); } - @Test(expected = ProcessException.class) + @Test public void testLookupMissingCredentialsNameAttribute() { final Map attributes = new HashMap<>(); - lookupService.getStorageCredentialsDetails(attributes); + assertThrows(ProcessException.class, () -> lookupService.getStorageCredentialsDetails(attributes)); } - @Test(expected = ProcessException.class) + @Test public void testLookupWithCredentialsNameThatDoesNotExist() { final Map attributes = new HashMap<>(); attributes.put(AzureStorageCredentialsControllerServiceLookup.AZURE_STORAGE_CREDENTIALS_NAME_ATTRIBUTE, "DOES-NOT-EXIST"); - lookupService.getStorageCredentialsDetails(attributes); + assertThrows(ProcessException.class, () -> lookupService.getStorageCredentialsDetails(attributes)); } @Test diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageEmulatorCredentialsControllerService.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageEmulatorCredentialsControllerService.java index 40f5545d05..dcd583e87f 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageEmulatorCredentialsControllerService.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestAzureStorageEmulatorCredentialsControllerService.java @@ -20,8 +20,8 @@ import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.NoOpProcessor; 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; public class TestAzureStorageEmulatorCredentialsControllerService { @@ -30,7 +30,7 @@ public class TestAzureStorageEmulatorCredentialsControllerService { private TestRunner runner; private AzureStorageCredentialsService credentialsService; - @Before + @BeforeEach public void setUp() throws InitializationException { runner = TestRunners.newTestRunner(NoOpProcessor.class); credentialsService = new AzureStorageEmulatorCredentialsControllerService(); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsProvenanceReportingTask.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsProvenanceReportingTask.java index ee7f8b9b67..814a461284 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsProvenanceReportingTask.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsProvenanceReportingTask.java @@ -16,29 +16,25 @@ */ package org.apache.nifi.reporting.azure.loganalytics; -import static org.junit.Assert.assertEquals; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import org.junit.jupiter.api.Test; -import java.io.IOException; +import javax.json.Json; +import javax.json.JsonBuilderFactory; +import javax.json.JsonObjectBuilder; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import javax.json.Json; -import javax.json.JsonBuilderFactory; -import javax.json.JsonObjectBuilder; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; - -import org.apache.nifi.reporting.InitializationException; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestAzureLogAnalyticsProvenanceReportingTask { @Test - public void testAddField1() throws IOException, InterruptedException, InitializationException { + public void testAddField1() { final Map config = Collections.emptyMap(); final JsonBuilderFactory factory = Json.createBuilderFactory(config); @@ -63,7 +59,7 @@ public class TestAzureLogAnalyticsProvenanceReportingTask { } @Test - public void testAddField2() throws IOException, InterruptedException, InitializationException { + public void testAddField2() { final Map config = Collections.emptyMap(); final JsonBuilderFactory factory = Json.createBuilderFactory(config); @@ -79,7 +75,7 @@ public class TestAzureLogAnalyticsProvenanceReportingTask { } @Test - public void testAddField3() throws IOException, InterruptedException, InitializationException { + public void testAddField3() { final Map config = Collections.emptyMap(); final JsonBuilderFactory factory = Json.createBuilderFactory(config); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsReportingTask.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsReportingTask.java index 1dbefa1a7e..6841d15325 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsReportingTask.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestAzureLogAnalyticsReportingTask.java @@ -16,17 +16,6 @@ */ package org.apache.nifi.reporting.azure.loganalytics; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.nifi.controller.status.ProcessGroupStatus; @@ -34,15 +23,25 @@ import org.apache.nifi.controller.status.ProcessorStatus; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.state.MockStateManager; import org.apache.nifi.util.MockComponentLog; - import org.apache.nifi.util.MockReportingContext; import org.apache.nifi.util.MockReportingInitializationContext; import org.apache.nifi.util.MockVariableRegistry; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.atLeast; +import static org.mockito.Mockito.verify; + public class TestAzureLogAnalyticsReportingTask { private static final String TEST_INIT_CONTEXT_ID = "test-init-context-id"; @@ -59,7 +58,7 @@ public class TestAzureLogAnalyticsReportingTask { private ProcessGroupStatus testGroupStatus2; private ProcessorStatus procStatus; - @Before + @BeforeEach public void setup() { testedReportingTask = new TestableAzureLogAnalyticsReportingTask(); rootGroupStatus = new ProcessGroupStatus(); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestMetricsFactory.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestMetricsFactory.java index 724b6cefd2..0dcb13af9c 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestMetricsFactory.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestMetricsFactory.java @@ -17,25 +17,24 @@ package org.apache.nifi.reporting.azure.loganalytics; -import java.util.ArrayList; -import java.util.List; - import com.google.gson.Gson; -import org.apache.nifi.metrics.jvm.JmxJvmMetrics; -import org.apache.nifi.metrics.jvm.JvmMetrics; - import org.apache.nifi.controller.status.ProcessGroupStatus; import org.apache.nifi.controller.status.ProcessorStatus; +import org.apache.nifi.metrics.jvm.JmxJvmMetrics; +import org.apache.nifi.metrics.jvm.JvmMetrics; import org.apache.nifi.reporting.azure.loganalytics.api.AzureLogAnalyticsMetricsFactory; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; public class TestMetricsFactory { private ProcessGroupStatus status; private final Gson gson = new Gson(); - @Before + @BeforeEach public void init() { status = new ProcessGroupStatus(); status.setId("1234"); diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestVerification.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestVerification.java index aa91e34000..4ccc013da6 100644 --- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestVerification.java +++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-reporting-task/src/test/java/org/apache/nifi/reporting/azure/loganalytics/TestVerification.java @@ -17,10 +17,10 @@ package org.apache.nifi.reporting.azure.loganalytics; -import static org.junit.Assert.assertTrue; - import java.util.List; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestVerification { static public void assertDatatFlowMetrics(List collectedMetrics) { diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/SearchResponseTest.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/SearchResponseTest.groovy index 6045ce4ff5..082a67f294 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/SearchResponseTest.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/SearchResponseTest.groovy @@ -17,8 +17,9 @@ package org.apache.nifi.elasticsearch -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.assertTrue class SearchResponseTest { @Test @@ -35,22 +36,22 @@ class SearchResponseTest { def response = new SearchResponse(results, aggs as Map, pitId, scrollId, searchAfter, num, took, timeout, warnings) def str = response.toString() - Assert.assertEquals(results, response.hits) - Assert.assertEquals(aggs, response.aggregations) - Assert.assertEquals(pitId, response.pitId) - Assert.assertEquals(scrollId, response.scrollId) - Assert.assertEquals(num, response.numberOfHits) - Assert.assertEquals(took, response.took) - Assert.assertEquals(timeout, response.timedOut) - Assert.assertEquals(warnings, response.warnings) - Assert.assertTrue(str.contains("aggregations")) - Assert.assertTrue(str.contains("hits")) - Assert.assertTrue(str.contains("pitId")) - Assert.assertTrue(str.contains("scrollId")) - Assert.assertTrue(str.contains("searchAfter")) - Assert.assertTrue(str.contains("numberOfHits")) - Assert.assertTrue(str.contains("took")) - Assert.assertTrue(str.contains("timedOut")) - Assert.assertTrue(str.contains("warnings")) + assertEquals(results, response.hits) + assertEquals(aggs, response.aggregations) + assertEquals(pitId, response.pitId) + assertEquals(scrollId, response.scrollId) + assertEquals(num, response.numberOfHits) + assertEquals(took, response.took) + assertEquals(timeout, response.timedOut) + assertEquals(warnings, response.warnings) + assertTrue(str.contains("aggregations")) + assertTrue(str.contains("hits")) + assertTrue(str.contains("pitId")) + assertTrue(str.contains("scrollId")) + assertTrue(str.contains("searchAfter")) + assertTrue(str.contains("numberOfHits")) + assertTrue(str.contains("took")) + assertTrue(str.contains("timedOut")) + assertTrue(str.contains("warnings")) } } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchClientService_IT.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchClientService_IT.groovy index 5c77cc1010..26b46d687e 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchClientService_IT.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchClientService_IT.groovy @@ -30,24 +30,24 @@ import org.apache.nifi.elasticsearch.UpdateOperationResponse import org.apache.nifi.security.util.StandardTlsConfiguration import org.apache.nifi.security.util.TemporaryKeyStoreBuilder import org.apache.nifi.security.util.TlsConfiguration -import org.apache.nifi.ssl.SSLContextService import org.apache.nifi.util.StringUtils 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 javax.net.ssl.SSLContext +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assumptions +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import static groovy.json.JsonOutput.prettyPrint import static groovy.json.JsonOutput.toJson -import static org.hamcrest.CoreMatchers.is -import static org.mockito.Mockito.mock -import static org.mockito.Mockito.when +import static org.junit.jupiter.api.Assumptions.assumeTrue + +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 class ElasticSearchClientService_IT { private TestRunner runner @@ -81,9 +81,9 @@ class ElasticSearchClientService_IT { return setup } - @BeforeClass + @BeforeAll static void beforeAll() throws Exception { - Assume.assumeTrue("Elasticsearch integration-tests not setup", isElasticsearchSetup()) + Assumptions.assumeTrue(isElasticsearchSetup(), "Elasticsearch integration-tests not setup") System.out.println( String.format("%n%n%n%n%n%n%n%n%n%n%n%n%n%n%nTYPE: %s%nVERSION: %s%nFLAVOUR %s%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n", @@ -101,7 +101,7 @@ class ElasticSearchClientService_IT { ) } - @Before + @BeforeEach void before() throws Exception { runner = TestRunners.newTestRunner(TestControllerServiceProcessor.class) service = new ElasticSearchClientServiceImpl() @@ -122,7 +122,7 @@ class ElasticSearchClientService_IT { service.refresh(null, null); } - @After + @AfterEach void after() throws Exception { service.onDisabled() } @@ -146,22 +146,22 @@ class ElasticSearchClientService_IT { SearchResponse response = service.search(query, INDEX, TYPE, null) - Assert.assertNotNull("Response was null", response) + assertNotNull(response, "Response was null") - Assert.assertEquals("Wrong count", 15, response.numberOfHits) - Assert.assertFalse("Timed out", response.isTimedOut()) - Assert.assertNotNull("Hits was null", response.getHits()) - Assert.assertEquals("Wrong number of hits", 10, response.hits.size()) - Assert.assertNotNull("Aggregations are missing", response.aggregations) - Assert.assertEquals("Aggregation count is wrong", 1, response.aggregations.size()) - Assert.assertNull("Unexpected ScrollId", response.scrollId) - Assert.assertNull("Unexpected Search_After", response.searchAfter) - Assert.assertNull("Unexpected pitId", response.pitId) + assertEquals(15, response.numberOfHits, "Wrong count") + assertFalse(response.isTimedOut(), "Timed out") + assertNotNull(response.getHits(), "Hits was null") + assertEquals(10, response.hits.size(), "Wrong number of hits") + assertNotNull(response.aggregations, "Aggregations are missing") + assertEquals(1, response.aggregations.size(), "Aggregation count is wrong") + assertNull(response.scrollId, "Unexpected ScrollId") + assertNull(response.searchAfter, "Unexpected Search_After") + assertNull(response.pitId, "Unexpected pitId") Map termCounts = response.aggregations.get("term_counts") as Map - Assert.assertNotNull("Term counts was missing", termCounts) + assertNotNull(termCounts, "Term counts was missing") def buckets = termCounts.get("buckets") - Assert.assertNotNull("Buckets branch was empty", buckets) + assertNotNull(buckets, "Buckets branch was empty") def expected = [ "one": 1, "two": 2, @@ -173,7 +173,7 @@ class ElasticSearchClientService_IT { buckets.each { aggRes -> def key = aggRes["key"] def docCount = aggRes["doc_count"] - Assert.assertEquals("${key} did not match.", expected[key as String], docCount) + assertEquals(expected[key as String], docCount, "${key} did not match.") } } @@ -196,19 +196,19 @@ class ElasticSearchClientService_IT { SearchResponse response = service.search(query, "messages", TYPE, [preference: "_local"]) - Assert.assertNotNull("Response was null", response) + assertNotNull(response, "Response was null") - Assert.assertEquals("Wrong count", 15, response.numberOfHits) - Assert.assertFalse("Timed out", response.isTimedOut()) - Assert.assertNotNull("Hits was null", response.getHits()) - Assert.assertEquals("Wrong number of hits", 10, response.hits.size()) - Assert.assertNotNull("Aggregations are missing", response.aggregations) - Assert.assertEquals("Aggregation count is wrong", 1, response.aggregations.size()) + assertEquals(15, response.numberOfHits, "Wrong count") + assertFalse(response.isTimedOut(), "Timed out") + assertNotNull(response.getHits(), "Hits was null") + assertEquals(10, response.hits.size(), "Wrong number of hits") + assertNotNull(response.aggregations, "Aggregations are missing") + assertEquals(1, response.aggregations.size(), "Aggregation count is wrong") Map termCounts = response.aggregations.get("term_counts") as Map - Assert.assertNotNull("Term counts was missing", termCounts) + assertNotNull(termCounts, "Term counts was missing") def buckets = termCounts.get("buckets") - Assert.assertNotNull("Buckets branch was empty", buckets) + assertNotNull(buckets, "Buckets branch was empty") def expected = [ "one": 1, "two": 2, @@ -220,7 +220,7 @@ class ElasticSearchClientService_IT { buckets.each { aggRes -> String key = aggRes["key"] def docCount = aggRes["doc_count"] - Assert.assertEquals("${key} did not match.", expected[key], docCount) + assertEquals(expected[key], docCount, "${key} did not match.") } } @@ -244,7 +244,7 @@ class ElasticSearchClientService_IT { query = prettyPrint(toJson([size: 1, query: [mlt: [fields: ["msg"], like: 1]]])) } final SearchResponse response = service.search(query, INDEX, type, null) - Assert.assertTrue("Missing warnings", !response.warnings.isEmpty()) + assertTrue(!response.warnings.isEmpty(), "Missing warnings") } @Test @@ -257,47 +257,47 @@ class ElasticSearchClientService_IT { // initiate the scroll final SearchResponse response = service.search(query, INDEX, TYPE, Collections.singletonMap("scroll", "10s")) - Assert.assertNotNull("Response was null", response) + assertNotNull(response, "Response was null") - Assert.assertEquals("Wrong count", 15, response.numberOfHits) - Assert.assertFalse("Timed out", response.isTimedOut()) - Assert.assertNotNull("Hits was null", response.getHits()) - Assert.assertEquals("Wrong number of hits", 2, response.hits.size()) - Assert.assertNotNull("Aggregations are missing", response.aggregations) - Assert.assertEquals("Aggregation count is wrong", 1, response.aggregations.size()) - Assert.assertNotNull("ScrollId missing", response.scrollId) - Assert.assertNull("Unexpected Search_After", response.searchAfter) - Assert.assertNull("Unexpected pitId", response.pitId) + assertEquals(15, response.numberOfHits, "Wrong count") + assertFalse(response.isTimedOut(), "Timed out") + assertNotNull(response.getHits(), "Hits was null") + assertEquals(2, response.hits.size(), "Wrong number of hits") + assertNotNull(response.aggregations, "Aggregations are missing") + assertEquals(1, response.aggregations.size(), "Aggregation count is wrong") + assertNotNull(response.scrollId, "ScrollId missing") + assertNull(response.searchAfter, "Unexpected Search_After") + assertNull(response.pitId, "Unexpected pitId") final Map termCounts = response.aggregations.get("term_counts") as Map - Assert.assertNotNull("Term counts was missing", termCounts) - Assert.assertEquals("Buckets count is wrong", 5, (termCounts.get("buckets") as List).size()) + assertNotNull(termCounts, "Term counts was missing") + assertEquals(5, (termCounts.get("buckets") as List).size(), "Buckets count is wrong") // scroll the next page final SearchResponse scrollResponse = service.scroll(prettyPrint((toJson([scroll_id: response.scrollId, scroll: "10s"])))) - Assert.assertNotNull("Scroll Response was null", scrollResponse) + assertNotNull(scrollResponse, "Scroll Response was null") - Assert.assertEquals("Wrong count", 15, scrollResponse.numberOfHits) - Assert.assertFalse("Timed out", scrollResponse.isTimedOut()) - Assert.assertNotNull("Hits was null", scrollResponse.getHits()) - Assert.assertEquals("Wrong number of hits", 2, scrollResponse.hits.size()) - Assert.assertNotNull("Aggregations missing", scrollResponse.aggregations) - Assert.assertEquals("Aggregation count is wrong", 0, scrollResponse.aggregations.size()) - Assert.assertNotNull("ScrollId missing", scrollResponse.scrollId) - Assert.assertNull("Unexpected Search_After", scrollResponse.searchAfter) - Assert.assertNull("Unexpected pitId", scrollResponse.pitId) + assertEquals(15, scrollResponse.numberOfHits, "Wrong count") + assertFalse(scrollResponse.isTimedOut(), "Timed out") + assertNotNull(scrollResponse.getHits(), "Hits was null") + assertEquals(2, scrollResponse.hits.size(), "Wrong number of hits") + assertNotNull(scrollResponse.aggregations, "Aggregations missing") + assertEquals(0, scrollResponse.aggregations.size(), "Aggregation count is wrong") + assertNotNull(scrollResponse.scrollId, "ScrollId missing") + assertNull(scrollResponse.searchAfter, "Unexpected Search_After") + assertNull(scrollResponse.pitId, "Unexpected pitId") - Assert.assertNotEquals("Same results", scrollResponse.hits, response.hits) + assertNotEquals(scrollResponse.hits, response.hits, "Same results") // delete the scroll DeleteOperationResponse deleteResponse = service.deleteScroll(scrollResponse.scrollId) - Assert.assertNotNull("Delete Response was null", deleteResponse) - Assert.assertTrue(deleteResponse.took > 0) + assertNotNull("Delete Response was null", deleteResponse) + assertTrue(deleteResponse.took > 0) // delete scroll again (should now be unknown but the 404 caught and ignored) deleteResponse = service.deleteScroll(scrollResponse.scrollId) - Assert.assertNotNull("Delete Response was null", deleteResponse) - Assert.assertEquals(0L, deleteResponse.took) + assertNotNull(deleteResponse, "Delete Response was null") + assertEquals(0L, deleteResponse.took) } @Test @@ -312,47 +312,47 @@ class ElasticSearchClientService_IT { // search first page final SearchResponse response = service.search(query, INDEX, TYPE, null) - Assert.assertNotNull("Response was null", response) + assertNotNull(response, "Response was null") - Assert.assertEquals("Wrong count", 15, response.numberOfHits) - Assert.assertFalse("Timed out", response.isTimedOut()) - Assert.assertNotNull("Hits was null", response.getHits()) - Assert.assertEquals("Wrong number of hits", 2, response.hits.size()) - Assert.assertNotNull("Aggregations missing", response.aggregations) - Assert.assertEquals("Aggregation count is wrong", 1, response.aggregations.size()) - Assert.assertNull("Unexpected ScrollId", response.scrollId) - Assert.assertNotNull("Search_After missing", response.searchAfter) - Assert.assertNull("Unexpected pitId", response.pitId) + assertEquals(15, response.numberOfHits, "Wrong count") + assertFalse(response.isTimedOut(), "Timed out") + assertNotNull(response.getHits(), "Hits was null") + assertEquals(2, response.hits.size(), "Wrong number of hits") + assertNotNull(response.aggregations, "Aggregations missing") + assertEquals(1, response.aggregations.size(), "Aggregation count is wrong") + assertNull(response.scrollId, "Unexpected ScrollId") + assertNotNull(response.searchAfter, "Search_After missing") + assertNull(response.pitId, "Unexpected pitId") final Map termCounts = response.aggregations.get("term_counts") as Map - Assert.assertNotNull("Term counts was missing", termCounts) - Assert.assertEquals("Buckets count is wrong", 5, (termCounts.get("buckets") as List).size()) + assertNotNull(termCounts, "Term counts was missing") + assertEquals(5, (termCounts.get("buckets") as List).size(), "Buckets count is wrong") // search the next page queryMap.search_after = new JsonSlurper().parseText(response.searchAfter) as Serializable queryMap.remove("aggs") final String secondPage = prettyPrint(toJson(queryMap)) final SearchResponse secondResponse = service.search(secondPage, INDEX, TYPE, null) - Assert.assertNotNull("Second Response was null", secondResponse) + assertNotNull(secondResponse, "Second Response was null") - Assert.assertEquals("Wrong count", 15, secondResponse.numberOfHits) - Assert.assertFalse("Timed out", secondResponse.isTimedOut()) - Assert.assertNotNull("Hits was null", secondResponse.getHits()) - Assert.assertEquals("Wrong number of hits", 2, secondResponse.hits.size()) - Assert.assertNotNull("Aggregations missing", secondResponse.aggregations) - Assert.assertEquals("Aggregation count is wrong", 0, secondResponse.aggregations.size()) - Assert.assertNull("Unexpected ScrollId", secondResponse.scrollId) - Assert.assertNotNull("Unexpected Search_After", secondResponse.searchAfter) - Assert.assertNull("Unexpected pitId", secondResponse.pitId) + assertEquals(15, secondResponse.numberOfHits, "Wrong count") + assertFalse(secondResponse.isTimedOut(), "Timed out") + assertNotNull(secondResponse.getHits(), "Hits was null") + assertEquals(2, secondResponse.hits.size(), "Wrong number of hits") + assertNotNull(secondResponse.aggregations, "Aggregations missing") + assertEquals(0, secondResponse.aggregations.size(), "Aggregation count is wrong") + assertNull(secondResponse.scrollId, "Unexpected ScrollId") + assertNotNull(secondResponse.searchAfter, "Unexpected Search_After") + assertNull(secondResponse.pitId, "Unexpected pitId") - Assert.assertNotEquals("Same results", secondResponse.hits, response.hits) + assertNotEquals(secondResponse.hits, response.hits, "Same results") } @Test void testPointInTime() { // Point in Time only available in 7.10+ with XPack enabled - Assume.assumeTrue("Requires version 7.10+", VERSION >= ES_7_10) - Assume.assumeThat("Requires XPack features", FLAVOUR, is(DEFAULT)) + assumeTrue(VERSION >= ES_7_10, "Requires version 7.10+") + assumeTrue(FLAVOUR == DEFAULT, "Requires XPack features") // initialise final String pitId = service.initialisePointInTime(INDEX, "10s") @@ -368,50 +368,50 @@ class ElasticSearchClientService_IT { // search first page final SearchResponse response = service.search(query, null, TYPE, null) - Assert.assertNotNull("Response was null", response) + assertNotNull(response, "Response was null") - Assert.assertEquals("Wrong count", 15, response.numberOfHits) - Assert.assertFalse("Timed out", response.isTimedOut()) - Assert.assertNotNull("Hits was null", response.getHits()) - Assert.assertEquals("Wrong number of hits", 2, response.hits.size()) - Assert.assertNotNull("Aggregations missing", response.aggregations) - Assert.assertEquals("Aggregation count is wrong", 1, response.aggregations.size()) - Assert.assertNull("Unexpected ScrollId", response.scrollId) - Assert.assertNotNull("Unexpected Search_After", response.searchAfter) - Assert.assertNotNull("pitId missing", response.pitId) + assertEquals(15, response.numberOfHits, "Wrong count") + assertFalse(response.isTimedOut(), "Timed out") + assertNotNull(response.getHits(), "Hits was null") + assertEquals(2, response.hits.size(), "Wrong number of hits") + assertNotNull(response.aggregations, "Aggregations missing") + assertEquals(1, response.aggregations.size(), "Aggregation count is wrong") + assertNull(response.scrollId, "Unexpected ScrollId") + assertNotNull(response.searchAfter, "Unexpected Search_After") + assertNotNull(response.pitId, "pitId missing") final Map termCounts = response.aggregations.get("term_counts") as Map - Assert.assertNotNull("Term counts was missing", termCounts) - Assert.assertEquals("Buckets count is wrong", 5, (termCounts.get("buckets") as List).size()) + assertNotNull(termCounts, "Term counts was missing") + assertEquals(5, (termCounts.get("buckets") as List).size(), "Buckets count is wrong") // search the next page queryMap.search_after = new JsonSlurper().parseText(response.searchAfter) as Serializable queryMap.remove("aggs") final String secondPage = prettyPrint(toJson(queryMap)) final SearchResponse secondResponse = service.search(secondPage, null, TYPE, null) - Assert.assertNotNull("Second Response was null", secondResponse) + assertNotNull(secondResponse, "Second Response was null") - Assert.assertEquals("Wrong count", 15, secondResponse.numberOfHits) - Assert.assertFalse("Timed out", secondResponse.isTimedOut()) - Assert.assertNotNull("Hits was null", secondResponse.getHits()) - Assert.assertEquals("Wrong number of hits", 2, secondResponse.hits.size()) - Assert.assertNotNull("Aggregations missing", secondResponse.aggregations) - Assert.assertEquals("Aggregation count is wrong", 0, secondResponse.aggregations.size()) - Assert.assertNull("Unexpected ScrollId", secondResponse.scrollId) - Assert.assertNotNull("Unexpected Search_After", secondResponse.searchAfter) - Assert.assertNotNull("pitId missing", secondResponse.pitId) + assertEquals(15, secondResponse.numberOfHits, "Wrong count") + assertFalse(secondResponse.isTimedOut(), "Timed out") + assertNotNull(secondResponse.getHits(), "Hits was null") + assertEquals(2, secondResponse.hits.size(), "Wrong number of hits") + assertNotNull(secondResponse.aggregations, "Aggregations missing") + assertEquals(0, secondResponse.aggregations.size(), "Aggregation count is wrong") + assertNull(secondResponse.scrollId, "Unexpected ScrollId") + assertNotNull(secondResponse.searchAfter, "Unexpected Search_After") + assertNotNull(secondResponse.pitId, "pitId missing") - Assert.assertNotEquals("Same results", secondResponse.hits, response.hits) + assertNotEquals(secondResponse.hits, response.hits, "Same results") // delete pitId DeleteOperationResponse deleteResponse = service.deletePointInTime(pitId) - Assert.assertNotNull("Delete Response was null", deleteResponse) - Assert.assertTrue(deleteResponse.took > 0) + assertNotNull(deleteResponse, "Delete Response was null") + assertTrue(deleteResponse.took > 0) // delete pitId again (should now be unknown but the 404 caught and ignored) deleteResponse = service.deletePointInTime(pitId) - Assert.assertNotNull("Delete Response was null", deleteResponse) - Assert.assertEquals(0L, deleteResponse.took) + assertNotNull(deleteResponse, "Delete Response was null") + assertEquals(0L, deleteResponse.took) } @Test @@ -424,8 +424,8 @@ class ElasticSearchClientService_IT { ] ])) DeleteOperationResponse response = service.deleteByQuery(query, INDEX, TYPE, null) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) } @Test @@ -438,8 +438,8 @@ class ElasticSearchClientService_IT { ] ])) DeleteOperationResponse response = service.deleteByQuery(query, INDEX, TYPE, [refresh: "true"]) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) } @Test @@ -452,8 +452,8 @@ class ElasticSearchClientService_IT { ] ])) UpdateOperationResponse response = service.updateByQuery(query, INDEX, TYPE, null) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) } @Test @@ -466,8 +466,8 @@ class ElasticSearchClientService_IT { ] ])) UpdateOperationResponse response = service.updateByQuery(query, INDEX, TYPE, [refresh: "true", slices: "1"]) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) } @Test @@ -476,13 +476,13 @@ class ElasticSearchClientService_IT { final def originalDoc = service.get(INDEX, TYPE, ID, null) try { DeleteOperationResponse response = service.deleteById(INDEX, TYPE, ID, null) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) - final ElasticsearchException ee = Assert.assertThrows(ElasticsearchException.class, { -> + assertNotNull(response) + assertTrue(response.getTook() > 0) + final ElasticsearchException ee = assertThrows(ElasticsearchException.class, { -> service.get(INDEX, TYPE, ID, null) }) - Assert.assertTrue(ee.isNotFound()) + assertTrue(ee.isNotFound()) final def doc = service.get(INDEX, TYPE, "2", null) - Assert.assertNotNull(doc) + assertNotNull(doc) } finally { // replace the deleted doc service.add(new IndexOperationRequest(INDEX, TYPE, "1", originalDoc, IndexOperationRequest.Operation.Index), null) @@ -496,16 +496,16 @@ class ElasticSearchClientService_IT { 1.upto(15) { index -> String id = String.valueOf(index) def doc = service.get(INDEX, TYPE, id, null) - Assert.assertNotNull("Doc was null", doc) - Assert.assertNotNull("${doc.toString()}\t${doc.keySet().toString()}", doc.get("msg")) + assertNotNull(doc, "Doc was null") + assertNotNull(doc.get("msg"), "${doc.toString()}\t${doc.keySet().toString()}") old = doc } } @Test void testGetNotFound() { - final ElasticsearchException ee = Assert.assertThrows(ElasticsearchException.class, { -> service.get(INDEX, TYPE, "not_found", null) }) - Assert.assertTrue(ee.isNotFound()) + final ElasticsearchException ee = assertThrows(ElasticsearchException.class, { -> service.get(INDEX, TYPE, "not_found", null) }) + assertTrue(ee.isNotFound()) } @Test @@ -522,26 +522,26 @@ class ElasticSearchClientService_IT { // index with nulls suppressNulls(false) IndexOperationResponse response = service.bulk([new IndexOperationRequest("nulls", TYPE, "1", doc, IndexOperationRequest.Operation.Index)], null) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) waitForIndexRefresh() Map result = service.get("nulls", TYPE, "1", null) - Assert.assertEquals(doc, result) + assertEquals(doc, result) // suppress nulls suppressNulls(true) response = service.bulk([new IndexOperationRequest("nulls", TYPE, "2", doc, IndexOperationRequest.Operation.Index)], null) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) waitForIndexRefresh() result = service.get("nulls", TYPE, "2", null) - Assert.assertTrue("Non-nulls (present): " + result.toString(), result.keySet().containsAll(["msg", "is_blank"])) - Assert.assertFalse("is_null (should be omitted): " + result.toString(), result.keySet().contains("is_null")) - Assert.assertFalse("is_empty (should be omitted): " + result.toString(), result.keySet().contains("is_empty")) - Assert.assertFalse("empty_nested (should be omitted): " + result.toString(), result.keySet().contains("empty_nested")) - Assert.assertFalse("empty_array (should be omitted): " + result.toString(), result.keySet().contains("empty_array")) + assertTrue(result.keySet().containsAll(["msg", "is_blank"]), "Non-nulls (present): " + result.toString()) + assertFalse(result.keySet().contains("is_null"), "is_null (should be omitted): " + result.toString()) + assertFalse(result.keySet().contains("is_empty"), "is_empty (should be omitted): " + result.toString()) + assertFalse(result.keySet().contains("empty_nested"), "empty_nested (should be omitted): " + result.toString()) + assertFalse(result.keySet().contains("empty_array"), "empty_array (should be omitted): " + result.toString()) } private void suppressNulls(final boolean suppressNulls) { @@ -567,8 +567,8 @@ class ElasticSearchClientService_IT { }}, IndexOperationRequest.Operation.Index)) } IndexOperationResponse response = service.bulk(payload, [refresh: "true"]) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) waitForIndexRefresh() /* @@ -579,17 +579,17 @@ class ElasticSearchClientService_IT { Long indexB = service.count(query, "bulk_b", TYPE, null) Long indexC = service.count(query, "bulk_c", TYPE, null) - Assert.assertNotNull(indexA) - Assert.assertNotNull(indexB) - Assert.assertNotNull(indexC) - Assert.assertEquals(indexA, indexB) - Assert.assertEquals(10, indexA.intValue()) - Assert.assertEquals(10, indexB.intValue()) - Assert.assertEquals(5, indexC.intValue()) + assertNotNull(indexA) + assertNotNull(indexB) + assertNotNull(indexC) + assertEquals(indexA, indexB) + assertEquals(10, indexA.intValue()) + assertEquals(10, indexB.intValue()) + assertEquals(5, indexC.intValue()) Long total = service.count(query, "bulk_*", TYPE, null) - Assert.assertNotNull(total) - Assert.assertEquals(25, total.intValue()) + assertNotNull(total) + assertEquals(25, total.intValue()) } @Test @@ -607,8 +607,8 @@ class ElasticSearchClientService_IT { }}, IndexOperationRequest.Operation.Index)) } IndexOperationResponse response = service.bulk(payload, [refresh: "true"]) - Assert.assertNotNull(response) - Assert.assertTrue(response.getTook() > 0) + assertNotNull(response) + assertTrue(response.getTook() > 0) /* * Now, check to ensure that both indexes got populated and refreshed appropriately. @@ -618,17 +618,17 @@ class ElasticSearchClientService_IT { Long indexB = service.count(query, "bulk_b", TYPE, null) Long indexC = service.count(query, "bulk_c", TYPE, null) - Assert.assertNotNull(indexA) - Assert.assertNotNull(indexB) - Assert.assertNotNull(indexC) - Assert.assertEquals(indexA, indexB) - Assert.assertEquals(10, indexA.intValue()) - Assert.assertEquals(10, indexB.intValue()) - Assert.assertEquals(5, indexC.intValue()) + assertNotNull(indexA) + assertNotNull(indexB) + assertNotNull(indexC) + assertEquals(indexA, indexB) + assertEquals(10, indexA.intValue()) + assertEquals(10, indexB.intValue()) + assertEquals(5, indexC.intValue()) Long total = service.count(query, "bulk_*", TYPE, null) - Assert.assertNotNull(total) - Assert.assertEquals(25, total.intValue()) + assertNotNull(total) + assertEquals(25, total.intValue()) } @Test @@ -638,7 +638,7 @@ class ElasticSearchClientService_IT { doc.put("msg", "Buongiorno, mondo") service.add(new IndexOperationRequest(INDEX, TYPE, TEST_ID, doc, IndexOperationRequest.Operation.Index), [refresh: "true"]) Map result = service.get(INDEX, TYPE, TEST_ID, null) - Assert.assertEquals("Not the same", doc, result) + assertEquals("Not the same", doc, result) Map updates = new HashMap<>() updates.put("from", "john.smith") @@ -648,9 +648,9 @@ class ElasticSearchClientService_IT { IndexOperationRequest request = new IndexOperationRequest(INDEX, TYPE, TEST_ID, updates, IndexOperationRequest.Operation.Update) service.add(request, [refresh: "true"]) result = service.get(INDEX, TYPE, TEST_ID, null) - Assert.assertTrue(result.containsKey("from")) - Assert.assertTrue(result.containsKey("msg")) - Assert.assertEquals("Not the same after update.", merged, result) + assertTrue(result.containsKey("from")) + assertTrue(result.containsKey("msg")) + assertEquals(merged, result, "Not the same after update.") final String UPSERTED_ID = "upsert-ftw" Map upsertItems = new HashMap<>() @@ -660,17 +660,17 @@ class ElasticSearchClientService_IT { request = new IndexOperationRequest(INDEX, TYPE, UPSERTED_ID, upsertItems, IndexOperationRequest.Operation.Upsert) service.add(request, [refresh: "true"]) result = service.get(INDEX, TYPE, UPSERTED_ID, null) - Assert.assertEquals(upsertItems, result) + assertEquals(upsertItems, result) List deletes = new ArrayList<>() deletes.add(new IndexOperationRequest(INDEX, TYPE, TEST_ID, null, IndexOperationRequest.Operation.Delete)) deletes.add(new IndexOperationRequest(INDEX, TYPE, UPSERTED_ID, null, IndexOperationRequest.Operation.Delete)) - Assert.assertFalse(service.bulk(deletes, [refresh: "true"]).hasErrors()) + assertFalse(service.bulk(deletes, [refresh: "true"]).hasErrors()) waitForIndexRefresh() // wait 1s for index refresh (doesn't prevent GET but affects later tests using _search or _bulk) - ElasticsearchException ee = Assert.assertThrows(ElasticsearchException.class, { -> service.get(INDEX, TYPE, TEST_ID, null) }) - Assert.assertTrue(ee.isNotFound()) - ee = Assert.assertThrows(ElasticsearchException.class, { -> service.get(INDEX, TYPE, UPSERTED_ID, null) }) - Assert.assertTrue(ee.isNotFound()) + ElasticsearchException ee = assertThrows(ElasticsearchException.class, { -> service.get(INDEX, TYPE, TEST_ID, null) }) + assertTrue(ee.isNotFound()) + ee = assertThrows(ElasticsearchException.class, { -> service.get(INDEX, TYPE, UPSERTED_ID, null) }) + assertTrue(ee.isNotFound()) } @Test diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupServiceTest.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupServiceTest.groovy index 419ab757a9..de3e6ccfa8 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupServiceTest.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupServiceTest.groovy @@ -23,16 +23,19 @@ import org.apache.nifi.schema.access.SchemaAccessUtils import org.apache.nifi.serialization.record.MapRecord 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 static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertNotNull +import static org.junit.jupiter.api.Assertions.assertTrue class ElasticSearchLookupServiceTest { ElasticSearchClientService mockClientService ElasticSearchLookupService lookupService TestRunner runner - @Before + @BeforeEach void setup() throws Exception { mockClientService = new TestElasticSearchClientService() lookupService = new ElasticSearchLookupService() @@ -58,12 +61,12 @@ class ElasticSearchLookupServiceTest { Optional result = lookupService.lookup(coordinates) as Optional - Assert.assertNotNull(result) - Assert.assertTrue(result.isPresent()) + assertNotNull(result) + assertTrue(result.isPresent()) MapRecord record = result.get() - Assert.assertEquals("john.smith", record.getAsString("username")) - Assert.assertEquals("testing1234", record.getAsString("password")) - Assert.assertEquals("john.smith@test.com", record.getAsString("email")) - Assert.assertEquals("Software Engineer", record.getAsString("position")) + assertEquals("john.smith", record.getAsString("username")) + assertEquals("testing1234", record.getAsString("password")) + assertEquals("john.smith@test.com", record.getAsString("email")) + assertEquals("Software Engineer", record.getAsString("position")) } } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupService_IT.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupService_IT.groovy index d92aed34fb..c2ea2e257a 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupService_IT.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchLookupService_IT.groovy @@ -30,20 +30,23 @@ import org.apache.nifi.serialization.record.RecordSchema import org.apache.nifi.serialization.record.type.RecordDataType import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners -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.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test + +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertNotNull +import static org.junit.jupiter.api.Assertions.assertTrue +import static org.junit.jupiter.api.Assumptions.assumeTrue class ElasticSearchLookupService_IT { private TestRunner runner private ElasticSearchClientService service private ElasticSearchLookupService lookupService - @BeforeClass + @BeforeAll static void beforeAll() throws Exception { - Assume.assumeTrue("Elasticsearch integration-tests not setup", ElasticSearchClientService_IT.isElasticsearchSetup()) + assumeTrue(ElasticSearchClientService_IT.isElasticsearchSetup(), "Elasticsearch integration-tests not setup") System.out.println( String.format("%n%n%n%n%n%n%n%n%n%n%n%n%n%n%nTYPE: %s%nVERSION: %s%nFLAVOUR %s%n%n%n%n%n%n%n%n%n%n%n%n%n%n%n", @@ -51,7 +54,7 @@ class ElasticSearchLookupService_IT { ) } - @Before + @BeforeEach void before() throws Exception { runner = TestRunners.newTestRunner(TestControllerServiceProcessor.class) service = new ElasticSearchClientServiceImpl() @@ -104,12 +107,12 @@ class ElasticSearchLookupService_IT { def coordinates = [ _id: "2" ] Optional result = lookupService.lookup(coordinates) - Assert.assertNotNull(result) - Assert.assertTrue(result.isPresent()) + assertNotNull(result) + assertTrue(result.isPresent()) def record = result.get() - Assert.assertEquals("jane.doe@company.com", record.getAsString("email")) - Assert.assertEquals("098-765-4321", record.getAsString("phone")) - Assert.assertEquals("GHIJK", record.getAsString("accessKey")) + assertEquals("jane.doe@company.com", record.getAsString("email")) + assertEquals("098-765-4321", record.getAsString("phone")) + assertEquals("GHIJK", record.getAsString("accessKey")) } @Test @@ -132,8 +135,8 @@ class ElasticSearchLookupService_IT { exception = ex } - Assert.assertNotNull(exception) - Assert.assertTrue(exception instanceof LookupFailureException) + assertNotNull(exception) + assertTrue(exception instanceof LookupFailureException) } } @@ -142,12 +145,12 @@ class ElasticSearchLookupService_IT { def coordinates = [ "phone": "098-765-4321", "email": "jane.doe@company.com" ] Optional result = lookupService.lookup(coordinates) - Assert.assertNotNull(result) - Assert.assertTrue(result.isPresent()) + assertNotNull(result) + assertTrue(result.isPresent()) def record = result.get() - Assert.assertEquals("jane.doe@company.com", record.getAsString("email")) - Assert.assertEquals("098-765-4321", record.getAsString("phone")) - Assert.assertEquals("GHIJK", record.getAsString("accessKey")) + assertEquals("jane.doe@company.com", record.getAsString("email")) + assertEquals("098-765-4321", record.getAsString("phone")) + assertEquals("GHIJK", record.getAsString("accessKey")) } @Test @@ -164,17 +167,17 @@ class ElasticSearchLookupService_IT { runner.enableControllerService(lookupService) Optional response = lookupService.lookup(coordinates) - Assert.assertNotNull(response) - Assert.assertTrue(response.isPresent()) + assertNotNull(response) + assertTrue(response.isPresent()) def rec = response.get() - Assert.assertEquals("Hello, world", rec.getValue("msg")) + assertEquals("Hello, world", rec.getValue("msg")) def subRec = getSubRecord(rec, "subField") - Assert.assertNotNull(subRec) + assertNotNull(subRec) def deeper = getSubRecord(subRec, "deeper") - Assert.assertNotNull(deeper) + assertNotNull(deeper) def deepest = getSubRecord(deeper, "deepest") - Assert.assertNotNull(deepest) - Assert.assertEquals("The sky is blue", deepest.getAsString("super_secret")) + assertNotNull(deepest) + assertEquals("The sky is blue", deepest.getAsString("super_secret")) } @Test @@ -186,7 +189,7 @@ class ElasticSearchLookupService_IT { def coordinates = ["_id": "1" ] Optional response = lookupService.lookup(coordinates) - Assert.assertNotNull(response) + assertNotNull(response) Record rec = response.get() Record subRec = getSubRecord(rec, "subField") @@ -195,12 +198,12 @@ class ElasticSearchLookupService_IT { def result = path.evaluate(r2) result.selectedFields.findFirst().get().updateValue(1234567890L) - Assert.assertNotNull(rec) - Assert.assertNotNull(subRec) - Assert.assertEquals("Hello, world", rec.getValue("msg")) - Assert.assertNotNull(rec.getValue("subField")) - Assert.assertEquals(new Long(100000), subRec.getValue("longField")) - Assert.assertEquals("2018-04-10T12:18:05Z", subRec.getValue("dateField")) + assertNotNull(rec) + assertNotNull(subRec) + assertEquals("Hello, world", rec.getValue("msg")) + assertNotNull(rec.getValue("subField")) + assertEquals(new Long(100000), subRec.getValue("longField")) + assertEquals("2018-04-10T12:18:05Z", subRec.getValue("dateField")) } static Record getSubRecord(Record rec, String fieldName) { @@ -220,11 +223,11 @@ class ElasticSearchLookupService_IT { def coordinates = ["msg": "Hello, world"] def result = lookupService.lookup(coordinates) - Assert.assertTrue(result.isPresent()) + assertTrue(result.isPresent()) def rec = result.get() ["dateField2": "2018-08-14T10:08:00Z", "longField2": 150000L].each { field -> def value = rec.getValue(field.key) - Assert.assertEquals(field.value, value) + assertEquals(field.value, value) } } } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchStringLookupServiceTest.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchStringLookupServiceTest.groovy index f3ad4b9215..318d1b462f 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchStringLookupServiceTest.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service/src/test/groovy/org/apache/nifi/elasticsearch/integration/ElasticSearchStringLookupServiceTest.groovy @@ -21,16 +21,19 @@ import org.apache.nifi.elasticsearch.ElasticSearchClientService import org.apache.nifi.elasticsearch.ElasticSearchStringLookupService 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 static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertNotNull +import static org.junit.jupiter.api.Assertions.assertTrue class ElasticSearchStringLookupServiceTest { ElasticSearchClientService mockClientService ElasticSearchStringLookupService lookupService TestRunner runner - @Before + @BeforeEach void setup() throws Exception { mockClientService = new TestElasticSearchClientService() lookupService = new ElasticSearchStringLookupService() @@ -51,9 +54,9 @@ class ElasticSearchStringLookupServiceTest { Optional result = lookupService.lookup(coordinates) - Assert.assertNotNull(result) - Assert.assertTrue(result.isPresent()) + assertNotNull(result) + assertTrue(result.isPresent()) String json = result.get() - Assert.assertEquals('{"username":"john.smith","password":"testing1234","email":"john.smith@test.com","position":"Software Engineer"}', json) + assertEquals('{"username":"john.smith","password":"testing1234","email":"john.smith@test.com","position":"Software Engineer"}', json) } } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestFetchElasticsearchHttp.java b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestFetchElasticsearchHttp.java index df19461c89..54afba3332 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestFetchElasticsearchHttp.java +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestFetchElasticsearchHttp.java @@ -16,30 +16,6 @@ */ package org.apache.nifi.processors.elasticsearch; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.HashMap; - -import org.apache.nifi.processor.ProcessContext; -import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.ssl.SSLContextService; -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.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - import okhttp3.Call; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -48,25 +24,47 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.ssl.SSLContextService; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestFetchElasticsearchHttp { private InputStream docExample; private TestRunner runner; - @Before - public void setUp() throws IOException { + @BeforeEach + public void setUp() { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); docExample = classloader.getResourceAsStream("DocumentExample.json"); } - @After + @AfterEach public void teardown() { runner = null; } @Test - public void testFetchElasticsearchOnTriggerEL() throws IOException { + public void testFetchElasticsearchOnTriggerEL() { runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(true)); // all docs are found runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "${es.url}"); @@ -101,7 +99,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTrigger() throws IOException { + public void testFetchElasticsearchOnTrigger() { runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(true)); // all docs are found runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -124,7 +122,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTriggerNoType() throws IOException { + public void testFetchElasticsearchOnTriggerNoType() { final String ES_URL = "http://127.0.0.1:9200"; final String DOC_ID = "28039652140"; FetchElasticsearchHttpTestProcessor processor = new FetchElasticsearchHttpTestProcessor(true); @@ -146,13 +144,12 @@ public class TestFetchElasticsearchHttp { final MockFlowFile out = runner.getFlowFilesForRelationship(FetchElasticsearchHttp.REL_SUCCESS).get(0); assertNotNull(out); out.assertAttributeEquals("doc_id", DOC_ID); - assertEquals("URL doesn't match expected value when type is not supplied", - "http://127.0.0.1:9200" + "/doc/_all/" + DOC_ID, - processor.getURL().toString()); + assertEquals("http://127.0.0.1:9200" + "/doc/_all/" + DOC_ID, + processor.getURL().toString(), "URL doesn't match expected value when type is not supplied"); } @Test - public void testFetchElasticsearchOnTriggerWithFields() throws IOException { + public void testFetchElasticsearchOnTriggerWithFields() { runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(true)); // all docs are found runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -177,7 +174,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTriggerWithDocNotFound() throws IOException { + public void testFetchElasticsearchOnTriggerWithDocNotFound() { runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(false)); // simulate doc not found runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); runner.setProperty(FetchElasticsearchHttp.INDEX, "doc"); @@ -198,7 +195,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTriggerWithServerErrorRetry() throws IOException { + public void testFetchElasticsearchOnTriggerWithServerErrorRetry() { FetchElasticsearchHttpTestProcessor processor = new FetchElasticsearchHttpTestProcessor(false); processor.setStatus(500, "Server error"); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -220,7 +217,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTriggerWithServerFail() throws IOException { + public void testFetchElasticsearchOnTriggerWithServerFail() { FetchElasticsearchHttpTestProcessor processor = new FetchElasticsearchHttpTestProcessor(false); processor.setStatus(100, "Should fail"); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -242,7 +239,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTriggerWithServerFailNoIncomingFlowFile() throws IOException { + public void testFetchElasticsearchOnTriggerWithServerFailNoIncomingFlowFile() { FetchElasticsearchHttpTestProcessor processor = new FetchElasticsearchHttpTestProcessor(false); processor.setStatus(100, "Should fail"); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -260,7 +257,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchWithBadHosts() throws IOException { + public void testFetchElasticsearchWithBadHosts() { runner = TestRunners.newTestRunner(new FetchElasticsearchHttpTestProcessor(false)); // simulate doc not found runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "127.0.0.1:9200"); runner.setProperty(FetchElasticsearchHttp.INDEX, "doc"); @@ -295,7 +292,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTriggerQueryParameter() throws IOException { + public void testFetchElasticsearchOnTriggerQueryParameter() { FetchElasticsearchHttpTestProcessor p = new FetchElasticsearchHttpTestProcessor(true); // all docs are found p.setExpectedUrl("http://127.0.0.1:9200/doc/status/28039652140?_source=id&myparam=myvalue"); runner = TestRunners.newTestRunner(p); @@ -321,7 +318,7 @@ public class TestFetchElasticsearchHttp { } @Test - public void testFetchElasticsearchOnTriggerQueryParameterNoType() throws IOException { + public void testFetchElasticsearchOnTriggerQueryParameterNoType() { FetchElasticsearchHttpTestProcessor p = new FetchElasticsearchHttpTestProcessor(true); // all docs are found p.setExpectedUrl("http://127.0.0.1:9200/doc/_all/28039652140?_source=id&myparam=myvalue"); runner = TestRunners.newTestRunner(p); @@ -379,30 +376,26 @@ public class TestFetchElasticsearchHttp { protected void createElasticsearchClient(ProcessContext context) throws ProcessException { client = mock(OkHttpClient.class); - when(client.newCall(any(Request.class))).thenAnswer(new Answer() { - - @Override - public Call answer(InvocationOnMock invocationOnMock) throws Throwable { - Request realRequest = (Request) invocationOnMock.getArguments()[0]; - assertTrue((expectedUrl == null) || (expectedUrl.equals(realRequest.url().toString()))); - StringBuilder sb = new StringBuilder("{\"_index\":\"randomuser.me\",\"_type\":\"user\",\"_id\":\"0\",\"_version\":2,"); - if (documentExists) { - sb.append("\"found\":true,\"_source\":{\"gender\":\"female\",\"name\":{\"title\":\"Ms\",\"first\":\"Joan\",\"last\":\"Smith\"}}"); - } else { - sb.append("\"found\": false"); - } - sb.append("}"); - Response mockResponse = new Response.Builder() - .request(realRequest) - .protocol(Protocol.HTTP_1_1) - .code(statusCode) - .message(statusMessage) - .body(ResponseBody.create(MediaType.parse("application/json"), sb.toString())) - .build(); - final Call call = mock(Call.class); - when(call.execute()).thenReturn(mockResponse); - return call; + when(client.newCall(any(Request.class))).thenAnswer((Answer) invocationOnMock -> { + Request realRequest = (Request) invocationOnMock.getArguments()[0]; + assertTrue((expectedUrl == null) || (expectedUrl.equals(realRequest.url().toString()))); + StringBuilder sb = new StringBuilder("{\"_index\":\"randomuser.me\",\"_type\":\"user\",\"_id\":\"0\",\"_version\":2,"); + if (documentExists) { + sb.append("\"found\":true,\"_source\":{\"gender\":\"female\",\"name\":{\"title\":\"Ms\",\"first\":\"Joan\",\"last\":\"Smith\"}}"); + } else { + sb.append("\"found\": false"); } + sb.append("}"); + Response mockResponse = new Response.Builder() + .request(realRequest) + .protocol(Protocol.HTTP_1_1) + .code(statusCode) + .message(statusMessage) + .body(ResponseBody.create(MediaType.parse("application/json"), sb.toString())) + .build(); + final Call call = mock(Call.class); + when(call.execute()).thenReturn(mockResponse); + return call; }); } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttp.java b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttp.java index af2ec7d68c..3d2e4292aa 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttp.java +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttp.java @@ -16,29 +16,6 @@ */ package org.apache.nifi.processors.elasticsearch; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.net.ConnectException; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; - -import org.apache.commons.io.IOUtils; -import org.apache.nifi.processor.ProcessContext; -import org.apache.nifi.processor.exception.ProcessException; -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.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - import okhttp3.Call; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -46,25 +23,47 @@ import okhttp3.Protocol; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; +import org.apache.commons.io.IOUtils; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; + +import java.io.IOException; +import java.net.ConnectException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; + +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.Mockito.mock; +import static org.mockito.Mockito.when; public class TestPutElasticsearchHttp { private static byte[] docExample; private TestRunner runner; - @Before + @BeforeEach public void once() throws IOException { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); docExample = IOUtils.toString(classloader.getResourceAsStream("DocumentExample.json"), StandardCharsets.UTF_8).getBytes(); } - @After + @AfterEach public void teardown() { runner = null; } @Test - public void testPutElasticSearchOnTriggerIndex() throws IOException { + public void testPutElasticSearchOnTriggerIndex() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -85,7 +84,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerCreate() throws IOException { + public void testPutElasticSearchOnTriggerCreate() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -107,7 +106,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerIndex_withoutType() throws IOException { + public void testPutElasticSearchOnTriggerIndex_withoutType() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -128,7 +127,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerUpdate() throws IOException { + public void testPutElasticSearchOnTriggerUpdate() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -149,7 +148,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerDelete() throws IOException { + public void testPutElasticSearchOnTriggerDelete() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -170,7 +169,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerEL() throws IOException { + public void testPutElasticSearchOnTriggerEL() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "${es.url}"); @@ -196,7 +195,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerBadIndexOp() throws IOException { + public void testPutElasticSearchOnTriggerBadIndexOp() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -217,7 +216,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchInvalidConfig() throws IOException { + public void testPutElasticSearchInvalidConfig() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -235,7 +234,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerWithFailures() throws IOException { + public void testPutElasticSearchOnTriggerWithFailures() { PutElasticsearchTestProcessor processor = new PutElasticsearchTestProcessor(true); processor.setStatus(100, "Should fail"); runner = TestRunners.newTestRunner(processor); // simulate failures @@ -261,7 +260,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerWithConnectException() throws IOException { + public void testPutElasticSearchOnTriggerWithConnectException() { PutElasticsearchTestProcessor processor = new PutElasticsearchTestProcessor(true); processor.setStatus(-1, "Connection Exception"); runner = TestRunners.newTestRunner(processor); // simulate failures @@ -279,7 +278,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticsearchOnTriggerWithNoIdAttribute() throws IOException { + public void testPutElasticsearchOnTriggerWithNoIdAttribute() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(true)); // simulate failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); runner.setProperty(PutElasticsearchHttp.INDEX, "doc"); @@ -298,7 +297,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticsearchOnTriggerWithIndexFromAttribute() throws IOException { + public void testPutElasticsearchOnTriggerWithIndexFromAttribute() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); runner.setProperty(PutElasticsearchHttp.INDEX, "${i}"); @@ -331,7 +330,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerWithInvalidIndexOp() throws IOException { + public void testPutElasticSearchOnTriggerWithInvalidIndexOp() { runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -372,7 +371,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerQueryParameter() throws IOException { + public void testPutElasticSearchOnTriggerQueryParameter() { PutElasticsearchTestProcessor p = new PutElasticsearchTestProcessor(false); // no failures p.setExpectedUrl("http://127.0.0.1:9200/_bulk?pipeline=my-pipeline"); @@ -397,7 +396,7 @@ public class TestPutElasticsearchHttp { } @Test - public void testPutElasticSearchOnTriggerWithDocumentNotFound() throws IOException { + public void testPutElasticSearchOnTriggerWithDocumentNotFound() { PutElasticsearchTestProcessor processor = new PutElasticsearchTestProcessor(true); processor.setResultField("not_found"); runner = TestRunners.newTestRunner(processor); // simulate failures @@ -448,47 +447,43 @@ public class TestPutElasticsearchHttp { protected void createElasticsearchClient(ProcessContext context) throws ProcessException { client = mock(OkHttpClient.class); - when(client.newCall(any(Request.class))).thenAnswer(new Answer() { - - @Override - public Call answer(InvocationOnMock invocationOnMock) throws Throwable { - final Call call = mock(Call.class); - if (statusCode != -1) { - Request realRequest = (Request) invocationOnMock.getArguments()[0]; - assertTrue((expectedUrl == null) || (expectedUrl.equals(realRequest.url().toString()))); - StringBuilder sb = new StringBuilder("{\"took\": 1, \"errors\": \""); - sb.append(responseHasFailures); - sb.append("\", \"items\": ["); - if (responseHasFailures) { - // This case is for a status code of 200 for the bulk response itself, but with an error (of 400) inside - sb.append("{\"index\":{\"_index\":\"doc\",\"_type\":\"status\",\"_id\":\"28039652140\",\"status\":\"400\","); - if(resultField != null) { - sb.append("\"result\":{\"not_found\","); - } else { - sb.append("\"error\":{\"type\":\"mapper_parsing_exception\",\"reason\":\"failed to parse [gender]\","); - } - sb.append("\"caused_by\":{\"type\":\"json_parse_exception\",\"reason\":\"Unexpected end-of-input in VALUE_STRING\\n at "); - sb.append("[Source: org.elasticsearch.common.io.stream.InputStreamStreamInput@1a2e3ac4; line: 1, column: 39]\"}}}},"); + when(client.newCall(any(Request.class))).thenAnswer((Answer) invocationOnMock -> { + final Call call = mock(Call.class); + if (statusCode != -1) { + Request realRequest = (Request) invocationOnMock.getArguments()[0]; + assertTrue((expectedUrl == null) || (expectedUrl.equals(realRequest.url().toString()))); + StringBuilder sb = new StringBuilder("{\"took\": 1, \"errors\": \""); + sb.append(responseHasFailures); + sb.append("\", \"items\": ["); + if (responseHasFailures) { + // This case is for a status code of 200 for the bulk response itself, but with an error (of 400) inside + sb.append("{\"index\":{\"_index\":\"doc\",\"_type\":\"status\",\"_id\":\"28039652140\",\"status\":\"400\","); + if(resultField != null) { + sb.append("\"result\":{\"not_found\","); + } else { + sb.append("\"error\":{\"type\":\"mapper_parsing_exception\",\"reason\":\"failed to parse [gender]\","); } - sb.append("{\"index\":{\"_index\":\"doc\",\"_type\":\"status\",\"_id\":\"28039652140\",\"status\":"); - sb.append(statusCode); - sb.append(",\"_source\":{\"text\": \"This is a test document\"}}}"); - - sb.append("]}"); - Response mockResponse = new Response.Builder() - .request(realRequest) - .protocol(Protocol.HTTP_1_1) - .code(statusCode) - .message(statusMessage) - .body(ResponseBody.create(MediaType.parse("application/json"), sb.toString())) - .build(); - - when(call.execute()).thenReturn(mockResponse); - } else { - when(call.execute()).thenThrow(ConnectException.class); + sb.append("\"caused_by\":{\"type\":\"json_parse_exception\",\"reason\":\"Unexpected end-of-input in VALUE_STRING\\n at "); + sb.append("[Source: org.elasticsearch.common.io.stream.InputStreamStreamInput@1a2e3ac4; line: 1, column: 39]\"}}}},"); } - return call; + sb.append("{\"index\":{\"_index\":\"doc\",\"_type\":\"status\",\"_id\":\"28039652140\",\"status\":"); + sb.append(statusCode); + sb.append(",\"_source\":{\"text\": \"This is a test document\"}}}"); + + sb.append("]}"); + Response mockResponse = new Response.Builder() + .request(realRequest) + .protocol(Protocol.HTTP_1_1) + .code(statusCode) + .message(statusMessage) + .body(ResponseBody.create(MediaType.parse("application/json"), sb.toString())) + .build(); + + when(call.execute()).thenReturn(mockResponse); + } else { + when(call.execute()).thenThrow(ConnectException.class); } + return call; }); } @@ -497,4 +492,20 @@ public class TestPutElasticsearchHttp { return client; } } + + @Test + public void testPutElasticSearchBadHostInEL() { + runner = TestRunners.newTestRunner(new PutElasticsearchTestProcessor(false)); // no failures + runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "${es.url}"); + + runner.setProperty(PutElasticsearchHttp.INDEX, "doc"); + runner.setProperty(PutElasticsearchHttp.TYPE, "status"); + runner.setProperty(PutElasticsearchHttp.BATCH_SIZE, "1"); + runner.setProperty(PutElasticsearchHttp.ID_ATTRIBUTE, "doc_id"); + + runner.enqueue(docExample, new HashMap() {{ + put("doc_id", "28039652140"); + }}); + assertThrows(AssertionError.class, () -> runner.run(1, true, true)); + } } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttpRecord.java b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttpRecord.java index fd16b292fb..047ae521db 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttpRecord.java +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestPutElasticsearchHttpRecord.java @@ -36,8 +36,8 @@ 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.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigDecimal; @@ -56,10 +56,11 @@ import java.util.Map; import java.util.Objects; import java.util.function.Consumer; -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.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -79,7 +80,7 @@ public class TestPutElasticsearchHttpRecord { private TestRunner runner; - @After + @AfterEach public void teardown() { runner = null; } @@ -824,7 +825,7 @@ public class TestPutElasticsearchHttpRecord { } } - @Test(expected = AssertionError.class) + @Test public void testPutElasticSearchBadHostInEL() { final TestRunner runner = TestRunners.newTestRunner(new PutElasticsearchHttpRecord()); @@ -832,11 +833,16 @@ public class TestPutElasticsearchHttpRecord { runner.setProperty(PutElasticsearchHttpRecord.INDEX, "doc"); runner.setProperty(PutElasticsearchHttpRecord.TYPE, "status"); runner.setProperty(PutElasticsearchHttpRecord.ID_RECORD_PATH, "/id"); - runner.assertValid(); + assertThrows(AssertionError.class, () -> { + runner.assertValid(); + runner.enqueue(new byte[0], new HashMap() {{ + put("doc_id", "1"); + }}); - runner.enqueue(new byte[0], Collections.singletonMap("doc_id", "1")); + runner.enqueue(new byte[0], Collections.singletonMap("doc_id", "1")); - runner.run(); + runner.run(); + }); } private void generateTestData() throws IOException { diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttp.java b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttp.java index 0479d22df6..c072f2ada9 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttp.java +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttp.java @@ -16,32 +16,6 @@ */ package org.apache.nifi.processors.elasticsearch; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.nifi.processor.ProcessContext; -import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.ssl.SSLContextService; -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.Test; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.mockito.stubbing.OngoingStubbing; - import okhttp3.Call; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -49,18 +23,43 @@ import okhttp3.Protocol; import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; +import org.apache.commons.io.IOUtils; +import org.apache.nifi.processor.ProcessContext; +import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.ssl.SSLContextService; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; +import org.mockito.stubbing.OngoingStubbing; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; +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.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestQueryElasticsearchHttp { private TestRunner runner; - @After + @AfterEach public void teardown() { runner = null; } @Test - public void testQueryElasticsearchOnTrigger_withInput() throws IOException { + public void testQueryElasticsearchOnTrigger_withInput() { runner = TestRunners.newTestRunner(new QueryElasticsearchHttpTestProcessor()); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -78,7 +77,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTrigger_withInput_withQueryInAttrs() throws IOException { + public void testQueryElasticsearchOnTrigger_withInput_withQueryInAttrs() { runner = TestRunners.newTestRunner(new QueryElasticsearchHttpTestProcessor()); runner.setValidateExpressionUsage(true); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -97,7 +96,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTrigger_withInput_EL() throws IOException { + public void testQueryElasticsearchOnTrigger_withInput_EL() { runner = TestRunners.newTestRunner(new QueryElasticsearchHttpTestProcessor()); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "${es.url}"); @@ -126,7 +125,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTrigger_withInput_attributeTarget() throws IOException { + public void testQueryElasticsearchOnTrigger_withInput_attributeTarget() { runner = TestRunners.newTestRunner(new QueryElasticsearchHttpTestProcessor()); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -152,7 +151,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTrigger_withNoInput() throws IOException { + public void testQueryElasticsearchOnTrigger_withNoInput() { runner = TestRunners.newTestRunner(new QueryElasticsearchHttpTestProcessor()); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -197,7 +196,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTriggerWithFields() throws IOException { + public void testQueryElasticsearchOnTriggerWithFields() { runner = TestRunners.newTestRunner(new QueryElasticsearchHttpTestProcessor()); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -216,7 +215,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTriggerWithLimit() throws IOException { + public void testQueryElasticsearchOnTriggerWithLimit() { runner = TestRunners.newTestRunner(new QueryElasticsearchHttpTestProcessor()); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -236,7 +235,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTriggerWithServerErrorRetry() throws IOException { + public void testQueryElasticsearchOnTriggerWithServerErrorRetry() { QueryElasticsearchHttpTestProcessor processor = new QueryElasticsearchHttpTestProcessor(); processor.setStatus(500, "Server error"); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -261,7 +260,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTriggerWithServerFail() throws IOException { + public void testQueryElasticsearchOnTriggerWithServerFail() { QueryElasticsearchHttpTestProcessor processor = new QueryElasticsearchHttpTestProcessor(); processor.setStatus(100, "Should fail"); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -286,7 +285,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTriggerWithIOException() throws IOException { + public void testQueryElasticsearchOnTriggerWithIOException() { QueryElasticsearchHttpTestProcessor processor = new QueryElasticsearchHttpTestProcessor(); processor.setExceptionToThrow(new IOException("Error reading from disk")); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -311,7 +310,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTriggerWithServerFailAfterSuccess() throws IOException { + public void testQueryElasticsearchOnTriggerWithServerFailAfterSuccess() { QueryElasticsearchHttpTestProcessor processor = new QueryElasticsearchHttpTestProcessor(); processor.setStatus(100, "Should fail", 2); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -337,7 +336,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTriggerWithServerFailNoIncomingFlowFile() throws IOException { + public void testQueryElasticsearchOnTriggerWithServerFailNoIncomingFlowFile() { QueryElasticsearchHttpTestProcessor processor = new QueryElasticsearchHttpTestProcessor(); processor.setStatus(100, "Should fail", 1); runner = TestRunners.newTestRunner(processor); // simulate doc not found @@ -395,7 +394,7 @@ public class TestQueryElasticsearchHttp { } @Test - public void testQueryElasticsearchOnTrigger_sourceIncludes() throws IOException { + public void testQueryElasticsearchOnTrigger_sourceIncludes() { QueryElasticsearchHttpTestProcessor p = new QueryElasticsearchHttpTestProcessor(); p.setExpectedParam("_source=test"); runner = TestRunners.newTestRunner(p); @@ -486,27 +485,23 @@ public class TestQueryElasticsearchHttp { private OngoingStubbing mockReturnDocument(OngoingStubbing stub, final String document, int statusCode, String statusMessage) { - return stub.thenAnswer(new Answer() { - - @Override - public Call answer(InvocationOnMock invocationOnMock) throws Throwable { - Request realRequest = (Request) invocationOnMock.getArguments()[0]; - assertTrue((expectedParam == null) || (realRequest.url().toString().contains(expectedParam))); - Response mockResponse = new Response.Builder() - .request(realRequest) - .protocol(Protocol.HTTP_1_1) - .code(statusCode) - .message(statusMessage) - .body(ResponseBody.create(MediaType.parse("application/json"), document)) - .build(); - final Call call = mock(Call.class); - if (exceptionToThrow != null) { - when(call.execute()).thenThrow(exceptionToThrow); - } else { - when(call.execute()).thenReturn(mockResponse); - } - return call; + return stub.thenAnswer((Answer) invocationOnMock -> { + Request realRequest = (Request) invocationOnMock.getArguments()[0]; + assertTrue((expectedParam == null) || (realRequest.url().toString().contains(expectedParam))); + Response mockResponse = new Response.Builder() + .request(realRequest) + .protocol(Protocol.HTTP_1_1) + .code(statusCode) + .message(statusMessage) + .body(ResponseBody.create(MediaType.parse("application/json"), document)) + .build(); + final Call call = mock(Call.class); + if (exceptionToThrow != null) { + when(call.execute()).thenThrow(exceptionToThrow); + } else { + when(call.execute()).thenReturn(mockResponse); } + return call; }); } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java index 6b6d906c1f..4f8d4d0a36 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestQueryElasticsearchHttpNoHits.java @@ -16,17 +16,6 @@ */ package org.apache.nifi.processors.elasticsearch; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; import okhttp3.Call; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -40,18 +29,28 @@ import org.apache.nifi.processor.exception.ProcessException; 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.Test; -import org.mockito.invocation.InvocationOnMock; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.mockito.stubbing.OngoingStubbing; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class TestQueryElasticsearchHttpNoHits { private TestRunner runner; - @After + @AfterEach public void teardown() { runner = null; } @@ -257,7 +256,7 @@ public class TestQueryElasticsearchHttpNoHits { if (expectHitCountOnQueryInfo) { out.assertAttributeEquals("es.query.hitcount", String.valueOf(expectedHits)); } - Assert.assertTrue(out.getAttribute("es.query.url").startsWith("http://127.0.0.1:9200/doc/status/_search?q=source%3ATwitter%20AND%20identifier%3A%22%22&size=2")); + assertTrue(out.getAttribute("es.query.url").startsWith("http://127.0.0.1:9200/doc/status/_search?q=source%3ATwitter%20AND%20identifier%3A%22%22&size=2")); } } } @@ -377,27 +376,23 @@ public class TestQueryElasticsearchHttpNoHits { private OngoingStubbing mockReturnDocument(OngoingStubbing stub, final String document, int statusCode, String statusMessage) { - return stub.thenAnswer(new Answer() { - - @Override - public Call answer(InvocationOnMock invocationOnMock) throws Throwable { - Request realRequest = (Request) invocationOnMock.getArguments()[0]; - assertTrue((expectedParam == null) || (realRequest.url().toString().endsWith(expectedParam))); - Response mockResponse = new Response.Builder() - .request(realRequest) - .protocol(Protocol.HTTP_1_1) - .code(statusCode) - .message(statusMessage) - .body(ResponseBody.create(MediaType.parse("application/json"), document)) - .build(); - final Call call = mock(Call.class); - if (exceptionToThrow != null) { - when(call.execute()).thenThrow(exceptionToThrow); - } else { - when(call.execute()).thenReturn(mockResponse); - } - return call; + return stub.thenAnswer((Answer) invocationOnMock -> { + Request realRequest = (Request) invocationOnMock.getArguments()[0]; + assertTrue((expectedParam == null) || (realRequest.url().toString().endsWith(expectedParam))); + Response mockResponse = new Response.Builder() + .request(realRequest) + .protocol(Protocol.HTTP_1_1) + .code(statusCode) + .message(statusMessage) + .body(ResponseBody.create(MediaType.parse("application/json"), document)) + .build(); + final Call call = mock(Call.class); + if (exceptionToThrow != null) { + when(call.execute()).thenThrow(exceptionToThrow); + } else { + when(call.execute()).thenReturn(mockResponse); } + return call; }); } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestScrollElasticsearchHttp.java b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestScrollElasticsearchHttp.java index f790256de8..c2ab44679f 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestScrollElasticsearchHttp.java +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-processors/src/test/java/org/apache/nifi/processors/elasticsearch/TestScrollElasticsearchHttp.java @@ -16,18 +16,13 @@ */ package org.apache.nifi.processors.elasticsearch; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; - +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Protocol; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.nifi.processor.ProcessContext; @@ -36,32 +31,35 @@ import org.apache.nifi.ssl.SSLContextService; 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.Test; -import org.mockito.invocation.InvocationOnMock; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.mockito.stubbing.OngoingStubbing; -import okhttp3.Call; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Protocol; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.ResponseBody; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.HashMap; +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.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestScrollElasticsearchHttp { private TestRunner runner; - @After + @AfterEach public void teardown() { runner = null; } @Test - public void testScrollElasticsearchOnTrigger_withNoInput() throws IOException { + public void testScrollElasticsearchOnTrigger_withNoInput() { runner = TestRunners.newTestRunner(new ScrollElasticsearchHttpTestProcessor()); runner.setProperty(AbstractElasticsearchHttpProcessor.ES_URL, "http://127.0.0.1:9200"); @@ -137,7 +135,7 @@ public class TestScrollElasticsearchHttp { return StringUtils.countMatches(page, "{\"timestamp\""); }) .reduce((a, b) -> a + b).get(); - Assert.assertEquals(3, numHits); + assertEquals(3, numHits); } @Test @@ -426,29 +424,25 @@ public class TestScrollElasticsearchHttp { private OngoingStubbing mockReturnDocument(OngoingStubbing stub, final String document, int statusCode, String statusMessage) { - return stub.thenAnswer(new Answer() { - - @Override - public Call answer(InvocationOnMock invocationOnMock) throws Throwable { - Request realRequest = (Request) invocationOnMock.getArguments()[0]; - if (realRequest.method().equals("GET")) { - assertTrue((expectedParam == null) || (realRequest.url().toString().contains(expectedParam))); - } - Response mockResponse = new Response.Builder() - .request(realRequest) - .protocol(Protocol.HTTP_1_1) - .code(statusCode) - .message(statusMessage) - .body(ResponseBody.create(MediaType.parse("application/json"), document)) - .build(); - final Call call = mock(Call.class); - if (exceptionToThrow != null) { - when(call.execute()).thenThrow(exceptionToThrow); - } else { - when(call.execute()).thenReturn(mockResponse); - } - return call; + return stub.thenAnswer((Answer) invocationOnMock -> { + Request realRequest = (Request) invocationOnMock.getArguments()[0]; + if (realRequest.method().equals("GET")) { + assertTrue((expectedParam == null) || (realRequest.url().toString().contains(expectedParam))); } + Response mockResponse = new Response.Builder() + .request(realRequest) + .protocol(Protocol.HTTP_1_1) + .code(statusCode) + .message(statusMessage) + .body(ResponseBody.create(MediaType.parse("application/json"), document)) + .build(); + final Call call = mock(Call.class); + if (exceptionToThrow != null) { + when(call.execute()).thenThrow(exceptionToThrow); + } else { + when(call.execute()).thenReturn(mockResponse); + } + return call; }); } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractByQueryElasticsearchTest.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractByQueryElasticsearchTest.groovy index 33be374750..05844679b5 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractByQueryElasticsearchTest.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractByQueryElasticsearchTest.groovy @@ -19,8 +19,11 @@ package org.apache.nifi.processors.elasticsearch import org.apache.nifi.util.MockFlowFile import org.apache.nifi.util.TestRunner -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 +import static org.junit.jupiter.api.Assertions.assertTrue abstract class AbstractByQueryElasticsearchTest { private static final String INDEX = "test_idx" @@ -53,10 +56,10 @@ abstract class AbstractByQueryElasticsearchTest { final List flowFiles = runner.getFlowFilesForRelationship(AbstractByQueryElasticsearch.REL_SUCCESS) final String attr = flowFiles.get(0).getAttribute(tookAttr()) final String query = flowFiles.get(0).getAttribute(queryAttr()) - Assert.assertNotNull(attr) - Assert.assertEquals(attr, "100") - Assert.assertNotNull(query) - Assert.assertEquals(queryParam, query) + assertNotNull(attr) + assertEquals(attr, "100") + assertNotNull(query) + assertEquals(queryParam, query) } @Test @@ -73,7 +76,7 @@ abstract class AbstractByQueryElasticsearchTest { postTest(runner, query) - Assert.assertTrue(client.getRequestParameters().isEmpty()) + assertTrue(client.getRequestParameters().isEmpty()) } @Test @@ -92,9 +95,9 @@ abstract class AbstractByQueryElasticsearchTest { postTest(runner, query) - Assert.assertEquals(2, client.getRequestParameters().size()) - Assert.assertEquals("true", client.getRequestParameters().get("refresh")) - Assert.assertEquals("auto", client.getRequestParameters().get("slices")) + assertEquals(2, client.getRequestParameters().size()) + assertEquals("true", client.getRequestParameters().get("refresh")) + assertEquals("auto", client.getRequestParameters().get("slices")) } @Test @@ -156,7 +159,7 @@ abstract class AbstractByQueryElasticsearchTest { final MockFlowFile mockFlowFile = runner.getFlowFilesForRelationship(AbstractByQueryElasticsearch.REL_FAILURE).get(0) final String attr = mockFlowFile.getAttribute(errorAttr()) - Assert.assertNotNull(attr) + assertNotNull(attr) } @Test @@ -190,7 +193,7 @@ abstract class AbstractByQueryElasticsearchTest { postTest(runner, query) - Assert.assertTrue(client.getRequestParameters().isEmpty()) + assertTrue(client.getRequestParameters().isEmpty()) } @Test @@ -211,8 +214,8 @@ abstract class AbstractByQueryElasticsearchTest { postTest(runner, query) - Assert.assertEquals(2, client.getRequestParameters().size()) - Assert.assertEquals("true", client.getRequestParameters().get("refresh")) - Assert.assertEquals("auto", client.getRequestParameters().get("slices")) + assertEquals(2, client.getRequestParameters().size()) + assertEquals("true", client.getRequestParameters().get("refresh")) + assertEquals("auto", client.getRequestParameters().get("slices")) } } diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractJsonQueryElasticsearchTest.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractJsonQueryElasticsearchTest.groovy index b33f94456c..a914b8e433 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractJsonQueryElasticsearchTest.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/AbstractJsonQueryElasticsearchTest.groovy @@ -23,15 +23,16 @@ import org.apache.nifi.provenance.ProvenanceEventType 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 static groovy.json.JsonOutput.prettyPrint import static groovy.json.JsonOutput.toJson import static org.hamcrest.CoreMatchers.equalTo import static org.hamcrest.CoreMatchers.is import static org.hamcrest.MatcherAssert.assertThat -import static org.junit.Assert.assertThrows +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertNotNull +import static org.junit.jupiter.api.Assertions.assertThrows abstract class AbstractJsonQueryElasticsearchTest

{ static final String INDEX_NAME = "messages" @@ -292,8 +293,8 @@ abstract class AbstractJsonQueryElasticsearchTest

ProvenanceEventType.SEND == e.getEventType() && e.getDetails() == null }).count() @@ -108,7 +109,7 @@ class PutElasticsearchJsonTest { @Test void simpleTest() { def evalParametersClosure = { Map params -> - Assert.assertTrue(params.isEmpty()) + assertTrue(params.isEmpty()) } clientService.evalParametersClosure = evalParametersClosure @@ -123,9 +124,9 @@ class PutElasticsearchJsonTest { runner.assertValid() def evalParametersClosure = { Map params -> - Assert.assertEquals(2, params.size()) - Assert.assertEquals("true", params.get("refresh")) - Assert.assertEquals("auto", params.get("slices")) + assertEquals(2, params.size()) + assertEquals("true", params.get("refresh")) + assertEquals("auto", params.get("slices")) } clientService.evalParametersClosure = evalParametersClosure @@ -135,10 +136,10 @@ class PutElasticsearchJsonTest { int indexCount = items.findAll { it.index == "test_index" }.size() int typeCount = items.findAll { it.type == "test_type" }.size() int opCount = items.findAll { it.operation == IndexOperationRequest.Operation.Index }.size() - Assert.assertEquals(1, idCount) - Assert.assertEquals(1, indexCount) - Assert.assertEquals(1, typeCount) - Assert.assertEquals(1, opCount) + assertEquals(1, idCount) + assertEquals(1, indexCount) + assertEquals(1, typeCount) + assertEquals(1, opCount) } clientService.evalClosure = evalClosure @@ -153,9 +154,9 @@ class PutElasticsearchJsonTest { runner.assertValid() def evalParametersClosure = { Map params -> - Assert.assertEquals(2, params.size()) - Assert.assertEquals("true", params.get("refresh")) - Assert.assertEquals("auto", params.get("slices")) + assertEquals(2, params.size()) + assertEquals("true", params.get("refresh")) + assertEquals("auto", params.get("slices")) } clientService.evalParametersClosure = evalParametersClosure @@ -179,8 +180,8 @@ class PutElasticsearchJsonTest { void testInvalidIndexOperation() { runner.setProperty(PutElasticsearchJson.INDEX_OP, "not-valid") runner.assertNotValid() - final AssertionError ae = Assert.assertThrows(AssertionError.class, runner.&run) - Assert.assertEquals(String.format("Processor has 1 validation failures:\n'%s' validated against 'not-valid' is invalid because %s must be Expression Language or one of %s\n", + final AssertionError ae = assertThrows(AssertionError.class, runner.&run) + assertEquals(String.format("Processor has 1 validation failures:\n'%s' validated against 'not-valid' is invalid because %s must be Expression Language or one of %s\n", PutElasticsearchJson.INDEX_OP.getName(), PutElasticsearchJson.INDEX_OP.getDisplayName(), PutElasticsearchJson.ALLOWED_INDEX_OPERATIONS), ae.getMessage() ) @@ -234,7 +235,7 @@ class PutElasticsearchJsonTest { runner.assertTransferCount(PutElasticsearchJson.REL_FAILURE, 0) runner.assertTransferCount(PutElasticsearchJson.REL_FAILED_DOCUMENTS, 1) assertThat(runner.getFlowFilesForRelationship(PutElasticsearchJson.REL_FAILED_DOCUMENTS)[0].getContent(), containsString("20abcd")) - Assert.assertEquals(1, + assertEquals(1, runner.getProvenanceEvents().stream().filter({ e -> ProvenanceEventType.SEND == e.getEventType() && "Elasticsearch _bulk operation error" == e.getDetails() }).count() @@ -258,7 +259,7 @@ class PutElasticsearchJsonTest { runner.assertTransferCount(PutElasticsearchJson.REL_FAILED_DOCUMENTS, 2) assertThat(runner.getFlowFilesForRelationship(PutElasticsearchJson.REL_FAILED_DOCUMENTS)[0].getContent(), containsString("not_found")) assertThat(runner.getFlowFilesForRelationship(PutElasticsearchJson.REL_FAILED_DOCUMENTS)[1].getContent(), containsString("20abcd")) - Assert.assertEquals(2, + assertEquals(2, runner.getProvenanceEvents().stream().filter({ e -> ProvenanceEventType.SEND == e.getEventType() && "Elasticsearch _bulk operation error" == e.getDetails() }).count() diff --git a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy index 50167ff9e0..c81539ffb3 100644 --- a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy +++ b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy @@ -34,9 +34,8 @@ 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.Before -import org.junit.Test +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.sql.Date import java.sql.Time @@ -48,6 +47,7 @@ import java.time.format.DateTimeFormatter import static groovy.json.JsonOutput.prettyPrint import static groovy.json.JsonOutput.toJson +import static org.junit.jupiter.api.Assertions.* class PutElasticsearchRecordTest { private static final int DATE_YEAR = 2020 @@ -82,7 +82,7 @@ class PutElasticsearchRecordTest { static final String flowFileContents = prettyPrint(toJson(flowFileContentMaps)) - @Before + @BeforeEach void setup() { clientService = new MockBulkLoadClientService() registry = new MockSchemaRegistry() @@ -118,10 +118,10 @@ class PutElasticsearchRecordTest { int indexCount = items.findAll { it.index == "test_index" }.size() int typeCount = items.findAll { it.type == "test_type" }.size() int opCount = items.findAll { it.operation == IndexOperationRequest.Operation.Index }.size() - Assert.assertEquals(2, timestampDefaultCount) - Assert.assertEquals(2, indexCount) - Assert.assertEquals(2, typeCount) - Assert.assertEquals(2, opCount) + assertEquals(2, timestampDefaultCount) + assertEquals(2, indexCount) + assertEquals(2, typeCount) + assertEquals(2, opCount) } basicTest(failure, retry, success, evalClosure) @@ -149,7 +149,7 @@ class PutElasticsearchRecordTest { ff.assertAttributeEquals("elasticsearch.put.error.count", "0") }) - Assert.assertEquals(success, + assertEquals(success, runner.getProvenanceEvents().stream().filter({ e -> ProvenanceEventType.SEND == e.getEventType() && e.getDetails() == "1 Elasticsearch _bulk operation batch(es) [0 error(s), 0 success(es)]" }).count() @@ -160,7 +160,7 @@ class PutElasticsearchRecordTest { @Test void simpleTest() { def evalParametersClosure = { Map params -> - Assert.assertTrue(params.isEmpty()) + assertTrue(params.isEmpty()) } clientService.evalParametersClosure = evalParametersClosure @@ -171,7 +171,7 @@ class PutElasticsearchRecordTest { void simpleTestCoercedDefaultTimestamp() { def evalClosure = { List items -> int timestampDefault = items.findAll { it.fields.get("@timestamp") == 100L }.size() - Assert.assertEquals(2, timestampDefault) + assertEquals(2, timestampDefault) } runner.setProperty(PutElasticsearchRecord.AT_TIMESTAMP, "100") @@ -186,9 +186,9 @@ class PutElasticsearchRecordTest { runner.assertValid() def evalParametersClosure = { Map params -> - Assert.assertEquals(2, params.size()) - Assert.assertEquals("true", params.get("refresh")) - Assert.assertEquals("auto", params.get("slices")) + assertEquals(2, params.size()) + assertEquals("true", params.get("refresh")) + assertEquals("auto", params.get("slices")) } clientService.evalParametersClosure = evalParametersClosure @@ -203,9 +203,9 @@ class PutElasticsearchRecordTest { runner.assertValid() def evalParametersClosure = { Map params -> - Assert.assertEquals(2, params.size()) - Assert.assertEquals("true", params.get("refresh")) - Assert.assertEquals("auto", params.get("slices")) + assertEquals(2, params.size()) + assertEquals("true", params.get("refresh")) + assertEquals("auto", params.get("slices")) } clientService.evalParametersClosure = evalParametersClosure @@ -282,21 +282,22 @@ class PutElasticsearchRecordTest { int ts = items.findAll { it.fields.get("ts") != null }.size() int id = items.findAll { it.fields.get("id") != null }.size() items.each { - Assert.assertNotNull(it.id) - Assert.assertTrue(it.id.startsWith("rec-")) - Assert.assertEquals("message", it.type) + assertNotNull(it.id) + assertTrue(it.id.startsWith("rec-")) + assertEquals("message", it.type) } - Assert.assertEquals(3, a) - Assert.assertEquals(3, b) - Assert.assertEquals(5, index) - Assert.assertEquals(1, create) - Assert.assertEquals(4, msg) - Assert.assertEquals(1, empties) - Assert.assertEquals(1, nulls) - Assert.assertEquals(1, timestamp) - Assert.assertEquals(5, timestampDefault) - Assert.assertEquals(0, ts) - Assert.assertEquals(0, id) + + assertEquals(3, a) + assertEquals(3, b) + assertEquals(5, index) + assertEquals(1, create) + assertEquals(4, msg) + assertEquals(1, empties) + assertEquals(1, nulls) + assertEquals(1, timestamp) + assertEquals(5, timestampDefault) + assertEquals(0, ts) + assertEquals(0, id) } clientService.evalClosure = evalClosure @@ -344,16 +345,16 @@ class PutElasticsearchRecordTest { int dateCount = items.findAll { it.fields.get("date") != null }.size() def idCount = items.findAll { it.fields.get("id") != null }.size() def defaultCoercedTimestampCount = items.findAll { it.fields.get("@timestamp") == 100L }.size() - Assert.assertEquals(5, testTypeCount) - Assert.assertEquals(1, messageTypeCount) - Assert.assertEquals(5, testIndexCount) - Assert.assertEquals(1, bulkIndexCount) - Assert.assertEquals(5, indexOperationCount) - Assert.assertEquals(1, updateOperationCount) - Assert.assertEquals(1, timestampCount) - Assert.assertEquals(5, defaultCoercedTimestampCount) - Assert.assertEquals(1, dateCount) - Assert.assertEquals(6, idCount) + assertEquals(5, testTypeCount) + assertEquals(1, messageTypeCount) + assertEquals(5, testIndexCount) + assertEquals(1, bulkIndexCount) + assertEquals(5, indexOperationCount) + assertEquals(1, updateOperationCount) + assertEquals(1, timestampCount) + assertEquals(5, defaultCoercedTimestampCount) + assertEquals(1, dateCount) + assertEquals(6, idCount) } clientService.evalClosure = evalClosure @@ -394,11 +395,11 @@ class PutElasticsearchRecordTest { def timestampCount = items.findAll { it.fields.get("@timestamp") == LOCAL_TIME.format(DateTimeFormatter.ofPattern(RecordFieldType.TIME.getDefaultFormat())) }.size() - Assert.assertEquals("null type", 5, nullTypeCount) - Assert.assertEquals("message type", 1, messageTypeCount) - Assert.assertEquals("null id", 2, nullIdCount) - Assert.assertEquals("rec- id", 4, recIdCount) - Assert.assertEquals("@timestamp", 1, timestampCount) + assertEquals(5, nullTypeCount, "null type") + assertEquals(1, messageTypeCount, "message type") + assertEquals(2, nullIdCount, "null id") + assertEquals(4, recIdCount, "rec- id",) + assertEquals(1, timestampCount, "@timestamp") } clientService.evalClosure = evalClosure @@ -436,13 +437,13 @@ class PutElasticsearchRecordTest { int delete = items.findAll { it.operation == IndexOperationRequest.Operation.Delete }.size() def timestampCount = items.findAll { it.fields.get("@timestamp") == 101L }.size() def noTimestampCount = items.findAll { it.fields.get("@timestamp") == null }.size() - Assert.assertEquals(1, index) - Assert.assertEquals(2, create) - Assert.assertEquals(1, update) - Assert.assertEquals(1, upsert) - Assert.assertEquals(1, delete) - Assert.assertEquals(1, timestampCount) - Assert.assertEquals(5, noTimestampCount) + assertEquals(1, index) + assertEquals(2, create) + assertEquals(1, update) + assertEquals(1, upsert) + assertEquals(1, delete) + assertEquals(1, timestampCount) + assertEquals(5, noTimestampCount) } runner.setProperty(PutElasticsearchRecord.AT_TIMESTAMP_RECORD_PATH, "/code") @@ -464,7 +465,7 @@ class PutElasticsearchRecordTest { clientService.evalClosure = { List items -> def timestampCount = items.findAll { it.fields.get("@timestamp") == "Hello" }.size() - Assert.assertEquals(1, timestampCount) + assertEquals(1, timestampCount) } runner.setProperty(PutElasticsearchRecord.AT_TIMESTAMP_RECORD_PATH, "/msg") @@ -526,17 +527,17 @@ class PutElasticsearchRecordTest { int dateNull = items.findAll { it.fields.get("date") == null }.size() int timeNull = items.findAll { it.fields.get("time") == null }.size() int choiceTsNull = items.findAll { it.fields.get("choice_ts") == null }.size() - Assert.assertEquals(5, msg) - Assert.assertEquals(2, timestamp) - Assert.assertEquals(2, date) - Assert.assertEquals(2, time) - Assert.assertEquals(1, choiceTs) - Assert.assertEquals(1, choiceNotTs) - Assert.assertEquals(3, tsNull) - Assert.assertEquals(3, dateNull) - Assert.assertEquals(3, timeNull) - Assert.assertEquals(3, choiceTsNull) - Assert.assertEquals(5, atTimestampDefault) + assertEquals(5, msg) + assertEquals(2, timestamp) + assertEquals(2, date) + assertEquals(2, time) + assertEquals(1, choiceTs) + assertEquals(1, choiceNotTs) + assertEquals(3, tsNull) + assertEquals(3, dateNull) + assertEquals(3, timeNull) + assertEquals(3, choiceTsNull) + assertEquals(5, atTimestampDefault) } clientService.evalClosure = evalClosure @@ -575,18 +576,18 @@ class PutElasticsearchRecordTest { int dateNull = items.findAll { it.fields.get("date") == null }.size() int timeNull = items.findAll { it.fields.get("time") == null }.size() int choiceTsNull = items.findAll { it.fields.get("choice_ts") == null }.size() - Assert.assertEquals(5, msg) - Assert.assertEquals(2, timestamp) - Assert.assertEquals(2, date) - Assert.assertEquals(2, time) - Assert.assertEquals(1, choiceTs) - Assert.assertEquals(1, choiceNotTs) - Assert.assertEquals(3, tsNull) - Assert.assertEquals(3, dateNull) - Assert.assertEquals(3, timeNull) - Assert.assertEquals(3, choiceTsNull) - Assert.assertEquals(2, atTimestamp) - Assert.assertEquals(3, atTimestampDefault) + assertEquals(5, msg) + assertEquals(2, timestamp) + assertEquals(2, date) + assertEquals(2, time) + assertEquals(1, choiceTs) + assertEquals(1, choiceNotTs) + assertEquals(3, tsNull) + assertEquals(3, dateNull) + assertEquals(3, timeNull) + assertEquals(3, choiceTsNull) + assertEquals(2, atTimestamp) + assertEquals(3, atTimestampDefault) } clientService.evalClosure = evalClosure @@ -613,8 +614,8 @@ class PutElasticsearchRecordTest { void testInvalidIndexOperation() { runner.setProperty(PutElasticsearchRecord.INDEX_OP, "not-valid") runner.assertNotValid() - final AssertionError ae = Assert.assertThrows(AssertionError.class, runner.&run) - Assert.assertEquals(String.format("Processor has 1 validation failures:\n'%s' validated against 'not-valid' is invalid because %s must be Expression Language or one of %s\n", + final AssertionError ae = assertThrows(AssertionError.class, runner.&run) + assertEquals(String.format("Processor has 1 validation failures:\n'%s' validated against 'not-valid' is invalid because %s must be Expression Language or one of %s\n", PutElasticsearchRecord.INDEX_OP.getName(), PutElasticsearchRecord.INDEX_OP.getDisplayName(), PutElasticsearchRecord.ALLOWED_INDEX_OPERATIONS), ae.getMessage() ) @@ -689,7 +690,7 @@ class PutElasticsearchRecordTest { runner.getFlowFilesForRelationship(PutElasticsearchRecord.REL_SUCCESSFUL_RECORDS)[0] .assertAttributeEquals(PutElasticsearchRecord.ATTR_RECORD_COUNT, "4") - Assert.assertEquals(1, + assertEquals(1, runner.getProvenanceEvents().stream().filter({ e -> ProvenanceEventType.SEND == e.getEventType() && e.getDetails() == "1 Elasticsearch _bulk operation batch(es) [1 error(s), 4 success(es)]" }).count() @@ -715,7 +716,7 @@ class PutElasticsearchRecordTest { runner.getFlowFilesForRelationship(PutElasticsearchRecord.REL_SUCCESSFUL_RECORDS)[0] .assertAttributeEquals(PutElasticsearchRecord.ATTR_RECORD_COUNT, "3") - Assert.assertEquals(1, + assertEquals(1, runner.getProvenanceEvents().stream().filter({ e -> ProvenanceEventType.SEND == e.getEventType() && e.getDetails() == "1 Elasticsearch _bulk operation batch(es) [2 error(s), 3 success(es)]" }).count() @@ -736,7 +737,7 @@ class PutElasticsearchRecordTest { runner.assertTransferCount(PutElasticsearchRecord.REL_FAILED_RECORDS, 0) runner.assertTransferCount(PutElasticsearchRecord.REL_SUCCESSFUL_RECORDS, 0) - Assert.assertEquals(1, + assertEquals(1, runner.getProvenanceEvents().stream().filter({ e -> ProvenanceEventType.SEND == e.getEventType() && e.getDetails() == "1 Elasticsearch _bulk operation batch(es) [1 error(s), 4 success(es)]" }).count() diff --git a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java index b15deff909..b5ff23b343 100644 --- a/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java +++ b/nifi-nar-bundles/nifi-graph-bundle/nifi-other-graph-services/src/test/java/org/apache/nifi/graph/OpenCypherClientServiceIT.java @@ -20,12 +20,7 @@ package org.apache.nifi.graph; import org.apache.nifi.util.NoOpProcessor; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.neo4j.driver.v1.Driver; @@ -38,6 +33,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + /* * To run this, setup JanusGraph using just the BerkeleyJE configuration for the server. * @@ -64,7 +62,7 @@ public class OpenCypherClientServiceIT { runner.enableControllerService(service); runner.assertValid(); - Assertions.assertEquals("gremlin://localhost:8182/gremlin", service.getTransitUrl()); + assertEquals("gremlin://localhost:8182/gremlin", service.getTransitUrl()); driver = GremlinDatabase.driver("//localhost:8182"); executeSession("MATCH (n) detach delete n"); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java index ed437c8f0e..6cadcf65cb 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/DeleteMongoIT.java @@ -24,13 +24,14 @@ import org.apache.nifi.mongodb.MongoDBControllerService; import org.apache.nifi.util.TestRunner; import org.bson.Document; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class DeleteMongoIT extends MongoWriteTestBase { @BeforeEach public void setup() { @@ -49,7 +50,7 @@ public class DeleteMongoIT extends MongoWriteTestBase { runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); - Assertions.assertEquals(0, collection.countDocuments(Document.parse(query)), + assertEquals(0, collection.countDocuments(Document.parse(query)), "Found a document that should have been deleted."); } @@ -73,8 +74,8 @@ public class DeleteMongoIT extends MongoWriteTestBase { runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); - Assertions.assertEquals(0, collection.countDocuments(Document.parse(query)), "Found a document that should have been deleted."); - Assertions.assertEquals(1, collection.countDocuments(Document.parse("{}")), "One document should have been left."); + assertEquals(0, collection.countDocuments(Document.parse(query)), "Found a document that should have been deleted."); + assertEquals(1, collection.countDocuments(Document.parse("{}")), "One document should have been left."); } @Test @@ -106,7 +107,7 @@ public class DeleteMongoIT extends MongoWriteTestBase { runner.assertTransferCount(DeleteMongo.REL_FAILURE, 1); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 0); - Assertions.assertEquals(3, collection.countDocuments(Document.parse("{}")), "A document was deleted"); + assertEquals(3, collection.countDocuments(Document.parse("{}")), "A document was deleted"); runner.setProperty(DeleteMongo.FAIL_ON_NO_DELETE, DeleteMongo.NO_FAIL); runner.clearTransferState(); @@ -117,7 +118,7 @@ public class DeleteMongoIT extends MongoWriteTestBase { runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); - Assertions.assertEquals(3, collection.countDocuments(Document.parse("{}")), "A document was deleted"); + assertEquals(3, collection.countDocuments(Document.parse("{}")), "A document was deleted"); } @Test @@ -137,6 +138,6 @@ public class DeleteMongoIT extends MongoWriteTestBase { runner.assertTransferCount(DeleteMongo.REL_SUCCESS, 1); runner.assertTransferCount(DeleteMongo.REL_FAILURE, 0); - Assertions.assertEquals(0, collection.countDocuments()); + assertEquals(0, collection.countDocuments()); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java index 7addf31363..6f5207c59f 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/GetMongoIT.java @@ -35,7 +35,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,6 +49,12 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; +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; + public class GetMongoIT { private static final String MONGO_URI = "mongodb://localhost"; private static final String DB_NAME = GetMongoIT.class.getSimpleName().toLowerCase(); @@ -109,10 +114,10 @@ public class GetMongoIT { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assertions.assertEquals(2, results.size()); + assertEquals(2, results.size()); Iterator it = results.iterator(); - Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); - Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); + assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); + assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); // missing query - is ok runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); @@ -124,7 +129,7 @@ public class GetMongoIT { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assertions.assertEquals(0, results.size()); + assertEquals(0, results.size()); // invalid query runner.setProperty(GetMongo.QUERY, "{a: x,y,z}"); @@ -134,8 +139,8 @@ public class GetMongoIT { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assertions.assertEquals(1, results.size()); - Assertions.assertTrue(results.iterator().next().toString().contains("is invalid because")); + assertEquals(1, results.size()); + assertTrue(results.iterator().next().toString().contains("is invalid because")); // invalid projection runner.setVariable("projection", "{a: x,y,z}"); @@ -147,8 +152,8 @@ public class GetMongoIT { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assertions.assertEquals(1, results.size()); - Assertions.assertTrue(results.iterator().next().toString().contains("is invalid")); + assertEquals(1, results.size()); + assertTrue(results.iterator().next().toString().contains("is invalid")); // invalid sort runner.removeProperty(GetMongo.PROJECTION); @@ -159,8 +164,8 @@ public class GetMongoIT { if (pc instanceof MockProcessContext) { results = ((MockProcessContext) pc).validate(); } - Assertions.assertEquals(1, results.size()); - Assertions.assertTrue(results.iterator().next().toString().contains("is invalid")); + assertEquals(1, results.size()); + assertTrue(results.iterator().next().toString().contains("is invalid")); } @Test @@ -177,8 +182,8 @@ public class GetMongoIT { Map parsed = mapper.readValue(raw, Map.class); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - Assertions.assertTrue(parsed.get("date_field").getClass() == String.class); - Assertions.assertTrue(((String)parsed.get("date_field")).startsWith(format.format(CAL.getTime()))); + assertTrue(parsed.get("date_field").getClass() == String.class); + assertTrue(((String)parsed.get("date_field")).startsWith(format.format(CAL.getTime()))); } @Test @@ -252,8 +257,8 @@ public class GetMongoIT { runner.assertTransferCount(GetMongo.REL_SUCCESS, 2); runner.assertTransferCount(GetMongo.REL_ORIGINAL, 1); List results = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); - Assertions.assertTrue(results.get(0).getSize() > 0, "Flowfile was empty"); - Assertions.assertEquals(results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json", "Wrong mime type"); + assertTrue(results.get(0).getSize() > 0, "Flowfile was empty"); + assertEquals(results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json", "Wrong mime type"); } @Test @@ -267,8 +272,8 @@ public class GetMongoIT { runner.assertTransferCount(GetMongo.REL_SUCCESS, 2); runner.assertTransferCount(GetMongo.REL_ORIGINAL, 1); List results = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); - Assertions.assertTrue(results.get(0).getSize() > 0, "Flowfile was empty"); - Assertions.assertEquals(results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json", "Wrong mime type"); + assertTrue(results.get(0).getSize() > 0, "Flowfile was empty"); + assertEquals(results.get(0).getAttribute(CoreAttributes.MIME_TYPE.key()), "application/json", "Wrong mime type"); } @Test @@ -283,7 +288,7 @@ public class GetMongoIT { List flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); byte[] raw = runner.getContentAsByteArray(flowFiles.get(0)); String json = new String(raw); - Assertions.assertTrue(json.contains("\n"), "JSON did not have new lines."); + assertTrue(json.contains("\n"), "JSON did not have new lines."); runner.clearTransferState(); runner.setProperty(GetMongo.USE_PRETTY_PRINTING, GetMongo.NO_PP); runner.enqueue("{}"); @@ -293,15 +298,15 @@ public class GetMongoIT { flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); raw = runner.getContentAsByteArray(flowFiles.get(0)); json = new String(raw); - Assertions.assertFalse(json.contains("\n"), "New lines detected"); + assertFalse(json.contains("\n"), "New lines detected"); } private void testQueryAttribute(String attr, String expected) { List flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); for (MockFlowFile mff : flowFiles) { String val = mff.getAttribute(attr); - Assertions.assertNotNull(val, "Missing query attribute"); - Assertions.assertEquals(expected, val, "Value was wrong"); + assertNotNull(val, "Missing query attribute"); + assertEquals(expected, val, "Value was wrong"); } } @@ -426,7 +431,7 @@ public class GetMongoIT { ex = pe; } - Assertions.assertNull(ex, "An exception was thrown!"); + assertNull(ex, "An exception was thrown!"); runner.assertTransferCount(GetMongo.REL_FAILURE, 0); runner.assertTransferCount(GetMongo.REL_ORIGINAL, 0); runner.assertTransferCount(GetMongo.REL_SUCCESS, 3); @@ -467,7 +472,7 @@ public class GetMongoIT { runner.assertTransferCount(GetMongo.REL_SUCCESS, 1); MockFlowFile flowFile = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS).get(0); - Assertions.assertTrue(flowFile.getAttributes().containsKey("property.1")); + assertTrue(flowFile.getAttributes().containsKey("property.1")); flowFile.assertAttributeEquals("property.1", "value-1"); } /* @@ -536,8 +541,8 @@ public class GetMongoIT { tmpRunner.run(); } catch (Throwable ex) { Throwable cause = ex.getCause(); - Assertions.assertTrue(cause instanceof ProcessException); - Assertions.assertTrue(ex.getMessage().contains(entry.getKey()), entry.getKey()); + assertTrue(cause instanceof ProcessException); + assertTrue(ex.getMessage().contains(entry.getKey()), entry.getKey()); } tmpRunner.clearTransferState(); @@ -553,10 +558,10 @@ public class GetMongoIT { for (MockFlowFile ff : ffs) { String db = ff.getAttribute(GetMongo.DB_NAME); String col = ff.getAttribute(GetMongo.COL_NAME); - Assertions.assertNotNull(db); - Assertions.assertNotNull(col); - Assertions.assertEquals(DB_NAME, db); - Assertions.assertEquals(COLLECTION_NAME, col); + assertNotNull(db); + assertNotNull(col); + assertEquals(DB_NAME, db); + assertEquals(COLLECTION_NAME, col); } } @@ -578,8 +583,8 @@ public class GetMongoIT { Pattern format = Pattern.compile("([\\d]{4})-([\\d]{2})-([\\d]{2})"); - Assertions.assertTrue(result.containsKey("date_field")); - Assertions.assertTrue(format.matcher((String) result.get("date_field")).matches()); + assertTrue(result.containsKey("date_field")); + assertTrue(format.matcher((String) result.get("date_field")).matches()); } @Test @@ -667,6 +672,6 @@ public class GetMongoIT { List flowFiles = runner.getFlowFilesForRelationship(GetMongo.REL_SUCCESS); MockFlowFile flowFile = flowFiles.get(0); - Assertions.assertEquals(0, flowFile.getSize()); + assertEquals(0, flowFile.getSize()); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java index fab7d7e5d9..93bda501c3 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java @@ -28,7 +28,6 @@ import org.apache.nifi.util.TestRunners; import org.bson.Document; import org.bson.types.ObjectId; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,6 +40,8 @@ import java.util.List; import java.util.Map; 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 PutMongoIT extends MongoWriteTestBase { @BeforeEach @@ -73,8 +74,8 @@ public class PutMongoIT extends MongoWriteTestBase { } assertEquals(2, results.size()); Iterator it = results.iterator(); - Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); - Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); + assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); + assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); // invalid write concern runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); @@ -89,7 +90,7 @@ public class PutMongoIT extends MongoWriteTestBase { results = ((MockProcessContext) pc).validate(); } assertEquals(1, results.size()); - Assertions.assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); + assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); // valid write concern runner.setProperty(PutMongo.WRITE_CONCERN, PutMongo.WRITE_CONCERN_UNACKNOWLEDGED); @@ -221,7 +222,7 @@ public class PutMongoIT extends MongoWriteTestBase { assertEquals(found.get("name"), document.get("name")); assertEquals(found.get("department"), document.get("department")); Document contacts = (Document)found.get("contacts"); - Assertions.assertNotNull(contacts); + assertNotNull(contacts); assertEquals(contacts.get("twitter"), "@JohnSmith"); assertEquals(contacts.get("email"), "john.smith@test.com"); assertEquals(contacts.get("phone"), "555-555-5555"); @@ -257,12 +258,12 @@ public class PutMongoIT extends MongoWriteTestBase { runner.assertTransferCount(PutMongo.REL_SUCCESS, 1); MongoCursor iterator = collection.find(new Document("name", "John Smith")).iterator(); - Assertions.assertTrue(iterator.hasNext(), "Document did not come back."); + assertTrue(iterator.hasNext(), "Document did not come back."); Document val = iterator.next(); Map contacts = (Map)val.get("contacts"); - Assertions.assertNotNull(contacts); - Assertions.assertTrue(contacts.containsKey("twitter") && contacts.get("twitter").equals("@JohnSmith")); - Assertions.assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); + assertNotNull(contacts); + assertTrue(contacts.containsKey("twitter") && contacts.get("twitter").equals("@JohnSmith")); + assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); } private void updateTests(TestRunner runner, Document document) { @@ -271,11 +272,11 @@ public class PutMongoIT extends MongoWriteTestBase { runner.assertTransferCount(PutMongo.REL_SUCCESS, 1); MongoCursor iterator = collection.find(document).iterator(); - Assertions.assertTrue(iterator.hasNext(), "Document did not come back."); + assertTrue(iterator.hasNext(), "Document did not come back."); Document val = iterator.next(); - Assertions.assertTrue(val.containsKey("email") && val.get("email").equals("john.smith@test.com")); - Assertions.assertTrue(val.containsKey("grade") && val.get("grade").equals("Sr. Principle Eng.")); - Assertions.assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); + assertTrue(val.containsKey("email") && val.get("email").equals("john.smith@test.com")); + assertTrue(val.containsKey("grade") && val.get("grade").equals("Sr. Principle Eng.")); + assertTrue(val.containsKey("writes") && val.get("writes").equals(1)); } @Test @@ -462,12 +463,12 @@ public class PutMongoIT extends MongoWriteTestBase { Document query = new Document("_id", "Test"); Document result = collection.find(query).first(); List array = (List)result.get("testArr"); - Assertions.assertNotNull(array, "Array was empty"); + assertNotNull(array, "Array was empty"); assertEquals(3, array.size(), "Wrong size"); for (int index = 0; index < array.size(); index++) { Document doc = (Document)array.get(index); String msg = doc.getString("msg"); - Assertions.assertNotNull("Msg was null", msg); + assertNotNull("Msg was null", msg); assertEquals(msg, "Hi", "Msg had wrong value"); } } @@ -517,7 +518,8 @@ public class PutMongoIT extends MongoWriteTestBase { Document query = new Document(updateKeyProps[index], updateKeys[index]); Document result = collection.find(query).first(); - Assertions.assertNotNull(result, "Result was null"); + + assertNotNull(result, "Result was null"); assertEquals(1, collection.countDocuments(query), "Count was wrong"); runner.clearTransferState(); index++; diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java index e57769ba17..a8fe7c85db 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoRecordIT.java @@ -39,7 +39,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -57,6 +56,7 @@ import java.util.Set; import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PutMongoRecordIT extends MongoWriteTestBase { @@ -102,9 +102,9 @@ public class PutMongoRecordIT extends MongoWriteTestBase { } assertEquals(3, results.size()); Iterator it = results.iterator(); - Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); - Assertions.assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); - Assertions.assertTrue(it.next().toString().contains("is invalid because Record Reader is required")); + assertTrue(it.next().toString().contains("is invalid because Mongo Database Name is required")); + assertTrue(it.next().toString().contains("is invalid because Mongo Collection Name is required")); + assertTrue(it.next().toString().contains("is invalid because Record Reader is required")); // invalid write concern runner.setProperty(AbstractMongoProcessor.URI, MONGO_URI); @@ -119,7 +119,7 @@ public class PutMongoRecordIT extends MongoWriteTestBase { results = ((MockProcessContext) pc).validate(); } assertEquals(1, results.size()); - Assertions.assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); + assertTrue(results.iterator().next().toString().matches("'Write Concern' .* is invalid because Given value not found in allowed set .*")); // valid write concern runner.setProperty(PutMongoRecord.WRITE_CONCERN, PutMongoRecord.WRITE_CONCERN_UNACKNOWLEDGED); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java index a878d5f1c2..7e5b460868 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoTest.java @@ -21,12 +21,15 @@ import org.apache.nifi.components.ValidationResult; import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.Iterator; +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 PutMongoTest { /* @@ -50,10 +53,10 @@ public class PutMongoTest { if (runner.getProcessContext() instanceof MockProcessContext) { results = ((MockProcessContext) runner.getProcessContext()).validate(); } - Assertions.assertNotNull(results); - Assertions.assertEquals(1, results.size()); + assertNotNull(results); + assertEquals(1, results.size()); Iterator it = results.iterator(); - Assertions.assertTrue(it.next().toString().endsWith("Both update query key and update query cannot be set at the same time.")); + assertTrue(it.next().toString().endsWith("Both update query key and update query cannot be set at the same time.")); runner.removeProperty(PutMongo.UPDATE_QUERY); runner.removeProperty(PutMongo.UPDATE_QUERY_KEY); @@ -65,9 +68,9 @@ public class PutMongoTest { results = ((MockProcessContext) runner.getProcessContext()).validate(); } - Assertions.assertNotNull(results); - Assertions.assertEquals(1, results.size()); + assertNotNull(results); + assertEquals(1, results.size()); it = results.iterator(); - Assertions.assertTrue(it.next().toString().endsWith("Either the update query key or the update query field must be set.")); + assertTrue(it.next().toString().endsWith("Either the update query key or the update query field must be set.")); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java index 9da63958cd..1050a466d8 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/RunMongoAggregationIT.java @@ -30,7 +30,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,6 +41,10 @@ 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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class RunMongoAggregationIT { private static final String MONGO_URI = "mongodb://localhost"; @@ -120,8 +123,8 @@ public class RunMongoAggregationIT { List flowFiles = runner.getFlowFilesForRelationship(RunMongoAggregation.REL_RESULTS); for (MockFlowFile mff : flowFiles) { String val = mff.getAttribute(AGG_ATTR); - Assertions.assertNotNull("Missing query attribute", val); - Assertions.assertEquals(val, queryInput, "Value was wrong"); + assertNotNull("Missing query attribute", val); + assertEquals(val, queryInput, "Value was wrong"); } } @@ -182,7 +185,7 @@ public class RunMongoAggregationIT { for (MockFlowFile mockFlowFile : flowFiles) { byte[] raw = runner.getContentAsByteArray(mockFlowFile); Map> read = mapper.readValue(raw, Map.class); - Assertions.assertTrue(read.get("myArray").get(1).equalsIgnoreCase( format.format(now.getTime()))); + assertTrue(read.get("myArray").get(1).equalsIgnoreCase( format.format(now.getTime()))); } runner.clearTransferState(); @@ -195,7 +198,7 @@ public class RunMongoAggregationIT { for (MockFlowFile mockFlowFile : flowFiles) { byte[] raw = runner.getContentAsByteArray(mockFlowFile); Map> read = mapper.readValue(raw, Map.class); - Assertions.assertTrue(read.get("myArray").get(1) == now.getTimeInMillis()); + assertTrue(read.get("myArray").get(1) == now.getTimeInMillis()); } } @@ -207,12 +210,12 @@ public class RunMongoAggregationIT { for (MockFlowFile mockFlowFile : flowFiles) { byte[] raw = runner.getContentAsByteArray(mockFlowFile); Map read = mapper.readValue(raw, Map.class); - Assertions.assertTrue(mappings.containsKey(read.get("_id")), "Value was not found"); + assertTrue(mappings.containsKey(read.get("_id")), "Value was not found"); String queryAttr = mockFlowFile.getAttribute(AGG_ATTR); - Assertions.assertNotNull("Query attribute was null.", queryAttr); - Assertions.assertTrue(queryAttr.contains("$project"), "Missing $project"); - Assertions.assertTrue(queryAttr.contains("$group"), "Missing $group"); + assertNotNull("Query attribute was null.", queryAttr); + assertTrue(queryAttr.contains("$project"), "Missing $project"); + assertTrue(queryAttr.contains("$group"), "Missing $group"); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java index 2a7d01d6d4..5553b7f94e 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/DeleteGridFSIT.java @@ -26,7 +26,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.types.ObjectId; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,6 +33,10 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +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 DeleteGridFSIT extends GridFSITTestBase { private TestRunner runner; private static final String BUCKET = "delete_test_bucket"; @@ -83,13 +86,13 @@ public class DeleteGridFSIT extends GridFSITTestBase { private void testForQueryAttribute(String mustContain, String attrName) { List flowFiles = runner.getFlowFilesForRelationship(DeleteGridFS.REL_SUCCESS); String attribute = flowFiles.get(0).getAttribute(attrName); - Assertions.assertTrue(attribute.contains(mustContain)); + assertTrue(attribute.contains(mustContain)); } private String setupTestFile() { String fileName = "simple-delete-test.txt"; ObjectId id = writeTestFile(fileName, "Hello, world!", BUCKET, new HashMap<>()); - Assertions.assertNotNull(id); + assertNotNull(id); return fileName; } @@ -105,6 +108,6 @@ public class DeleteGridFSIT extends GridFSITTestBase { runner.assertTransferCount(DeleteGridFS.REL_FAILURE, 0); runner.assertTransferCount(DeleteGridFS.REL_SUCCESS, 1); - Assertions.assertFalse(fileExists(fileName, BUCKET), String.format("File %s still exists.", fileName)); + assertFalse(fileExists(fileName, BUCKET), String.format("File %s still exists.", fileName)); } } diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java index 8e285f05cb..a5896970ee 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/FetchGridFSIT.java @@ -27,7 +27,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.types.ObjectId; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,6 +34,10 @@ 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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class FetchGridFSIT extends GridFSITTestBase { TestRunner runner; @@ -56,7 +59,7 @@ public class FetchGridFSIT extends GridFSITTestBase { final String fileName = "get_by_name.txt"; final String content = "Hello, world"; ObjectId id = writeTestFile(fileName, content, BUCKET, new HashMap<>()); - Assertions.assertNotNull(id); + assertNotNull(id); String query = String.format("{\"filename\": \"%s\"}", fileName); runner.enqueue(query); @@ -66,7 +69,7 @@ public class FetchGridFSIT extends GridFSITTestBase { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); List flowFiles = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS); byte[] rawData = runner.getContentAsByteArray(flowFiles.get(0)); - Assertions.assertEquals(new String(rawData), content, "Data did not match for the file"); + assertEquals(new String(rawData), content, "Data did not match for the file"); runner.clearTransferState(); runner.setProperty(FetchGridFS.QUERY, query); @@ -78,7 +81,7 @@ public class FetchGridFSIT extends GridFSITTestBase { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); flowFiles = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS); rawData = runner.getContentAsByteArray(flowFiles.get(0)); - Assertions.assertEquals(new String(rawData), content, "Data did not match for the file"); + assertEquals(new String(rawData), content, "Data did not match for the file"); } @Test @@ -87,7 +90,7 @@ public class FetchGridFSIT extends GridFSITTestBase { String content = "Hello, world take %d"; for (int index = 0; index < 5; index++) { ObjectId id = writeTestFile(String.format(baseName, index), String.format(content, index), BUCKET, new HashMap<>()); - Assertions.assertNotNull(id); + assertNotNull(id); } AllowableValue[] values = new AllowableValue[] { QueryHelper.MODE_MANY_COMMITS, QueryHelper.MODE_ONE_COMMIT }; @@ -110,7 +113,7 @@ public class FetchGridFSIT extends GridFSITTestBase { final String fileName = "get_by_name.txt"; final String content = "Hello, world"; ObjectId id = writeTestFile(fileName, content, BUCKET, new HashMap<>()); - Assertions.assertNotNull(id); + assertNotNull(id); final String queryAttr = "gridfs.query.used"; final Map attrs = new HashMap<>(); @@ -125,15 +128,15 @@ public class FetchGridFSIT extends GridFSITTestBase { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); MockFlowFile mff = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS).get(0); String attr = mff.getAttribute(queryAttr); - Assertions.assertNotNull("Query attribute was null.", attr); - Assertions.assertTrue(attr.contains("filename"), "Wrong content."); + assertNotNull("Query attribute was null.", attr); + assertTrue(attr.contains("filename"), "Wrong content."); runner.clearTransferState(); id = writeTestFile(fileName, content, BUCKET, new HashMap(){{ put("lookupKey", "xyz"); }}); - Assertions.assertNotNull(id); + assertNotNull(id); String query = "{ \"metadata\": { \"lookupKey\": \"xyz\" }}"; @@ -146,8 +149,8 @@ public class FetchGridFSIT extends GridFSITTestBase { runner.assertTransferCount(FetchGridFS.REL_SUCCESS, 1); mff = runner.getFlowFilesForRelationship(FetchGridFS.REL_SUCCESS).get(0); attr = mff.getAttribute(queryAttr); - Assertions.assertNotNull("Query attribute was null.", attr); - Assertions.assertTrue(attr.contains("metadata"), "Wrong content."); + assertNotNull("Query attribute was null.", attr); + assertTrue(attr.contains("metadata"), "Wrong content."); } @Test @@ -176,7 +179,7 @@ public class FetchGridFSIT extends GridFSITTestBase { final String fileName = "get_by_name.txt"; final String content = "Hello, world"; ObjectId id = writeTestFile(fileName, content, BUCKET, new HashMap<>()); - Assertions.assertNotNull(id); + assertNotNull(id); runner.run(); runner.assertTransferCount(FetchGridFS.REL_FAILURE, failure); diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java index cc3c1116f0..c17e09da84 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/gridfs/PutGridFSIT.java @@ -27,13 +27,14 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class PutGridFSIT extends GridFSITTestBase { TestRunner runner; @@ -61,7 +62,7 @@ public class PutGridFSIT extends GridFSITTestBase { runner.run(); runner.assertAllFlowFilesTransferred(PutGridFS.REL_SUCCESS); - Assertions.assertTrue(fileExists(fileName, BUCKET), "File does not exist"); + assertTrue(fileExists(fileName, BUCKET), "File does not exist"); } @Test @@ -86,8 +87,8 @@ public class PutGridFSIT extends GridFSITTestBase { put("department", "Accounting"); }}; - Assertions.assertTrue(fileExists(fileName, BUCKET), "File does not exist"); - Assertions.assertTrue(fileHasProperties(fileName, BUCKET, attrs), "File is missing PARENT_PROPERTIES"); + assertTrue(fileExists(fileName, BUCKET), "File does not exist"); + assertTrue(fileHasProperties(fileName, BUCKET, attrs), "File is missing PARENT_PROPERTIES"); } @Test @@ -106,8 +107,9 @@ public class PutGridFSIT extends GridFSITTestBase { String bucketName = String.format("%s.files", BUCKET); MongoCollection files = client.getDatabase(DB).getCollection(bucketName); Document query = Document.parse(String.format("{\"filename\": \"%s\"}", fileName)); + long count = files.countDocuments(query); - Assertions.assertTrue(count == 10, "Wrong count"); + assertTrue(count == 10, "Wrong count"); } @Test diff --git a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java index 0944061571..2ab890d253 100644 --- a/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java +++ b/nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-services/src/test/java/org/apache/nifi/mongodb/MongoDBLookupServiceIT.java @@ -31,7 +31,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.bson.Document; import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -45,7 +44,11 @@ import java.util.Map; import java.util.Optional; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +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.junit.jupiter.api.Assertions.fail; public class MongoDBLookupServiceIT { private static final String DB_NAME = String.format("nifi_test-%d", Calendar.getInstance().getTimeInMillis()); @@ -106,8 +109,8 @@ public class MongoDBLookupServiceIT { criteria.put("uuid", "x-y-z"); Optional result = service.lookup(criteria); - Assertions.assertNotNull(result.get(), "The value was null."); - Assertions.assertEquals("Hello, world", result.get(), "The value was wrong."); + assertNotNull(result.get(), "The value was null."); + assertEquals("Hello, world", result.get(), "The value was wrong."); Map clean = new HashMap<>(); clean.putAll(criteria); @@ -116,10 +119,10 @@ public class MongoDBLookupServiceIT { try { result = service.lookup(criteria); } catch (LookupFailureException ex) { - Assertions.fail(); + fail(); } - Assertions.assertTrue(!result.isPresent()); + assertTrue(!result.isPresent()); } @Test @@ -136,23 +139,23 @@ public class MongoDBLookupServiceIT { Map context = new HashMap<>(); context.put("schema.name", "user"); Optional result = service.lookup(criteria, context); - Assertions.assertTrue(result.isPresent()); - Assertions.assertNotNull(result.get()); + assertTrue(result.isPresent()); + assertNotNull(result.get()); MapRecord record = (MapRecord)result.get(); - Assertions.assertEquals("john.smith", record.getAsString("username")); - Assertions.assertEquals("testing1234", record.getAsString("password")); + assertEquals("john.smith", record.getAsString("username")); + assertEquals("testing1234", record.getAsString("password")); /* * Test falling back on schema detection if a user doesn't specify the context argument */ result = service.lookup(criteria); - Assertions.assertTrue(result.isPresent()); - Assertions.assertNotNull(result.get()); + assertTrue(result.isPresent()); + assertNotNull(result.get()); record = (MapRecord)result.get(); - Assertions.assertEquals("john.smith", record.getAsString("username")); - Assertions.assertEquals("testing1234", record.getAsString("password")); + assertEquals("john.smith", record.getAsString("username")); + assertEquals("testing1234", record.getAsString("password")); } @Test @@ -175,8 +178,8 @@ public class MongoDBLookupServiceIT { attrs.put("schema.text", new String(contents)); Optional results = service.lookup(criteria, attrs); - Assertions.assertNotNull(results); - Assertions.assertTrue(results.isPresent()); + assertNotNull(results); + assertTrue(results.isPresent()); } @Test @@ -207,23 +210,23 @@ public class MongoDBLookupServiceIT { criteria.put("uuid", "x-y-z"); Optional result = service.lookup(criteria); - Assertions.assertNotNull(result.get(), "The value was null."); - Assertions.assertTrue(result.get() instanceof MapRecord, "The value was wrong."); + assertNotNull(result.get(), "The value was null."); + assertTrue(result.get() instanceof MapRecord, "The value was wrong."); MapRecord record = (MapRecord)result.get(); RecordSchema subSchema = ((RecordDataType)record.getSchema().getField("subrecordField").get().getDataType()).getChildSchema(); - Assertions.assertEquals("Hello, world", record.getValue("stringField"), "The value was wrong."); - Assertions.assertEquals("x-y-z", record.getValue("uuid"), "The value was wrong."); - Assertions.assertEquals(new Long(10000), record.getValue("longField")); - Assertions.assertEquals((Double.MAX_VALUE / 2.0), record.getValue("decimalField")); - Assertions.assertEquals(d, record.getValue("dateField")); - Assertions.assertEquals(ts.getTime(), ((Date)record.getValue("timestampField")).getTime()); + assertEquals("Hello, world", record.getValue("stringField"), "The value was wrong."); + assertEquals("x-y-z", record.getValue("uuid"), "The value was wrong."); + assertEquals(new Long(10000), record.getValue("longField")); + assertEquals((Double.MAX_VALUE / 2.0), record.getValue("decimalField")); + assertEquals(d, record.getValue("dateField")); + assertEquals(ts.getTime(), ((Date)record.getValue("timestampField")).getTime()); Record subRecord = record.getAsRecord("subrecordField", subSchema); - Assertions.assertNotNull(subRecord); - Assertions.assertEquals("test", subRecord.getValue("nestedString")); - Assertions.assertEquals(new Long(1000), subRecord.getValue("nestedLong")); - Assertions.assertEquals(list, record.getValue("arrayField")); + assertNotNull(subRecord); + assertEquals("test", subRecord.getValue("nestedString")); + assertEquals(new Long(1000), subRecord.getValue("nestedLong")); + assertEquals(list, record.getValue("arrayField")); Map clean = new HashMap<>(); clean.putAll(criteria); @@ -232,10 +235,10 @@ public class MongoDBLookupServiceIT { try { result = service.lookup(criteria); } catch (LookupFailureException ex) { - Assertions.fail(); + fail(); } - Assertions.assertTrue(!result.isPresent()); + assertTrue(!result.isPresent()); } @Test diff --git a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/ITRedisDistributedMapCacheClientService.java b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/ITRedisDistributedMapCacheClientService.java index 9efef5c3bc..191930c7de 100644 --- a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/ITRedisDistributedMapCacheClientService.java +++ b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/ITRedisDistributedMapCacheClientService.java @@ -34,10 +34,9 @@ import org.apache.nifi.redis.util.RedisUtils; import org.apache.nifi.reporting.InitializationException; 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 redis.embedded.RedisServer; import java.io.ByteArrayOutputStream; @@ -55,6 +54,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * This is an integration test that is meant to be run against a real Redis instance. */ @@ -67,7 +70,7 @@ public class ITRedisDistributedMapCacheClientService { private RedisDistributedMapCacheClientService redisMapCacheClientService; private int redisPort; - @Before + @BeforeEach public void setup() throws IOException { this.redisPort = getAvailablePort(); @@ -86,7 +89,7 @@ public class ITRedisDistributedMapCacheClientService { } } - @After + @AfterEach public void teardown() throws IOException { if (redisServer != null) { redisServer.stop(); @@ -180,70 +183,70 @@ public class ITRedisDistributedMapCacheClientService { final String value = "the time is " + timestamp; // verify the key doesn't exists, put the key/value, then verify it exists - Assert.assertFalse(cacheClient.containsKey(key, stringSerializer)); + assertFalse(cacheClient.containsKey(key, stringSerializer)); cacheClient.put(key, value, stringSerializer, stringSerializer); - Assert.assertTrue(cacheClient.containsKey(key, stringSerializer)); + assertTrue(cacheClient.containsKey(key, stringSerializer)); // verify get returns the expected value we set above final String retrievedValue = cacheClient.get(key, stringSerializer, stringDeserializer); - Assert.assertEquals(value, retrievedValue); + assertEquals(value, retrievedValue); // verify get returns null for a key that doesn't exist final String missingValue = cacheClient.get("does-not-exist", stringSerializer, stringDeserializerWithoutNullCheck); - Assert.assertEquals(null, missingValue); + assertEquals(null, missingValue); // verify remove removes the entry and contains key returns false after - Assert.assertTrue(cacheClient.remove(key, stringSerializer)); - Assert.assertFalse(cacheClient.containsKey(key, stringSerializer)); + assertTrue(cacheClient.remove(key, stringSerializer)); + assertFalse(cacheClient.containsKey(key, stringSerializer)); // verify putIfAbsent works the first time and returns false the second time - Assert.assertTrue(cacheClient.putIfAbsent(key, value, stringSerializer, stringSerializer)); - Assert.assertFalse(cacheClient.putIfAbsent(key, "some other value", stringSerializer, stringSerializer)); - Assert.assertEquals(value, cacheClient.get(key, stringSerializer, stringDeserializer)); + assertTrue(cacheClient.putIfAbsent(key, value, stringSerializer, stringSerializer)); + assertFalse(cacheClient.putIfAbsent(key, "some other value", stringSerializer, stringSerializer)); + assertEquals(value, cacheClient.get(key, stringSerializer, stringDeserializer)); // verify that getAndPutIfAbsent returns the existing value and doesn't modify it in the cache final String getAndPutIfAbsentResult = cacheClient.getAndPutIfAbsent(key, value, stringSerializer, stringSerializer, stringDeserializer); - Assert.assertEquals(value, getAndPutIfAbsentResult); - Assert.assertEquals(value, cacheClient.get(key, stringSerializer, stringDeserializer)); + assertEquals(value, getAndPutIfAbsentResult); + assertEquals(value, cacheClient.get(key, stringSerializer, stringDeserializer)); // verify that getAndPutIfAbsent on a key that doesn't exist returns null final String keyThatDoesntExist = key + "_DOES_NOT_EXIST"; - Assert.assertFalse(cacheClient.containsKey(keyThatDoesntExist, stringSerializer)); + assertFalse(cacheClient.containsKey(keyThatDoesntExist, stringSerializer)); final String getAndPutIfAbsentResultWhenDoesntExist = cacheClient.getAndPutIfAbsent(keyThatDoesntExist, value, stringSerializer, stringSerializer, stringDeserializer); - Assert.assertEquals(null, getAndPutIfAbsentResultWhenDoesntExist); - Assert.assertEquals(value, cacheClient.get(keyThatDoesntExist, stringSerializer, stringDeserializer)); + assertEquals(null, getAndPutIfAbsentResultWhenDoesntExist); + assertEquals(value, cacheClient.get(keyThatDoesntExist, stringSerializer, stringDeserializer)); // verify atomic fetch returns the correct entry final AtomicCacheEntry entry = cacheClient.fetch(key, stringSerializer, stringDeserializer); - Assert.assertEquals(key, entry.getKey()); - Assert.assertEquals(value, entry.getValue()); - Assert.assertTrue(Arrays.equals(value.getBytes(StandardCharsets.UTF_8), entry.getRevision().orElse(null))); + assertEquals(key, entry.getKey()); + assertEquals(value, entry.getValue()); + assertTrue(Arrays.equals(value.getBytes(StandardCharsets.UTF_8), entry.getRevision().orElse(null))); final AtomicCacheEntry notLatestEntry = new AtomicCacheEntry<>(entry.getKey(), entry.getValue(), "not previous".getBytes(StandardCharsets.UTF_8)); // verify atomic replace does not replace when previous value is not equal - Assert.assertFalse(cacheClient.replace(notLatestEntry, stringSerializer, stringSerializer)); - Assert.assertEquals(value, cacheClient.get(key, stringSerializer, stringDeserializer)); + assertFalse(cacheClient.replace(notLatestEntry, stringSerializer, stringSerializer)); + assertEquals(value, cacheClient.get(key, stringSerializer, stringDeserializer)); // verify atomic replace does replace when previous value is equal final String replacementValue = "this value has been replaced"; entry.setValue(replacementValue); - Assert.assertTrue(cacheClient.replace(entry, stringSerializer, stringSerializer)); - Assert.assertEquals(replacementValue, cacheClient.get(key, stringSerializer, stringDeserializer)); + assertTrue(cacheClient.replace(entry, stringSerializer, stringSerializer)); + assertEquals(replacementValue, cacheClient.get(key, stringSerializer, stringDeserializer)); // verify atomic replace does replace no value previous existed final String replaceKeyDoesntExist = key + "_REPLACE_DOES_NOT_EXIST"; final AtomicCacheEntry entryDoesNotExist = new AtomicCacheEntry<>(replaceKeyDoesntExist, replacementValue, null); - Assert.assertTrue(cacheClient.replace(entryDoesNotExist, stringSerializer, stringSerializer)); - Assert.assertEquals(replacementValue, cacheClient.get(replaceKeyDoesntExist, stringSerializer, stringDeserializer)); + assertTrue(cacheClient.replace(entryDoesNotExist, stringSerializer, stringSerializer)); + assertEquals(replacementValue, cacheClient.get(replaceKeyDoesntExist, stringSerializer, stringDeserializer)); final int numToDelete = 2000; for (int i=0; i < numToDelete; i++) { cacheClient.put(key + "-" + i, value, stringSerializer, stringSerializer); } - Assert.assertTrue(cacheClient.removeByPattern("test-redis-processor-*") >= numToDelete); - Assert.assertFalse(cacheClient.containsKey(key, stringSerializer)); + assertTrue(cacheClient.removeByPattern("test-redis-processor-*") >= numToDelete); + assertFalse(cacheClient.containsKey(key, stringSerializer)); Map bulk = new HashMap<>(); bulk.put("bulk-1", "testing1"); @@ -253,11 +256,11 @@ public class ITRedisDistributedMapCacheClientService { bulk.put("bulk-5", "testing5"); cacheClient.putAll(bulk, stringSerializer, stringSerializer); - Assert.assertTrue(cacheClient.containsKey("bulk-1", stringSerializer)); - Assert.assertTrue(cacheClient.containsKey("bulk-2", stringSerializer)); - Assert.assertTrue(cacheClient.containsKey("bulk-3", stringSerializer)); - Assert.assertTrue(cacheClient.containsKey("bulk-4", stringSerializer)); - Assert.assertTrue(cacheClient.containsKey("bulk-5", stringSerializer)); + assertTrue(cacheClient.containsKey("bulk-1", stringSerializer)); + assertTrue(cacheClient.containsKey("bulk-2", stringSerializer)); + assertTrue(cacheClient.containsKey("bulk-3", stringSerializer)); + assertTrue(cacheClient.containsKey("bulk-4", stringSerializer)); + assertTrue(cacheClient.containsKey("bulk-5", stringSerializer)); session.transfer(flowFile, REL_SUCCESS); } catch (final Exception e) { diff --git a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/TestRedisConnectionPoolService.java b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/TestRedisConnectionPoolService.java index 40d4c42132..b1e6fe761f 100644 --- a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/TestRedisConnectionPoolService.java +++ b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/service/TestRedisConnectionPoolService.java @@ -26,10 +26,9 @@ import org.apache.nifi.util.MockProcessContext; import org.apache.nifi.util.StandardProcessorTestRunner; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -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.mockito.Mockito; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; @@ -37,6 +36,9 @@ import javax.net.ssl.SSLContext; import java.io.IOException; import java.security.GeneralSecurityException; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestRedisConnectionPoolService { public static final String SSL_CONTEXT_IDENTIFIER = "ssl-context-service"; @@ -46,12 +48,12 @@ public class TestRedisConnectionPoolService { private static SSLContext sslContext; - @BeforeClass + @BeforeAll public static void classSetup() throws IOException, GeneralSecurityException { sslContext = SSLContext.getDefault(); } - @Before + @BeforeEach public void setup() throws InitializationException { proc = new FakeRedisProcessor(); testRunner = TestRunners.newTestRunner(proc); @@ -81,8 +83,8 @@ public class TestRedisConnectionPoolService { JedisConnectionFactory connectionFactory = getJedisConnectionFactory(); // Uses config from test runner // Verify that the client configuration will be using an SSL socket factory and SSL parameters - Assert.assertTrue(connectionFactory.getClientConfiguration().getSslSocketFactory().isPresent()); - Assert.assertTrue(connectionFactory.getClientConfiguration().getSslParameters().isPresent()); + assertTrue(connectionFactory.getClientConfiguration().getSslSocketFactory().isPresent()); + assertTrue(connectionFactory.getClientConfiguration().getSslParameters().isPresent()); // Now remove the SSL context service testRunner.disableControllerService(redisService); @@ -91,8 +93,8 @@ public class TestRedisConnectionPoolService { connectionFactory = getJedisConnectionFactory(); // Now the client configuration will not use SSL - Assert.assertFalse(connectionFactory.getClientConfiguration().getSslSocketFactory().isPresent()); - Assert.assertFalse(connectionFactory.getClientConfiguration().getSslParameters().isPresent()); + assertFalse(connectionFactory.getClientConfiguration().getSslSocketFactory().isPresent()); + assertFalse(connectionFactory.getClientConfiguration().getSslParameters().isPresent()); } private void setDefaultRedisProperties() { diff --git a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/ITRedisStateProvider.java b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/ITRedisStateProvider.java index 7396d66c6e..69e5b766af 100644 --- a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/ITRedisStateProvider.java +++ b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/ITRedisStateProvider.java @@ -25,9 +25,9 @@ import org.apache.nifi.components.state.StateProviderInitializationContext; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.redis.util.RedisUtils; import org.apache.nifi.util.MockComponentLog; -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 redis.embedded.RedisServer; import javax.net.ssl.SSLContext; @@ -40,10 +40,10 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -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; /** * NOTE: These test cases should be kept in-sync with AbstractTestStateProvider which is in the framework @@ -56,7 +56,7 @@ public class ITRedisStateProvider { private RedisServer redisServer; private RedisStateProvider provider; - @Before + @BeforeEach public void setup() throws Exception { final int redisPort = getAvailablePort(); @@ -68,7 +68,7 @@ public class ITRedisStateProvider { this.provider = createProvider(properties); } - @After + @AfterEach public void teardown() throws IOException { if (provider != null) { try { diff --git a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateMapJsonSerDe.java b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateMapJsonSerDe.java index f147045919..6731926879 100644 --- a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateMapJsonSerDe.java +++ b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateMapJsonSerDe.java @@ -16,17 +16,20 @@ */ package org.apache.nifi.redis.state; -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.IOException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + public class TestRedisStateMapJsonSerDe { private RedisStateMapSerDe serDe; - @Before + @BeforeEach public void setup() { serDe = new RedisStateMapJsonSerDe(); } @@ -42,23 +45,23 @@ public class TestRedisStateMapJsonSerDe { .build(); final byte[] serialized = serDe.serialize(stateMap); - Assert.assertNotNull(serialized); + assertNotNull(serialized); final RedisStateMap deserialized = serDe.deserialize(serialized); - Assert.assertNotNull(deserialized); - Assert.assertEquals(stateMap.getVersion(), deserialized.getVersion()); - Assert.assertEquals(stateMap.getEncodingVersion(), deserialized.getEncodingVersion()); - Assert.assertEquals(stateMap.toMap(), deserialized.toMap()); + assertNotNull(deserialized); + assertEquals(stateMap.getVersion(), deserialized.getVersion()); + assertEquals(stateMap.getEncodingVersion(), deserialized.getEncodingVersion()); + assertEquals(stateMap.toMap(), deserialized.toMap()); } @Test public void testSerializeWhenNull() throws IOException { - Assert.assertNull(serDe.serialize(null)); + assertNull(serDe.serialize(null)); } @Test public void testDeserializeWhenNull() throws IOException { - Assert.assertNull(serDe.deserialize(null)); + assertNull(serDe.deserialize(null)); } @Test @@ -66,14 +69,14 @@ public class TestRedisStateMapJsonSerDe { final RedisStateMap stateMap = new RedisStateMap.Builder().build(); final byte[] serialized = serDe.serialize(stateMap); - Assert.assertNotNull(serialized); + assertNotNull(serialized); final RedisStateMap deserialized = serDe.deserialize(serialized); - Assert.assertNotNull(deserialized); - Assert.assertEquals(RedisStateMap.DEFAULT_VERSION.longValue(), stateMap.getVersion()); - Assert.assertEquals(RedisStateMap.DEFAULT_ENCODING, stateMap.getEncodingVersion()); - Assert.assertNotNull(deserialized.toMap()); - Assert.assertEquals(0, deserialized.toMap().size()); + assertNotNull(deserialized); + assertEquals(RedisStateMap.DEFAULT_VERSION.longValue(), stateMap.getVersion()); + assertEquals(RedisStateMap.DEFAULT_ENCODING, stateMap.getEncodingVersion()); + assertNotNull(deserialized.toMap()); + assertEquals(0, deserialized.toMap().size()); } } diff --git a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateProvider.java b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateProvider.java index 45fd899768..b0c5a16ef0 100644 --- a/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateProvider.java +++ b/nifi-nar-bundles/nifi-redis-bundle/nifi-redis-extensions/src/test/java/org/apache/nifi/redis/state/TestRedisStateProvider.java @@ -21,22 +21,23 @@ import org.apache.nifi.components.ValidationResult; import org.apache.nifi.components.state.StateProviderInitializationContext; import org.apache.nifi.redis.util.RedisUtils; import org.apache.nifi.util.MockPropertyValue; -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 org.mockito.Mockito; import javax.net.ssl.SSLContext; -import java.io.IOException; import java.util.Collection; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class TestRedisStateProvider { private RedisStateProvider redisStateProvider; private StateProviderInitializationContext context; private ValidationContext validationContext; - @Before + @BeforeEach public void init() { context = Mockito.mock(StateProviderInitializationContext.class); redisStateProvider = new RedisStateProvider(); @@ -62,27 +63,27 @@ public class TestRedisStateProvider { } @Test - public void customValidate_enabledTlsSuccess() throws IOException { + public void customValidate_enabledTlsSuccess() { this.enableTls(true); redisStateProvider.initialize(context); Collection results = redisStateProvider.customValidate(validationContext); - Assert.assertTrue(results.isEmpty()); + assertTrue(results.isEmpty()); } @Test - public void customValidate_disableTlsSuccess() throws IOException { + public void customValidate_disableTlsSuccess() { this.enableTls(false); redisStateProvider.initialize(context); Collection results = redisStateProvider.customValidate(validationContext); - Assert.assertTrue(results.isEmpty()); + assertTrue(results.isEmpty()); } @Test - public void customValidate_enableTlsButNoSslContext() throws IOException { + public void customValidate_enableTlsButNoSslContext() { this.enableTls(true); Mockito.when(context.getSSLContext()).thenReturn(null); @@ -90,6 +91,6 @@ public class TestRedisStateProvider { redisStateProvider.initialize(context); Collection results = redisStateProvider.customValidate(validationContext); - Assert.assertEquals(1, results.size()); + assertEquals(1, results.size()); } } diff --git a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITAbstractRethinkDBTest.java b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITAbstractRethinkDBTest.java deleted file mode 100644 index 7131834651..0000000000 --- a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITAbstractRethinkDBTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.rethinkdb; - -import org.apache.nifi.util.TestRunner; - -import com.rethinkdb.RethinkDB; -import com.rethinkdb.net.Connection; - -/** - * Abstract base class for RethinkDB integration tests - */ -public class ITAbstractRethinkDBTest { - protected TestRunner runner; - protected Connection connection; - protected String dbName = "test"; - protected String dbHost = "localhost"; - protected String dbPort = "28015"; - protected String user = "admin"; - protected String password = "admin"; - protected String table = "test"; - - public void setUp() throws Exception { - runner.setProperty(AbstractRethinkDBProcessor.DB_NAME, dbName); - runner.setProperty(AbstractRethinkDBProcessor.DB_HOST, dbHost); - runner.setProperty(AbstractRethinkDBProcessor.DB_PORT, dbPort); - runner.setProperty(AbstractRethinkDBProcessor.USERNAME, user); - runner.setProperty(AbstractRethinkDBProcessor.PASSWORD, password); - runner.setProperty(AbstractRethinkDBProcessor.TABLE_NAME, table); - runner.setProperty(AbstractRethinkDBProcessor.CHARSET, "UTF-8"); - - connection = RethinkDB.r.connection().user(user, password).db(dbName).hostname(dbHost).port(Integer.parseInt(dbPort)).connect(); - } - - public void tearDown() throws Exception { - runner = null; - connection.close(); - connection = null; - } - -} \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITDeleteRethinkDBTest.java b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITDeleteRethinkDBTest.java deleted file mode 100644 index 47869d39ba..0000000000 --- a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITDeleteRethinkDBTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.rethinkdb; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import com.rethinkdb.RethinkDB; - -import net.minidev.json.JSONObject; - -/** - * Integration test for deleting documents from RethinkDB. Please ensure that the RethinkDB is running - * on local host with default port and has database test with table test and user - * admin with password admin before running the integration tests or set the attributes in the - * test accordingly. - */ -@Ignore("Comment this out for running tests against a real instance of RethinkDB") -public class ITDeleteRethinkDBTest extends ITAbstractRethinkDBTest { - - @Before - public void setUp() throws Exception { - runner = TestRunners.newTestRunner(DeleteRethinkDB.class); - super.setUp(); - runner.setProperty(DeleteRethinkDB.DURABILITY, "soft"); - runner.setProperty(DeleteRethinkDB.RETURN_CHANGES, "true"); - - connection = RethinkDB.r.connection().user(user, password).db(dbName).hostname(dbHost).port(Integer.parseInt(dbPort)).connect(); - RethinkDB.r.db(dbName).table(table).delete().run(connection); - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 0L, count); - } - - @After - public void tearDown() throws Exception { - super.tearDown(); - } - - @Test - public void testDeleteDocumentById() { - JSONObject message = new JSONObject(); - message.put("id", "1"); - message.put("value", "one"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - - runner.setProperty(AbstractRethinkDBProcessor.RETHINKDB_DOCUMENT_ID, "${rethinkdb.id}"); - - Map props = new HashMap<>(); - props.put("rethinkdb.id","1"); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_SUCCESS, 1); - - String changeMessage = ("{\"old_val\":" + message + "}"); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - assertEquals("Error should be null",null, flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - assertEquals("Content should be same size", changeMessage.length(), flowFiles.get(0).getSize()); - flowFiles.get(0).assertContentEquals(changeMessage); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_DELETED_KEY), "1"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_ERROR_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_INSERTED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_UNCHANGED_KEY),"0"); - - Map document = RethinkDB.r.db(dbName).table(table).get("1").run(connection); - assertEquals("Document should be null", document, null); - } - - @Test - public void testDeleteDocumentByIdNoChanges() { - JSONObject message = new JSONObject(); - message.put("id", "11"); - message.put("value", "one"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - - runner.setProperty(AbstractRethinkDBProcessor.RETHINKDB_DOCUMENT_ID, "${rethinkdb.id}"); - runner.setProperty(DeleteRethinkDB.RETURN_CHANGES, "false"); - - Map props = new HashMap<>(); - props.put("rethinkdb.id","11"); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_SUCCESS, 1); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - assertEquals("Error should be null",null, flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_DELETED_KEY), "1"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_ERROR_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_INSERTED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_UNCHANGED_KEY),"0"); - assertEquals(flowFiles.get(0).getSize(), 0); - - Map document = RethinkDB.r.db(dbName).table(table).get("1").run(connection); - assertEquals("Document should be null", document, null); - } - - @Test - public void testDeleteDocumentByIdNotFound() { - JSONObject message = new JSONObject(); - message.put("id", "1"); - message.put("value", "one"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - - runner.setProperty(AbstractRethinkDBProcessor.RETHINKDB_DOCUMENT_ID, "${rethinkdb.id}"); - - Map props = new HashMap<>(); - props.put("rethinkdb.id", String.valueOf(System.currentTimeMillis())); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_NOT_FOUND, 1); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_NOT_FOUND); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - assertNotNull("Error should not be null", flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - assertEquals("Content should be same size", 0, flowFiles.get(0).getSize()); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_DELETED_KEY), "0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_ERROR_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_INSERTED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_SKIPPED_KEY),"1"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_UNCHANGED_KEY),"0"); - - Map document = RethinkDB.r.db(dbName).table(table).get("1").run(connection); - assertNotNull("Document should not be null", document); - assertEquals("id should be same", document.get("id"), "1"); - } - - @Test - public void testDeleteDocumentByHardCodedId() { - JSONObject message = new JSONObject(); - message.put("id", "2"); - message.put("value", "two"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1, count); - - runner.setProperty(AbstractRethinkDBProcessor.RETHINKDB_DOCUMENT_ID, "2"); - - Map props = new HashMap<>(); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_SUCCESS, 1); - - String changeMessage = ("{\"old_val\":" + message + "}"); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - assertEquals("Error should be null",null, flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - assertEquals("Content should be same size", changeMessage.length(), flowFiles.get(0).getSize()); - flowFiles.get(0).assertContentEquals(changeMessage); - - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_DELETED_KEY), "1"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_ERROR_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_INSERTED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(DeleteRethinkDB.RETHINKDB_DELETE_RESULT_UNCHANGED_KEY),"0"); - - Map document = RethinkDB.r.db(dbName).table(table).get("2").run(connection); - assertEquals("Document should be null", document, null); - } - -} \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITGetRethinkDBTest.java b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITGetRethinkDBTest.java deleted file mode 100644 index 38887001d0..0000000000 --- a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITGetRethinkDBTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.rethinkdb; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunners; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import com.rethinkdb.RethinkDB; - -import net.minidev.json.JSONObject; - -/** - * Integration test for getting documents from RethinkDB. Please ensure that the RethinkDB is running - * on local host with default port and has database test with table test and user - * admin with password admin before running the integration tests or set the attributes in the - * test accordingly. - */ -@Ignore("Comment this out for running tests against a real instance of RethinkDB") -public class ITGetRethinkDBTest extends ITAbstractRethinkDBTest { - - @Before - public void setUp() throws Exception { - runner = TestRunners.newTestRunner(GetRethinkDB.class); - super.setUp(); - runner.setProperty(AbstractRethinkDBProcessor.MAX_DOCUMENTS_SIZE, "1 KB"); - RethinkDB.r.db(dbName).table(table).delete().run(connection); - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 0L, count); - } - - @After - public void tearDown() throws Exception { - super.tearDown(); - } - - @Test - public void testGetDocumentById() { - JSONObject message = new JSONObject(); - message.put("id", "1"); - message.put("value", "one"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - - runner.setProperty(GetRethinkDB.RETHINKDB_DOCUMENT_ID, "${rethinkdb.id}"); - runner.assertValid(); - - Map props = new HashMap<>(); - props.put("rethinkdb.id","1"); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_SUCCESS, 1); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - assertEquals("Error should be null",null, flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - assertEquals("Content should be same size", message.toString().length(), flowFiles.get(0).getSize()); - flowFiles.get(0).assertContentEquals(message.toString()); - } - - @Test - public void testGetDocumentByIdNotFound() { - JSONObject message = new JSONObject(); - message.put("id", "1"); - message.put("value", "one"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - - runner.setProperty(GetRethinkDB.RETHINKDB_DOCUMENT_ID, "${rethinkdb.id}"); - runner.assertValid(); - - Map props = new HashMap<>(); - props.put("rethinkdb.id", String.valueOf(System.currentTimeMillis())); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_NOT_FOUND, 1); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_NOT_FOUND); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - assertNotNull("Error should not be null", flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - assertEquals("Content should be same size", 0, flowFiles.get(0).getSize()); - } - - @Test - public void testGetDocumentByHardCodedId() { - JSONObject message = new JSONObject(); - message.put("id", "2"); - message.put("value", "two"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1, count); - - runner.setProperty(GetRethinkDB.RETHINKDB_DOCUMENT_ID, "2"); - runner.assertValid(); - - Map props = new HashMap<>(); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_SUCCESS, 1); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - assertEquals("Error should be null",null, flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - assertEquals("Content should be same size", message.toString().length(), flowFiles.get(0).getSize()); - flowFiles.get(0).assertContentEquals(message.toString()); - } - - @Test - public void testGetDocumentTooBig() { - JSONObject message = new JSONObject(); - message.put("id", "2"); - message.put("value", "two"); - RethinkDB.r.db(dbName).table(table).insert(message).run(connection); - - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1, count); - - runner.setProperty(GetRethinkDB.RETHINKDB_DOCUMENT_ID, "2"); - runner.setProperty(AbstractRethinkDBProcessor.MAX_DOCUMENTS_SIZE, "2B"); - runner.assertValid(); - - Map props = new HashMap<>(); - - runner.enqueue(new byte [] {},props); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(AbstractRethinkDBProcessor.REL_FAILURE, 1); - - List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_FAILURE); - assertEquals("Flow file count should be same", 1, flowFiles.size()); - String errorMessage = flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE); - assertNotNull("Error should be not be null", errorMessage); - assertEquals("Error message should be same", "Document too big size " + message.toJSONString().length() + " bytes",errorMessage); - } -} \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITPutRethinkDBTest.java b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITPutRethinkDBTest.java deleted file mode 100644 index 052d3845be..0000000000 --- a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/ITPutRethinkDBTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.processors.rethinkdb; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import java.util.List; -import org.apache.nifi.util.MockFlowFile; -import org.apache.nifi.util.TestRunners; -import org.json.simple.JSONArray; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.rethinkdb.RethinkDB; - -import net.minidev.json.JSONObject; - -/** - * Integration test for RethinkDB. Please ensure that the RethinkDB is running - * on local host with default port and has database test with table test and user - * admin with password admin before running the integration tests or set the attributes in the - * test accordingly. - */ -@Ignore("Comment this out for running tests against a real instance of RethinkDB") -public class ITPutRethinkDBTest extends ITAbstractRethinkDBTest { - - @Before - public void setUp() throws Exception { - runner = TestRunners.newTestRunner(PutRethinkDB.class); - super.setUp(); - runner.setProperty(AbstractRethinkDBProcessor.MAX_DOCUMENTS_SIZE, "1 KB"); - runner.setProperty(PutRethinkDB.CONFLICT_STRATEGY, PutRethinkDB.CONFLICT_STRATEGY_UPDATE); - runner.setProperty(PutRethinkDB.DURABILITY, PutRethinkDB.DURABILITY_HARD); - } - - @After - public void tearDown() throws Exception { - super.tearDown(); - } - - @Test - public void testValidSingleMessage() { - runner.assertValid(); - RethinkDB.r.db(dbName).table(table).delete().run(connection); - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 0L, count); - - JSONObject message = new JSONObject(); - message.put("hello", "rethinkdb"); - byte [] bytes = message.toJSONString().getBytes(); - runner.enqueue(bytes); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(PutRethinkDB.REL_SUCCESS, 1); - - List flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0"); - assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null"); - - count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - } - - @Test - public void testValidSingleMessageTwiceConflictUpdate() { - runner.assertValid(); - RethinkDB.r.db(dbName).table(table).delete().run(connection); - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 0L, count); - - JSONObject message = new JSONObject(); - message.put("id", "rethinkdb"); - byte [] bytes = message.toJSONString().getBytes(); - runner.enqueue(bytes); - runner.run(1,false,true); - - List flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0"); - assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null"); - - runner.enqueue(bytes); - runner.run(1,true,true); - - flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS); - assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); - assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0"); - assertNotNull(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); - assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"0"); - assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"1"); - assertEquals(flowFiles.get(1).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null"); - - count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - } - - @Test - public void testValidSingleMessageTwiceConflictError() { - runner.setProperty(PutRethinkDB.CONFLICT_STRATEGY, PutRethinkDB.CONFLICT_STRATEGY_ERROR); - runner.assertValid(); - RethinkDB.r.db(dbName).table(table).delete().run(connection); - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 0L, count); - - JSONObject message = new JSONObject(); - message.put("id", "rethinkdb"); - byte [] bytes = message.toJSONString().getBytes(); - runner.enqueue(bytes); - runner.run(1,false,true); - - List flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0"); - assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"1"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null"); - - runner.enqueue(bytes); - runner.run(1,true,true); - - flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_FAILURE); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"1"); - assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0"); - assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY)); - - count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 1L, count); - } - - @Test - public void testValidArrayMessage() { - runner.assertValid(); - RethinkDB.r.db(dbName).table(table).delete().run(connection); - long count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 0L, count); - - JSONObject message1 = new JSONObject(); - message1.put("hello", "rethinkdb"); - JSONObject message2 = new JSONObject(); - message2.put("hello2", "rethinkdb2"); - JSONArray array = new JSONArray(); - array.add(message1); - array.add(message2); - byte [] bytes = array.toJSONString().getBytes(); - - runner.enqueue(bytes); - runner.run(1,true,true); - runner.assertAllFlowFilesTransferred(PutRethinkDB.REL_SUCCESS, 1); - - List flowFiles = runner.getFlowFilesForRelationship(PutRethinkDB.REL_SUCCESS); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_DELETED_KEY), "0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_ERROR_KEY),"0"); - assertNotNull(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_GENERATED_KEYS_KEY)); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_INSERTED_KEY),"2"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_REPLACED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_SKIPPED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_UNCHANGED_KEY),"0"); - assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_INSERT_RESULT_FIRST_ERROR_KEY),"null"); - - count = RethinkDB.r.db(dbName).table(table).count().run(connection); - assertEquals("Count should be same", 2L, count); - } -} \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestDeleteRethinkDB.java b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestDeleteRethinkDB.java index eef4672054..b6fef76d04 100644 --- a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestDeleteRethinkDB.java +++ b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestDeleteRethinkDB.java @@ -21,17 +21,17 @@ import com.rethinkdb.net.Connection; 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.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestDeleteRethinkDB { private static final String DOCUMENT_ID = "id1"; @@ -39,7 +39,7 @@ public class TestDeleteRethinkDB { private AbstractRethinkDBProcessor mockDeleteRethinkDB; private Map document = new HashMap<>(); - @Before + @BeforeEach public void setUp() throws Exception { mockDeleteRethinkDB = new DeleteRethinkDB() { @Override @@ -77,7 +77,7 @@ public class TestDeleteRethinkDB { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } @@ -208,7 +208,6 @@ public class TestDeleteRethinkDB { List flowFiles = runner.getFlowFilesForRelationship(AbstractRethinkDBProcessor.REL_SUCCESS); flowFiles.get(0).assertContentEquals(json); assertNull(flowFiles.get(0).getAttribute(AbstractRethinkDBProcessor.RETHINKDB_ERROR_MESSAGE)); - } @Test diff --git a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestGetRethinkDB.java b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestGetRethinkDB.java index 710954980d..ece46e3e91 100644 --- a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestGetRethinkDB.java +++ b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestGetRethinkDB.java @@ -16,22 +16,21 @@ */ package org.apache.nifi.processors.rethinkdb; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import com.google.gson.Gson; +import com.rethinkdb.net.Connection; +import org.apache.nifi.util.MockFlowFile; +import org.apache.nifi.util.TestRunner; +import org.apache.nifi.util.TestRunners; +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 java.util.Map; -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 com.google.gson.Gson; -import com.rethinkdb.net.Connection; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestGetRethinkDB { private static final String DOCUMENT_ID = "id1"; @@ -39,7 +38,7 @@ public class TestGetRethinkDB { private AbstractRethinkDBProcessor mockGetRethinkDB; private Map document; - @Before + @BeforeEach public void setUp() throws Exception { mockGetRethinkDB = new GetRethinkDB() { @Override @@ -66,7 +65,7 @@ public class TestGetRethinkDB { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } diff --git a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestPutRethinkDB.java b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestPutRethinkDB.java index 9f44018c0f..c783366680 100644 --- a/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestPutRethinkDB.java +++ b/nifi-nar-bundles/nifi-rethinkdb-bundle/nifi-rethinkdb-processors/src/test/java/org/apache/nifi/processors/rethinkdb/TestPutRethinkDB.java @@ -16,27 +16,30 @@ */ package org.apache.nifi.processors.rethinkdb; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import java.util.HashMap; -import java.util.List; +import com.rethinkdb.gen.ast.Insert; +import com.rethinkdb.net.Connection; +import net.minidev.json.JSONObject; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.json.simple.JSONArray; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import com.rethinkdb.gen.ast.Insert; -import com.rethinkdb.net.Connection; -import net.minidev.json.JSONObject; +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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; public class TestPutRethinkDB { private TestRunner runner; private PutRethinkDB mockPutRethinkDB; protected HashMap result = new HashMap<>(); - @Before + @BeforeEach public void setUp() throws Exception { result.put(PutRethinkDB.RESULT_DELETED_KEY, 0L); result.put(PutRethinkDB.RESULT_ERROR_KEY, 0L); @@ -72,7 +75,7 @@ public class TestPutRethinkDB { runner.assertValid(); } - @After + @AfterEach public void tearDown() throws Exception { runner = null; } @@ -228,7 +231,7 @@ public class TestPutRethinkDB { assertEquals(flowFiles.get(0).getAttribute(PutRethinkDB.RETHINKDB_ERROR_MESSAGE),"testException"); } - @Test(expected=AssertionError.class) + @Test public void testMakeConnectionThrowsException() { mockPutRethinkDB = new PutRethinkDB() { @Override @@ -253,7 +256,7 @@ public class TestPutRethinkDB { byte [] bytes = message.toJSONString().getBytes(); runner.enqueue(bytes); - runner.run(1,true,true); + assertThrows(AssertionError.class, () -> runner.run(1,true,true)); } @Test