This is an automated email from the ASF dual-hosted git repository. exceptionfactory pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi.git
commit 99b0cd42ef951bfd46ce2ad3cee321facfe14b1c Author: dan-s1 <[email protected]> AuthorDate: Mon Feb 6 15:41:22 2023 +0000 NIFI-11130 Further updates from JUnit 4 to 5 This closes #6927 Signed-off-by: David Handermann <[email protected]> --- .../nifi/CassandraDistributedMapCacheIT.groovy | 21 +++++----- .../org/apache/nifi/rules/TestRulesFactory.java | 9 +++-- .../EncryptedFileSystemRepositoryTest.groovy | 45 ++++++++++++---------- .../serialization/FlowFromDOMFactoryTest.groovy | 17 ++++---- .../fingerprint/FingerprintFactoryGroovyIT.groovy | 19 +++++---- .../FingerprintFactoryGroovyTest.groovy | 12 +++--- ...cryptedSequentialAccessWriteAheadLogTest.groovy | 11 +++--- ...ComponentStatusRepositoryForComponentsTest.java | 3 +- .../remote/SocketRemoteSiteListenerTest.groovy | 8 ++-- .../nifi/web/server/HostHeaderHandlerTest.groovy | 29 +++++++------- .../nifi/web/api/ApplicationResourceTest.groovy | 29 ++++++++------ .../nifi/web/api/ProcessGroupResourceTest.groovy | 11 ++++-- ...JsonContentConversionExceptionMapperTest.groovy | 15 +++++--- .../nifi/web/filter/CatchAllFilterTest.groovy | 6 ++- .../jolt/record/TestJoltTransformRecord.java | 3 +- .../EncryptedSchemaRecordReaderWriterTest.groovy | 40 +++++++++++-------- .../rules/handlers/TestActionHandlerLookup.java | 5 ++- .../script/ExecuteScriptGroovyTest.groovy | 7 ++-- .../processors/standard/TestEncryptContent.java | 5 ++- .../org/apache/nifi/ssl/SSLContextServiceTest.java | 5 +-- 20 files changed, 174 insertions(+), 126 deletions(-) diff --git a/nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-distributedmapcache-service/src/test/groovy/org/apache/nifi/CassandraDistributedMapCacheIT.groovy b/nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-distributedmapcache-service/src/test/groovy/org/apache/nifi/CassandraDistributedMapCacheIT.groovy index 2fdc3e6657..025312e35f 100644 --- a/nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-distributedmapcache-service/src/test/groovy/org/apache/nifi/CassandraDistributedMapCacheIT.groovy +++ b/nifi-nar-bundles/nifi-cassandra-bundle/nifi-cassandra-distributedmapcache-service/src/test/groovy/org/apache/nifi/CassandraDistributedMapCacheIT.groovy @@ -36,6 +36,10 @@ import org.testcontainers.junit.jupiter.Container import org.testcontainers.junit.jupiter.Testcontainers import org.testcontainers.utility.DockerImageName +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue + /** * Setup instructions: * @@ -118,14 +122,13 @@ class CassandraDistributedMapCacheIT { @Test void testContainsKey() { - def contains = distributedMapCache.containsKey("contains-key", serializer) - assert contains + assertTrue(distributedMapCache.containsKey("contains-key", serializer)) } @Test void testGetAndPutIfAbsent() { - def result = distributedMapCache.getAndPutIfAbsent('get-and-put-key', 'testing', serializer, serializer, deserializer) - assert result == 'testvalue' + String result = distributedMapCache.getAndPutIfAbsent('get-and-put-key', 'testing', serializer, serializer, deserializer) + assertEquals("testvalue", result) } @Test @@ -135,20 +138,20 @@ class CassandraDistributedMapCacheIT { @Test void testGet() { - def result = distributedMapCache.get("contains-key", serializer, deserializer) - assert result == "testvalue" + String result = distributedMapCache.get("contains-key", serializer, deserializer) + assertEquals("testvalue", result) } @Test void testPut() { distributedMapCache.put("put-key", "sometestdata", serializer, serializer) Thread.sleep(1000) - assert distributedMapCache.containsKey("put-key", serializer) + assertTrue(distributedMapCache.containsKey("put-key", serializer)) } @Test void testPutIfAbsent() { - assert distributedMapCache.putIfAbsent("put-if-absent-key", "testingthis", serializer, serializer) - assert !distributedMapCache.putIfAbsent("put-if-absent-key", "testingthis", serializer, serializer) + assertTrue(distributedMapCache.putIfAbsent("put-if-absent-key", "testingthis", serializer, serializer)) + assertFalse(distributedMapCache.putIfAbsent("put-if-absent-key", "testingthis", serializer, serializer)) } } diff --git a/nifi-nar-bundles/nifi-easyrules-bundle/nifi-easyrules-service/src/test/java/org/apache/nifi/rules/TestRulesFactory.java b/nifi-nar-bundles/nifi-easyrules-bundle/nifi-easyrules-service/src/test/java/org/apache/nifi/rules/TestRulesFactory.java index 9f4491e8d5..23f60c7751 100644 --- a/nifi-nar-bundles/nifi-easyrules-bundle/nifi-easyrules-service/src/test/java/org/apache/nifi/rules/TestRulesFactory.java +++ b/nifi-nar-bundles/nifi-easyrules-bundle/nifi-easyrules-service/src/test/java/org/apache/nifi/rules/TestRulesFactory.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestRulesFactory { @Test @@ -32,7 +33,7 @@ public class TestRulesFactory { String testYamlFile = "src/test/resources/test_nifi_rules.yml"; List<Rule> rules = RulesFactory.createRulesFromFile(testYamlFile, "YAML", "NIFI"); assertEquals(2, rules.size()); - assert confirmEntries(rules); + assertTrue(confirmEntries(rules)); }); } @@ -42,7 +43,7 @@ public class TestRulesFactory { String testYamlFile = "src/test/resources/test_mvel_rules.yml"; List<Rule> rules = RulesFactory.createRulesFromFile(testYamlFile, "YAML", "MVEL"); assertEquals(2, rules.size()); - assert confirmEntries(rules); + assertTrue(confirmEntries(rules)); assertSame("EXPRESSION", rules.get(0).getActions().get(0).getType()); }); } @@ -63,7 +64,7 @@ public class TestRulesFactory { String testJsonFile = "src/test/resources/test_nifi_rules.json"; List<Rule> rules = RulesFactory.createRulesFromFile(testJsonFile, "JSON", "NIFI"); assertEquals(2, rules.size()); - assert confirmEntries(rules); + assertTrue(confirmEntries(rules)); }); } @@ -74,7 +75,7 @@ public class TestRulesFactory { List<Rule> rules = RulesFactory.createRulesFromFile(testJsonFile, "JSON", "MVEL"); assertEquals(2, rules.size()); assertSame("EXPRESSION", rules.get(0).getActions().get(0).getType()); - assert confirmEntries(rules); + assertTrue(confirmEntries(rules)); }); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/repository/crypto/EncryptedFileSystemRepositoryTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/repository/crypto/EncryptedFileSystemRepositoryTest.groovy index 2c1962dae4..f0dc13ad31 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/repository/crypto/EncryptedFileSystemRepositoryTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/repository/crypto/EncryptedFileSystemRepositoryTest.groovy @@ -38,6 +38,9 @@ import java.nio.charset.StandardCharsets import java.nio.file.Path import java.security.Security +import static org.junit.jupiter.api.Assertions.assertArrayEquals +import static org.junit.jupiter.api.Assertions.assertEquals + @DisabledOnOs(OS.WINDOWS) class EncryptedFileSystemRepositoryTest { private static final Logger logger = LoggerFactory.getLogger(EncryptedFileSystemRepositoryTest.class) @@ -108,7 +111,7 @@ class EncryptedFileSystemRepositoryTest { void testReadNullContentClaimShouldReturnEmptyInputStream() { final InputStream inputStream = repository.read((ContentClaim) null) final int read = inputStream.read() - assert read == -1 + assertEquals(-1, read) } /** @@ -129,8 +132,8 @@ class EncryptedFileSystemRepositoryTest { // Assert // Use the EFSR to decrypt the same content - def retrievedBytes = verifyClaimDecryption(claim, plainBytes) - assert new String(retrievedBytes, StandardCharsets.UTF_8) == plainContent + byte [] retrievedBytes = verifyClaimDecryption(claim, plainBytes) + assertEquals(plainContent, new String(retrievedBytes, StandardCharsets.UTF_8)) } /** @@ -175,8 +178,8 @@ class EncryptedFileSystemRepositoryTest { String pieceOfContent = content[i] // Use the EFSR to decrypt the same content - def retrievedBytes = verifyClaimDecryption(claim, pieceOfContent.bytes) - assert new String(retrievedBytes, StandardCharsets.UTF_8) == pieceOfContent + byte [] retrievedBytes = verifyClaimDecryption(claim, pieceOfContent.bytes) + assertEquals(pieceOfContent, new String(retrievedBytes, StandardCharsets.UTF_8)) } } @@ -200,7 +203,7 @@ class EncryptedFileSystemRepositoryTest { logger.info("Read bytes via repository (${retrievedContent.length}): ${pba(retrievedContent)}") // Assert - assert new String(retrievedContent, StandardCharsets.UTF_8) == plainContent + assertEquals(plainContent, new String(retrievedContent, StandardCharsets.UTF_8)) } /** @@ -297,7 +300,7 @@ class EncryptedFileSystemRepositoryTest { logger.info("Read bytes from output stream (${exportedBytes.length}): ${pba(exportedBytes)}") // Assert - assert exportedBytes == plainBytes + assertArrayEquals(plainBytes, exportedBytes) } /** @@ -330,9 +333,9 @@ class EncryptedFileSystemRepositoryTest { logger.info("Read bytes from output stream (${exportedBytes.length}): ${pba(exportedBytes)}") // Assert - assert exportedBytes == plainBytes[offset..<(offset + length)] as byte[] - assert exportedBytes.length == length - assert bytesWritten == length + assertArrayEquals(plainBytes[offset..<(offset + length)] as byte[], exportedBytes) + assertEquals(length, exportedBytes.length) + assertEquals(length, bytesWritten) } /** @@ -362,7 +365,7 @@ class EncryptedFileSystemRepositoryTest { // Assert try { - assert exportedBytes == plainBytes + assertArrayEquals(plainBytes, exportedBytes) } finally { // Clean up tempOutputFile.delete() @@ -401,9 +404,9 @@ class EncryptedFileSystemRepositoryTest { // Assert try { - assert exportedBytes == plainBytes[offset..<(offset + length)] as byte[] - assert exportedBytes.length == length - assert bytesWritten == length + assertArrayEquals(plainBytes[offset..<(offset + length)] as byte[], exportedBytes) + assertEquals(length, exportedBytes.length) + assertEquals(length, bytesWritten) } finally { // Clean up tempOutputFile.delete() @@ -431,12 +434,12 @@ class EncryptedFileSystemRepositoryTest { logger.info("Cloned claim ${claim} to ${clonedClaim}") // Use the EFSR to decrypt the original claim content - def retrievedOriginalBytes = verifyClaimDecryption(claim, plainBytes) - assert retrievedOriginalBytes == plainBytes + byte [] retrievedOriginalBytes = verifyClaimDecryption(claim, plainBytes) + assertArrayEquals(plainBytes, retrievedOriginalBytes) // Use the EFSR to decrypt the cloned claim content - def retrievedClonedBytes = verifyClaimDecryption(clonedClaim, plainBytes) - assert retrievedClonedBytes == plainBytes + byte [] retrievedClonedBytes = verifyClaimDecryption(clonedClaim, plainBytes) + assertArrayEquals(plainBytes, retrievedClonedBytes) } /** @@ -475,7 +478,9 @@ class EncryptedFileSystemRepositoryTest { } /** - * Simple test to merge encrypted content claims and ensure that the merged encryption metadata accurately reflects the new claim and allows for decryption, including the header, demarcator, and footer. + * Simple test to merge encrypted content claims and ensure that the merged encryption + * metadata accurately reflects the new claim and allows for decryption, + * including the header, demarcator, and footer. */ @Test void testMergeWithMarkersShouldUpdateEncryptionMetadata() { @@ -549,7 +554,7 @@ class EncryptedFileSystemRepositoryTest { logger.info("Read ${description} bytes via repository (${retrievedBytes.length}): ${pba(retrievedBytes)}") // Assert - assert retrievedBytes == plainBytes + assertArrayEquals(plainBytes, retrievedBytes) return retrievedBytes } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/serialization/FlowFromDOMFactoryTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/serialization/FlowFromDOMFactoryTest.groovy index 8766720e0c..af39f51903 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/serialization/FlowFromDOMFactoryTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/controller/serialization/FlowFromDOMFactoryTest.groovy @@ -25,6 +25,10 @@ import org.slf4j.LoggerFactory import static groovy.test.GroovyAssert.shouldFail +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertThrows +import static org.junit.jupiter.api.Assertions.assertTrue + class FlowFromDOMFactoryTest { private static final Logger logger = LoggerFactory.getLogger(FlowFromDOMFactoryTest.class) @@ -48,7 +52,7 @@ class FlowFromDOMFactoryTest { logger.info("Recovered: ${recovered}") // Assert - assert property == recovered + assertEquals(property, recovered) } @Test @@ -60,14 +64,13 @@ class FlowFromDOMFactoryTest { PropertyEncryptor flowEncryptor = createExceptionEncryptor() // Act - def msg = shouldFail(EncryptionException) { - String recovered = FlowFromDOMFactory.decrypt(wrappedProperty, flowEncryptor) - logger.info("Recovered: ${recovered}") - } - logger.expected(msg) + EncryptionException ee = assertThrows(EncryptionException.class, + () -> FlowFromDOMFactory.decrypt(wrappedProperty, flowEncryptor)) + logger.expected(ee.getMessage()) // Assert - assert msg.message =~ "Check that the nifi.sensitive.props.key value in nifi.properties matches the value used to encrypt the flow.xml.gz file" + assertTrue(ee.getMessage().contains("Check that the nifi.sensitive.props.key value " + + "in nifi.properties matches the value used to encrypt the flow.xml.gz file")) } private PropertyEncryptor createEncryptor() { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyIT.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyIT.groovy index afb37cfff3..8710aba8f4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyIT.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyIT.groovy @@ -30,7 +30,10 @@ import org.slf4j.LoggerFactory import java.security.Security -class FingerprintFactoryGroovyIT extends GroovyTestCase { +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue + +class FingerprintFactoryGroovyIT { private static final Logger logger = LoggerFactory.getLogger(FingerprintFactoryGroovyIT.class) private static PropertyEncryptor mockEncryptor = [ @@ -81,7 +84,7 @@ class FingerprintFactoryGroovyIT extends GroovyTestCase { FingerprintFactory fingerprintFactory = new FingerprintFactory(mockEncryptor, extensionManager, mockSensitiveValueEncoder) - def results = [] + List<String> results = [] def resultDurations = [] // Act @@ -105,15 +108,15 @@ class FingerprintFactoryGroovyIT extends GroovyTestCase { // Assert final long MAX_DURATION_NANOS = 1_000_000_000 // 1 second - assert resultDurations.max() <= MAX_DURATION_NANOS * 2 - assert resultDurations.sum() / testIterations < MAX_DURATION_NANOS + assertTrue(resultDurations.max() <= MAX_DURATION_NANOS * 2) + assertTrue(resultDurations.sum() / testIterations < MAX_DURATION_NANOS) // Assert the fingerprint does not contain the password - results.each { String fingerprint -> - assert !(fingerprint =~ "originalPlaintextPassword") + results.forEach(fingerprint -> { + assertFalse(fingerprint.contains("originalPlaintextPassword")) def maskedValue = (fingerprint =~ /\[MASKED\] \([\w\/\+=]+\)/) - assert maskedValue + assertTrue(maskedValue.find()) logger.info("Masked value: ${maskedValue[0]}") - } + }) } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyTest.groovy index 25700ca7b5..36caa01ba4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/fingerprint/FingerprintFactoryGroovyTest.groovy @@ -22,9 +22,7 @@ import org.apache.nifi.nar.ExtensionManager import org.apache.nifi.nar.StandardExtensionDiscoveringManager import org.apache.nifi.util.NiFiProperties import org.bouncycastle.jce.provider.BouncyCastleProvider -import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.AfterAll -import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.Test import org.slf4j.Logger @@ -32,7 +30,10 @@ import org.slf4j.LoggerFactory import java.security.Security -class FingerprintFactoryGroovyTest extends GroovyTestCase { +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue + +class FingerprintFactoryGroovyTest { private static final Logger logger = LoggerFactory.getLogger(FingerprintFactoryGroovyTest.class) private static PropertyEncryptor mockEncryptor = [ @@ -83,11 +84,10 @@ class FingerprintFactoryGroovyTest extends GroovyTestCase { logger.info("Generated flow fingerprint: ${fingerprint}") // Assert - // Assert the fingerprint does not contain the password - assert !(fingerprint =~ "originalPlaintextPassword") + assertFalse(fingerprint.contains("originalPlaintextPassword")) def maskedValue = (fingerprint =~ /\[MASKED\] \([\w\/\+=]+\)/) - assert maskedValue + assertTrue(maskedValue.find()) logger.info("Masked value: ${maskedValue[0]}") } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/wali/EncryptedSequentialAccessWriteAheadLogTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/wali/EncryptedSequentialAccessWriteAheadLogTest.groovy index fb00f21e8f..d50e116ea3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/wali/EncryptedSequentialAccessWriteAheadLogTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/groovy/org/apache/nifi/wali/EncryptedSequentialAccessWriteAheadLogTest.groovy @@ -44,6 +44,7 @@ import org.wali.SerDe import org.wali.SerDeFactory import org.wali.SingletonSerDeFactory +import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertNotNull import static org.junit.jupiter.api.Assertions.assertTrue @@ -151,11 +152,11 @@ class EncryptedSequentialAccessWriteAheadLogTest { final Collection<SerializedRepositoryRecord> recovered = recoveryRepo.recoverRecords() // Ensure that the same records are returned (order is not guaranteed) - assert recovered.size() == records.size() - assert recovered.every { it.type == RepositoryRecordType.CREATE } + assertEquals(records.size(), recovered.size()) + recovered.forEach(it -> assertEquals(RepositoryRecordType.CREATE, it.type)) // Check that all attributes (flowfile record) in the recovered records were present in the original list - assert recovered.every { (it as SerializedRepositoryRecord).getFlowFileRecord() in records*.getFlowFileRecord() } + recovered.forEach(it -> assertTrue(it.getFlowFileRecord() in records*.getFlowFileRecord())) } /** This test creates flowfile records, adds them to the repository, and then recovers them to ensure they were persisted */ @@ -182,8 +183,8 @@ class EncryptedSequentialAccessWriteAheadLogTest { final Collection<SerializedRepositoryRecord> recovered = recoveryRepo.recoverRecords() // Ensure that the same records (except now UPDATE instead of CREATE) are returned (order is not guaranteed) - assert recovered.size() == records.size() - assert recovered.every { it.type == RepositoryRecordType.CREATE } + assertEquals(records.size(), recovered.size()) + recovered.forEach(it -> assertEquals( RepositoryRecordType.CREATE, it.type)) } private EncryptedSchemaRepositoryRecordSerde buildEncryptedSerDe() { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepositoryForComponentsTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepositoryForComponentsTest.java index 08cdbfd33e..016adabd62 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepositoryForComponentsTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/VolatileComponentStatusRepositoryForComponentsTest.java @@ -26,6 +26,7 @@ import java.time.ZoneOffset; import java.util.Date; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -83,7 +84,7 @@ public class VolatileComponentStatusRepositoryForComponentsTest { private void testFilterDatesReturnAll(VolatileComponentStatusRepository repo) { List<Date> dates = repo.filterDates(null, null, Integer.MAX_VALUE); - assert repo.timestamps != null; + assertNotNull(repo.timestamps); assertEquals(repo.timestamps.getSize(), dates.size()); assertEquals(dates, repo.timestamps.asList()); repo.timestamps.add(new Date()); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/groovy/org/apache/nifi/remote/SocketRemoteSiteListenerTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/groovy/org/apache/nifi/remote/SocketRemoteSiteListenerTest.groovy index 5d712f7389..0a28a0aebd 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/groovy/org/apache/nifi/remote/SocketRemoteSiteListenerTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/test/groovy/org/apache/nifi/remote/SocketRemoteSiteListenerTest.groovy @@ -33,6 +33,8 @@ import javax.net.ssl.SSLContext import javax.net.ssl.SSLServerSocket import java.security.Security +import static org.junit.jupiter.api.Assertions.assertArrayEquals +import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertTrue class SocketRemoteSiteListenerTest { @@ -94,11 +96,11 @@ class SocketRemoteSiteListenerTest { * @param enabledProtocols the actual protocols, either in {@code String[]} or {@code Collection<String>} form * @param expectedProtocols the specific protocol versions to be present (ordered as desired) */ - void assertProtocolVersions(def enabledProtocols, def expectedProtocols) { + static void assertProtocolVersions(def enabledProtocols, def expectedProtocols) { if (TlsConfiguration.getJavaVersion() > 8) { - assert enabledProtocols == expectedProtocols as String[] + assertArrayEquals(expectedProtocols as String[], enabledProtocols) } else { - assert enabledProtocols as Set == expectedProtocols as Set + assertEquals(expectedProtocols as Set, enabledProtocols as Set) } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/java/org/apache/nifi/web/server/HostHeaderHandlerTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/java/org/apache/nifi/web/server/HostHeaderHandlerTest.groovy index 07d7699a90..ae74084f24 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/java/org/apache/nifi/web/server/HostHeaderHandlerTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/test/java/org/apache/nifi/web/server/HostHeaderHandlerTest.groovy @@ -24,6 +24,9 @@ import org.junit.jupiter.api.Test import org.slf4j.Logger import org.slf4j.LoggerFactory +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertTrue + class HostHeaderHandlerTest { private static final Logger logger = LoggerFactory.getLogger(HostHeaderHandlerTest.class) @@ -61,8 +64,8 @@ class HostHeaderHandlerTest { logger.info("Handler: ${handler}") // Assert - assert handler.hostHeaderIsValid(hostname) - assert handler.hostHeaderIsValid("${hostname}:${port}") + assertTrue(handler.hostHeaderIsValid(hostname)) + assertTrue(handler.hostHeaderIsValid("${hostname}:${port}")) } /** @@ -83,7 +86,7 @@ class HostHeaderHandlerTest { // Assert DEFAULT_HOSTS_AND_PORTS_1_5_0.each { String host -> logger.debug("Validating ${host}") - assert handler.hostHeaderIsValid(host) + assertTrue(handler.hostHeaderIsValid(host)) } } @@ -108,7 +111,7 @@ class HostHeaderHandlerTest { // Assert DEFAULT_HOSTS_AND_PORTS.each { String host -> logger.debug("Validating ${host}") - assert handler.hostHeaderIsValid(host) + assertTrue(handler.hostHeaderIsValid(host)) } } @@ -138,13 +141,13 @@ class HostHeaderHandlerTest { logger.info("Parsed custom hostnames: ${customHostnames}") // Assert - assert customHostnames.size() == otherHosts.size() + 2 // Two provided hostnames had ports + assertEquals(otherHosts.size() + 2, customHostnames.size()) // Two provided hostnames had ports otherHosts.each { String host -> logger.debug("Checking ${host}") - assert customHostnames.contains(host) + assertTrue(customHostnames.contains(host)) String portlessHost = "${host.split(":", 2)[0]}".toString() logger.debug("Checking ${portlessHost}") - assert customHostnames.contains(portlessHost) + assertTrue(customHostnames.contains(portlessHost)) } } @@ -187,10 +190,10 @@ class HostHeaderHandlerTest { logger.info("Parsed custom hostnames: ${customHostnames}") // Assert - assert customHostnames.size() == ipv6Hosts.size() + assertEquals(ipv6Hosts.size(), customHostnames.size()) ipv6Hosts.each { String host -> logger.debug("Checking ${host}") - assert customHostnames.contains(host) + assertTrue(customHostnames.contains(host)) } } @@ -233,13 +236,13 @@ class HostHeaderHandlerTest { logger.info("Parsed custom hostnames: ${customHostnames}") // Assert - assert customHostnames.size() == ipv6Hosts.size() * 2 + assertEquals(ipv6Hosts.size() * 2, customHostnames.size()) ipv6Hosts.each { String host -> logger.debug("Checking ${host}") - assert customHostnames.contains(host) + assertTrue(customHostnames.contains(host)) String portlessHost = "${StringUtils.substringBeforeLast(host, ":")}".toString() logger.debug("Checking ${portlessHost}") - assert customHostnames.contains(portlessHost) + assertTrue(customHostnames.contains(portlessHost)) } } @@ -269,6 +272,6 @@ class HostHeaderHandlerTest { } // Assert - assert hostsAreIPv6.every() + hostsAreIPv6.forEach(hostIsIPv6 -> assertTrue(hostIsIPv6)) } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ApplicationResourceTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ApplicationResourceTest.groovy index 1b67778a88..8c243276e9 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ApplicationResourceTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ApplicationResourceTest.groovy @@ -34,6 +34,7 @@ import static org.apache.nifi.web.util.WebUtils.FORWARDED_PORT_HTTP_HEADER import static org.apache.nifi.web.util.WebUtils.FORWARDED_PREFIX_HTTP_HEADER import static org.apache.nifi.web.util.WebUtils.FORWARDED_PROTO_HTTP_HEADER +import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertThrows class ApplicationResourceTest { @@ -100,10 +101,10 @@ class ApplicationResourceTest { ApplicationResource resource = buildApplicationResource() NiFiProperties niFiProperties = new NiFiProperties([(PROXY_CONTEXT_PATH_PROP): ALLOWED_PATH] as Properties) resource.properties = niFiProperties - + String expectedUri = "https://nifi.apache.org:8081" + ALLOWED_PATH + "/actualResource" String generatedUri = resource.generateResourceUri('actualResource') - assert generatedUri == "https://nifi.apache.org:8081${ALLOWED_PATH}/actualResource" + assertEquals(expectedUri, generatedUri) } @Test @@ -112,10 +113,10 @@ class ApplicationResourceTest { String multipleAllowedPaths = [ALLOWED_PATH, "another/path", "a/third/path"].join(",") NiFiProperties niFiProperties = new NiFiProperties([(PROXY_CONTEXT_PATH_PROP): multipleAllowedPaths] as Properties) resource.properties = niFiProperties - + String expectedUri = "https://nifi.apache.org:8081" + ALLOWED_PATH + "/actualResource" String generatedUri = resource.generateResourceUri('actualResource') - assert generatedUri == "https://nifi.apache.org:8081${ALLOWED_PATH}/actualResource" + assertEquals(expectedUri, generatedUri) } @Test @@ -137,9 +138,10 @@ class ApplicationResourceTest { ApplicationResource resource = buildApplicationResource([FORWARDED_CONTEXT_HTTP_HEADER]) NiFiProperties niFiProperties = new NiFiProperties([(PROXY_CONTEXT_PATH_PROP): ALLOWED_PATH] as Properties) resource.properties = niFiProperties - + String expectedUri = "https://nifi.apache.org:8081" + ALLOWED_PATH + "/actualResource" String generatedUri = resource.generateResourceUri('actualResource') - assert generatedUri == "https://nifi.apache.org:8081${ALLOWED_PATH}/actualResource" + + assertEquals(expectedUri, generatedUri) } @Test @@ -147,9 +149,10 @@ class ApplicationResourceTest { ApplicationResource resource = buildApplicationResource([FORWARDED_PREFIX_HTTP_HEADER]) NiFiProperties niFiProperties = new NiFiProperties([(PROXY_CONTEXT_PATH_PROP): ALLOWED_PATH] as Properties) resource.properties = niFiProperties - + String expectedUri = "https://nifi.apache.org:8081" + ALLOWED_PATH + "/actualResource" String generatedUri = resource.generateResourceUri('actualResource') - assert generatedUri == "https://nifi.apache.org:8081${ALLOWED_PATH}/actualResource" + + assertEquals(expectedUri, generatedUri) } @Test @@ -158,9 +161,10 @@ class ApplicationResourceTest { String multipleAllowedPaths = [ALLOWED_PATH, "another/path", "a/third/path"].join(",") NiFiProperties niFiProperties = new NiFiProperties([(PROXY_CONTEXT_PATH_PROP): multipleAllowedPaths] as Properties) resource.properties = niFiProperties - + String expectedUri = "https://nifi.apache.org:8081" + ALLOWED_PATH + "/actualResource" String generatedUri = resource.generateResourceUri('actualResource') - assert generatedUri == "https://nifi.apache.org:8081${ALLOWED_PATH}/actualResource" + + assertEquals(expectedUri, generatedUri) } @Test @@ -169,8 +173,9 @@ class ApplicationResourceTest { String multipleAllowedPaths = [ALLOWED_PATH, "another/path", "a/third/path"].join(",") NiFiProperties niFiProperties = new NiFiProperties([(PROXY_CONTEXT_PATH_PROP): multipleAllowedPaths] as Properties) resource.properties = niFiProperties - + String expectedUri = "https://nifi.apache.org:8081" + ALLOWED_PATH + "/actualResource" String generatedUri = resource.generateResourceUri('actualResource') - assert generatedUri == "https://nifi.apache.org:8081${ALLOWED_PATH}/actualResource" + + assertEquals(expectedUri, generatedUri) } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ProcessGroupResourceTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ProcessGroupResourceTest.groovy index cde4c7bf34..f2bed9956a 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ProcessGroupResourceTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/ProcessGroupResourceTest.groovy @@ -31,6 +31,9 @@ import javax.servlet.http.HttpServletRequest import javax.ws.rs.core.Response import javax.ws.rs.core.UriInfo +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertFalse + class ProcessGroupResourceTest { private static final Logger logger = LoggerFactory.getLogger(ProcessGroupResourceTest.class) @@ -67,12 +70,12 @@ class ProcessGroupResourceTest { // Assert // Assert that the expected error response was returned - assert response.status == Response.Status.OK.statusCode + assertEquals(Response.Status.OK.statusCode, response.status) // Assert that the error response is sanitized String responseEntity = response.entity as String logger.info("Error response: ${responseEntity}") - assert !(responseEntity =~ /<script.*>/) + assertFalse((responseEntity =~ /<script.*>/).find()) } /** This test creates a malformed template import request to exercise error handling and sanitization */ @@ -143,12 +146,12 @@ class ProcessGroupResourceTest { // Assert responses.each { Response r -> // Assert that the expected error response was returned - assert r.status == Response.Status.OK.statusCode + assertEquals(Response.Status.OK.statusCode, r.status) // Assert that the error response is sanitized String entity = r.entity as String logger.info("Error response: ${entity}") - assert !(entity =~ /<script.*>/) + assertFalse((entity =~ /<script.*>/).find()) } } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/config/JsonContentConversionExceptionMapperTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/config/JsonContentConversionExceptionMapperTest.groovy index d871c8fde1..a300848d93 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/config/JsonContentConversionExceptionMapperTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/groovy/org/apache/nifi/web/api/config/JsonContentConversionExceptionMapperTest.groovy @@ -28,7 +28,10 @@ import org.slf4j.LoggerFactory import javax.ws.rs.core.Response -class JsonContentConversionExceptionMapperTest extends GroovyTestCase { +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertFalse + +class JsonContentConversionExceptionMapperTest { private static final Logger logger = LoggerFactory.getLogger(ProcessGroupResourceTest.class) @BeforeAll @@ -57,8 +60,10 @@ class JsonContentConversionExceptionMapperTest extends GroovyTestCase { logger.info(response.toString()) // Assert - assert response.status == Response.Status.BAD_REQUEST.statusCode - assert response.entity == "The provided proxyPort value \'thisIsAnInvalidPort\' is not of required type class java.lang.Integer" + assertEquals(Response.Status.BAD_REQUEST.statusCode, response.status) + String expectedEntity = "The provided proxyPort value 'thisIsAnInvalidPort' is not" + + " of required type class java.lang.Integer" + assertEquals(expectedEntity, response.entity) } @Test @@ -80,7 +85,7 @@ class JsonContentConversionExceptionMapperTest extends GroovyTestCase { logger.info(response.toString()) // Assert - assert response.status == Response.Status.BAD_REQUEST.statusCode - assert !(response.entity =~ /<script.*>/) + assertEquals(Response.Status.BAD_REQUEST.statusCode, response.status) + assertFalse((response.entity =~ /<script.*>/).find()) } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-error/src/test/groovy/org/apache/nifi/web/filter/CatchAllFilterTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-error/src/test/groovy/org/apache/nifi/web/filter/CatchAllFilterTest.groovy index 43be5a9a70..1608b1532e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-error/src/test/groovy/org/apache/nifi/web/filter/CatchAllFilterTest.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-error/src/test/groovy/org/apache/nifi/web/filter/CatchAllFilterTest.groovy @@ -31,6 +31,8 @@ import javax.servlet.ServletResponse import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse +import static org.junit.jupiter.api.Assertions.assertEquals + class CatchAllFilterTest { private static final Logger logger = LoggerFactory.getLogger(CatchAllFilterTest.class) @@ -67,7 +69,7 @@ class CatchAllFilterTest { logger.info("Allowed context paths: ${caf.getAllowedContextPaths()}") // Assert - assert caf.getAllowedContextPaths() == EXPECTED_ALLOWED_CONTEXT_PATHS + assertEquals(EXPECTED_ALLOWED_CONTEXT_PATHS, caf.getAllowedContextPaths()) } @Test @@ -128,6 +130,6 @@ class CatchAllFilterTest { caf.doFilter(mockRequest, mockResponse, mockFilterChain) // Assert - assert forwardedRequestTo == EXPECTED_FORWARD_PATH + assertEquals(EXPECTED_FORWARD_PATH, forwardedRequestTo) } } diff --git a/nifi-nar-bundles/nifi-jolt-record-bundle/nifi-jolt-record-processors/src/test/java/org/apache/nifi/processors/jolt/record/TestJoltTransformRecord.java b/nifi-nar-bundles/nifi-jolt-record-bundle/nifi-jolt-record-processors/src/test/java/org/apache/nifi/processors/jolt/record/TestJoltTransformRecord.java index 6bc52441f4..bdbcbf61af 100644 --- a/nifi-nar-bundles/nifi-jolt-record-bundle/nifi-jolt-record-processors/src/test/java/org/apache/nifi/processors/jolt/record/TestJoltTransformRecord.java +++ b/nifi-nar-bundles/nifi-jolt-record-bundle/nifi-jolt-record-processors/src/test/java/org/apache/nifi/processors/jolt/record/TestJoltTransformRecord.java @@ -50,6 +50,7 @@ import java.util.Set; import java.util.function.BiFunction; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @DisabledOnOs(OS.WINDOWS) //The pretty printed json comparisons dont work on windows @@ -586,7 +587,7 @@ runner.assertTransferCount(JoltTransformRecord.REL_ORIGINAL, 1); runner.setProperty(writer, "Pretty Print JSON", "true"); runner.enableControllerService(writer); URL t = getClass().getResource("/TestJoltTransformRecord/TestCustomJoltTransform.jar"); - assert t != null; + assertNotNull(t); final String customJarPath = t.getPath(); final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformRecord/customChainrSpec.json"))); final String customJoltTransform = "TestCustomJoltTransform"; diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/groovy/org/apache/nifi/provenance/EncryptedSchemaRecordReaderWriterTest.groovy b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/groovy/org/apache/nifi/provenance/EncryptedSchemaRecordReaderWriterTest.groovy index 1e0560ee76..acac14246a 100644 --- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/groovy/org/apache/nifi/provenance/EncryptedSchemaRecordReaderWriterTest.groovy +++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/test/groovy/org/apache/nifi/provenance/EncryptedSchemaRecordReaderWriterTest.groovy @@ -41,8 +41,11 @@ import java.security.KeyManagementException import java.security.Security import java.util.concurrent.atomic.AtomicLong -import static groovy.test.GroovyAssert.shouldFail import static org.apache.nifi.provenance.TestUtil.createFlowFile +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 class EncryptedSchemaRecordReaderWriterTest extends AbstractTestRecordReaderWriter { private static final Logger logger = LoggerFactory.getLogger(EncryptedSchemaRecordReaderWriterTest.class) @@ -95,15 +98,19 @@ class EncryptedSchemaRecordReaderWriterTest extends AbstractTestRecordReaderWrit } private static - final FlowFile buildFlowFile(Map attributes = [:], long id = idGenerator.getAndIncrement(), long fileSize = 3000L) { + final FlowFile buildFlowFile(Map attributes = [:], long id = idGenerator.getAndIncrement(), + long fileSize = 3000L) { if (!attributes?.uuid) { attributes.uuid = UUID.randomUUID().toString() } createFlowFile(id, fileSize, attributes) } - private - static ProvenanceEventRecord buildEventRecord(FlowFile flowfile = buildFlowFile(), ProvenanceEventType eventType = ProvenanceEventType.RECEIVE, String transitUri = TRANSIT_URI, String componentId = COMPONENT_ID, String componentType = PROCESSOR_TYPE, long eventTime = System.currentTimeMillis()) { + private static ProvenanceEventRecord buildEventRecord(FlowFile flowfile = buildFlowFile(), + ProvenanceEventType eventType = ProvenanceEventType.RECEIVE, + String transitUri = TRANSIT_URI, String componentId = COMPONENT_ID, + String componentType = PROCESSOR_TYPE, + long eventTime = System.currentTimeMillis()) { final ProvenanceEventBuilder builder = new StandardProvenanceEventRecord.Builder() builder.setEventTime(eventTime) builder.setEventType(eventType) @@ -164,17 +171,18 @@ class EncryptedSchemaRecordReaderWriterTest extends AbstractTestRecordReaderWrit logger.info("Generated encrypted reader: ${reader}") ProvenanceEventRecord encryptedEvent = reader.nextRecord() - assert encryptedEvent - assert encryptedRecordId as long == encryptedEvent.getEventId() - assert record.componentId == encryptedEvent.getComponentId() - assert record.componentType == encryptedEvent.getComponentType() + assertNotNull(encryptedEvent) + assertEquals(encryptedRecordId, encryptedEvent.getEventId()) + assertEquals(record.componentId, encryptedEvent.getComponentId()) + assertEquals(record.componentType, encryptedEvent.getComponentType()) logger.info("Successfully read encrypted record: ${encryptedEvent}") - assert !reader.nextRecord() + assertNull(reader.nextRecord()) } /** - * Build a record and write it with a standard writer and the encrypted writer to different repositories. Recover with the standard reader and the contents of the encrypted record should be unreadable. + * Build a record and write it with a standard writer and the encrypted writer to different repositories. + * Recover with the standard reader and the contents of the encrypted record should be unreadable. */ @Test void testShouldWriteEncryptedRecordAndPlainRecord() { @@ -213,13 +221,13 @@ class EncryptedSchemaRecordReaderWriterTest extends AbstractTestRecordReaderWrit logger.info("Generated standard reader: ${reader}") ProvenanceEventRecord standardEvent = reader.nextRecord() - assert standardEvent - assert standardRecordId as long == standardEvent.getEventId() - assert record.componentId == standardEvent.getComponentId() - assert record.componentType == standardEvent.getComponentType() + assertNotNull(standardEvent) + assertEquals(standardRecordId, standardEvent.getEventId()) + assertEquals(record.componentId, standardEvent.getComponentId()) + assertEquals(record.componentType, standardEvent.getComponentType()) logger.info("Successfully read standard record: ${standardEvent}") - assert !reader.nextRecord() + assertNull(reader.nextRecord()) // Demonstrate unable to read from encrypted file with standard reader TocReader incompatibleTocReader = new StandardTocReader(encryptedTocFile) @@ -227,6 +235,6 @@ class EncryptedSchemaRecordReaderWriterTest extends AbstractTestRecordReaderWrit RecordReader incompatibleReader = new EventIdFirstSchemaRecordReader(efis, encryptedJournalFile.getName(), incompatibleTocReader, MAX_ATTRIBUTE_SIZE) logger.info("Generated standard reader (attempting to read encrypted file): ${incompatibleReader}") - shouldFail(EOFException) { incompatibleReader.nextRecord() } + assertThrows(EOFException.class, () -> incompatibleReader.nextRecord()) } } diff --git a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java index 58d1413e80..a015427e57 100644 --- a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java +++ b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestActionHandlerLookup { @@ -76,7 +77,7 @@ public class TestActionHandlerLookup { action.setType("ALERT"); action.setAttributes(attributes); actionHandlerLookup.execute(null, action, metrics); - assert alertHandler.getExecuteContextCalled(); + assertTrue(alertHandler.getExecuteContextCalled()); } @Test @@ -91,7 +92,7 @@ public class TestActionHandlerLookup { action.setType("LOG"); action.setAttributes(attributes); actionHandlerLookup.execute(null, action, metrics); - assert logHandler.getExecuteContextCalled(); + assertTrue(logHandler.getExecuteContextCalled()); } @Test diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy index 39ede15b8f..e56b0b07b5 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy @@ -26,6 +26,7 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import static org.junit.jupiter.api.Assertions.assertNotNull +import static org.junit.jupiter.api.Assertions.assertTrue class ExecuteScriptGroovyTest extends BaseScriptTest { private static final Logger logger = LoggerFactory.getLogger(ExecuteScriptGroovyTest.class) @@ -81,7 +82,7 @@ class ExecuteScriptGroovyTest extends BaseScriptTest { flowFile.assertAttributeExists("time-updated") flowFile.assertAttributeExists("thread") - assert flowFile.getAttribute("thread") =~ SINGLE_POOL_THREAD_PATTERN + assertTrue((flowFile.getAttribute("thread") =~ SINGLE_POOL_THREAD_PATTERN).find()) } @Test @@ -104,7 +105,7 @@ class ExecuteScriptGroovyTest extends BaseScriptTest { flowFile.assertAttributeExists("time-updated") flowFile.assertAttributeExists("thread") - assert flowFile.getAttribute("thread") =~ /pool-\d+-thread-1/ + assertTrue((flowFile.getAttribute("thread") =~ /pool-\d+-thread-1/).find()) } } @@ -134,7 +135,7 @@ class ExecuteScriptGroovyTest extends BaseScriptTest { flowFile.assertAttributeExists("time-updated") flowFile.assertAttributeExists("thread") - assert flowFile.getAttribute("thread") =~ /pool-\d+-thread-[1-${POOL_SIZE}]/ + assertTrue((flowFile.getAttribute("thread") =~ /pool-\d+-thread-[1-${POOL_SIZE}]/).find()) } } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java index afa00d05b9..6968cb057c 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEncryptContent.java @@ -235,8 +235,9 @@ public class TestEncryptContent { // Other than the round trip, checks that the provided cipher is actually used, inferring it from the ciphertext InputStream ciphertext = new ByteArrayInputStream(flowFile.toByteArray()); BCPGInputStream pgpin = new BCPGInputStream(getDecoderStream(ciphertext)); - assert pgpin.nextPacketTag() == 3; - assert ((SymmetricKeyEncSessionPacket) pgpin.readPacket()).getEncAlgorithm() == Integer.valueOf(cipher.getValue()); + assertEquals(3, pgpin.nextPacketTag()); + assertEquals(Integer.parseInt(cipher.getValue()), + ((SymmetricKeyEncSessionPacket) pgpin.readPacket()).getEncAlgorithm()); pgpin.close(); } } diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java b/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java index 141990e00b..68bd77e334 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-ssl-context-bundle/nifi-ssl-context-service/src/test/java/org/apache/nifi/ssl/SSLContextServiceTest.java @@ -213,9 +213,8 @@ public class SSLContextServiceTest { runner.assertValid(service); // Act - boolean isDeleted = tmpKeystore.delete(); - assert isDeleted; - assert !tmpKeystore.exists(); + assertTrue(tmpKeystore.delete()); + assertFalse(tmpKeystore.exists()); // Manually validate the service (expecting cached result to be returned) final MockProcessContext processContext = (MockProcessContext) runner.getProcessContext();
