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:
Mike Thomsen 2021-08-25 15:31:05 -04:00 committed by exceptionfactory
parent ab4cadc204
commit 8b62ebeb76
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
25 changed files with 259 additions and 288 deletions

View File

@ -16,20 +16,20 @@
*/ */
package org.apache.nifi.processors.beats.frame; 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 javax.xml.bind.DatatypeConverter;
import java.nio.ByteBuffer;
import org.junit.Assert; import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import org.junit.Before;
import org.junit.Test;
public class TestBeatsEncoder { public class TestBeatsEncoder {
private BeatsEncoder encoder; private BeatsEncoder encoder;
@Before @BeforeEach
public void setup() { public void setup() {
this.encoder = new BeatsEncoder(); this.encoder = new BeatsEncoder();
} }
@ -44,6 +44,6 @@ public class TestBeatsEncoder {
byte[] encoded = encoder.encode(frame); byte[] encoded = encoder.encode(frame);
Assert.assertArrayEquals(DatatypeConverter.parseHexBinary("31410000007B"), encoded); assertArrayEquals(DatatypeConverter.parseHexBinary("31410000007B"), encoded);
} }
} }

View File

@ -16,23 +16,24 @@
*/ */
package org.apache.nifi.processors.beats.frame; 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 { public class TestBeatsFrame {
@Test(expected = BeatsFrameException.class) @Test
public void testInvalidVersion() { 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() { 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() { public void testBlankFrameType() {
new BeatsFrame.Builder().frameType(((byte) 0x00)).dataSize(5).build(); assertThrows(BeatsFrameException.class, () -> new BeatsFrame.Builder().frameType(((byte) 0x00)).dataSize(5).build());
} }
} }

View File

@ -27,9 +27,10 @@ import org.apache.nifi.processor.exception.ProcessException
import org.apache.nifi.service.CassandraSessionProvider import org.apache.nifi.service.CassandraSessionProvider
import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunner
import org.apache.nifi.util.TestRunners import org.apache.nifi.util.TestRunners
import org.junit.AfterClass import org.junit.jupiter.api.AfterAll
import org.junit.BeforeClass import org.junit.jupiter.api.BeforeAll
import org.junit.Test import org.junit.jupiter.api.Test
/** /**
* Setup instructions: * Setup instructions:
* *
@ -46,7 +47,7 @@ class CassandraDistributedMapCacheIT {
static CassandraDistributedMapCache distributedMapCache static CassandraDistributedMapCache distributedMapCache
static Session session static Session session
@BeforeClass @BeforeAll
static void setup() { static void setup() {
runner = TestRunners.newTestRunner(new AbstractProcessor() { runner = TestRunners.newTestRunner(new AbstractProcessor() {
@Override @Override
@ -82,7 +83,7 @@ class CassandraDistributedMapCacheIT {
""") """)
} }
@AfterClass @AfterAll
static void cleanup() { static void cleanup() {
session.execute("TRUNCATE dmc") session.execute("TRUNCATE dmc")
} }

View File

@ -33,8 +33,8 @@ import org.apache.nifi.service.CassandraSessionProvider;
import org.apache.nifi.ssl.SSLContextService; import org.apache.nifi.ssl.SSLContextService;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -46,10 +46,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.Assert.assertTrue; 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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -61,7 +62,7 @@ public class AbstractCassandraProcessorTest {
MockAbstractCassandraProcessor processor; MockAbstractCassandraProcessor processor;
private TestRunner testRunner; private TestRunner testRunner;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
processor = new MockAbstractCassandraProcessor(); processor = new MockAbstractCassandraProcessor();
testRunner = TestRunners.newTestRunner(processor); testRunner = TestRunners.newTestRunner(processor);
@ -137,9 +138,9 @@ public class AbstractCassandraProcessorTest {
assertEquals(AbstractCassandraProcessor.getSchemaForType("bytes").getType().getName(), "bytes"); assertEquals(AbstractCassandraProcessor.getSchemaForType("bytes").getType().getName(), "bytes");
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testGetSchemaForTypeBadType() throws Exception { public void testGetSchemaForTypeBadType() throws Exception {
AbstractCassandraProcessor.getSchemaForType("nothing"); assertThrows(IllegalArgumentException.class, () -> AbstractCassandraProcessor.getSchemaForType("nothing"));
} }
@Test @Test
@ -165,10 +166,10 @@ public class AbstractCassandraProcessorTest {
assertEquals("bytes", AbstractCassandraProcessor.getPrimitiveAvroTypeFromCassandraType(DataType.blob())); assertEquals("bytes", AbstractCassandraProcessor.getPrimitiveAvroTypeFromCassandraType(DataType.blob()));
} }
@Test(expected = IllegalArgumentException.class) @Test
public void testGetPrimitiveAvroTypeFromCassandraTypeBadType() throws Exception { public void testGetPrimitiveAvroTypeFromCassandraTypeBadType() throws Exception {
DataType mockDataType = mock(DataType.class); DataType mockDataType = mock(DataType.class);
AbstractCassandraProcessor.getPrimitiveAvroTypeFromCassandraType(mockDataType); assertThrows(IllegalArgumentException.class, () -> AbstractCassandraProcessor.getPrimitiveAvroTypeFromCassandraType(mockDataType));
} }
@Test @Test

View File

@ -33,8 +33,8 @@ import com.datastax.driver.core.exceptions.UnavailableException;
import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -43,7 +43,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; 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.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
@ -60,7 +60,7 @@ public class PutCassandraQLTest {
private TestRunner testRunner; private TestRunner testRunner;
private MockPutCassandraQL processor; private MockPutCassandraQL processor;
@Before @BeforeEach
public void setUp() { public void setUp() {
processor = new MockPutCassandraQL(); processor = new MockPutCassandraQL();
testRunner = TestRunners.newTestRunner(processor); testRunner = TestRunners.newTestRunner(processor);

View File

@ -27,14 +27,15 @@ import org.apache.nifi.serialization.record.MockRecordParser;
import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.AfterClass; import org.junit.jupiter.api.AfterAll;
import org.junit.Assert; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PutCassandraRecordIT { public class PutCassandraRecordIT {
private static TestRunner testRunner; private static TestRunner testRunner;
@ -48,7 +49,7 @@ public class PutCassandraRecordIT {
private static final String HOST = "localhost"; private static final String HOST = "localhost";
private static final int PORT = 9042; private static final int PORT = 9042;
@BeforeClass @BeforeAll
public static void setup() throws InitializationException { public static void setup() throws InitializationException {
recordReader = new MockRecordParser(); recordReader = new MockRecordParser();
testRunner = TestRunners.newTestRunner(PutCassandraRecord.class); testRunner = TestRunners.newTestRunner(PutCassandraRecord.class);
@ -88,7 +89,7 @@ public class PutCassandraRecordIT {
testRunner.run(); testRunner.run();
testRunner.assertAllFlowFilesTransferred(PutCassandraRecord.REL_SUCCESS, 1); testRunner.assertAllFlowFilesTransferred(PutCassandraRecord.REL_SUCCESS, 1);
Assert.assertEquals(5, getRecordsCount()); assertEquals(5, getRecordsCount());
} }
private int getRecordsCount() { private int getRecordsCount() {
@ -109,7 +110,7 @@ public class PutCassandraRecordIT {
session.execute(query); session.execute(query);
} }
@AfterClass @AfterAll
public static void shutdown() { public static void shutdown() {
String dropKeyspace = "DROP KEYSPACE " + KEYSPACE; String dropKeyspace = "DROP KEYSPACE " + KEYSPACE;
String dropTable = "DROP TABLE IF EXISTS " + KEYSPACE + "." + TABLE; String dropTable = "DROP TABLE IF EXISTS " + KEYSPACE + "." + TABLE;

View File

@ -20,8 +20,8 @@ import com.datastax.driver.core.querybuilder.Insert;
import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema; import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.Tuple; import org.apache.nifi.util.Tuple;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@ -31,7 +31,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; 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.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -41,7 +41,7 @@ public class PutCassandraRecordInsertTest {
@Mock @Mock
private RecordSchema schema; private RecordSchema schema;
@Before @BeforeEach
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);

View File

@ -31,8 +31,8 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType; import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -42,7 +42,7 @@ import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; 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.any;
import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
@ -56,7 +56,7 @@ public class PutCassandraRecordTest {
private TestRunner testRunner; private TestRunner testRunner;
private MockRecordParser recordReader; private MockRecordParser recordReader;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
MockPutCassandraRecord processor = new MockPutCassandraRecord(); MockPutCassandraRecord processor = new MockPutCassandraRecord();
recordReader = new MockRecordParser(); recordReader = new MockRecordParser();

View File

@ -19,8 +19,8 @@ package org.apache.nifi.processors.cassandra;
import com.datastax.driver.core.Statement; import com.datastax.driver.core.Statement;
import org.apache.nifi.serialization.record.RecordSchema; import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.Tuple; import org.apache.nifi.util.Tuple;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
@ -30,8 +30,8 @@ import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
public class PutCassandraRecordUpdateTest { public class PutCassandraRecordUpdateTest {
@ -40,7 +40,7 @@ public class PutCassandraRecordUpdateTest {
@Mock @Mock
private RecordSchema schema; private RecordSchema schema;
@Before @BeforeEach
public void setUp() { public void setUp() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);

View File

@ -16,16 +16,6 @@
*/ */
package org.apache.nifi.processors.cassandra; 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.Cluster;
import com.datastax.driver.core.Configuration; import com.datastax.driver.core.Configuration;
import com.datastax.driver.core.ConsistencyLevel; 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.InvalidQueryException;
import com.datastax.driver.core.exceptions.NoHostAvailableException; import com.datastax.driver.core.exceptions.NoHostAvailableException;
import com.datastax.driver.core.exceptions.ReadTimeoutException; 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.io.ByteArrayOutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -50,16 +51,16 @@ import java.util.Optional;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.net.ssl.SSLContext;
import org.apache.avro.Schema; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.nifi.processor.exception.ProcessException; import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.nifi.util.MockFlowFile; import static org.junit.jupiter.api.Assertions.fail;
import org.apache.nifi.util.MockProcessContext; import static org.mockito.ArgumentMatchers.any;
import org.apache.nifi.util.TestRunner; import static org.mockito.ArgumentMatchers.anyLong;
import org.apache.nifi.util.TestRunners; import static org.mockito.ArgumentMatchers.anyString;
import org.codehaus.jackson.map.ObjectMapper; import static org.mockito.Mockito.doReturn;
import org.junit.Before; import static org.mockito.Mockito.mock;
import org.junit.Test; import static org.mockito.Mockito.when;
public class QueryCassandraTest { public class QueryCassandraTest {
@ -67,7 +68,7 @@ public class QueryCassandraTest {
private TestRunner testRunner; private TestRunner testRunner;
private MockQueryCassandra processor; private MockQueryCassandra processor;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp() throws Exception {
processor = new MockQueryCassandra(); processor = new MockQueryCassandra();
testRunner = TestRunners.newTestRunner(processor); testRunner = TestRunners.newTestRunner(processor);
@ -150,7 +151,7 @@ public class QueryCassandraTest {
testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1); testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS); List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS);
assertNotNull(files); 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\"," assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"]," + "\"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\"}," + "\"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); testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS); List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS);
assertNotNull(files); 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\"," assertEquals("{\"results\":[{\"user_id\":\"user1\",\"first_name\":\"Joe\",\"last_name\":\"Smith\","
+ "\"emails\":[\"jsmith@notareal.com\"],\"top_places\":[\"New York, NY\",\"Santa Clara, CA\"]," + "\"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\"}," + "\"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); testRunner.assertAllFlowFilesTransferred(QueryCassandra.REL_SUCCESS, 1);
List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS); List<MockFlowFile> files = testRunner.getFlowFilesForRelationship(QueryCassandra.REL_SUCCESS);
assertNotNull(files); 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 @Test

View File

@ -20,20 +20,20 @@ import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeAll;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestCassandraSessionProvider { public class TestCassandraSessionProvider {
private static TestRunner runner; private static TestRunner runner;
private static CassandraSessionProvider sessionProvider; private static CassandraSessionProvider sessionProvider;
@BeforeClass @BeforeAll
public static void setup() throws InitializationException { public static void setup() throws InitializationException {
MockCassandraProcessor mockCassandraProcessor = new MockCassandraProcessor(); MockCassandraProcessor mockCassandraProcessor = new MockCassandraProcessor();
sessionProvider = new CassandraSessionProvider(); sessionProvider = new CassandraSessionProvider();

View File

@ -16,17 +16,12 @@
*/ */
package org.apache.nifi.processors.ccda; 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.MockFlowFile;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Before; import org.junit.jupiter.api.BeforeAll;
import org.junit.BeforeClass; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.openhealthtools.mdht.uml.cda.consol.ConsolFactory; import org.openhealthtools.mdht.uml.cda.consol.ConsolFactory;
import org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument; import org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument;
import org.openhealthtools.mdht.uml.cda.consol.ProblemConcernAct; 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.consol.VitalSignsSection;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil; 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 { public class TestExtractCCDAAttributes {
private TestRunner runner; private TestRunner runner;
@BeforeClass @BeforeAll
public static void setup() { public static void setup() {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "INFO"); System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi", "INFO");
} }
@Before @BeforeEach
public void init() { public void init() {
runner = TestRunners.newTestRunner(ExtractCCDAAttributes.class); runner = TestRunners.newTestRunner(ExtractCCDAAttributes.class);
} }

View File

@ -31,6 +31,10 @@ import com.github.shyiko.mysql.binlog.event.WriteRowsEventData
import com.github.shyiko.mysql.binlog.network.SSLMode import com.github.shyiko.mysql.binlog.network.SSLMode
import groovy.json.JsonSlurper import groovy.json.JsonSlurper
import org.apache.commons.io.output.WriterOutputStream 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.MockBinlogClient
import org.apache.nifi.cdc.mysql.event.BinlogEventInfo import org.apache.nifi.cdc.mysql.event.BinlogEventInfo
import org.apache.nifi.cdc.mysql.processors.ssl.BinaryLogSSLSocketFactory 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.distributed.cache.client.Serializer
import org.apache.nifi.flowfile.attributes.CoreAttributes import org.apache.nifi.flowfile.attributes.CoreAttributes
import org.apache.nifi.logging.ComponentLog 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.processor.exception.ProcessException
import org.apache.nifi.provenance.ProvenanceEventType import org.apache.nifi.provenance.ProvenanceEventType
import org.apache.nifi.reporting.InitializationException 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.MockControllerServiceInitializationContext
import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunner
import org.apache.nifi.util.TestRunners import org.apache.nifi.util.TestRunners
import org.junit.After import org.junit.jupiter.api.BeforeEach
import org.junit.Before import org.junit.jupiter.api.Test
import org.junit.Test import org.junit.jupiter.api.function.Executable
import javax.net.ssl.SSLContext import javax.net.ssl.SSLContext
import java.sql.Connection import java.sql.Connection
@ -70,9 +69,10 @@ import java.util.concurrent.TimeoutException
import java.util.regex.Matcher import java.util.regex.Matcher
import java.util.regex.Pattern import java.util.regex.Pattern
import static org.junit.Assert.assertEquals import static org.junit.jupiter.api.Assertions.assertEquals
import static org.junit.Assert.assertNotNull import static org.junit.jupiter.api.Assertions.assertNotNull
import static org.junit.Assert.assertTrue 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.ArgumentMatchers.anyString
import static org.mockito.Mockito.doReturn import static org.mockito.Mockito.doReturn
import static org.mockito.Mockito.mock import static org.mockito.Mockito.mock
@ -89,18 +89,13 @@ class CaptureChangeMySQLTest {
TestRunner testRunner TestRunner testRunner
MockBinlogClient client MockBinlogClient client
@Before @BeforeEach
void setUp() throws Exception { void setUp() throws Exception {
processor = new MockCaptureChangeMySQL() processor = new MockCaptureChangeMySQL()
testRunner = TestRunners.newTestRunner(processor) testRunner = TestRunners.newTestRunner(processor)
client = new MockBinlogClient('localhost', 3306, 'root', 'password') client = new MockBinlogClient('localhost', 3306, 'root', 'password')
} }
@After
void tearDown() throws Exception {
}
@Test @Test
void testSslModeDisabledSslContextServiceNotRequired() { void testSslModeDisabledSslContextServiceNotRequired() {
testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306') testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306')
@ -148,10 +143,10 @@ class CaptureChangeMySQLTest {
testRunner.assertValid() testRunner.assertValid()
testRunner.run() testRunner.run()
assertEquals("SSL Mode not matched", sslMode, client.getSSLMode()) assertEquals(sslMode, client.getSSLMode(), "SSL Mode not matched")
def sslSocketFactory = client.sslSocketFactory def sslSocketFactory = client.sslSocketFactory
assertNotNull('Binary Log SSLSocketFactory not found', sslSocketFactory) assertNotNull(sslSocketFactory, 'Binary Log SSLSocketFactory not found')
assertEquals('Binary Log SSLSocketFactory class not matched', BinaryLogSSLSocketFactory.class, sslSocketFactory.getClass()) assertEquals(BinaryLogSSLSocketFactory.class, sslSocketFactory.getClass(), 'Binary Log SSLSocketFactory class not matched')
} }
@Test @Test
@ -348,7 +343,7 @@ class CaptureChangeMySQLTest {
} }
} }
@Test(expected = AssertionError.class) @Test
void testCommitWithoutBegin() throws Exception { void testCommitWithoutBegin() throws Exception {
testRunner.setProperty(CaptureChangeMySQL.DRIVER_LOCATION, DRIVER_LOCATION) testRunner.setProperty(CaptureChangeMySQL.DRIVER_LOCATION, DRIVER_LOCATION)
testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306') testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306')
@ -356,15 +351,14 @@ class CaptureChangeMySQLTest {
testRunner.setProperty(CaptureChangeMySQL.PASSWORD, 'password') testRunner.setProperty(CaptureChangeMySQL.PASSWORD, 'password')
testRunner.setProperty(CaptureChangeMySQL.CONNECT_TIMEOUT, '2 seconds') testRunner.setProperty(CaptureChangeMySQL.CONNECT_TIMEOUT, '2 seconds')
testRunner.run(1, false, true) testRunner.run(1, false, true)
// COMMIT // COMMIT
client.sendEvent(new Event( client.sendEvent(new Event(
[timestamp: new Date().time, eventType: EventType.XID, nextPosition: 12] as EventHeaderV4, [timestamp: new Date().time, eventType: EventType.XID, nextPosition: 12] as EventHeaderV4,
{} as EventData {} as EventData
)) ))
assertThrows(AssertionError.class, { testRunner.run(1, true, false) } as Executable)
testRunner.run(1, true, false)
} }
@Test @Test
@ -593,7 +587,7 @@ class CaptureChangeMySQLTest {
assertEquals(5, resultFiles.size()) assertEquals(5, resultFiles.size())
} }
@Test(expected = AssertionError.class) @Test
void testNoTableInformationAvailable() throws Exception { void testNoTableInformationAvailable() throws Exception {
testRunner.setProperty(CaptureChangeMySQL.DRIVER_LOCATION, DRIVER_LOCATION) testRunner.setProperty(CaptureChangeMySQL.DRIVER_LOCATION, DRIVER_LOCATION)
testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306') testRunner.setProperty(CaptureChangeMySQL.HOSTS, 'localhost:3306')
@ -634,7 +628,7 @@ class CaptureChangeMySQLTest {
{} as EventData {} as EventData
)) ))
testRunner.run(1, true, false) assertThrows(AssertionError.class, { testRunner.run(1, true, false) } as Executable)
} }
@Test @Test

View File

@ -16,12 +16,12 @@
*/ */
package org.apache.nifi.cdc.mysql.event; package org.apache.nifi.cdc.mysql.event;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.sql.Types; import java.sql.Types;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
/** /**

View File

@ -16,18 +16,17 @@
*/ */
package org.apache.nifi.cdc.mysql.processors.ssl; 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.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; 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.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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -47,9 +46,9 @@ public class BinaryLogSSLSocketFactoryTest {
when(socket.getPort()).thenReturn(PORT); when(socket.getPort()).thenReturn(PORT);
final SSLSocket sslSocket = socketFactory.createSocket(socket); final SSLSocket sslSocket = socketFactory.createSocket(socket);
assertNotNull("SSL Socket not found", sslSocket); assertNotNull(sslSocket, "SSL Socket not found");
assertEquals("Address not matched", address, sslSocket.getInetAddress()); assertEquals(address, sslSocket.getInetAddress(), "Address not matched");
assertEquals("Port not matched", PORT, sslSocket.getPort()); assertEquals(PORT, sslSocket.getPort(), "Port not matched");
} }
@Test @Test

View File

@ -21,8 +21,8 @@ import org.apache.nifi.processor.Processor;
import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
public class ConfluentSchemaRegistryTest { public class ConfluentSchemaRegistryTest {
@ -33,7 +33,7 @@ public class ConfluentSchemaRegistryTest {
private ConfluentSchemaRegistry registry; private ConfluentSchemaRegistry registry;
@Before @BeforeEach
public void setUp() throws InitializationException { public void setUp() throws InitializationException {
registry = new ConfluentSchemaRegistry(); registry = new ConfluentSchemaRegistry();
final Processor processor = Mockito.mock(Processor.class); final Processor processor = Mockito.mock(Processor.class);

View File

@ -23,9 +23,10 @@ import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestCouchbaseClusterService { public class TestCouchbaseClusterService {
@ -40,8 +41,8 @@ public class TestCouchbaseClusterService {
} }
} }
@Before @BeforeEach
public void init() throws Exception { public void init() {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true"); System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.couchbase.PutCouchbaseKey", "debug"); System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.processors.couchbase.PutCouchbaseKey", "debug");
@ -58,11 +59,6 @@ public class TestCouchbaseClusterService {
CouchbaseClusterControllerService service = new CouchbaseClusterService(); CouchbaseClusterControllerService service = new CouchbaseClusterService();
testRunner.addControllerService(SERVICE_ID, service); testRunner.addControllerService(SERVICE_ID, service);
testRunner.setProperty(service, CouchbaseClusterService.CONNECTION_STRING, connectionString); testRunner.setProperty(service, CouchbaseClusterService.CONNECTION_STRING, connectionString);
try { assertThrows(AssertionError.class, () -> testRunner.enableControllerService(service));
testRunner.enableControllerService(service);
Assert.fail("The service shouldn't be enabled when it couldn't connect to a cluster.");
} catch (AssertionError e) {
}
} }
} }

View File

@ -25,7 +25,7 @@ import org.apache.nifi.distributed.cache.client.Deserializer;
import org.apache.nifi.distributed.cache.client.Serializer; import org.apache.nifi.distributed.cache.client.Serializer;
import org.apache.nifi.util.MockConfigurationContext; import org.apache.nifi.util.MockConfigurationContext;
import org.apache.nifi.util.MockControllerServiceInitializationContext; import org.apache.nifi.util.MockControllerServiceInitializationContext;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; 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.BUCKET_NAME;
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE; 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.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
@ -69,5 +69,4 @@ public class TestCouchbaseMapCacheClient {
assertEquals("value", cacheEntry); assertEquals("value", cacheEntry);
} }
}
}

View File

@ -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.JsonArray;
import com.couchbase.client.java.document.json.JsonObject; import com.couchbase.client.java.document.json.JsonObject;
import com.couchbase.client.java.error.TranscodingException; import com.couchbase.client.java.error.TranscodingException;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.fail; import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestCouchbaseUtils { public class TestCouchbaseUtils {
@Ignore("This test method requires a live Couchbase Server instance") @Disabled("This test method requires a live Couchbase Server instance")
@Test @Test
public void testDocumentTypesAndStringConversion() { public void testDocumentTypesAndStringConversion() {
final CouchbaseCluster cluster = CouchbaseCluster.fromConnectionString("couchbase://192.168.99.100:8091"); 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()); final String stringFromByteBuff = CouchbaseUtils.getStringContent(binaryDocument.content());
assertEquals("value", stringFromByteBuff); assertEquals("value", stringFromByteBuff);
try { TranscodingException e = assertThrows(TranscodingException.class, () -> bucket.get(BinaryDocument.create("JsonDocument")));
bucket.get(BinaryDocument.create("JsonDocument")); assertTrue(e.getMessage().contains("Flags (0x2000000) indicate non-binary document for id 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"));
}
} }
} }

View File

@ -38,9 +38,8 @@ import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.HashMap; 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.AbstractCouchbaseProcessor.REL_SUCCESS;
import static org.apache.nifi.processors.couchbase.CouchbaseAttributes.Exception; import static org.apache.nifi.processors.couchbase.CouchbaseAttributes.Exception;
import static org.apache.nifi.processors.couchbase.GetCouchbaseKey.PUT_VALUE_TO_ATTRIBUTE; import static org.apache.nifi.processors.couchbase.GetCouchbaseKey.PUT_VALUE_TO_ATTRIBUTE;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.fail; 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.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -68,7 +68,7 @@ public class TestGetCouchbaseKey {
private static final String SERVICE_ID = "couchbaseClusterService"; private static final String SERVICE_ID = "couchbaseClusterService";
private TestRunner testRunner; private TestRunner testRunner;
@Before @BeforeEach
public void init() throws Exception { public void init() throws Exception {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true"); System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
@ -185,12 +185,8 @@ public class TestGetCouchbaseKey {
testRunner.setProperty(DOC_ID, docIdExp); testRunner.setProperty(DOC_ID, docIdExp);
testRunner.enqueue(new byte[0]); testRunner.enqueue(new byte[0]);
try { AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
testRunner.run(); assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
fail("Exception should be thrown.");
} catch (AssertionError e) {
Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
}
testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_SUCCESS, 0);
testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0);
@ -212,12 +208,9 @@ public class TestGetCouchbaseKey {
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
properties.put("someProperty", "someValue"); properties.put("someProperty", "someValue");
testRunner.enqueue(inFileData, properties); testRunner.enqueue(inFileData, properties);
try {
testRunner.run(); AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
fail("Exception should be thrown."); assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
} catch (AssertionError e) {
Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
}
testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_SUCCESS, 0);
testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0);
@ -367,12 +360,9 @@ public class TestGetCouchbaseKey {
byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8); byte[] inFileData = inFileDataStr.getBytes(StandardCharsets.UTF_8);
testRunner.enqueue(inFileData); testRunner.enqueue(inFileData);
try {
testRunner.run(); AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
fail("ProcessException should be thrown."); assertTrue(e.getCause().getClass().equals(ProcessException.class));
} catch (AssertionError e) {
Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
}
testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_SUCCESS, 0);
testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0);
@ -394,13 +384,10 @@ public class TestGetCouchbaseKey {
String inputFileDataStr = "input FlowFile data"; String inputFileDataStr = "input FlowFile data";
byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8); byte[] inFileData = inputFileDataStr.getBytes(StandardCharsets.UTF_8);
testRunner.enqueue(inFileData); testRunner.enqueue(inFileData);
try {
testRunner.run(); AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
fail("ProcessException should be thrown."); assertTrue(e.getCause().getClass().equals(ProcessException.class));
} catch (AssertionError e) { assertTrue(e.getCause().getCause().getClass().equals(AuthenticationException.class));
Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
Assert.assertTrue(e.getCause().getCause().getClass().equals(AuthenticationException.class));
}
testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_SUCCESS, 0);
testRunner.assertTransferCount(REL_ORIGINAL, 0); testRunner.assertTransferCount(REL_ORIGINAL, 0);
@ -486,7 +473,7 @@ public class TestGetCouchbaseKey {
MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0); MockFlowFile orgFile = testRunner.getFlowFilesForRelationship(REL_RETRY).get(0);
orgFile.assertContentEquals(inputFileDataStr); orgFile.assertContentEquals(inputFileDataStr);
orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName()); orgFile.assertAttributeEquals(Exception.key(), exception.getClass().getName());
Assert.assertEquals(true, orgFile.isPenalized()); assertEquals(true, orgFile.isPenalized());
} }
@Test @Test

View File

@ -16,30 +16,15 @@
*/ */
package org.apache.nifi.processors.couchbase; package org.apache.nifi.processors.couchbase;
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME; import com.couchbase.client.core.CouchbaseException;
import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE; import com.couchbase.client.core.ServiceNotAvailableException;
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.deps.io.netty.buffer.Unpooled; 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.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.attribute.expression.language.exception.AttributeExpressionLanguageException;
import org.apache.nifi.couchbase.CouchbaseClusterControllerService; import org.apache.nifi.couchbase.CouchbaseClusterControllerService;
import org.apache.nifi.couchbase.DocumentType; 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.MockFlowFile;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import com.couchbase.client.core.CouchbaseException; import java.nio.charset.StandardCharsets;
import com.couchbase.client.core.ServiceNotAvailableException; import java.util.HashMap;
import com.couchbase.client.java.Bucket; import java.util.Map;
import com.couchbase.client.java.PersistTo;
import com.couchbase.client.java.ReplicateTo; import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.BUCKET_NAME;
import com.couchbase.client.java.document.RawJsonDocument; import static org.apache.nifi.couchbase.CouchbaseConfigurationProperties.COUCHBASE_CLUSTER_SERVICE;
import com.couchbase.client.java.error.DurabilityException; 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 { public class TestPutCouchbaseKey {
@ -68,7 +67,7 @@ public class TestPutCouchbaseKey {
private static final String SERVICE_ID = "couchbaseClusterService"; private static final String SERVICE_ID = "couchbaseClusterService";
private TestRunner testRunner; private TestRunner testRunner;
@Before @BeforeEach
public void init() throws Exception { public void init() throws Exception {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info");
System.setProperty("org.slf4j.simpleLogger.showDateTime", "true"); System.setProperty("org.slf4j.simpleLogger.showDateTime", "true");
@ -237,12 +236,9 @@ public class TestPutCouchbaseKey {
Map<String, String> properties = new HashMap<>(); Map<String, String> properties = new HashMap<>();
properties.put("someProperty", somePropertyValue); properties.put("someProperty", somePropertyValue);
testRunner.enqueue(inFileDataBytes, properties); testRunner.enqueue(inFileDataBytes, properties);
try {
testRunner.run(); AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
fail("Exception should be thrown."); assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
} catch (AssertionError e){
Assert.assertTrue(e.getCause().getClass().equals(AttributeExpressionLanguageException.class));
}
testRunner.assertTransferCount(REL_SUCCESS, 0); testRunner.assertTransferCount(REL_SUCCESS, 0);
testRunner.assertTransferCount(REL_RETRY, 0); testRunner.assertTransferCount(REL_RETRY, 0);
@ -294,12 +290,9 @@ public class TestPutCouchbaseKey {
testRunner.enqueue(inFileDataBytes); testRunner.enqueue(inFileDataBytes);
testRunner.setProperty(DOC_ID, docId); testRunner.setProperty(DOC_ID, docId);
testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString()); testRunner.setProperty(PutCouchbaseKey.REPLICATE_TO, ReplicateTo.ONE.toString());
try {
testRunner.run(); AssertionError e = assertThrows(AssertionError.class, () -> testRunner.run());
fail("ProcessException should be thrown."); assertTrue(e.getCause().getClass().equals(ProcessException.class));
} catch (AssertionError e){
Assert.assertTrue(e.getCause().getClass().equals(ProcessException.class));
}
verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE)); verify(bucket, times(1)).upsert(any(RawJsonDocument.class), eq(PersistTo.NONE), eq(ReplicateTo.ONE));

View File

@ -22,15 +22,16 @@ import org.apache.nifi.processors.cybersecurity.matchers.SSDeepHashMatcher;
import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestCompareFuzzyHash { public class TestCompareFuzzyHash {
String ssdeepInput = "48:c1xs8Z/m6H0eRH31S8p8bHENANkPrNy4tkPytwPyh2jTytxPythPytNdPytDgYyF:OuO/mg3HFSRHEb44RNMi6uHU2hcq3"; String ssdeepInput = "48:c1xs8Z/m6H0eRH31S8p8bHENANkPrNy4tkPytwPyh2jTytxPythPytNdPytDgYyF:OuO/mg3HFSRHEb44RNMi6uHU2hcq3";
@ -39,7 +40,7 @@ public class TestCompareFuzzyHash {
final CompareFuzzyHash proc = new CompareFuzzyHash(); final CompareFuzzyHash proc = new CompareFuzzyHash();
final private TestRunner runner = TestRunners.newTestRunner(proc); final private TestRunner runner = TestRunners.newTestRunner(proc);
@After @AfterEach
public void stop() { public void stop() {
runner.shutdown(); runner.shutdown();
} }
@ -70,7 +71,7 @@ public class TestCompareFuzzyHash {
"\"nifi/nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml\"" "\"nifi/nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml\""
); );
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity")); double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
Assert.assertTrue(similarity >= matchingSimilarity); assertTrue(similarity >= matchingSimilarity);
outFile.assertAttributeNotExists("fuzzyhash.value.1.match"); outFile.assertAttributeNotExists("fuzzyhash.value.1.match");
} }
@ -101,13 +102,13 @@ public class TestCompareFuzzyHash {
); );
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity")); double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
Assert.assertTrue(similarity >= matchingSimilarity); assertTrue(similarity >= matchingSimilarity);
outFile.assertAttributeEquals("fuzzyhash.value.1.match", outFile.assertAttributeEquals("fuzzyhash.value.1.match",
"\"nifi/nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml\"" "\"nifi/nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml\""
); );
similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.1.similarity")); similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.1.similarity"));
Assert.assertTrue(similarity >= matchingSimilarity); assertTrue(similarity >= matchingSimilarity);
} }
@Test @Test
@ -203,7 +204,7 @@ public class TestCompareFuzzyHash {
"nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/pom.xml" "nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/pom.xml"
); );
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity")); double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
Assert.assertTrue(similarity <= matchingSimilarity); assertTrue(similarity <= matchingSimilarity);
outFile.assertAttributeNotExists("fuzzyhash.value.1.match"); outFile.assertAttributeNotExists("fuzzyhash.value.1.match");
} }
@ -233,14 +234,14 @@ public class TestCompareFuzzyHash {
"nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/pom.xml" "nifi-nar-bundles/nifi-lumberjack-bundle/nifi-lumberjack-processors/pom.xml"
); );
double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity")); double similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.0.similarity"));
Assert.assertTrue(similarity <= matchingSimilarity); assertTrue(similarity <= matchingSimilarity);
outFile.assertAttributeEquals( outFile.assertAttributeEquals(
"fuzzyhash.value.1.match", "fuzzyhash.value.1.match",
"nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml" "nifi-nar-bundles/nifi-beats-bundle/nifi-beats-processors/pom.xml"
); );
similarity = Double.valueOf(outFile.getAttribute("fuzzyhash.value.1.similarity")); 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) { 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 // Now test with a valid string
Assert.assertTrue(matcher.isValidHash(ssdeepInput)); assertTrue(matcher.isValidHash(ssdeepInput));
} }
} }

