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 <exceptionfactory@apache.org>
This commit is contained in:
Mike Thomsen 2021-08-25 07:50:52 -04:00 committed by exceptionfactory
parent 43bf2b5975
commit f35f010deb
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
173 changed files with 2472 additions and 3554 deletions

View File

@ -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<Key, Value> 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<MockFlowFile> 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");

View File

@ -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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS);
runner.run();
List<MockFlowFile> 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<MockFlowFile> results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS);
Assert.assertEquals("Wrong count, received " + results.size(), 1, results.size());
assertRecordCount(results, 5);
runner.run();
List<MockFlowFile> 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<MockFlowFile> results = runner.getFlowFilesForRelationship(ScanAccumulo.REL_SUCCESS);
runner.run();
List<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> results, String expected) {
for (MockFlowFile ff : results) {
Assert.assertEquals(expected, ff.getContent());
assertEquals(expected, ff.getContent());
}
}
}

View File

@ -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);

View File

@ -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");

View File

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

View File

@ -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<String,String> 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<String,String> 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<String,String> 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));
}
}

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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<String, String> 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<String, String> 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<String, String> 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;

View File

@ -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 {

View File

@ -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();

View File

@ -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");
}

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -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

View File

@ -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.");
}
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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");
}
}

View File

@ -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();

View File

@ -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<Exception> 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 {

View File

@ -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<ValidationResult> 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<ValidationResult> 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<ValidationResult> 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<ValidationResult> 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<ValidationResult> 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<ValidationResult> 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"));
}
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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<GenericRecord> reader = new DataFileStream<>(in, new GenericDatumReader<GenericRecord>())) {
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++;
}
}

View File

@ -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<AmazonS3Client>() {

View File

@ -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.

View File

@ -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.

View File

@ -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<Dimension> 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);
}

View File

@ -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;
/**

View File

@ -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<PropertyDescriptor, String> 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<PropertyDescriptor, String> 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<PropertyDescriptor, String> 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<PropertyDescriptor, String> 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<PropertyDescriptor, String> 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<PropertyDescriptor, String> 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<PropertyDescriptor, String> 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<PropertyDescriptor, String> 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

View File

@ -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());
}
}

View File

@ -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;
}

View File

@ -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<String, List<WriteRequest>>());
@ -379,6 +378,5 @@ public class DeleteDynamoDBTest extends AbstractDynamoDBTest {
for (MockFlowFile flowFile : flowFiles) {
assertEquals("runtimeException", flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_ERROR_EXCEPTION_MESSAGE));
}
}
}

View File

@ -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<ConfigVerificationResult> 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<ConfigVerificationResult> 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"));
}

View File

@ -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);

View File

@ -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<MockFlowFile> 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<ConfigVerificationResult> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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));
}
}
}

View File

@ -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 {

View File

@ -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<String, List<WriteRequest>>());

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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();

View File

@ -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");

View File

@ -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");

View File

@ -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;
}

View File

@ -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;

View File

@ -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");

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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");
}
}

View File

@ -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() {

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<String, String> 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<String, String> 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<String, String> 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<String, String> 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<MockFlowFile> 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<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS);
Assert.assertEquals(1, successFiles.size());
assertEquals(1, successFiles.size());
final List<ProvenanceEventRecord> 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<PartETag>(), 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<PartETag>(), 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<PartETag>(), 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<PartETag>(), 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<PartETag>(), 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<PartETag>(), 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<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS);
Assert.assertEquals(1, successFiles.size());
assertEquals(1, successFiles.size());
final List<MockFlowFile> 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<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS);
Assert.assertEquals(1, successFiles.size());
assertEquals(1, successFiles.size());
final List<MockFlowFile> 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<MockFlowFile> successFiles = runner.getFlowFilesForRelationship(PutS3Object.REL_SUCCESS);
Assert.assertEquals(1, successFiles.size());
assertEquals(1, successFiles.size());
final List<MockFlowFile> 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<String, String> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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);

View File

@ -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");
}
}

View File

@ -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<String, String> attrs = new HashMap<>();
@ -139,10 +134,10 @@ public class TestDeleteS3Object {
}
@Test
public void testGetPropertyDescriptors() throws Exception {
public void testGetPropertyDescriptors() {
DeleteS3Object processor = new DeleteS3Object();
List<PropertyDescriptor> 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));

View File

@ -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() {

View File

@ -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() {

View File

@ -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<PropertyDescriptor> 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));

View File

@ -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<MockFlowFile> 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<MockFlowFile> 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<MockFlowFile> 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<PropertyDescriptor> 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));

View File

@ -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();
}

View File

@ -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());
}
}

View File

@ -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();
}

View File

@ -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<PropertyDescriptor> 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());
}
}

View File

@ -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();

View File

@ -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.

View File

@ -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<String, String> 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);
}
}
}

View File

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

View File

@ -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";

View File

@ -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<String, String> attrs = new HashMap<>();
attrs.put("filename", "1.txt");

View File

@ -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);

View File

@ -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;
}
};

View File

@ -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<String, String> 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<String, String> 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<String, String> attrs = new HashMap<>();
attrs.put("filename", "1.txt");
@ -129,5 +127,4 @@ public class TestPutSQS {
runner.assertAllFlowFilesTransferred(PutSQS.REL_SUCCESS, 1);
}
}

View File

@ -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}");

View File

@ -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();

View File

@ -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();
}

View File

@ -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<Group> 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<Group> 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<Group> 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<Group> 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<Group> 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());
}
}

View File

@ -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();

View File

@ -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());
}
}

View File

@ -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";

View File

@ -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;
}
}

View File

@ -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();
}

Some files were not shown because too many files have changed in this diff Show More