mirror of https://github.com/apache/nifi.git
NIFI-9103 Refactored nifi-datadog-bundle to use JUnit 5
- NIFI-9102 Refactored nifi-cybersecurity-bundle to use JUnit 5 - NIFI-9101 Refactored nifi-couchbase-bundle to use JUnit 5 - NIFI-9100 Refactored nifi-confluent-platform-bundle to use JUnit 5 - NIFI-9099 Refactored nifi-cdc to use JUnit 5 - NIFI-9098 Refactored nifi-ccda-bundle to use JUnit 5 - NIFI-9097 Refactored nifi-cassandra-bundle to use JUnit 5 - NIFI-9096 Refactored nifi-beats-bundle to use JUnit 5 This closes #5789 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
ab4cadc204
commit
8b62ebeb76
|
@ -16,20 +16,20 @@
|
|||
*/
|
||||
package org.apache.nifi.processors.beats.frame;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
|
||||
public class TestBeatsEncoder {
|
||||
private BeatsEncoder encoder;
|
||||
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.encoder = new BeatsEncoder();
|
||||
}
|
||||
|
@ -44,6 +44,6 @@ public class TestBeatsEncoder {
|
|||
|
||||
byte[] encoded = encoder.encode(frame);
|
||||
|
||||
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("31410000007B"), encoded);
|
||||
assertArrayEquals(DatatypeConverter.parseHexBinary("31410000007B"), encoded);
|
||||
}
|
||||
}
|
|
@ -16,23 +16,24 @@
|
|||
*/
|
||||
package org.apache.nifi.processors.beats.frame;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class TestBeatsFrame {
|
||||
|
||||
@Test(expected = BeatsFrameException.class)
|
||||
@Test
|
||||
public void testInvalidVersion() {
|
||||
new BeatsFrame.Builder().seqNumber(1234).dataSize(3).build();
|
||||
assertThrows(BeatsFrameException.class, () -> new BeatsFrame.Builder().seqNumber(1234).dataSize(3).build());
|
||||
}
|
||||
|
||||
@Test(expected = BeatsFrameException.class)
|
||||
@Test
|
||||
public void testInvalidFrameType() {
|
||||
new BeatsFrame.Builder().frameType((byte) 0x70).dataSize(5).build();
|
||||
assertThrows(BeatsFrameException.class, () -> new BeatsFrame.Builder().frameType((byte) 0x70).dataSize(5).build());
|
||||
}
|
||||
|
||||
@Test(expected = BeatsFrameException.class)
|
||||
@Test
|
||||
public void testBlankFrameType() {
|
||||
new BeatsFrame.Builder().frameType(((byte) 0x00)).dataSize(5).build();
|
||||
assertThrows(BeatsFrameException.class, () -> new BeatsFrame.Builder().frameType(((byte) 0x00)).dataSize(5).build());
|
||||
}
|
||||
}
|
|
@ -27,9 +27,10 @@ import org.apache.nifi.processor.exception.ProcessException
|
|||
import org.apache.nifi.service.CassandraSessionProvider
|
||||
import org.apache.nifi.util.TestRunner
|
||||
import org.apache.nifi.util.TestRunners
|
||||
import org.junit.AfterClass
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* Setup instructions:
|
||||
*
|
||||
|
@ -46,7 +47,7 @@ class CassandraDistributedMapCacheIT {
|
|||
static CassandraDistributedMapCache distributedMapCache
|
||||
static Session session
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
runner = TestRunners.newTestRunner(new AbstractProcessor() {
|
||||
@Override
|
||||
|
@ -82,7 +83,7 @@ class CassandraDistributedMapCacheIT {
|
|||
""")
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
session.execute("TRUNCATE dmc")
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ import org.apache.nifi.service.CassandraSessionProvider;
|
|||
import org.apache.nifi.ssl.SSLContextService;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -46,10 +46,11 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
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.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -61,7 +62,7 @@ public class AbstractCassandraProcessorTest {
|
|||
MockAbstractCassandraProcessor processor;
|
||||
private TestRunner testRunner;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
processor = new MockAbstractCassandraProcessor();
|
||||
testRunner = TestRunners.newTestRunner(processor);
|
||||
|
@ -137,9 +138,9 @@ public class AbstractCassandraProcessorTest {
|
|||
assertEquals(AbstractCassandraProcessor.getSchemaForType("bytes").getType().getName(), "bytes");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetSchemaForTypeBadType() throws Exception {
|
||||
AbstractCassandraProcessor.getSchemaForType("nothing");
|
||||
assertThrows(IllegalArgumentException.class, () -> AbstractCassandraProcessor.getSchemaForType("nothing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -165,10 +166,10 @@ public class AbstractCassandraProcessorTest {
|
|||
assertEquals("bytes", AbstractCassandraProcessor.getPrimitiveAvroTypeFromCassandraType(DataType.blob()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testGetPrimitiveAvroTypeFromCassandraTypeBadType() throws Exception {
|
||||
DataType mockDataType = mock(DataType.class);
|
||||
AbstractCassandraProcessor.getPrimitiveAvroTypeFromCassandraType(mockDataType);
|
||||
assertThrows(IllegalArgumentException.class, () -> AbstractCassandraProcessor.getPrimitiveAvroTypeFromCassandraType(mockDataType));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -33,8 +33,8 @@ import com.datastax.driver.core.exceptions.UnavailableException;
|
|||
import org.apache.nifi.processor.exception.ProcessException;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -43,7 +43,7 @@ import java.util.List;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
@ -60,7 +60,7 @@ public class PutCassandraQLTest {
|
|||
private TestRunner testRunner;
|
||||
private MockPutCassandraQL processor;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
processor = new MockPutCassandraQL();
|
||||
testRunner = TestRunners.newTestRunner(processor);
|
||||
|
|
|
@ -27,14 +27,15 @@ import org.apache.nifi.serialization.record.MockRecordParser;
|
|||
import org.apache.nifi.serialization.record.RecordFieldType;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class PutCassandraRecordIT {
|
||||
|
||||
private static TestRunner testRunner;
|
||||
|
@ -48,7 +49,7 @@ public class PutCassandraRecordIT {
|
|||
private static final String HOST = "localhost";
|
||||
private static final int PORT = 9042;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws InitializationException {
|
||||
recordReader = new MockRecordParser();
|
||||
testRunner = TestRunners.newTestRunner(PutCassandraRecord.class);
|
||||
|
@ -88,7 +89,7 @@ public class PutCassandraRecordIT {
|
|||
testRunner.run();
|
||||
|
||||
testRunner.assertAllFlowFilesTransferred(PutCassandraRecord.REL_SUCCESS, 1);
|
||||
Assert.assertEquals(5, getRecordsCount());
|
||||
assertEquals(5, getRecordsCount());
|
||||
}
|
||||
|
||||
private int getRecordsCount() {
|
||||
|
@ -109,7 +110,7 @@ public class PutCassandraRecordIT {
|
|||
session.execute(query);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void shutdown() {
|
||||
String dropKeyspace = "DROP KEYSPACE " + KEYSPACE;
|
||||
String dropTable = "DROP TABLE IF EXISTS " + KEYSPACE + "." + TABLE;
|
||||
|
|
|
@ -20,8 +20,8 @@ import com.datastax.driver.core.querybuilder.Insert;
|
|||
import org.apache.nifi.serialization.record.RecordFieldType;
|
||||
import org.apache.nifi.serialization.record.RecordSchema;
|
||||
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 org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
|
@ -31,7 +31,7 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class PutCassandraRecordInsertTest {
|
|||
@Mock
|
||||
private RecordSchema schema;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ import org.apache.nifi.serialization.record.RecordField;
|
|||
import org.apache.nifi.serialization.record.RecordFieldType;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.InetSocketAddress;
|
||||
|
@ -42,7 +42,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
@ -56,7 +56,7 @@ public class PutCassandraRecordTest {
|
|||
private TestRunner testRunner;
|
||||
private MockRecordParser recordReader;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
MockPutCassandraRecord processor = new MockPutCassandraRecord();
|
||||
recordReader = new MockRecordParser();
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.apache.nifi.processors.cassandra;
|
|||
import com.datastax.driver.core.Statement;
|
||||
import org.apache.nifi.serialization.record.RecordSchema;
|
||||
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 org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
|
@ -30,8 +30,8 @@ import java.util.Map;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class PutCassandraRecordUpdateTest {
|
||||
|
@ -40,7 +40,7 @@ public class PutCassandraRecordUpdateTest {
|
|||
@Mock
|
||||
private RecordSchema schema;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
|
|
|
@ -16,16 +16,6 @@
|
|||
*/
|
||||
package org.apache.nifi.processors.cassandra;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Configuration;
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
|
@ -38,6 +28,17 @@ import com.datastax.driver.core.SniEndPoint;
|
|||
import com.datastax.driver.core.exceptions.InvalidQueryException;
|
||||
import com.datastax.driver.core.exceptions.NoHostAvailableException;
|
||||
import com.datastax.driver.core.exceptions.ReadTimeoutException;
|
||||
import org.apache.avro.Schema;
|
||||
import org.apache.nifi.processor.exception.ProcessException;
|
||||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.MockProcessContext;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -50,16 +51,16 @@ import java.util.Optional;
|
|||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import org.apache.avro.Schema;
|
||||
import org.apache.nifi.processor.exception.ProcessException;
|
||||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.MockProcessContext;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class QueryCassandraTest {
|
||||
|
@ -67,7 +68,7 @@ public class QueryCassandraTest {
|
|||
private TestRunner testRunner;
|
||||
private MockQueryCassandra processor;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
processor = new MockQueryCassandra();
|
||||
testRunner = TestRunners.newTestRunner(processor);
|
||||
|
@ -150,7 +151,7 @@ public class QueryCassandraTest {
|
|||
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
|
||||
List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS);
|
||||
assertNotNull(files);
|
||||
assertEquals("One file should be transferred to success", 1, files.size());
|
||||
assertEquals(1, files.size(), "One file should be transferred to success");
|
||||
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
|
||||
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"],"
|
||||
+ "\"todo\":{\"2016-01-03 05:00:00+0000\":\"Set my alarm \\\"for\\\" a month from now\"},"
|
||||
|
@ -187,7 +188,7 @@ public class QueryCassandraTest {
|
|||
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
|
||||
List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS);
|
||||
assertNotNull(files);
|
||||
assertEquals("One file should be transferred to success", 1, files.size());
|
||||
assertEquals(1, files.size(), "One file should be transferred to success");
|
||||
assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
|
||||
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"],"
|
||||
+ "\"todo\":{\"2016-01-03 05:00:00+0000\":\"Set my alarm \\\"for\\\" a month from now\"},"
|
||||
|
@ -211,7 +212,7 @@ public class QueryCassandraTest {
|
|||
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
|
||||
List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS);
|
||||
assertNotNull(files);
|
||||
assertEquals("One file should be transferred to success", 1, files.size());
|
||||
assertEquals(1, files.size(), "One file should be transferred to success");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -20,20 +20,20 @@ import org.apache.nifi.components.PropertyDescriptor;
|
|||
import org.apache.nifi.reporting.InitializationException;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestCassandraSessionProvider {
|
||||
|
||||
private static TestRunner runner;
|
||||
private static CassandraSessionProvider sessionProvider;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() throws InitializationException {
|
||||
MockCassandraProcessor mockCassandraProcessor = new MockCassandraProcessor();
|
||||
sessionProvider = new CassandraSessionProvider();
|
||||
|
|
|
@ -16,17 +16,12 @@
|
|||
*/
|
||||
package org.apache.nifi.processors.ccda;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openhealthtools.mdht.uml.cda.consol.ConsolFactory;
|
||||
import org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument;
|
||||
import org.openhealthtools.mdht.uml.cda.consol.ProblemConcernAct;
|
||||
|
@ -38,17 +33,22 @@ import org.openhealthtools.mdht.uml.cda.consol.VitalSignsOrganizer;
|
|||
import org.openhealthtools.mdht.uml.cda.consol.VitalSignsSection;
|
||||
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class TestExtractCCDAAttributes {
|
||||
|
||||
private TestRunner runner;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "INFO");
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
runner = TestRunners.newTestRunner(ExtractCCDAAttributes.class);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,10 @@ import com.github.shyiko.mysql.binlog.event.WriteRowsEventData
|
|||
import com.github.shyiko.mysql.binlog.network.SSLMode
|
||||
import groovy.json.JsonSlurper
|
||||
import org.apache.commons.io.output.WriterOutputStream
|
||||
import org.apache.nifi.cdc.event.ColumnDefinition
|
||||
import org.apache.nifi.cdc.event.TableInfo
|
||||
import org.apache.nifi.cdc.event.TableInfoCacheKey
|
||||
import org.apache.nifi.cdc.event.io.EventWriter
|
||||
import org.apache.nifi.cdc.mysql.MockBinlogClient
|
||||
import org.apache.nifi.cdc.mysql.event.BinlogEventInfo
|
||||
import org.apache.nifi.cdc.mysql.processors.ssl.BinaryLogSSLSocketFactory
|
||||
|
@ -43,11 +47,6 @@ import org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService
|
|||
import org.apache.nifi.distributed.cache.client.Serializer
|
||||
import org.apache.nifi.flowfile.attributes.CoreAttributes
|
||||
import org.apache.nifi.logging.ComponentLog
|
||||
|
||||
import org.apache.nifi.cdc.event.ColumnDefinition
|
||||
import org.apache.nifi.cdc.event.TableInfo
|
||||
import org.apache.nifi.cdc.event.TableInfoCacheKey
|
||||
import org.apache.nifi.cdc.event.io.EventWriter
|
||||
import org.apache.nifi.processor.exception.ProcessException
|
||||
import org.apache.nifi.provenance.ProvenanceEventType
|
||||
import org.apache.nifi.reporting.InitializationException
|
||||
|
@ -57,9 +56,9 @@ import org.apache.nifi.util.MockComponentLog
|
|||
import org.apache.nifi.util.MockControllerServiceInitializationContext
|
||||
import org.apache.nifi.util.TestRunner
|
||||
import org.apache.nifi.util.TestRunners
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.function.Executable
|
||||
|
||||
import javax.net.ssl.SSLContext
|
||||
import java.sql.Connection
|
||||
|
@ -70,9 +69,10 @@ import java.util.concurrent.TimeoutException
|
|||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
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.junit.jupiter.api.Assertions.assertThrows
|
||||
import static org.mockito.ArgumentMatchers.anyString
|
||||
import static org.mockito.Mockito.doReturn
|
||||
import static org.mockito.Mockito.mock
|
||||
|
@ -89,18 +89,13 @@ class CaptureChangeMySQLTest {
|
|||
TestRunner testRunner
|
||||
MockBinlogClient client
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
processor = new MockCaptureChangeMySQL()
|
||||
testRunner = TestRunners.newTestRunner(processor)
|
||||
client = new MockBinlogClient('localhost', 3306, 'root', 'password')
|
||||
}
|
||||
|
||||
@After
|
||||
void tearDown() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSslModeDisabledSslContextServiceNotRequired() {
|
||||
testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306')
|
||||
|
@ -148,10 +143,10 @@ class CaptureChangeMySQLTest {
|
|||
testRunner.assertValid()
|
||||
|
||||
testRunner.run()
|
||||
assertEquals("SSL Mode not matched", sslMode, client.getSSLMode())
|
||||
assertEquals(sslMode, client.getSSLMode(), "SSL Mode not matched")
|
||||
def sslSocketFactory = client.sslSocketFactory
|
||||
assertNotNull('Binary Log SSLSocketFactory not found', sslSocketFactory)
|
||||
assertEquals('Binary Log SSLSocketFactory class not matched', BinaryLogSSLSocketFactory.class, sslSocketFactory.getClass())
|
||||
assertNotNull(sslSocketFactory, 'Binary Log SSLSocketFactory not found')
|
||||
assertEquals(BinaryLogSSLSocketFactory.class, sslSocketFactory.getClass(), 'Binary Log SSLSocketFactory class not matched')
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -348,7 +343,7 @@ class CaptureChangeMySQLTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
@Test
|
||||
void testCommitWithoutBegin() throws Exception {
|
||||
testRunner.setProperty(CaptureChangeMySQL.DRIVER_LOCATION, DRIVER_LOCATION)
|
||||
testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306')
|
||||
|
@ -356,15 +351,14 @@ class CaptureChangeMySQLTest {
|
|||
testRunner.setProperty(CaptureChangeMySQL.PASSWORD, 'password')
|
||||
testRunner.setProperty(CaptureChangeMySQL.CONNECT_TIMEOUT, '2 seconds')
|
||||
|
||||
testRunner.run(1, false, true)
|
||||
testRunner.run(1, false, true)
|
||||
|
||||
// COMMIT
|
||||
client.sendEvent(new Event(
|
||||
[timestamp: new Date().time, eventType: EventType.XID, nextPosition: 12] as EventHeaderV4,
|
||||
{} as EventData
|
||||
))
|
||||
|
||||
testRunner.run(1, true, false)
|
||||
assertThrows(AssertionError.class, { testRunner.run(1, true, false) } as Executable)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -593,7 +587,7 @@ class CaptureChangeMySQLTest {
|
|||
assertEquals(5, resultFiles.size())
|
||||
}
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
@Test
|
||||
void testNoTableInformationAvailable() throws Exception {
|
||||
testRunner.setProperty(CaptureChangeMySQL.DRIVER_LOCATION, DRIVER_LOCATION)
|
||||
testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306')
|
||||
|
@ -634,7 +628,7 @@ class CaptureChangeMySQLTest {
|
|||
{} as EventData
|
||||
))
|
||||
|
||||
testRunner.run(1, true, false)
|
||||
assertThrows(AssertionError.class, { testRunner.run(1, true, false) } as Executable)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
*/
|
||||
package org.apache.nifi.cdc.mysql.event;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,18 +16,17 @@
|
|||
*/
|
||||
package org.apache.nifi.cdc.mysql.processors.ssl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
@ -47,9 +46,9 @@ public class BinaryLogSSLSocketFactoryTest {
|
|||
when(socket.getPort()).thenReturn(PORT);
|
||||
|
||||
final SSLSocket sslSocket = socketFactory.createSocket(socket);
|
||||
assertNotNull("SSL Socket not found", sslSocket);
|
||||
assertEquals("Address not matched", address, sslSocket.getInetAddress());
|
||||
assertEquals("Port not matched", PORT, sslSocket.getPort());
|
||||
assertNotNull(sslSocket, "SSL Socket not found");
|
||||
assertEquals(address, sslSocket.getInetAddress(), "Address not matched");
|
||||
assertEquals(PORT, sslSocket.getPort(), "Port not matched");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -21,8 +21,8 @@ import org.apache.nifi.processor.Processor;
|
|||
import org.apache.nifi.reporting.InitializationException;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class ConfluentSchemaRegistryTest {
|
||||
|
@ -33,7 +33,7 @@ public class ConfluentSchemaRegistryTest {
|
|||
|
||||
private ConfluentSchemaRegistry registry;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() throws InitializationException {
|
||||
registry = new ConfluentSchemaRegistry();
|
||||
final Processor processor = Mockito.mock(Processor.class);
|
||||
|
|
|
@ -23,9 +23,10 @@ import org.apache.nifi.processor.exception.ProcessException;
|
|||
import org.apache.nifi.reporting.InitializationException;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
||||
public class TestCouchbaseClusterService {
|
||||
|
@ -40,8 +41,8 @@ public class TestCouchbaseClusterService {
|
|||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
|
||||
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
|
||||
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.couchbase.PutCouchbaseKey", "debug");
|
||||
|
@ -58,11 +59,6 @@ public class TestCouchbaseClusterService {
|
|||
CouchbaseClusterControllerService service = new CouchbaseClusterService();
|
||||
testRunner.addControllerService(SERVICE_ID, service);
|
||||
testRunner.setProperty(service, CouchbaseClusterService.CONNECTION_STRING, connectionString);
|
||||
try {
|
||||
testRunner.enableControllerService(service);
|
||||
Assert.fail("The service shouldn't be enabled when it couldn't connect to a cluster.");
|
||||
} catch (AssertionError e) {
|
||||
}
|
||||
assertThrows(AssertionError.class, () -> testRunner.enableControllerService(service));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.apache.nifi.distributed.cache.client.Deserializer;
|
|||
import org.apache.nifi.distributed.cache.client.Serializer;
|
||||
import org.apache.nifi.util.MockConfigurationContext;
|
||||
import org.apache.nifi.util.MockControllerServiceInitializationContext;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
|
@ -33,7 +33,7 @@ import java.util.Map;
|
|||
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME;
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -69,5 +69,4 @@ public class TestCouchbaseMapCacheClient {
|
|||
|
||||
assertEquals("value", cacheEntry);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -33,18 +33,18 @@ import com.couchbase.client.java.document.StringDocument;
|
|||
import com.couchbase.client.java.document.json.JsonArray;
|
||||
import com.couchbase.client.java.document.json.JsonObject;
|
||||
import com.couchbase.client.java.error.TranscodingException;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestCouchbaseUtils {
|
||||
|
||||
@Ignore("This test method requires a live Couchbase Server instance")
|
||||
@Disabled("This test method requires a live Couchbase Server instance")
|
||||
@Test
|
||||
public void testDocumentTypesAndStringConversion() {
|
||||
final CouchbaseCluster cluster = CouchbaseCluster.fromConnectionString("couchbase://192.168.99.100:8091");
|
||||
|
@ -86,12 +86,7 @@ public class TestCouchbaseUtils {
|
|||
final String stringFromByteBuff = CouchbaseUtils.getStringContent(binaryDocument.content());
|
||||
assertEquals("value", stringFromByteBuff);
|
||||
|
||||
try {
|
||||
bucket.get(BinaryDocument.create("JsonDocument"));
|
||||
fail("Getting a JSON document as a BinaryDocument fails");
|
||||
} catch (TranscodingException e) {
|
||||
assertTrue(e.getMessage().contains("Flags (0x2000000) indicate non-binary document for id JsonDocument"));
|
||||
}
|
||||
|
||||
TranscodingException e = assertThrows(TranscodingException.class, () -> bucket.get(BinaryDocument.create("JsonDocument")));
|
||||
assertTrue(e.getMessage().contains("Flags (0x2000000) indicate non-binary document for id JsonDocument"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,9 +38,8 @@ import org.apache.nifi.reporting.InitializationException;
|
|||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
|
@ -56,8 +55,9 @@ import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.RE
|
|||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_SUCCESS;
|
||||
import static org.apache.nifi.processors.couchbase.CouchbaseAttributes.Exception;
|
||||
import static org.apache.nifi.processors.couchbase.GetCouchbaseKey.PUT_VALUE_TO_ATTRIBUTE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -68,7 +68,7 @@ public class TestGetCouchbaseKey {
|
|||
private static final String SERVICE_ID = "couchbaseClusterService";
|
||||
private TestRunner testRunner;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() throws Exception {
|
||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
|
||||
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
|
||||
|
@ -185,12 +185,8 @@ public class TestGetCouchbaseKey {
|
|||
testRunner.setProperty(DOC_ID, docIdExp);
|
||||
testRunner.enqueue(new byte[0]);
|
||||
|
||||
try {
|
||||
testRunner.run();
|
||||
fail("Exception should be thrown.");
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
|
||||
}
|
||||
AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
|
||||
assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
|
||||
|
||||
testRunner.assertTransferCount(REL_SUCCESS, 0);
|
||||
testRunner.assertTransferCount(REL_ORIGINAL, 0);
|
||||
|
@ -212,12 +208,9 @@ public class TestGetCouchbaseKey {
|
|||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("someProperty", "someValue");
|
||||
testRunner.enqueue(inFileData, properties);
|
||||
try {
|
||||
testRunner.run();
|
||||
fail("Exception should be thrown.");
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
|
||||
}
|
||||
|
||||
AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
|
||||
assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
|
||||
|
||||
testRunner.assertTransferCount(REL_SUCCESS, 0);
|
||||
testRunner.assertTransferCount(REL_ORIGINAL, 0);
|
||||
|
@ -367,12 +360,9 @@ public class TestGetCouchbaseKey {
|
|||
|
||||
byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
|
||||
testRunner.enqueue(inFileData);
|
||||
try {
|
||||
testRunner.run();
|
||||
fail("ProcessException should be thrown.");
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
|
||||
}
|
||||
|
||||
AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
|
||||
assertTrue(e.getCause().getClass().equals(ProcessException.class));
|
||||
|
||||
testRunner.assertTransferCount(REL_SUCCESS, 0);
|
||||
testRunner.assertTransferCount(REL_ORIGINAL, 0);
|
||||
|
@ -394,13 +384,10 @@ public class TestGetCouchbaseKey {
|
|||
String inputFileDataStr = "input FlowFile data";
|
||||
byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
|
||||
testRunner.enqueue(inFileData);
|
||||
try {
|
||||
testRunner.run();
|
||||
fail("ProcessException should be thrown.");
|
||||
} catch (AssertionError e) {
|
||||
Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
|
||||
Assert.assertTrue(e.getCause().getCause().getClass().equals(AuthenticationException.class));
|
||||
}
|
||||
|
||||
AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
|
||||
assertTrue(e.getCause().getClass().equals(ProcessException.class));
|
||||
assertTrue(e.getCause().getCause().getClass().equals(AuthenticationException.class));
|
||||
|
||||
testRunner.assertTransferCount(REL_SUCCESS, 0);
|
||||
testRunner.assertTransferCount(REL_ORIGINAL, 0);
|
||||
|
@ -486,7 +473,7 @@ public class TestGetCouchbaseKey {
|
|||
MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
|
||||
orgFile.assertContentEquals(inputFileDataStr);
|
||||
orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
|
||||
Assert.assertEquals(true, orgFile.isPenalized());
|
||||
assertEquals(true, orgFile.isPenalized());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,30 +16,15 @@
|
|||
*/
|
||||
package org.apache.nifi.processors.couchbase;
|
||||
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME;
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE;
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.DOCUMENT_TYPE;
|
||||
import static org.apache.nifi.processors.couchbase.CouchbaseAttributes.Exception;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.DOC_ID;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_FAILURE;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_RETRY;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_SUCCESS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.couchbase.client.core.CouchbaseException;
|
||||
import com.couchbase.client.core.ServiceNotAvailableException;
|
||||
import com.couchbase.client.deps.io.netty.buffer.Unpooled;
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.PersistTo;
|
||||
import com.couchbase.client.java.ReplicateTo;
|
||||
import com.couchbase.client.java.document.ByteArrayDocument;
|
||||
import com.couchbase.client.java.document.RawJsonDocument;
|
||||
import com.couchbase.client.java.error.DurabilityException;
|
||||
import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException;
|
||||
import org.apache.nifi.couchbase.CouchbaseClusterControllerService;
|
||||
import org.apache.nifi.couchbase.DocumentType;
|
||||
|
@ -49,18 +34,32 @@ import org.apache.nifi.reporting.InitializationException;
|
|||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Assert;
|
||||
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 com.couchbase.client.core.CouchbaseException;
|
||||
import com.couchbase.client.core.ServiceNotAvailableException;
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.PersistTo;
|
||||
import com.couchbase.client.java.ReplicateTo;
|
||||
import com.couchbase.client.java.document.RawJsonDocument;
|
||||
import com.couchbase.client.java.error.DurabilityException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME;
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE;
|
||||
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.DOCUMENT_TYPE;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.DOC_ID;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_FAILURE;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_RETRY;
|
||||
import static org.apache.nifi.processors.couchbase.AbstractCouchbaseProcessor.REL_SUCCESS;
|
||||
import static org.apache.nifi.processors.couchbase.CouchbaseAttributes.Exception;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class TestPutCouchbaseKey {
|
||||
|
@ -68,7 +67,7 @@ public class TestPutCouchbaseKey {
|
|||
private static final String SERVICE_ID = "couchbaseClusterService";
|
||||
private TestRunner testRunner;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() throws Exception {
|
||||
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
|
||||
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
|
||||
|
@ -237,12 +236,9 @@ public class TestPutCouchbaseKey {
|
|||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("someProperty", somePropertyValue);
|
||||
testRunner.enqueue(inFileDataBytes, properties);
|
||||
try {
|
||||
testRunner.run();
|
||||
fail("Exception should be thrown.");
|
||||
} catch (AssertionError e){
|
||||
Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
|
||||
}
|
||||
|
||||
AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
|
||||
assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
|
||||
|
||||
testRunner.assertTransferCount(REL_SUCCESS, 0);
|
||||
testRunner.assertTransferCount(REL_RETRY, 0);
|
||||
|
@ -294,12 +290,9 @@ public class TestPutCouchbaseKey {
|
|||
testRunner.enqueue(inFileDataBytes);
|
||||
testRunner.setProperty(DOC_ID, docId);
|
||||
testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
|
||||
try {
|
||||
testRunner.run();
|
||||
fail("ProcessException should be thrown.");
|
||||
} catch (AssertionError e){
|
||||
Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
|
||||
}
|
||||
|
||||
AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
|
||||
assertTrue(e.getCause().getClass().equals(ProcessException.class));
|
||||
|
||||
verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE));
|
||||
|
||||
|
|
|
@ -22,15 +22,16 @@ import org.apache.nifi.processors.cybersecurity.matchers.SSDeepHashMatcher;
|
|||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
public class TestCompareFuzzyHash {
|
||||
String ssdeepInput = "48:c1xs8Z/m6H0eRH31S8p8bHENANkPrNy4tkPytwPyh2jTytxPythPytNdPytDgYyF:OuO/mg3HFSRHEb44RNMi6uHU2hcq3";
|
||||
|
@ -39,7 +40,7 @@ public class TestCompareFuzzyHash {
|
|||
final CompareFuzzyHash proc = new CompareFuzzyHash();
|
||||
final private TestRunner runner = TestRunners.newTestRunner(proc);
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stop() {
|
||||
runner.shutdown();
|
||||
}
|
||||
|
@ -70,7 +71,7 @@ public class TestCompareFuzzyHash {
|
|||
"\"nifi/nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml\""
|
||||
);
|
||||
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
|
||||
Assert.assertTrue(similarity >= matchingSimilarity);
|
||||
assertTrue(similarity >= matchingSimilarity);
|
||||
|
||||
outFile.assertAttributeNotExists("fuzzyhash.value.1.match");
|
||||
}
|
||||
|
@ -101,13 +102,13 @@ public class TestCompareFuzzyHash {
|
|||
);
|
||||
|
||||
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
|
||||
Assert.assertTrue(similarity >= matchingSimilarity);
|
||||
assertTrue(similarity >= matchingSimilarity);
|
||||
|
||||
outFile.assertAttributeEquals("fuzzyhash.value.1.match",
|
||||
"\"nifi/nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml\""
|
||||
);
|
||||
similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.1.similarity"));
|
||||
Assert.assertTrue(similarity >= matchingSimilarity);
|
||||
assertTrue(similarity >= matchingSimilarity);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -203,7 +204,7 @@ public class TestCompareFuzzyHash {
|
|||
"nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/pom.xml"
|
||||
);
|
||||
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
|
||||
Assert.assertTrue(similarity <= matchingSimilarity);
|
||||
assertTrue(similarity <= matchingSimilarity);
|
||||
|
||||
outFile.assertAttributeNotExists("fuzzyhash.value.1.match");
|
||||
}
|
||||
|
@ -233,14 +234,14 @@ public class TestCompareFuzzyHash {
|
|||
"nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/pom.xml"
|
||||
);
|
||||
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
|
||||
Assert.assertTrue(similarity <= matchingSimilarity);
|
||||
assertTrue(similarity <= matchingSimilarity);
|
||||
|
||||
outFile.assertAttributeEquals(
|
||||
"fuzzyhash.value.1.match",
|
||||
"nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml"
|
||||
);
|
||||
similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.1.similarity"));
|
||||
Assert.assertTrue(similarity <= matchingSimilarity);
|
||||
assertTrue(similarity <= matchingSimilarity);
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,11 +371,11 @@ public class TestCompareFuzzyHash {
|
|||
);
|
||||
|
||||
for (String item : invalidPayloads) {
|
||||
Assert.assertTrue("item '" + item + "' should have failed validation", !matcher.isValidHash(item));
|
||||
assertTrue(!matcher.isValidHash(item), "item '" + item + "' should have failed validation");
|
||||
}
|
||||
|
||||
// Now test with a valid string
|
||||
Assert.assertTrue(matcher.isValidHash(ssdeepInput));
|
||||
assertTrue(matcher.isValidHash(ssdeepInput));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,22 +20,23 @@ package org.apache.nifi.processors.cybersecurity;
|
|||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
public class TestFuzzyHashContent {
|
||||
|
||||
private TestRunner runner;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
runner = TestRunners.newTestRunner(FuzzyHashContent.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void stop() {
|
||||
runner.shutdown();
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ public class TestFuzzyHashContent {
|
|||
|
||||
final MockFlowFile outFile = runner.getFlowFilesForRelationship(FuzzyHashContent.REL_SUCCESS).get(0);
|
||||
|
||||
Assert.assertEquals("6:hERjIfhRrlB63J0FDw1NBQmEH68xwMSELN:hZrlB62IwMS",outFile.getAttribute("fuzzyhash.value") );
|
||||
assertEquals("6:hERjIfhRrlB63J0FDw1NBQmEH68xwMSELN:hZrlB62IwMS",outFile.getAttribute("fuzzyhash.value") );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -89,7 +90,7 @@ public class TestFuzzyHashContent {
|
|||
|
||||
final MockFlowFile outFile = runner.getFlowFilesForRelationship(FuzzyHashContent.REL_SUCCESS).get(0);
|
||||
|
||||
Assert.assertEquals("E2F0818B7AE7173906A72221570E30979B11C0FC47B518A1E89D257E2343CEC02381ED",
|
||||
assertEquals("E2F0818B7AE7173906A72221570E30979B11C0FC47B518A1E89D257E2343CEC02381ED",
|
||||
outFile.getAttribute("fuzzyhash.value"));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ import org.apache.nifi.reporting.ReportingContext;
|
|||
import org.apache.nifi.reporting.ReportingInitializationContext;
|
||||
import org.apache.nifi.reporting.datadog.metrics.MetricsService;
|
||||
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.Mockito;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -61,7 +61,7 @@ public class TestDataDogReportingTask {
|
|||
private volatile JmxJvmMetrics virtualMachineMetrics;
|
||||
private Logger logger;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
initProcessGroupStatus();
|
||||
initProcessorStatuses();
|
||||
|
|
|
@ -21,20 +21,21 @@ import org.apache.nifi.controller.status.ProcessorStatus;
|
|||
import org.apache.nifi.metrics.jvm.JmxJvmMetrics;
|
||||
import org.apache.nifi.reporting.datadog.metrics.MetricNames;
|
||||
import org.apache.nifi.reporting.datadog.metrics.MetricsService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestMetricsService {
|
||||
|
||||
private ProcessGroupStatus status;
|
||||
private MetricsService metricsService;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
status = new ProcessGroupStatus();
|
||||
metricsService = new MetricsService();
|
||||
|
@ -60,15 +61,15 @@ public class TestMetricsService {
|
|||
|
||||
final Map<String, Double> metrics = metricsService.getDataFlowMetrics(status);
|
||||
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
//test processor status metric retrieving
|
||||
|
@ -81,11 +82,11 @@ public class TestMetricsService {
|
|||
|
||||
final Map<String, Double> metrics = metricsService.getProcessorMetrics(procStatus);
|
||||
|
||||
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
|
||||
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
|
||||
Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
|
||||
Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
|
||||
Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
|
||||
assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
|
||||
assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
|
||||
assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
|
||||
assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
|
||||
assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
|
||||
}
|
||||
|
||||
//test JVM status metric retrieving
|
||||
|
@ -94,17 +95,17 @@ public class TestMetricsService {
|
|||
final JmxJvmMetrics virtualMachineMetrics = JmxJvmMetrics.getInstance();
|
||||
|
||||
final Map<String, Double> metrics = metricsService.getJVMMetrics(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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue