NIFI-9080 Converted nifi-commons to use JUnit 5

This closes #5332

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Mike Thomsen 2021-08-13 07:11:25 -04:00 committed by exceptionfactory
parent 309ab8f4ab
commit 8d513c5ed3
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
110 changed files with 1257 additions and 1852 deletions

View File

@ -16,14 +16,14 @@
*/
package org.apache.nifi.bootstrap.util;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class OSUtilsTest {
@ -34,7 +34,7 @@ public class OSUtilsTest {
final Logger logger = LoggerFactory.getLogger("testing");
final Long pid = OSUtils.getProcessId(process, logger);
process.destroy();
assertNotNull("Process ID not found", pid);
assertNotNull(pid, "Process ID not found");
}
@Test

View File

@ -18,39 +18,36 @@ package org.apache.nifi.attribute.expression.language
import org.apache.nifi.attribute.expression.language.evaluation.QueryResult
import org.apache.nifi.expression.AttributeExpression
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@RunWith(JUnit4.class)
public class QueryGroovyTest extends GroovyTestCase {
class QueryGroovyTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(QueryGroovyTest.class)
@BeforeClass
public static void setUpOnce() throws Exception {
@BeforeAll
static void setUpOnce() throws Exception {
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Before
public void setUp() {
@BeforeEach
void setUp() {
}
@After
public void tearDown() {
@AfterEach
void tearDown() {
Query.metaClass.static = null
}
@Test
public void testReplaceShouldReplaceAllLiteralMatches() {
void testReplaceShouldReplaceAllLiteralMatches() {
// Arrange
int n = 3
final String ORIGINAL_VALUE = "Hello World"
@ -90,7 +87,7 @@ public class QueryGroovyTest extends GroovyTestCase {
}
@Test
public void testReplaceFirstShouldOnlyReplaceFirstRegexMatch() {
void testReplaceFirstShouldOnlyReplaceFirstRegexMatch() {
// Arrange
int n = 3
final String ORIGINAL_VALUE = "Hello World"
@ -130,7 +127,7 @@ public class QueryGroovyTest extends GroovyTestCase {
}
@Test
public void testReplaceFirstShouldOnlyReplaceFirstLiteralMatch() {
void testReplaceFirstShouldOnlyReplaceFirstLiteralMatch() {
// Arrange
int n = 3
final String ORIGINAL_VALUE = "Hello World"
@ -170,7 +167,7 @@ public class QueryGroovyTest extends GroovyTestCase {
}
@Test
public void testShouldDemonstrateDifferenceBetweenStringReplaceAndStringReplaceFirst() {
void testShouldDemonstrateDifferenceBetweenStringReplaceAndStringReplaceFirst() {
// Arrange
int n = 3
final String ORIGINAL_VALUE = "Hello World"

View File

@ -29,9 +29,8 @@ import org.apache.nifi.parameter.Parameter;
import org.apache.nifi.parameter.ParameterDescriptor;
import org.apache.nifi.parameter.ParameterLookup;
import org.apache.nifi.registry.VariableRegistry;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.BufferedInputStream;
@ -55,10 +54,11 @@ import static java.lang.Double.NaN;
import static java.lang.Double.POSITIVE_INFINITY;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestQuery {
@ -138,20 +138,11 @@ public class TestQuery {
}
private void assertValid(final String query) {
try {
Query.compile(query);
} catch (final Exception e) {
e.printStackTrace();
Assert.fail("Expected query to be valid, but it failed to compile due to " + e);
}
assertDoesNotThrow(() -> Query.compile(query));
}
private void assertInvalid(final String query) {
try {
Query.compile(query);
Assert.fail("Expected query to be invalid, but it did compile");
} catch (final Exception e) {
}
assertThrows(Exception.class, () -> Query.compile(query));
}
@Test
@ -159,11 +150,7 @@ public class TestQuery {
Query.validateExpression("${abc:substring(${xyz:length()})}", false);
Query.isValidExpression("${now():format('yyyy-MM-dd')}");
try {
Query.validateExpression("$${attr}", false);
Assert.fail("invalid query validated");
} catch (final AttributeExpressionLanguageParsingException e) {
}
assertThrows(AttributeExpressionLanguageParsingException.class, () -> Query.validateExpression("$${attr}", false));
Query.validateExpression("$${attr}", true);
@ -311,7 +298,7 @@ public class TestQuery {
}
@Test
@Ignore("Requires specific locale")
@Disabled("Requires specific locale")
public void implicitDateConversion() {
final Date date = new Date();
final Query query = Query.compile("${dateTime:format('yyyy/MM/dd HH:mm:ss.SSS')}");
@ -376,22 +363,15 @@ public class TestQuery {
ADDRESS_BOOK_JSON_PATH_EMPTY,
"", "${json:jsonPathDelete('$.missingpath')}", "");
verifyEquals("${json:jsonPath('$.missingpath')}", attributes, "");
try {
verifyEquals("${json:jsonPath('$..')}", attributes, "");
Assert.fail("Did not detect bad JSON path expression");
} catch (final AttributeExpressionLanguageException e) {
}
try {
verifyEquals("${missing:jsonPath('$.firstName')}", attributes, "");
Assert.fail("Did not detect empty JSON document");
} catch (AttributeExpressionLanguageException e) {
}
assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${json:jsonPath('$..')}", attributes, ""));
assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${missing:jsonPath('$.firstName')}", attributes, ""));
attributes.put("invalid", "[}");
try {
verifyEquals("${invlaid:jsonPath('$.firstName')}", attributes, "John");
Assert.fail("Did not detect invalid JSON document");
} catch (AttributeExpressionLanguageException e) {
}
assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${invlaid:jsonPath('$.firstName')}", attributes, "John"));
}
private void verifyAddressBookAttributes(String originalAddressBook, Map<String,String> attributes, String updatedAttribute, Object updatedValue) {
@ -526,13 +506,12 @@ public class TestQuery {
verifyEquals("${json:jsonPath('$.missing-path')}", attributes, "");
}
@Test(expected=IllegalArgumentException.class)
public void testJsonPathAddNicknameJimmyAtNonArray() throws IOException {
Map<String,String> attributes = verifyJsonPathExpressions(
assertThrows(IllegalArgumentException.class, () -> verifyJsonPathExpressions(
ADDRESS_BOOK_JSON_PATH_EMPTY,
"",
"${json:jsonPathAdd('$.firstName', 'Jimmy')}",
"");
""));
}
@Test
@ -601,9 +580,9 @@ public class TestQuery {
verifyEquals("${allAttributes( 'x', 'y' ):join(',')}", attributes, ",");
}
@Test(expected = AttributeExpressionLanguageException.class)
@Test
public void testCannotCombineWithNonReducingFunction() {
Query.compile("${allAttributes( 'a.1' ):plus(1)}");
assertThrows(AttributeExpressionLanguageException.class, () -> Query.compile("${allAttributes( 'a.1' ):plus(1)}"));
}
@Test
@ -1128,32 +1107,25 @@ public class TestQuery {
attributes.put("negativeDecimal", "-64.1");
// Test that errors relating to not finding methods are properly handled
try {
verifyEquals("${math('rand'):toNumber()}", attributes, 0L);
fail();
} catch (AttributeExpressionLanguageException expected) {
AttributeExpressionLanguageException expected = assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${math('rand'):toNumber()}", attributes, 0L));
assertEquals("Cannot evaluate 'math' function because no subjectless method was found with the name:'rand'", expected.getMessage());
}
try {
verifyEquals("${negativeDecimal:math('absolute')}", attributes, 0L);
fail();
} catch (AttributeExpressionLanguageException expected) {
expected = assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${negativeDecimal:math('absolute')}", attributes, 0L));
assertEquals("Cannot evaluate 'math' function because no method was found matching the passed parameters: name:'absolute', one argument of type: 'double'", expected.getMessage());
}
try {
verifyEquals("${oneDecimal:math('power', ${two:toDecimal()})}", attributes, 0L);
fail();
} catch (AttributeExpressionLanguageException expected) {
expected = assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${oneDecimal:math('power', ${two:toDecimal()})}", attributes, 0L));
assertEquals("Cannot evaluate 'math' function because no method was found matching the passed parameters: name:'power', " +
"first argument type: 'double', second argument type: 'double'", expected.getMessage());
}
try {
verifyEquals("${oneDecimal:math('power', ${two})}", attributes, 0L);
fail();
} catch (AttributeExpressionLanguageException expected) {
expected = assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${oneDecimal:math('power', ${two})}", attributes, 0L));
assertEquals("Cannot evaluate 'math' function because no method was found matching the passed parameters: name:'power', " +
"first argument type: 'double', second argument type: 'long'", expected.getMessage());
}
// Can only verify that it runs. ToNumber() will verify that it produced a number greater than or equal to 0.0 and less than 1.0
verifyEquals("${math('random'):toNumber()}", attributes, 0L);
@ -1363,12 +1335,7 @@ public class TestQuery {
verifyEquals("${allAttributes('abc', 'xyz'):length():equals(4)}", attributes, true);
verifyEquals("${allAttributes('abc', 'xyz', 'other'):isNull()}", attributes, false);
try {
Query.compile("${allAttributes('#ah'):equals('hello')");
Assert.fail("Was able to compile with allAttributes and an invalid attribute name");
} catch (final AttributeExpressionLanguageParsingException e) {
// expected behavior
}
assertThrows(AttributeExpressionLanguageParsingException.class, () -> Query.compile("${allAttributes('#ah'):equals('hello')"));
}
@Test
@ -1925,7 +1892,7 @@ public class TestQuery {
for (int i = 0; i < results.size(); i++) {
long result = (Long) getResult("${random()}", attrs).getValue();
assertThat("random", result, greaterThan(negOne));
assertEquals("duplicate random", true, results.add(result));
assertEquals(true, results.add(result), "duplicate random");
}
}
@ -2108,10 +2075,11 @@ public class TestQuery {
verifyEquals("${nbr_attr:hash('MD5')}", attributes, "d3d9446802a44259755d38e6d163e820");
}
@Test(expected = AttributeExpressionLanguageException.class)
@Test
public void testHashFailure() {
final Map<String, String> attributes = new HashMap<>();
verifyEquals("${literal('john'):hash('NOT_A_ALGO')}", attributes, "527bd5b5d689e2c32ae974c6229ff785");
assertThrows(AttributeExpressionLanguageException.class,
() -> verifyEquals("${literal('john'):hash('NOT_A_ALGO')}", attributes, "527bd5b5d689e2c32ae974c6229ff785"));
}
@Test
@ -2177,24 +2145,9 @@ public class TestQuery {
assertTrue(multipleResultExpectedResults.contains(actualResult));
verifyEquals("${str:repeat(4)}", attributes, "abcabcabcabc");
try {
verifyEquals("${str:repeat(-1)}", attributes, "");
fail("Should have failed on numRepeats < 0");
} catch(AttributeExpressionLanguageException aele) {
// Do nothing, it is expected
}
try {
verifyEquals("${str:repeat(0)}", attributes, "");
fail("Should have failed on numRepeats = 0");
} catch(AttributeExpressionLanguageException aele) {
// Do nothing, it is expected
}
try {
verifyEquals("${str:repeat(2,1)}", attributes, "");
fail("Should have failed on minRepeats > maxRepeats");
} catch(AttributeExpressionLanguageException aele) {
// Do nothing, it is expected
}
assertThrows(AttributeExpressionLanguageException.class, () -> verifyEquals("${str:repeat(-1)}", attributes, ""));
assertThrows(AttributeExpressionLanguageException.class, () -> verifyEquals("${str:repeat(0)}", attributes, ""));
assertThrows(AttributeExpressionLanguageException.class, () -> verifyEquals("${str:repeat(2,1)}", attributes, ""));
}
@Test

View File

@ -19,8 +19,8 @@ package org.apache.nifi.attribute.expression.language;
import org.apache.nifi.parameter.Parameter;
import org.apache.nifi.parameter.ParameterDescriptor;
import org.apache.nifi.parameter.ParameterLookup;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
@ -55,7 +55,7 @@ public class TestStandardPreparedQuery {
}
@Test
@Ignore("Intended for manual performance testing; should not be run in an automated environment")
@Disabled("Intended for manual performance testing; should not be run in an automated environment")
public void test10MIterations() {
final Map<String, String> attrs = new HashMap<>();
attrs.put("xx", "world");
@ -70,7 +70,7 @@ public class TestStandardPreparedQuery {
}
@Test
@Ignore("Takes too long")
@Disabled("Takes too long")
public void test10MIterationsWithQuery() {
final Map<String, String> attrs = new HashMap<>();
attrs.put("xx", "world");

View File

@ -18,7 +18,7 @@ package org.apache.nifi.attribute.expression.language;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.registry.VariableRegistry;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;

View File

@ -19,8 +19,8 @@ package org.apache.nifi.flow.encryptor;
import org.apache.nifi.encrypt.PropertyEncryptor;
import org.apache.nifi.encrypt.PropertyEncryptorBuilder;
import org.apache.nifi.security.util.EncryptionMethod;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -49,7 +49,7 @@ public class StandardFlowEncryptorTest {
private StandardFlowEncryptor flowEncryptor;
@Before
@BeforeEach
public void setEncryptors() {
inputEncryptor = getPropertyEncryptor(INPUT_KEY, EncryptionMethod.MD5_256AES.getAlgorithm());
outputEncryptor = getPropertyEncryptor(OUTPUT_KEY, EncryptionMethod.SHA256_256AES.getAlgorithm());

View File

@ -17,8 +17,8 @@
package org.apache.nifi.flow.encryptor.command;
import org.apache.nifi.stream.io.GZIPOutputStream;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileOutputStream;
@ -39,7 +39,7 @@ import static org.junit.Assert.assertTrue;
public class SetSensitivePropertiesKeyTest {
private static final String FLOW_CONTENTS = "<property><value>PROPERTY</value></property>";
@After
@AfterEach
public void clearProperties() {
System.clearProperty(SetSensitivePropertiesKey.PROPERTIES_FILE_PATH);
}

View File

@ -16,8 +16,7 @@
*/
package org.apache.nifi.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -26,7 +25,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class TestPackageUnpackageV3 {

View File

@ -16,9 +16,17 @@
*/
package org.apache.nifi.hl7.query;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.validation.impl.ValidationContextFactory;
import org.apache.nifi.hl7.hapi.HapiMessage;
import org.apache.nifi.hl7.model.HL7Field;
import org.apache.nifi.hl7.model.HL7Message;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.ArrayList;
@ -26,18 +34,9 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.nifi.hl7.hapi.HapiMessage;
import org.apache.nifi.hl7.model.HL7Field;
import org.apache.nifi.hl7.model.HL7Message;
import org.junit.Before;
import org.junit.Test;
import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HL7Exception;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import ca.uhn.hl7v2.parser.PipeParser;
import ca.uhn.hl7v2.validation.impl.ValidationContextFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@SuppressWarnings("resource")
public class TestHL7Query {
@ -60,7 +59,7 @@ public class TestHL7Query {
private HL7Message hypoglycemia;
@Before
@BeforeEach
public void init() throws IOException, HL7Exception {
this.hyperglycemia = createMessage(HYPERGLYCEMIA);
this.hypoglycemia = createMessage(HYPOGLYCEMIA);

View File

@ -20,21 +20,21 @@ import org.apache.nifi.components.ValidationContext
import org.apache.nifi.components.ValidationResult
import org.apache.nifi.components.Validator
import org.apache.nifi.processor.util.JsonValidator
import org.junit.Before
import org.junit.Test
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import static groovy.json.JsonOutput.prettyPrint
import static groovy.json.JsonOutput.toJson
import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertTrue
import static org.mockito.Mockito.mock
import static groovy.json.JsonOutput.*
class TestStandardValidators {
final String DUMMY_JSON_PROPERTY = "JSONProperty"
Validator validator
ValidationContext context
@Before
@BeforeEach
void setup() {
validator = JsonValidator.INSTANCE
context = mock(ValidationContext.class)

View File

@ -16,13 +16,13 @@
*/
package org.apache.nifi.parameter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestExpressionLanguageAgnosticParameterParser {

View File

@ -16,13 +16,14 @@
*/
package org.apache.nifi.parameter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.List;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestExpressionLanguageAwareParameterParser {

View File

@ -16,15 +16,15 @@
*/
package org.apache.nifi.parameter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class TestStandardParameterTokenList {

View File

@ -16,8 +16,7 @@
*/
package org.apache.nifi.util;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.InetSocketAddress;
@ -29,10 +28,12 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -54,9 +55,9 @@ public class NiFiPropertiesTest {
directories.add(narLibDir.toString());
}
Assert.assertEquals("Did not have the anticipated number of directories", expectedDirectories.size(), directories.size());
assertEquals(expectedDirectories.size(), directories.size(), "Did not have the anticipated number of directories");
for (File expectedDirectory : expectedDirectories) {
Assert.assertTrue("Listed directories did not contain expected directory", directories.contains(expectedDirectory.getPath()));
assertTrue(directories.contains(expectedDirectory.getPath()), "Listed directories did not contain expected directory");
}
}
@ -95,43 +96,31 @@ public class NiFiPropertiesTest {
additionalProperties.put(NiFiProperties.REMOTE_INPUT_HOST, "localhost");
NiFiProperties properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);
try {
properties.validate();
} catch (Throwable t) {
Assert.fail("unexpected exception: " + t.getMessage());
}
assertGoodProperties(properties);
// expect no error to be thrown
additionalProperties.put(NiFiProperties.REMOTE_INPUT_HOST, "");
properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);
try {
properties.validate();
} catch (Throwable t) {
Assert.fail("unexpected exception: " + t.getMessage());
}
assertGoodProperties(properties);
// expect no error to be thrown
additionalProperties.remove(NiFiProperties.REMOTE_INPUT_HOST);
properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);
try {
properties.validate();
} catch (Throwable t) {
Assert.fail("unexpected exception: " + t.getMessage());
}
assertGoodProperties(properties);
// expected error
additionalProperties = new HashMap<>();
additionalProperties.put(NiFiProperties.REMOTE_INPUT_HOST, "http://localhost");
properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);
try {
properties.validate();
Assert.fail("Validation should throw an exception");
} catch (Throwable t) {
// nothing to do
final NiFiProperties test = properties;
assertThrows(Throwable.class, () -> test.validate());
}
private void assertGoodProperties(final NiFiProperties properties) {
assertDoesNotThrow(() -> properties.validate());
}
@Test
@ -187,7 +176,7 @@ public class NiFiPropertiesTest {
assertEquals(Integer.parseInt(portValue), clusterProtocolPort.intValue());
}
@Test(expected = NumberFormatException.class)
@Test
public void testShouldVerifyExceptionThrownWhenInValidFormatPortValue() {
// Testing with CLUSTER_NODE_PROTOCOL_PORT
@ -200,10 +189,7 @@ public class NiFiPropertiesTest {
// Act
Integer clusterProtocolPort = properties.getClusterNodeProtocolPort();
// Assert
// Expect NumberFormatException thrown
assertEquals(Integer.parseInt(portValue), clusterProtocolPort.intValue());
assertThrows(NumberFormatException.class, () -> Integer.parseInt(portValue));
}
@Test
@ -225,7 +211,7 @@ public class NiFiPropertiesTest {
assertEquals(Integer.parseInt(portValue), clusterProtocolAddress.getPort());
}
@Test(expected = RuntimeException.class)
@Test
public void testShouldVerifyExceptionThrownWhenInvalidPortValue() {
// Testing with CLUSTER_NODE_ADDRESS
@ -238,15 +224,10 @@ public class NiFiPropertiesTest {
additionalProperties.put(NiFiProperties.CLUSTER_NODE_ADDRESS, addressValue);
NiFiProperties properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);
// Act
InetSocketAddress clusterProtocolAddress = properties.getClusterNodeProtocolAddress();
// Assert
// Expect RuntimeException thrown
assertEquals(Integer.parseInt(portValue), clusterProtocolAddress.getPort());
assertThrows(RuntimeException.class, () -> properties.getClusterNodeProtocolAddress());
}
@Test(expected = RuntimeException.class)
@Test
public void testShouldVerifyExceptionThrownWhenPortValueIsZero() {
// Arrange
String portValue = "0";
@ -256,12 +237,7 @@ public class NiFiPropertiesTest {
additionalProperties.put(NiFiProperties.CLUSTER_NODE_ADDRESS, addressValue);
NiFiProperties properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);
// Act
InetSocketAddress clusterProtocolAddress = properties.getClusterNodeProtocolAddress();
// Assert
// Expect RuntimeException thrown
assertEquals(Integer.parseInt(portValue), clusterProtocolAddress.getPort());
assertThrows(RuntimeException.class, () -> properties.getClusterNodeProtocolAddress());
}
@Test
@ -384,9 +360,9 @@ public class NiFiPropertiesTest {
final Map<String, String> result = testSubject.getPropertiesWithPrefix("nifi.web.http");
// then
Assert.assertEquals(4, result.size());
Assert.assertTrue(result.containsKey("nifi.web.http.host"));
Assert.assertTrue(result.containsKey("nifi.web.https.host"));
assertEquals(4, result.size());
assertTrue(result.containsKey("nifi.web.http.host"));
assertTrue(result.containsKey("nifi.web.https.host"));
}
@Test
@ -398,9 +374,9 @@ public class NiFiPropertiesTest {
final Map<String, String> result = testSubject.getPropertiesWithPrefix("nifi.web.http.");
// then
Assert.assertEquals(2, result.size());
Assert.assertTrue(result.containsKey("nifi.web.http.host"));
Assert.assertFalse(result.containsKey("nifi.web.https.host"));
assertEquals(2, result.size());
assertTrue(result.containsKey("nifi.web.http.host"));
assertFalse(result.containsKey("nifi.web.https.host"));
}
@Test
@ -412,7 +388,7 @@ public class NiFiPropertiesTest {
final Map<String, String> result = testSubject.getPropertiesWithPrefix("invalid.property");
// then
Assert.assertTrue(result.isEmpty());
assertTrue(result.isEmpty());
}
@Test
@ -424,9 +400,9 @@ public class NiFiPropertiesTest {
final Set<String> result = testSubject.getDirectSubsequentTokens("nifi.web.http");
// then
Assert.assertEquals(2, result.size());
Assert.assertTrue(result.contains("host"));
Assert.assertTrue(result.contains("port"));
assertEquals(2, result.size());
assertTrue(result.contains("host"));
assertTrue(result.contains("port"));
}
@Test
@ -438,9 +414,9 @@ public class NiFiPropertiesTest {
final Set<String> result = testSubject.getDirectSubsequentTokens("nifi.web.http.");
// then
Assert.assertEquals(2, result.size());
Assert.assertTrue(result.contains("host"));
Assert.assertTrue(result.contains("port"));
assertEquals(2, result.size());
assertTrue(result.contains("host"));
assertTrue(result.contains("port"));
}
@Test
@ -452,7 +428,7 @@ public class NiFiPropertiesTest {
final Set<String> result = testSubject.getDirectSubsequentTokens("lorem.ipsum");
// then
Assert.assertTrue(result.isEmpty());
assertTrue(result.isEmpty());
}
@Test
@ -464,10 +440,10 @@ public class NiFiPropertiesTest {
final Set<String> result = testSubject.getDirectSubsequentTokens("nifi.web");
// then
Assert.assertEquals(4, result.size());
Assert.assertTrue(result.contains("http"));
Assert.assertTrue(result.contains("https"));
Assert.assertTrue(result.contains("war"));
Assert.assertTrue(result.contains("jetty"));
assertEquals(4, result.size());
assertTrue(result.contains("http"));
assertTrue(result.contains("https"));
assertTrue(result.contains("war"));
assertTrue(result.contains("jetty"));
}
}

View File

@ -16,16 +16,17 @@
*/
package org.apache.nifi.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StringUtilsTest {

View File

@ -22,8 +22,8 @@ import org.apache.nifi.security.util.EncryptionMethod;
import org.apache.nifi.security.util.crypto.AESKeyedCipherProvider;
import org.apache.nifi.security.util.crypto.KeyedCipherProvider;
import org.apache.nifi.util.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
@ -55,7 +55,7 @@ public class KeyedCipherPropertyEncryptorTest {
private KeyedCipherPropertyEncryptor encryptor;
@Before
@BeforeEach
public void setUp() {
encryptor = new KeyedCipherPropertyEncryptor(CIPHER_PROVIDER, ENCRYPTION_METHOD, SECRET_KEY);
}

View File

@ -20,8 +20,8 @@ import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
import org.apache.nifi.security.util.EncryptionMethod;
import org.apache.nifi.security.util.crypto.PBECipherProvider;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@ -46,7 +46,7 @@ public class PasswordBasedCipherPropertyEncryptorTest {
private PasswordBasedCipherPropertyEncryptor encryptor;
@Before
@BeforeEach
public void setUp() {
encryptor = new PasswordBasedCipherPropertyEncryptor(CIPHER_PROVIDER, ENCRYPTION_METHOD, PASSWORD);
}

View File

@ -19,7 +19,7 @@ package org.apache.nifi.encrypt;
import org.apache.nifi.security.util.EncryptionMethod;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.util.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Properties;

View File

@ -16,8 +16,8 @@
*/
package org.apache.nifi.encrypt;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
@ -31,7 +31,7 @@ public class StandardPropertySecretKeyProviderTest {
private StandardPropertySecretKeyProvider provider;
@Before
@BeforeEach
public void setUp() {
provider = new StandardPropertySecretKeyProvider();
}

View File

@ -28,9 +28,9 @@ import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.serialization.record.type.ArrayDataType;
import org.apache.nifi.serialization.record.util.DataTypeUtils;
import org.apache.nifi.uuid5.Uuid5Util;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.StandardCharsets;
@ -57,8 +57,8 @@ import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class TestRecordPath {
@ -72,12 +72,12 @@ public class TestRecordPath {
private static final String TEST_TIMEZONE_OFFSET = String.format("GMT+0%d:00", TEST_OFFSET_HOURS);
@BeforeClass
@BeforeAll
public static void setTestTimezone() {
System.setProperty(USER_TIMEZONE_PROPERTY, TEST_TIMEZONE);
}
@AfterClass
@AfterAll
public static void setSystemTimezone() {
System.setProperty(USER_TIMEZONE_PROPERTY, SYSTEM_TIMEZONE);
}
@ -93,12 +93,7 @@ public class TestRecordPath {
RecordPath.compile("/name[contains(., 'hello')]");
// substring is not a filter function so cannot be used as a predicate
try {
RecordPath.compile("/name[substring(., 1, 2)]");
fail("Expected RecordPathException");
} catch (final RecordPathException e) {
// expected
}
assertThrows(RecordPathException.class, () -> RecordPath.compile("/name[substring(., 1, 2)]"));
// substring is not a filter function so can be used as *part* of a predicate but not as the entire predicate
RecordPath.compile("/name[substring(., 1, 2) = 'e']");
@ -1568,7 +1563,7 @@ public class TestRecordPath {
assertEquals("Hello World!", RecordPath.compile("toString(/bytes, \"UTF-16\")").evaluate(record).getSelectedFields().findFirst().get().getValue());
}
@Test(expected = IllegalCharsetNameException.class)
@Test
public void testToStringBadCharset() {
final List<RecordField> fields = new ArrayList<>();
fields.add(new RecordField("id", RecordFieldType.INT.getDataType()));
@ -1581,7 +1576,9 @@ public class TestRecordPath {
values.put("bytes", "Hello World!".getBytes(StandardCharsets.UTF_16));
final Record record = new MapRecord(schema, values);
RecordPath.compile("toString(/bytes, \"NOT A REAL CHARSET\")").evaluate(record).getSelectedFields().findFirst().get().getValue();
assertThrows(IllegalCharsetNameException.class, () ->
RecordPath.compile("toString(/bytes, \"NOT A REAL CHARSET\")").evaluate(record)
.getSelectedFields().findFirst().get().getValue());
}
@Test
@ -1601,7 +1598,7 @@ public class TestRecordPath {
(byte[]) RecordPath.compile("toBytes(/s, \"UTF-16LE\")").evaluate(record).getSelectedFields().findFirst().get().getValue());
}
@Test(expected = IllegalCharsetNameException.class)
@Test
public void testToBytesBadCharset() {
final List<RecordField> fields = new ArrayList<>();
fields.add(new RecordField("id", RecordFieldType.INT.getDataType()));
@ -1614,7 +1611,8 @@ public class TestRecordPath {
values.put("s", "Hello World!");
final Record record = new MapRecord(schema, values);
RecordPath.compile("toBytes(/s, \"NOT A REAL CHARSET\")").evaluate(record).getSelectedFields().findFirst().get().getValue();
assertThrows(IllegalCharsetNameException.class, () -> RecordPath.compile("toBytes(/s, \"NOT A REAL CHARSET\")").evaluate(record)
.getSelectedFields().findFirst().get().getValue());
}
@Test
@ -1796,22 +1794,21 @@ public class TestRecordPath {
// test invalid JSON
final Record recordInvalidJson = new MapRecord(schema, Collections.singletonMap("json_str", "{\"invalid\": \"json"));
try {
RecordPath.compile("unescapeJson(/json_str)").evaluate(recordInvalidJson).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue();
fail("Expected a RecordPathException for invalid JSON");
} catch (RecordPathException rpe) {
RecordPathException rpe = assertThrows(RecordPathException.class,
() -> RecordPath.compile("unescapeJson(/json_str)")
.evaluate(recordInvalidJson).getSelectedFields()
.findFirst().orElseThrow(IllegalStateException::new).getValue());
assertEquals("Unable to deserialise JSON String into Record Path value", rpe.getMessage());
}
// test not String
final Record recordNotString = new MapRecord(schema, Collections.singletonMap("person", new MapRecord(person, Collections.singletonMap("age", 30))));
try {
RecordPath.compile("unescapeJson(/person/age)").evaluate(recordNotString).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue();
fail("Expected IllegalArgumentException for non-String input");
} catch (IllegalArgumentException iae) {
IllegalArgumentException iae = assertThrows(IllegalArgumentException.class,
() -> RecordPath.compile("unescapeJson(/person/age)")
.evaluate(recordNotString).getSelectedFields()
.findFirst().orElseThrow(IllegalStateException::new).getValue());
assertEquals("Argument supplied to unescapeJson must be a String", iae.getMessage());
}
}
@Test
public void testHash() {
@ -1820,10 +1817,11 @@ public class TestRecordPath {
assertEquals("5753a498f025464d72e088a9d5d6e872592d5f91", RecordPath.compile("hash(/firstName, 'SHA-1')").evaluate(record).getSelectedFields().findFirst().get().getValue());
}
@Test(expected = RecordPathException.class)
@Test
public void testHashFailure() {
final Record record = getCaseTestRecord();
assertEquals("61409aa1fd47d4a5332de23cbf59a36f", RecordPath.compile("hash(/firstName, 'NOT_A_ALGO')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertThrows(RecordPathException.class, () -> RecordPath.compile("hash(/firstName, 'NOT_A_ALGO')").evaluate(record)
.getSelectedFields().findFirst().get().getValue());
}
@Test

View File

@ -16,13 +16,6 @@
*/
package org.apache.nifi.record.path.util;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.nifi.record.path.FieldValue;
import org.apache.nifi.serialization.SimpleRecordSchema;
import org.apache.nifi.serialization.record.DataType;
@ -32,6 +25,13 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
/**
* Abstract base class for tests that walk FieldValue hierarchies.
*/

View File

@ -16,15 +16,16 @@
*/
package org.apache.nifi.record.path.util;
import static org.junit.Assert.assertEquals;
import org.apache.nifi.record.path.FieldValue;
import org.apache.nifi.record.path.RecordPath;
import org.apache.nifi.serialization.record.Record;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.nifi.record.path.FieldValue;
import org.apache.nifi.record.path.RecordPath;
import org.apache.nifi.serialization.record.Record;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class TestFieldValueLogicalPathBuilder extends AbstractWalkerTest {
@ -86,9 +87,9 @@ public class TestFieldValueLogicalPathBuilder extends AbstractWalkerTest {
}
}
@Test(expected = NullPointerException.class)
@Test
public void buildLogicalPathBuilderFailsNull() {
final FieldValueLogicalPathBuilder builder = getDefaultLogicalPathBuilder();
builder.buildLogicalPath(null);
assertThrows(NullPointerException.class, () -> builder.buildLogicalPath(null));
}
}

View File

@ -16,15 +16,15 @@
*/
package org.apache.nifi.record.path.util;
import static org.junit.Assert.assertEquals;
import org.apache.nifi.record.path.FieldValue;
import org.apache.nifi.record.path.RecordPath;
import org.apache.nifi.serialization.record.Record;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.nifi.record.path.FieldValue;
import org.apache.nifi.record.path.RecordPath;
import org.apache.nifi.serialization.record.Record;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestFieldValueWalker extends AbstractWalkerTest {

View File

@ -27,5 +27,4 @@
several interfaces for interacting with Records. This module should not depend
on any external libraries.
</description>
</project>

View File

@ -20,8 +20,7 @@ package org.apache.nifi.serialization;
import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.SchemaIdentifier;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.ArrayList;
@ -31,6 +30,7 @@ import java.util.List;
import java.util.Set;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestSimpleRecordSchema {
@ -40,11 +40,7 @@ public class TestSimpleRecordSchema {
fields.add(new RecordField("hello", RecordFieldType.STRING.getDataType(), null, set("foo", "bar")));
fields.add(new RecordField("goodbye", RecordFieldType.STRING.getDataType(), null, set("baz", "bar")));
try {
new SimpleRecordSchema(fields);
Assert.fail("Was able to create two fields with same alias");
} catch (final IllegalArgumentException expected) {
}
assertThrows(IllegalArgumentException.class, () -> new SimpleRecordSchema(fields));
}
@Test
@ -53,11 +49,7 @@ public class TestSimpleRecordSchema {
fields.add(new RecordField("hello", RecordFieldType.STRING.getDataType(), null, set("foo", "bar")));
fields.add(new RecordField("hello", RecordFieldType.STRING.getDataType()));
try {
new SimpleRecordSchema(fields);
Assert.fail("Was able to create two fields with same name");
} catch (final IllegalArgumentException expected) {
}
assertThrows(IllegalArgumentException.class, () -> new SimpleRecordSchema(fields));
}
@Test
@ -66,11 +58,7 @@ public class TestSimpleRecordSchema {
fields.add(new RecordField("hello", RecordFieldType.STRING.getDataType(), null, set("foo", "bar")));
fields.add(new RecordField("bar", RecordFieldType.STRING.getDataType()));
try {
new SimpleRecordSchema(fields);
Assert.fail("Was able to create two fields with conflicting names/aliases");
} catch (final IllegalArgumentException expected) {
}
assertThrows(IllegalArgumentException.class, () -> new SimpleRecordSchema(fields));
}
@Test

View File

@ -19,13 +19,15 @@ package org.apache.nifi.serialization.record;
import org.apache.nifi.serialization.SimpleRecordSchema;
import org.apache.nifi.serialization.record.type.ArrayDataType;
import org.apache.nifi.serialization.record.type.DecimalDataType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import java.math.BigDecimal;
import java.sql.Array;
@ -54,7 +56,8 @@ import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class ResultSetRecordSetTest {
private static final String COLUMN_NAME_VARCHAR = "varchar";
@ -105,7 +108,7 @@ public class ResultSetRecordSetTest {
@Mock
private ResultSetMetaData resultSetMetaData;
@Before
@BeforeEach
public void setUp() throws SQLException {
setUpMocks(COLUMNS, resultSetMetaData, resultSet);
}

View File

@ -22,7 +22,7 @@ import org.apache.nifi.serialization.record.type.ChoiceDataType;
import org.apache.nifi.serialization.record.type.RecordDataType;
import org.apache.nifi.serialization.record.util.DataTypeUtils;
import org.apache.nifi.serialization.record.util.IllegalTypeConversionException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.math.BigInteger;
@ -55,11 +55,12 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestDataTypeUtils {
private static final ZoneId SYSTEM_DEFAULT_ZONE_ID = ZoneOffset.systemDefault();
@ -82,12 +83,12 @@ public class TestDataTypeUtils {
Timestamp ts = DataTypeUtils.toTimestamp(date, null, null);
assertNotNull(ts);
assertEquals("Times didn't match", ts.getTime(), date.getTime());
assertEquals(ts.getTime(), date.getTime(), "Times didn't match");
java.sql.Date sDate = new java.sql.Date(date.getTime());
ts = DataTypeUtils.toTimestamp(date, null, null);
assertNotNull(ts);
assertEquals("Times didn't match", ts.getTime(), sDate.getTime());
assertEquals(ts.getTime(), sDate.getTime(), "Times didn't match");
}
/*
@ -102,7 +103,7 @@ public class TestDataTypeUtils {
java.sql.Date output = DataTypeUtils.toDate(ts, null, null);
assertNotNull(output);
assertEquals("Timestamps didn't match", output.getTime(), ts.getTime());
assertEquals(output.getTime(), ts.getTime(), "Timestamps didn't match");
}
@Test
@ -266,11 +267,11 @@ public class TestDataTypeUtils {
assertTrue(bytes instanceof Byte[]);
assertNotNull(bytes);
Byte[] b = (Byte[]) bytes;
assertEquals("Conversion from String to byte[] failed", (long) 72, (long) b[0] ); // H
assertEquals("Conversion from String to byte[] failed", (long) 101, (long) b[1] ); // e
assertEquals("Conversion from String to byte[] failed", (long) 108, (long) b[2] ); // l
assertEquals("Conversion from String to byte[] failed", (long) 108, (long) b[3] ); // l
assertEquals("Conversion from String to byte[] failed", (long) 111, (long) b[4] ); // o
assertEquals((long) 72, (long) b[0], "Conversion from String to byte[] failed"); // H
assertEquals((long) 101, (long) b[1], "Conversion from String to byte[] failed" ); // e
assertEquals((long) 108, (long) b[2], "Conversion from String to byte[] failed" ); // l
assertEquals((long) 108, (long) b[3], "Conversion from String to byte[] failed" ); // l
assertEquals((long) 111, (long) b[4], "Conversion from String to byte[] failed" ); // o
}
@Test
@ -278,7 +279,7 @@ public class TestDataTypeUtils {
Object s = DataTypeUtils.convertType("Hello".getBytes(StandardCharsets.UTF_16), RecordFieldType.STRING.getDataType(),null, StandardCharsets.UTF_16);
assertNotNull(s);
assertTrue(s instanceof String);
assertEquals("Conversion from byte[] to String failed", "Hello", s);
assertEquals("Hello", s, "Conversion from byte[] to String failed");
}
@Test
@ -286,7 +287,7 @@ public class TestDataTypeUtils {
Object b = DataTypeUtils.convertType("Hello".getBytes(StandardCharsets.UTF_16), RecordFieldType.ARRAY.getArrayDataType(RecordFieldType.BYTE.getDataType()),null, StandardCharsets.UTF_16);
assertNotNull(b);
assertTrue(b instanceof Byte[]);
assertEquals("Conversion from byte[] to String failed at char 0", (Object) "Hello".getBytes(StandardCharsets.UTF_16)[0], ((Byte[]) b)[0]);
assertEquals((Object) "Hello".getBytes(StandardCharsets.UTF_16)[0], ((Byte[]) b)[0], "Conversion from byte[] to String failed at char 0");
}
@Test
@ -314,19 +315,22 @@ public class TestDataTypeUtils {
assertNull(DataTypeUtils.convertType(null, RecordFieldType.DECIMAL.getDecimalDataType(30, 10), null, StandardCharsets.UTF_8));
}
@Test(expected = IllegalTypeConversionException.class)
@Test
public void testConvertToBigDecimalWhenInputStringIsInvalid() {
DataTypeUtils.convertType("test", RecordFieldType.DECIMAL.getDecimalDataType(30, 10), null, StandardCharsets.UTF_8);
assertThrows(IllegalTypeConversionException.class, () -> DataTypeUtils.convertType("test", RecordFieldType.DECIMAL.getDecimalDataType(30, 10),
null, StandardCharsets.UTF_8));
}
@Test(expected = IllegalTypeConversionException.class)
@Test
public void testConvertToBigDecimalWhenUnsupportedType() {
DataTypeUtils.convertType(new ArrayList<Double>(), RecordFieldType.DECIMAL.getDecimalDataType(30, 10), null, StandardCharsets.UTF_8);
assertThrows(IllegalTypeConversionException.class, () -> DataTypeUtils.convertType(new ArrayList<Double>(), RecordFieldType.DECIMAL.getDecimalDataType(30, 10),
null, StandardCharsets.UTF_8));
}
@Test(expected = IllegalTypeConversionException.class)
@Test
public void testConvertToBigDecimalWhenUnsupportedNumberType() {
DataTypeUtils.convertType(new DoubleAdder(), RecordFieldType.DECIMAL.getDecimalDataType(30, 10), null, StandardCharsets.UTF_8);
assertThrows(IllegalTypeConversionException.class, () -> DataTypeUtils.convertType(new DoubleAdder(), RecordFieldType.DECIMAL.getDecimalDataType(30, 10),
null, StandardCharsets.UTF_8));
}
@Test
@ -413,16 +417,16 @@ public class TestDataTypeUtils {
for (final String decimal : decimals) {
for (final String exp : exponents) {
String toTest = prefix + "100" + decimal + exp;
assertTrue(toTest + " not valid float", DataTypeUtils.isFloatTypeCompatible(toTest));
assertTrue(toTest + " not valid double", DataTypeUtils.isDoubleTypeCompatible(toTest));
assertTrue(DataTypeUtils.isFloatTypeCompatible(toTest), toTest + " not valid float");
assertTrue(DataTypeUtils.isDoubleTypeCompatible(toTest), toTest + " not valid double");
Double.parseDouble(toTest); // ensure we can actually parse it
Float.parseFloat(toTest);
if (decimal.length() > 1) {
toTest = prefix + decimal + exp;
assertTrue(toTest + " not valid float", DataTypeUtils.isFloatTypeCompatible(toTest));
assertTrue(toTest + " not valid double", DataTypeUtils.isDoubleTypeCompatible(toTest));
assertTrue(DataTypeUtils.isFloatTypeCompatible(toTest), toTest + " not valid float");
assertTrue(DataTypeUtils.isDoubleTypeCompatible(toTest), toTest + " not valid double");
Double.parseDouble(toTest); // ensure we can actually parse it
Float.parseFloat(toTest);
}
@ -532,7 +536,7 @@ public class TestDataTypeUtils {
};
Optional<String> actual = DataTypeUtils.findMostSuitableTypeByStringValue(valueAsString, types, dataTypeMapper);
assertTrue("Exception not thrown during test as intended.", exceptionThrown.get());
assertTrue(exceptionThrown.get(), "Exception not thrown during test as intended.");
assertEquals(expected, actual);
}
@ -753,11 +757,11 @@ public class TestDataTypeUtils {
final BigDecimal indirectResult = whenExpectingValidConversion(expectedValue, incomingValue, RecordFieldType.DECIMAL.getDecimalDataType(30, 10));
// In some cases, direct equality check comes with false negative as the changing representation brings in
// insignificant changes what might break the comparison. For example 12F will be represented as "12.0"
assertEquals(failureMessage + "indirect", 0, expectedValue.compareTo(indirectResult));
assertEquals(0, expectedValue.compareTo(indirectResult), failureMessage + "indirect");
// Checking direct conversion
final BigDecimal directResult = DataTypeUtils.toBigDecimal(incomingValue, "field");
assertEquals(failureMessage + "direct", 0, expectedValue.compareTo(directResult));
assertEquals(0, expectedValue.compareTo(directResult), failureMessage + "direct");
}
@ -947,7 +951,7 @@ public class TestDataTypeUtils {
@Test
public void testConvertTypeStringToDateDefaultTimeZoneFormat() {
final Object converted = DataTypeUtils.convertType(ISO_8601_YEAR_MONTH_DAY, RecordFieldType.DATE.getDataType(), DATE_FIELD);
assertTrue("Converted value is not java.sql.Date", converted instanceof java.sql.Date);
assertTrue(converted instanceof java.sql.Date, "Converted value is not java.sql.Date");
assertEquals(ISO_8601_YEAR_MONTH_DAY, converted.toString());
}
@ -958,7 +962,7 @@ public class TestDataTypeUtils {
public void testConvertTypeStringToDateConfiguredTimeZoneFormat() {
final DateFormat dateFormat = DataTypeUtils.getDateFormat(CUSTOM_MONTH_DAY_YEAR_PATTERN, "GMT");
final Object converted = DataTypeUtils.convertType(CUSTOM_MONTH_DAY_YEAR, RecordFieldType.DATE.getDataType(), () -> dateFormat, null, null,"date");
assertTrue("Converted value is not java.sql.Date", converted instanceof java.sql.Date);
assertTrue(converted instanceof java.sql.Date, "Converted value is not java.sql.Date");
assertEquals(ISO_8601_YEAR_MONTH_DAY, converted.toString());
}
@ -969,7 +973,7 @@ public class TestDataTypeUtils {
public void testConvertTypeStringToDateConfiguredSystemDefaultTimeZoneFormat() {
final DateFormat dateFormat = DataTypeUtils.getDateFormat(CUSTOM_MONTH_DAY_YEAR_PATTERN, TimeZone.getDefault().getID());
final Object converted = DataTypeUtils.convertType(CUSTOM_MONTH_DAY_YEAR, RecordFieldType.DATE.getDataType(), () -> dateFormat, null, null,"date");
assertTrue("Converted value is not java.sql.Date", converted instanceof java.sql.Date);
assertTrue(converted instanceof java.sql.Date, "Converted value is not java.sql.Date");
assertEquals(ISO_8601_YEAR_MONTH_DAY, converted.toString());
}
@ -1006,6 +1010,6 @@ public class TestDataTypeUtils {
private void assertToLocalDateEquals(final String expected, final Object value) {
final DateTimeFormatter systemDefaultZoneFormatter = DataTypeUtils.getDateTimeFormatter(RecordFieldType.DATE.getDefaultFormat(), SYSTEM_DEFAULT_ZONE_ID);
final LocalDate localDate = DataTypeUtils.toLocalDate(value, () -> systemDefaultZoneFormatter, DATE_FIELD);
assertEquals(String.format("Value Class [%s] to LocalDate not matched", value.getClass()), expected, localDate.toString());
assertEquals(expected, localDate.toString(), String.format("Value Class [%s] to LocalDate not matched", value.getClass()));
}
}

View File

@ -17,8 +17,8 @@
package org.apache.nifi.serialization.record;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.apache.nifi.serialization.SimpleRecordSchema;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
@ -27,9 +27,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.nifi.serialization.SimpleRecordSchema;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class TestMapRecord {
@ -71,12 +71,7 @@ public class TestMapRecord {
new RecordField("hello", RecordFieldType.INT.getDataType(), 84);
new RecordField("hello", RecordFieldType.INT.getDataType(), (Object) null);
try {
new RecordField("hello", RecordFieldType.INT.getDataType(), "foo");
Assert.fail("Was able to set a default value of \"foo\" for INT type");
} catch (final IllegalArgumentException expected) {
// expected
}
assertThrows(IllegalArgumentException.class, () -> new RecordField("hello", RecordFieldType.INT.getDataType(), "foo"));
}
private Set<String> set(final String... values) {

View File

@ -16,18 +16,19 @@
*/
package org.apache.nifi.rocksdb;
import org.apache.commons.lang3.SystemUtils;
import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.RocksIterator;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
@ -42,13 +43,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
@DisabledOnOs(OS.WINDOWS)
public class TestRocksDBMetronome {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private static final byte[] KEY = "key".getBytes(StandardCharsets.UTF_8);
private static final byte[] VALUE = "value".getBytes(StandardCharsets.UTF_8);
private static final byte[] KEY_2 = "key 2".getBytes(StandardCharsets.UTF_8);
@ -56,17 +55,12 @@ public class TestRocksDBMetronome {
private ExecutorService executor;
@BeforeClass
public static void setupClass() {
Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS);
}
@Before
@BeforeEach
public void before() {
executor = Executors.newSingleThreadExecutor();
}
@After
@AfterEach
public void after() {
executor.shutdownNow();
}
@ -98,10 +92,16 @@ public class TestRocksDBMetronome {
}
}
private Path newFolder(Path parent) {
File newFolder = parent.resolve("temp-" + System.currentTimeMillis()).toFile();
newFolder.mkdirs();
return newFolder.toPath();
}
@Test
public void testPutGetDelete() throws Exception {
public void testPutGetDelete(@TempDir Path temporaryFolder) throws Exception {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.build()) {
db.initialize();
@ -122,9 +122,9 @@ public class TestRocksDBMetronome {
}
@Test
public void testPutGetConfiguration() throws Exception {
public void testPutGetConfiguration(@TempDir Path temporaryFolder) throws Exception {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.build()) {
db.initialize();
@ -136,32 +136,36 @@ public class TestRocksDBMetronome {
}
}
@Test(expected = IllegalStateException.class)
public void testPutBeforeInit() throws Exception {
@Test
public void testPutBeforeInit(@TempDir Path temporaryFolder) throws Exception {
assertThrows(IllegalStateException.class, () -> {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.build()) {
db.put(KEY, VALUE);
}
});
}
@Test(expected = IllegalStateException.class)
public void testPutClosed() throws Exception {
@Test
public void testPutClosed(@TempDir Path temporaryFolder) {
assertThrows(IllegalStateException.class, () -> {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.build()) {
db.initialize();
db.close();
db.put(KEY_2, VALUE_2);
}
});
}
@Test
public void testColumnFamilies() throws Exception {
public void testColumnFamilies(@TempDir Path temporaryFolder) throws Exception {
String secondFamilyName = "second family";
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.addColumnFamily(secondFamilyName)
.build()) {
db.initialize();
@ -210,9 +214,9 @@ public class TestRocksDBMetronome {
}
@Test
public void testIterator() throws Exception {
public void testIterator(@TempDir Path temporaryFolder) throws Exception {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.build()) {
db.initialize();
@ -236,9 +240,9 @@ public class TestRocksDBMetronome {
}
@Test
public void testCounterIncrement() throws Exception {
public void testCounterIncrement(@TempDir Path temporaryFolder) throws Exception {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.setSyncMillis(Long.MAX_VALUE) // effectively disable the auto-sync
.build()) {
db.initialize();
@ -254,10 +258,11 @@ public class TestRocksDBMetronome {
}
}
@Test(timeout = 10_000)
public void testWaitForSync() throws Exception {
@Test
@Timeout(unit = TimeUnit.MILLISECONDS, value = 10_000)
public void testWaitForSync(@TempDir Path temporaryFolder) throws Exception {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.setSyncMillis(Long.MAX_VALUE) // effectively disable the auto-sync
.build()) {
db.initialize();
@ -285,10 +290,11 @@ public class TestRocksDBMetronome {
}
}
@Test(timeout = 10_000)
public void testWaitForSyncWithValue() throws Exception {
@Test
@Timeout(unit = TimeUnit.MILLISECONDS, value = 10_000)
public void testWaitForSyncWithValue(@TempDir Path temporaryFolder) throws Exception {
try (RocksDBMetronome db = new RocksDBMetronome.Builder()
.setStoragePath(temporaryFolder.newFolder().toPath())
.setStoragePath(newFolder(temporaryFolder))
.setSyncMillis(Long.MAX_VALUE) // effectively disable the auto-sync
.build()) {
db.initialize();
@ -312,15 +318,11 @@ public class TestRocksDBMetronome {
}
}
private void assertBlocks(RocksDBMetronome db, int counterValue) throws InterruptedException, java.util.concurrent.ExecutionException {
private void assertBlocks(RocksDBMetronome db, int counterValue) {
Future<Boolean> future = getWaitForSyncFuture(db, counterValue);
try {
future.get(1, TimeUnit.SECONDS);
fail();
} catch (TimeoutException expected) {
assertThrows(TimeoutException.class, () -> future.get(1, TimeUnit.SECONDS));
assertFalse(future.isDone());
}
future.cancel(true);
}

View File

@ -17,11 +17,7 @@
package org.apache.nifi.repository.schema;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -34,7 +30,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestSchemaRecordReader {

View File

@ -17,11 +17,8 @@
package org.apache.nifi.repository.schema;
import static org.apache.nifi.repository.schema.SchemaRecordWriter.MAX_ALLOWED_UTF_LENGTH;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -35,8 +32,11 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import static org.apache.nifi.repository.schema.SchemaRecordWriter.MAX_ALLOWED_UTF_LENGTH;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestSchemaRecordReaderWriter {
@ -237,69 +237,69 @@ public class TestSchemaRecordReaderWriter {
@Test
public void testSingleCharUTF8Lengths() {
// verify handling of single characters mapping to utf8 byte strings
assertEquals("test 1 char string truncated to 0 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 0));
assertEquals("test 2 char string truncated to 0 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 0));
assertEquals("test 3 char string truncated to 0 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 0));
assertEquals("test 1 char string truncated to 1 utf bytes should be 1", 1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 1));
assertEquals("test 2 char string truncated to 1 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 1));
assertEquals("test 3 char string truncated to 1 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 1));
assertEquals("test 1 char string truncated to 2 utf bytes should be 1", 1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 2));
assertEquals("test 2 char string truncated to 2 utf bytes should be 2", 1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 2));
assertEquals("test 3 char string truncated to 2 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 2));
assertEquals("test 1 char string truncated to 3 utf bytes should be 1", 1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 3));
assertEquals("test 2 char string truncated to 3 utf bytes should be 2", 1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 3));
assertEquals("test 3 char string truncated to 3 utf bytes should be 3", 1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 3));
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 0), "test 1 char string truncated to 0 utf bytes should be 0");
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 0), "test 2 char string truncated to 0 utf bytes should be 0");
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 0), "test 3 char string truncated to 0 utf bytes should be 0");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 1), "test 1 char string truncated to 1 utf bytes should be 1");
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 1), "test 2 char string truncated to 1 utf bytes should be 0");
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 1), "test 3 char string truncated to 1 utf bytes should be 0");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 2), "test 1 char string truncated to 2 utf bytes should be 1");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 2), "test 2 char string truncated to 2 utf bytes should be 2");
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 2), "test 3 char string truncated to 2 utf bytes should be 0");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringOneByte, 3), "test 1 char string truncated to 3 utf bytes should be 1");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringTwoByte, 3), "test 2 char string truncated to 3 utf bytes should be 2");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(utfStringThreeByte, 3), "test 3 char string truncated to 3 utf bytes should be 3");
}
@Test
public void testMultiCharUTFLengths() {
// test boundary conditions as 1, 2, and 3 UTF byte chars are included into utf limit positions used by strings
final String testString1 = utfStringOneByte + utfStringTwoByte + utfStringThreeByte; // char 'abc' utf 'abbccc'
assertEquals("test 6 char string truncated to 0 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 0)); // utf ''
assertEquals("test 6 char string truncated to 1 utf bytes should be 1", 1, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 1)); // utf 'a'
assertEquals("test 6 char string truncated to 2 utf bytes should be 1", 1, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 2)); // utf 'a'
assertEquals("test 6 char string truncated to 3 utf bytes should be 2", 2, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 3)); // utf 'abb'
assertEquals("test 6 char string truncated to 4 utf bytes should be 2", 2, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 4)); // utf 'abb'
assertEquals("test 6 char string truncated to 5 utf bytes should be 2", 2, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 5)); // utf 'abb'
assertEquals("test 6 char string truncated to 6 utf bytes should be 3", 3, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 6)); // utf 'abbccc'
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 0), "test 6 char string truncated to 0 utf bytes should be 0"); // utf ''
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 1), "test 6 char string truncated to 1 utf bytes should be 1"); // utf 'a'
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 2), "test 6 char string truncated to 2 utf bytes should be 1"); // utf 'a'
assertEquals(2, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 3), "test 6 char string truncated to 3 utf bytes should be 2"); // utf 'abb'
assertEquals(2, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 4), "test 6 char string truncated to 4 utf bytes should be 2"); // utf 'abb'
assertEquals(2, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 5), "test 6 char string truncated to 5 utf bytes should be 2"); // utf 'abb'
assertEquals(3, SchemaRecordWriter.getCharsInUTF8Limit(testString1, 6), "test 6 char string truncated to 6 utf bytes should be 3"); // utf 'abbccc'
}
@Test
public void testSmallCharUTFLengths() throws UnsupportedEncodingException {
final String string12b = StringUtils.repeat(utfStringOneByte + utfStringTwoByte + utfStringThreeByte, 2);
assertEquals("test multi-char string truncated to 0 utf bytes should be 0", 0, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 0));
assertEquals("test multi-char string truncated to 1 utf bytes should be 0", 1, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 1));
assertEquals("test multi-char string truncated to 2 utf bytes should be 0", 1, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 2));
assertEquals("test multi-char string truncated to 3 utf bytes should be 0", 2, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 3));
assertEquals("test multi-char string truncated to 4 utf bytes should be 0", 2, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 4));
assertEquals("test multi-char string truncated to 5 utf bytes should be 0", 2, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 5));
assertEquals("test multi-char string truncated to 6 utf bytes should be 0", 3, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 6));
assertEquals("test multi-char string truncated to 7 utf bytes should be 0", 4, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 7));
assertEquals("test multi-char string truncated to 8 utf bytes should be 0", 4, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 8));
assertEquals("test multi-char string truncated to 9 utf bytes should be 0", 5, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 9));
assertEquals("test multi-char string truncated to 10 utf bytes should be 0", 5, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 10));
assertEquals("test multi-char string truncated to 11 utf bytes should be 0", 5, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 11));
assertEquals("test multi-char string truncated to 12 utf bytes should be 0", 6, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 12));
assertEquals(0, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 0), "test multi-char string truncated to 0 utf bytes should be 0");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 1), "test multi-char string truncated to 1 utf bytes should be 0");
assertEquals(1, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 2), "test multi-char string truncated to 2 utf bytes should be 0");
assertEquals(2, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 3), "test multi-char string truncated to 3 utf bytes should be 0");
assertEquals(2, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 4), "test multi-char string truncated to 4 utf bytes should be 0");
assertEquals(2, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 5), "test multi-char string truncated to 5 utf bytes should be 0");
assertEquals(3, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 6), "test multi-char string truncated to 6 utf bytes should be 0");
assertEquals(4, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 7), "test multi-char string truncated to 7 utf bytes should be 0");
assertEquals(4, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 8), "test multi-char string truncated to 8 utf bytes should be 0");
assertEquals(5, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 9), "test multi-char string truncated to 9 utf bytes should be 0");
assertEquals(5, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 10), "test multi-char string truncated to 10 utf bytes should be 0");
assertEquals(5, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 11), "test multi-char string truncated to 11 utf bytes should be 0");
assertEquals(6, SchemaRecordWriter.getCharsInUTF8Limit(string12b, 12), "test multi-char string truncated to 12 utf bytes should be 0");
}
@Test
public void testLargeCharUTFLengths() {
final String string64k = StringUtils.repeat(utfStringOneByte + utfStringTwoByte + utfStringThreeByte, 21845);
assertEquals("test 64k char string should be 64k chars long", 65535, string64k.length());
assertEquals(65535, string64k.length(), "test 64k char string should be 64k chars long");
// drop half the chars going to utf of 64k bytes -- (1+1+1) * 21845 = 65535 chars which converts to (1+2+3) * 21845 = 131070 utf bytes so 1/2 is truncated
assertEquals("test 64k char string truncated to 65,535 utf bytes should be 32768", 32768, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65535));
assertEquals(32768, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65535), "test 64k char string truncated to 65,535 utf bytes should be 32768");
// dropping bytes off the end of utf length
assertEquals("test 64k char string truncated to 65,534 utf bytes should be 32767", 32767, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65534)); // lost 2 byte char
assertEquals("test 64k char string truncated to 65,533 utf bytes should be 32767", 32767, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65533));
assertEquals("test 64k char string truncated to 65,532 utf bytes should be 32766", 32766, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65532)); // lost 1 byte char
assertEquals("test 64k char string truncated to 65,531 utf bytes should be 32765", 32765, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65531)); // lost 3 byte char
assertEquals("test 64k char string truncated to 65,530 utf bytes should be 32765", 32765, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65530));
assertEquals("test 64k char string truncated to 65,529 utf bytes should be 32765", 32765, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65529));
assertEquals("test 64k char string truncated to 65,528 utf bytes should be 32764", 32764, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65528)); // lost 2 byte char (again)
assertEquals(32767, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65534), "test 64k char string truncated to 65,534 utf bytes should be 32767"); // lost 2 byte char
assertEquals(32767, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65533), "test 64k char string truncated to 65,533 utf bytes should be 32767");
assertEquals(32766, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65532), "test 64k char string truncated to 65,532 utf bytes should be 32766"); // lost 1 byte char
assertEquals(32765, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65531), "test 64k char string truncated to 65,531 utf bytes should be 32765"); // lost 3 byte char
assertEquals(32765, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65530), "test 64k char string truncated to 65,530 utf bytes should be 32765");
assertEquals(32765, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65529), "test 64k char string truncated to 65,529 utf bytes should be 32765");
assertEquals(32764, SchemaRecordWriter.getCharsInUTF8Limit(string64k, 65528), "test 64k char string truncated to 65,528 utf bytes should be 32764"); // lost 2 byte char (again)
}
private SimpleRecordField createField(final String fieldName, final FieldType type) {

View File

@ -18,10 +18,9 @@ package org.apache.nifi.security.krb;
import org.apache.nifi.logging.ComponentLog;
import org.apache.nifi.processor.ProcessContext;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;
import javax.security.auth.Subject;
@ -29,6 +28,7 @@ import javax.security.auth.kerberos.KerberosPrincipal;
import javax.security.auth.kerberos.KerberosTicket;
import javax.security.auth.login.LoginException;
import java.io.File;
import java.nio.file.Path;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.Principal;
@ -41,13 +41,9 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class KerberosUserIT {
@ClassRule
public static TemporaryFolder tmpDir = new TemporaryFolder();
private static KDCServer kdc;
private static KerberosPrincipal principal1;
@ -59,18 +55,21 @@ public class KerberosUserIT {
private static KerberosPrincipal principal3;
private static final String principal3Password = "changeme";
@BeforeClass
public static void setupClass() throws Exception {
kdc = new KDCServer(tmpDir.newFolder("mini-kdc_"));
@BeforeAll
public static void setupClass(@TempDir Path tmpDir) throws Exception {
File kdcFolder = tmpDir.resolve("mini-kdc_").toFile();
kdcFolder.mkdirs();
kdc = new KDCServer(kdcFolder);
kdc.setMaxTicketLifetime("15"); // set ticket lifetime to 15 seconds so we can test relogin
kdc.start();
principal1 = new KerberosPrincipal("user1@" + kdc.getRealm());
principal1KeytabFile = tmpDir.newFile("user1.keytab");
principal1KeytabFile = tmpDir.resolve("user1.keytab").toFile();
kdc.createKeytabPrincipal(principal1KeytabFile, "user1");
principal2 = new KerberosPrincipal("user2@" + kdc.getRealm());
principal2KeytabFile = tmpDir.newFile("user2.keytab");
principal2KeytabFile = tmpDir.resolve("user2.keytab").toFile();
kdc.createKeytabPrincipal(principal2KeytabFile, "user2");
principal3 = new KerberosPrincipal("user3@" + kdc.getRealm());
@ -113,16 +112,10 @@ public class KerberosUserIT {
}
@Test
public void testKeytabLoginWithUnknownPrincipal() throws LoginException {
public void testKeytabLoginWithUnknownPrincipal() {
final String unknownPrincipal = "doesnotexist@" + kdc.getRealm();
final KerberosUser user1 = new KerberosKeytabUser(unknownPrincipal, principal1KeytabFile.getAbsolutePath());
try {
user1.login();
fail("Login should have failed");
} catch (Exception e) {
// exception is expected here
//e.printStackTrace();
}
assertThrows(Exception.class, () -> user1.login());
}
@Test
@ -147,11 +140,11 @@ public class KerberosUserIT {
assertEquals(0, userSubject.getPrincipals().size());
}
@Test(expected = LoginException.class)
public void testPasswordUserLoginWithInvalidPassword() throws LoginException {
@Test
public void testPasswordUserLoginWithInvalidPassword() {
// perform login for user
final KerberosUser user = new KerberosPasswordUser("user3", "NOT THE PASSWORD");
user.login();
assertThrows(LoginException.class, () -> user.login());
}
@Test

View File

@ -17,7 +17,7 @@
package org.apache.nifi.security.kms;
import org.apache.nifi.security.kms.util.SecretKeyUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
import java.io.FileOutputStream;
@ -31,9 +31,9 @@ import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class FileBasedKeyProviderTest {
private static final String KEYS_EXTENSION = ".keys";

View File

@ -22,7 +22,7 @@ import org.apache.nifi.security.kms.configuration.KeyProviderConfiguration;
import org.apache.nifi.security.kms.configuration.KeyStoreKeyProviderConfiguration;
import org.apache.nifi.security.kms.configuration.StaticKeyProviderConfiguration;
import org.apache.nifi.security.kms.util.SecretKeyUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
import java.io.File;
@ -32,8 +32,8 @@ import java.security.KeyStore;
import java.util.Collections;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class KeyProviderFactoryTest {

View File

@ -17,8 +17,8 @@
package org.apache.nifi.security.kms;
import org.apache.nifi.security.kms.util.SecretKeyUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
import java.io.IOException;
@ -28,9 +28,9 @@ import java.security.KeyStore;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class KeyStoreKeyProviderTest {
private static final String KEY_ID = UUID.randomUUID().toString();
@ -43,7 +43,7 @@ public class KeyStoreKeyProviderTest {
private static KeyStore keyStore;
@BeforeClass
@BeforeAll
public static void setKeyStore() throws GeneralSecurityException, IOException {
keyStore = getKeyStore();
}

View File

@ -17,7 +17,7 @@
package org.apache.nifi.security.kms;
import org.apache.nifi.security.kms.util.SecretKeyUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
import java.security.KeyManagementException;
@ -25,9 +25,9 @@ import java.util.Collections;
import java.util.List;
import java.util.UUID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StaticKeyProviderTest {
private static final String KEY_ID = UUID.randomUUID().toString();

View File

@ -17,7 +17,7 @@
package org.apache.nifi.security.kms.reader;
import org.apache.nifi.security.kms.util.SecretKeyUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
import java.io.FileOutputStream;
@ -28,7 +28,7 @@ import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class StandardFileBasedKeyReaderTest {
private static final String KEYS_EXTENSION = ".keys";
@ -45,7 +45,7 @@ public class StandardFileBasedKeyReaderTest {
final Path path = getSecretKeysPath(ROOT_KEY, Collections.singletonMap(keyId, secretKey));
final Map<String, SecretKey> secretKeys = reader.readSecretKeys(path, ROOT_KEY);
final SecretKey readSecretKey = secretKeys.get(keyId);
assertEquals("Secret Key not matched", secretKey, readSecretKey);
assertEquals(secretKey, readSecretKey, "Secret Key not matched");
}
private Path getSecretKeysPath(final SecretKey rootKey, final Map<String, SecretKey> secretKeys) throws Exception {

View File

@ -170,12 +170,14 @@ public class SSLSocketChannelTest {
}
@Test
@Timeout(value = CHANNEL_TIMEOUT, unit = TimeUnit.MILLISECONDS)
public void testServerReadWriteTls12() throws Exception {
assertServerChannelConnectedReadClosed(TLS_1_2);
}
@EnabledIf(TLS_1_3_SUPPORTED)
@Test
@Timeout(value = CHANNEL_TIMEOUT, unit = TimeUnit.MILLISECONDS)
public void testServerReadWriteTls13() throws Exception {
assertServerChannelConnectedReadClosed(TLS_1_3);
}

View File

@ -16,34 +16,30 @@
*/
package org.apache.nifi.security.util
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@RunWith(JUnit4.class)
class TlsConfigurationTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(TlsConfigurationTest.class)
@BeforeClass
@BeforeAll
static void setUpOnce() {
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Before
@BeforeEach
void setUp() {
super.setUp()
}
@After
@AfterEach
void tearDown() {
}

View File

@ -16,16 +16,16 @@
*/
package org.apache.nifi.security.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
public class TlsPlatformTest {
private static final int ZERO_LENGTH = 0;

View File

@ -20,22 +20,14 @@ import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers
import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.asn1.x500.style.BCStyle
import org.bouncycastle.asn1.x500.style.IETFUtils
import org.bouncycastle.asn1.x509.Extension
import org.bouncycastle.asn1.x509.Extensions
import org.bouncycastle.asn1.x509.ExtensionsGenerator
import org.bouncycastle.asn1.x509.GeneralName
import org.bouncycastle.asn1.x509.GeneralNames
import org.bouncycastle.asn1.x509.*
import org.bouncycastle.operator.OperatorCreationException
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequest
import org.bouncycastle.pkcs.jcajce.JcaPKCS10CertificationRequestBuilder
import org.bouncycastle.util.IPAddress
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -43,27 +35,15 @@ import javax.net.ssl.SSLException
import javax.net.ssl.SSLPeerUnverifiedException
import javax.net.ssl.SSLSession
import javax.net.ssl.SSLSocket
import java.security.InvalidKeyException
import java.security.KeyPair
import java.security.KeyPairGenerator
import java.security.NoSuchAlgorithmException
import java.security.NoSuchProviderException
import java.security.SignatureException
import java.security.*
import java.security.cert.Certificate
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
import java.util.concurrent.Callable
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ExecutionException
import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import java.util.concurrent.*
import java.util.concurrent.atomic.AtomicBoolean
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue
@RunWith(JUnit4.class)
class CertificateUtilsTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(CertificateUtilsTest.class)
@ -80,24 +60,13 @@ class CertificateUtilsTest extends GroovyTestCase {
private static final String ISSUER_DN = "CN=NiFi Test CA,OU=Security,O=Apache,ST=CA,C=US"
private static final List<String> SUBJECT_ALT_NAMES = ["127.0.0.1", "nifi.nifi.apache.org"]
@BeforeClass
@BeforeAll
static void setUpOnce() {
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Before
void setUp() {
super.setUp()
}
@After
void tearDown() {
}
/**
* Generates a public/private RSA keypair using the default key size.
*

View File

@ -19,13 +19,8 @@ package org.apache.nifi.security.util.crypto
import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -36,8 +31,8 @@ import java.security.SecureRandom
import java.security.Security
import static groovy.test.GroovyAssert.shouldFail
import static org.junit.jupiter.api.Assumptions.assumeTrue
@RunWith(JUnit4.class)
class AESKeyedCipherProviderGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(AESKeyedCipherProviderGroovyTest.class)
@ -49,7 +44,7 @@ class AESKeyedCipherProviderGroovyTest {
private static final SecretKey key = new SecretKeySpec(Hex.decodeHex(KEY_HEX as char[]), "AES")
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -58,14 +53,6 @@ class AESKeyedCipherProviderGroovyTest {
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
private static boolean isUnlimitedStrengthCryptoAvailable() {
Cipher.getMaxAllowedKeyLength("AES") > 128
}
@ -127,7 +114,7 @@ class AESKeyedCipherProviderGroovyTest {
@Test
void testGetCipherWithUnlimitedStrengthShouldBeInternallyConsistent() throws Exception {
// Arrange
Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.", isUnlimitedStrengthCryptoAvailable())
assumeTrue(isUnlimitedStrengthCryptoAvailable(), "Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.")
KeyedCipherProvider cipherProvider = new AESKeyedCipherProvider()
final List<Integer> LONG_KEY_LENGTHS = [192, 256]

View File

@ -20,13 +20,10 @@ import org.apache.commons.codec.binary.Base64
import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.Assumptions
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -38,7 +35,6 @@ import java.security.Security
import static groovy.test.GroovyAssert.shouldFail
@RunWith(JUnit4.class)
class Argon2CipherProviderGroovyTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(Argon2CipherProviderGroovyTest.class)
@ -53,7 +49,7 @@ class Argon2CipherProviderGroovyTest extends GroovyTestCase {
RandomIVPBECipherProvider cipherProvider
private final IntRange FULL_SALT_LENGTH_RANGE= (49..53)
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -70,17 +66,12 @@ class Argon2CipherProviderGroovyTest extends GroovyTestCase {
}
}
@Before
@BeforeEach
void setUp() throws Exception {
// Very fast parameters to test for correctness rather than production values
cipherProvider = new Argon2CipherProvider(1024, 1, 3)
}
@After
void tearDown() throws Exception {
}
@Test
void testGetCipherShouldBeInternallyConsistent() throws Exception {
// Arrange
@ -234,8 +225,8 @@ class Argon2CipherProviderGroovyTest extends GroovyTestCase {
@Test
void testGetCipherWithUnlimitedStrengthShouldBeInternallyConsistent() throws Exception {
// Arrange
Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.",
CipherUtility.isUnlimitedStrengthCryptoSupported())
Assumptions.assumeTrue(CipherUtility.isUnlimitedStrengthCryptoSupported(),
"Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.")
final String PASSWORD = "shortPassword"
final byte[] SALT = cipherProvider.generateSalt()

View File

@ -18,22 +18,20 @@ package org.apache.nifi.security.util.crypto
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Hex
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.charset.StandardCharsets
import java.security.Security
@RunWith(JUnit4.class)
class Argon2SecureHasherTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(Argon2SecureHasherTest.class)
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -46,32 +44,6 @@ class Argon2SecureHasherTest extends GroovyTestCase {
Hex.decode(hex?.replaceAll("[^0-9a-fA-F]", ""))
}
@Ignore("Cannot override static salt")
@Test
void testShouldMatchReferenceVectors() {
// Arrange
int hashLength = 32
int memory = 32
int parallelism = 4
int iterations = 3
logger.info("Generating Argon2 hash for hash length: ${hashLength} B, mem: ${memory} KiB, parallelism: ${parallelism}, iterations: ${iterations}")
Argon2SecureHasher a2sh = new Argon2SecureHasher(hashLength, memory, parallelism, iterations)
// Override the static salt for the published test vector
// a2sh.staticSalt = [0x02] * 16
// Act
byte[] hash = a2sh.hashRaw([0x01] * 32 as byte[])
logger.info("Generated hash: ${Hex.encode(hash)}")
// Assert
assert hash == decodeHex("0d 64 0d f5 8d 78 76 6c 08 c0 37 a3 4a 8b 53 c9 d0 " +
"1e f0 45 2d 75 b6 5e b5 25 20 e9 6b 01 e6 59")
// Clean up
// Argon2SecureHasher.staticSalt = "NiFi Static Salt".bytes
}
@Test
void testShouldBeDeterministicWithStaticSalt() {
// Arrange
@ -297,7 +269,7 @@ class Argon2SecureHasherTest extends GroovyTestCase {
* This test can have the minimum time threshold updated to determine if the performance
* is still sufficient compared to the existing threat model.
*/
@Ignore("Long running test")
@EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true")
@Test
void testDefaultCostParamsShouldBeSufficient() {
// Arrange

View File

@ -21,14 +21,9 @@ import at.favre.lib.crypto.bcrypt.Radix64Encoder
import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -41,8 +36,8 @@ import java.security.Security
import static groovy.test.GroovyAssert.shouldFail
import static org.junit.Assert.assertTrue
import static org.junit.jupiter.api.Assumptions.assumeTrue
@RunWith(JUnit4.class)
class BcryptCipherProviderGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(BcryptCipherProviderGroovyTest.class)
@ -54,7 +49,7 @@ class BcryptCipherProviderGroovyTest {
public static final String MICROBENCHMARK = "microbenchmark"
private static ArrayList<Integer> AES_KEY_LENGTHS
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -71,15 +66,6 @@ class BcryptCipherProviderGroovyTest {
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testGetCipherShouldBeInternallyConsistent() throws Exception {
// Arrange
@ -143,8 +129,8 @@ class BcryptCipherProviderGroovyTest {
@Test
void testGetCipherWithUnlimitedStrengthShouldBeInternallyConsistent() throws Exception {
// Arrange
Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.",
CipherUtility.isUnlimitedStrengthCryptoSupported())
assumeTrue(CipherUtility.isUnlimitedStrengthCryptoSupported(),
"Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.")
RandomIVPBECipherProvider cipherProvider = new BcryptCipherProvider(4)
@ -610,7 +596,7 @@ class BcryptCipherProviderGroovyTest {
assert decryptMsg =~ "The salt must be of the format"
}
@Ignore("This test can be run on a specific machine to evaluate if the default work factor is sufficient")
@Disabled("This test can be run on a specific machine to evaluate if the default work factor is sufficient")
@Test
void testDefaultConstructorShouldProvideStrongWorkFactor() {
// Arrange

View File

@ -18,37 +18,25 @@ package org.apache.nifi.security.util.crypto
import at.favre.lib.crypto.bcrypt.Radix64Encoder
import org.bouncycastle.util.encoders.Hex
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.charset.StandardCharsets
@RunWith(JUnit4.class)
class BcryptSecureHasherTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(BcryptSecureHasher)
@BeforeClass
@BeforeAll
static void setupOnce() throws Exception {
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testShouldBeDeterministicWithStaticSalt() {
// Arrange
@ -263,7 +251,7 @@ class BcryptSecureHasherTest extends GroovyTestCase {
* This test can have the minimum time threshold updated to determine if the performance
* is still sufficient compared to the existing threat model.
*/
@Ignore("Long running test")
@EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true")
@Test
void testDefaultCostParamsShouldBeSufficient() {
// Arrange

View File

@ -18,19 +18,13 @@ package org.apache.nifi.security.util.crypto
import org.apache.nifi.security.util.KeyDerivationFunction
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.security.Security
@RunWith(JUnit4.class)
class CipherProviderFactoryGroovyTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(CipherProviderFactoryGroovyTest.class)
@ -44,7 +38,7 @@ class CipherProviderFactoryGroovyTest extends GroovyTestCase {
(KeyDerivationFunction.ARGON2) : Argon2CipherProvider.class
]
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -53,14 +47,6 @@ class CipherProviderFactoryGroovyTest extends GroovyTestCase {
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testGetCipherProviderShouldResolveRegisteredKDFs() {
// Arrange
@ -75,24 +61,4 @@ class CipherProviderFactoryGroovyTest extends GroovyTestCase {
assert cp.class == (EXPECTED_CIPHER_PROVIDERS.get(kdf))
}
}
@Ignore("Cannot mock enum using Groovy map coercion")
@Test
void testGetCipherProviderShouldHandleUnregisteredKDFs() {
// Arrange
// Can't mock this; see http://stackoverflow.com/questions/5323505/mocking-java-enum-to-add-a-value-to-test-fail-case
KeyDerivationFunction invalidKDF = [name: "Unregistered", description: "Not a registered KDF"] as KeyDerivationFunction
logger.info("Expected: ${invalidKDF.kdfName} -> error")
// Act
def msg = shouldFail(IllegalArgumentException) {
CipherProvider cp = CipherProviderFactory.getCipherProvider(invalidKDF)
logger.info("Resolved: ${invalidKDF.kdfName} -> ${cp.class.simpleName}")
}
logger.expected(msg)
// Assert
assert msg =~ "No cipher provider registered for ${invalidKDF.kdfName}"
}
}

View File

@ -20,18 +20,13 @@ import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.apache.nifi.security.util.KeyDerivationFunction
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.security.Security
@RunWith(JUnit4.class)
class CipherUtilityGroovyTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(CipherUtilityGroovyTest.class)
@ -76,7 +71,7 @@ class CipherUtilityGroovyTest extends GroovyTestCase {
"AES/GCM/NoPadding"]
]
@BeforeClass
@BeforeAll
static void setUpOnce() {
Security.addProvider(new BouncyCastleProvider())
@ -87,16 +82,6 @@ class CipherUtilityGroovyTest extends GroovyTestCase {
logger.info("Mapped algorithms: ${ALGORITHMS_MAPPED_BY_CIPHER}")
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testShouldParseCipherFromAlgorithm() {
// Arrange

View File

@ -18,23 +18,18 @@ package org.apache.nifi.security.util.crypto
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.security.Security
@RunWith(JUnit4.class)
class HashAlgorithmTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(HashAlgorithmTest.class)
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -43,14 +38,6 @@ class HashAlgorithmTest extends GroovyTestCase {
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testDetermineBrokenAlgorithms() throws Exception {
// Arrange

View File

@ -16,18 +16,12 @@
*/
package org.apache.nifi.security.util.crypto
import org.apache.nifi.components.AllowableValue
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Hex
import org.junit.After
import org.junit.AfterClass
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -35,14 +29,10 @@ import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
import java.security.Security
@RunWith(JUnit4.class)
class HashServiceTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(HashServiceTest.class)
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder()
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -51,18 +41,6 @@ class HashServiceTest extends GroovyTestCase {
}
}
@AfterClass
static void tearDownOnce() throws Exception {
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testShouldHashValue() {
// Arrange
@ -393,16 +371,12 @@ class HashServiceTest extends GroovyTestCase {
// No command-line md2sum tool available
def algorithms = HashAlgorithm.values() - HashAlgorithm.MD2
File inputFile = temporaryFolder.newFile()
// Generates a file with "apachenifi" 10 times per line for 10_000 lines (11 bytes * 10 * 10_000 ~= 1 MiB)
if (!inputFile.exists() || inputFile.length() == 0) {
inputFile.createNewFile()
StringBuilder sb = new StringBuilder()
10_000.times { int i ->
inputFile << "${i.toString().padLeft(5)}: ${"apachenifi " * 10}\n"
}
sb.append("${i.toString().padLeft(5)}: ${"apachenifi " * 10}\n")
}
/* These values were generated using command-line tools (openssl dgst -md5, shasum [-a 1 224 256 384 512 512224 512256], rhash --sha3-224, b2sum -l 160)
* Ex: {@code $ openssl dgst -md5 src/test/resources/HashServiceTest/largefile.txt}
*/
@ -428,9 +402,8 @@ class HashServiceTest extends GroovyTestCase {
// Act
def generatedHashes = algorithms.collectEntries { HashAlgorithm algorithm ->
// Get a new InputStream for each iteration, or it will calculate the hash of an empty input on iterations 1 - n
InputStream input = inputFile.newInputStream()
InputStream input = new ByteArrayInputStream(sb.toString().bytes)
String hash = HashService.hashValueStreaming(algorithm, input)
logger.info("${algorithm.getName().padLeft(11)}(${inputFile.path}) [${hash.length() / 2}] = ${hash}")
[(algorithm.name), hash]
}

View File

@ -19,14 +19,9 @@ package org.apache.nifi.security.util.crypto
import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -38,8 +33,8 @@ import javax.crypto.spec.PBEParameterSpec
import java.security.Security
import static org.junit.Assert.fail
import static org.junit.jupiter.api.Assumptions.assumeTrue
@RunWith(JUnit4.class)
class NiFiLegacyCipherProviderGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(NiFiLegacyCipherProviderGroovyTest.class)
@ -51,7 +46,7 @@ class NiFiLegacyCipherProviderGroovyTest {
private static final byte[] SALT_16_BYTES = Hex.decodeHex("aabbccddeeff00112233445566778899".toCharArray())
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -59,15 +54,6 @@ class NiFiLegacyCipherProviderGroovyTest {
limitedStrengthPbeEncryptionMethods = pbeEncryptionMethods.findAll { !it.isUnlimitedStrength() }
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
private static Cipher getLegacyCipher(String password, byte[] salt, String algorithm) {
try {
final PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray())
@ -123,9 +109,6 @@ class NiFiLegacyCipherProviderGroovyTest {
@Test
void testGetCipherWithUnlimitedStrengthShouldBeInternallyConsistent() throws Exception {
// Arrange
Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.",
CipherUtility.isUnlimitedStrengthCryptoSupported())
NiFiLegacyCipherProvider cipherProvider = new NiFiLegacyCipherProvider()
@ -260,7 +243,7 @@ class NiFiLegacyCipherProviderGroovyTest {
* from the password using a long digest result at the time of key length checking.
* @throws IOException
*/
@Ignore("Only needed once to determine max supported password lengths")
@EnabledIfSystemProperty(named = "legacyCipherTest", matches = "true", disabledReason = "Only needed once to determine max supported password lengths")
@Test
void testShouldDetermineDependenceOnUnlimitedStrengthCrypto() throws IOException {
def encryptionMethods = EncryptionMethod.values().findAll { it.algorithm.startsWith("PBE") }

View File

@ -19,13 +19,8 @@ package org.apache.nifi.security.util.crypto
import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -38,8 +33,8 @@ import java.security.Security
import static groovy.test.GroovyAssert.shouldFail
import static org.junit.Assert.fail
import static org.junit.jupiter.api.Assumptions.assumeTrue
@RunWith(JUnit4.class)
class OpenSSLPKCS5CipherProviderGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(OpenSSLPKCS5CipherProviderGroovyTest.class)
@ -49,7 +44,7 @@ class OpenSSLPKCS5CipherProviderGroovyTest {
private static final String PROVIDER_NAME = "BC"
private static final int ITERATION_COUNT = 0
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -57,15 +52,6 @@ class OpenSSLPKCS5CipherProviderGroovyTest {
limitedStrengthPbeEncryptionMethods = pbeEncryptionMethods.findAll { !it.isUnlimitedStrength() }
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
private static Cipher getLegacyCipher(String password, byte[] salt, String algorithm) {
try {
final PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray())
@ -121,8 +107,8 @@ class OpenSSLPKCS5CipherProviderGroovyTest {
@Test
void testGetCipherWithUnlimitedStrengthShouldBeInternallyConsistent() throws Exception {
// Arrange
Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.",
CipherUtility.isUnlimitedStrengthCryptoSupported())
assumeTrue(CipherUtility.isUnlimitedStrengthCryptoSupported(),
"Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.")
OpenSSLPKCS5CipherProvider cipherProvider = new OpenSSLPKCS5CipherProvider()

View File

@ -19,9 +19,10 @@ package org.apache.nifi.security.util.crypto
import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.*
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -30,8 +31,8 @@ import java.security.Security
import static groovy.test.GroovyAssert.shouldFail
import static org.junit.Assert.assertTrue
import static org.junit.jupiter.api.Assumptions.assumeTrue
@RunWith(JUnit4.class)
class PBKDF2CipherProviderGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(PBKDF2CipherProviderGroovyTest.class)
@ -47,7 +48,7 @@ class PBKDF2CipherProviderGroovyTest {
private final String IV_HEX = "01" * 16
private static ArrayList<Integer> AES_KEY_LENGTHS
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -64,15 +65,6 @@ class PBKDF2CipherProviderGroovyTest {
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testGetCipherShouldBeInternallyConsistent() throws Exception {
// Arrange
@ -163,10 +155,6 @@ class PBKDF2CipherProviderGroovyTest {
@Test
void testGetCipherWithUnlimitedStrengthShouldBeInternallyConsistent() throws Exception {
// Arrange
Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.",
CipherUtility.isUnlimitedStrengthCryptoSupported())
RandomIVPBECipherProvider cipherProvider = new PBKDF2CipherProvider(DEFAULT_PRF, TEST_ITERATION_COUNT)
final String PASSWORD = "shortPassword"
@ -468,7 +456,7 @@ class PBKDF2CipherProviderGroovyTest {
}
}
@Ignore("This test can be run on a specific machine to evaluate if the default iteration count is sufficient")
@EnabledIfSystemProperty(named = "nifi.test.unstable", matches = "true")
@Test
void testDefaultConstructorShouldProvideStrongIterationCount() {
// Arrange

View File

@ -18,18 +18,26 @@ package org.apache.nifi.security.util.crypto
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Hex
import org.junit.*
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.charset.StandardCharsets
import java.security.Security
@RunWith(JUnit4.class)
class PBKDF2SecureHasherTest extends GroovyTestCase {
@BeforeClass
private static final Logger logger = LoggerFactory.getLogger(PBKDF2SecureHasherTest)
@BeforeAll
static void setupOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Test
@ -242,7 +250,7 @@ class PBKDF2SecureHasherTest extends GroovyTestCase {
* This test can have the minimum time threshold updated to determine if the performance
* is still sufficient compared to the existing threat model.
*/
@Ignore("Long running test")
@EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true")
@Test
void testDefaultCostParamsShouldBeSufficient() {
// Arrange

View File

@ -21,14 +21,11 @@ import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.EncryptionMethod
import org.apache.nifi.security.util.crypto.scrypt.Scrypt
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -41,8 +38,8 @@ import java.security.Security
import static groovy.test.GroovyAssert.shouldFail
import static org.junit.Assert.assertTrue
import static org.junit.jupiter.api.Assumptions.assumeTrue
@RunWith(JUnit4.class)
class ScryptCipherProviderGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(ScryptCipherProviderGroovyTest.class)
@ -56,7 +53,7 @@ class ScryptCipherProviderGroovyTest {
RandomIVPBECipherProvider cipherProvider
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -73,17 +70,12 @@ class ScryptCipherProviderGroovyTest {
}
}
@Before
@BeforeEach
void setUp() throws Exception {
// Very fast parameters to test for correctness rather than production values
cipherProvider = new ScryptCipherProvider(4, 1, 1)
}
@After
void tearDown() throws Exception {
}
@Test
void testGetCipherShouldBeInternallyConsistent() throws Exception {
// Arrange
@ -143,8 +135,8 @@ class ScryptCipherProviderGroovyTest {
@Test
void testGetCipherWithUnlimitedStrengthShouldBeInternallyConsistent() throws Exception {
// Arrange
Assume.assumeTrue("Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.",
CipherUtility.isUnlimitedStrengthCryptoSupported())
assumeTrue(CipherUtility.isUnlimitedStrengthCryptoSupported(),
"Test is being skipped due to this JVM lacking JCE Unlimited Strength Jurisdiction Policy file.")
final String PASSWORD = "shortPassword"
final byte[] SALT = cipherProvider.generateSalt()
@ -621,7 +613,8 @@ class ScryptCipherProviderGroovyTest {
assert isScryptSalt
}
@Ignore("This test can be run on a specific machine to evaluate if the default parameters are sufficient")
@EnabledIfSystemProperty(named = "nifi.test.unstable", matches = "true",
disabledReason = "This test can be run on a specific machine to evaluate if the default parameters are sufficient")
@Test
void testDefaultConstructorShouldProvideStrongParameters() {
// Arrange

View File

@ -16,15 +16,29 @@
*/
package org.apache.nifi.security.util.crypto
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Hex
import org.junit.*
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.nio.charset.StandardCharsets
import java.security.Security
@RunWith(JUnit4.class)
class ScryptSecureHasherTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(ScryptSecureHasherTest)
@BeforeAll
static void setupOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Test
void testShouldBeDeterministicWithStaticSalt() {
@ -239,7 +253,7 @@ class ScryptSecureHasherTest extends GroovyTestCase {
* This test can have the minimum time threshold updated to determine if the performance
* is still sufficient compared to the existing threat model.
*/
@Ignore("Long running test")
@EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true")
@Test
void testDefaultCostParamsShouldBeSufficient() {
// Arrange

View File

@ -19,14 +19,10 @@ package org.apache.nifi.security.util.scrypt
import org.apache.commons.codec.binary.Hex
import org.apache.nifi.security.util.crypto.scrypt.Scrypt
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIfSystemProperty
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -34,8 +30,8 @@ import java.security.SecureRandom
import java.security.Security
import static groovy.test.GroovyAssert.shouldFail
import static org.junit.jupiter.api.Assumptions.assumeTrue
@RunWith(JUnit4.class)
class ScryptGroovyTest {
private static final Logger logger = LoggerFactory.getLogger(ScryptGroovyTest.class)
@ -50,7 +46,7 @@ class ScryptGroovyTest {
private static final int DK_LEN = 128
private static final long TWO_GIGABYTES = 2048L * 1024 * 1024
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -59,15 +55,6 @@ class ScryptGroovyTest {
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testDeriveScryptKeyShouldBeInternallyConsistent() throws Exception {
// Arrange
@ -150,8 +137,7 @@ class ScryptGroovyTest {
long totalMemory = Runtime.getRuntime().totalMemory()
logger.info("Required memory: ${TWO_GIGABYTES} bytes")
logger.info("Max heap memory: ${totalMemory} bytes")
Assume.assumeTrue("Test is being skipped due to JVM heap size. Please run with -Xmx3072m to set sufficient heap size",
totalMemory >= TWO_GIGABYTES)
assumeTrue(totalMemory >= TWO_GIGABYTES, "Test is being skipped due to JVM heap size. Please run with -Xmx3072m to set sufficient heap size")
// These values are taken from Colin Percival's scrypt paper: https://www.tarsnap.com/scrypt/scrypt.pdf
final byte[] HASH = Hex.decodeHex("2101cb9b6a511aaeaddbbe09cf70f881" +
@ -180,7 +166,7 @@ class ScryptGroovyTest {
assert calculatedHash == HASH
}
@Ignore("This test was just to exercise the heap and debug OOME issues")
@EnabledIfSystemProperty(named = "nifi.test.unstable", matches = "true")
@Test
void testShouldCauseOutOfMemoryError() {
SecureRandom secureRandom = new SecureRandom()

View File

@ -16,12 +16,8 @@
*/
package org.apache.nifi.security.xml
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.xml.sax.SAXParseException
@ -38,27 +34,16 @@ import javax.xml.stream.XMLStreamReader
import static groovy.test.GroovyAssert.shouldFail
@RunWith(JUnit4.class)
class XmlUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(XmlUtilsTest.class)
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
@Test
void testShouldHandleXXEInUnmarshal() {
// Arrange

View File

@ -16,22 +16,17 @@
*/
package org.apache.nifi.security;
import org.apache.nifi.components.ValidationContext;
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.security.xml.XXEValidator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import org.apache.nifi.components.ValidationContext;
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.security.xml.XXEValidator;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class XXEValidatorTest {
private String simpleXMLFile = "src/test/resources/no_xxe.xml";
private String remoteXXEFile = "src/test/resources/remote_xxe_file.xml";
@ -41,21 +36,11 @@ public class XXEValidatorTest {
private String configurationKey = "Configuration Name";
private ValidationContext validationContext;
@BeforeClass
public static void setUpOnce() throws Exception {
}
@Before
@BeforeEach
public void setUp() throws Exception {
validationContext = mock(ValidationContext.class);
}
@After
public void tearDown() throws Exception {
}
@Test
public void testXmlFileWithNoXXEIsValid() {
// Arrange

View File

@ -17,6 +17,12 @@
package org.apache.nifi.security.util;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -32,13 +38,6 @@ import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.UUID;
import org.apache.commons.lang3.StringUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@ -60,7 +59,7 @@ public class KeyStoreUtilsTest {
private static X509Certificate certificate;
private static SecretKey secretKey;
@BeforeClass
@BeforeAll
public static void generateKeysAndCertificates() throws NoSuchAlgorithmException, CertificateException {
keyPair = KeyPairGenerator.getInstance(KEY_ALGORITHM).generateKeyPair();
certificate = CertificateUtils.generateSelfSignedX509Certificate(keyPair, SUBJECT_DN, SIGNING_ALGORITHM, DURATION_DAYS);

View File

@ -16,9 +16,7 @@
*/
package org.apache.nifi.security.util.crypto;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
@ -26,9 +24,6 @@ public class SecureHasherFactoryTest {
private static final Argon2SecureHasher DEFAULT_HASHER = new Argon2SecureHasher();
@Rule
public ExpectedException exceptionRule = ExpectedException.none();
@Test
public void testSecureHasherFactoryArgon2() {
SecureHasher hasher = SecureHasherFactory.getSecureHasher("NIFI_ARGON2_AES_GCM_128");

View File

@ -18,13 +18,10 @@ package org.apache.nifi.properties
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Hex
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
@ -35,7 +32,8 @@ import java.nio.charset.StandardCharsets
import java.security.SecureRandom
import java.security.Security
@RunWith(JUnit4.class)
import static org.junit.Assume.assumeTrue
class AESSensitivePropertyProviderTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(AESSensitivePropertyProviderTest.class)
@ -52,7 +50,7 @@ class AESSensitivePropertyProviderTest extends GroovyTestCase {
private static final Base64.Encoder encoder = Base64.encoder
private static final Base64.Decoder decoder = Base64.decoder
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -61,12 +59,12 @@ class AESSensitivePropertyProviderTest extends GroovyTestCase {
}
}
@Before
@BeforeEach
void setUp() throws Exception {
}
@After
@AfterEach
void tearDown() throws Exception {
}
@ -475,7 +473,7 @@ class AESSensitivePropertyProviderTest extends GroovyTestCase {
@Test
void testShouldDecryptPaddedValue() {
// Arrange
Assume.assumeTrue("JCE unlimited strength crypto policy must be installed for this test", Cipher.getMaxAllowedKeyLength("AES") > 128)
assumeTrue("JCE unlimited strength crypto policy must be installed for this test", Cipher.getMaxAllowedKeyLength("AES") > 128)
final String EXPECTED_VALUE = getKeyOfSize(256) // "thisIsABadKeyPassword"
String cipherText = "aYDkDKys1ENr3gp+||sTBPpMlIvHcOLTGZlfWct8r9RY8BuDlDkoaYmGJ/9m9af9tZIVzcnDwvYQAaIKxRGF7vI2yrY7Xd6x9GTDnWGiGiRXlaP458BBMMgfzH2O8"

View File

@ -17,10 +17,9 @@
package org.apache.nifi.properties;
import org.apache.nifi.properties.configuration.AwsKmsClientProvider;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.internal.util.io.IOUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -32,6 +31,10 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* To run this test, make sure to first configure sensitive credential information as in the following link
* https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html
@ -99,18 +102,18 @@ public class AwsKmsSensitivePropertyProviderIT {
IOUtil.writeText(bootstrapConfText.toString(), mockAWSBootstrapConf.toFile());
}
@BeforeClass
@BeforeAll
public static void initOnce() throws IOException {
initializeBootstrapProperties();
Assert.assertNotNull(props);
assertNotNull(props);
final AwsKmsClientProvider provider = new AwsKmsClientProvider();
final Properties properties = provider.getClientProperties(props).orElse(null);
final KmsClient kmsClient = provider.getClient(properties).orElse(null);
spp = new AwsKmsSensitivePropertyProvider(kmsClient, properties);
Assert.assertNotNull(spp);
assertNotNull(spp);
}
@AfterClass
@AfterAll
public static void tearDownOnce() throws IOException {
Files.deleteIfExists(mockBootstrapConf);
Files.deleteIfExists(mockAWSBootstrapConf);
@ -132,8 +135,8 @@ public class AwsKmsSensitivePropertyProviderIT {
String unprotectedValue = spp.unprotect(protectedValue, ProtectedPropertyContext.defaultContext("property"));
logger.info("Unprotected Value: " + unprotectedValue);
Assert.assertEquals(SAMPLE_PLAINTEXT, unprotectedValue);
Assert.assertNotEquals(SAMPLE_PLAINTEXT, protectedValue);
Assert.assertNotEquals(protectedValue, unprotectedValue);
assertEquals(SAMPLE_PLAINTEXT, unprotectedValue);
assertNotEquals(SAMPLE_PLAINTEXT, protectedValue);
assertNotEquals(protectedValue, unprotectedValue);
}
}

View File

@ -19,9 +19,9 @@ package org.apache.nifi.properties;
import org.apache.commons.io.FilenameUtils;
import org.apache.nifi.util.NiFiProperties;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.internal.util.io.IOUtil;
import java.io.FileOutputStream;
@ -35,12 +35,12 @@ import java.security.Security;
import java.util.Properties;
import java.util.function.Supplier;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StandardSensitivePropertyProviderFactoryTest {
@ -56,7 +56,9 @@ public class StandardSensitivePropertyProviderFactoryTest {
private static Path nifiProperties;
private static String defaultBootstrapContents;
@BeforeClass
private static NiFiProperties niFiProperties;
@BeforeAll
public static void initOnce() throws IOException {
Security.addProvider(new BouncyCastleProvider());
tempConfDir = Files.createTempDirectory("conf");
@ -86,7 +88,7 @@ public class StandardSensitivePropertyProviderFactoryTest {
return bootstrapConf;
}
@AfterClass
@AfterAll
public static void tearDownOnce() throws IOException {
Files.deleteIfExists(bootstrapConf);
Files.deleteIfExists(hashicorpVaultBootstrapConf);

View File

@ -17,8 +17,8 @@
package org.apache.nifi.authentication.single.user.command;
import org.apache.commons.io.FilenameUtils;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
@ -34,14 +34,14 @@ import java.util.UUID;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SetSingleUserCredentialsTest {
private static final Pattern BCRYPT_PATTERN = Pattern.compile("\\$2b\\$12\\$.+");
private static final String PROPERTIES_PATH = "/conf/login.nifi.properties";
@After
@AfterEach
public void clearProperties() {
System.clearProperty(SetSingleUserCredentials.PROPERTIES_FILE_PATH);
}
@ -66,8 +66,8 @@ public class SetSingleUserCredentialsTest {
private void assertProvidersUpdated(final Path providersConfigurationPath, final String username) throws IOException {
final String providersConfiguration = new String(Files.readAllBytes(providersConfigurationPath), StandardCharsets.UTF_8);
assertTrue("Username not found", providersConfiguration.contains(username));
assertTrue("Encoded Password not found", BCRYPT_PATTERN.matcher(providersConfiguration).find());
assertTrue(providersConfiguration.contains(username), "Username not found");
assertTrue(BCRYPT_PATTERN.matcher(providersConfiguration).find(), "Encoded Password not found");
}
private Path getNiFiProperties(final Path providersPath) throws IOException, URISyntaxException {

View File

@ -16,12 +16,12 @@
*/
package org.apache.nifi.authentication.single.user.encoder;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.regex.Pattern;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BCryptPasswordEncoderTest {
@ -31,8 +31,8 @@ public class BCryptPasswordEncoderTest {
public void testEncode() {
final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
final String encoded = encoder.encode(String.class.getSimpleName().toCharArray());
assertNotNull("Encoded Password not found", encoded);
assertTrue("Encoded Password bcrypt hash not found", BCRYPT_PATTERN.matcher(encoded).matches());
assertNotNull(encoded, "Encoded Password not found");
assertTrue(BCRYPT_PATTERN.matcher(encoded).matches(), "Encoded Password bcrypt hash not found");
}
@Test
@ -40,6 +40,6 @@ public class BCryptPasswordEncoderTest {
final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
final char[] password = String.class.getSimpleName().toCharArray();
final String encoded = encoder.encode(password);
assertTrue("Encoded Password not matched", encoder.matches(password, encoded));
assertTrue(encoder.matches(password, encoded), "Encoded Password not matched");
}
}

View File

@ -17,7 +17,7 @@
package org.apache.nifi.authentication.single.user.writer;
import org.apache.nifi.authentication.single.user.SingleUserCredentials;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.net.URISyntaxException;
@ -27,7 +27,7 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.UUID;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class StandardLoginCredentialsWriterTest {
private static final String BLANK_PROVIDERS = "/conf/login-identity-providers.xml";
@ -64,7 +64,7 @@ public class StandardLoginCredentialsWriterTest {
writer.writeLoginCredentials(credentials);
final String configuration = new String(Files.readAllBytes(configuredProvidersPath));
assertTrue("Username not found", configuration.contains(username));
assertTrue("Password not found", configuration.contains(password));
assertTrue(configuration.contains(username), "Username not found");
assertTrue(configuration.contains(password), "Password not found");
}
}

View File

@ -23,19 +23,16 @@ import org.apache.nifi.remote.TransferDirection
import org.apache.nifi.remote.protocol.SiteToSiteTransportProtocol
import org.apache.nifi.remote.util.PeerStatusCache
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.security.Security
import java.util.concurrent.ArrayBlockingQueue
@RunWith(JUnit4.class)
class PeerSelectorTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(PeerSelectorTest.class)
@ -51,7 +48,7 @@ class PeerSelectorTest extends GroovyTestCase {
private static mockPP
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -60,14 +57,14 @@ class PeerSelectorTest extends GroovyTestCase {
}
}
@Before
@BeforeEach
void setUp() {
// Mock collaborators
mockPSP = mockPeerStatusProvider()
mockPP = mockPeerPersistence()
}
@After
@AfterEach
void tearDown() {
}

View File

@ -21,7 +21,7 @@ import org.apache.nifi.remote.protocol.http.HttpProxy;
import org.apache.nifi.remote.util.SiteToSiteRestApiClient;
import org.apache.nifi.web.api.dto.ControllerDTO;
import org.apache.nifi.web.api.dto.PortDTO;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import javax.net.ssl.SSLContext;
import java.io.IOException;
@ -31,11 +31,11 @@ import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
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.eq;
import static org.mockito.Mockito.doAnswer;
@ -190,18 +190,7 @@ public class TestSiteInfoProvider {
return apiClient;
}).when(siteInfoProvider).createSiteToSiteRestApiClient(any(), any());
try {
siteInfoProvider.getSiteToSitePort();
fail();
} catch (IOException e) {
assertThrows(IOException.class, () -> siteInfoProvider.getSiteToSitePort());
assertThrows(IOException.class, () -> siteInfoProvider.getActiveClusterUrl());
}
try {
siteInfoProvider.getActiveClusterUrl();
fail();
} catch (IOException e) {
}
}
}

View File

@ -16,40 +16,7 @@
*/
package org.apache.nifi.remote.client.http;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.LOCATION_HEADER_NAME;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.LOCATION_URI_INTENT_NAME;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.LOCATION_URI_INTENT_VALUE;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.PROTOCOL_VERSION;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.SERVER_SIDE_TRANSACTION_TTL;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.nifi.controller.ScheduledState;
import org.apache.nifi.remote.Peer;
import org.apache.nifi.remote.Transaction;
@ -88,11 +55,13 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.littleshoot.proxy.HttpProxyServer;
import org.littleshoot.proxy.ProxyAuthenticator;
import org.littleshoot.proxy.impl.DefaultHttpProxyServer;
@ -100,6 +69,40 @@ import org.littleshoot.proxy.impl.ThreadPoolConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.LOCATION_HEADER_NAME;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.LOCATION_URI_INTENT_NAME;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.LOCATION_URI_INTENT_VALUE;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.PROTOCOL_VERSION;
import static org.apache.nifi.remote.protocol.http.HttpHeaders.SERVER_SIDE_TRANSACTION_TTL;
import static org.junit.Assert.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class TestHttpClient {
private static final Logger logger = LoggerFactory.getLogger(TestHttpClient.class);
@ -139,11 +142,11 @@ public class TestHttpClient {
controller.setInstanceId("remote-instance-id");
controller.setName("Remote NiFi Flow");
assertNotNull("Test case should set <inputPorts> depending on the test scenario.", inputPorts);
assertNotNull(inputPorts, "Test case should set <inputPorts> depending on the test scenario.");
controller.setInputPorts(inputPorts);
controller.setInputPortCount(inputPorts.size());
assertNotNull("Test case should set <outputPorts> depending on the test scenario.", outputPorts);
assertNotNull(outputPorts, "Test case should set <outputPorts> depending on the test scenario.");
controller.setOutputPorts(outputPorts);
controller.setOutputPortCount(outputPorts.size());
@ -171,10 +174,10 @@ public class TestHttpClient {
final PeersEntity peersEntity = new PeersEntity();
if (req.getLocalPort() == httpConnector.getLocalPort()) {
assertNotNull("Test case should set <peers> depending on the test scenario.", peers);
assertNotNull(peers, "Test case should set <peers> depending on the test scenario.");
peersEntity.setPeers(peers);
} else {
assertNotNull("Test case should set <peersSecure> depending on the test scenario.", peersSecure);
assertNotNull(peersSecure, "Test case should set <peersSecure> depending on the test scenario.");
peersEntity.setPeers(peersSecure);
}
@ -431,7 +434,7 @@ public class TestHttpClient {
out.flush();
}
@BeforeClass
@BeforeAll
public static void setup() throws Exception {
// Create embedded Jetty server
// Use less threads to mitigate Gateway Timeout (504) with proxy test
@ -559,7 +562,7 @@ public class TestHttpClient {
.start();
}
@AfterClass
@AfterAll
public static void teardown() throws Exception {
logger.info("Stopping servers.");
try {
@ -600,7 +603,7 @@ public class TestHttpClient {
}
@Before
@BeforeEach
public void before() throws Exception {
testCaseFinished = new CountDownLatch(1);
@ -678,7 +681,7 @@ public class TestHttpClient {
}
@After
@AfterEach
public void after() throws Exception {
testCaseFinished.countDown();
}
@ -774,15 +777,10 @@ public class TestHttpClient {
.portName("input-unknown")
.build()
) {
try {
client.createTransaction(TransferDirection.SEND);
fail();
} catch (IOException e) {
logger.info("Exception message: {}", e.getMessage());
IOException e = assertThrows(IOException.class, () -> client.createTransaction(TransferDirection.SEND));
assertTrue(e.getMessage().contains("Failed to determine the identifier of port"));
}
}
}
private void testSend(SiteToSiteClient client) throws Exception {
@ -858,7 +856,7 @@ public class TestHttpClient {
.build()
) {
final Transaction transaction = client.createTransaction(TransferDirection.SEND);
assertNull("createTransaction should fail at peer selection and return null.", transaction);
assertNull(transaction, "createTransaction should fail at peer selection and return null.");
}
}
@ -885,15 +883,10 @@ public class TestHttpClient {
.portName("input-access-denied")
.build()
) {
try {
client.createTransaction(TransferDirection.SEND);
fail("Handshake exception should be thrown.");
} catch (HandshakeException e) {
assertThrows(HandshakeException.class, () -> client.createTransaction(TransferDirection.SEND));
}
}
}
@Test
public void testSendSuccessHTTPS() throws Exception {
@ -1112,13 +1105,8 @@ public class TestHttpClient {
}
private void completeShouldFail(Transaction transaction) throws IOException {
try {
transaction.complete();
fail("Complete operation should fail since transaction has already failed.");
} catch (IllegalStateException e) {
logger.info("An exception was thrown as expected.", e);
}
private void completeShouldFail(Transaction transaction) {
assertThrows(IllegalStateException.class, () -> transaction.complete());
}
private void confirmShouldFail(Transaction transaction) throws IOException {
@ -1131,8 +1119,8 @@ public class TestHttpClient {
}
@Test
@DisabledOnOs(OS.WINDOWS)
public void testSendTimeout() throws Exception {
assumeFalse(isWindowsEnvironment());//skip on windows
try (
SiteToSiteClient client = getDefaultBuilder()
.timeout(1, TimeUnit.SECONDS)
@ -1151,26 +1139,17 @@ public class TestHttpClient {
serverChecksum = "1345413116";
transaction.send(packet);
try {
transaction.confirm();
fail();
} catch (IOException e) {
logger.info("An exception was thrown as expected.", e);
IOException e = assertThrows(IOException.class, () -> transaction.confirm());
assertTrue(e.getMessage().contains("TimeoutException"));
}
completeShouldFail(transaction);
}
}
private boolean isWindowsEnvironment() {
return System.getProperty("os.name").toLowerCase().startsWith("windows");
}
@Test
@DisabledOnOs(OS.WINDOWS)
public void testSendTimeoutAfterDataExchange() throws Exception {
assumeFalse(isWindowsEnvironment());//skip on windows
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote.protocol.http.HttpClientTransaction", "INFO");
try (
@ -1197,17 +1176,11 @@ public class TestHttpClient {
}
}
try {
confirmShouldFail(transaction);
fail("Should be timeout.");
} catch (IOException e) {
logger.info("Exception message: {}", e.getMessage());
IOException e = assertThrows(IOException.class, () -> confirmShouldFail(transaction));
assertTrue(e.getMessage().contains("TimeoutException"));
}
completeShouldFail(transaction);
}
}
@Test
@ -1218,15 +1191,10 @@ public class TestHttpClient {
.portName("output-unknown")
.build()
) {
try {
client.createTransaction(TransferDirection.RECEIVE);
fail();
} catch (IOException e) {
logger.info("Exception message: {}", e.getMessage());
IOException e = assertThrows(IOException.class, () -> client.createTransaction(TransferDirection.RECEIVE));
assertTrue(e.getMessage().contains("Failed to determine the identifier of port"));
}
}
}
private void testReceive(SiteToSiteClient client) throws IOException {
final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE);
@ -1361,15 +1329,10 @@ public class TestHttpClient {
.portName("output-timeout")
.build()
) {
try {
client.createTransaction(TransferDirection.RECEIVE);
fail();
} catch (IOException e) {
logger.info("An exception was thrown as expected.", e);
IOException e = assertThrows(IOException.class, () -> client.createTransaction(TransferDirection.RECEIVE));
assertTrue(e instanceof SocketTimeoutException);
}
}
}
@Test
public void testReceiveTimeoutAfterDataExchange() throws Exception {
@ -1387,13 +1350,8 @@ public class TestHttpClient {
assertNotNull(packet);
consumeDataPacket(packet);
try {
transaction.receive();
fail();
} catch (IOException e) {
logger.info("An exception was thrown as expected.", e);
IOException e = assertThrows(IOException.class, () -> transaction.receive());
assertTrue(e.getCause() instanceof SocketTimeoutException);
}
confirmShouldFail(transaction);
completeShouldFail(transaction);

View File

@ -0,0 +1,99 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.remote.client.socket;
import org.apache.nifi.remote.Transaction;
import org.apache.nifi.remote.TransferDirection;
import org.apache.nifi.remote.client.SiteToSiteClient;
import org.apache.nifi.remote.protocol.DataPacket;
import org.apache.nifi.remote.util.StandardDataPacket;
import org.apache.nifi.stream.io.StreamUtils;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class SiteToSiteClientIT {
@Test
public void testReceive() throws IOException {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG");
final SiteToSiteClient client = new SiteToSiteClient.Builder()
.url("http://localhost:8080/nifi")
.portName("cba")
.requestBatchCount(10)
.build();
try {
for (int i = 0; i < 1000; i++) {
final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE);
assertNotNull(transaction);
DataPacket packet;
while (true) {
packet = transaction.receive();
if (packet == null) {
break;
}
final InputStream in = packet.getData();
final long size = packet.getSize();
final byte[] buff = new byte[(int) size];
StreamUtils.fillBuffer(in, buff);
}
transaction.confirm();
transaction.complete();
}
} finally {
client.close();
}
}
@Test
public void testSend() throws IOException {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG");
final SiteToSiteClient client = new SiteToSiteClient.Builder()
.url("http://localhost:8080/nifi")
.portName("input")
.build();
try {
final Transaction transaction = client.createTransaction(TransferDirection.SEND);
assertNotNull(transaction);
final Map<String, String> attrs = new HashMap<>();
attrs.put("site-to-site", "yes, please!");
final byte[] bytes = "Hello".getBytes();
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final DataPacket packet = new StandardDataPacket(attrs, bais, bytes.length);
transaction.send(packet);
transaction.confirm();
transaction.complete();
} finally {
client.close();
}
}
}

View File

@ -20,95 +20,22 @@ import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import org.apache.nifi.components.state.StateManager;
import org.apache.nifi.remote.Transaction;
import org.apache.nifi.remote.TransferDirection;
import org.apache.nifi.remote.client.SiteToSiteClient;
import org.apache.nifi.remote.client.SiteToSiteClientConfig;
import org.apache.nifi.remote.protocol.DataPacket;
import org.apache.nifi.remote.util.StandardDataPacket;
import org.apache.nifi.stream.io.StreamUtils;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
public class TestSiteToSiteClient {
@Test
@Ignore("For local testing only; not really a unit test but a manual test")
public void testReceive() throws IOException {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG");
final SiteToSiteClient client = new SiteToSiteClient.Builder()
.url("http://localhost:8080/nifi")
.portName("cba")
.requestBatchCount(10)
.build();
try {
for (int i = 0; i < 1000; i++) {
final Transaction transaction = client.createTransaction(TransferDirection.RECEIVE);
Assert.assertNotNull(transaction);
DataPacket packet;
while (true) {
packet = transaction.receive();
if (packet == null) {
break;
}
final InputStream in = packet.getData();
final long size = packet.getSize();
final byte[] buff = new byte[(int) size];
StreamUtils.fillBuffer(in, buff);
}
transaction.confirm();
transaction.complete();
}
} finally {
client.close();
}
}
@Test
@Ignore("For local testing only; not really a unit test but a manual test")
public void testSend() throws IOException {
System.setProperty("org.slf4j.simpleLogger.log.org.apache.nifi.remote", "DEBUG");
final SiteToSiteClient client = new SiteToSiteClient.Builder()
.url("http://localhost:8080/nifi")
.portName("input")
.build();
try {
final Transaction transaction = client.createTransaction(TransferDirection.SEND);
Assert.assertNotNull(transaction);
final Map<String, String> attrs = new HashMap<>();
attrs.put("site-to-site", "yes, please!");
final byte[] bytes = "Hello".getBytes();
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final DataPacket packet = new StandardDataPacket(attrs, bais, bytes.length);
transaction.send(packet);
transaction.confirm();
transaction.complete();
} finally {
client.close();
}
}
@Test
public void testSerialization() {
final SiteToSiteClientConfig clientConfig = new SiteToSiteClient.Builder()
@ -132,7 +59,7 @@ public class TestSiteToSiteClient {
try {
SiteToSiteClientConfig clientConfig2 = kryo.readObject(input, SiteToSiteClient.StandardSiteToSiteClientConfig.class);
Assert.assertEquals(clientConfig.getUrls(), clientConfig2.getUrls());
assertEquals(clientConfig.getUrls(), clientConfig2.getUrls());
} finally {
input.close();
}
@ -163,10 +90,10 @@ public class TestSiteToSiteClient {
try {
SiteToSiteClientConfig clientConfig2 = kryo.readObject(input, SiteToSiteClient.StandardSiteToSiteClientConfig.class);
Assert.assertEquals(clientConfig.getUrls(), clientConfig2.getUrls());
assertEquals(clientConfig.getUrls(), clientConfig2.getUrls());
// Serialization works, but the state manager is not serialized.
Assert.assertNotNull(clientConfig.getStateManager());
Assert.assertNull(clientConfig2.getStateManager());
assertNotNull(clientConfig.getStateManager());
assertNull(clientConfig2.getStateManager());
} finally {
input.close();
}
@ -181,8 +108,8 @@ public class TestSiteToSiteClient {
.urls(urls)
.buildConfig();
Assert.assertEquals("http://node1:8080/nifi", config.getUrl());
Assert.assertEquals(urls, config.getUrls());
assertEquals("http://node1:8080/nifi", config.getUrl());
assertEquals(urls, config.getUrls());
}
}

View File

@ -16,22 +16,23 @@
*/
package org.apache.nifi.remote.protocol;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.apache.nifi.remote.Transaction;
import org.apache.nifi.remote.TransactionCompletion;
import org.apache.nifi.remote.util.StandardDataPacket;
import org.apache.nifi.stream.io.StreamUtils;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import org.apache.nifi.remote.Transaction;
import org.apache.nifi.remote.TransactionCompletion;
import org.apache.nifi.remote.util.StandardDataPacket;
import org.apache.nifi.stream.io.StreamUtils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SiteToSiteTestUtils {
public static DataPacket createDataPacket(String contents) {
@ -61,7 +62,7 @@ public class SiteToSiteTestUtils {
TransactionCompletion completion = transaction.complete();
assertEquals(Transaction.TransactionState.TRANSACTION_COMPLETED, transaction.getState());
assertFalse("Should NOT be backoff", completion.isBackoff());
assertFalse(completion.isBackoff(), "Should NOT be backoff");
assertEquals(0, completion.getDataPacketsTransferred());
}
@ -81,7 +82,7 @@ public class SiteToSiteTestUtils {
TransactionCompletion completion = transaction.complete();
assertEquals(Transaction.TransactionState.TRANSACTION_COMPLETED, transaction.getState());
assertFalse("Should NOT be backoff", completion.isBackoff());
assertFalse(completion.isBackoff(), "Should NOT be backoff");
assertEquals(1, completion.getDataPacketsTransferred());
}
@ -104,7 +105,7 @@ public class SiteToSiteTestUtils {
TransactionCompletion completion = transaction.complete();
assertEquals(Transaction.TransactionState.TRANSACTION_COMPLETED, transaction.getState());
assertFalse("Should NOT be backoff", completion.isBackoff());
assertFalse(completion.isBackoff(), "Should NOT be backoff");
assertEquals(2, completion.getDataPacketsTransferred());
}
@ -124,36 +125,18 @@ public class SiteToSiteTestUtils {
packet = transaction.receive();
assertNull(packet);
try {
transaction.confirm();
fail();
} catch (IOException e){
assertTrue(e.getMessage().contains("Received a BadChecksum response"));
IOException io = assertThrows(IOException.class, () -> transaction.confirm());
assertTrue(io.getMessage().contains("Received a BadChecksum response"));
assertEquals(Transaction.TransactionState.ERROR, transaction.getState());
}
try {
transaction.complete();
fail("It's not confirmed.");
} catch (IllegalStateException e){
assertThrows(IllegalStateException.class, () -> transaction.complete());
assertEquals(Transaction.TransactionState.ERROR, transaction.getState());
}
}
public static void execSendZeroFlowFile(Transaction transaction) throws IOException {
assertEquals(Transaction.TransactionState.TRANSACTION_STARTED, transaction.getState());
try {
transaction.confirm();
fail("Nothing has been sent.");
} catch (IllegalStateException e){
}
try {
transaction.complete();
fail("Nothing has been sent.");
} catch (IllegalStateException e){
}
assertThrows(IllegalStateException.class, () -> transaction.confirm());
assertThrows(IllegalStateException.class, () -> transaction.complete());
}
public static void execSendOneFlowFile(Transaction transaction) throws IOException {
@ -167,7 +150,7 @@ public class SiteToSiteTestUtils {
TransactionCompletion completion = transaction.complete();
assertEquals(Transaction.TransactionState.TRANSACTION_COMPLETED, transaction.getState());
assertFalse("Should NOT be backoff", completion.isBackoff());
assertFalse(completion.isBackoff(), "Should NOT be backoff");
assertEquals(1, completion.getDataPacketsTransferred());
}
@ -185,7 +168,7 @@ public class SiteToSiteTestUtils {
TransactionCompletion completion = transaction.complete();
assertEquals(Transaction.TransactionState.TRANSACTION_COMPLETED, transaction.getState());
assertFalse("Should NOT be backoff", completion.isBackoff());
assertFalse(completion.isBackoff(), "Should NOT be backoff");
assertEquals(2, completion.getDataPacketsTransferred());
}
@ -198,22 +181,13 @@ public class SiteToSiteTestUtils {
packet = createDataPacket("contents on client 2");
transaction.send(packet);
try {
transaction.confirm();
fail();
} catch (IOException e){
IOException e = assertThrows(IOException.class, () -> transaction.confirm());
assertTrue(e.getMessage().contains("peer calculated CRC32 Checksum as Different checksum"));
assertEquals(Transaction.TransactionState.ERROR, transaction.getState());
}
try {
transaction.complete();
fail("It's not confirmed.");
} catch (IllegalStateException e){
assertThrows(IllegalStateException.class, () -> transaction.complete());
assertEquals(Transaction.TransactionState.ERROR, transaction.getState());
}
}
public static void execSendButDestinationFull(Transaction transaction) throws IOException {
assertEquals(Transaction.TransactionState.TRANSACTION_STARTED, transaction.getState());
@ -229,7 +203,7 @@ public class SiteToSiteTestUtils {
TransactionCompletion completion = transaction.complete();
assertEquals(Transaction.TransactionState.TRANSACTION_COMPLETED, transaction.getState());
assertTrue("Should be backoff", completion.isBackoff());
assertTrue(completion.isBackoff(), "Should be backoff");
assertEquals(2, completion.getDataPacketsTransferred());
}

View File

@ -16,32 +16,6 @@
*/
package org.apache.nifi.remote.protocol.http;
import static org.apache.nifi.remote.protocol.ResponseCode.CONFIRM_TRANSACTION;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.createDataPacket;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveOneFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveTwoFlowFiles;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveWithInvalidChecksum;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveZeroFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendButDestinationFull;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendOneFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendTwoFlowFiles;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendWithInvalidChecksum;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendZeroFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.readContents;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.nifi.events.EventReporter;
import org.apache.nifi.remote.Peer;
import org.apache.nifi.remote.PeerDescription;
@ -57,12 +31,37 @@ import org.apache.nifi.remote.protocol.ResponseCode;
import org.apache.nifi.remote.util.SiteToSiteRestApiClient;
import org.apache.nifi.reporting.Severity;
import org.apache.nifi.web.api.entity.TransactionResultEntity;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static org.apache.nifi.remote.protocol.ResponseCode.CONFIRM_TRANSACTION;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.createDataPacket;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveOneFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveTwoFlowFiles;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveWithInvalidChecksum;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execReceiveZeroFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendButDestinationFull;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendOneFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendTwoFlowFiles;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendWithInvalidChecksum;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendZeroFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.readContents;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
public class TestHttpClientTransaction {
private Logger logger = LoggerFactory.getLogger(TestHttpClientTransaction.class);
@ -108,7 +107,7 @@ public class TestHttpClientTransaction {
execReceiveZeroFlowFile(transaction);
assertEquals("Client sends nothing as payload to receive flow files.", 0, clientRequest.toByteArray().length);
assertEquals(0, clientRequest.toByteArray().length, "Client sends nothing as payload to receive flow files.");
}
@Test
@ -129,7 +128,7 @@ public class TestHttpClientTransaction {
execReceiveOneFlowFile(transaction);
assertEquals("Client sends nothing as payload to receive flow files.", 0, clientRequest.toByteArray().length);
assertEquals(0, clientRequest.toByteArray().length, "Client sends nothing as payload to receive flow files.");
verify(apiClient).commitReceivingFlowFiles(transactionUrl, CONFIRM_TRANSACTION, "3680976076");
}
@ -152,7 +151,7 @@ public class TestHttpClientTransaction {
execReceiveTwoFlowFiles(transaction);
assertEquals("Client sends nothing as payload to receive flow files.", 0, clientRequest.toByteArray().length);
assertEquals(0, clientRequest.toByteArray().length, "Client sends nothing as payload to receive flow files.");
verify(apiClient).commitReceivingFlowFiles(transactionUrl, CONFIRM_TRANSACTION, "2969091230");
}
@ -176,7 +175,7 @@ public class TestHttpClientTransaction {
execReceiveWithInvalidChecksum(transaction);
assertEquals("Client sends nothing as payload to receive flow files.", 0, clientRequest.toByteArray().length);
assertEquals(0, clientRequest.toByteArray().length, "Client sends nothing as payload to receive flow files.");
verify(apiClient).commitReceivingFlowFiles(transactionUrl, CONFIRM_TRANSACTION, "2969091230");
}
@ -194,7 +193,7 @@ public class TestHttpClientTransaction {
execSendZeroFlowFile(transaction);
assertEquals("Client didn't send anything", 0, clientRequest.toByteArray().length);
assertEquals(0, clientRequest.toByteArray().length, "Client didn't send anything");
}
@Test
@ -204,13 +203,10 @@ public class TestHttpClientTransaction {
final String transactionUrl = "http://www.example.com/data-transfer/input-ports/portId/transactions/transactionId";
doNothing().when(apiClient).openConnectionForSend(eq(transactionUrl), any(Peer.class));
// Emulate that server returns correct checksum.
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
doAnswer(invocation -> {
HttpCommunicationsSession commSession = (HttpCommunicationsSession)invocation.getArguments()[0];
commSession.setChecksum("2946083981");
return null;
}
}).when(apiClient).finishTransferFlowFiles(any(CommunicationsSession.class));
TransactionResultEntity resultEntity = new TransactionResultEntity();
resultEntity.setResponseCode(ResponseCode.TRANSACTION_FINISHED.getCode());
@ -238,13 +234,10 @@ public class TestHttpClientTransaction {
final String transactionUrl = "http://www.example.com/data-transfer/input-ports/portId/transactions/transactionId";
doNothing().when(apiClient).openConnectionForSend(eq("portId"), any(Peer.class));
// Emulate that server returns correct checksum.
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
doAnswer(invocation -> {
HttpCommunicationsSession commSession = (HttpCommunicationsSession)invocation.getArguments()[0];
commSession.setChecksum("3359812065");
return null;
}
}).when(apiClient).finishTransferFlowFiles(any(CommunicationsSession.class));
TransactionResultEntity resultEntity = new TransactionResultEntity();
resultEntity.setResponseCode(ResponseCode.TRANSACTION_FINISHED.getCode());
@ -273,21 +266,15 @@ public class TestHttpClientTransaction {
final String transactionUrl = "http://www.example.com/data-transfer/input-ports/portId/transactions/transactionId";
doNothing().when(apiClient).openConnectionForSend(eq(transactionUrl), any(Peer.class));
// Emulate that server returns incorrect checksum.
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
doAnswer(invocation -> {
HttpCommunicationsSession commSession = (HttpCommunicationsSession)invocation.getArguments()[0];
commSession.setChecksum("Different checksum");
return null;
}
}).when(apiClient).finishTransferFlowFiles(any(CommunicationsSession.class));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
doAnswer(invocation -> {
TransactionResultEntity serverResult = new TransactionResultEntity();
serverResult.setResponseCode(ResponseCode.CANCEL_TRANSACTION.getCode());
return serverResult;
}
}).when(apiClient).commitTransferFlowFiles(eq(transactionUrl), eq(ResponseCode.BAD_CHECKSUM));
ByteArrayOutputStream serverResponseBos = new ByteArrayOutputStream();
@ -314,13 +301,10 @@ public class TestHttpClientTransaction {
final String transactionUrl = "http://www.example.com/data-transfer/input-ports/portId/transactions/transactionId";
doNothing().when(apiClient).openConnectionForSend(eq("portId"), any(Peer.class));
// Emulate that server returns correct checksum.
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
doAnswer(invocation -> {
HttpCommunicationsSession commSession = (HttpCommunicationsSession)invocation.getArguments()[0];
commSession.setChecksum("3359812065");
return null;
}
}).when(apiClient).finishTransferFlowFiles(any(CommunicationsSession.class));
TransactionResultEntity resultEntity = new TransactionResultEntity();
resultEntity.setResponseCode(ResponseCode.TRANSACTION_FINISHED_BUT_DESTINATION_FULL.getCode());

View File

@ -30,7 +30,7 @@ import org.apache.nifi.remote.protocol.DataPacket;
import org.apache.nifi.remote.protocol.RequestType;
import org.apache.nifi.remote.protocol.Response;
import org.apache.nifi.remote.protocol.ResponseCode;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -51,7 +51,7 @@ import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendTwoFlo
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendWithInvalidChecksum;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.execSendZeroFlowFile;
import static org.apache.nifi.remote.protocol.SiteToSiteTestUtils.readContents;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -124,7 +124,7 @@ public class TestSocketClientTransaction {
assertEquals(RequestType.RECEIVE_FLOWFILES, RequestType.readRequestType(sentByClient));
Response confirmResponse = Response.read(sentByClient);
assertEquals(ResponseCode.CONFIRM_TRANSACTION, confirmResponse.getCode());
assertEquals("Checksum should be calculated at client", "3680976076", confirmResponse.getMessage());
assertEquals( "3680976076", confirmResponse.getMessage(), "Checksum should be calculated at client");
Response completeResponse = Response.read(sentByClient);
assertEquals(ResponseCode.TRANSACTION_FINISHED, completeResponse.getCode());
assertEquals(-1, sentByClient.read());
@ -157,7 +157,7 @@ public class TestSocketClientTransaction {
assertEquals(RequestType.RECEIVE_FLOWFILES, RequestType.readRequestType(sentByClient));
Response confirmResponse = Response.read(sentByClient);
assertEquals(ResponseCode.CONFIRM_TRANSACTION, confirmResponse.getCode());
assertEquals("Checksum should be calculated at client", "2969091230", confirmResponse.getMessage());
assertEquals("2969091230", confirmResponse.getMessage(), "Checksum should be calculated at client");
Response completeResponse = Response.read(sentByClient);
assertEquals(ResponseCode.TRANSACTION_FINISHED, completeResponse.getCode());
assertEquals(-1, sentByClient.read());
@ -188,7 +188,7 @@ public class TestSocketClientTransaction {
assertEquals(RequestType.RECEIVE_FLOWFILES, RequestType.readRequestType(sentByClient));
Response confirmResponse = Response.read(sentByClient);
assertEquals(ResponseCode.CONFIRM_TRANSACTION, confirmResponse.getCode());
assertEquals("Checksum should be calculated at client", "2969091230", confirmResponse.getMessage());
assertEquals( "2969091230", confirmResponse.getMessage(), "Checksum should be calculated at client");
assertEquals(-1, sentByClient.read());
}

View File

@ -16,21 +16,21 @@
*/
package org.apache.nifi.remote.util;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Iterator;
import java.util.Set;
import static org.apache.nifi.remote.util.SiteToSiteRestApiClient.parseClusterUrls;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestSiteToSiteRestApiClient {
private static void assertSingleUri(final String expected, final Set<String> urls) {
Assert.assertEquals(1, urls.size());
Assert.assertEquals(expected, urls.iterator().next().toString());
assertEquals(1, urls.size());
assertEquals(expected, urls.iterator().next().toString());
}
@Test
@ -122,57 +122,42 @@ public class TestSiteToSiteRestApiClient {
@Test
public void testGetUrlsEmpty() throws Exception {
try {
parseClusterUrls(null);
fail("Should fail if cluster URL was not specified.");
} catch (IllegalArgumentException e) {
}
assertThrows(IllegalArgumentException.class, () -> parseClusterUrls(null));
try {
parseClusterUrls("");
fail("Should fail if cluster URL was not specified.");
} catch (IllegalArgumentException e) {
}
assertThrows(IllegalArgumentException.class, () -> parseClusterUrls(""));
}
@Test
public void testGetUrlsOne() throws Exception {
final Set<String> urls = parseClusterUrls("http://localhost:8080/nifi");
Assert.assertEquals(1, urls.size());
Assert.assertEquals("http://localhost:8080/nifi-api", urls.iterator().next());
assertEquals(1, urls.size());
assertEquals("http://localhost:8080/nifi-api", urls.iterator().next());
}
@Test
public void testGetUrlsThree() throws Exception {
final Set<String> urls = parseClusterUrls("http://host1:8080/nifi,http://host2:8080/nifi,http://host3:8080/nifi");
Assert.assertEquals(3, urls.size());
assertEquals(3, urls.size());
final Iterator<String> iterator = urls.iterator();
Assert.assertEquals("http://host1:8080/nifi-api", iterator.next());
Assert.assertEquals("http://host2:8080/nifi-api", iterator.next());
Assert.assertEquals("http://host3:8080/nifi-api", iterator.next());
assertEquals("http://host1:8080/nifi-api", iterator.next());
assertEquals("http://host2:8080/nifi-api", iterator.next());
assertEquals("http://host3:8080/nifi-api", iterator.next());
}
@Test
public void testGetUrlsDifferentProtocols() throws Exception {
public void testGetUrlsDifferentProtocols() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> parseClusterUrls("http://host1:8080/nifi,https://host2:8080/nifi,http://host3:8080/nifi"));
try {
parseClusterUrls("http://host1:8080/nifi,https://host2:8080/nifi,http://host3:8080/nifi");
fail("Should fail if cluster URLs contain different protocols.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Different protocols"));
}
assertTrue(exception.getMessage().contains("Different protocols"));
}
@Test
public void testGetUrlsMalformed() throws Exception {
try {
parseClusterUrls("http://host1:8080/nifi,host&2:8080,http://host3:8080/nifi");
fail("Should fail if cluster URLs contain illegal URL.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("malformed"));
}
public void testGetUrlsMalformed() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> parseClusterUrls("http://host1:8080/nifi,host&2:8080,http://host3:8080/nifi"));
assertTrue(exception.getMessage().contains("malformed"));
}
}

View File

@ -16,25 +16,19 @@
*/
package org.apache.nifi.io.socket
import org.apache.nifi.security.util.KeystoreType
import org.apache.nifi.security.util.StandardTlsConfiguration
import org.apache.nifi.security.util.TlsConfiguration
import org.apache.nifi.util.NiFiProperties
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import javax.net.ssl.SSLServerSocket
import java.security.Security
@RunWith(JUnit4.class)
class SocketUtilsTest extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(SocketUtilsTest.class)
@ -65,7 +59,7 @@ class SocketUtilsTest extends GroovyTestCase {
// private static final TlsConfiguration TLS_CONFIGURATION = new StandardTlsConfiguration(KEYSTORE_PATH, KEYSTORE_PASSWORD, KEY_PASSWORD, KEYSTORE_TYPE, TRUSTSTORE_PATH, TRUSTSTORE_PASSWORD, TRUSTSTORE_TYPE, PROTOCOL)
// private static final SSLContext sslContext = SslContextFactory.createSslContext(TLS_CONFIGURATION, ClientAuth.NONE)
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
Security.addProvider(new BouncyCastleProvider())
@ -74,16 +68,6 @@ class SocketUtilsTest extends GroovyTestCase {
}
}
@Before
void setUp() {
}
@After
void tearDown() {
}
@Test
void testCreateSSLServerSocketShouldRestrictTlsProtocols() {
// Arrange

View File

@ -16,6 +16,13 @@
*/
package org.apache.nifi.io.nio.example;
import org.apache.nifi.io.nio.BufferPool;
import org.apache.nifi.io.nio.ChannelListener;
import org.apache.nifi.io.nio.consumer.StreamConsumer;
import org.apache.nifi.io.nio.consumer.StreamConsumerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Calendar;
import java.util.HashSet;
@ -27,14 +34,6 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.apache.nifi.io.nio.BufferPool;
import org.apache.nifi.io.nio.ChannelListener;
import org.apache.nifi.io.nio.consumer.StreamConsumer;
import org.apache.nifi.io.nio.consumer.StreamConsumerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/

View File

@ -16,13 +16,13 @@
*/
package org.apache.nifi.io.nio.example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*/
public class TCPClient {

View File

@ -16,13 +16,13 @@
*/
package org.apache.nifi.io.nio.example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*/
public class UDPClient {

View File

@ -16,11 +16,11 @@
*/
package org.apache.nifi.io.nio.example;
import org.apache.nifi.io.nio.consumer.AbstractStreamConsumer;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.apache.nifi.io.nio.consumer.AbstractStreamConsumer;
/**
*
*/

View File

@ -16,39 +16,23 @@
*/
package org.apache.nifi.util
import org.junit.After
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.concurrent.TimeUnit
@RunWith(JUnit4.class)
class TestFormatUtilsGroovy extends GroovyTestCase {
private static final Logger logger = LoggerFactory.getLogger(TestFormatUtilsGroovy.class)
@BeforeClass
@BeforeAll
static void setUpOnce() throws Exception {
logger.metaClass.methodMissing = { String name, args ->
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
}
}
@Before
void setUp() throws Exception {
}
@After
void tearDown() throws Exception {
}
/**
* New feature test
*/

View File

@ -17,7 +17,7 @@
package org.apache.nifi.processor;
import org.apache.nifi.util.FormatUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.text.DecimalFormatSymbols;
import java.util.concurrent.TimeUnit;

View File

@ -16,7 +16,7 @@
*/
package org.apache.nifi.remote.io;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -24,10 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.apache.nifi.remote.io.CompressionInputStream;
import org.apache.nifi.remote.io.CompressionOutputStream;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class TestCompressionInputOutputStreams {

View File

@ -16,12 +16,15 @@
*/
package org.apache.nifi.stream.io;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import junit.framework.TestCase;
public class ByteCountingInputStreamTest extends TestCase {
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ByteCountingInputStreamTest {
@Test
public void testReset() throws Exception {
final ByteArrayInputStream reader = new ByteArrayInputStream("abcdefghijklmnopqrstuvwxyz".getBytes(StandardCharsets.UTF_8));
@ -53,6 +56,7 @@ public class ByteCountingInputStreamTest extends TestCase {
assertEquals(bytesAtMark, bcis.getBytesRead());
}
@Test
public void testAvailableShouldReturnCorrectCount() throws Exception {
// Arrange
final String ALPHABET = "abcdefghijklmnopqrstuvwxyz";

View File

@ -16,15 +16,21 @@
*/
package org.apache.nifi.stream.io;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import junit.framework.TestCase;
public class LimitingInputStreamTest extends TestCase {
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class LimitingInputStreamTest {
private final static byte[] TEST_BUFFER = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
@Test
public void testReadLimitNotReached() throws IOException {
final LimitingInputStream is = new LimitingInputStream(new ByteArrayInputStream(TEST_BUFFER), 50);
long bytesRead = StreamUtils.copy(is, new ByteArrayOutputStream());
@ -32,6 +38,7 @@ public class LimitingInputStreamTest extends TestCase {
assertFalse(is.hasReachedLimit());
}
@Test
public void testReadLimitMatched() throws IOException {
final LimitingInputStream is = new LimitingInputStream(new ByteArrayInputStream(TEST_BUFFER), 10);
long bytesRead = StreamUtils.copy(is, new ByteArrayOutputStream());
@ -39,11 +46,11 @@ public class LimitingInputStreamTest extends TestCase {
assertTrue(is.hasReachedLimit());
}
@Test
public void testReadLimitExceeded() throws IOException {
final LimitingInputStream is = new LimitingInputStream(new ByteArrayInputStream(TEST_BUFFER), 9);
final long bytesRead = StreamUtils.copy(is, new ByteArrayOutputStream());
assertEquals(bytesRead, 9);
assertTrue(is.hasReachedLimit());
}
}

View File

@ -16,8 +16,9 @@
*/
package org.apache.nifi.stream.io;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@ -26,13 +27,16 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
@Ignore("Tests are time-based")
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Disabled("Tests are time-based")
public class TestLeakyBucketThrottler {
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testOutputStreamInterface() throws IOException {
// throttle rate at 1 MB/sec
final LeakyBucketStreamThrottler throttler = new LeakyBucketStreamThrottler(1024 * 1024);
@ -51,7 +55,8 @@ public class TestLeakyBucketThrottler {
}
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testInputStreamInterface() throws IOException {
final byte[] data = new byte[1024 * 1024 * 4];
@ -75,7 +80,8 @@ public class TestLeakyBucketThrottler {
}
}
@Test(timeout = 10000)
@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testDirectInterface() throws IOException, InterruptedException {
// throttle rate at 1 MB/sec
try (final LeakyBucketStreamThrottler throttler = new LeakyBucketStreamThrottler(1024 * 1024);

View File

@ -16,13 +16,7 @@
*/
package org.apache.nifi.stream.io.util;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -30,39 +24,26 @@ import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
@SuppressWarnings("resource")
public class StreamDemarcatorTest {
@Test
public void validateInitializationFailure() {
try {
new StreamDemarcator(null, null, -1);
fail();
} catch (IllegalArgumentException e) {
// success
}
assertThrows(IllegalArgumentException.class, () ->new StreamDemarcator(null, null, -1));
try {
new StreamDemarcator(mock(InputStream.class), null, -1);
fail();
} catch (IllegalArgumentException e) {
// success
}
assertThrows(IllegalArgumentException.class, () -> new StreamDemarcator(mock(InputStream.class), null, -1));
try {
new StreamDemarcator(mock(InputStream.class), null, 10, -1);
fail();
} catch (IllegalArgumentException e) {
// success
}
assertThrows(IllegalArgumentException.class, () -> new StreamDemarcator(mock(InputStream.class), null, 10, -1));
try {
new StreamDemarcator(mock(InputStream.class), new byte[0], 10, 1);
fail();
} catch (IllegalArgumentException e) {
// success
}
assertThrows(IllegalArgumentException.class, () -> new StreamDemarcator(mock(InputStream.class), new byte[0], 10, 1));
}
@Test
@ -229,13 +210,13 @@ public class StreamDemarcatorTest {
assertNull(scanner.nextToken());
}
@Test(expected = IOException.class)
@Test
public void validateMaxBufferSize() throws IOException {
String data = "THIS IS MY TEXT<MY DELIMITER>THIS IS MY NEW TEXT THEN<MY DELIMITER>THIS IS MY NEWEST TEXT";
ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
StreamDemarcator scanner = new StreamDemarcator(is, "<MY DELIMITER>".getBytes(StandardCharsets.UTF_8), 20);
scanner.nextToken();
scanner.nextToken();
assertThrows(IOException.class, () -> scanner.nextToken());
}
@Test

View File

@ -17,8 +17,8 @@
package org.apache.nifi.stream.io.util;
import org.apache.nifi.stream.io.RepeatingInputStream;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -100,8 +100,9 @@ public class TestLineDemarcator {
}
@Test
@Ignore("Intended only for manual testing. While this can take a while to run, it can be very helpful for manual testing before and after a change to the class. However, we don't want this to " +
"run in automated tests because we have no way to compare from one run to another, so it will only slow down automated tests.")
@Disabled("Intended only for manual testing. While this can take a while to run, it can be very helpful for manual testing before " +
"and after a change to the class. However, we don't want this to run in automated tests because we have no way to compare " +
"from one run to another, so it will only slow down automated tests.")
public void testPerformance() throws IOException {
final String lines = "The\nquick\nbrown\nfox\njumped\nover\nthe\nlazy\ndog.\r\n\n";
final byte[] bytes = lines.getBytes(StandardCharsets.UTF_8);

View File

@ -16,32 +16,33 @@
*/
package org.apache.nifi.stream.io.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import org.apache.nifi.stream.io.util.TextLineDemarcator.OffsetInfo;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.nifi.stream.io.util.TextLineDemarcator.OffsetInfo;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
@SuppressWarnings("resource")
public class TextLineDemarcatorTest {
@Test(expected = IllegalArgumentException.class)
@Test
public void nullStream() {
new TextLineDemarcator(null);
assertThrows(IllegalArgumentException.class, () -> new TextLineDemarcator(null));
}
@Test(expected = IllegalArgumentException.class)
@Test
public void illegalBufferSize() {
new TextLineDemarcator(mock(InputStream.class), -234);
assertThrows(IllegalArgumentException.class, () -> new TextLineDemarcator(mock(InputStream.class), -234));
}
@Test

View File

@ -16,7 +16,7 @@
*/
package org.apache.nifi.util;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;

View File

@ -16,10 +16,10 @@
*/
package org.apache.nifi.util;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestNaiveSearchRingBuffer {

View File

@ -16,6 +16,8 @@
*/
package org.apache.nifi.util.file.classloader;
import org.junit.jupiter.api.Test;
import java.io.FilenameFilter;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
@ -24,12 +26,10 @@ import java.nio.file.Paths;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestClassLoaderUtils {
@ -46,25 +46,16 @@ public class TestClassLoaderUtils {
final ClassLoader originalClassLoader = this.getClass().getClassLoader();
ClassLoader customClassLoader = ClassLoaderUtils.getCustomClassLoader(null,originalClassLoader, getJarFilenameFilter());
assertTrue(customClassLoader != null);
try{
customClassLoader.loadClass("TestSuccess");
}catch (ClassNotFoundException cex){
ClassNotFoundException cex = assertThrows(ClassNotFoundException.class, () -> customClassLoader.loadClass("TestSuccess"));
assertTrue(cex.getLocalizedMessage().equals("TestSuccess"));
return;
}
fail("exception did not occur, class should not be found");
}
@Test
public void testGetCustomClassLoaderWithInvalidPath() {
final String jarFilePath = "src/test/resources/FakeTestClassLoaderUtils/TestSuccess.jar";
try {
ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter());
}catch(MalformedURLException mex){
MalformedURLException mex = assertThrows(MalformedURLException.class,
() -> ClassLoaderUtils.getCustomClassLoader(jarFilePath, this.getClass().getClassLoader(), getJarFilenameFilter()));
assertTrue(mex.getLocalizedMessage().equals("Path specified does not exist"));
return;
}
fail("exception did not occur, path should not exist");
}
@Test
@ -99,10 +90,10 @@ public class TestClassLoaderUtils {
assertEquals(1, urls.length);
}
@Test(expected = MalformedURLException.class)
@Test
public void testGetURLsForClasspathWithSomeNonExistentAndNoSuppression() throws MalformedURLException {
final String jarFilePath = "src/test/resources/TestClassLoaderUtils/TestSuccess.jar,src/test/resources/TestClassLoaderUtils/FakeTest.jar";
ClassLoaderUtils.getURLsForClasspath(jarFilePath, null, false);
assertThrows(MalformedURLException.class, () -> ClassLoaderUtils.getURLsForClasspath(jarFilePath, null, false));
}
@Test

View File

@ -16,9 +16,7 @@
*/
package org.apache.nifi.util.file.monitor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.FileOutputStream;
@ -27,7 +25,9 @@ import java.io.OutputStream;
import java.nio.file.Path;
import java.util.UUID;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestCompoundUpdateMonitor {

View File

@ -16,8 +16,7 @@
*/
package org.apache.nifi.util.file.monitor;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
@ -28,7 +27,8 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestSynchronousFileWatcher {

View File

@ -16,15 +16,16 @@
*/
package org.apache.nifi.util.locale;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* Testing of the test suite environment {@link java.util.Locale}. The locales specified
* in ".github/workflows/ci-workflow.yml" are exercised. This test is inert when run in alternate locales.
@ -37,14 +38,14 @@ public class TestLocaleOfTestSuite {
@Test
public void testLocaleCI_EN_AU() {
final Locale locale = Locale.getDefault();
Assume.assumeTrue(locale.toLanguageTag().equals("en-AU"));
assumeTrue(locale.toLanguageTag().equals("en-AU"));
final String runtimeJavaVersion = System.getProperty("java.version");
final boolean isJava8 = Pattern.compile("1\\.8.+").matcher(runtimeJavaVersion).matches();
final String expected = (isJava8 ? "E" : "e"); // tested in Java 8 and Java 11
Assert.assertEquals(expected, DecimalFormatSymbols.getInstance(locale).getExponentSeparator());
Assert.assertEquals("1,000", NumberFormat.getInstance(locale).format(1000));
assertEquals(expected, DecimalFormatSymbols.getInstance(locale).getExponentSeparator());
assertEquals("1,000", NumberFormat.getInstance(locale).format(1000));
}
/**
@ -53,10 +54,10 @@ public class TestLocaleOfTestSuite {
@Test
public void testLocaleCI_JA_JP() {
final Locale locale = Locale.getDefault();
Assume.assumeTrue(locale.toLanguageTag().equals("ja-JP"));
assumeTrue(locale.toLanguageTag().equals("ja-JP"));
Assert.assertEquals("E", DecimalFormatSymbols.getInstance(locale).getExponentSeparator());
Assert.assertEquals("1,000", NumberFormat.getInstance(locale).format(1000));
assertEquals("E", DecimalFormatSymbols.getInstance(locale).getExponentSeparator());
assertEquals("1,000", NumberFormat.getInstance(locale).format(1000));
}
/**
@ -65,9 +66,9 @@ public class TestLocaleOfTestSuite {
@Test
public void testLocaleCI_FR_FR() {
final Locale locale = Locale.getDefault();
Assume.assumeTrue(locale.toLanguageTag().equals("fr-FR"));
assumeTrue(locale.toLanguageTag().equals("fr-FR"));
Assert.assertEquals("E", DecimalFormatSymbols.getInstance(locale).getExponentSeparator());
Assert.assertEquals("1\u00a0000", NumberFormat.getInstance(locale).format(1000));
assertEquals("E", DecimalFormatSymbols.getInstance(locale).getExponentSeparator());
assertEquals("1\u00a0000", NumberFormat.getInstance(locale).format(1000));
}
}

View File

@ -16,12 +16,12 @@
*/
package org.apache.nifi.util.text;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;
import java.util.Map;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestRegexDateTimeMatcher {
@ -63,7 +63,7 @@ public class TestRegexDateTimeMatcher {
final RegexDateTimeMatcher matcher = new RegexDateTimeMatcher.Compiler().compile(entry.getValue());
final boolean matches = matcher.matches(entry.getKey());
assertTrue("Pattern <" + entry.getValue() + "> did not match <" + entry.getKey() + ">", matches);
assertTrue(matches, "Pattern <" + entry.getValue() + "> did not match <" + entry.getKey() + ">");
}
}
}

View File

@ -16,17 +16,17 @@
*/
package org.apache.nifi.util.timebuffer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.nifi.util.RingBuffer;
import org.apache.nifi.util.RingBuffer.ForEachEvaluator;
import org.apache.nifi.util.RingBuffer.IterationDirection;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.nifi.util.RingBuffer;
import org.apache.nifi.util.RingBuffer.ForEachEvaluator;
import org.apache.nifi.util.RingBuffer.IterationDirection;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test;
/**
*

View File

@ -16,12 +16,12 @@
*/
package org.apache.nifi.util.timebuffer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.jupiter.api.Test;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
public class TestTimedBuffer {

View File

@ -16,26 +16,26 @@
*/
package org.apache.nifi.util.validator;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.apache.nifi.components.PropertyValue;
import org.apache.nifi.components.ValidationContext;
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.components.Validator;
import org.apache.nifi.processor.util.StandardValidators;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestStandardValidators {
@Test

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