View File

@ -20,22 +20,23 @@ package org.apache.nifi.processors.cybersecurity;
import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.TestRunners;
import org.junit.After; import org.junit.jupiter.api.AfterEach;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestFuzzyHashContent { public class TestFuzzyHashContent {
private TestRunner runner; private TestRunner runner;
@Before @BeforeEach
public void init() { public void init() {
runner = TestRunners.newTestRunner(FuzzyHashContent.class); runner = TestRunners.newTestRunner(FuzzyHashContent.class);
} }
@After @AfterEach
public void stop() { public void stop() {
runner.shutdown(); runner.shutdown();
} }
@ -53,7 +54,7 @@ public class TestFuzzyHashContent {
final MockFlowFile outFile = runner.getFlowFilesForRelationship(FuzzyHashContent.REL_SUCCESS).get(0); 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 @Test
@ -89,7 +90,7 @@ public class TestFuzzyHashContent {
final MockFlowFile outFile = runner.getFlowFilesForRelationship(FuzzyHashContent.REL_SUCCESS).get(0); final MockFlowFile outFile = runner.getFlowFilesForRelationship(FuzzyHashContent.REL_SUCCESS).get(0);
Assert.assertEquals("E2F0818B7AE7173906A72221570E30979B11C0FC47B518A1E89D257E2343CEC02381ED", assertEquals("E2F0818B7AE7173906A72221570E30979B11C0FC47B518A1E89D257E2343CEC02381ED",
outFile.getAttribute("fuzzyhash.value")); outFile.getAttribute("fuzzyhash.value"));
} }

View File

@ -28,8 +28,8 @@ import org.apache.nifi.reporting.ReportingContext;
import org.apache.nifi.reporting.ReportingInitializationContext; import org.apache.nifi.reporting.ReportingInitializationContext;
import org.apache.nifi.reporting.datadog.metrics.MetricsService; import org.apache.nifi.reporting.datadog.metrics.MetricsService;
import org.apache.nifi.util.MockPropertyValue; import org.apache.nifi.util.MockPropertyValue;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import java.io.IOException; import java.io.IOException;
@ -61,7 +61,7 @@ public class TestDataDogReportingTask {
private volatile JmxJvmMetrics virtualMachineMetrics; private volatile JmxJvmMetrics virtualMachineMetrics;
private Logger logger; private Logger logger;
@Before @BeforeEach
public void setup() { public void setup() {
initProcessGroupStatus(); initProcessGroupStatus();
initProcessorStatuses(); initProcessorStatuses();

View File

@ -21,20 +21,21 @@ import org.apache.nifi.controller.status.ProcessorStatus;
import org.apache.nifi.metrics.jvm.JmxJvmMetrics; import org.apache.nifi.metrics.jvm.JmxJvmMetrics;
import org.apache.nifi.reporting.datadog.metrics.MetricNames; import org.apache.nifi.reporting.datadog.metrics.MetricNames;
import org.apache.nifi.reporting.datadog.metrics.MetricsService; import org.apache.nifi.reporting.datadog.metrics.MetricsService;
import org.junit.Assert; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestMetricsService { public class TestMetricsService {
private ProcessGroupStatus status; private ProcessGroupStatus status;
private MetricsService metricsService; private MetricsService metricsService;
@Before @BeforeEach
public void init() { public void init() {
status = new ProcessGroupStatus(); status = new ProcessGroupStatus();
metricsService = new MetricsService(); metricsService = new MetricsService();
@ -60,15 +61,15 @@ public class TestMetricsService {
final Map<String, Double> metrics = metricsService.getDataFlowMetrics(status); final Map<String, Double> metrics = metricsService.getDataFlowMetrics(status);
Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED)); assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED)); assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED));
Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT)); assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_SENT)); assertTrue(metrics.containsKey(MetricNames.BYTES_SENT));
Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED)); assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED));
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED)); assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED));
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ)); assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN)); assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS)); assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
} }
//test processor status metric retrieving //test processor status metric retrieving
@ -81,11 +82,11 @@ public class TestMetricsService {
final Map<String, Double> metrics = metricsService.getProcessorMetrics(procStatus); final Map<String, Double> metrics = metricsService.getProcessorMetrics(procStatus);
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ)); assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN)); assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED)); assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT)); assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS)); assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
} }
//test JVM status metric retrieving //test JVM status metric retrieving
@ -94,17 +95,17 @@ public class TestMetricsService {
final JmxJvmMetrics virtualMachineMetrics = JmxJvmMetrics.getInstance(); final JmxJvmMetrics virtualMachineMetrics = JmxJvmMetrics.getInstance();
final Map<String, Double> metrics = metricsService.getJVMMetrics(virtualMachineMetrics); final Map<String, Double> metrics = metricsService.getJVMMetrics(virtualMachineMetrics);
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_UPTIME)); assertTrue(metrics.containsKey(MetricNames.JVM_UPTIME));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USED)); assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USED));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USAGE)); assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USAGE));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_NON_HEAP_USAGE)); assertTrue(metrics.containsKey(MetricNames.JVM_NON_HEAP_USAGE));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_RUNNABLE)); assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_RUNNABLE));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_BLOCKED)); assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_BLOCKED));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TIMED_WAITING)); assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TIMED_WAITING));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TERMINATED)); assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TERMINATED));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_COUNT)); assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_COUNT));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_DAEMON_THREAD_COUNT)); assertTrue(metrics.containsKey(MetricNames.JVM_DAEMON_THREAD_COUNT));
Assert.assertTrue(metrics.containsKey(MetricNames.JVM_FILE_DESCRIPTOR_USAGE)); assertTrue(metrics.containsKey(MetricNames.JVM_FILE_DESCRIPTOR_USAGE));
} }
} }