You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ex...@apache.org on 2026/01/21 02:13:05 UTC
(nifi) branch main updated: NIFI-15422 Added unit tests for property migration of Processors in standard-bundle (#10787)
This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new ad1b681b3b NIFI-15422 Added unit tests for property migration of Processors in standard-bundle (#10787)
ad1b681b3b is described below
commit ad1b681b3bcb83fbf3f48e41560d3e309a6e3dc0
Author: dan-s1 <ds...@gmail.com>
AuthorDate: Tue Jan 20 21:13:00 2026 -0500
NIFI-15422 Added unit tests for property migration of Processors in standard-bundle (#10787)
Signed-off-by: David Handermann <ex...@apache.org>
---
.../standard/AbstractDatabaseFetchProcessor.java | 12 +-
.../nifi/processors/standard/AttributesToJSON.java | 4 +-
.../processors/standard/DeduplicateRecord.java | 2 +-
.../processors/standard/ExtractRecordSchema.java | 2 +-
.../apache/nifi/processors/standard/FetchFTP.java | 1 -
.../nifi/processors/standard/FlattenJson.java | 2 +-
.../nifi/processors/standard/ForkRecord.java | 7 +-
.../processors/standard/GenerateTableFetch.java | 24 +-
.../apache/nifi/processors/standard/GetFTP.java | 1 -
.../processors/standard/HandleHttpRequest.java | 2 +-
.../nifi/processors/standard/ListenUDPRecord.java | 1 -
.../nifi/processors/standard/PartitionRecord.java | 2 +-
.../processors/standard/PutDatabaseRecord.java | 3 +-
.../apache/nifi/processors/standard/PutFTP.java | 1 -
.../nifi/processors/standard/TransformXml.java | 1 -
.../nifi/processors/standard/CountTextTest.java | 40 +-
.../standard/CryptographicHashContentTest.java | 22 +-
.../processors/standard/HandleHttpRequestTest.java | 15 +
.../processors/standard/PutDatabaseRecordTest.java | 33 ++
.../standard/QueryDatabaseTableRecordTest.java | 24 +
.../standard/QueryDatabaseTableTest.java | 24 +
.../processors/standard/TestAttributesToCSV.java | 49 +-
.../processors/standard/TestAttributesToJSON.java | 70 ++-
.../standard/TestCalculateRecordStats.java | 11 +
.../processors/standard/TestDeduplicateRecord.java | 30 +-
.../nifi/processors/standard/TestEnforceOrder.java | 54 +-
.../processors/standard/TestEvaluateXPath.java | 45 +-
.../processors/standard/TestEvaluateXQuery.java | 159 +++---
.../nifi/processors/standard/TestExecuteSQL.java | 27 +
.../processors/standard/TestExecuteSQLRecord.java | 32 +-
.../standard/TestExecuteStreamCommand.java | 12 +-
.../nifi/processors/standard/TestExtractGrok.java | 27 +-
.../standard/TestExtractRecordSchema.java | 27 +-
.../apache/nifi/processors/standard/TestFTP.java | 66 ++-
.../nifi/processors/standard/TestFetchFTP.java | 31 +-
.../nifi/processors/standard/TestFlattenJson.java | 557 +++++++++++----------
.../nifi/processors/standard/TestForkRecord.java | 59 ++-
.../processors/standard/TestGenerateFlowFile.java | 32 +-
.../processors/standard/TestGenerateRecord.java | 32 +-
.../standard/TestGenerateTableFetch.java | 23 +-
.../processors/standard/TestIdentifyMimeType.java | 14 +
.../standard/TestListDatabaseTables.java | 19 +
.../nifi/processors/standard/TestListFile.java | 28 +-
.../nifi/processors/standard/TestListenHTTP.java | 24 +-
.../nifi/processors/standard/TestListenTCP.java | 21 +
.../processors/standard/TestListenUDPRecord.java | 55 +-
.../nifi/processors/standard/TestLogAttribute.java | 43 +-
.../nifi/processors/standard/TestLogMessage.java | 13 +
.../processors/standard/TestLookupAttribute.java | 30 +-
.../nifi/processors/standard/TestLookupRecord.java | 66 ++-
.../nifi/processors/standard/TestMergeContent.java | 20 +-
.../nifi/processors/standard/TestMergeRecord.java | 35 +-
.../nifi/processors/standard/TestNotify.java | 20 +-
.../processors/standard/TestPackageFlowFile.java | 11 +
.../processors/standard/TestParseSyslog5424.java | 34 +-
.../processors/standard/TestPartitionRecord.java | 21 +-
.../nifi/processors/standard/TestPutEmail.java | 31 +-
.../nifi/processors/standard/TestPutRecord.java | 19 +-
.../nifi/processors/standard/TestPutSQL.java | 171 +++----
.../nifi/processors/standard/TestQueryRecord.java | 129 +++--
.../nifi/processors/standard/TestReplaceText.java | 351 ++++++-------
.../processors/standard/TestRetryFlowFile.java | 19 +-
.../nifi/processors/standard/TestSampleRecord.java | 153 ++----
.../nifi/processors/standard/TestTailFile.java | 22 +-
.../nifi/processors/standard/TestTransformXml.java | 75 +--
.../processors/standard/TestUnpackContent.java | 17 +-
.../processors/standard/TestUpdateCounter.java | 44 +-
.../standard/TestUpdateDatabaseTable.java | 24 +
.../nifi/processors/standard/TestValidateCsv.java | 51 +-
.../processors/standard/TestValidateRecord.java | 24 +
.../apache/nifi/processors/standard/TestWait.java | 89 ++--
71 files changed, 1996 insertions(+), 1243 deletions(-)
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java
index 335d51d1c0..6ca9ba1b26 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java
@@ -362,37 +362,37 @@ public abstract class AbstractDatabaseFetchProcessor extends AbstractSessionFact
case INTEGER:
case SMALLINT:
case TINYINT:
- Integer colIntValue = resultSet.getInt(columnIndex);
+ int colIntValue = resultSet.getInt(columnIndex);
Integer maxIntValue = null;
if (maxValueString != null) {
maxIntValue = Integer.valueOf(maxValueString);
}
if (maxIntValue == null || colIntValue > maxIntValue) {
- return colIntValue.toString();
+ return Integer.toString(colIntValue);
}
break;
case BIGINT:
- Long colLongValue = resultSet.getLong(columnIndex);
+ long colLongValue = resultSet.getLong(columnIndex);
Long maxLongValue = null;
if (maxValueString != null) {
maxLongValue = Long.valueOf(maxValueString);
}
if (maxLongValue == null || colLongValue > maxLongValue) {
- return colLongValue.toString();
+ return Long.toString(colLongValue);
}
break;
case FLOAT:
case REAL:
case DOUBLE:
- Double colDoubleValue = resultSet.getDouble(columnIndex);
+ double colDoubleValue = resultSet.getDouble(columnIndex);
Double maxDoubleValue = null;
if (maxValueString != null) {
maxDoubleValue = Double.valueOf(maxValueString);
}
if (maxDoubleValue == null || colDoubleValue > maxDoubleValue) {
- return colDoubleValue.toString();
+ return Double.toString(colDoubleValue);
}
break;
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
index 1cb7d756ec..21ad54d0d9 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AttributesToJSON.java
@@ -213,7 +213,7 @@ public class AttributesToJSON extends AbstractProcessor {
protected Map<String, Object> buildAttributesMapForFlowFile(FlowFile ff, Set<String> attributes, Set<String> attributesToRemove,
boolean nullValForEmptyString, Pattern attPattern) {
Map<String, Object> result;
- //If list of attributes specified get only those attributes. Otherwise write them all
+ //If list of attributes specified get only those attributes. Otherwise, write them all
if (attributes != null || attPattern != null) {
result = new LinkedHashMap<>();
if (attributes != null) {
@@ -246,7 +246,7 @@ public class AttributesToJSON extends AbstractProcessor {
}
private Set<String> buildAtrs(String atrList) {
- //If list of attributes specified get only those attributes. Otherwise write them all
+ //If list of attributes specified get only those attributes. Otherwise, write them all
if (StringUtils.isNotBlank(atrList)) {
String[] ats = StringUtils.split(atrList, AT_LIST_SEPARATOR);
if (ats != null) {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeduplicateRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeduplicateRecord.java
index 674fde8af8..aedb8f8328 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeduplicateRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DeduplicateRecord.java
@@ -420,7 +420,7 @@ public class DeduplicateRecord extends AbstractProcessor {
final RecordSetWriter nonDuplicatesWriter = writerFactory
.createWriter(getLogger(), writerFactory.getSchema(flowFile.getAttributes(), reader.getSchema()), nonDupeStream, nonDuplicatesFlowFile);
final RecordSetWriter duplicatesWriter = writerFactory
- .createWriter(getLogger(), writerFactory.getSchema(flowFile.getAttributes(), reader.getSchema()), dupeStream, duplicatesFlowFile);
+ .createWriter(getLogger(), writerFactory.getSchema(flowFile.getAttributes(), reader.getSchema()), dupeStream, duplicatesFlowFile)
) {
final FilterWrapper filter = getFilter(context);
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractRecordSchema.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractRecordSchema.java
index c8f95bc888..e184f3a5bd 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractRecordSchema.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExtractRecordSchema.java
@@ -132,7 +132,7 @@ public class ExtractRecordSchema extends AbstractProcessor {
} catch (final Exception e) {
getLogger().error("Failed to process {}; will route to failure", flowFile, e);
- // Since we are wrapping the exceptions above there should always be a cause
+ // Since we are wrapping the exceptions above there should always be a cause,
// but it's possible it might not have a message. This handles that by logging
// the name of the class thrown.
Throwable c = e.getCause();
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFTP.java
index c8d2963650..4038c91b44 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFTP.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FetchFTP.java
@@ -115,7 +115,6 @@ public class FetchFTP extends FetchFileTransfer {
@Override
public void migrateProperties(PropertyConfiguration config) {
- super.migrateProperties(config);
FTPTransfer.migrateProxyProperties(config);
config.renameProperty(FTPTransfer.OBSOLETE_UTF8_ENCODING, FTPTransfer.UTF8_ENCODING.getName());
config.renameProperty(OLD_FILE_NOT_FOUND_LOG_LEVEL_PROPERTY_NAME, FILE_NOT_FOUND_LOG_LEVEL.getName());
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
index 428783f028..b85d470ca5 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/FlattenJson.java
@@ -197,7 +197,7 @@ public class FlattenJson extends AbstractProcessor {
final String mode = context.getProperty(FLATTEN_MODE).getValue();
final FlattenMode flattenMode = getFlattenMode(mode);
- final Character separator = context.getProperty(SEPARATOR).evaluateAttributeExpressions(flowFile).getValue().charAt(0);
+ final char separator = context.getProperty(SEPARATOR).evaluateAttributeExpressions(flowFile).getValue().charAt(0);
final String returnType = context.getProperty(RETURN_TYPE).getValue();
final Charset charset = Charset.forName(context.getProperty(CHARACTER_SET).getValue());
final PrintMode printMode = context.getProperty(PRETTY_PRINT).asBoolean() ? PrintMode.PRETTY : PrintMode.MINIMAL;
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ForkRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ForkRecord.java
index 1646182e12..37e41eed35 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ForkRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ForkRecord.java
@@ -340,11 +340,10 @@ public class ForkRecord extends AbstractProcessor {
}
}
- if (!(dataType instanceof ArrayDataType)) {
+ if (!(dataType instanceof ArrayDataType arrayDataType)) {
continue;
}
- final ArrayDataType arrayDataType = (ArrayDataType) dataType;
final DataType elementType = arrayDataType.getElementType();
if (elementType.getFieldType() != RecordFieldType.RECORD) {
@@ -379,7 +378,7 @@ public class ForkRecord extends AbstractProcessor {
addParentFieldSchemas(fieldMap, parentField);
} catch (NoSuchElementException e) {
- return; // No parent field, nothing to do
+ return; // No parent field, nothing to do. NOTE: A return statement is needed to ensure this method does not recurse infinitely.
}
}
@@ -479,7 +478,7 @@ public class ForkRecord extends AbstractProcessor {
// recursive call
recursivelyAddParentFields(recordToWrite, parentField);
} catch (NoSuchElementException e) {
- return;
+ return; // NOTE: A return statement is needed to ensure this method does not recurse infinitely.
}
}
});
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateTableFetch.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateTableFetch.java
index 17e8135576..b96429f4bf 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateTableFetch.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateTableFetch.java
@@ -83,16 +83,18 @@ import java.util.stream.IntStream;
@InputRequirement(Requirement.INPUT_ALLOWED)
@Tags({"sql", "select", "jdbc", "query", "database", "fetch", "generate"})
@SeeAlso({QueryDatabaseTable.class, ExecuteSQL.class, ListDatabaseTables.class})
-@CapabilityDescription("Generates SQL select queries that fetch \"pages\" of rows from a table. The partition size property, along with the table's row count, "
- + "determine the size and number of pages and generated FlowFiles. In addition, incremental fetching can be achieved by setting Maximum-Value Columns, "
- + "which causes the processor to track the columns' maximum values, thus only fetching rows whose columns' values exceed the observed maximums. This "
- + "processor is intended to be run on the Primary Node only.\n\n"
- + "This processor can accept incoming connections; the behavior of the processor is different whether incoming connections are provided:\n"
- + " - If no incoming connection(s) are specified, the processor will generate SQL queries on the specified processor schedule. Expression Language is supported for many "
- + "fields, but no FlowFile attributes are available. However the properties will be evaluated using the Environment/System properties.\n"
- + " - If incoming connection(s) are specified and no FlowFile is available to a processor task, no work will be performed.\n"
- + " - If incoming connection(s) are specified and a FlowFile is available to a processor task, the FlowFile's attributes may be used in Expression Language for such fields "
- + "as Table Name and others. However, the Max-Value Columns and Columns to Return fields must be empty or refer to columns that are available in each specified table.")
+@CapabilityDescription("""
+ Generates SQL select queries that fetch "pages" of rows from a table. The partition size property, along with the table's row count, \
+ determine the size and number of pages and generated FlowFiles. In addition, incremental fetching can be achieved by setting Maximum-Value Columns, \
+ which causes the processor to track the columns' maximum values, thus only fetching rows whose columns' values exceed the observed maximums. This \
+ processor is intended to be run on the Primary Node only.
+
+ This processor can accept incoming connections; the behavior of the processor is different whether incoming connections are provided:
+ - If no incoming connection(s) are specified, the processor will generate SQL queries on the specified processor schedule. Expression Language is supported for many \
+ fields, but no FlowFile attributes are available. However the properties will be evaluated using the Environment/System properties.
+ - If incoming connection(s) are specified and no FlowFile is available to a processor task, no work will be performed.
+ - If incoming connection(s) are specified and a FlowFile is available to a processor task, the FlowFile's attributes may be used in Expression Language for such fields \
+ as Table Name and others. However, the Max-Value Columns and Columns to Return fields must be empty or refer to columns that are available in each specified table.""")
@Stateful(scopes = Scope.CLUSTER, description = "After performing a query on the specified table, the maximum values for "
+ "the specified column(s) will be retained for use in future executions of the query. This allows the Processor "
+ "to fetch only those records that have max values greater than the retained values. This can be used for "
@@ -253,7 +255,7 @@ public class GenerateTableFetch extends AbstractDatabaseFetchProcessor {
@Override
public void onTrigger(final ProcessContext context, final ProcessSessionFactory sessionFactory) throws ProcessException {
- // Fetch the column/table info once (if the table name and max value columns are not dynamic). Otherwise do the setup later
+ // Fetch the column/table info once (if the table name and max value columns are not dynamic). Otherwise, do the setup later
if (!isDynamicTableName && !isDynamicMaxValues && !setupComplete.get()) {
super.setup(context);
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java
index 497f6f90c6..4d901ea80e 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFTP.java
@@ -88,7 +88,6 @@ public class GetFTP extends GetFileTransfer {
@Override
public void migrateProperties(PropertyConfiguration config) {
- super.migrateProperties(config);
FTPTransfer.migrateProxyProperties(config);
config.renameProperty(FTPTransfer.OBSOLETE_UTF8_ENCODING, FTPTransfer.UTF8_ENCODING.getName());
config.renameProperty(FTPTransfer.OLD_FOLLOW_SYMLINK_PROPERTY_NAME, FTPTransfer.FOLLOW_SYMLINK.getName());
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java
index 639640694f..6a0af5daf9 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/HandleHttpRequest.java
@@ -855,7 +855,7 @@ public class HandleHttpRequest extends AbstractProcessor implements ListenCompon
}
protected void handleFlowContentStreamingError(final ProcessSession session, final HttpRequestContainer container, final Optional<FlowFile> flowFile, final Exception e) {
- // There may be many reasons which can produce an IOException on the HTTP stream and in some of them, eg.
+ // There may be many reasons which can produce an IOException on the HTTP stream and in some of them, e.g.
// bad requests, the connection to the client is not closed. In order to address also these cases, we try
// and answer with a BAD_REQUEST, which lets the client know that the request has not been correctly
// processed and makes it aware that the connection can be closed.
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenUDPRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenUDPRecord.java
index 289dffdd3a..ce458b0711 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenUDPRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListenUDPRecord.java
@@ -360,7 +360,6 @@ public class ListenUDPRecord extends AbstractListenEventProcessor<StandardEvent>
@Override
public void migrateProperties(PropertyConfiguration config) {
- super.migrateProperties(config);
config.renameProperty("sending-host", SENDING_HOST.getName());
config.renameProperty("sending-host-port", SENDING_HOST_PORT.getName());
config.renameProperty("record-reader", RECORD_READER.getName());
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PartitionRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PartitionRecord.java
index 84203f4e1d..7ef06e9577 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PartitionRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PartitionRecord.java
@@ -417,7 +417,7 @@ public class PartitionRecord extends AbstractProcessor {
}
// There exists a single value that is scalar. Create attribute using the property name as the attribute name
- final String attributeValue = DataTypeUtils.toString(value, (String) null);
+ final String attributeValue = DataTypeUtils.toString(value, null);
attributes.put(entry.getKey(), attributeValue);
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
index 622ef738e9..ba9265bdd0 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
@@ -971,9 +971,8 @@ public class PutDatabaseRecord extends AbstractProcessor {
}
if (targetDataType != null) {
if (sqlType == Types.BLOB || sqlType == Types.BINARY || sqlType == Types.VARBINARY || sqlType == Types.LONGVARBINARY) {
- if (currentValue instanceof Object[]) {
+ if (currentValue instanceof Object[] src) {
// Convert Object[Byte] arrays to byte[]
- Object[] src = (Object[]) currentValue;
if (src.length > 0) {
if (!(src[0] instanceof Byte)) {
throw new IllegalTypeConversionException("Cannot convert value " + currentValue + " to BLOB/BINARY/VARBINARY/LONGVARBINARY");
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFTP.java
index fc950ba078..79f81e0121 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFTP.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutFTP.java
@@ -106,7 +106,6 @@ public class PutFTP extends PutFileTransfer<FTPTransfer> {
@Override
public void migrateProperties(PropertyConfiguration config) {
- super.migrateProperties(config);
FTPTransfer.migrateProxyProperties(config);
config.renameProperty(FTPTransfer.OBSOLETE_UTF8_ENCODING, FTPTransfer.UTF8_ENCODING.getName());
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformXml.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformXml.java
index 23e2e31da7..55e50a395f 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformXml.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/TransformXml.java
@@ -322,7 +322,6 @@ public class TransformXml extends AbstractProcessor {
public void migrateProperties(PropertyConfiguration config) {
config.renameProperty("xslt-controller", XSLT_CONTROLLER.getName());
OBSOLETE_XSLT_CONTROLLER_KEY_PROPERTY_NAMES.forEach(obsoletePropertyName -> config.renameProperty(obsoletePropertyName, XSLT_CONTROLLER_KEY.getName()));
- config.renameProperty("xslt-controller-key", XSLT_CONTROLLER_KEY.getName());
config.renameProperty("indent-output", INDENT_OUTPUT.getName());
config.renameProperty("secure-processing", SECURE_PROCESSING.getName());
config.renameProperty("cache-size", CACHE_SIZE.getName());
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CountTextTest.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CountTextTest.java
index 08014cd968..ac2791565f 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CountTextTest.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CountTextTest.java
@@ -19,6 +19,7 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -72,7 +73,7 @@ public class CountTextTest {
runner.run();
runner.assertAllFlowFilesTransferred(CountText.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).getFirst();
for (final Map.Entry<String, String> entry: expectedValues.entrySet()) {
final String attribute = entry.getKey();
final String expectedValue = entry.getValue();
@@ -116,7 +117,7 @@ public class CountTextTest {
runner.run();
runner.assertAllFlowFilesTransferred(CountText.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).getFirst();
for (final Map.Entry<String, String> entry: expectedValues.entrySet()) {
final String attribute = entry.getKey();
final String expectedValue = entry.getValue();
@@ -148,7 +149,7 @@ public class CountTextTest {
runner.run();
runner.assertAllFlowFilesTransferred(CountText.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(CountText.TEXT_WORD_COUNT, EXPECTED_WORD_COUNT);
}
@@ -176,7 +177,7 @@ public class CountTextTest {
runner.run();
runner.assertAllFlowFilesTransferred(CountText.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).getFirst();
for (final Map.Entry<String, String> entry: expectedValues.entrySet()) {
final String attribute = entry.getKey();
final String expectedValue = entry.getValue();
@@ -187,7 +188,7 @@ public class CountTextTest {
}
@Test
- void testShouldTrackSessionCountersAcrossMultipleFlowfiles() throws IOException, NoSuchFieldException, IllegalAccessException {
+ void testShouldTrackSessionCountersAcrossMultipleFlowfiles() throws IOException {
final Path inputPath = Paths.get("src/test/resources/TestCountText/jabberwocky.txt");
final Map<String, String> expectedValues = new HashMap<>();
@@ -210,7 +211,7 @@ public class CountTextTest {
runner.run();
runner.assertAllFlowFilesTransferred(CountText.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).getFirst();
for (final Map.Entry<String, String> entry: expectedValues.entrySet()) {
final String attribute = entry.getKey();
final String expectedValue = entry.getValue();
@@ -219,10 +220,10 @@ public class CountTextTest {
}
}
- assertEquals(Long.valueOf(expectedValues.get(TLC)) * n, runner.getCounterValue("Lines Counted"));
- assertEquals(Long.valueOf(expectedValues.get(TLNEC)) * n, runner.getCounterValue("Lines (non-empty) Counted"));
- assertEquals(Long.valueOf(expectedValues.get(TWC)) * n, runner.getCounterValue("Words Counted"));
- assertEquals(Long.valueOf(expectedValues.get(TCC)) * n, runner.getCounterValue("Characters Counted"));
+ assertEquals(Long.parseLong(expectedValues.get(TLC)) * n, runner.getCounterValue("Lines Counted"));
+ assertEquals(Long.parseLong(expectedValues.get(TLNEC)) * n, runner.getCounterValue("Lines (non-empty) Counted"));
+ assertEquals(Long.parseLong(expectedValues.get(TWC)) * n, runner.getCounterValue("Words Counted"));
+ assertEquals(Long.parseLong(expectedValues.get(TCC)) * n, runner.getCounterValue("Characters Counted"));
}
@Test
@@ -272,7 +273,7 @@ public class CountTextTest {
runner.run();
runner.assertAllFlowFilesTransferred(CountText.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(CountText.TEXT_WORD_COUNT, EXPECTED_WORD_COUNT);
}
@@ -299,9 +300,24 @@ public class CountTextTest {
runner.run();
runner.assertAllFlowFilesTransferred(CountText.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(CountText.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(CountText.TEXT_WORD_COUNT, EXPECTED_WORD_COUNT);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("text-line-count", CountText.TEXT_LINE_COUNT_PD.getName()),
+ Map.entry("text-line-nonempty-count", CountText.TEXT_LINE_NONEMPTY_COUNT_PD.getName()),
+ Map.entry("text-word-count", CountText.TEXT_WORD_COUNT_PD.getName()),
+ Map.entry("text-character-count", CountText.TEXT_CHARACTER_COUNT_PD.getName()),
+ Map.entry("split-words-on-symbols", CountText.SPLIT_WORDS_ON_SYMBOLS_PD.getName()),
+ Map.entry("character-encoding", CountText.CHARACTER_ENCODING_PD.getName()),
+ Map.entry("ajust-immediately", CountText.ADJUST_IMMEDIATELY.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CryptographicHashContentTest.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CryptographicHashContentTest.java
index 6c00311b56..a10e0d7fde 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CryptographicHashContentTest.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/CryptographicHashContentTest.java
@@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.nifi.processors.standard.hash.HashAlgorithm;
import org.apache.nifi.processors.standard.hash.HashService;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -71,7 +72,7 @@ public class CryptographicHashContentTest {
final List<MockFlowFile> successfulFlowfiles = runner.getFlowFilesForRelationship(CryptographicHashContent.REL_SUCCESS);
// Extract the generated attributes from the flowfile
- MockFlowFile flowFile = successfulFlowfiles.get(0);
+ MockFlowFile flowFile = successfulFlowfiles.getFirst();
String hashAttribute = String.format("content_%s", algorithm.getName());
flowFile.assertAttributeExists(hashAttribute);
flowFile.assertAttributeEquals(hashAttribute, expectedContentHash);
@@ -104,7 +105,7 @@ public class CryptographicHashContentTest {
final List<MockFlowFile> successfulFlowfiles = runner.getFlowFilesForRelationship(CryptographicHashContent.REL_SUCCESS);
// Extract the generated attributes from the flowfile
- MockFlowFile flowFile = successfulFlowfiles.get(0);
+ MockFlowFile flowFile = successfulFlowfiles.getFirst();
String hashAttribute = String.format("content_%s", algorithm.getName());
flowFile.assertAttributeExists(hashAttribute);
@@ -146,7 +147,7 @@ public class CryptographicHashContentTest {
final List<MockFlowFile> successfulFlowfiles = runner.getFlowFilesForRelationship(CryptographicHashContent.REL_SUCCESS);
// Extract the generated attributes from the flowfile
- MockFlowFile flowFile = successfulFlowfiles.get(0);
+ MockFlowFile flowFile = successfulFlowfiles.getFirst();
String hashAttribute = String.format("content_%s", algorithm.getName());
flowFile.assertAttributeExists(hashAttribute);
flowFile.assertAttributeEquals(hashAttribute, expectedContentHash);
@@ -179,7 +180,7 @@ public class CryptographicHashContentTest {
final List<MockFlowFile> successfulFlowfiles = runner.getFlowFilesForRelationship(CryptographicHashContent.REL_SUCCESS);
// Extract the generated attributes from the flowfile
- MockFlowFile flowFile = successfulFlowfiles.get(0);
+ MockFlowFile flowFile = successfulFlowfiles.getFirst();
String hashAttribute = String.format("content_%s", algorithm.getName());
flowFile.assertAttributeExists(hashAttribute);
@@ -216,9 +217,20 @@ public class CryptographicHashContentTest {
final List<MockFlowFile> failedFlowfiles = runner.getFlowFilesForRelationship(CryptographicHashContent.REL_FAILURE);
// Extract the generated attributes from the flowfile
- MockFlowFile flowFile = failedFlowfiles.get(0);
+ MockFlowFile flowFile = failedFlowfiles.getFirst();
String hashAttribute = String.format("content_%s", algorithm.getName());
flowFile.assertAttributeNotExists(hashAttribute);
}
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "fail_when_empty", CryptographicHashContent.FAIL_WHEN_EMPTY.getName(),
+ "hash_algorithm", CryptographicHashContent.HASH_ALGORITHM.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/HandleHttpRequestTest.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/HandleHttpRequestTest.java
index 5ccc1ab2c7..b9815e6062 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/HandleHttpRequestTest.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/HandleHttpRequestTest.java
@@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.http.HttpContextMap;
import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.AfterEach;
@@ -32,6 +33,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
+import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@@ -122,6 +124,19 @@ class HandleHttpRequestTest {
runner.run(1, true, false);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "parameters-to-attributes", HandleHttpRequest.PARAMETERS_TO_ATTRIBUTES.getName(),
+ "container-queue-size", HandleHttpRequest.CONTAINER_QUEUE_SIZE.getName(),
+ "multipart-request-max-size", HandleHttpRequest.MULTIPART_REQUEST_MAX_SIZE.getName(),
+ "multipart-read-buffer-size", HandleHttpRequest.MULTIPART_READ_BUFFER_SIZE.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private URL getUrl() {
final int port = handleHttpRequest.getPort();
final URI uri = URI.create(URL_FORMAT.formatted(port));
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java
index 4478bff83b..d195e5c898 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/PutDatabaseRecordTest.java
@@ -33,7 +33,9 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -2265,6 +2267,37 @@ class PutDatabaseRecordTest extends AbstractDatabaseConnectionServiceTest {
assertTrue(recordError.contains(PutDatabaseRecord.PRE_PROCESSING_SQL.getName()), "Pre-Processing SQL not found in [%s]".formatted(recordError));
}
+ @Test
+ void testMigrateProperties() {
+ runner = TestRunners.newTestRunner(PutDatabaseRecord.class);
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("put-db-record-record-reader", PutDatabaseRecord.RECORD_READER_FACTORY.getName()),
+ Map.entry("db-type", PutDatabaseRecord.DB_TYPE.getName()),
+ Map.entry("put-db-record-statement-type", PutDatabaseRecord.STATEMENT_TYPE.getName()),
+ Map.entry("put-db-record-dcbp-service", PutDatabaseRecord.DBCP_SERVICE.getName()),
+ Map.entry("put-db-record-catalog-name", PutDatabaseRecord.CATALOG_NAME.getName()),
+ Map.entry("put-db-record-schema-name", PutDatabaseRecord.SCHEMA_NAME.getName()),
+ Map.entry("put-db-record-table-name", PutDatabaseRecord.TABLE_NAME.getName()),
+ Map.entry("put-db-record-binary-format", PutDatabaseRecord.BINARY_STRING_FORMAT.getName()),
+ Map.entry("put-db-record-translate-field-names", PutDatabaseRecord.TRANSLATE_FIELD_NAMES.getName()),
+ Map.entry("put-db-record-unmatched-field-behavior", PutDatabaseRecord.UNMATCHED_FIELD_BEHAVIOR.getName()),
+ Map.entry("put-db-record-unmatched-column-behavior", PutDatabaseRecord.UNMATCHED_COLUMN_BEHAVIOR.getName()),
+ Map.entry("put-db-record-update-keys", PutDatabaseRecord.UPDATE_KEYS.getName()),
+ Map.entry("put-db-record-field-containing-sql", PutDatabaseRecord.FIELD_CONTAINING_SQL.getName()),
+ Map.entry("put-db-record-allow-multiple-statements", PutDatabaseRecord.ALLOW_MULTIPLE_STATEMENTS.getName()),
+ Map.entry("put-db-record-quoted-identifiers", PutDatabaseRecord.QUOTE_IDENTIFIERS.getName()),
+ Map.entry("put-db-record-quoted-table-identifiers", PutDatabaseRecord.QUOTE_TABLE_IDENTIFIER.getName()),
+ Map.entry("put-db-record-query-timeout", PutDatabaseRecord.QUERY_TIMEOUT.getName()),
+ Map.entry("table-schema-cache-size", PutDatabaseRecord.TABLE_SCHEMA_CACHE_SIZE.getName()),
+ Map.entry("put-db-record-max-batch-size", PutDatabaseRecord.MAX_BATCH_SIZE.getName()),
+ Map.entry("database-session-autocommit", PutDatabaseRecord.AUTO_COMMIT.getName()),
+ Map.entry(RollbackOnFailure.OLD_ROLLBACK_ON_FAILURE_PROPERTY_NAME, RollbackOnFailure.ROLLBACK_ON_FAILURE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void recreateTable() throws ProcessException {
try (final Connection conn = dbcp.getConnection();
final Statement stmt = conn.createStatement()) {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java
index d01fd32891..cc95b3705a 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableRecordTest.java
@@ -21,6 +21,7 @@ import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.serialization.record.MockRecordWriter;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.db.JdbcProperties;
import org.junit.jupiter.api.AfterEach;
@@ -35,6 +36,7 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -1038,4 +1040,26 @@ class QueryDatabaseTableRecordTest extends AbstractDatabaseConnectionServiceTest
assertThrows(AssertionError.class, runner::run);
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("db-fetch-db-type", AbstractDatabaseFetchProcessor.DB_TYPE.getName()),
+ Map.entry("db-fetch-where-clause", AbstractDatabaseFetchProcessor.WHERE_CLAUSE.getName()),
+ Map.entry("db-fetch-sql-query", AbstractDatabaseFetchProcessor.SQL_QUERY.getName()),
+ Map.entry("qdbt-max-rows", AbstractQueryDatabaseTable.MAX_ROWS_PER_FLOW_FILE.getName()),
+ Map.entry("qdbt-output-batch-size", AbstractQueryDatabaseTable.OUTPUT_BATCH_SIZE.getName()),
+ Map.entry("qdbt-max-frags", AbstractQueryDatabaseTable.MAX_FRAGMENTS.getName()),
+ Map.entry("transaction-isolation-level", AbstractQueryDatabaseTable.TRANS_ISOLATION_LEVEL.getName()),
+ Map.entry("initial-load-strategy", AbstractQueryDatabaseTable.INITIAL_LOAD_STRATEGY.getName()),
+ Map.entry("qdbtr-record-writer", QueryDatabaseTableRecord.RECORD_WRITER_FACTORY.getName()),
+ Map.entry("qdbtr-normalize", QueryDatabaseTableRecord.NORMALIZE_NAMES.getName()),
+ Map.entry(JdbcProperties.OLD_USE_AVRO_LOGICAL_TYPES_PROPERTY_NAME, JdbcProperties.USE_AVRO_LOGICAL_TYPES.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_SCALE_PROPERTY_NAME, JdbcProperties.VARIABLE_REGISTRY_ONLY_DEFAULT_SCALE.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_PRECISION_PROPERTY_NAME, JdbcProperties.VARIABLE_REGISTRY_ONLY_DEFAULT_PRECISION.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
index bac7c75fda..0002781a11 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/QueryDatabaseTableTest.java
@@ -24,7 +24,9 @@ import org.apache.nifi.components.state.Scope;
import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.db.JdbcProperties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -39,6 +41,7 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -1069,6 +1072,27 @@ public class QueryDatabaseTableTest extends AbstractDatabaseConnectionServiceTes
assertThrows(AssertionError.class, runner::run);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("db-fetch-db-type", AbstractDatabaseFetchProcessor.DB_TYPE.getName()),
+ Map.entry("db-fetch-where-clause", AbstractDatabaseFetchProcessor.WHERE_CLAUSE.getName()),
+ Map.entry("db-fetch-sql-query", AbstractDatabaseFetchProcessor.SQL_QUERY.getName()),
+ Map.entry("qdbt-max-rows", AbstractQueryDatabaseTable.MAX_ROWS_PER_FLOW_FILE.getName()),
+ Map.entry("qdbt-output-batch-size", AbstractQueryDatabaseTable.OUTPUT_BATCH_SIZE.getName()),
+ Map.entry("qdbt-max-frags", AbstractQueryDatabaseTable.MAX_FRAGMENTS.getName()),
+ Map.entry("transaction-isolation-level", AbstractQueryDatabaseTable.TRANS_ISOLATION_LEVEL.getName()),
+ Map.entry("initial-load-strategy", AbstractQueryDatabaseTable.INITIAL_LOAD_STRATEGY.getName()),
+ Map.entry(JdbcProperties.OLD_NORMALIZE_NAMES_FOR_AVRO_PROPERTY_NAME, JdbcProperties.NORMALIZE_NAMES_FOR_AVRO.getName()),
+ Map.entry(JdbcProperties.OLD_USE_AVRO_LOGICAL_TYPES_PROPERTY_NAME, JdbcProperties.USE_AVRO_LOGICAL_TYPES.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_SCALE_PROPERTY_NAME, JdbcProperties.VARIABLE_REGISTRY_ONLY_DEFAULT_SCALE.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_PRECISION_PROPERTY_NAME, JdbcProperties.VARIABLE_REGISTRY_ONLY_DEFAULT_PRECISION.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private long getNumberOfRecordsFromStream(InputStream in) throws IOException {
final DatumReader<GenericRecord> datumReader = new GenericDatumReader<>();
try (DataFileStream<GenericRecord> dataFileReader = new DataFileStream<>(in, datumReader)) {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java
index f7cccefe4e..2e38485b7e 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToCSV.java
@@ -19,8 +19,10 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
@@ -46,10 +48,15 @@ public class TestAttributesToCSV {
private static final String OUTPUT_MIME_TYPE = "text/csv";
private static final String SPLIT_REGEX = OUTPUT_SEPARATOR + "(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)";
private static final String newline = System.lineSeparator();
+ private TestRunner testRunner;
+
+ @BeforeEach
+ void setUp() {
+ testRunner = TestRunners.newTestRunner(new AttributesToCSV());
+ }
@Test
public void testAttrListNoCoreNullOffNewAttrToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -70,7 +77,6 @@ public class TestAttributesToCSV {
@Test
public void testAttrListNoCoreNullOffNewAttrToContent() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
//set the destination of the csv string to be an attribute
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -93,7 +99,6 @@ public class TestAttributesToCSV {
@Test
public void testAttrListNoCoreNullOffTwoNewAttrToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -114,7 +119,6 @@ public class TestAttributesToCSV {
@Test
public void testAttrListNoCoreNullTwoNewAttrToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "true");
@@ -135,7 +139,6 @@ public class TestAttributesToCSV {
@Test
public void testNoAttrListNoCoreNullOffToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
//set the destination of the csv string to be an attribute
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -154,7 +157,6 @@ public class TestAttributesToCSV {
@Test
public void testNoAttrListNoCoreNullToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "true");
@@ -173,7 +175,6 @@ public class TestAttributesToCSV {
@Test
public void testNoAttrListCoreNullOffToContent() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_OVERWRITE_CONTENT);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -211,7 +212,6 @@ public class TestAttributesToCSV {
@Test
public void testNoAttrListCoreNullOffToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -247,7 +247,6 @@ public class TestAttributesToCSV {
@Test
public void testNoAttrListNoCoreNullOffToContent() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_OVERWRITE_CONTENT);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -277,13 +276,11 @@ public class TestAttributesToCSV {
assertTrue(contentValues.contains("Malibu Beach"));
assertTrue(contentValues.contains("\"California, US\""));
assertTrue(contentValues.contains("\"This is our family's favorite beach. We highly recommend it. \n\nThanks, Jim\""));
-
}
@Test
public void testAttrListNoCoreNullOffToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_LIST, "beach-name,beach-location,beach-endorsement");
@@ -319,7 +316,6 @@ public class TestAttributesToCSV {
@Test
public void testAttrListCoreNullOffToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_LIST, "beach-name,beach-location,beach-endorsement");
@@ -359,7 +355,6 @@ public class TestAttributesToCSV {
@Test
public void testAttrListNoCoreNullOffOverrideCoreByAttrListToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_LIST, "beach-name,beach-location,beach-endorsement,uuid");
@@ -400,7 +395,6 @@ public class TestAttributesToCSV {
@Test
public void testAttrListFromExpCoreNullOffToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_LIST, "${myAttribs}");
@@ -457,12 +451,10 @@ public class TestAttributesToCSV {
assertTrue(CSVDataValues.contains(flowFile.getAttribute("filename")));
assertTrue(CSVDataValues.contains(flowFile.getAttribute("path")));
assertTrue(CSVDataValues.contains(flowFile.getAttribute("uuid")));
-
}
@Test
public void testAttrListWithCommasInNameFromExpCoreNullOffToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_LIST, "${myAttribs}");
@@ -520,13 +512,11 @@ public class TestAttributesToCSV {
assertTrue(CSVDataValues.contains(flowFile.getAttribute("filename")));
assertTrue(CSVDataValues.contains(flowFile.getAttribute("path")));
assertTrue(CSVDataValues.contains(flowFile.getAttribute("uuid")));
-
}
@Test
public void testAttrListFromExpNoCoreNullOffOverrideCoreByAttrListToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_LIST, "${myAttribs}");
@@ -568,7 +558,6 @@ public class TestAttributesToCSV {
@Test
public void testAttributesRegex() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_REGEX, "${myRegEx}");
@@ -610,7 +599,6 @@ public class TestAttributesToCSV {
@Test
public void testAttributesRegexAndList() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.ATTRIBUTES_REGEX, "${myRegEx}");
@@ -657,7 +645,6 @@ public class TestAttributesToCSV {
@Test
public void testSchemaToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -687,7 +674,6 @@ public class TestAttributesToCSV {
@Test
public void testSchemaToContent() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
//set the destination of the csv string to be an attribute
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_OVERWRITE_CONTENT);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "false");
@@ -720,7 +706,6 @@ public class TestAttributesToCSV {
@Test
public void testSchemaWithCoreAttribuesToAttribute() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_NEW_ATTRIBUTE);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
testRunner.setProperty(AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING, "false");
@@ -752,7 +737,6 @@ public class TestAttributesToCSV {
@Test
public void testSchemaWithCoreAttribuesToContent() {
- final TestRunner testRunner = TestRunners.newTestRunner(new AttributesToCSV());
//set the destination of the csv string to be an attribute
testRunner.setProperty(AttributesToCSV.DESTINATION, OUTPUT_OVERWRITE_CONTENT);
testRunner.setProperty(AttributesToCSV.INCLUDE_CORE_ATTRIBUTES, "true");
@@ -785,8 +769,23 @@ public class TestAttributesToCSV {
assertEquals(contentDataString.split(newline)[0], "beach-name,beach-location,path,filename,uuid");
assertEquals(contentDataString.split(newline)[1], "Malibu Beach,\"California, US\"," + path + "," + filename + "," + uuid);
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("attribute-list", AttributesToCSV.ATTRIBUTES_LIST.getName()),
+ Map.entry("attributes-regex", AttributesToCSV.ATTRIBUTES_REGEX.getName()),
+ Map.entry("destination", AttributesToCSV.DESTINATION.getName()),
+ Map.entry("include-core-attributes", AttributesToCSV.INCLUDE_CORE_ATTRIBUTES.getName()),
+ Map.entry("null-value", AttributesToCSV.NULL_VALUE_FOR_EMPTY_STRING.getName()),
+ Map.entry("include-schema", AttributesToCSV.INCLUDE_SCHEMA.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = testRunner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private List<String> getStrings(String sdata) {
return Arrays.asList(Pattern.compile(SPLIT_REGEX).split(sdata));
}
-
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
index 10a62d7fd6..01af74535d 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestAttributesToJSON.java
@@ -18,14 +18,17 @@
package org.apache.nifi.processors.standard;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -55,10 +58,13 @@ public class TestAttributesToJSON {
private static final String TEST_ATTRIBUTE_KEY = "TestAttribute";
private static final String TEST_ATTRIBUTE_VALUE = "TestValue";
-
private static final ObjectMapper MAPPER = new ObjectMapper();
+ private TestRunner runner;
- private final TestRunner runner = TestRunners.newTestRunner(new AttributesToJSON());
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(AttributesToJSON.class);
+ }
@Test
public void testInvalidUserSuppliedAttributeList() {
@@ -103,11 +109,11 @@ public class TestAttributesToJSON {
runner.assertTransferCount(AttributesToJSON.REL_SUCCESS, 1);
runner.assertTransferCount(AttributesToJSON.REL_FAILURE, 0);
- //Make sure that the value is a true JSON null for the non existing attribute
+ //Make sure that the value is a true JSON null for the non-existing attribute
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
assertNull(val.get(NON_PRESENT_ATTRIBUTE_KEY));
}
@@ -131,11 +137,11 @@ public class TestAttributesToJSON {
runner.assertTransferCount(AttributesToJSON.REL_SUCCESS, 1);
runner.assertTransferCount(AttributesToJSON.REL_FAILURE, 0);
- //Make sure that the value is a true JSON null for the non existing attribute
+ //Make sure that the value is a true JSON null for the non-existing attribute
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
assertEquals(val.get(NON_PRESENT_ATTRIBUTE_KEY), "");
}
@@ -181,7 +187,7 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
assertEquals(TEST_ATTRIBUTE_VALUE, val.get(TEST_ATTRIBUTE_KEY));
}
@@ -224,7 +230,7 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
assertEquals(TEST_ATTRIBUTE_VALUE, val.get(TEST_ATTRIBUTE_KEY));
assertEquals(1, val.size());
}
@@ -250,7 +256,7 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
assertEquals(TEST_ATTRIBUTE_VALUE, val.get(TEST_ATTRIBUTE_KEY));
assertEquals(1, val.size());
}
@@ -276,9 +282,9 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
- //If a Attribute is requested but does not exist then it is placed in the JSON with an empty string
+ //If an Attribute is requested but does not exist then it is placed in the JSON with an empty string
assertEquals("", val.get("NonExistingAttribute"));
assertEquals(1, val.size());
}
@@ -304,7 +310,7 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
assertEquals(TEST_ATTRIBUTE_VALUE, val.get(TEST_ATTRIBUTE_KEY));
assertEquals(TEST_ATTRIBUTE_VALUE, val.get(CoreAttributes.PATH.key()));
assertEquals(2, val.size());
@@ -331,7 +337,7 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, String> val = MAPPER.readValue(json, HashMap.class);
+ Map<String, String> val = MAPPER.readValue(json, new TypeReference<>() { });
assertEquals(TEST_ATTRIBUTE_VALUE, val.get(CoreAttributes.PATH.key()));
assertEquals(1, val.size());
}
@@ -352,7 +358,7 @@ public class TestAttributesToJSON {
runner.assertTransferCount(AttributesToJSON.REL_SUCCESS, 1);
runner.assertTransferCount(AttributesToJSON.REL_FAILURE, 0);
- Map<String, String> val = MAPPER.readValue(runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS).getFirst().toByteArray(), HashMap.class);
+ Map<String, String> val = MAPPER.readValue(runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS).getFirst().toByteArray(), new TypeReference<>() { });
assertEquals(TEST_ATTRIBUTE_VALUE, val.get(TEST_ATTRIBUTE_KEY));
assertEquals(1, val.size());
}
@@ -377,7 +383,7 @@ public class TestAttributesToJSON {
assertEquals(AttributesToJSON.APPLICATION_JSON, flowFile.getAttribute(CoreAttributes.MIME_TYPE.key()));
- Map<String, String> val = MAPPER.readValue(flowFile.toByteArray(), HashMap.class);
+ Map<String, String> val = MAPPER.readValue(flowFile.toByteArray(), new TypeReference<>() { });
assertEquals(3, val.size());
Set<String> coreAttributes = Arrays.stream(CoreAttributes.values()).map(CoreAttributes::key).collect(Collectors.toSet());
val.keySet().forEach(k -> assertTrue(coreAttributes.contains(k)));
@@ -402,7 +408,7 @@ public class TestAttributesToJSON {
assertNull(flowFile.getAttribute(CoreAttributes.MIME_TYPE.key()));
- Map<String, String> val = MAPPER.readValue(flowFile.getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME), HashMap.class);
+ Map<String, String> val = MAPPER.readValue(flowFile.getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME), new TypeReference<>() { });
assertEquals(3, val.size());
Set<String> coreAttributes = Arrays.stream(CoreAttributes.values()).map(CoreAttributes::key).collect(Collectors.toSet());
val.keySet().forEach(k -> assertTrue(coreAttributes.contains(k)));
@@ -431,7 +437,7 @@ public class TestAttributesToJSON {
MockFlowFile flowFile = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS).getFirst();
- Map<String, String> val = MAPPER.readValue(flowFile.getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME), HashMap.class);
+ Map<String, String> val = MAPPER.readValue(flowFile.getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME), new TypeReference<>() { });
assertTrue(val.containsKey("delimited.header.column.1"));
assertTrue(val.containsKey("delimited.header.column.2"));
assertTrue(val.containsKey("delimited.header.column.3"));
@@ -459,7 +465,7 @@ public class TestAttributesToJSON {
List<MockFlowFile> flowFilesForRelationship = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS);
MockFlowFile flowFile = flowFilesForRelationship.getFirst();
assertEquals(AttributesToJSON.APPLICATION_JSON, flowFile.getAttribute(CoreAttributes.MIME_TYPE.key()));
- Map<String, Object> val = MAPPER.readValue(flowFile.toByteArray(), Map.class);
+ Map<String, Object> val = MAPPER.readValue(flowFile.toByteArray(), new TypeReference<>() { });
assertInstanceOf(expectedClass, val.get(TEST_ATTRIBUTE_KEY));
}
@@ -488,7 +494,7 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, Object> val = MAPPER.readValue(json, Map.class);
+ Map<String, Object> val = MAPPER.readValue(json, new TypeReference<>() { });
assertInstanceOf(expectedClass, val.get(TEST_ATTRIBUTE_KEY));
}
@@ -528,17 +534,20 @@ public class TestAttributesToJSON {
String json = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS)
.getFirst().getAttribute(AttributesToJSON.JSON_ATTRIBUTE_NAME);
- Map<String, Object> val = MAPPER.readValue(json, Map.class);
+ Map<String, Object> val = MAPPER.readValue(json, new TypeReference<>() { });
assertInstanceOf(String.class, val.get(TEST_ATTRIBUTE_KEY));
}
@Test
public void testAttributeWithJsonBetweenLeadingAndTrailingSpaces() throws JsonProcessingException {
- final String jsonBetweenLeadingAndTrailingSpaces = "\n{\n" +
- " \"fruit\": \"Apple\",\n" +
- " \"size\": \"Large\",\n" +
- " \"color\": \"Red\"\n" +
- "}\n";
+ final String jsonBetweenLeadingAndTrailingSpaces = """
+
+ {
+ "fruit": "Apple",
+ "size": "Large",
+ "color": "Red"
+ }
+ """;
assertDoesNotThrow(() -> MAPPER.readValue(jsonBetweenLeadingAndTrailingSpaces, Map.class));
runner.setProperty(AttributesToJSON.DESTINATION, AttributesToJSON.DESTINATION_CONTENT);
@@ -553,7 +562,16 @@ public class TestAttributesToJSON {
runner.assertTransferCount(AttributesToJSON.REL_FAILURE, 0);
runner.assertTransferCount(AttributesToJSON.REL_SUCCESS, 1);
MockFlowFile result = runner.getFlowFilesForRelationship(AttributesToJSON.REL_SUCCESS).getFirst();
- Map<String, Object> attributes = MAPPER.readValue(result.getContent(), Map.class);
+ Map<String, Object> attributes = MAPPER.readValue(result.getContent(), new TypeReference<>() { });
assertInstanceOf(Map.class, attributes.get(TEST_ATTRIBUTE_KEY));
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed =
+ Map.of("attributes-to-json-regex", AttributesToJSON.ATTRIBUTES_REGEX.getName());
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCalculateRecordStats.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCalculateRecordStats.java
index e04f3c53e8..f493bc46d0 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCalculateRecordStats.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestCalculateRecordStats.java
@@ -27,6 +27,7 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -188,6 +189,16 @@ public class TestCalculateRecordStats {
commonTest(counts, sports, expectedAttributes);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed =
+ Map.of("record-stats-reader", CalculateRecordStats.RECORD_READER.getName(),
+ "record-stats-limit", CalculateRecordStats.LIMIT.getName());
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void commonTest(Map<String, String> procProperties, List<String> sports, Map<String, String> expectedAttributes) {
int index = 1;
for (final String sport : sports) {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeduplicateRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeduplicateRecord.java
index 1ccc82bf87..0d1a6e6bab 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeduplicateRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestDeduplicateRecord.java
@@ -23,6 +23,7 @@ import org.apache.nifi.serialization.record.MockRecordParser;
import org.apache.nifi.serialization.record.MockRecordWriter;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -39,15 +40,12 @@ public class TestDeduplicateRecord {
private TestRunner runner;
private MockRecordParser reader;
- private MockRecordWriter writer;
@BeforeEach
public void setup() throws InitializationException {
runner = TestRunners.newTestRunner(DeduplicateRecord.class);
-
- // RECORD_READER, RECORD_WRITER
reader = new MockRecordParser();
- writer = new MockRecordWriter("header", false);
+ final MockRecordWriter writer = new MockRecordWriter("header", false);
runner.addControllerService("reader", reader);
runner.enableControllerService(reader);
@@ -367,6 +365,26 @@ public class TestDeduplicateRecord {
doCountTests(0, 1, 1, 1, 1, 3);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("record-reader", DeduplicateRecord.RECORD_READER.getName()),
+ Map.entry("record-writer", DeduplicateRecord.RECORD_WRITER.getName()),
+ Map.entry("deduplication-strategy", DeduplicateRecord.DEDUPLICATION_STRATEGY.getName()),
+ Map.entry("distributed-map-cache", DeduplicateRecord.DISTRIBUTED_MAP_CACHE.getName()),
+ Map.entry("cache-identifier", DeduplicateRecord.CACHE_IDENTIFIER.getName()),
+ Map.entry("put-cache-identifier", DeduplicateRecord.PUT_CACHE_IDENTIFIER.getName()),
+ Map.entry("include-zero-record-flowfiles", DeduplicateRecord.INCLUDE_ZERO_RECORD_FLOWFILES.getName()),
+ Map.entry("record-hashing-algorithm", DeduplicateRecord.RECORD_HASHING_ALGORITHM.getName()),
+ Map.entry("filter-type", DeduplicateRecord.FILTER_TYPE.getName()),
+ Map.entry("filter-capacity-hint", DeduplicateRecord.FILTER_CAPACITY_HINT.getName()),
+ Map.entry("bloom-filter-certainty", DeduplicateRecord.BLOOM_FILTER_FPP.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
void doCountTests(int failure, int original, int duplicates, int notDuplicates, int notDupeCount, int dupeCount) {
runner.assertTransferCount(DeduplicateRecord.REL_FAILURE, failure);
runner.assertTransferCount(DeduplicateRecord.REL_ORIGINAL, original);
@@ -375,12 +393,12 @@ public class TestDeduplicateRecord {
List<MockFlowFile> duplicateFlowFile = runner.getFlowFilesForRelationship(DeduplicateRecord.REL_DUPLICATE);
if (duplicateFlowFile != null) {
- assertEquals(String.valueOf(dupeCount), duplicateFlowFile.get(0).getAttribute(DeduplicateRecord.RECORD_COUNT_ATTRIBUTE));
+ assertEquals(String.valueOf(dupeCount), duplicateFlowFile.getFirst().getAttribute(DeduplicateRecord.RECORD_COUNT_ATTRIBUTE));
}
List<MockFlowFile> nonDuplicateFlowFile = runner.getFlowFilesForRelationship(DeduplicateRecord.REL_NON_DUPLICATE);
if (nonDuplicateFlowFile != null) {
- assertEquals(String.valueOf(notDupeCount), nonDuplicateFlowFile.get(0).getAttribute(DeduplicateRecord.RECORD_COUNT_ATTRIBUTE));
+ assertEquals(String.valueOf(notDupeCount), nonDuplicateFlowFile.getFirst().getAttribute(DeduplicateRecord.RECORD_COUNT_ATTRIBUTE));
}
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java
index f504527c22..ed77ee6b6e 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEnforceOrder.java
@@ -19,8 +19,10 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.components.state.Scope;
import org.apache.nifi.state.MockStateManager;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
@@ -30,11 +32,15 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestEnforceOrder {
+ private TestRunner runner;
+
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(EnforceOrder.class);
+ }
@Test
public void testDefaultPropertyValidation() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
// Default values should not be valid.
runner.assertNotValid();
@@ -45,8 +51,6 @@ public class TestEnforceOrder {
@Test
public void testCustomPropertyValidation() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
// Set required properties.
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.assertValid();
@@ -65,9 +69,25 @@ public class TestEnforceOrder {
runner.assertValid();
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("group-id", EnforceOrder.GROUP_IDENTIFIER.getName()),
+ Map.entry("order-attribute", EnforceOrder.ORDER_ATTRIBUTE.getName()),
+ Map.entry("initial-order", EnforceOrder.INITIAL_ORDER.getName()),
+ Map.entry("maximum-order", EnforceOrder.MAX_ORDER.getName()),
+ Map.entry("wait-timeout", EnforceOrder.WAIT_TIMEOUT.getName()),
+ Map.entry("inactive-timeout", EnforceOrder.INACTIVE_TIMEOUT.getName()),
+ Map.entry("batch-count", EnforceOrder.BATCH_COUNT.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
private static class Ordered {
private final Map<String, String> map = new HashMap<>();
+
private Ordered(final int index) {
map.put("index", String.valueOf(index));
}
@@ -89,15 +109,13 @@ public class TestEnforceOrder {
return map;
}
- private static MockFlowFile enqueue(final TestRunner runner, final String group, final int index) {
- return runner.enqueue(group + "." + index, i(group, index).map());
+ private static void enqueue(final TestRunner runner, final String group, final int index) {
+ runner.enqueue(group + "." + index, i(group, index).map());
}
}
@Test
public void testSort() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.assertValid();
@@ -117,8 +135,6 @@ public class TestEnforceOrder {
@Test
public void testDuplicatedOrder() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "1");
@@ -147,8 +163,6 @@ public class TestEnforceOrder {
@Test
public void testNoGroupIdentifier() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "1");
@@ -173,8 +187,6 @@ public class TestEnforceOrder {
@Test
public void testIllegalOrderValue() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "1");
@@ -200,8 +212,6 @@ public class TestEnforceOrder {
@Test
public void testInitialOrderValue() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "${index.start}");
@@ -244,8 +254,6 @@ public class TestEnforceOrder {
@Test
public void testMaxOrder() {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${fragment.identifier}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "1");
@@ -279,8 +287,6 @@ public class TestEnforceOrder {
@Test
public void testWaitOvertakeSkip() throws Exception {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "1");
@@ -372,13 +378,10 @@ public class TestEnforceOrder {
skipped.get(0).assertAttributeExists(EnforceOrder.ATTR_DETAIL);
skipped.get(1).assertContentEquals("a.4");
skipped.get(1).assertAttributeExists(EnforceOrder.ATTR_DETAIL);
-
}
@Test
public void testCleanInactiveGroups() throws Exception {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "1");
@@ -426,13 +429,10 @@ public class TestEnforceOrder {
runner.assertAllFlowFilesTransferred(EnforceOrder.REL_WAIT, 1);
final List<MockFlowFile> waiting = runner.getFlowFilesForRelationship(EnforceOrder.REL_WAIT);
waiting.getFirst().assertContentEquals("b.2");
-
}
@Test
- public void testClearOldProperties() throws Exception {
- final TestRunner runner = TestRunners.newTestRunner(EnforceOrder.class);
-
+ public void testClearOldProperties() {
runner.setProperty(EnforceOrder.GROUP_IDENTIFIER, "${group}");
runner.setProperty(EnforceOrder.ORDER_ATTRIBUTE, "index");
runner.setProperty(EnforceOrder.INITIAL_ORDER, "1");
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXPath.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXPath.java
index c4cd0141a5..d88ac43e84 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXPath.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXPath.java
@@ -17,15 +17,19 @@
package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -35,9 +39,15 @@ public class TestEvaluateXPath {
private static final Path XML_SNIPPET_EMBEDDED_DOCTYPE = Paths.get("src/test/resources/TestXml/xml-snippet-embedded-doctype.xml");
private static final Path XML_SNIPPET_NONEXISTENT_DOCTYPE = Paths.get("src/test/resources/TestXml/xml-snippet-external-doctype.xml");
+ private TestRunner testRunner;
+
+ @BeforeEach
+ void setUp() {
+ testRunner = TestRunners.newTestRunner(new EvaluateXPath());
+ }
+
@Test
public void testAsAttribute() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_ATTRIBUTE);
testRunner.setProperty("xpath.result1", "/");
testRunner.setProperty("xpath.result2", "/*:bundle/node/subNode/value/text()");
@@ -46,14 +56,13 @@ public class TestEvaluateXPath {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).getFirst();
out.assertAttributeEquals("xpath.result2", "Hello");
assertTrue(out.getAttribute("xpath.result1").contains("Hello"));
}
@Test
public void testCheckIfElementExists() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_ATTRIBUTE);
testRunner.setProperty("xpath.result1", "/");
testRunner.setProperty("xpath.result.exist.1", "boolean(/*:bundle/node)");
@@ -63,7 +72,7 @@ public class TestEvaluateXPath {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).getFirst();
assertTrue(out.getAttribute("xpath.result1").contains("Hello"));
out.assertAttributeEquals("xpath.result.exist.1", "true");
out.assertAttributeEquals("xpath.result.exist.2", "false");
@@ -71,7 +80,6 @@ public class TestEvaluateXPath {
@Test
public void testUnmatched() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty("xpath.result.exist.2", "/*:bundle/node2");
@@ -79,12 +87,11 @@ public class TestEvaluateXPath {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_NO_MATCH, 1);
- testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_NO_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
public void testMultipleXPathForContent() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty(EvaluateXPath.RETURN_TYPE, EvaluateXPath.RETURN_TYPE_AUTO);
testRunner.setProperty("some.property.1", "/*:bundle/node/subNode[1]");
@@ -97,7 +104,6 @@ public class TestEvaluateXPath {
@Test
public void testWriteToContent() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty("some.property", "/*:bundle/node/subNode[1]");
@@ -105,7 +111,7 @@ public class TestEvaluateXPath {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).getFirst();
final byte[] outData = testRunner.getContentAsByteArray(out);
final String outXml = new String(outData, StandardCharsets.UTF_8);
assertTrue(outXml.contains("subNode"));
@@ -114,7 +120,6 @@ public class TestEvaluateXPath {
@Test
public void testFailureIfContentMatchesMultipleNodes() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty("some.property", "/*:bundle/node/subNode");
@@ -126,7 +131,6 @@ public class TestEvaluateXPath {
@Test
public void testWriteStringToContent() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty(EvaluateXPath.RETURN_TYPE, EvaluateXPath.RETURN_TYPE_STRING);
testRunner.setProperty("some.property", "/*:bundle/node/subNode[1]/value/text()");
@@ -135,13 +139,12 @@ public class TestEvaluateXPath {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).getFirst();
out.assertContentEquals("Hello");
}
@Test
public void testWriteNodeSetToAttribute() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_ATTRIBUTE);
testRunner.setProperty(EvaluateXPath.RETURN_TYPE, EvaluateXPath.RETURN_TYPE_NODESET);
testRunner.setProperty("some.property", "/*:bundle/node/subNode[1]");
@@ -150,7 +153,7 @@ public class TestEvaluateXPath {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).getFirst();
final String outXml = out.getAttribute("some.property");
assertTrue(outXml.contains("subNode"));
assertTrue(outXml.contains("Hello"));
@@ -158,7 +161,6 @@ public class TestEvaluateXPath {
@Test
public void testSuccessForEmbeddedDocTypeValidation() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty(EvaluateXPath.RETURN_TYPE, EvaluateXPath.RETURN_TYPE_STRING);
testRunner.setProperty(EvaluateXPath.VALIDATE_DTD, "true");
@@ -168,13 +170,12 @@ public class TestEvaluateXPath {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXPath.REL_MATCH).getFirst();
out.assertContentEquals("Hello");
}
@Test
public void testFailureForEmbeddedDocTypeValidationDisabled() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty(EvaluateXPath.RETURN_TYPE, EvaluateXPath.RETURN_TYPE_STRING);
testRunner.setProperty(EvaluateXPath.VALIDATE_DTD, "false");
@@ -188,7 +189,6 @@ public class TestEvaluateXPath {
@Test
public void testFailureForExternalDocTypeWithDocTypeValidationEnabled() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty(EvaluateXPath.RETURN_TYPE, EvaluateXPath.RETURN_TYPE_STRING);
testRunner.setProperty("some.property", "/*:bundle/node/subNode[1]/value/text()");
@@ -201,7 +201,6 @@ public class TestEvaluateXPath {
@Test
public void testFailureForExternalDocTypeWithDocTypeValidationDisabled() throws IOException {
- final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXPath());
testRunner.setProperty(EvaluateXPath.DESTINATION, EvaluateXPath.DESTINATION_CONTENT);
testRunner.setProperty(EvaluateXPath.RETURN_TYPE, EvaluateXPath.RETURN_TYPE_STRING);
testRunner.setProperty(EvaluateXPath.VALIDATE_DTD, "false");
@@ -212,4 +211,12 @@ public class TestEvaluateXPath {
testRunner.assertAllFlowFilesTransferred(EvaluateXPath.REL_FAILURE, 1);
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of("Validate DTD", EvaluateXPath.VALIDATE_DTD.getName());
+
+ final PropertyMigrationResult propertyMigrationResult = testRunner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java
index 938a3818ce..3edeae6848 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestEvaluateXQuery.java
@@ -17,6 +17,7 @@
package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.Test;
@@ -62,7 +63,7 @@ public class TestEvaluateXQuery {
for (final boolean omitDeclaration : booleans) {
formattedResults = getFormattedResult(XML_SNIPPET, atomicQuery, method, indent, omitDeclaration);
assertEquals(1, formattedResults.size());
- assertEquals("7", formattedResults.get(0));
+ assertEquals("7", formattedResults.getFirst());
}
}
}
@@ -72,7 +73,7 @@ public class TestEvaluateXQuery {
for (final boolean omitDeclaration : booleans) {
formattedResults = getFormattedResult(XML_SNIPPET, singleTextNodeQuery, method, indent, omitDeclaration);
assertEquals(1, formattedResults.size());
- assertEquals("apple", formattedResults.get(0));
+ assertEquals("apple", formattedResults.getFirst());
}
}
}
@@ -80,56 +81,65 @@ public class TestEvaluateXQuery {
formattedResults = getFormattedResult(XML_SNIPPET, singleElementNodeQuery, "xml", false, false);
assertEquals(1, formattedResults.size());
String expectedXml
- = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><fruit xmlns:ns=\"http://namespace/1\" taste=\"crisp\">\n"
- + "<!-- Apples are my favorite -->\n"
- + " <name>apple</name>\n"
- + " <color>red</color>\n"
- + " </fruit>";
- assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.get(0)));
+ = """
+ <?xml version="1.0" encoding="UTF-8"?><fruit xmlns:ns="http://namespace/1" taste="crisp">
+ <!-- Apples are my favorite -->
+ <name>apple</name>
+ <color>red</color>
+ </fruit>""";
+ assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.getFirst()));
}
{
formattedResults = getFormattedResult(XML_SNIPPET, singleElementNodeQuery, "html", false, false);
assertEquals(1, formattedResults.size());
String expectedXml
- = "<fruit xmlns:ns=\"http://namespace/1\" taste=\"crisp\">\n"
- + " <!-- Apples are my favorite -->\n"
- + " <name>apple</name>\n"
- + " <color>red</color>\n"
- + " </fruit>";
- assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.get(0)));
+ = """
+ <fruit xmlns:ns="http://namespace/1" taste="crisp">
+ <!-- Apples are my favorite -->
+ <name>apple</name>
+ <color>red</color>
+ </fruit>""";
+ assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.getFirst()));
}
{
formattedResults = getFormattedResult(XML_SNIPPET, singleElementNodeQuery, "text", false, false);
assertEquals(1, formattedResults.size());
String expectedXml
- = "\n \n"
- + " apple\n"
- + " red\n"
- + " ";
- assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.get(0)));
+ = """
+
+ \s
+ apple
+ red
+ \
+ """;
+ assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.getFirst()));
}
{
formattedResults = getFormattedResult(XML_SNIPPET, singleElementNodeQuery, "xml", true, false);
assertEquals(1, formattedResults.size());
String expectedXml
- = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- + "<fruit xmlns:ns=\"http://namespace/1\" taste=\"crisp\">\n"
- + " <!-- Apples are my favorite -->\n"
- + " <name>apple</name>\n"
- + " <color>red</color>\n"
- + " </fruit>\n";
- assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.get(0)));
+ = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <fruit xmlns:ns="http://namespace/1" taste="crisp">
+ <!-- Apples are my favorite -->
+ <name>apple</name>
+ <color>red</color>
+ </fruit>
+ """;
+ assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.getFirst()));
}
{
formattedResults = getFormattedResult(XML_SNIPPET, singleElementNodeQuery, "xml", true, true);
assertEquals(1, formattedResults.size());
String expectedXml
- = "<fruit xmlns:ns=\"http://namespace/1\" taste=\"crisp\">\n"
- + " <!-- Apples are my favorite -->\n"
- + " <name>apple</name>\n"
- + " <color>red</color>\n"
- + " </fruit>\n";
- assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.get(0)));
+ = """
+ <fruit xmlns:ns="http://namespace/1" taste="crisp">
+ <!-- Apples are my favorite -->
+ <name>apple</name>
+ <color>red</color>
+ </fruit>
+ """;
+ assertEquals(spaceTrimmed(expectedXml), spaceTrimmed(formattedResults.getFirst()));
}
}
@@ -244,24 +254,26 @@ public class TestEvaluateXQuery {
/* String all matches fruit & color (single, newline delimited result)*/
doXqueryTest(XML_SNIPPET, "string-join((for $y in (for $x in //fruit return string-join(($x/name/text() , $x/color/text()), ' - ')) return $y), '\n')",
Collections.singletonList(
- "apple - red\n"
- + "apple - green\n"
- + "banana - yellow\n"
- + "orange - orange\n"
- + "blueberry - blue\n"
- + "raspberry - red\n"
- + "none"));
+ """
+ apple - red
+ apple - green
+ banana - yellow
+ orange - orange
+ blueberry - blue
+ raspberry - red
+ none"""));
/* String all matches fruit & color using "let" (single, newline delimited result)*/
doXqueryTest(XML_SNIPPET, "string-join((for $y in (for $x in //fruit let $d := string-join(($x/name/text() , $x/color/text()), ' - ') return $d) return $y), '\n')",
Collections.singletonList(
- "apple - red\n"
- + "apple - green\n"
- + "banana - yellow\n"
- + "orange - orange\n"
- + "blueberry - blue\n"
- + "raspberry - red\n"
- + "none"));
+ """
+ apple - red
+ apple - green
+ banana - yellow
+ orange - orange
+ blueberry - blue
+ raspberry - red
+ none"""));
/* String all matches name only, comma delimited (one result)*/
doXqueryTest(XML_SNIPPET, "string-join((for $x in //fruit return $x/name/text()), ', ')",
@@ -299,7 +311,7 @@ public class TestEvaluateXQuery {
assertEquals(1, resultFlowFiles.size());
- final MockFlowFile out = resultFlowFiles.get(0);
+ final MockFlowFile out = resultFlowFiles.getFirst();
for (int i = 0; i < expectedResults.size(); i++) {
String key = "xquery";
@@ -359,9 +371,9 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
final String attributeString = out.getAttribute("xquery.result1").replaceAll(">\\s+<", "><");
- final String xmlSnippetString = new String(Files.readAllBytes(XML_SNIPPET), StandardCharsets.UTF_8).replaceAll(">\\s+<", "><");
+ final String xmlSnippetString = Files.readString(XML_SNIPPET).replaceAll(">\\s+<", "><");
assertEquals(xmlSnippetString, attributeString);
}
@@ -377,7 +389,7 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
out.assertAttributeEquals("xquery.result.exist.1", "true");
out.assertAttributeEquals("xquery.result.exist.2", "false");
}
@@ -392,7 +404,7 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1);
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -405,9 +417,9 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).getFirst();
out.assertAttributeEquals("xquery.result.exist.2", null);
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -419,7 +431,7 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1);
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -443,7 +455,7 @@ public class TestEvaluateXQuery {
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
for (int i = 0; i < fruitNames.length; i++) {
final String outXml = out.getAttribute("some.property." + (i + 1));
@@ -451,7 +463,7 @@ public class TestEvaluateXQuery {
}
out.assertAttributeEquals("xquery.result.exist.2", null);
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -464,10 +476,10 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_NO_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).getFirst();
out.assertAttributeEquals("xquery.result.exist.2", null);
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_NO_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -491,9 +503,9 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
out.assertAttributeEquals("xquery.result2", "apple");
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -506,7 +518,7 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
out.assertContentEquals("apple");
}
@@ -520,10 +532,10 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
final String outXml = out.getAttribute("some.property");
assertTrue(outXml.contains("<name xmlns:ns=\"http://namespace/1\">apple</name>"));
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -536,7 +548,7 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
final byte[] outData = testRunner.getContentAsByteArray(out);
final String outXml = new String(outData, StandardCharsets.UTF_8);
assertTrue(outXml.contains("<name xmlns:ns=\"http://namespace/1\">apple</name>"));
@@ -572,13 +584,13 @@ public class TestEvaluateXQuery {
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
for (int i = 0; i < fruitNames.length; i++) {
final String outXml = out.getAttribute("some.property." + (i + 1));
assertEquals(fruitNames[i], outXml.trim());
}
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -614,14 +626,14 @@ public class TestEvaluateXQuery {
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
for (int i = 0; i < fruitNames.length; i++) {
final String outXml = out.getAttribute("some.property." + (i + 1));
String expectedXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><name xmlns:ns=\"http://namespace/1\">" + fruitNames[i] + "</name>";
assertEquals(expectedXml, outXml.trim());
}
- testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0).assertContentEquals(XML_SNIPPET);
+ testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst().assertContentEquals(XML_SNIPPET);
}
@Test
@@ -635,7 +647,7 @@ public class TestEvaluateXQuery {
testRunner.run();
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_MATCH, 1);
- final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).get(0);
+ final MockFlowFile out = testRunner.getFlowFilesForRelationship(EvaluateXQuery.REL_MATCH).getFirst();
out.assertContentEquals("Hello");
}
@@ -677,4 +689,13 @@ public class TestEvaluateXQuery {
testRunner.assertAllFlowFilesTransferred(EvaluateXQuery.REL_FAILURE, 1);
}
+
+ @Test
+ void testMigrateProperties() {
+ final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateXQuery());
+ final Map<String, String> expectedRenamed = Map.of("Validate DTD", EvaluateXQuery.VALIDATE_DTD.getName());
+
+ final PropertyMigrationResult propertyMigrationResult = testRunner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
index 5852d62f38..77f4f5af73 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
@@ -26,8 +26,10 @@ import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.flowfile.attributes.FragmentAttributes;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.db.AvroUtil;
+import org.apache.nifi.util.db.JdbcProperties;
import org.apache.nifi.util.db.SimpleCommerceDataSet;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -45,6 +47,10 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import static org.apache.nifi.util.db.JdbcProperties.DEFAULT_PRECISION;
+import static org.apache.nifi.util.db.JdbcProperties.DEFAULT_SCALE;
+import static org.apache.nifi.util.db.JdbcProperties.NORMALIZE_NAMES_FOR_AVRO;
+import static org.apache.nifi.util.db.JdbcProperties.USE_AVRO_LOGICAL_TYPES;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -614,6 +620,27 @@ public class TestExecuteSQL extends AbstractDatabaseConnectionServiceTest {
firstFlowFile.assertContentEquals("test");
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("sql-pre-query", AbstractExecuteSQL.SQL_PRE_QUERY.getName()),
+ Map.entry("SQL select query", AbstractExecuteSQL.SQL_QUERY.getName()),
+ Map.entry("sql-post-query", AbstractExecuteSQL.SQL_POST_QUERY.getName()),
+ Map.entry("esql-max-rows", AbstractExecuteSQL.MAX_ROWS_PER_FLOW_FILE.getName()),
+ Map.entry("esql-output-batch-size", AbstractExecuteSQL.OUTPUT_BATCH_SIZE.getName()),
+ Map.entry("esql-fetch-size", AbstractExecuteSQL.FETCH_SIZE.getName()),
+ Map.entry("esql-auto-commit", AbstractExecuteSQL.AUTO_COMMIT.getName()),
+ Map.entry("compression-format", ExecuteSQL.COMPRESSION_FORMAT.getName()),
+ Map.entry(JdbcProperties.OLD_NORMALIZE_NAMES_FOR_AVRO_PROPERTY_NAME, NORMALIZE_NAMES_FOR_AVRO.getName()),
+ Map.entry(JdbcProperties.OLD_USE_AVRO_LOGICAL_TYPES_PROPERTY_NAME, USE_AVRO_LOGICAL_TYPES.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_PRECISION_PROPERTY_NAME, DEFAULT_PRECISION.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_SCALE_PROPERTY_NAME, DEFAULT_SCALE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void insertRecords() throws SQLException {
try (
Connection connection = getConnection();
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java
index 9b124ffe3e..ea9d57c756 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQLRecord.java
@@ -35,9 +35,11 @@ import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.serialization.record.RecordSet;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.apache.nifi.util.db.JdbcCommon.AvroConversionOptions;
+import org.apache.nifi.util.db.JdbcProperties;
import org.apache.nifi.util.db.SimpleCommerceDataSet;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -654,6 +656,26 @@ class TestExecuteSQLRecord extends AbstractDatabaseConnectionServiceTest {
assertTrue(json.contains("\"test\":[\"test\"]"), "Expected JSON to contain array of strings: " + json);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("sql-pre-query", AbstractExecuteSQL.SQL_PRE_QUERY.getName()),
+ Map.entry("SQL select query", AbstractExecuteSQL.SQL_QUERY.getName()),
+ Map.entry("sql-post-query", AbstractExecuteSQL.SQL_POST_QUERY.getName()),
+ Map.entry("esql-max-rows", AbstractExecuteSQL.MAX_ROWS_PER_FLOW_FILE.getName()),
+ Map.entry("esql-output-batch-size", AbstractExecuteSQL.OUTPUT_BATCH_SIZE.getName()),
+ Map.entry("esql-fetch-size", AbstractExecuteSQL.FETCH_SIZE.getName()),
+ Map.entry("esql-auto-commit", AbstractExecuteSQL.AUTO_COMMIT.getName()),
+ Map.entry("esqlrecord-record-writer", ExecuteSQLRecord.RECORD_WRITER_FACTORY.getName()),
+ Map.entry("esqlrecord-normalize", ExecuteSQLRecord.NORMALIZE_NAMES.getName()),
+ Map.entry(JdbcProperties.OLD_USE_AVRO_LOGICAL_TYPES_PROPERTY_NAME, JdbcProperties.USE_AVRO_LOGICAL_TYPES.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_PRECISION_PROPERTY_NAME, JdbcProperties.DEFAULT_PRECISION.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_SCALE_PROPERTY_NAME, JdbcProperties.DEFAULT_SCALE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
private void insertRecords() throws SQLException {
try (
@@ -700,7 +722,7 @@ class TestExecuteSQLRecord extends AbstractDatabaseConnectionServiceTest {
}
@Override
- public WriteResult write(final Record record) throws IOException {
+ public WriteResult write(final Record record) {
throw new UnsupportedOperationException("Record-by-record writes not supported");
}
@@ -710,20 +732,20 @@ class TestExecuteSQLRecord extends AbstractDatabaseConnectionServiceTest {
}
@Override
- public void flush() throws IOException {
+ public void flush() {
}
@Override
- public void close() throws IOException {
+ public void close() {
}
@Override
- public void beginRecordSet() throws IOException {
+ public void beginRecordSet() {
currentRecordCount = 0;
}
@Override
- public WriteResult finishRecordSet() throws IOException {
+ public WriteResult finishRecordSet() {
return WriteResult.of(Math.toIntExact(currentRecordCount), Collections.emptyMap());
}
};
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java
index 7f60f4b616..739dd97056 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteStreamCommand.java
@@ -23,6 +23,7 @@ import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.processors.standard.util.ArgumentUtils;
import org.apache.nifi.util.LogMessage;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -570,7 +571,7 @@ public class TestExecuteStreamCommand {
}
@Test
- public void testArgumentsWithQuotesFromAttributeDynamicProperties() throws Exception {
+ public void testArgumentsWithQuotesFromAttributeDynamicProperties() {
Map<String, String> attrs = new HashMap<>();
String exStr = "Hello World with quotes";
attrs.put("str.attribute", exStr);
@@ -1150,6 +1151,15 @@ public class TestExecuteStreamCommand {
assertEquals(expected, attribute.substring(attribute.length() - expected.length()));
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed =
+ Map.of("argumentsStrategy", ExecuteStreamCommand.ARGUMENTS_STRATEGY.getName());
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().startsWith("windows");
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java
index e2f94b2f97..6da13d0a31 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractGrok.java
@@ -18,6 +18,7 @@
package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -26,6 +27,9 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestExtractGrok {
@@ -52,7 +56,7 @@ public class TestExtractGrok {
testRunner.enqueue("admin - 127.0.0.1");
testRunner.run();
testRunner.assertAllFlowFilesTransferred(ExtractGrok.REL_MATCH);
- final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).get(0);
+ final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).getFirst();
matched.assertAttributeEquals("grok.username", "admin");
}
@@ -64,7 +68,7 @@ public class TestExtractGrok {
testRunner.enqueue(GROK_LOG_INPUT);
testRunner.run();
testRunner.assertAllFlowFilesTransferred(ExtractGrok.REL_MATCH);
- final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).get(0);
+ final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).getFirst();
matched.assertAttributeEquals("grok.verb", "GET");
matched.assertAttributeEquals("grok.response", "401");
@@ -83,7 +87,7 @@ public class TestExtractGrok {
testRunner.enqueue("-42");
testRunner.run();
testRunner.assertAllFlowFilesTransferred(ExtractGrok.REL_MATCH);
- final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).get(0);
+ final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).getFirst();
matched.assertAttributeEquals("grok.NUMBER", "[-42, null]");
}
@@ -95,7 +99,7 @@ public class TestExtractGrok {
testRunner.enqueue("-42");
testRunner.run();
testRunner.assertAllFlowFilesTransferred(ExtractGrok.REL_MATCH);
- final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).get(0);
+ final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).getFirst();
matched.assertAttributeEquals("grok.NUMBER", "-42");
}
@@ -107,7 +111,7 @@ public class TestExtractGrok {
testRunner.enqueue(GROK_TEXT_INPUT);
testRunner.run();
testRunner.assertAllFlowFilesTransferred(ExtractGrok.REL_NO_MATCH);
- final MockFlowFile notMatched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_NO_MATCH).get(0);
+ final MockFlowFile notMatched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_NO_MATCH).getFirst();
notMatched.assertContentEquals(GROK_TEXT_INPUT);
}
@@ -135,7 +139,7 @@ public class TestExtractGrok {
testRunner.enqueue(GROK_LOG_INPUT);
testRunner.run();
testRunner.assertAllFlowFilesTransferred(ExtractGrok.REL_MATCH);
- final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).get(0);
+ final MockFlowFile matched = testRunner.getFlowFilesForRelationship(ExtractGrok.REL_MATCH).getFirst();
matched.assertAttributeEquals("grok.verb", "GET");
matched.assertAttributeEquals("grok.response", "401");
@@ -150,4 +154,15 @@ public class TestExtractGrok {
matched.assertAttributeNotExists("grok.BASE10NUM");
matched.assertAttributeNotExists("grok.COMMONAPACHELOG");
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "Grok Pattern file", ExtractGrok.GROK_PATTERNS.getName(),
+ "Named captures only", ExtractGrok.NAMED_CAPTURES_ONLY.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = testRunner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractRecordSchema.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractRecordSchema.java
index 8a9bef6c0e..6909d1c45b 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractRecordSchema.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExtractRecordSchema.java
@@ -22,8 +22,10 @@ import org.apache.nifi.serialization.RecordReader;
import org.apache.nifi.serialization.record.MockRecordParser;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.InputStream;
@@ -32,14 +34,21 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class TestExtractRecordSchema {
static final Path NAME_AGE_SCHEMA_PATH = Paths.get("src/test/resources/TestExtractRecordSchema/name_age_schema.avsc");
+ private TestRunner runner;
+
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(ExtractRecordSchema.class);
+ }
@Test
public void testSuccessfulExtraction() throws Exception {
final MockRecordParser readerService = new MockRecordParser();
- final TestRunner runner = TestRunners.newTestRunner(ExtractRecordSchema.class);
runner.addControllerService("reader", readerService);
runner.enableControllerService(readerService);
runner.setProperty(ExtractRecordSchema.RECORD_READER, "reader");
@@ -55,7 +64,7 @@ public class TestExtractRecordSchema {
runner.run();
runner.assertAllFlowFilesTransferred(ExtractRecordSchema.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ExtractRecordSchema.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ExtractRecordSchema.REL_SUCCESS).getFirst();
final String expectedAttributeValue = new String(Files.readAllBytes(NAME_AGE_SCHEMA_PATH));
out.assertAttributeEquals(ExtractRecordSchema.SCHEMA_ATTRIBUTE_NAME, expectedAttributeValue);
@@ -64,7 +73,6 @@ public class TestExtractRecordSchema {
@Test
public void testNoSchema() throws Exception {
final MockRecordParser readerService = new MockRecordParserSchemaNotFound();
- final TestRunner runner = TestRunners.newTestRunner(ExtractRecordSchema.class);
runner.addControllerService("reader", readerService);
runner.enableControllerService(readerService);
runner.setProperty(ExtractRecordSchema.RECORD_READER, "reader");
@@ -73,11 +81,22 @@ public class TestExtractRecordSchema {
runner.run();
runner.assertAllFlowFilesTransferred(ExtractRecordSchema.REL_FAILURE, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ExtractRecordSchema.REL_FAILURE).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ExtractRecordSchema.REL_FAILURE).getFirst();
out.assertAttributeEquals("record.error.message", "org.apache.nifi.schema.access.SchemaNotFoundException Thrown");
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "record-reader", ExtractRecordSchema.RECORD_READER.getName(),
+ "cache-size", ExtractRecordSchema.SCHEMA_CACHE_SIZE.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private static class MockRecordParserSchemaNotFound extends MockRecordParser {
@Override
public RecordReader createRecordReader(Map<String, String> variables, InputStream in, long inputLength, ComponentLog logger) throws SchemaNotFoundException {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java
index 0b1f0dbf62..a1efca007b 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java
@@ -18,13 +18,16 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.migration.ProxyServiceMigration;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.util.file.transfer.FetchFileTransfer;
import org.apache.nifi.processor.util.file.transfer.PutFileTransfer;
import org.apache.nifi.processor.util.list.AbstractListProcessor;
+import org.apache.nifi.processor.util.list.ListedEntityTracker;
import org.apache.nifi.processors.standard.util.FTPTransfer;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.AfterEach;
@@ -45,6 +48,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -74,7 +78,7 @@ public class TestFTP {
}
@AfterEach
- public void tearDown() throws Exception {
+ public void tearDown() {
fakeFtpServer.stop();
}
@@ -221,10 +225,23 @@ public class TestFTP {
runner.run();
- final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(GetFTP.REL_SUCCESS).get(0);
+ final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(GetFTP.REL_SUCCESS).getFirst();
retrievedFile.assertContentEquals("Just some random test test test chocolate");
}
+ @Test
+ void testGetFtpMigrateProperties() {
+ TestRunner runner = TestRunners.newTestRunner(GetFTP.class);
+ final Map<String, String> expectedRenamed = Map.of(
+ FTPTransfer.OBSOLETE_UTF8_ENCODING, FTPTransfer.UTF8_ENCODING.getName(),
+ FTPTransfer.OLD_FOLLOW_SYMLINK_PROPERTY_NAME, FTPTransfer.FOLLOW_SYMLINK.getName(),
+ ProxyServiceMigration.OBSOLETE_PROXY_CONFIGURATION_SERVICE, ProxyServiceMigration.PROXY_CONFIGURATION_SERVICE
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
@Test
public void testFetchFtp() {
FileSystem results = fakeFtpServer.getFileSystem();
@@ -254,7 +271,7 @@ public class TestFTP {
runner.run();
- final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).get(0);
+ final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).getFirst();
retrievedFile.assertContentEquals("Just some random test test test chocolate");
}
@@ -296,6 +313,29 @@ public class TestFTP {
runner.assertAllFlowFilesContainAttribute(FetchFileTransfer.FAILURE_REASON_ATTRIBUTE);
}
+ @Test
+ void testListFtpMigrateProperties() {
+ TestRunner runner = TestRunners.newTestRunner(ListFTP.class);
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry(FTPTransfer.OBSOLETE_UTF8_ENCODING, FTPTransfer.UTF8_ENCODING.getName()),
+ Map.entry(FTPTransfer.OLD_FOLLOW_SYMLINK_PROPERTY_NAME, FTPTransfer.FOLLOW_SYMLINK.getName()),
+ Map.entry(ListedEntityTracker.OLD_TRACKING_STATE_CACHE_PROPERTY_NAME, ListedEntityTracker.TRACKING_STATE_CACHE.getName()),
+ Map.entry(ListedEntityTracker.OLD_TRACKING_TIME_WINDOW_PROPERTY_NAME, ListedEntityTracker.TRACKING_TIME_WINDOW.getName()),
+ Map.entry(ListedEntityTracker.OLD_INITIAL_LISTING_TARGET_PROPERTY_NAME, ListedEntityTracker.INITIAL_LISTING_TARGET.getName()),
+ Map.entry("target-system-timestamp-precision", AbstractListProcessor.TARGET_SYSTEM_TIMESTAMP_PRECISION.getName()),
+ Map.entry("listing-strategy", AbstractListProcessor.LISTING_STRATEGY.getName()),
+ Map.entry("record-writer", AbstractListProcessor.RECORD_WRITER.getName()),
+ Map.entry(ProxyServiceMigration.OBSOLETE_PROXY_CONFIGURATION_SERVICE, ProxyServiceMigration.PROXY_CONFIGURATION_SERVICE)
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+
+ final Set<String> expectedRemoved = Set.of("Distributed Cache Service", "Proxy Type", "Proxy Host",
+ "Proxy Port", "Http Proxy Username", "Http Proxy Password");
+ assertEquals(expectedRemoved, propertyMigrationResult.getPropertiesRemoved());
+ }
+
@Test
public void testListFtpHostPortVariablesFileFound() throws InterruptedException {
final FileSystem fs = fakeFtpServer.getFileSystem();
@@ -348,7 +388,7 @@ public class TestFTP {
runner.run();
runner.assertTransferCount(FetchFTP.REL_SUCCESS, 1);
- final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).get(0);
+ final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).getFirst();
retrievedFile.assertContentEquals("Just some random test test test chocolate");
}
@@ -380,7 +420,7 @@ public class TestFTP {
runner.run();
runner.assertTransferCount(FetchFTP.REL_SUCCESS, 1);
- final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).get(0);
+ final MockFlowFile retrievedFile = runner.getFlowFilesForRelationship(FetchFTP.REL_SUCCESS).getFirst();
runner.assertAllFlowFilesContainAttribute("ftp.remote.host");
runner.assertAllFlowFilesContainAttribute("ftp.remote.port");
runner.assertAllFlowFilesContainAttribute("ftp.listing.user");
@@ -392,4 +432,20 @@ public class TestFTP {
retrievedFile.assertAttributeEquals("ftp.listing.user", username);
retrievedFile.assertAttributeEquals("filename", "randombytes-2");
}
+
+ @Test
+ void testPutFtpMigrateProperties() {
+ final TestRunner runner = TestRunners.newTestRunner(PutFTP.class);
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry(FTPTransfer.OBSOLETE_UTF8_ENCODING, FTPTransfer.UTF8_ENCODING.getName()),
+ Map.entry(ProxyServiceMigration.OBSOLETE_PROXY_CONFIGURATION_SERVICE, ProxyServiceMigration.PROXY_CONFIGURATION_SERVICE)
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+
+ final Set<String> expectedRemoved = Set.of("Proxy Type", "Proxy Host",
+ "Proxy Port", "Http Proxy Username", "Http Proxy Password");
+ assertEquals(expectedRemoved, propertyMigrationResult.getPropertiesRemoved());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java
index cdf0bf7be1..e5f6b6ede4 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFetchFTP.java
@@ -22,6 +22,7 @@ import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.context.PropertyContext;
import org.apache.nifi.flowfile.FlowFile;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.migration.ProxyServiceMigration;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.processor.exception.ProcessException;
@@ -31,12 +32,12 @@ import org.apache.nifi.processor.util.file.transfer.PermissionDeniedException;
import org.apache.nifi.processors.standard.util.FTPTransfer;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import org.mockito.stubbing.Answer;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -92,7 +93,7 @@ public class TestFetchFTP {
runner.run(1, false, false);
runner.assertAllFlowFilesTransferred(FetchFileTransfer.REL_SUCCESS, 1);
assertFalse(proc.isClosed);
- runner.getFlowFilesForRelationship(FetchFileTransfer.REL_SUCCESS).get(0).assertContentEquals("world");
+ runner.getFlowFilesForRelationship(FetchFileTransfer.REL_SUCCESS).getFirst().assertContentEquals("world");
}
@Test
@@ -102,7 +103,7 @@ public class TestFetchFTP {
runner.run(1, false, false);
runner.assertAllFlowFilesTransferred(FetchFileTransfer.REL_SUCCESS, 1);
assertFalse(proc.isClosed);
- MockFlowFile transferredFlowFile = runner.getFlowFilesForRelationship(FetchFileTransfer.REL_SUCCESS).get(0);
+ MockFlowFile transferredFlowFile = runner.getFlowFilesForRelationship(FetchFileTransfer.REL_SUCCESS).getFirst();
transferredFlowFile.assertContentEquals("world");
transferredFlowFile.assertAttributeExists(CoreAttributes.PATH.key());
transferredFlowFile.assertAttributeEquals(CoreAttributes.PATH.key(), "./here/is/my/path");
@@ -115,7 +116,7 @@ public class TestFetchFTP {
runner.run(1, false, false);
runner.assertAllFlowFilesTransferred(FetchFileTransfer.REL_NOT_FOUND, 1);
runner.assertAllFlowFilesContainAttribute(FetchFileTransfer.FAILURE_REASON_ATTRIBUTE);
- MockFlowFile transferredFlowFile = runner.getPenalizedFlowFiles().get(0);
+ MockFlowFile transferredFlowFile = runner.getPenalizedFlowFiles().getFirst();
assertEquals(FetchFileTransfer.REL_NOT_FOUND.getName(), transferredFlowFile.getAttribute(FetchFileTransfer.FAILURE_REASON_ATTRIBUTE));
}
@@ -127,7 +128,7 @@ public class TestFetchFTP {
runner.run(1, false, false);
runner.assertAllFlowFilesTransferred(FetchFileTransfer.REL_PERMISSION_DENIED, 1);
runner.assertAllFlowFilesContainAttribute(FetchFileTransfer.FAILURE_REASON_ATTRIBUTE);
- MockFlowFile transferredFlowFile = runner.getPenalizedFlowFiles().get(0);
+ MockFlowFile transferredFlowFile = runner.getPenalizedFlowFiles().getFirst();
assertEquals(FetchFileTransfer.REL_PERMISSION_DENIED.getName(), transferredFlowFile.getAttribute(FetchFileTransfer.FAILURE_REASON_ATTRIBUTE));
}
@@ -167,7 +168,7 @@ public class TestFetchFTP {
runner.run(1, false, false);
runner.assertAllFlowFilesTransferred(FetchFileTransfer.REL_COMMS_FAILURE, 1);
runner.assertAllFlowFilesContainAttribute(FetchFileTransfer.FAILURE_REASON_ATTRIBUTE);
- MockFlowFile transferredFlowFile = runner.getPenalizedFlowFiles().get(0);
+ MockFlowFile transferredFlowFile = runner.getPenalizedFlowFiles().getFirst();
assertEquals(FetchFileTransfer.REL_COMMS_FAILURE.getName(), transferredFlowFile.getAttribute(FetchFileTransfer.FAILURE_REASON_ATTRIBUTE));
assertTrue(proc.isClosed);
@@ -185,6 +186,7 @@ public class TestFetchFTP {
runner.assertAllFlowFilesTransferred(FetchFileTransfer.REL_SUCCESS, 1);
proc.fileContents.containsKey("/moved/hello.txt");
+ runner.getLogger().warn("Keys in fileContents is {}", proc.fileContents.keySet());
assertEquals(1, proc.fileContents.size());
}
@@ -258,6 +260,17 @@ public class TestFetchFTP {
assertTrue(proc.fileContents.containsKey("hello.txt"));
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ FTPTransfer.OBSOLETE_UTF8_ENCODING, FTPTransfer.UTF8_ENCODING.getName(),
+ FetchFileTransfer.OLD_FILE_NOT_FOUND_LOG_LEVEL_PROPERTY_NAME, FetchFileTransfer.FILE_NOT_FOUND_LOG_LEVEL.getName(),
+ ProxyServiceMigration.OBSOLETE_PROXY_CONFIGURATION_SERVICE, ProxyServiceMigration.PROXY_CONFIGURATION_SERVICE
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
private static class TestableFetchFTP extends FetchFTP {
private boolean allowAccess = true;
@@ -273,8 +286,9 @@ public class TestFetchFTP {
private TestableFetchFTP() throws IOException {
when(mockFtpClient.retrieveFileStream(anyString()))
- .then((Answer) invocationOnMock -> {
- byte[] content = fileContents.get(invocationOnMock.getArgument(0));
+ .then(invocationOnMock -> {
+ String key = invocationOnMock.getArgument(0);
+ byte[] content = fileContents.get(key);
if (content == null) {
throw new FileNotFoundException();
}
@@ -282,7 +296,6 @@ public class TestFetchFTP {
});
when(mockFtpClient.login(anyString(), anyString())).thenReturn(true);
when(mockFtpClient.setFileType(anyInt())).thenReturn(true);
-
}
public void addContent(final String filename, final byte[] content) {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java
index c601818352..e4659ea4b7 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFlattenJson.java
@@ -18,8 +18,10 @@
package org.apache.nifi.processors.standard;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -45,22 +47,23 @@ public class TestFlattenJson {
@Test
void testFlatten() throws JsonProcessingException {
- final String json = "{\n" +
- " \"test\": {\n" +
- " \"msg\": \"Hello, world\"\n" +
- " },\n" +
- " \"first\": {\n" +
- " \"second\": {\n" +
- " \"third\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "test": {
+ "msg": "Hello, world"
+ },
+ "first": {
+ "second": {
+ "third": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }
+ }
+ }""";
final Map parsed = (Map) baseTest(testRunner, json, 2);
assertEquals(parsed.get("test.msg"), "Hello, world", "test.msg should exist, but doesn't");
assertEquals(parsed.get("first.second.third"),
@@ -70,18 +73,19 @@ public class TestFlattenJson {
@Test
void testFlattenRecordSet() throws JsonProcessingException {
- final String json = "[\n" +
- " {\n" +
- " \"first\": {\n" +
- " \"second\": \"Hello\"\n" +
- " }\n" +
- " },\n" +
- " {\n" +
- " \"first\": {\n" +
- " \"second\": \"World\"\n" +
- " }\n" +
- " }\n" +
- "]";
+ final String json = """
+ [
+ {
+ "first": {
+ "second": "Hello"
+ }
+ },
+ {
+ "first": {
+ "second": "World"
+ }
+ }
+ ]""";
final List<String> expected = Arrays.asList("Hello", "World");
final List parsed = (List) baseTest(testRunner, json, 2);
@@ -94,19 +98,20 @@ public class TestFlattenJson {
@Test
void testDifferentSeparator() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second\": {\n" +
- " \"third\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second": {
+ "third": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }
+ }
+ }""";
testRunner.setProperty(FlattenJson.SEPARATOR, "_");
final Map parsed = (Map) baseTest(testRunner, json, 1);
@@ -117,19 +122,20 @@ public class TestFlattenJson {
@Test
void testExpressionLanguage() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second\": {\n" +
- " \"third\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second": {
+ "third": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }
+ }
+ }""";
testRunner.setValidateExpressionUsage(true);
testRunner.setProperty(FlattenJson.SEPARATOR, "${separator.char}");
@@ -141,19 +147,20 @@ public class TestFlattenJson {
@Test
void testFlattenModeNormal() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second\": {\n" +
- " \"third\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second": {
+ "third": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }
+ }
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_NORMAL);
final Map parsed = (Map) baseTest(testRunner, json, 5);
@@ -162,39 +169,40 @@ public class TestFlattenJson {
@Test
void testFlattenModeKeepArrays() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second\": [\n" +
- " {\n" +
- " \"x\": 1,\n" +
- " \"y\": 2,\n" +
- " \"z\": [\n" +
- " 3,\n" +
- " 4,\n" +
- " 5\n" +
- " ]\n" +
- " },\n" +
- " [\n" +
- " 6,\n" +
- " 7,\n" +
- " 8\n" +
- " ],\n" +
- " [\n" +
- " [\n" +
- " 9,\n" +
- " 10\n" +
- " ],\n" +
- " 11,\n" +
- " 12\n" +
- " ]\n" +
- " ],\n" +
- " \"third\": {\n" +
- " \"a\": \"b\",\n" +
- " \"c\": \"d\",\n" +
- " \"e\": \"f\"\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second": [
+ {
+ "x": 1,
+ "y": 2,
+ "z": [
+ 3,
+ 4,
+ 5
+ ]
+ },
+ [
+ 6,
+ 7,
+ 8
+ ],
+ [
+ [
+ 9,
+ 10
+ ],
+ 11,
+ 12
+ ]
+ ],
+ "third": {
+ "a": "b",
+ "c": "d",
+ "e": "f"
+ }
+ }
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_KEEP_ARRAYS);
final Map parsed = (Map) baseTest(testRunner, json, 4);
@@ -205,39 +213,40 @@ public class TestFlattenJson {
@Test
void testFlattenModeKeepPrimitiveArrays() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second\": [\n" +
- " {\n" +
- " \"x\": 1,\n" +
- " \"y\": 2,\n" +
- " \"z\": [\n" +
- " 3,\n" +
- " 4,\n" +
- " 5\n" +
- " ]\n" +
- " },\n" +
- " [\n" +
- " 6,\n" +
- " 7,\n" +
- " 8\n" +
- " ],\n" +
- " [\n" +
- " [\n" +
- " 9,\n" +
- " 10\n" +
- " ],\n" +
- " 11,\n" +
- " 12\n" +
- " ]\n" +
- " ],\n" +
- " \"third\": {\n" +
- " \"a\": \"b\",\n" +
- " \"c\": \"d\",\n" +
- " \"e\": \"f\"\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second": [
+ {
+ "x": 1,
+ "y": 2,
+ "z": [
+ 3,
+ 4,
+ 5
+ ]
+ },
+ [
+ 6,
+ 7,
+ 8
+ ],
+ [
+ [
+ 9,
+ 10
+ ],
+ 11,
+ 12
+ ]
+ ],
+ "third": {
+ "a": "b",
+ "c": "d",
+ "e": "f"
+ }
+ }
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_KEEP_PRIMITIVE_ARRAYS);
final Map parsed = (Map) baseTest(testRunner, json, 10);
@@ -251,19 +260,20 @@ public class TestFlattenJson {
@Test
void testFlattenModeDotNotation() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second\": {\n" +
- " \"third\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second": {
+ "third": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }
+ }
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_DOT_NOTATION);
final Map parsed = (Map) baseTest(testRunner, json, 5);
@@ -272,16 +282,17 @@ public class TestFlattenJson {
@Test
void testFlattenSlash() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second\": {\n" +
- " \"third\": [\n" +
- " \"http://localhost/value1\",\n" +
- " \"http://localhost/value2\"\n" +
- " ]\n" +
- " }\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second": {
+ "third": [
+ "http://localhost/value1",
+ "http://localhost/value2"
+ ]
+ }
+ }
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_NORMAL);
final Map parsed = (Map) baseTest(testRunner, json, 2);
@@ -290,9 +301,10 @@ public class TestFlattenJson {
@Test
void testEscapeForJson() throws JsonProcessingException {
- final String json = "{\n" +
- " \"name\": \"Jos\\u00e9\"\n" +
- "}";
+ final String json = """
+ {
+ "name": "Jos\\u00e9"
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_NORMAL);
final Map parsed = (Map) baseTest(testRunner, json, 1);
@@ -301,16 +313,17 @@ public class TestFlattenJson {
@Test
void testUnFlatten() throws JsonProcessingException {
- final String json = "{\n" +
- " \"test.msg\": \"Hello, world\",\n" +
- " \"first.second.third\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- "}";
+ final String json = """
+ {
+ "test.msg": "Hello, world",
+ "first.second.third": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }""";
testRunner.setProperty(FlattenJson.RETURN_TYPE, FlattenJson.RETURN_TYPE_UNFLATTEN);
final Map parsed = (Map) baseTest(testRunner, json, 2);
@@ -321,15 +334,16 @@ public class TestFlattenJson {
@Test
void testUnFlattenWithDifferentSeparator() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first_second_third\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- "}";
+ final String json = """
+ {
+ "first_second_third": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }""";
testRunner.setProperty(FlattenJson.SEPARATOR, "_");
testRunner.setProperty(FlattenJson.RETURN_TYPE, FlattenJson.RETURN_TYPE_UNFLATTEN);
@@ -340,19 +354,20 @@ public class TestFlattenJson {
@Test
void testUnFlattenForKeepArraysMode() throws JsonProcessingException {
- final String json = "{\n" +
- " \"a.b\": 1,\n" +
- " \"a.c\": [\n" +
- " false,\n" +
- " {\n" +
- " \"i.j\": [\n" +
- " false,\n" +
- " true,\n" +
- " \"xy\"\n" +
- " ]\n" +
- " }\n" +
- " ]\n" +
- "}";
+ final String json = """
+ {
+ "a.b": 1,
+ "a.c": [
+ false,
+ {
+ "i.j": [
+ false,
+ true,
+ "xy"
+ ]
+ }
+ ]
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_KEEP_ARRAYS);
testRunner.setProperty(FlattenJson.RETURN_TYPE, FlattenJson.RETURN_TYPE_UNFLATTEN);
@@ -365,66 +380,69 @@ public class TestFlattenJson {
@Test
void testUnFlattenForKeepPrimitiveArraysMode() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first.second[0].x\": 1,\n" +
- " \"first.second[0].y\": 2,\n" +
- " \"first.second[0].z\": [\n" +
- " 3,\n" +
- " 4,\n" +
- " 5\n" +
- " ],\n" +
- " \"first.second[1]\": [\n" +
- " 6,\n" +
- " 7,\n" +
- " 8\n" +
- " ],\n" +
- " \"first.second[2][0]\": [\n" +
- " 9,\n" +
- " 10\n" +
- " ],\n" +
- " \"first.second[2][1]\": 11,\n" +
- " \"first.second[2][2]\": 12,\n" +
- " \"first.third.a\": \"b\",\n" +
- " \"first.third.c\": \"d\",\n" +
- " \"first.third.e\": \"f\"\n" +
- "}";
+ final String json = """
+ {
+ "first.second[0].x": 1,
+ "first.second[0].y": 2,
+ "first.second[0].z": [
+ 3,
+ 4,
+ 5
+ ],
+ "first.second[1]": [
+ 6,
+ 7,
+ 8
+ ],
+ "first.second[2][0]": [
+ 9,
+ 10
+ ],
+ "first.second[2][1]": 11,
+ "first.second[2][2]": 12,
+ "first.third.a": "b",
+ "first.third.c": "d",
+ "first.third.e": "f"
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_KEEP_PRIMITIVE_ARRAYS);
testRunner.setProperty(FlattenJson.RETURN_TYPE, FlattenJson.RETURN_TYPE_UNFLATTEN);
final Map parsed = (Map) baseTest(testRunner, json, 1);
assertEquals(1, ((Map) ((List) ((Map) parsed.get("first")).get("second")).get(0)).get("x"));
- assertEquals(Arrays.asList(9, 10), ((List) ((List) ((Map) parsed.get("first")).get("second")).get(2)).get(0));
+ assertEquals(Arrays.asList(9, 10), ((List) ((List) ((Map) parsed.get("first")).get("second")).get(2)).getFirst());
assertEquals("d", ((Map) ((Map) parsed.get("first")).get("third")).get("c"));
}
@Test
void testUnFlattenForDotNotationMode() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first.second.third.0\": [\n" +
- " \"one\",\n" +
- " \"two\",\n" +
- " \"three\",\n" +
- " \"four\",\n" +
- " \"five\"\n" +
- " ]\n" +
- "}";
+ final String json = """
+ {
+ "first.second.third.0": [
+ "one",
+ "two",
+ "three",
+ "four",
+ "five"
+ ]
+ }""";
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_DOT_NOTATION);
testRunner.setProperty(FlattenJson.RETURN_TYPE, FlattenJson.RETURN_TYPE_UNFLATTEN);
final Map parsed = (Map) baseTest(testRunner, json, 1);
assertEquals(Arrays.asList("one", "two", "three", "four", "five"),
- ((List) ((Map) ((Map) parsed.get("first")).get("second")).get("third")).get(0));
+ ((List) ((Map) ((Map) parsed.get("first")).get("second")).get("third")).getFirst());
}
@Test
void testFlattenWithIgnoreReservedCharacters() throws JsonProcessingException {
- final String json = "{\n" +
- " \"first\": {\n" +
- " \"second.third\": \"Hello\",\n" +
- " \"fourth\": \"World\"\n" +
- " }\n" +
- "}";
+ final String json = """
+ {
+ "first": {
+ "second.third": "Hello",
+ "fourth": "World"
+ }
+ }""";
testRunner.setProperty(FlattenJson.IGNORE_RESERVED_CHARACTERS, "true");
@@ -435,18 +453,19 @@ public class TestFlattenJson {
@Test
void testFlattenRecordSetWithIgnoreReservedCharacters() throws JsonProcessingException {
- final String json = "[\n" +
- " {\n" +
- " \"first\": {\n" +
- " \"second_third\": \"Hello\"\n" +
- " }\n" +
- " },\n" +
- " {\n" +
- " \"first\": {\n" +
- " \"second_third\": \"World\"\n" +
- " }\n" +
- " }\n" +
- "]";
+ final String json = """
+ [
+ {
+ "first": {
+ "second_third": "Hello"
+ }
+ },
+ {
+ "first": {
+ "second_third": "World"
+ }
+ }
+ ]""";
testRunner.setProperty(FlattenJson.SEPARATOR, "_");
testRunner.setProperty(FlattenJson.IGNORE_RESERVED_CHARACTERS, "true");
@@ -460,18 +479,19 @@ public class TestFlattenJson {
@Test
void testFlattenModeNormalWithIgnoreReservedCharacters() throws JsonProcessingException {
- final String json = "[\n" +
- " {\n" +
- " \"first\": {\n" +
- " \"second_third\": \"Hello\"\n" +
- " }\n" +
- " },\n" +
- " {\n" +
- " \"first\": {\n" +
- " \"second_third\": \"World\"\n" +
- " }\n" +
- " }\n" +
- "]";
+ final String json = """
+ [
+ {
+ "first": {
+ "second_third": "Hello"
+ }
+ },
+ {
+ "first": {
+ "second_third": "World"
+ }
+ }
+ ]""";
testRunner.setProperty(FlattenJson.SEPARATOR, "_");
testRunner.setProperty(FlattenJson.IGNORE_RESERVED_CHARACTERS, "true");
testRunner.setProperty(FlattenJson.FLATTEN_MODE, FlattenJson.FLATTEN_MODE_NORMAL);
@@ -481,27 +501,42 @@ public class TestFlattenJson {
assertEquals("World", parsed.get("[1]_first_second_third"), "Separator not applied.");
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("flatten-json-separator", FlattenJson.SEPARATOR.getName()),
+ Map.entry("flatten-mode", FlattenJson.FLATTEN_MODE.getName()),
+ Map.entry("ignore-reserved-characters", FlattenJson.IGNORE_RESERVED_CHARACTERS.getName()),
+ Map.entry("flatten-json-return-type", FlattenJson.RETURN_TYPE.getName()),
+ Map.entry("flatten-json-character-set", FlattenJson.CHARACTER_SET.getName()),
+ Map.entry("flatten-json-pretty-print-json", FlattenJson.PRETTY_PRINT.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = testRunner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private Object baseTest(TestRunner testRunner, String json, int keyCount) throws JsonProcessingException {
return baseTest(testRunner, json, Collections.emptyMap(), keyCount);
}
- private Object baseTest(TestRunner testRunner, String json, Map attrs, int keyCount) throws JsonProcessingException {
+ private Object baseTest(TestRunner testRunner, String json, Map<String, String> attrs, int keyCount) throws JsonProcessingException {
testRunner.enqueue(json, attrs);
testRunner.run(1, true);
testRunner.assertTransferCount(FlattenJson.REL_FAILURE, 0);
testRunner.assertTransferCount(FlattenJson.REL_SUCCESS, 1);
final List<MockFlowFile> flowFiles = testRunner.getFlowFilesForRelationship(FlattenJson.REL_SUCCESS);
- final byte[] content = testRunner.getContentAsByteArray(flowFiles.get(0));
+ final byte[] content = testRunner.getContentAsByteArray(flowFiles.getFirst());
final String asJson = new String(content);
if (asJson.startsWith("[")) {
- final List parsed;
- parsed = mapper.readValue(asJson, List.class);
+ final List<?> parsed = mapper.readValue(asJson, new TypeReference<>() {
+ });
assertEquals(keyCount, parsed.size(), "Too many keys");
return parsed;
} else {
- final Map parsed;
- parsed = mapper.readValue(asJson, Map.class);
+ final Map<?, ?> parsed = mapper.readValue(asJson, new TypeReference<>() {
+ });
assertEquals(keyCount, parsed.size(), "Too many keys");
return parsed;
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java
index 378c4504b4..cee7694df4 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestForkRecord.java
@@ -37,6 +37,7 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -46,11 +47,14 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class TestForkRecord {
private final String dateFormat = RecordFieldType.DATE.getDefaultFormat();
@@ -277,8 +281,13 @@ public class TestForkRecord {
final MockFlowFile mff = runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst();
mff.assertAttributeEquals("record.count", "4");
- mff.assertContentEquals("header\n5,John Doe,123 My Street,My City,MS,11111,USA,4750.89,150.31\n6,John Doe,123 My Street,My City,MS,11111,USA,4750.89,-15.31\n"
- + "7,John Doe,123 My Street,My City,MS,11111,USA,48212.38,36.78\n8,John Doe,123 My Street,My City,MS,11111,USA,48212.38,-21.34\n");
+ mff.assertContentEquals("""
+ header
+ 5,John Doe,123 My Street,My City,MS,11111,USA,4750.89,150.31
+ 6,John Doe,123 My Street,My City,MS,11111,USA,4750.89,-15.31
+ 7,John Doe,123 My Street,My City,MS,11111,USA,48212.38,36.78
+ 8,John Doe,123 My Street,My City,MS,11111,USA,48212.38,-21.34
+ """);
}
@Test
@@ -354,8 +363,13 @@ public class TestForkRecord {
final MockFlowFile mff = runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst();
mff.assertAttributeEquals("record.count", "4");
- mff.assertContentEquals("header\n5,John Doe,123 My Street,My City,MS,11111,USA,4750.89,150.31\n6,John Doe,123 My Street,My City,MS,11111,USA,4750.89,-15.31\n"
- + "7,John Doe,123 My Street,My City,MS,11111,USA,48212.38,36.78\n8,John Doe,123 My Street,My City,MS,11111,USA,48212.38,-21.34\n");
+ mff.assertContentEquals("""
+ header
+ 5,John Doe,123 My Street,My City,MS,11111,USA,4750.89,150.31
+ 6,John Doe,123 My Street,My City,MS,11111,USA,4750.89,-15.31
+ 7,John Doe,123 My Street,My City,MS,11111,USA,48212.38,36.78
+ 8,John Doe,123 My Street,My City,MS,11111,USA,48212.38,-21.34
+ """);
}
@Test
@@ -363,8 +377,9 @@ public class TestForkRecord {
final JsonTreeReader jsonReader = new JsonTreeReader();
runner.addControllerService("record-reader", jsonReader);
- final String inputSchemaText = new String(Files.readAllBytes(Paths.get("src/test/resources/TestForkRecord/schema/schema.avsc")));
- final String outputSchemaText = new String(Files.readAllBytes(Paths.get("src/test/resources/TestForkRecord/schema/schema.avsc")));
+ final Path schemaFile = Paths.get("src/test/resources/TestForkRecord/schema/schema.avsc");
+ final String inputSchemaText = new String(Files.readAllBytes(schemaFile));
+ final String outputSchemaText = new String(Files.readAllBytes(schemaFile));
runner.setProperty(jsonReader, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.SCHEMA_TEXT_PROPERTY);
runner.setProperty(jsonReader, SchemaAccessUtils.SCHEMA_TEXT, inputSchemaText);
@@ -372,6 +387,7 @@ public class TestForkRecord {
runner.setProperty(ForkRecord.RECORD_READER, "record-reader");
final JsonRecordSetWriter jsonWriter = new JsonRecordSetWriter();
+ final Path complexInputJson = Paths.get("src/test/resources/TestForkRecord/input/complex-input-json.json");
runner.addControllerService("record-writer", jsonWriter);
runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_ACCESS_STRATEGY, SchemaAccessUtils.SCHEMA_TEXT_PROPERTY);
runner.setProperty(jsonWriter, SchemaAccessUtils.SCHEMA_TEXT, outputSchemaText);
@@ -383,7 +399,7 @@ public class TestForkRecord {
runner.setProperty(ForkRecord.MODE, ForkRecord.MODE_SPLIT);
runner.setProperty("my-path", "/address");
- runner.enqueue(Paths.get("src/test/resources/TestForkRecord/input/complex-input-json.json"));
+ runner.enqueue(complexInputJson);
runner.run();
runner.assertTransferCount(ForkRecord.REL_ORIGINAL, 1);
runner.assertTransferCount(ForkRecord.REL_FORK, 1);
@@ -393,7 +409,7 @@ public class TestForkRecord {
runner.clearTransferState();
runner.setProperty("my-path", "/bankAccounts[*]/last5Transactions");
- runner.enqueue(Paths.get("src/test/resources/TestForkRecord/input/complex-input-json.json"));
+ runner.enqueue(complexInputJson);
runner.run();
runner.assertTransferCount(ForkRecord.REL_ORIGINAL, 1);
runner.assertTransferCount(ForkRecord.REL_FORK, 1);
@@ -463,8 +479,8 @@ public class TestForkRecord {
runner.assertTransferCount(ForkRecord.REL_FORK, 1);
final String expectedOutput = JsonUtil.getExpectedContent(Paths.get("src/test/resources/TestForkRecord/output/extract-bank-accounts-with-parents.json"));
- runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertAttributeEquals("record.count", "5");
- runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertContentEquals(expectedOutput);
+ runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst().assertAttributeEquals("record.count", "5");
+ runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst().assertContentEquals(expectedOutput);
}
@Test
@@ -493,8 +509,8 @@ public class TestForkRecord {
runner.assertTransferCount(ForkRecord.REL_FORK, 1);
final String expectedOutput = JsonUtil.getExpectedContent(Paths.get("src/test/resources/TestForkRecord/output/extract-address-without-parents.json"));
- runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertAttributeEquals("record.count", "5");
- runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertContentEquals(expectedOutput);
+ runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst().assertAttributeEquals("record.count", "5");
+ runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst().assertContentEquals(expectedOutput);
}
@Test
@@ -523,8 +539,21 @@ public class TestForkRecord {
runner.assertTransferCount(ForkRecord.REL_FORK, 1);
final String expectedOutput = JsonUtil.getExpectedContent(Paths.get("src/test/resources/TestForkRecord/output/extract-address-with-parents.json"));
- runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertAttributeEquals("record.count", "5");
- runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).get(0).assertContentEquals(expectedOutput);
+ runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst().assertAttributeEquals("record.count", "5");
+ runner.getFlowFilesForRelationship(ForkRecord.REL_FORK).getFirst().assertContentEquals(expectedOutput);
+ }
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "record-reader", ForkRecord.RECORD_READER.getName(),
+ "record-writer", ForkRecord.RECORD_WRITER.getName(),
+ "fork-mode", ForkRecord.MODE.getName(),
+ "include-parent-fields", ForkRecord.INCLUDE_PARENT_FIELDS.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
}
private class JsonRecordReader extends AbstractControllerService implements RecordReaderFactory {
@@ -549,7 +578,7 @@ public class TestForkRecord {
}
}
- private class CustomRecordWriter extends MockRecordWriter {
+ private static class CustomRecordWriter extends MockRecordWriter {
RecordSchema schema;
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java
index b6602e50a6..e867caf94c 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateFlowFile.java
@@ -17,10 +17,14 @@
package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Map;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -28,10 +32,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* Unit tests for the GenerateFlowFile processor.
*/
public class TestGenerateFlowFile {
+ private TestRunner runner;
+
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(new GenerateFlowFile());
+ }
@Test
public void testGenerateCustomText() {
- TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "100MB");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_TEXT);
runner.setProperty(GenerateFlowFile.CUSTOM_TEXT, "This is my custom text!");
@@ -39,14 +48,13 @@ public class TestGenerateFlowFile {
runner.run();
runner.assertTransferCount(GenerateFlowFile.SUCCESS, 1);
- MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(0);
+ MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).getFirst();
generatedFlowFile.assertContentEquals("This is my custom text!");
generatedFlowFile.assertAttributeNotExists("mime.type");
}
@Test
public void testInvalidCustomText() {
- TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "100MB");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_BINARY);
runner.setProperty(GenerateFlowFile.CUSTOM_TEXT, "This is my custom text!");
@@ -59,7 +67,6 @@ public class TestGenerateFlowFile {
@Test
public void testDynamicPropertiesToAttributes() {
- TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "1B");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_TEXT);
runner.setProperty(GenerateFlowFile.MIME_TYPE, "application/text");
@@ -70,7 +77,7 @@ public class TestGenerateFlowFile {
runner.run();
runner.assertTransferCount(GenerateFlowFile.SUCCESS, 1);
- MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(0);
+ MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).getFirst();
generatedFlowFile.assertAttributeEquals("plain.dynamic.property", "Plain Value");
generatedFlowFile.assertAttributeEquals("expression.dynamic.property", "Expression Value");
generatedFlowFile.assertAttributeEquals("mime.type", "application/text");
@@ -78,7 +85,6 @@ public class TestGenerateFlowFile {
@Test
public void testContextParametersToAttributes() {
- TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setParameterContextValue("context.parameter.property", "context.parameter.value");
runner.setProperty(GenerateFlowFile.FILE_SIZE, "1B");
runner.setProperty(GenerateFlowFile.DATA_FORMAT, GenerateFlowFile.DATA_FORMAT_TEXT);
@@ -89,7 +95,7 @@ public class TestGenerateFlowFile {
runner.run();
runner.assertTransferCount(GenerateFlowFile.SUCCESS, 1);
- MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(0);
+ MockFlowFile generatedFlowFile = runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).getFirst();
generatedFlowFile.assertAttributeEquals("expression.context.parameter", "context.parameter.value");
generatedFlowFile.assertAttributeEquals("mime.type", "application/text");
}
@@ -97,7 +103,6 @@ public class TestGenerateFlowFile {
@Test
public void testExpressionLanguageSupport() {
- TestRunner runner = TestRunners.newTestRunner(new GenerateFlowFile());
runner.setProperty(GenerateFlowFile.FILE_SIZE, "${nextInt()}B");
runner.setProperty(GenerateFlowFile.UNIQUE_FLOWFILES, "true");
runner.setProperty(GenerateFlowFile.BATCH_SIZE, "2");
@@ -120,5 +125,16 @@ public class TestGenerateFlowFile {
assertEquals(runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(0).getSize(), runner.getFlowFilesForRelationship(GenerateFlowFile.SUCCESS).get(1).getSize());
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "generate-ff-custom-text", GenerateFlowFile.CUSTOM_TEXT.getName(),
+ "character-set", GenerateFlowFile.CHARSET.getName(),
+ "mime-type", GenerateFlowFile.MIME_TYPE.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java
index 8b0ba18a95..399a394cd6 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateRecord.java
@@ -31,6 +31,7 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.serialization.record.type.RecordDataType;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -46,7 +47,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
@@ -85,7 +85,7 @@ public class TestGenerateRecord {
testRunner.run();
testRunner.assertTransferCount(GenerateRecord.REL_SUCCESS, 1);
- MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).getFirst();
final String output = flowFile.getContent();
for (String line : output.split(System.lineSeparator())) {
// A null value would not be output so a comma would be the last character on the line
@@ -114,7 +114,7 @@ public class TestGenerateRecord {
testRunner.run();
testRunner.assertTransferCount(GenerateRecord.REL_SUCCESS, 1);
- MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).getFirst();
final String output = flowFile.getContent();
for (String line : output.split(System.lineSeparator())) {
// A null value would not be output so a comma would be the last character on the line
@@ -143,7 +143,7 @@ public class TestGenerateRecord {
testRunner.run();
testRunner.assertTransferCount(GenerateRecord.REL_SUCCESS, 1);
- MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).getFirst();
// null values should cause all fields to be empty in the output
// create a string of commas whose number equals the number of fields in the datatypeFunctionMap (size - 1 copies)
flowFile.assertContentEquals(String.join("", Collections.nCopies(FakerUtils.getDatatypeFunctionMap().size() - 1, ",")) + "\n");
@@ -153,7 +153,7 @@ public class TestGenerateRecord {
@Test
public void testFieldsReturnValue() throws Exception {
- List<Field> fieldTypeFields = Arrays.stream(GenerateRecord.class.getFields()).filter((field) -> field.getName().startsWith("FT_")).collect(Collectors.toList());
+ List<Field> fieldTypeFields = Arrays.stream(GenerateRecord.class.getFields()).filter((field) -> field.getName().startsWith("FT_")).toList();
for (Field field : fieldTypeFields) {
testRunner.setProperty(field.getName().toLowerCase(Locale.ROOT), ((AllowableValue) field.get(processor)).getValue());
}
@@ -190,7 +190,7 @@ public class TestGenerateRecord {
testRunner.run();
testRunner.assertTransferCount(GenerateRecord.REL_SUCCESS, 1);
- MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).getFirst();
final String output = flowFile.getContent();
for (String line : output.split(System.lineSeparator())) {
// A null value would not be output so a comma would be the last character on the line
@@ -214,7 +214,7 @@ public class TestGenerateRecord {
testRunner.run();
testRunner.assertTransferCount(GenerateRecord.REL_SUCCESS, 1);
- final MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).get(0);
+ final MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).getFirst();
final AvroReader avroReader = new AvroReader();
testRunner.addControllerService("avroReader", avroReader);
@@ -222,7 +222,7 @@ public class TestGenerateRecord {
final byte[] validFlowFileBytes = flowFile.toByteArray();
try (
final ByteArrayInputStream resultContentStream = new ByteArrayInputStream(validFlowFileBytes);
- final RecordReader recordReader = avroReader.createRecordReader(flowFile.getAttributes(), resultContentStream, validFlowFileBytes.length, testRunner.getLogger());
+ final RecordReader recordReader = avroReader.createRecordReader(flowFile.getAttributes(), resultContentStream, validFlowFileBytes.length, testRunner.getLogger())
) {
// Check correct schema
final RecordSchema resultSchema = recordReader.getSchema();
@@ -283,8 +283,22 @@ public class TestGenerateRecord {
testRunner.run();
testRunner.assertTransferCount(GenerateRecord.REL_SUCCESS, 1);
- MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = testRunner.getFlowFilesForRelationship(GenerateRecord.REL_SUCCESS).getFirst();
// null values should cause all fields to be empty in the output (2 top-level record fields in this case
flowFile.assertContentEquals(",\n");
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "record-writer", GenerateRecord.RECORD_WRITER.getName(),
+ "number-of-records", GenerateRecord.NUM_RECORDS.getName(),
+ "nullable-fields", GenerateRecord.NULLABLE_FIELDS.getName(),
+ "null-percentage", GenerateRecord.NULL_PERCENTAGE.getName(),
+ "schema-text", GenerateRecord.SCHEMA_TEXT.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = testRunner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java
index 696f7211d0..0cf73811f9 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGenerateTableFetch.java
@@ -21,6 +21,7 @@ import org.apache.nifi.components.state.StateManager;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessSession;
import org.apache.nifi.util.MockSessionFactory;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -376,7 +377,7 @@ class TestGenerateTableFetch extends AbstractDatabaseConnectionServiceTest {
runner.setProperty(GenerateTableFetch.TABLE_NAME, "TEST_QUERY_DB_TABLE");
runner.setIncomingConnection(false);
runner.setProperty(GenerateTableFetch.MAX_VALUE_COLUMN_NAMES, "ID");
- // Set partition size to 0 so we can see that the flow file gets all rows
+ // Set partition size to 0, so we can see that the flow file gets all rows
runner.setProperty(GenerateTableFetch.PARTITION_SIZE, "0");
runner.run();
@@ -396,7 +397,7 @@ class TestGenerateTableFetch extends AbstractDatabaseConnectionServiceTest {
runner.setIncomingConnection(false);
runner.setProperty(GenerateTableFetch.COLUMN_NAMES, "ID,BUCKET");
runner.setProperty(GenerateTableFetch.MAX_VALUE_COLUMN_NAMES, "ID");
- // Set partition size to 0 so we can see that the flow file gets all rows
+ // Set partition size to 0, so we can see that the flow file gets all rows
runner.setProperty(GenerateTableFetch.PARTITION_SIZE, "1");
runner.setProperty(GenerateTableFetch.OUTPUT_EMPTY_FLOWFILE_ON_ZERO_RESULTS, "false");
@@ -427,7 +428,7 @@ class TestGenerateTableFetch extends AbstractDatabaseConnectionServiceTest {
runner.setProperty(GenerateTableFetch.TABLE_NAME, "TEST_QUERY_DB_TABLE");
runner.setIncomingConnection(false);
runner.setProperty(GenerateTableFetch.MAX_VALUE_COLUMN_NAMES, "ID, BUCKET");
- // Set partition size to 1 so we can compare flow files to records
+ // Set partition size to 1, so we can compare flow files to records
runner.setProperty(GenerateTableFetch.PARTITION_SIZE, "1");
runner.run();
@@ -1098,6 +1099,22 @@ class TestGenerateTableFetch extends AbstractDatabaseConnectionServiceTest {
runner.clearTransferState();
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("db-fetch-db-type", AbstractDatabaseFetchProcessor.DB_TYPE.getName()),
+ Map.entry("db-fetch-where-clause", AbstractDatabaseFetchProcessor.WHERE_CLAUSE.getName()),
+ Map.entry("db-fetch-sql-query", AbstractDatabaseFetchProcessor.SQL_QUERY.getName()),
+ Map.entry("gen-table-fetch-partition-size", GenerateTableFetch.PARTITION_SIZE.getName()),
+ Map.entry("gen-table-column-for-val-partitioning", GenerateTableFetch.COLUMN_FOR_VALUE_PARTITIONING.getName()),
+ Map.entry("gen-table-output-flowfile-on-zero-results", GenerateTableFetch.OUTPUT_EMPTY_FLOWFILE_ON_ZERO_RESULTS.getName()),
+ Map.entry("gen-table-custom-orderby-column", GenerateTableFetch.CUSTOM_ORDERBY_COLUMN.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void assertResultsFound(final String query, final int results) throws SQLException {
int resultsFound = 0;
try (
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java
index ac2a074e02..d2214c7e29 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestIdentifyMimeType.java
@@ -231,6 +231,20 @@ class TestIdentifyMimeType {
assertEquals(expectedExtension, extension, "Expected " + file + " to have extension " + expectedExtension + ", but it was " + extension);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "use-filename-in-detection", IdentifyMimeType.USE_FILENAME_IN_DETECTION.getName(),
+ "config-strategy", IdentifyMimeType.CONFIG_STRATEGY.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+
+ final Set<String> expectedRemoved = Set.of("config-file", "config-body");
+ assertEquals(expectedRemoved, propertyMigrationResult.getPropertiesRemoved());
+ }
+
private static Stream<Arguments> replaceWithConfigFileData() {
final Map<String, String> expectedMimeTypes = new HashMap<>();
expectedMimeTypes.put("1.7z", "application/octet-stream");
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java
index bb322de6f0..0b3f96e896 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListDatabaseTables.java
@@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.serialization.record.MockRecordWriter;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -27,6 +28,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -160,6 +162,23 @@ class TestListDatabaseTables extends AbstractDatabaseConnectionServiceTest {
runner.assertTransferCount(ListDatabaseTables.REL_SUCCESS, 2);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("list-db-tables-db-connection", ListDatabaseTables.DBCP_SERVICE.getName()),
+ Map.entry("list-db-tables-catalog", ListDatabaseTables.CATALOG.getName()),
+ Map.entry("list-db-tables-schema-pattern", ListDatabaseTables.SCHEMA_PATTERN.getName()),
+ Map.entry("list-db-tables-name-pattern", ListDatabaseTables.TABLE_NAME_PATTERN.getName()),
+ Map.entry("list-db-tables-types", ListDatabaseTables.TABLE_TYPES.getName()),
+ Map.entry("list-db-include-count", ListDatabaseTables.INCLUDE_COUNT.getName()),
+ Map.entry("list-db-refresh-interval", ListDatabaseTables.REFRESH_INTERVAL.getName()),
+ Map.entry("record-writer", ListDatabaseTables.RECORD_WRITER.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void createTables() throws SQLException {
createFirstTable();
createSecondTable();
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java
index 8b2e8bc5c6..7c6529a475 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListFile.java
@@ -27,9 +27,11 @@ import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.util.file.transfer.FileInfo;
import org.apache.nifi.processor.util.list.AbstractListProcessor;
import org.apache.nifi.processor.util.list.ListProcessorTestWatcher;
+import org.apache.nifi.processor.util.list.ListedEntityTracker;
import org.apache.nifi.util.LogMessage;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeAll;
@@ -57,6 +59,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -890,11 +893,34 @@ public class TestListFile {
assertEquals(2, runner.getFlowFilesForRelationship(ListFile.REL_SUCCESS).size());
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("track-performance", ListFile.TRACK_PERFORMANCE.getName()),
+ Map.entry("max-performance-metrics", ListFile.MAX_TRACKED_FILES.getName()),
+ Map.entry("max-operation-time", ListFile.MAX_DISK_OPERATION_TIME.getName()),
+ Map.entry("max-listing-time", ListFile.MAX_LISTING_TIME.getName()),
+ Map.entry(ListedEntityTracker.OLD_TRACKING_STATE_CACHE_PROPERTY_NAME, ListedEntityTracker.TRACKING_STATE_CACHE.getName()),
+ Map.entry(ListedEntityTracker.OLD_TRACKING_TIME_WINDOW_PROPERTY_NAME, ListedEntityTracker.TRACKING_TIME_WINDOW.getName()),
+ Map.entry(ListedEntityTracker.OLD_INITIAL_LISTING_TARGET_PROPERTY_NAME, ListedEntityTracker.INITIAL_LISTING_TARGET.getName()),
+ Map.entry(ListedEntityTracker.OLD_NODE_IDENTIFIER_PROPERTY_NAME, ListedEntityTracker.NODE_IDENTIFIER.getName()),
+ Map.entry("target-system-timestamp-precision", AbstractListProcessor.TARGET_SYSTEM_TIMESTAMP_PRECISION.getName()),
+ Map.entry("listing-strategy", AbstractListProcessor.LISTING_STRATEGY.getName()),
+ Map.entry("record-writer", AbstractListProcessor.RECORD_WRITER.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+
+ final Set<String> expectedRemoved = Set.of("Distributed Cache Service");
+ assertEquals(expectedRemoved, propertyMigrationResult.getPropertiesRemoved());
+ }
+
/*
* HFS+, default for OS X, only has granularity to one second, accordingly, we go back in time to establish consistent test cases
*
* Provides "now" minus 1 second in millis
- */
+ */
private static long getTestModifiedTime() {
final long nowMillis = System.currentTimeMillis();
// Subtract a second to avoid possible rounding issues
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java
index 9d829d8c39..db4ad68d24 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenHTTP.java
@@ -43,6 +43,7 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.ssl.SSLContextProvider;
import org.apache.nifi.util.FlowFilePackagerV3;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.eclipse.jetty.server.NetworkConnector;
@@ -543,6 +544,25 @@ public class TestListenHTTP {
return parser;
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("health-check-port", ListenHTTP.HEALTH_CHECK_PORT.getName()),
+ Map.entry("Authorized DN Pattern", ListenHTTP.AUTHORIZED_DN_PATTERN.getName()),
+ Map.entry("authorized-issuer-dn-pattern", ListenHTTP.AUTHORIZED_ISSUER_DN_PATTERN.getName()),
+ Map.entry("multipart-request-max-size", ListenHTTP.MULTIPART_REQUEST_MAX_SIZE.getName()),
+ Map.entry("multipart-read-buffer-size", ListenHTTP.MULTIPART_READ_BUFFER_SIZE.getName()),
+ Map.entry("client-authentication", ListenHTTP.CLIENT_AUTHENTICATION.getName()),
+ Map.entry("max-thread-pool-size", ListenHTTP.MAX_THREAD_POOL_SIZE.getName()),
+ Map.entry("record-reader", ListenHTTP.RECORD_READER.getName()),
+ Map.entry("record-writer", ListenHTTP.RECORD_WRITER.getName()),
+ Map.entry("HTTP Headers to receive as Attributes (Regex)", ListenHTTP.HEADERS_AS_ATTRIBUTES_REGEX.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private int startSecureServer() {
runner.setProperty(ListenHTTP.BASE_PATH, HTTP_BASE_PATH);
runner.setProperty(ListenHTTP.RETURN_CODE, Integer.toString(HttpServletResponse.SC_NO_CONTENT));
@@ -823,9 +843,7 @@ public class TestListenHTTP {
final List<ProvenanceEventRecord> provenanceEvents = runner.getProvenanceEvents();
assertEquals(2, provenanceEvents.size());
- provenanceEvents.forEach(provenanceEvent -> {
- assertEquals("urn:nifi:dummy-uuid", provenanceEvent.getSourceSystemFlowFileIdentifier());
- });
+ provenanceEvents.forEach(provenanceEvent -> assertEquals("urn:nifi:dummy-uuid", provenanceEvent.getSourceSystemFlowFileIdentifier()));
}
private byte[] generateRandomBinaryData() {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCP.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCP.java
index 6bc9445b50..d7e4704fe4 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCP.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenTCP.java
@@ -30,6 +30,7 @@ import org.apache.nifi.security.ssl.StandardSslContextBuilder;
import org.apache.nifi.security.util.ClientAuth;
import org.apache.nifi.ssl.SSLContextProvider;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeAll;
@@ -46,9 +47,13 @@ import java.security.cert.X509Certificate;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import javax.net.ssl.SSLContext;
import javax.security.auth.x500.X500Principal;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class TestListenTCP {
private static final String CLIENT_CERTIFICATE_SUBJECT_DN_ATTRIBUTE = "client.certificate.subject.dn";
private static final String CLIENT_CERTIFICATE_ISSUER_DN_ATTRIBUTE = "client.certificate.issuer.dn";
@@ -188,6 +193,22 @@ public class TestListenTCP {
}
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("pool-receive-buffers", ListenTCP.POOL_RECV_BUFFERS.getName()),
+ Map.entry("idle-timeout", ListenTCP.IDLE_CONNECTION_TIMEOUT.getName()),
+ Map.entry(ListenerProperties.OLD_WORKER_THREADS_PROPERTY_NAME, ListenerProperties.WORKER_THREADS.getName()),
+ Map.entry(ListenerProperties.OLD_MESSAGE_DELIMITER_PROPERTY_NAME, ListenerProperties.MESSAGE_DELIMITER.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+
+ final Set<String> expectedRemoved = Set.of("max-receiving-threads");
+ assertEquals(expectedRemoved, propertyMigrationResult.getPropertiesRemoved());
+ }
+
private void run(final List<String> messages, final int flowFiles, final SSLContext sslContext) throws Exception {
runner.setProperty(ListenTCP.PORT, "0");
final String message = StringUtils.join(messages, null);
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java
index 8de2185d5f..84589a684c 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestListenUDPRecord.java
@@ -26,31 +26,35 @@ import org.apache.nifi.schema.access.SchemaAccessUtils;
import org.apache.nifi.serialization.RecordReaderFactory;
import org.apache.nifi.serialization.record.MockRecordWriter;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import java.io.IOException;
import java.nio.channels.SelectableChannel;
import java.nio.charset.StandardCharsets;
+import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class TestListenUDPRecord {
- static final String SCHEMA_TEXT = "{\n" +
- " \"name\": \"syslogRecord\",\n" +
- " \"namespace\": \"nifi\",\n" +
- " \"type\": \"record\",\n" +
- " \"fields\": [\n" +
- " { \"name\": \"timestamp\", \"type\": \"string\" },\n" +
- " { \"name\": \"logsource\", \"type\": \"string\" },\n" +
- " { \"name\": \"message\", \"type\": \"string\" }\n" +
- " ]\n" +
- "}";
+ static final String SCHEMA_TEXT = """
+ {
+ "name": "syslogRecord",
+ "namespace": "nifi",
+ "type": "record",
+ "fields": [
+ { "name": "timestamp", "type": "string" },
+ { "name": "logsource", "type": "string" },
+ { "name": "message", "type": "string" }
+ ]
+ }""";
static final String DATAGRAM_1 = "[ {\"timestamp\" : \"123456789\", \"logsource\" : \"syslog\", \"message\" : \"This is a test 1\"} ]";
static final String DATAGRAM_2 = "[ {\"timestamp\" : \"123456789\", \"logsource\" : \"syslog\", \"message\" : \"This is a test 2\"} ]";
@@ -110,7 +114,7 @@ public class TestListenUDPRecord {
runner.run();
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
- final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
+ final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "3");
}
@@ -133,7 +137,7 @@ public class TestListenUDPRecord {
runner.run();
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
- MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
+ MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "1");
// batch 2
@@ -141,7 +145,7 @@ public class TestListenUDPRecord {
runner.run();
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
- flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
+ flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "1");
// batch 3
@@ -149,7 +153,7 @@ public class TestListenUDPRecord {
runner.run();
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
- flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
+ flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "1");
// no more left
@@ -171,7 +175,7 @@ public class TestListenUDPRecord {
runner.run();
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_SUCCESS, 1);
- final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).get(0);
+ final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_SUCCESS).getFirst();
flowFile.assertAttributeEquals(ListenUDPRecord.RECORD_COUNT_ATTR, "6");
}
@@ -189,7 +193,7 @@ public class TestListenUDPRecord {
runner.assertTransferCount(ListenUDPRecord.REL_SUCCESS, 1);
runner.assertTransferCount(ListenUDPRecord.REL_PARSE_FAILURE, 1);
- final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_PARSE_FAILURE).get(0);
+ final MockFlowFile flowFile = runner.getFlowFilesForRelationship(ListenUDPRecord.REL_PARSE_FAILURE).getFirst();
flowFile.assertContentEquals("WILL NOT PARSE");
}
@@ -218,13 +222,28 @@ public class TestListenUDPRecord {
runner.assertAllFlowFilesTransferred(ListenUDPRecord.REL_PARSE_FAILURE, 0);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("sending-host", ListenUDPRecord.SENDING_HOST.getName()),
+ Map.entry("sending-host-port", ListenUDPRecord.SENDING_HOST_PORT.getName()),
+ Map.entry("record-reader", ListenUDPRecord.RECORD_READER.getName()),
+ Map.entry("record-writer", ListenUDPRecord.RECORD_WRITER.getName()),
+ Map.entry("poll-timeout", ListenUDPRecord.POLL_TIMEOUT.getName()),
+ Map.entry("batch-size", ListenUDPRecord.BATCH_SIZE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private static class TestableListenUDPRecord extends ListenUDPRecord {
private volatile BlockingQueue<StandardEvent<SelectableChannel>> testEvents = new LinkedBlockingQueue<>();
private volatile BlockingQueue<StandardEvent<SelectableChannel>> testErrorEvents = new LinkedBlockingQueue<>();
@Override
- protected ChannelDispatcher createDispatcher(ProcessContext context, BlockingQueue<StandardEvent> events) throws IOException {
+ protected ChannelDispatcher createDispatcher(ProcessContext context, BlockingQueue<StandardEvent> events) {
return Mockito.mock(ChannelDispatcher.class);
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java
index cdbe43dfad..a74584ecc5 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogAttribute.java
@@ -20,22 +20,32 @@ import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.ProcessSession;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;
import java.util.Map;
+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 TestLogAttribute {
+ private LogAttribute logAttribute;
+ private TestRunner runner;
+
+ @BeforeEach
+ void setUp() {
+ logAttribute = new LogAttribute();
+ runner = TestRunners.newTestRunner(logAttribute);
+ }
+
@Test
public void testLogPropertyCSVNoIgnore() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -57,8 +67,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyRegexNoIgnore() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -80,8 +88,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyWithCSVAndRegexNoIgnore() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -105,8 +111,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyWithIgnoreCSV() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -128,8 +132,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyWithIgnoreRegex() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -151,8 +153,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyWithIgnoreCSVAndRegex() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -176,8 +176,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyCSVWithIgnoreRegex() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -201,8 +199,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyCSVWithIgnoreCSV() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -226,8 +222,6 @@ public class TestLogAttribute {
@Test
public void testLogPropertyRegexWithIgnoreRegex() {
- final LogAttribute logAttribute = new LogAttribute();
- final TestRunner runner = TestRunners.newTestRunner(logAttribute);
final ProcessContext context = runner.getProcessContext();
final ProcessSession session = runner.getProcessSessionFactory().createSession();
final MockComponentLog LOG = runner.getLogger();
@@ -247,4 +241,17 @@ public class TestLogAttribute {
assertTrue(logMessage.contains("foo-value"));
assertFalse(logMessage.contains("bar-value"));
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("attributes-to-log-regex", LogAttribute.ATTRIBUTES_TO_LOG_REGEX.getName()),
+ Map.entry("attributes-to-ignore-regex", LogAttribute.ATTRIBUTES_TO_IGNORE_REGEX.getName()),
+ Map.entry("character-set", LogAttribute.CHARSET.getName()),
+ Map.entry("Log prefix", LogAttribute.LOG_PREFIX.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java
index e172d45189..e72c476b88 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLogMessage.java
@@ -20,6 +20,7 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.AfterEach;
@@ -110,4 +111,16 @@ public class TestLogMessage {
runner.setProperty(LogMessage.LOG_LEVEL, logLevel.name().toUpperCase());
runner.assertValid();
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("log-level", LogMessage.LOG_LEVEL.getName()),
+ Map.entry("log-prefix", LogMessage.LOG_PREFIX.getName()),
+ Map.entry("log-message", LogMessage.LOG_MESSAGE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java
index 7b248ca050..1f07066860 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupAttribute.java
@@ -17,14 +17,15 @@
package org.apache.nifi.processors.standard;
import org.apache.nifi.controller.AbstractControllerService;
-import org.apache.nifi.lookup.LookupFailureException;
import org.apache.nifi.lookup.LookupService;
import org.apache.nifi.lookup.SimpleKeyValueLookupService;
import org.apache.nifi.lookup.StringLookupService;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
@@ -38,11 +39,17 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestLookupAttribute {
+ private TestRunner runner;
+
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(LookupAttribute.class);
+ }
+
@Test
public void testKeyValueLookupAttribute() throws InitializationException {
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
- final TestRunner runner = TestRunners.newTestRunner(new LookupAttribute());
runner.addControllerService("simple-key-value-lookup-service", service);
runner.setProperty(service, "key1", "value1");
runner.setProperty(service, "key2", "value2");
@@ -88,7 +95,6 @@ public class TestLookupAttribute {
public void testLookupAttributeUnmatched() throws InitializationException {
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
- final TestRunner runner = TestRunners.newTestRunner(new LookupAttribute());
runner.addControllerService("simple-key-value-lookup-service", service);
runner.setProperty(service, "key1", "value1");
runner.setProperty(service, "key2", "value2");
@@ -120,7 +126,6 @@ public class TestLookupAttribute {
public void testCustomValidateInvalidLookupService() throws InitializationException {
final InvalidLookupService service = new InvalidLookupService();
- final TestRunner runner = TestRunners.newTestRunner(new LookupAttribute());
runner.addControllerService("invalid-lookup-service", service);
runner.enableControllerService(service);
runner.assertValid(service);
@@ -133,7 +138,6 @@ public class TestLookupAttribute {
public void testCustomValidateMissingDynamicProps() throws InitializationException {
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
- final TestRunner runner = TestRunners.newTestRunner(new LookupAttribute());
runner.addControllerService("simple-key-value-lookup-service", service);
runner.enableControllerService(service);
runner.assertValid(service);
@@ -143,9 +147,8 @@ public class TestLookupAttribute {
@Test
public void testLookupServicePassFlowfileAttributes() throws InitializationException {
- final LookupService service = new TestService();
+ final LookupService<String> service = new TestService();
- final TestRunner runner = TestRunners.newTestRunner(new LookupAttribute());
runner.addControllerService("simple-key-value-lookup-service", service);
runner.enableControllerService(service);
runner.assertValid(service);
@@ -162,6 +165,17 @@ public class TestLookupAttribute {
runner.assertAllFlowFilesTransferred(LookupAttribute.REL_MATCHED, 1);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("lookup-service", LookupAttribute.LOOKUP_SERVICE.getName()),
+ Map.entry("include-empty-values", LookupAttribute.INCLUDE_EMPTY_VALUES.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private static class InvalidLookupService extends AbstractControllerService implements StringLookupService {
@Override
public Optional<String> lookup(Map<String, Object> coordinates) {
@@ -176,7 +190,7 @@ public class TestLookupAttribute {
static class TestService extends AbstractControllerService implements StringLookupService {
@Override
- public Optional<String> lookup(Map<String, Object> coordinates, Map<String, String> context) throws LookupFailureException {
+ public Optional<String> lookup(Map<String, Object> coordinates, Map<String, String> context) {
assertNotNull(coordinates);
assertNotNull(context);
assertEquals(1, coordinates.size());
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java
index c8db5c533f..6281aba141 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestLookupRecord.java
@@ -35,6 +35,7 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -59,12 +60,11 @@ public class TestLookupRecord {
private TestRunner runner;
private MapLookup lookupService;
private MockRecordParser recordReader;
- private MockRecordWriter recordWriter;
@BeforeEach
public void setup() throws InitializationException {
recordReader = new MockRecordParser();
- recordWriter = new MockRecordWriter(null, false);
+ MockRecordWriter recordWriter = new MockRecordWriter(null, false);
lookupService = new MapLookup();
runner = TestRunners.newTestRunner(LookupRecord.class);
@@ -394,8 +394,7 @@ public class TestLookupRecord {
attrs.put("schema.name", "person");
attrs.put("something_something", "test");
- Map<String, Object> expected = new HashMap<>();
- expected.putAll(attrs);
+ Map<String, Object> expected = new HashMap<>(attrs);
lookupService.setExpectedContext(expected);
@@ -407,7 +406,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_MATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
out.assertAttributeEquals("record.count", "3");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -424,7 +423,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_MATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
out.assertAttributeEquals("record.count", "3");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -447,7 +446,7 @@ public class TestLookupRecord {
runner.assertTransferCount(LookupRecord.REL_MATCHED, 1);
runner.assertTransferCount(LookupRecord.REL_UNMATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
out.assertAttributeEquals("record.count", "1");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -461,7 +460,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_UNMATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).getFirst();
out.assertAttributeEquals("record.count", "3");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -480,12 +479,12 @@ public class TestLookupRecord {
runner.assertTransferCount(LookupRecord.REL_MATCHED, 1);
runner.assertTransferCount(LookupRecord.REL_UNMATCHED, 1);
- final MockFlowFile matched = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile matched = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
matched.assertAttributeEquals("record.count", "2");
matched.assertAttributeEquals("mime.type", "text/plain");
matched.assertContentEquals("John Doe,48,Soccer\nJimmy Doe,14,Football\n");
- final MockFlowFile unmatched = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).get(0);
+ final MockFlowFile unmatched = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).getFirst();
unmatched.assertAttributeEquals("record.count", "1");
unmatched.assertAttributeEquals("mime.type", "text/plain");
unmatched.assertContentEquals("Jane Doe,47,\n");
@@ -503,7 +502,7 @@ public class TestLookupRecord {
runner.assertTransferCount(LookupRecord.REL_FAILURE, 0);
runner.assertTransferCount(LookupRecord.REL_SUCCESS, 1);
- final MockFlowFile matched = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).get(0);
+ final MockFlowFile matched = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).getFirst();
matched.assertAttributeEquals("record.count", "3");
matched.assertAttributeEquals("mime.type", "text/plain");
matched.assertContentEquals("John Doe,48,\nJane Doe,47,Soccer\nJimmy Doe,14,Football\n");
@@ -522,7 +521,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_MATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
out.assertAttributeEquals("record.count", "3");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -537,7 +536,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_UNMATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).getFirst();
out.assertAttributeEquals("record.count", "3");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -552,7 +551,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_FAILURE, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_FAILURE).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_FAILURE).getFirst();
out.assertAttributeNotExists("record.count");
out.assertContentEquals("");
}
@@ -569,7 +568,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_MATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
out.assertAttributeEquals("record.count", "3");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -589,7 +588,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_UNMATCHED, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).getFirst();
out.assertAttributeEquals("record.count", "3");
out.assertAttributeEquals("mime.type", "text/plain");
@@ -645,7 +644,7 @@ public class TestLookupRecord {
runner.enqueue("");
runner.run();
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
out.assertContentEquals("John Doe,48,basketball,soccer\n");
}
@@ -687,7 +686,7 @@ public class TestLookupRecord {
runner.enqueue("");
runner.run();
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
// We can't be sure of the order of the fields in the record, so we allow either 'least' or 'favorite' to be first
final String outputContents = new String(out.toByteArray());
@@ -733,7 +732,7 @@ public class TestLookupRecord {
runner.enqueue("");
runner.run();
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
// We can't be sure of the order of the fields in the record, so we allow either 'least' or 'favorite' to be first
final String outputContents = new String(out.toByteArray());
@@ -778,7 +777,7 @@ public class TestLookupRecord {
runner.enqueue("");
runner.run();
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).getFirst();
out.assertContentEquals("John Doe,48,soccer,basketball\nJane Doe,47\n");
}
@@ -820,7 +819,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_SUCCESS);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).getFirst();
out.assertContentEquals(new File("src/test/resources/TestLookupRecord/lookup-array-output.json").toPath());
}
@@ -874,7 +873,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_SUCCESS);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_SUCCESS).getFirst();
out.assertContentEquals(new File("src/test/resources/TestLookupRecord/lookup-array-output-empty-array.json").toPath());
}
@@ -910,11 +909,11 @@ public class TestLookupRecord {
runner.run();
runner.assertTransferCount(LookupRecord.REL_UNMATCHED, 1);
- final MockFlowFile outUnmatched = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).get(0);
+ final MockFlowFile outUnmatched = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).getFirst();
outUnmatched.assertContentEquals(new File("src/test/resources/TestLookupRecord/lookup-array-output-missing-unmatched.json").toPath());
runner.assertTransferCount(LookupRecord.REL_MATCHED, 1);
- final MockFlowFile outMatched = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).get(0);
+ final MockFlowFile outMatched = runner.getFlowFilesForRelationship(LookupRecord.REL_MATCHED).getFirst();
outMatched.assertContentEquals(new File("src/test/resources/TestLookupRecord/lookup-array-output-missing-matched.json").toPath());
}
@@ -955,7 +954,7 @@ public class TestLookupRecord {
runner.run();
runner.assertAllFlowFilesTransferred(LookupRecord.REL_UNMATCHED);
- final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(LookupRecord.REL_UNMATCHED).getFirst();
out.assertContentEquals(new File("src/test/resources/TestLookupRecord/lookup-array-output-unmatched.json").toPath());
}
@@ -972,6 +971,23 @@ public class TestLookupRecord {
runner.assertAllFlowFilesTransferred(LookupRecord.REL_MATCHED, 1);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("record-reader", LookupRecord.RECORD_READER.getName()),
+ Map.entry("record-writer", LookupRecord.RECORD_WRITER.getName()),
+ Map.entry("lookup-service", LookupRecord.LOOKUP_SERVICE.getName()),
+ Map.entry("result-contents", LookupRecord.RESULT_CONTENTS.getName()),
+ Map.entry("routing-strategy", LookupRecord.ROUTING_STRATEGY.getName()),
+ Map.entry("record-update-strategy", LookupRecord.REPLACEMENT_STRATEGY.getName()),
+ Map.entry("result-record-path", LookupRecord.RESULT_RECORD_PATH.getName()),
+ Map.entry("record-path-lookup-miss-result-cache-size", LookupRecord.CACHE_SIZE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private static class MapLookup extends AbstractControllerService implements StringLookupService {
protected final Map<String, String> values = new HashMap<>();
private Map<String, Object> expectedContext;
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java
index 3ebc81c95f..e876c306fc 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java
@@ -33,10 +33,12 @@ import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.flowfile.attributes.StandardFlowFileMediaType;
import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.util.bin.BinFiles;
import org.apache.nifi.processor.util.bin.InsertionLocation;
import org.apache.nifi.processors.standard.merge.AttributeStrategyUtil;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.Test;
@@ -94,7 +96,7 @@ public class TestMergeContent {
assertEquals(1024 * 6, bundle.getSize());
// Queue should not be empty because the first FlowFile will be transferred back to the input queue
- // when we run out @OnStopped logic, since it won't be transferred to any bin.
+ // when we run our @OnStopped logic, since it won't be transferred to any bin.
runner.assertQueueNotEmpty();
}
@@ -618,8 +620,7 @@ public class TestMergeContent {
Collection<ValidationResult> results = new HashSet<>();
ProcessContext context = runner.getProcessContext();
- if (context instanceof MockProcessContext) {
- MockProcessContext mockContext = (MockProcessContext) context;
+ if (context instanceof MockProcessContext mockContext) {
results = mockContext.validate();
}
@@ -1479,4 +1480,17 @@ public class TestMergeContent {
testRunner.enqueue("World!", attributes);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("mergecontent-metadata-strategy", MergeContent.METADATA_STRATEGY.getName()),
+ Map.entry("Header File", MergeContent.HEADER.getName()),
+ Map.entry("Footer File", MergeContent.FOOTER.getName()),
+ Map.entry("Demarcator File", MergeContent.DEMARCATOR.getName()),
+ Map.entry("Maximum number of Bins", BinFiles.MAX_BIN_COUNT.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java
index b90ed8a851..c2098fc77e 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeRecord.java
@@ -26,6 +26,7 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -73,7 +74,7 @@ public class TestMergeRecord {
runner.assertTransferCount(MergeRecord.REL_MERGED, 1);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 1);
- final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).get(0);
+ final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).getFirst();
mff.assertAttributeEquals("record.count", "2");
mff.assertContentEquals("header\nJohn,35\nJane,34\n");
@@ -91,7 +92,7 @@ public class TestMergeRecord {
runner.assertTransferCount(MergeRecord.REL_MERGED, 1);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 2);
- final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).get(0);
+ final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).getFirst();
mff.assertAttributeEquals("record.count", "2");
mff.assertContentEquals("header\nJohn,35\nJane,34\n");
@@ -120,7 +121,7 @@ public class TestMergeRecord {
runner.assertTransferCount(MergeRecord.REL_MERGED, 1);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 2);
- final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).get(0);
+ final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).getFirst();
mff.assertAttributeEquals("record.count", "2");
mff.assertContentEquals("header\nJohn\nJane\n");
@@ -371,7 +372,7 @@ public class TestMergeRecord {
final StringBuilder sb = new StringBuilder("Name, Age\n");
for (int i = 0; i < 100; i++) {
- sb.append("Person " + i + ", " + i + "\n");
+ sb.append("Person ").append(i).append(", ").append(i).append("\n");
}
runner.enqueue(sb.toString());
@@ -404,7 +405,7 @@ public class TestMergeRecord {
final StringBuilder sb = new StringBuilder("Name, Age\n");
for (int i = 0; i < 100; i++) {
- sb.append("Person " + i + ", " + i + "\n");
+ sb.append("Person ").append(i).append(", ").append(i).append("\n");
}
runner.enqueue(sb.toString());
@@ -433,7 +434,7 @@ public class TestMergeRecord {
assertEquals(4, runner.getQueueSize().getObjectCount());
- runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).stream().forEach(ff -> ff.assertAttributeEquals("record.count", "10"));
+ runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).forEach(ff -> ff.assertAttributeEquals("record.count", "10"));
}
@Test
@@ -577,7 +578,7 @@ public class TestMergeRecord {
runner.assertTransferCount(MergeRecord.REL_MERGED, 1);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 3);
- final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).get(0);
+ final MockFlowFile mff = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).getFirst();
mff.assertAttributeEquals("record.count", "3");
mff.assertContentEquals("header\nJohn,35\nJane,34\nAlex,28\n");
runner.clearTransferState();
@@ -596,7 +597,7 @@ public class TestMergeRecord {
runner.assertTransferCount(MergeRecord.REL_MERGED, 2);
runner.assertTransferCount(MergeRecord.REL_ORIGINAL, 5);
- final MockFlowFile mff1 = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).get(0);
+ final MockFlowFile mff1 = runner.getFlowFilesForRelationship(MergeRecord.REL_MERGED).getFirst();
mff1.assertAttributeEquals("record.count", "3");
mff1.assertContentEquals("header\nJohn,35\nJane,34\nAlex,28\n");
@@ -658,4 +659,22 @@ public class TestMergeRecord {
runner.removeProperty("max_records");
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("record-reader", MergeRecord.RECORD_READER.getName()),
+ Map.entry("record-writer", MergeRecord.RECORD_WRITER.getName()),
+ Map.entry("merge-strategy", MergeRecord.MERGE_STRATEGY.getName()),
+ Map.entry("correlation-attribute-name", MergeRecord.CORRELATION_ATTRIBUTE_NAME.getName()),
+ Map.entry("min-bin-size", MergeRecord.MIN_SIZE.getName()),
+ Map.entry("max-bin-size", MergeRecord.MAX_SIZE.getName()),
+ Map.entry("min-records", MergeRecord.MIN_RECORDS.getName()),
+ Map.entry("max-records", MergeRecord.MAX_RECORDS.getName()),
+ Map.entry("max.bin.count", MergeRecord.MAX_BIN_COUNT.getName()),
+ Map.entry("max-bin-age", MergeRecord.MAX_BIN_AGE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java
index 32ac020200..442815f690 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestNotify.java
@@ -23,6 +23,7 @@ import org.apache.nifi.distributed.cache.client.Deserializer;
import org.apache.nifi.distributed.cache.client.Serializer;
import org.apache.nifi.processors.standard.WaitNotifyProtocol.Signal;
import org.apache.nifi.reporting.InitializationException;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -69,7 +70,7 @@ public class TestNotify {
runner.run();
runner.assertAllFlowFilesTransferred(Notify.REL_SUCCESS, 1);
- runner.getFlowFilesForRelationship(Notify.REL_SUCCESS).get(0).assertAttributeEquals(Notify.NOTIFIED_ATTRIBUTE_NAME, "true");
+ runner.getFlowFilesForRelationship(Notify.REL_SUCCESS).getFirst().assertAttributeEquals(Notify.NOTIFIED_ATTRIBUTE_NAME, "true");
runner.clearTransferState();
final Signal signal = new WaitNotifyProtocol(service).getSignal("1");
@@ -357,7 +358,7 @@ public class TestNotify {
public <K, V> V get(final K key, final Serializer<K> keySerializer, final Deserializer<V> valueDeserializer) throws IOException {
verifyNotFail();
- final AtomicCacheEntry entry = values.get(key);
+ final AtomicCacheEntry<?, ?, ?> entry = values.get(key);
if (entry == null) {
return null;
}
@@ -400,5 +401,18 @@ public class TestNotify {
}
}
-
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("distributed-cache-service", Notify.DISTRIBUTED_CACHE_SERVICE.getName()),
+ Map.entry("release-signal-id", Notify.RELEASE_SIGNAL_IDENTIFIER.getName()),
+ Map.entry("signal-counter-name", Notify.SIGNAL_COUNTER_NAME.getName()),
+ Map.entry("signal-counter-delta", Notify.SIGNAL_COUNTER_DELTA.getName()),
+ Map.entry("signal-buffer-count", Notify.SIGNAL_BUFFER_COUNT.getName()),
+ Map.entry("attribute-cache-regex", Notify.ATTRIBUTE_CACHE_REGEX.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPackageFlowFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPackageFlowFile.java
index fbf5eebe58..7b3528a85d 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPackageFlowFile.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPackageFlowFile.java
@@ -21,6 +21,7 @@ import org.apache.nifi.flowfile.attributes.StandardFlowFileMediaType;
import org.apache.nifi.util.FlowFileUnpackager;
import org.apache.nifi.util.FlowFileUnpackagerV3;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.Assertions;
@@ -32,6 +33,8 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class TestPackageFlowFile {
private static final String SAMPLE_CONTENT = "Hello, World!";
@@ -155,4 +158,12 @@ public class TestPackageFlowFile {
runner.assertTransferCount(PackageFlowFile.REL_ORIGINAL, 7);
runner.assertQueueNotEmpty();
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of("max-batch-size", PackageFlowFile.BATCH_SIZE.getName());
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java
index 401d330607..3cf799f518 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestParseSyslog5424.java
@@ -20,12 +20,16 @@ package org.apache.nifi.processors.standard;
import com.github.palindromicity.syslog.NilPolicy;
import org.apache.nifi.syslog.attributes.SyslogAttributes;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
+import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
@@ -39,9 +43,15 @@ public class TestParseSyslog5424 {
+ " [exampleSDID@32473 iut=\"3\" eventSource=\"Application\" eventID=\"1011\"]"
+ " [exampleSDID@32480 iut=\"4\" eventSource=\"Other Application\" eventID=\"2022\"] Removing instance";
+ private TestRunner runner;
+
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(ParseSyslog5424.class);
+ }
+
@Test
public void testValidMessage() {
- final TestRunner runner = TestRunners.newTestRunner(new ParseSyslog5424());
runner.setProperty(ParseSyslog5424.NIL_POLICY, NilPolicy.DASH.name());
runner.enqueue(SYSLOG_LINE_ALL.getBytes());
runner.run();
@@ -50,7 +60,6 @@ public class TestParseSyslog5424 {
@Test
public void testValidMessageWithNils() {
- final TestRunner runner = TestRunners.newTestRunner(new ParseSyslog5424());
runner.setProperty(ParseSyslog5424.NIL_POLICY, NilPolicy.DASH.name());
runner.enqueue(SYSLOG_LINE_NILS.getBytes());
runner.run();
@@ -59,7 +68,6 @@ public class TestParseSyslog5424 {
@Test
public void testInvalidMessage() {
- final TestRunner runner = TestRunners.newTestRunner(new ParseSyslog5424());
runner.setProperty(ParseSyslog5424.NIL_POLICY, NilPolicy.OMIT.name());
runner.enqueue("<hello> yesterday localhost\n".getBytes());
runner.run();
@@ -69,36 +77,44 @@ public class TestParseSyslog5424 {
@Test
public void testDefaultHasBodyAttribute() {
- final TestRunner runner = TestRunners.newTestRunner(new ParseSyslog5424());
runner.setProperty(ParseSyslog5424.NIL_POLICY, NilPolicy.DASH.name());
runner.enqueue(SYSLOG_LINE_NILS.getBytes());
runner.run();
runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS, 1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS);
- assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
+ assertNotNull(results.getFirst().getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
}
@Test
public void testIncludeBodyAttributeTrue() {
- final TestRunner runner = TestRunners.newTestRunner(new ParseSyslog5424());
runner.setProperty(ParseSyslog5424.NIL_POLICY, NilPolicy.DASH.name());
runner.setProperty(ParseSyslog5424.INCLUDE_BODY_IN_ATTRIBUTES, "true");
runner.enqueue(SYSLOG_LINE_NILS.getBytes());
runner.run();
runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS, 1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS);
- assertNotNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
+ assertNotNull(results.getFirst().getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
}
@Test
public void testIncludeBodyAttributeFalse() {
- final TestRunner runner = TestRunners.newTestRunner(new ParseSyslog5424());
runner.setProperty(ParseSyslog5424.NIL_POLICY, NilPolicy.DASH.name());
runner.setProperty(ParseSyslog5424.INCLUDE_BODY_IN_ATTRIBUTES, "false");
runner.enqueue(SYSLOG_LINE_NILS.getBytes());
runner.run();
runner.assertAllFlowFilesTransferred(ParseSyslog5424.REL_SUCCESS, 1);
List<MockFlowFile> results = runner.getFlowFilesForRelationship(ParseSyslog5424.REL_SUCCESS);
- assertNull(results.get(0).getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
+ assertNull(results.getFirst().getAttribute(SyslogAttributes.SYSLOG_BODY.key()));
+ }
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "nil_policy", ParseSyslog5424.NIL_POLICY.getName(),
+ "include_policy", ParseSyslog5424.INCLUDE_BODY_IN_ATTRIBUTES.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
}
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java
index 0df24eac68..01d4a4d3d6 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPartitionRecord.java
@@ -22,6 +22,7 @@ import org.apache.nifi.serialization.record.MockRecordParser;
import org.apache.nifi.serialization.record.MockRecordWriter;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -29,6 +30,7 @@ import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.List;
+import java.util.Map;
import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -38,12 +40,11 @@ public class TestPartitionRecord {
private TestRunner runner;
private MockRecordParser readerService;
- private MockRecordWriter writerService;
@BeforeEach
public void setup() throws InitializationException {
readerService = new MockRecordParser();
- writerService = new MockRecordWriter(null, false);
+ MockRecordWriter writerService = new MockRecordWriter(null, false);
runner = TestRunners.newTestRunner(PartitionRecord.class);
runner.addControllerService("reader", readerService);
@@ -82,7 +83,7 @@ public class TestPartitionRecord {
assertEquals(3L, out.stream().filter(ff -> ff.getAttribute("record.count").equals("1")).count());
assertEquals(1L, out.stream().filter(ff -> ff.getAttribute("record.count").equals("2")).count());
out.forEach(ff -> ff.assertAttributeEquals("fragment.count", "4"));
- IntStream.of(1, 3).forEach((i) -> out.get(i).assertAttributeEquals("fragment.id", out.get(0).getAttribute("fragment.id")));
+ IntStream.of(1, 3).forEach((i) -> out.get(i).assertAttributeEquals("fragment.id", out.getFirst().getAttribute("fragment.id")));
IntStream.of(0, 3).forEach((i) -> assertEquals(1L, out.stream().filter(ff -> ff.getAttribute("fragment.index").equals(String.valueOf(i))).count()));
out.stream().filter(ff -> ff.getAttribute("record.count").equals("2")).forEach(ff -> ff.assertContentEquals("Jake,49,\nJake,14,\n"));
@@ -167,7 +168,7 @@ public class TestPartitionRecord {
runner.assertTransferCount(PartitionRecord.REL_FAILURE, 0);
runner.assertTransferCount(PartitionRecord.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(PartitionRecord.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(PartitionRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "5");
out.assertContentEquals("John,30,\nJake,30,\nMark,30,\nJane,30,\nJake,30,\n");
out.assertAttributeEquals("age", "30");
@@ -240,7 +241,7 @@ public class TestPartitionRecord {
runner.run();
runner.assertAllFlowFilesTransferred(PartitionRecord.REL_FAILURE, 1);
- runner.getFlowFilesForRelationship(PartitionRecord.REL_FAILURE).get(0).assertContentEquals(new byte[0]);
+ runner.getFlowFilesForRelationship(PartitionRecord.REL_FAILURE).getFirst().assertContentEquals(new byte[0]);
}
@@ -252,4 +253,14 @@ public class TestPartitionRecord {
assertEquals(new PartitionRecord.ValueWrapper(a), new PartitionRecord.ValueWrapper(b));
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "record-reader", PartitionRecord.RECORD_READER.getName(),
+ "record-writer", PartitionRecord.RECORD_WRITER.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
index 3a2eccac2e..8d1b695f35 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutEmail.java
@@ -27,6 +27,7 @@ import org.apache.commons.codec.binary.StringUtils;
import org.apache.commons.io.IOUtils;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.oauth2.OAuth2AccessTokenProvider;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -132,7 +133,7 @@ public class TestPutEmail {
// Verify that the Message was populated correctly
assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
- Message message = processor.getMessages().get(0);
+ Message message = processor.getMessages().getFirst();
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("TestingNiFi", message.getHeader("X-Mailer")[0], "X-Mailer Header");
assertEquals("Message Body", getMessageText(message, StandardCharsets.UTF_8));
@@ -170,7 +171,7 @@ public class TestPutEmail {
runner.assertAllFlowFilesTransferred(PutEmail.REL_SUCCESS);
assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
- Message message = processor.getMessages().get(0);
+ Message message = processor.getMessages().getFirst();
assertEquals("XOAUTH2", message.getSession().getProperty("mail.smtp.auth.mechanisms"));
assertEquals("access_token_123", message.getSession().getProperty("mail.smtp.password"));
}
@@ -207,7 +208,7 @@ public class TestPutEmail {
// Verify that the Message was populated correctly
assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
- Message message = processor.getMessages().get(0);
+ Message message = processor.getMessages().getFirst();
assertEquals("\"test@apache.org\" <NiFi>", message.getFrom()[0].toString());
assertEquals("TestingNÃFiNonASCII", MimeUtility.decodeText(message.getHeader("X-Mailer")[0]), "X-Mailer Header");
assertEquals("the message body", getMessageText(message, StandardCharsets.UTF_8));
@@ -281,7 +282,7 @@ public class TestPutEmail {
// Verify that the Message was populated correctly
assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
- Message message = processor.getMessages().get(0);
+ Message message = processor.getMessages().getFirst();
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("TestingNiFi", message.getHeader("X-Mailer")[0], "X-Mailer Header");
assertEquals("recipient@apache.org", message.getRecipients(RecipientType.TO)[0].toString());
@@ -326,7 +327,7 @@ public class TestPutEmail {
// Verify that the Message was populated correctly
assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
- Message message = processor.getMessages().get(0);
+ Message message = processor.getMessages().getFirst();
assertEquals("test@apache.org", message.getFrom()[0].toString());
assertEquals("from@apache.org", message.getFrom()[1].toString());
assertEquals("TestingNiFi", message.getHeader("X-Mailer")[0], "X-Mailer Header");
@@ -409,11 +410,26 @@ public class TestPutEmail {
// Verify that the Message was populated correctly
assertEquals(1, processor.getMessages().size(), "Expected a single message to be sent");
- Message message = processor.getMessages().get(0);
+ Message message = processor.getMessages().getFirst();
final String retrievedMessageText = getMessageText(message, StandardCharsets.UTF_8);
assertNotEquals(rawString, retrievedMessageText);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("authorization-mode", PutEmail.AUTHORIZATION_MODE.getName()),
+ Map.entry("oauth2-access-token-provider", PutEmail.OAUTH2_ACCESS_TOKEN_PROVIDER.getName()),
+ Map.entry("SMTP TLS", PutEmail.SMTP_TLS.getName()),
+ Map.entry("attribute-name-regex", PutEmail.ATTRIBUTE_NAME_REGEX.getName()),
+ Map.entry("email-ff-content-as-message", PutEmail.CONTENT_AS_MESSAGE.getName()),
+ Map.entry("input-character-set", PutEmail.INPUT_CHARACTER_SET.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void setRequiredProperties(final TestRunner runner) {
// values here may be overridden in some tests
runner.setProperty(PutEmail.SMTP_HOSTNAME, "smtp-host");
@@ -423,8 +439,7 @@ public class TestPutEmail {
}
private String getMessageText(final Message message, final Charset charset) throws Exception {
- if (message.getContent() instanceof MimeMultipart) {
- final MimeMultipart multipart = (MimeMultipart) message.getContent();
+ if (message.getContent() instanceof MimeMultipart multipart) {
final BodyPart part = multipart.getBodyPart(0);
final InputStream is = part.getDataHandler().getInputStream();
final String encoding = StandardCharsets.US_ASCII.equals(charset) ? "7bit" : "base64";
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java
index e6373470ee..e88289c05d 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutRecord.java
@@ -18,11 +18,15 @@ package org.apache.nifi.processors.standard;
import org.apache.nifi.serialization.record.MockRecordParser;
import org.apache.nifi.serialization.record.RecordFieldType;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -34,8 +38,7 @@ public class TestPutRecord {
@BeforeEach
public void setup() {
- PutRecord processor = new PutRecord();
- testRunner = TestRunners.newTestRunner(processor);
+ testRunner = TestRunners.newTestRunner(PutRecord.class);
recordReader = new MockRecordParser();
testRunner.setProperty(PutRecord.RECORD_READER, "reader");
mockRecordSinkService = new MockRecordSinkService();
@@ -146,4 +149,16 @@ public class TestPutRecord {
testRunner.assertAllFlowFilesTransferred(PutRecord.REL_RETRY, 1);
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("put-record-reader", PutRecord.RECORD_READER.getName()),
+ Map.entry("put-record-sink", PutRecord.RECORD_SINK.getName()),
+ Map.entry("put-record-include-zero-record-results", PutRecord.INCLUDE_ZERO_RECORD_RESULTS.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = testRunner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java
index fb94b0315c..617ca2741d 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestPutSQL.java
@@ -26,10 +26,12 @@ import org.apache.nifi.provenance.ProvenanceEventRecord;
import org.apache.nifi.provenance.ProvenanceEventType;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -76,6 +78,7 @@ public class TestPutSQL {
private static final String SERVICE_ID = FilteringEmbeddedDatabaseConnectionService.class.getSimpleName();
private static FilteringEmbeddedDatabaseConnectionService service;
+ private TestRunner runner;
@BeforeAll
static void setService(@TempDir final Path databaseLocation) throws SQLException {
@@ -94,10 +97,16 @@ public class TestPutSQL {
service.close();
}
- @Test
- public void testDirectStatements() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ @BeforeEach
+ void setUp() throws InitializationException {
+ runner = TestRunners.newTestRunner(PutSQL.class);
+ runner.addControllerService(SERVICE_ID, service);
+ runner.enableControllerService(service);
+ runner.setProperty(PutSQL.CONNECTION_POOL, SERVICE_ID);
+ }
+ @Test
+ public void testDirectStatements() throws ProcessException, SQLException {
recreateTable("PERSONS", createPersons);
runner.enqueue("INSERT INTO PERSONS (ID, NAME, CODE) VALUES (1, 'Mark', 84)".getBytes());
@@ -132,8 +141,7 @@ public class TestPutSQL {
}
@Test
- public void testCommitOnCleanup() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testCommitOnCleanup() throws ProcessException, SQLException {
runner.setProperty(PutSQL.AUTO_COMMIT, "false");
recreateTable("PERSONS", createPersons);
@@ -156,8 +164,7 @@ public class TestPutSQL {
}
@Test
- public void testInsertWithGeneratedKeys() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testInsertWithGeneratedKeys() throws ProcessException, SQLException {
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "true");
recreateTable("PERSONS_AI", createPersonsAutoId);
@@ -181,8 +188,7 @@ public class TestPutSQL {
}
@Test
- public void testProvenanceEventsWithBatchMode() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testProvenanceEventsWithBatchMode() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "10");
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
@@ -191,8 +197,7 @@ public class TestPutSQL {
}
@Test
- public void testProvenanceEventsWithFragmentedTransaction() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testProvenanceEventsWithFragmentedTransaction() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "10");
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "true");
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
@@ -201,8 +206,7 @@ public class TestPutSQL {
}
@Test
- public void testProvenanceEventsWithObtainGeneratedKeys() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testProvenanceEventsWithObtainGeneratedKeys() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "10");
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "true");
@@ -227,8 +231,7 @@ public class TestPutSQL {
}
@Test
- public void testKeepFlowFileOrderingWithBatchMode() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testKeepFlowFileOrderingWithBatchMode() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "10");
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
@@ -237,8 +240,7 @@ public class TestPutSQL {
}
@Test
- public void testKeepFlowFileOrderingWithFragmentedTransaction() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testKeepFlowFileOrderingWithFragmentedTransaction() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "10");
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "true");
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
@@ -247,8 +249,7 @@ public class TestPutSQL {
}
@Test
- public void testKeepFlowFileOrderingWithObtainGeneratedKeys() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testKeepFlowFileOrderingWithObtainGeneratedKeys() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "10");
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "true");
@@ -295,8 +296,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadStatementAndSupportTransaction() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadStatementAndSupportTransaction() throws ProcessException {
testFailInMiddleWithBadStatement(runner);
runner.run();
@@ -306,8 +306,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadStatementAndNotSupportTransaction() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadStatementAndNotSupportTransaction() throws ProcessException {
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
testFailInMiddleWithBadStatement(runner);
runner.run();
@@ -319,8 +318,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadStatementRollbackOnFailure() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadStatementRollbackOnFailure() throws ProcessException {
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
runner.enqueue("INSERT INTO PERSONS_AI (NAME, CODE) VALUES ('Mark', 84)".getBytes());
@@ -335,8 +333,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterTypeAndNotSupportTransaction() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadParameterTypeAndNotSupportTransaction() throws ProcessException {
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
testFailInMiddleWithBadParameterType(runner);
runner.run();
@@ -349,8 +346,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterTypeAndSupportTransaction() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadParameterTypeAndSupportTransaction() throws ProcessException {
testFailInMiddleWithBadParameterType(runner);
runner.run();
@@ -361,8 +357,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterTypeRollbackOnFailure() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadParameterTypeRollbackOnFailure() throws ProcessException {
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
@@ -387,8 +382,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithNumberFormatException() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithNumberFormatException() throws ProcessException {
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "false");
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
final Map<String, String> goodAttributes = new HashMap<>();
@@ -413,8 +407,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterValueAndSupportTransaction() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadParameterValueAndSupportTransaction() throws ProcessException, SQLException {
testFailInMiddleWithBadParameterValue(runner);
runner.run();
@@ -434,8 +427,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterValueAndNotSupportTransaction() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadParameterValueAndNotSupportTransaction() throws ProcessException, SQLException {
runner.setProperty(PutSQL.SUPPORT_TRANSACTIONS, "false");
testFailInMiddleWithBadParameterValue(runner);
runner.run();
@@ -462,8 +454,7 @@ public class TestPutSQL {
}
@Test
- public void testFailInMiddleWithBadParameterValueRollbackOnFailure() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testFailInMiddleWithBadParameterValueRollbackOnFailure() throws ProcessException, SQLException {
runner.setProperty(PutSQL.OBTAIN_GENERATED_KEYS, "false");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
@@ -498,8 +489,7 @@ public class TestPutSQL {
@Test
- public void testUsingSqlDataTypesWithNegativeValues() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testUsingSqlDataTypesWithNegativeValues() throws ProcessException, SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE PERSONS2 (id integer primary key, name varchar(100), code bigint)");
@@ -528,8 +518,7 @@ public class TestPutSQL {
// Not specifying a format for the date fields here to continue to test backwards compatibility
@Test
- public void testUsingTimestampValuesEpochAndString() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testUsingTimestampValuesEpochAndString() throws ProcessException, SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE TIMESTAMPTEST1 (id integer primary key, ts1 timestamp(3), ts2 timestamp(3))");
@@ -565,8 +554,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingTimestampValuesWithFormatAttribute() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testUsingTimestampValuesWithFormatAttribute() throws ProcessException, SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE TIMESTAMPTEST2 (id integer primary key, ts1 timestamp(9), ts2 timestamp(9))");
@@ -609,8 +597,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingDateTimeValuesWithFormatAttribute() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testUsingDateTimeValuesWithFormatAttribute() throws ProcessException, SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE TIMESTAMPTEST3 (id integer primary key, ts1 TIME, ts2 DATE)");
@@ -697,8 +684,7 @@ public class TestPutSQL {
}
@Test
- public void testBitType() throws SQLException, InitializationException {
- final TestRunner runner = initTestRunner();
+ public void testBitType() throws SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE BITTESTS (id integer primary key, bt1 BOOLEAN)");
@@ -810,8 +796,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingTimeValuesEpochAndString() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testUsingTimeValuesEpochAndString() throws ProcessException, SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE TIMETESTS (id integer primary key, ts1 time, ts2 time)");
@@ -851,8 +836,7 @@ public class TestPutSQL {
}
@Test
- public void testUsingDateValuesEpochAndString() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testUsingDateValuesEpochAndString() throws ProcessException, SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE DATETESTS (id integer primary key, ts1 date, ts2 date)");
@@ -887,8 +871,7 @@ public class TestPutSQL {
}
@Test
- public void testBinaryColumnTypes() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testBinaryColumnTypes() throws ProcessException, SQLException {
try (final Connection conn = service.getConnection()) {
try (final Statement stmt = conn.createStatement()) {
stmt.executeUpdate("CREATE TABLE BINARYTESTS (id integer primary key, bn1 BLOB, bn2 BLOB, bn3 BLOB)");
@@ -1012,9 +995,7 @@ public class TestPutSQL {
}
@Test
- public void testStatementsWithPreparedParameters() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
-
+ public void testStatementsWithPreparedParameters() throws ProcessException, SQLException {
recreateTable("PERSONS", createPersons);
final Map<String, String> attributes = new HashMap<>();
@@ -1069,9 +1050,7 @@ public class TestPutSQL {
}
@Test
- public void testMultipleStatementsWithinFlowFile() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
-
+ public void testMultipleStatementsWithinFlowFile() throws ProcessException, SQLException {
recreateTable("PERSONS", createPersons);
final String sql = "INSERT INTO PERSONS (ID, NAME, CODE) VALUES (?, ?, ?); " +
@@ -1105,8 +1084,7 @@ public class TestPutSQL {
}
@Test
- public void testMultipleStatementsWithinFlowFileRollbackOnFailure() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testMultipleStatementsWithinFlowFileRollbackOnFailure() throws ProcessException, SQLException {
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
recreateTable("PERSONS", createPersons);
@@ -1140,8 +1118,7 @@ public class TestPutSQL {
@Test
- public void testWithNullParameter() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testWithNullParameter() throws ProcessException, SQLException {
final Map<String, String> attributes = new HashMap<>();
attributes.put("sql.args.1.type", String.valueOf(Types.INTEGER));
attributes.put("sql.args.1.value", "1");
@@ -1169,9 +1146,7 @@ public class TestPutSQL {
}
@Test
- public void testInvalidStatement() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
-
+ public void testInvalidStatement() throws ProcessException, SQLException {
recreateTable("PERSONS", createPersons);
final String sql = "INSERT INTO PERSONS (ID, NAME, CODE) VALUES (?, ?, ?); " +
@@ -1205,8 +1180,7 @@ public class TestPutSQL {
}
@Test
- public void testInvalidStatementRollbackOnFailure() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testInvalidStatementRollbackOnFailure() throws ProcessException, SQLException {
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
recreateTable("PERSONS", createPersons);
@@ -1239,13 +1213,7 @@ public class TestPutSQL {
}
@Test
- public void testRetryableFailureRollbackOnFailure() throws InitializationException, ProcessException {
- final TestRunner runner = TestRunners.newTestRunner(PutSQL.class);
-
- runner.addControllerService(SERVICE_ID, service);
- runner.enableControllerService(service);
-
- runner.setProperty(PutSQL.CONNECTION_POOL, SERVICE_ID);
+ public void testRetryableFailureRollbackOnFailure() throws ProcessException {
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
final String sql = "INSERT INTO PERSONS (ID, NAME, CODE) VALUES (?, ?, ?); " +
@@ -1270,8 +1238,7 @@ public class TestPutSQL {
}
@Test
- public void testMultipleFlowFilesSuccessfulInTransaction() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testMultipleFlowFilesSuccessfulInTransaction() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "1");
recreateTable("PERSONS", createPersons);
@@ -1325,8 +1292,7 @@ public class TestPutSQL {
}
@Test
- public void testMultipleFlowFilesSuccessfulInTransactionRollBackOnFailure() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testMultipleFlowFilesSuccessfulInTransactionRollBackOnFailure() throws ProcessException, SQLException {
runner.setProperty(PutSQL.BATCH_SIZE, "1");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
@@ -1354,9 +1320,7 @@ public class TestPutSQL {
}
@Test
- public void testTransactionTimeout() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
-
+ public void testTransactionTimeout() throws ProcessException {
runner.setProperty(PutSQL.TRANSACTION_TIMEOUT, "5 secs");
final Map<String, String> attributes = new HashMap<>();
attributes.put("fragment.identifier", "1");
@@ -1389,9 +1353,7 @@ public class TestPutSQL {
}
@Test
- public void testTransactionTimeoutRollbackOnFailure() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
-
+ public void testTransactionTimeoutRollbackOnFailure() throws ProcessException {
runner.setProperty(PutSQL.TRANSACTION_TIMEOUT, "5 secs");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
final Map<String, String> attributes = new HashMap<>();
@@ -1425,9 +1387,7 @@ public class TestPutSQL {
}
@Test
- public void testNullFragmentCountRollbackOnFailure() throws InitializationException, ProcessException {
- final TestRunner runner = initTestRunner();
-
+ public void testNullFragmentCountRollbackOnFailure() throws ProcessException {
runner.setProperty(PutSQL.TRANSACTION_TIMEOUT, "5 secs");
runner.setProperty(RollbackOnFailure.ROLLBACK_ON_FAILURE, "true");
final Map<String, String> attribute1 = new HashMap<>();
@@ -1449,8 +1409,7 @@ public class TestPutSQL {
}
@Test
- public void testStatementsFromProperty() throws InitializationException, ProcessException, SQLException {
- final TestRunner runner = initTestRunner();
+ public void testStatementsFromProperty() throws ProcessException, SQLException {
runner.setProperty(PutSQL.SQL_STATEMENT, "INSERT INTO PERSONS (ID, NAME, CODE) VALUES (${row.id}, 'Mark', 84)");
recreateTable("PERSONS", createPersons);
@@ -1551,9 +1510,6 @@ public class TestPutSQL {
try {
recreateTable("PERSONS", createPersons);
-
- TestRunner runner = initTestRunner();
-
runner.enqueue("INSERT INTO PERSONS (ID, NAME, CODE) VALUES (1, 'Mark', 84)", new HashMap<>());
runner.run();
@@ -1572,9 +1528,6 @@ public class TestPutSQL {
try {
recreateTable("PERSONS", createPersons);
-
- TestRunner runner = initTestRunner();
-
Map<String, String> attributes = new HashMap<>();
attributes.put("database.name", "someDatabaseName");
runner.enqueue("INSERT INTO PERSONS (ID, NAME, CODE) VALUES (1, 'Mark', 84)", attributes);
@@ -1589,6 +1542,18 @@ public class TestPutSQL {
}
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("putsql-sql-statement", PutSQL.SQL_STATEMENT.getName()),
+ Map.entry("database-session-autocommit", PutSQL.AUTO_COMMIT.getName()),
+ Map.entry(RollbackOnFailure.OLD_ROLLBACK_ON_FAILURE_PROPERTY_NAME, RollbackOnFailure.ROLLBACK_ON_FAILURE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void makeServiceLookLikeAnInstanceOfDBCPConnectionPoolLookup() {
// service has a FlowFileFilter when, and only when it is a DBCPConnectionPoolLookup
// As such, it requires incoming FileFiles to have a 'database.name' attribute
@@ -1700,16 +1665,6 @@ public class TestPutSQL {
return DatatypeConverter.printBase64Binary(bBinary);
}
- private TestRunner initTestRunner() throws InitializationException {
- final TestRunner runner = TestRunners.newTestRunner(PutSQL.class);
-
- runner.addControllerService(SERVICE_ID, service);
- runner.enableControllerService(service);
- runner.setProperty(PutSQL.CONNECTION_POOL, SERVICE_ID);
-
- return runner;
- }
-
private static void assertSQLExceptionRelatedAttributes(final TestRunner runner, Relationship relationship) {
List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(relationship);
flowFiles.forEach(ff -> {
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java
index e66a76ab4a..46f84480da 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestQueryRecord.java
@@ -47,8 +47,10 @@ import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.serialization.record.RecordSet;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.apache.nifi.util.db.JdbcProperties;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
@@ -65,10 +67,14 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
+import static org.apache.nifi.util.db.JdbcProperties.DEFAULT_PRECISION;
+import static org.apache.nifi.util.db.JdbcProperties.DEFAULT_SCALE;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class TestQueryRecord {
@@ -86,7 +92,7 @@ public class TestQueryRecord {
/*
* we have to disable validation of expression language because the scope of the evaluation
- * depends of the value of another property: if we are caching the schema/queries or not. If
+ * depends on the value of another property: if we are caching the schema/queries or not. If
* we don't disable the validation, it'll throw an error saying that the scope is incorrect.
*/
runner.setValidateExpressionUsage(false);
@@ -130,14 +136,14 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<MockFlowFile> flowFilesOriginal = runner.getFlowFilesForRelationship(QueryRecord.REL_ORIGINAL);
- flowFilesOriginal.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, QueryRecord.REL_ORIGINAL.getName());
+ flowFilesOriginal.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, QueryRecord.REL_ORIGINAL.getName());
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("John Doe", output.getValue("nameObj"));
assertEquals(30, output.getValue("age"));
@@ -186,7 +192,7 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(50, written.size());
@@ -229,12 +235,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
}
@@ -267,12 +273,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
assertEquals(JobLevel.IC2, output.getValue("jobLevel"));
@@ -309,12 +315,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
assertEquals(new BigDecimal("90.500000000"), output.getValue("height_total"));
@@ -352,13 +358,13 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
final Number height = 121.0;
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
assertEquals(height.doubleValue(), output.getValue("height_total_double"));
@@ -398,13 +404,13 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
final Number height = 60;
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
assertEquals(height.longValue(), output.getValue("height_total_long"));
@@ -440,12 +446,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(2, written.size());
- final Record output0 = written.get(0);
+ final Record output0 = written.getFirst();
assertEquals("1", output0.getValue("id"));
assertArrayEquals(new Object[]{"a", "d", "g"}, (Object[]) output0.getValue("tags"));
@@ -484,12 +490,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(3, written.size());
- final Record output0 = written.get(0);
+ final Record output0 = written.getFirst();
assertEquals("1", output0.getValue("id"));
assertEquals("a", output0.getValue("first"));
assertEquals("d", output0.getValue("second"));
@@ -547,12 +553,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
}
@@ -587,7 +593,7 @@ public class TestQueryRecord {
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record out = written.get(0);
+ final Record out = written.getFirst();
assertEquals("12345", out.getAsString("ArticleCode"));
assertEquals("Credit Card", out.getAsString("ArticleName"));
assertEquals("10101", out.getAsString("ProductCode"));
@@ -665,7 +671,7 @@ public class TestQueryRecord {
assertEquals("1234", fr.getAsString("employeeId"));
assertEquals("xxx.yyyy@zzzz.com", fr.getAsString("email"));
assertEquals(406, fr.getAsInt("timeSpent"));
- assertEquals(null, fr.getValue("proficiencyLevel"));
+ assertNull(fr.getValue("proficiencyLevel"));
}
@@ -697,12 +703,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
}
@@ -736,12 +742,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("John Doe", output.getValue("name"));
assertEquals("Software Engineer", output.getValue("title"));
}
@@ -776,12 +782,12 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
final List<Record> written = writer.getRecordsWritten();
assertEquals(1, written.size());
- final Record output = written.get(0);
+ final Record output = written.getFirst();
assertEquals("basketball", output.getValue("sport"));
assertEquals("John Doe", output.getValue("nameObj"));
}
@@ -1024,7 +1030,7 @@ public class TestQueryRecord {
runner.run(2 * numIterations);
runner.assertTransferCount(REL_NAME, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
out.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
out.assertContentEquals("\"name\",\"points\"\n\"Tom\",\"49\"\n");
}
@@ -1059,7 +1065,7 @@ public class TestQueryRecord {
runner.run(2 * numIterations);
runner.assertTransferCount(REL_NAME, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
out.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
out.assertContentEquals("\"name\",\"points\"\n\"Tom\",\"49\"\n\"Alice\",\n,\"36\"\n");
}
@@ -1092,7 +1098,7 @@ public class TestQueryRecord {
runner.run(2 * numIterations);
runner.assertTransferCount(REL_NAME, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
out.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
out.assertContentEquals("\"name\",\"points\"\n\"Tom\",\"49\"\n");
}
@@ -1120,7 +1126,7 @@ public class TestQueryRecord {
runner.enqueue("name,age\n");
runner.run();
runner.assertTransferCount(REL_NAME, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
out.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
out.assertContentEquals("\"name\",\"age\"\n");
}
@@ -1155,7 +1161,7 @@ public class TestQueryRecord {
runner.run();
runner.assertTransferCount(REL_NAME, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
out.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
out.assertContentEquals("\"NAME\",\"POINTS\"\n\"100\",\"90.75\"\n");
@@ -1191,7 +1197,7 @@ public class TestQueryRecord {
runner.assertAllFlowFilesTransferred(QueryRecord.REL_FAILURE, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(QueryRecord.REL_FAILURE);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, QueryRecord.REL_FAILURE.getName());
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, QueryRecord.REL_FAILURE.getName());
}
@Test
@@ -1219,7 +1225,7 @@ public class TestQueryRecord {
runner.run();
runner.assertTransferCount(REL_NAME, 1);
- final MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
flowFileOut.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
flowFileOut.assertContentEquals("\"name\",\"points\"\n\"Tom\",\"100\"\n\"Jerry\",\"2\"\n");
}
@@ -1252,11 +1258,11 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
runner.assertTransferCount("count", 1);
- final MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
flowFileOut.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
flowFileOut.assertContentEquals("1\n\n\n3\n");
- final MockFlowFile countFlowFile = runner.getFlowFilesForRelationship("count").get(0);
+ final MockFlowFile countFlowFile = runner.getFlowFilesForRelationship("count").getFirst();
countFlowFile.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, "count");
countFlowFile.assertContentEquals("2\n");
}
@@ -1293,7 +1299,7 @@ public class TestQueryRecord {
runner.assertTransferCount(REL_NAME, 1);
final List<MockFlowFile> flowFiles = runner.getFlowFilesForRelationship(REL_NAME);
- flowFiles.get(0).assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
+ flowFiles.getFirst().assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
}
@Test
@@ -1317,7 +1323,7 @@ public class TestQueryRecord {
runner.run();
runner.assertTransferCount(REL_NAME, 1);
- final MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).get(0);
+ final MockFlowFile flowFileOut = runner.getFlowFilesForRelationship(REL_NAME).getFirst();
flowFileOut.assertAttributeEquals(QueryRecord.ROUTE_ATTRIBUTE_KEY, REL_NAME);
flowFileOut.assertContentEquals("[]");
}
@@ -1388,23 +1394,36 @@ public class TestQueryRecord {
final Record outputRecord = recordReader.nextRecord();
final Object barValue = outputRecord.getValue("bar");
- final int barLength;
- if (barValue instanceof byte[]) {
- barLength = ((byte[]) barValue).length;
- } else if (barValue instanceof Byte[]) {
- barLength = ((Byte[]) barValue).length;
- } else if (barValue instanceof Object[] objects) {
- barLength = objects.length;
- } else if (barValue instanceof ByteBuffer buffer) {
- barLength = buffer.remaining();
- } else {
- throw new AssertionError("Unexpected bar type: " + barValue.getClass());
- }
+ final int barLength = switch (barValue) {
+ case byte[] bytes -> bytes.length;
+ case Byte[] bytes -> bytes.length;
+ case Object[] objects -> objects.length;
+ case ByteBuffer buffer -> buffer.remaining();
+ case null, default -> throw new AssertionError("Unexpected bar type: " + barValue.getClass());
+ };
assertEquals(8, barLength);
}
}
+ @Test
+ void testMigrateProperties() {
+ final TestRunner runner = getRunner();
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("record-reader", QueryRecord.RECORD_READER_FACTORY.getName()),
+ Map.entry("record-writer", QueryRecord.RECORD_WRITER_FACTORY.getName()),
+ Map.entry("include-zero-record-flowfiles", QueryRecord.INCLUDE_ZERO_RECORD_FLOWFILES.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_PRECISION_PROPERTY_NAME, DEFAULT_PRECISION.getName()),
+ Map.entry(JdbcProperties.OLD_DEFAULT_SCALE_PROPERTY_NAME, DEFAULT_SCALE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+
+ final Set<String> expectedRemoved = Set.of("cache-schema");
+ assertEquals(expectedRemoved, propertyMigrationResult.getPropertiesRemoved());
+ }
+
private static class ResultSetValidatingRecordWriter extends AbstractControllerService implements RecordSetWriterFactory {
private final List<String> columnNames;
@@ -1415,8 +1434,8 @@ public class TestQueryRecord {
@Override
public RecordSchema getSchema(Map<String, String> variables, RecordSchema readSchema) {
final List<RecordField> recordFields = columnNames.stream()
- .map(name -> new RecordField(name, RecordFieldType.STRING.getDataType()))
- .collect(Collectors.toList());
+ .map(name -> new RecordField(name, RecordFieldType.STRING.getDataType()))
+ .collect(Collectors.toList());
return new SimpleRecordSchema(recordFields);
}
@@ -1442,7 +1461,7 @@ public class TestQueryRecord {
assertEquals(columnNames, colNames);
// Iterate over the rest of the records to ensure that we read the entire stream. If we don't
- // do this, we won't consume all of the data and as a result we will not close the stream properly
+ // do this, we won't consume all the data and as a result we will not close the stream properly
while (rs.next() != null) {
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
index 11b9db5451..d3cbebcdf6 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
@@ -17,8 +17,10 @@
package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -40,23 +42,22 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestReplaceText {
+ private TestRunner runner;
- public TestRunner getRunner() {
- TestRunner runner = TestRunners.newTestRunner(ReplaceText.class);
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(ReplaceText.class);
/*
* we have to disable validation of expression language because the scope of the evaluation
- * for the search value depends of another property (the evaluation mode). If not disabling
+ * for the search value depends on another property (the evaluation mode). If not disabling
* the validation, it'll throw an error about the eval
*/
runner.setValidateExpressionUsage(false);
-
- return runner;
}
@Test
public void testLiteralReplaceWithExpressionLanguageInSearchEntireText() {
- final TestRunner runner = getRunner();
runner.enqueue("Me, you, and the other", Collections.singletonMap("search.value", "you, and"));
runner.setProperty(ReplaceText.SEARCH_VALUE, "Me, ${search.value}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\"Replacement\"");
@@ -65,13 +66,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("\"Replacement\" the other");
}
@Test
public void testLiteralReplaceWithExpressionLanguageInReplacementEntireText() {
- final TestRunner runner = getRunner();
runner.enqueue("Me, you, and the other", Collections.singletonMap("replacement.value", "us"));
runner.setProperty(ReplaceText.SEARCH_VALUE, "Me, you,");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "With ${replacement.value}");
@@ -80,13 +80,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("With us and the other");
}
@Test
public void testLiteralReplaceWithExpressionLanguageInSearchLineByLine() {
- final TestRunner runner = getRunner();
runner.enqueue("Me, you, and the other", Collections.singletonMap("search.value", "you, and"));
runner.setProperty(ReplaceText.SEARCH_VALUE, "Me, ${search.value}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\"Replacement\"");
@@ -95,13 +94,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("\"Replacement\" the other");
}
@Test
public void testLiteralReplaceWithExpressionLanguageInReplacementLineByLine() {
- final TestRunner runner = getRunner();
runner.enqueue("Me, you, and the other", Collections.singletonMap("replacement.value", "us"));
runner.setProperty(ReplaceText.SEARCH_VALUE, "Me, you,");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "With ${replacement.value}");
@@ -110,25 +108,24 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("With us and the other");
}
@Test
public void testConfigurationCornerCase() throws IOException {
- final TestRunner runner = getRunner();
+ final Path helloText = Paths.get("src/test/resources/hello.txt");
runner.run();
- runner.enqueue(Paths.get("src/test/resources/hello.txt"));
+ runner.enqueue(helloText);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals(Paths.get("src/test/resources/hello.txt"));
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
+ out.assertContentEquals(helloText);
}
@Test
public void testIterativeRegexReplace() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "\"([a-z]+?)\":\"(.*?)\"");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\"${'$1':toUpper()}\":\"$2\"");
@@ -136,13 +133,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("{\"NAME\":\"Smith\",\"MIDDLE\":\"nifi\",\"FIRSTNAME\":\"John\"}");
}
@Test
public void testIterativeRegexReplaceLineByLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "\"([a-z]+?)\":\"(.*?)\"");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\"${'$1':toUpper()}\":\"$2\"");
@@ -151,14 +147,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("{\"NAME\":\"Smith\",\"MIDDLE\":\"nifi\",\"FIRSTNAME\":\"John\"}");
}
@Test
public void testSimple() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "ell");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "lle");
@@ -166,13 +161,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hlleo, World!".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testWithEscapedDollarSignInReplacement() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s:^.*$)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "a\\$b");
@@ -180,13 +174,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("a\\$b".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testWithUnEscapedDollarSignInReplacement() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s:^.*$)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "a$b");
@@ -194,13 +187,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("a$b".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testPrependSimple() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "TEST");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.PREPEND);
@@ -208,13 +200,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("TESTHello, World!".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testPrependLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "_");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.PREPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -223,13 +214,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("_hello\n_there\n_madam".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testPrependFirstLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "_");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.PREPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -239,13 +229,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("_hello\nthere\nmadam".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testPrependLastLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "_");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.PREPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -255,13 +244,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello\nthere\n_madam".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testPrependExceptFirstLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "_");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.PREPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -271,14 +259,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello\n_there\n_madam".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testPrependExceptLastLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "_");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.PREPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -288,13 +275,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("_hello\n_there\nmadam".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testAppendSimple() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "TEST");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -302,13 +288,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hello, World!TEST".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testAppendWithCarriageReturn() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -317,14 +302,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello!\rthere!\rsir!");
}
@Test
public void testAppendFirstLineWithCarriageReturn() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -334,13 +318,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello!\rthere\rsir");
}
@Test
public void testAppendExceptFirstLineWithCarriageReturn() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -350,13 +333,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello\rthere!\rsir!");
}
@Test
public void testAppendLastLineWithCarriageReturn() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -366,13 +348,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello\rthere\rsir!");
}
@Test
public void testAppendExceptLastLineWithCarriageReturn() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -382,13 +363,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello!\rthere!\rsir");
}
@Test
public void testAppendWithNewLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -397,13 +377,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello!\nthere!\nsir!");
}
@Test
public void testAppendWithCarriageReturnNewLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -412,13 +391,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello!\r\nthere!\r\nsir!");
}
@Test
public void testAppendFirstLineWithCarriageReturnNewLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -428,14 +406,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello!\r\nthere\r\nsir");
}
@Test
public void testAppendLastLineWithCarriageReturnNewLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -445,14 +422,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello\r\nthere\r\nsir!");
}
@Test
public void testAppendExceptFistLineWithCarriageReturnNewLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -462,14 +438,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello\r\nthere!\r\nsir!");
}
@Test
public void testAppendExceptLastLineWithCarriageReturnNewLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "!");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
@@ -480,13 +455,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello!\r\nthere!\r\nsir");
}
@Test
public void testLiteralSimple() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "ell");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "lle");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.LITERAL_REPLACE);
@@ -495,13 +469,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hlleo, World!".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testLiteralBackReference() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "ell");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[$1]");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.LITERAL_REPLACE);
@@ -510,13 +483,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("H[$1]o, World!");
}
@Test
public void testLiteral() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, ".ell.");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "test");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.LITERAL_REPLACE);
@@ -535,7 +507,6 @@ public class TestReplaceText {
@Test
public void testBackReference() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[$1]");
@@ -543,13 +514,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("H[ell]o, World!");
}
@Test
public void testBackRefFollowedByNumbers() throws IOException {
- final TestRunner runner = getRunner();
String expected = "Hell23o, World!";
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$123");
@@ -559,14 +529,13 @@ public class TestReplaceText {
runner.enqueue(Paths.get("src/test/resources/hello.txt"), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
final String actual = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertEquals(expected, actual);
}
@Test
public void testBackRefWithNoCapturingGroup() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "ell");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$0123");
@@ -575,14 +544,13 @@ public class TestReplaceText {
runner.enqueue(Paths.get("src/test/resources/hello.txt"), attributes);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
final String actual = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertEquals("Hell123o, World!", actual);
}
@Test
public void testReplacementWithExpressionLanguage() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "${replaceKey}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "GoodBye");
@@ -593,13 +561,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hello, World!");
}
@Test
public void testReplacementWithExpressionLanguageIsEscaped() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[${abc}]");
@@ -610,13 +577,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("H[$1]o, World!");
}
@Test
public void testRegexWithExpressionLanguage() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "${replaceKey}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${replaceValue}");
@@ -628,13 +594,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Good-bye, World!");
}
@Test
public void testRegexWithExpressionLanguageIsEscaped() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "${replaceKey}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${replaceValue}");
@@ -646,13 +611,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hello, World!");
}
@Test
public void testBackReferenceWithTooLargeOfIndexIsEscaped() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$1$2");
@@ -664,13 +628,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hell$2o, World!");
}
@Test
public void testBackReferenceWithInvalidReferenceIsEscaped() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$d");
@@ -682,13 +645,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("H$do, World!");
}
@Test
public void testEscapingDollarSign() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\\$1");
@@ -700,13 +662,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("H$1o, World!");
}
@Test
public void testReplaceWithEmptyString() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ell)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "");
@@ -714,13 +675,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Ho, World!");
}
@Test
public void testWithNoMatch() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "Z");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "Morning");
@@ -728,13 +688,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hello, World!");
}
@Test
public void testWithMultipleMatches() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "l");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "R");
@@ -742,13 +701,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("HeRRo, WorRd!");
}
@Test
public void testAttributeToContent() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
@@ -759,13 +717,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Good");
}
@Test
public void testRoutesToFailureIfTooLarge() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "[123]");
runner.setProperty(ReplaceText.MAX_BUFFER_SIZE, "1 b");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
@@ -782,7 +739,6 @@ public class TestReplaceText {
@Test
public void testRoutesToFailureIfLineTooLarge() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "[123]");
runner.setProperty(ReplaceText.MAX_BUFFER_SIZE, "5 kb");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
@@ -799,7 +755,6 @@ public class TestReplaceText {
@Test
public void testRoutesToSuccessIfTooLargeButRegexIsDotAsterisk() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
runner.setProperty(ReplaceText.MAX_BUFFER_SIZE, "1 b");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
@@ -811,13 +766,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Good");
}
@Test
public void testProblematicCase1() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${filename}\t${now():format(\"yyyy/MM/dd'T'HHmmss'Z'\")}\t${fileSize}\n");
@@ -828,7 +782,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertTrue(outContent.startsWith("abc.txt\t"));
assertTrue(outContent.endsWith("13\n"));
@@ -836,7 +790,6 @@ public class TestReplaceText {
@Test
public void testGetExistingContent() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "attribute header\n\n${filename}\n\ndata header\n\n$1\n\nfooter");
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.ENTIRE_TEXT);
@@ -848,14 +801,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
assertEquals("attribute header\n\nabc.txt\n\ndata header\n\nHello\nWorld!\n\nfooter", outContent);
}
@Test
public void testReplaceWithinCurlyBraces() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, ".+");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "{ ${filename} }");
@@ -866,7 +818,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("{ abc.txt }");
}
@@ -875,7 +827,6 @@ public class TestReplaceText {
final String defaultValue = "default-replacement-value";
// leave the default regex settings
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, defaultValue);
final Map<String, String> attributes = new HashMap<>();
@@ -884,7 +835,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(defaultValue);
}
@@ -893,7 +844,6 @@ public class TestReplaceText {
final String defaultValue = "default-replacement-value";
// leave the default regex settings
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, defaultValue);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.ENTIRE_TEXT);
@@ -903,7 +853,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(defaultValue);
}
@@ -911,7 +861,6 @@ public class TestReplaceText {
@Test
public void testSimpleLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "odo");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "ood");
@@ -920,14 +869,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/food.txt")));
}
@Test
public void testZeroByteContentFileLineByLine(@TempDir Path tempDir) throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "odo");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "ood");
@@ -945,7 +893,6 @@ public class TestReplaceText {
@Test
public void testPrependSimpleLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.PREPEND);
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "TEST ");
@@ -954,13 +901,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/PrependLineByLineTest.txt")));
}
@Test
public void testAppendSimpleLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, " TEST");
@@ -969,13 +915,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/AppendLineByLineTest.txt")));
}
@Test
public void testAppendEndlineCR() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "TEST");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -984,13 +929,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hello TEST\rWorld TEST\r".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testAppendEndlineCRLF() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "TEST");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.APPEND);
@@ -999,13 +943,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Hello TEST\r\nWorld TEST\r\n".getBytes(StandardCharsets.UTF_8));
}
@Test
public void testSimpleLiteral() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "odo");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "ood");
@@ -1015,13 +958,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/food.txt")));
}
@Test
public void testLiteralBackReferenceLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "jo");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[$1]");
@@ -1032,13 +974,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/cu[$1]_Po[$1].txt")));
}
@Test
public void testLiteralLineByLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, ".ell.");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "test");
@@ -1048,13 +989,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Htesto, World! test \n test test");
}
@Test
public void testBackReferenceLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(DODO)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[$1]");
@@ -1063,13 +1003,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/[DODO].txt")));
}
@Test
public void testReplacementWithExpressionLanguageIsEscapedLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(jo)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "[${abc}]");
@@ -1081,13 +1020,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/cu[$1]_Po[$1].txt")));
}
@Test
public void testRegexWithExpressionLanguageLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "${replaceKey}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${replaceValue}");
@@ -1100,13 +1038,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Spider.txt")));
}
@Test
public void testRegexWithExpressionLanguageIsEscapedLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "${replaceKey}");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${replaceValue}");
@@ -1119,13 +1056,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
}
@Test
public void testBackReferenceWithTooLargeOfIndexIsEscapedLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(lu)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$1$2");
@@ -1138,14 +1074,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/Blu$2e_clu$2e.txt")));
}
@Test
public void testBackReferenceWithTooLargeOfIndexIsEscapedFirstLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.FIRST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(H)");
@@ -1157,14 +1092,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/ReplaceFirstLine.txt")));
}
@Test
public void testBackReferenceWithTooLargeOfIndexIsEscapedLastLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.LAST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(O)");
@@ -1176,7 +1110,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/ReplaceLastLine.txt")));
}
@@ -1184,7 +1118,6 @@ public class TestReplaceText {
@Test
public void testBackReferenceWithTooLargeOfIndexIsEscapedExceptFirstLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.EXCEPT_FIRST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(H)");
@@ -1196,7 +1129,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/ReplaceExceptFirstLine.txt")));
}
@@ -1205,7 +1138,6 @@ public class TestReplaceText {
@Test
public void testBackReferenceWithTooLargeOfIndexIsEscapedExceptLastLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.EXCEPT_LAST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(O)");
@@ -1217,7 +1149,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/ReplaceExceptLastLine.txt")));
}
@@ -1225,7 +1157,6 @@ public class TestReplaceText {
@Test
public void testLiteralBackReferenceFistLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.FIRST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "H");
@@ -1237,7 +1168,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/LiteralReplaceFirstLine.txt")));
}
@@ -1246,7 +1177,6 @@ public class TestReplaceText {
@Test
public void testLiteralBackReferenceExceptFirstLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.EXCEPT_FIRST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "H");
@@ -1258,14 +1188,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/LiteralReplaceExceptFirstLine.txt")));
}
@Test
public void testLiteralBackReferenceLastLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.LAST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "O");
@@ -1277,14 +1206,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/LiteralReplaceLastLine.txt")));
}
@Test
public void testLiteralBackReferenceExceptLastLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.LINE_BY_LINE_EVALUATION_MODE, ReplaceText.EXCEPT_LAST_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "O");
@@ -1296,13 +1224,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/LiteralReplaceExceptLastLine.txt")));
}
@Test
public void testBackReferenceWithInvalidReferenceIsEscapedLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(ew)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$d");
@@ -1315,13 +1242,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/D$d_h$d.txt")));
}
@Test
public void testEscapingDollarSignLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(DO)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "\\$1");
@@ -1334,13 +1260,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/$1$1.txt")));
}
@Test
public void testReplaceWithEmptyStringLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(jo)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "");
@@ -1349,13 +1274,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/cu_Po.txt")));
}
@Test
public void testWithNoMatchLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "Z");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "Morning");
@@ -1364,13 +1288,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/testFile.txt")));
}
@Test
public void testWithMultipleMatchesLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "l");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "R");
@@ -1379,13 +1302,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(translateNewLines(new File("src/test/resources/TestReplaceTextLineByLine/BRue_cRue_RiRey.txt")));
}
@Test
public void testAttributeToContentLineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
@@ -1397,13 +1319,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Good\nGood\nGood\nGood\nGood\nGood\nGood\nGood\nGood\nGood\nGood");
}
@Test
public void testAttributeToContentWindows() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${abc}");
@@ -1415,13 +1336,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("Good\r\nGood\r\nGood\r");
}
@Test
public void testProblematicCase1LineByLine() throws IOException {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${filename}\t${now():format(\"yyyy/MM/dd'T'HHmmss'Z'\")}\t${fileSize}\n");
@@ -1433,7 +1353,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
final String outContent = translateNewLines(new String(out.toByteArray(), StandardCharsets.UTF_8));
assertTrue(outContent.startsWith("abc.txt\t"));
assertTrue(outContent.endsWith("193\n") || outContent.endsWith("203\r\n"));
@@ -1441,7 +1361,6 @@ public class TestReplaceText {
@Test
public void testGetExistingContentLineByLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "attribute header\n\n${filename}\n\ndata header\n\n$1\n\nfooter\n");
@@ -1453,41 +1372,60 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
final String outContent = new String(out.toByteArray(), StandardCharsets.UTF_8);
- final String expectedContent = "attribute header\n\nabc.txt\n\ndata header\n\nHello\n\n\nfooter\n"
- + "attribute header\n\nabc.txt\n\ndata header\n\nWorld!\n\nfooter\n";
+ final String expectedContent = """
+ attribute header
+
+ abc.txt
+
+ data header
+
+ Hello
+
+
+ footer
+ attribute header
+
+ abc.txt
+
+ data header
+
+ World!
+
+ footer
+ """;
assertEquals(expectedContent, outContent);
}
@Test
public void testCapturingGroupInExpressionLanguage() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(.*?),(.*?),(\\d+.*)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$1,$2,${ '$3':toDate('ddMMMyyyy'):format('yyyy/MM/dd') }");
final String csvIn =
- "2006,10-01-2004,10may2004\n"
- + "2007,15-05-2006,10jun2005\r\n"
- + "2009,8-8-2008,10aug2008";
+ """
+ 2006,10-01-2004,10may2004
+ 2007,15-05-2006,10jun2005\r
+ 2009,8-8-2008,10aug2008""";
final String expectedCsvOut =
- "2006,10-01-2004,2004/05/10\n"
- + "2007,15-05-2006,2005/06/10\r\n"
- + "2009,8-8-2008,2008/08/10";
+ """
+ 2006,10-01-2004,2004/05/10
+ 2007,15-05-2006,2005/06/10\r
+ 2009,8-8-2008,2008/08/10""";
runner.enqueue(csvIn.getBytes());
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(expectedCsvOut);
}
@Test
public void testCapturingGroupInExpressionLanguage2() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "(.*)/(.*?).jpg");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$1/${ '$2':substring(0,1) }.png");
@@ -1504,13 +1442,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(expectedCsvOut);
}
@Test
public void testAlwaysReplaceEntireText() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.ENTIRE_TEXT);
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.ALWAYS_REPLACE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "i do not exist anywhere in the text");
@@ -1523,13 +1460,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("abc.txt");
}
@Test
public void testAlwaysReplaceLineByLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.LINE_BY_LINE);
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.ALWAYS_REPLACE);
runner.setProperty(ReplaceText.SEARCH_VALUE, "i do not exist anywhere in the text");
@@ -1542,7 +1478,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("abc.txt\nabc.txt\r\nabc.txt\n");
}
@@ -1551,7 +1487,6 @@ public class TestReplaceText {
// Test the old Default Regex and with a custom Replacement Value that should fail because the
// Perl regex "(?s:^.*$)" must be written "(?s)(^.*$)" in Java for there to be a capture group.
// private static final String DEFAULT_REGEX = "(?s:^.*$)";
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s:^.*$)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${'$1':toUpper()}"); // should uppercase group but there is none
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
@@ -1561,14 +1496,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("");
}
@Test
public void testRegexWithGoodCaptureGroup() {
// Test the new Default Regex and with a custom Replacement Values that should succeed.
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*$)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${'$1':toUpper()}"); // will uppercase group with good Java regex
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
@@ -1578,7 +1512,7 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("TESTING\n123");
}
@@ -1586,23 +1520,19 @@ public class TestReplaceText {
public void testRegexNoCaptureDefaultReplacement() {
// Test the old Default Regex and new Default Regex with the default replacement. This should fail
// because the regex does not create a capture group.
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s:^.*$)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "$1");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.ENTIRE_TEXT);
runner.enqueue("testing\n123".getBytes());
- final AssertionError e = assertThrows(AssertionError.class, () -> {
- runner.run();
- });
+ final AssertionError e = assertThrows(AssertionError.class, () -> runner.run());
assertInstanceOf(IndexOutOfBoundsException.class, e.getCause());
assertTrue(e.getMessage().contains("java.lang.IndexOutOfBoundsException: No group 1"));
}
@Test
public void testProcessorConfigurationRegexNotValid() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?<!\\),*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "hello");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
@@ -1614,7 +1544,7 @@ public class TestReplaceText {
runner.enqueue("(?<!\\),*".getBytes());
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("hello");
runner.setProperty(ReplaceText.SEARCH_VALUE, "");
@@ -1630,7 +1560,6 @@ public class TestReplaceText {
@Test
public void testSurroundWithEntireText() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.SURROUND);
runner.setProperty(ReplaceText.PREPEND_TEXT, "<pre>");
runner.setProperty(ReplaceText.APPEND_TEXT, "<post>");
@@ -1641,13 +1570,12 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile output = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile output = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
output.assertContentEquals("<pre>" + input + "<post>");
}
@Test
public void testSurroundLineByLine() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.SURROUND);
runner.setProperty(ReplaceText.PREPEND_TEXT, "<pre>");
runner.setProperty(ReplaceText.APPEND_TEXT, "<post>");
@@ -1658,15 +1586,13 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile output = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile output = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
output.assertContentEquals("<pre>Hello<post>\n<pre>There<post>\n<pre>How are you<post>\n<pre>Today?<post>");
}
@Test
public void testBackReferenceEscapeWithRegexReplaceUsingEL() {
- final TestRunner runner = getRunner();
-
runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*$)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${'$1':toUpper()}");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
@@ -1676,7 +1602,7 @@ public class TestReplaceText {
runner.enqueue("wo$rd".getBytes());
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals("WO$RD");
runner.enqueue("wo$1rd".getBytes());
@@ -1718,14 +1644,13 @@ public class TestReplaceText {
}
private void testSubstituteVariables(String inputContent, String expectedContent, String evaluationMode, Map<String, String> attributesMap) {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, evaluationMode);
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.SUBSTITUTE_VARIABLES.getValue());
runner.enqueue(inputContent, attributesMap);
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).getFirst();
out.assertContentEquals(expectedContent);
}
@@ -1742,7 +1667,6 @@ public class TestReplaceText {
*/
@Test
public void testForStackOverflow() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "New text");
runner.setProperty(ReplaceText.REPLACEMENT_STRATEGY, ReplaceText.REGEX_REPLACE);
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.ENTIRE_TEXT);
@@ -1768,7 +1692,6 @@ public class TestReplaceText {
*/
@Test
public void testWithInvalidExpression() {
- final TestRunner runner = getRunner();
runner.setProperty(ReplaceText.EVALUATION_MODE, ReplaceText.ENTIRE_TEXT);
runner.setProperty(ReplaceText.SEARCH_VALUE, ".*");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "${date:toDate(\"yyyy/MM/dd\")}");
@@ -1780,11 +1703,19 @@ public class TestReplaceText {
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_FAILURE, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_FAILURE).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(ReplaceText.REL_FAILURE).getFirst();
final String outContent = translateNewLines(new String(out.toByteArray(), StandardCharsets.UTF_8));
assertEquals("hi", outContent);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of("Regular Expression", ReplaceText.SEARCH_VALUE.getName());
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private String translateNewLines(final File file) throws IOException {
return translateNewLines(file.toPath());
}
@@ -1796,7 +1727,7 @@ public class TestReplaceText {
}
private String translateNewLines(final String text) {
- final String lineSeparator = System.getProperty("line.separator");
+ final String lineSeparator = System.lineSeparator();
final Pattern pattern = Pattern.compile("\n", Pattern.MULTILINE);
final String translated = pattern.matcher(text).replaceAll(lineSeparator);
return translated;
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java
index 8a6f3341fa..a3ebc4f486 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestRetryFlowFile.java
@@ -16,6 +16,7 @@
*/
package org.apache.nifi.processors.standard;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.AfterEach;
@@ -26,6 +27,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import static org.apache.nifi.processors.standard.RetryFlowFile.FAIL_ON_OVERWRITE;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -138,7 +141,7 @@ public class TestRetryFlowFile {
@Test
public void testFailOnOverwrite() {
- runner.setProperty(RetryFlowFile.FAIL_ON_OVERWRITE, "true");
+ runner.setProperty(FAIL_ON_OVERWRITE, "true");
runner.enqueue("", Collections.singletonMap("flowfile.retries", "ZZAaa"));
runner.run();
@@ -255,4 +258,18 @@ public class TestRetryFlowFile {
runner.assertTransferCount(RetryFlowFile.RETRIES_EXCEEDED, 0);
runner.assertTransferCount(RetryFlowFile.FAILURE, 1);
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("retry-attribute", RetryFlowFile.RETRY_ATTRIBUTE.getName()),
+ Map.entry("maximum-retries", RetryFlowFile.MAXIMUM_RETRIES.getName()),
+ Map.entry("penalize-retries", RetryFlowFile.PENALIZE_RETRIED.getName()),
+ Map.entry("reuse-mode", RetryFlowFile.REUSE_MODE.getName()),
+ Map.entry("Fail on Non-numerical Overwrite", RetryFlowFile.FAIL_ON_OVERWRITE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java
index 4a920c820a..6e2422c821 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestSampleRecord.java
@@ -26,8 +26,10 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
@@ -43,12 +45,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestSampleRecord {
- @Test
- public void testIntervalSampling() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
+ private TestRunner runner;
+ private MockRecordParser readerService;
+
+ @BeforeEach
+ void setUp() throws InitializationException {
+ runner = TestRunners.newTestRunner(SampleRecord.class);
+ readerService = new MockRecordParser();
final MockRecordWriter writerService = new MockRecordWriter("header", false);
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
runner.addControllerService("reader", readerService);
runner.enableControllerService(readerService);
runner.addControllerService("writer", writerService);
@@ -56,6 +61,10 @@ public class TestSampleRecord {
runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
+ }
+
+ @Test
+ public void testIntervalSampling() {
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.INTERVAL_SAMPLING_KEY);
runner.assertNotValid();
runner.setProperty(SampleRecord.SAMPLING_INTERVAL, "4");
@@ -71,7 +80,7 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "25");
runner.clearTransferState();
@@ -81,23 +90,12 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "100");
}
@Test
- public void testIntervalSamplingWithNoRecords() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
- final MockRecordWriter writerService = new MockRecordWriter("header", false);
-
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
- runner.addControllerService("reader", readerService);
- runner.enableControllerService(readerService);
- runner.addControllerService("writer", writerService);
- runner.enableControllerService(writerService);
-
- runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
- runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
+ public void testIntervalSamplingWithNoRecords() {
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.INTERVAL_SAMPLING_KEY);
runner.assertNotValid();
runner.setProperty(SampleRecord.SAMPLING_INTERVAL, "0");
@@ -113,22 +111,13 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "0");
}
@Test
- public void testRangeSampling() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
- final MockRecordWriter writerService = new MockRecordWriter("header", false);
-
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
- runner.addControllerService("reader", readerService);
- runner.enableControllerService(readerService);
- runner.addControllerService("writer", writerService);
- runner.enableControllerService(writerService);
-
+ public void testRangeSampling() {
runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.RANGE_SAMPLING_KEY);
@@ -146,7 +135,7 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "6");
runner.clearTransferState();
@@ -156,7 +145,7 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "1");
out.assertContentEquals("header\n3,8\n");
@@ -167,7 +156,7 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "2");
out.assertContentEquals("header\n1,6\n2,7\n");
@@ -179,7 +168,7 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "2");
out.assertContentEquals("header\n8,13\n20,25\n");
@@ -190,23 +179,12 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "100");
}
@Test
- public void testProbabilisticSamplingWithSeed() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
- final MockRecordWriter writerService = new MockRecordWriter("header", false);
-
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
- runner.addControllerService("reader", readerService);
- runner.enableControllerService(readerService);
- runner.addControllerService("writer", writerService);
- runner.enableControllerService(writerService);
-
- runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
- runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
+ public void testProbabilisticSamplingWithSeed() {
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.PROBABILISTIC_SAMPLING_KEY);
runner.assertNotValid();
runner.setProperty(SampleRecord.SAMPLING_PROBABILITY, "10");
@@ -223,7 +201,7 @@ public class TestSampleRecord {
runner.run();
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
String firstContent = new String(runner.getContentAsByteArray(first));
runner.clearTransferState();
@@ -231,25 +209,14 @@ public class TestSampleRecord {
runner.run();
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile second = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile second = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
String secondContent = new String(runner.getContentAsByteArray(second));
assertEquals(firstContent, secondContent);
}
@Test
- public void testProbabilisticSamplingWithAllRecords() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
- final MockRecordWriter writerService = new MockRecordWriter("header", false);
-
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
- runner.addControllerService("reader", readerService);
- runner.enableControllerService(readerService);
- runner.addControllerService("writer", writerService);
- runner.enableControllerService(writerService);
-
- runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
- runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
+ public void testProbabilisticSamplingWithAllRecords() {
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.PROBABILISTIC_SAMPLING_KEY);
runner.assertNotValid();
runner.setProperty(SampleRecord.SAMPLING_PROBABILITY, "100");
@@ -278,7 +245,7 @@ public class TestSampleRecord {
runner.run();
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
String[] content = new String(runner.getContentAsByteArray(first)).split(".*\n");
for (int i = 0; i < content.length; i++) {
assertEquals(content[i], records.get(i).toString());
@@ -286,18 +253,7 @@ public class TestSampleRecord {
}
@Test
- public void testProbabilisticSamplingWithNoRecords() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
- final MockRecordWriter writerService = new MockRecordWriter("header", false);
-
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
- runner.addControllerService("reader", readerService);
- runner.enableControllerService(readerService);
- runner.addControllerService("writer", writerService);
- runner.enableControllerService(writerService);
-
- runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
- runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
+ public void testProbabilisticSamplingWithNoRecords() {
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.PROBABILISTIC_SAMPLING_KEY);
runner.assertNotValid();
runner.setProperty(SampleRecord.SAMPLING_PROBABILITY, "0");
@@ -316,24 +272,13 @@ public class TestSampleRecord {
runner.run();
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
String content = new String(runner.getContentAsByteArray(first));
assertTrue(content.isEmpty());
}
@Test
- public void testReservoirSampling() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
- final MockRecordWriter writerService = new MockRecordWriter("header", false);
-
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
- runner.addControllerService("reader", readerService);
- runner.enableControllerService(readerService);
- runner.addControllerService("writer", writerService);
- runner.enableControllerService(writerService);
-
- runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
- runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
+ public void testReservoirSampling() {
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.RESERVOIR_SAMPLING_KEY);
runner.assertNotValid();
runner.setProperty(SampleRecord.RESERVOIR_SIZE, "10");
@@ -349,24 +294,13 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile out = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
out.assertAttributeEquals("record.count", "10");
}
@Test
- public void testReservoirSamplingWithSeed() throws InitializationException {
- final MockRecordParser readerService = new MockRecordParser();
- final MockRecordWriter writerService = new MockRecordWriter("header", false);
-
- final TestRunner runner = TestRunners.newTestRunner(SampleRecord.class);
- runner.addControllerService("reader", readerService);
- runner.enableControllerService(readerService);
- runner.addControllerService("writer", writerService);
- runner.enableControllerService(writerService);
-
- runner.setProperty(SampleRecord.RECORD_READER_FACTORY, "reader");
- runner.setProperty(SampleRecord.RECORD_WRITER_FACTORY, "writer");
+ public void testReservoirSamplingWithSeed() {
runner.setProperty(SampleRecord.SAMPLING_STRATEGY, SampleRecord.RESERVOIR_SAMPLING_KEY);
runner.setProperty(SampleRecord.RANDOM_SEED, "1");
runner.assertNotValid();
@@ -383,7 +317,7 @@ public class TestSampleRecord {
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile first = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
String firstContent = new String(runner.getContentAsByteArray(first));
first.assertAttributeEquals("record.count", "10");
@@ -392,9 +326,26 @@ public class TestSampleRecord {
runner.run();
runner.assertTransferCount(SampleRecord.REL_SUCCESS, 1);
runner.assertTransferCount(SampleRecord.REL_ORIGINAL, 1);
- final MockFlowFile second = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).get(0);
+ final MockFlowFile second = runner.getFlowFilesForRelationship(SampleRecord.REL_SUCCESS).getFirst();
String secondContent = new String(runner.getContentAsByteArray(second));
assertEquals(firstContent, secondContent);
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("record-reader", SampleRecord.RECORD_READER_FACTORY.getName()),
+ Map.entry("record-writer", SampleRecord.RECORD_WRITER_FACTORY.getName()),
+ Map.entry("sample-record-sampling-strategy", SampleRecord.SAMPLING_STRATEGY.getName()),
+ Map.entry("sample-record-interval", SampleRecord.SAMPLING_INTERVAL.getName()),
+ Map.entry("sample-record-range", SampleRecord.SAMPLING_RANGE.getName()),
+ Map.entry("sample-record-probability", SampleRecord.SAMPLING_PROBABILITY.getName()),
+ Map.entry("sample-record-reservoir", SampleRecord.RESERVOIR_SIZE.getName()),
+ Map.entry("sample-record-random-seed", SampleRecord.RANDOM_SEED.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
index 1ef389c33c..d222871123 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTailFile.java
@@ -21,6 +21,7 @@ import org.apache.nifi.components.state.StateMap;
import org.apache.nifi.processors.standard.TailFile.TailFileState;
import org.apache.nifi.util.MockFlowFile;
import org.apache.nifi.util.MockProcessContext;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.AfterEach;
@@ -59,7 +60,6 @@ import static org.junit.jupiter.api.Assertions.fail;
public class TestTailFile {
private File file;
- private File existingFile;
private File otherFile;
private RandomAccessFile raf;
@@ -76,7 +76,7 @@ public class TestTailFile {
file.delete();
assertTrue(file.createNewFile());
- existingFile = new File("target/existing-log.txt");
+ File existingFile = new File("target/existing-log.txt");
existingFile.delete();
assertTrue(existingFile.createNewFile());
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(existingFile)))) {
@@ -1289,6 +1289,24 @@ public class TestTailFile {
runner.clearTransferState();
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("tail-base-directory", TailFile.BASE_DIRECTORY.getName()),
+ Map.entry("tail-mode", TailFile.MODE.getName()),
+ Map.entry("File to Tail", TailFile.FILENAME.getName()),
+ Map.entry("File Location", TailFile.STATE_LOCATION.getName()),
+ Map.entry("tailfile-recursive-lookup", TailFile.RECURSIVE.getName()),
+ Map.entry("tailfile-lookup-frequency", TailFile.LOOKUP_FREQUENCY.getName()),
+ Map.entry("tailfile-maximum-age", TailFile.MAXIMUM_AGE.getName()),
+ Map.entry("reread-on-nul", TailFile.REREAD_ON_NUL.getName()),
+ Map.entry("pre-allocated-buffer-size", TailFile.PRE_ALLOCATED_BUFFER_SIZE.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void assertNumberOfStateMapEntries(int expectedNumberOfLogFiles) throws IOException {
final int numberOfStateKeysPerFile = 6;
StateMap states = runner.getStateManager().getState(Scope.LOCAL);
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java
index 1775e781f2..55ee41aa19 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestTransformXml.java
@@ -20,8 +20,10 @@ import org.apache.nifi.lookup.SimpleKeyValueLookupService;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockComponentLog;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.BufferedReader;
@@ -33,21 +35,26 @@ import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
+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 TestTransformXml {
+ private TestRunner runner;
+
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(TransformXml.class);
+ }
@Test
public void testStylesheetNotFound() {
- final TestRunner controller = TestRunners.newTestRunner(TransformXml.class);
- controller.setProperty(TransformXml.XSLT_FILE_NAME, "/no/path/to/math.xsl");
- controller.assertNotValid();
+ runner.setProperty(TransformXml.XSLT_FILE_NAME, "/no/path/to/math.xsl");
+ runner.assertNotValid();
}
@Test
public void testNonXmlContent() {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/math.xsl");
final Map<String, String> attributes = new HashMap<>();
@@ -56,13 +63,12 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_FAILURE);
- final MockFlowFile original = runner.getFlowFilesForRelationship(TransformXml.REL_FAILURE).get(0);
+ final MockFlowFile original = runner.getFlowFilesForRelationship(TransformXml.REL_FAILURE).getFirst();
original.assertContentEquals("not xml");
}
@Test
public void testTransformMath() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty("header", "Test for mod");
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/math.xsl");
@@ -71,7 +77,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/math.html"))).trim();
transformed.assertContentEquals(expectedContent);
@@ -79,7 +85,6 @@ public class TestTransformXml {
@Test
public void testTransformCsv() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/tokens.xsl");
runner.setProperty("uuid_0", "${uuid_0}");
runner.setProperty("uuid_1", "${uuid_1}");
@@ -105,7 +110,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/tokens.xml")));
transformed.assertContentEquals(expectedContent);
@@ -114,7 +119,6 @@ public class TestTransformXml {
@Test
public void testTransformExpressionLanguage() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty("header", "Test for mod");
runner.setProperty(TransformXml.XSLT_FILE_NAME, "${xslt.path}");
@@ -124,7 +128,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/math.html"))).trim();
transformed.assertContentEquals(expectedContent);
@@ -132,7 +136,6 @@ public class TestTransformXml {
@Test
public void testTransformNoCache() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty("header", "Test for mod");
runner.setProperty(TransformXml.CACHE_SIZE, "0");
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/math.xsl");
@@ -140,7 +143,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/math.html"))).trim();
transformed.assertContentEquals(expectedContent);
@@ -148,7 +151,6 @@ public class TestTransformXml {
@Test
public void testTransformBothControllerFileNotValid() throws InitializationException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/math.xsl");
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
@@ -163,15 +165,12 @@ public class TestTransformXml {
@Test
public void testTransformNoneControllerFileNotValid() {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty(TransformXml.CACHE_SIZE, "0");
runner.assertNotValid();
}
@Test
public void testTransformControllerNoKey() throws InitializationException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
-
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
runner.addControllerService("simple-key-value-lookup-service", service);
runner.setProperty(service, "key1", "value1");
@@ -184,8 +183,6 @@ public class TestTransformXml {
@Test
public void testTransformWithController() throws IOException, InitializationException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
-
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
runner.addControllerService("simple-key-value-lookup-service", service);
runner.setProperty(service, "math", "<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
@@ -209,7 +206,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/math.html"))).trim();
transformed.assertContentEquals(expectedContent);
@@ -217,8 +214,6 @@ public class TestTransformXml {
@Test
public void testTransformWithXsltNotFoundInController() throws IOException, InitializationException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
-
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
runner.addControllerService("simple-key-value-lookup-service", service);
runner.enableControllerService(service);
@@ -238,8 +233,6 @@ public class TestTransformXml {
@Test
public void testTransformWithControllerNoCache() throws IOException, InitializationException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
-
final SimpleKeyValueLookupService service = new SimpleKeyValueLookupService();
runner.addControllerService("simple-key-value-lookup-service", service);
runner.setProperty(service, "math", "<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">"
@@ -264,7 +257,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/math.html"))).trim();
transformed.assertContentEquals(expectedContent);
@@ -272,7 +265,6 @@ public class TestTransformXml {
@Test
public void testTransformSecureProcessingEnabledXmlWithEntity() {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/doc-node.xsl");
runner.setProperty(TransformXml.INDENT_OUTPUT, Boolean.FALSE.toString());
@@ -281,7 +273,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><doc xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"/>";
transformed.assertContentEquals(expected);
@@ -289,7 +281,6 @@ public class TestTransformXml {
@Test
public void testTransformSecureProcessingEnabledXslWithEntity() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/doctype-entity-file-uri.xsl");
runner.setProperty(TransformXml.INDENT_OUTPUT, Boolean.FALSE.toString());
@@ -297,14 +288,13 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
transformed.assertContentEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
@Test
public void testNonMatchingTemplateTag() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty("header", "Test for mod");
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/nonMatchingEndTag.xsl");
@@ -314,13 +304,12 @@ public class TestTransformXml {
runner.assertAllFlowFilesTransferred(TransformXml.REL_FAILURE);
MockComponentLog logger = runner.getLogger();
assertFalse(logger.getErrorMessages().isEmpty());
- String firstMessage = logger.getErrorMessages().get(0).getMsg();
+ String firstMessage = logger.getErrorMessages().getFirst().getMsg();
assertTrue(firstMessage.contains("xsl:template"));
}
@Test
public void testMessageTerminate() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty("header", "Test message terminate");
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/employeeMessageTerminate.xsl");
@@ -330,13 +319,12 @@ public class TestTransformXml {
runner.assertAllFlowFilesTransferred(TransformXml.REL_FAILURE);
MockComponentLog logger = runner.getLogger();
assertFalse(logger.getErrorMessages().isEmpty());
- String firstMessage = logger.getErrorMessages().get(0).getMsg();
+ String firstMessage = logger.getErrorMessages().getFirst().getMsg();
assertTrue(firstMessage.contains("xsl:message"));
}
@Test
public void testMessageNonTerminate() throws IOException {
- final TestRunner runner = TestRunners.newTestRunner(new TransformXml());
runner.setProperty("header", "Test message non terminate");
runner.setProperty(TransformXml.XSLT_FILE_NAME, "src/test/resources/TestTransformXml/employeeMessageNonTerminate.xsl");
@@ -344,7 +332,7 @@ public class TestTransformXml {
runner.run();
runner.assertAllFlowFilesTransferred(TransformXml.REL_SUCCESS);
- final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).get(0);
+ final MockFlowFile transformed = runner.getFlowFilesForRelationship(TransformXml.REL_SUCCESS).getFirst();
final String expectedContent = new String(Files.readAllBytes(Paths.get("src/test/resources/TestTransformXml/employee.html")));
transformed.assertContentEquals(expectedContent);
@@ -352,4 +340,21 @@ public class TestTransformXml {
assertTrue(logger.getErrorMessages().isEmpty());
assertTrue(logger.getWarnMessages().isEmpty());
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("xslt-controller", TransformXml.XSLT_CONTROLLER.getName()),
+ Map.entry("xslt-controller-key", TransformXml.XSLT_CONTROLLER_KEY.getName()),
+ Map.entry("XSLT Lookup key", TransformXml.XSLT_CONTROLLER_KEY.getName()),
+ Map.entry("indent-output", TransformXml.INDENT_OUTPUT.getName()),
+ Map.entry("secure-processing", TransformXml.SECURE_PROCESSING.getName()),
+ Map.entry("cache-size", TransformXml.CACHE_SIZE.getName()),
+ Map.entry("cache-ttl-after-last-access", TransformXml.CACHE_TTL_AFTER_LAST_ACCESS.getName()),
+ Map.entry("XSLT file name", TransformXml.XSLT_FILE_NAME.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
index 4b69676d0e..9edfe081f6 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUnpackContent.java
@@ -24,6 +24,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.Test;
@@ -459,7 +460,7 @@ public class TestUnpackContent {
runner.assertTransferCount(UnpackContent.REL_SUCCESS, 2);
runner.assertTransferCount(UnpackContent.REL_ORIGINAL, 1);
- runner.getFlowFilesForRelationship(UnpackContent.REL_ORIGINAL).get(0).assertAttributeEquals(FRAGMENT_COUNT, "2");
+ runner.getFlowFilesForRelationship(UnpackContent.REL_ORIGINAL).getFirst().assertAttributeEquals(FRAGMENT_COUNT, "2");
runner.assertTransferCount(UnpackContent.REL_FAILURE, 0);
final List<MockFlowFile> unpacked = runner.getFlowFilesForRelationship(UnpackContent.REL_SUCCESS);
@@ -494,7 +495,7 @@ public class TestUnpackContent {
runner.assertTransferCount(UnpackContent.REL_SUCCESS, 2);
runner.assertTransferCount(UnpackContent.REL_ORIGINAL, 1);
- final MockFlowFile originalFlowFile = runner.getFlowFilesForRelationship(UnpackContent.REL_ORIGINAL).get(0);
+ final MockFlowFile originalFlowFile = runner.getFlowFilesForRelationship(UnpackContent.REL_ORIGINAL).getFirst();
originalFlowFile.assertAttributeExists(FRAGMENT_ID);
originalFlowFile.assertAttributeEquals(FRAGMENT_COUNT, "2");
runner.assertTransferCount(UnpackContent.REL_FAILURE, 0);
@@ -576,6 +577,16 @@ public class TestUnpackContent {
runner.assertTransferCount(UnpackContent.REL_SUCCESS, numThreads * 2);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "allow-stored-entries-wdd", UnpackContent.ALLOW_STORED_ENTRIES_WITH_DATA_DESCRIPTOR.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private void runZipEncryptionMethod(final EncryptionMethod encryptionMethod) throws IOException {
runner.setProperty(UnpackContent.PACKAGING_FORMAT, UnpackContent.PackageFormat.ZIP_FORMAT);
runner.setProperty(UnpackContent.ALLOW_STORED_ENTRIES_WITH_DATA_DESCRIPTOR, "false");
@@ -592,7 +603,7 @@ public class TestUnpackContent {
runner.assertTransferCount(UnpackContent.REL_SUCCESS, 1);
runner.assertTransferCount(UnpackContent.REL_ORIGINAL, 1);
- final MockFlowFile unpacked = runner.getFlowFilesForRelationship(UnpackContent.REL_SUCCESS).iterator().next();
+ final MockFlowFile unpacked = runner.getFlowFilesForRelationship(UnpackContent.REL_SUCCESS).getFirst();
unpacked.assertAttributeEquals(UnpackContent.FILE_ENCRYPTION_METHOD_ATTRIBUTE, encryptionMethod.toString());
unpacked.assertAttributeEquals(UnpackContent.FRAGMENT_INDEX, FIRST_FRAGMENT_INDEX);
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java
index 6abe5d3f23..3b1f7c5e27 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateCounter.java
@@ -16,8 +16,10 @@
*/
package org.apache.nifi.processors.standard;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
@@ -26,35 +28,47 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestUpdateCounter {
+ private TestRunner runner;
+ @BeforeEach
+ void setUp() {
+ runner = TestRunners.newTestRunner(new UpdateCounter());
+ }
@Test
public void testwithFileName() {
- final TestRunner firstrunner = TestRunners.newTestRunner(new UpdateCounter());
- firstrunner.setProperty(UpdateCounter.COUNTER_NAME, "firewall");
- firstrunner.setProperty(UpdateCounter.DELTA, "1");
+ runner.setProperty(UpdateCounter.COUNTER_NAME, "firewall");
+ runner.setProperty(UpdateCounter.DELTA, "1");
Map<String, String> attributes = new HashMap<>();
- firstrunner.enqueue("", attributes);
- firstrunner.run();
- firstrunner.assertAllFlowFilesTransferred(UpdateCounter.SUCCESS, 1);
+ runner.enqueue("", attributes);
+ runner.run();
+ runner.assertAllFlowFilesTransferred(UpdateCounter.SUCCESS, 1);
}
@Test
public void testExpressionLanguage() {
-
- final TestRunner firstrunner = TestRunners.newTestRunner(new UpdateCounter());
- firstrunner.setProperty(UpdateCounter.COUNTER_NAME, "${filename}");
- firstrunner.setProperty(UpdateCounter.DELTA, "${num}");
+ runner.setProperty(UpdateCounter.COUNTER_NAME, "${filename}");
+ runner.setProperty(UpdateCounter.DELTA, "${num}");
final Map<String, String> attributes = new HashMap<>();
attributes.put("filename", "test");
attributes.put("num", "40");
- firstrunner.enqueue(new byte[0], attributes);
- firstrunner.run();
- Long counter = firstrunner.getCounterValue("test");
- assertEquals(java.util.Optional.ofNullable(counter), java.util.Optional.ofNullable(40L));
- firstrunner.assertAllFlowFilesTransferred(UpdateCounter.SUCCESS, 1);
+ runner.enqueue(new byte[0], attributes);
+ runner.run();
+ Long counter = runner.getCounterValue("test");
+ assertEquals(java.util.Optional.ofNullable(counter), java.util.Optional.of(40L));
+ runner.assertAllFlowFilesTransferred(UpdateCounter.SUCCESS, 1);
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.of(
+ "counter-name", UpdateCounter.COUNTER_NAME.getName(),
+ "delta", UpdateCounter.DELTA.getName()
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateDatabaseTable.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateDatabaseTable.java
index c4251fd979..2b472e065b 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateDatabaseTable.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestUpdateDatabaseTable.java
@@ -22,6 +22,7 @@ import org.apache.nifi.serialization.record.MockRecordWriter;
import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -364,6 +365,29 @@ class TestUpdateDatabaseTable extends AbstractDatabaseConnectionServiceTest {
}
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("record-reader", UpdateDatabaseTable.RECORD_READER.getName()),
+ Map.entry("db-type", UpdateDatabaseTable.DB_TYPE.getName()),
+ Map.entry("updatedatabasetable-dbcp-service", UpdateDatabaseTable.DBCP_SERVICE.getName()),
+ Map.entry("updatedatabasetable-catalog-name", UpdateDatabaseTable.CATALOG_NAME.getName()),
+ Map.entry("updatedatabasetable-schema-name", UpdateDatabaseTable.SCHEMA_NAME.getName()),
+ Map.entry("updatedatabasetable-table-name", UpdateDatabaseTable.TABLE_NAME.getName()),
+ Map.entry("updatedatabasetable-create-table", UpdateDatabaseTable.CREATE_TABLE.getName()),
+ Map.entry("updatedatabasetable-primary-keys", UpdateDatabaseTable.PRIMARY_KEY_FIELDS.getName()),
+ Map.entry("updatedatabasetable-translate-field-names", UpdateDatabaseTable.TRANSLATE_FIELD_NAMES.getName()),
+ Map.entry("updatedatabasetable-update-field-names", UpdateDatabaseTable.UPDATE_FIELD_NAMES.getName()),
+ Map.entry("updatedatabasetable-record-writer", UpdateDatabaseTable.RECORD_WRITER_FACTORY.getName()),
+ Map.entry("updatedatabasetable-quoted-column-identifiers", UpdateDatabaseTable.QUOTE_COLUMN_IDENTIFIERS.getName()),
+ Map.entry("updatedatabasetable-quoted-table-identifiers", UpdateDatabaseTable.QUOTE_TABLE_IDENTIFIER.getName()),
+ Map.entry("updatedatabasetable-query-timeout", UpdateDatabaseTable.QUERY_TIMEOUT.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private ResultSet getTableColumns(final Statement statement, final String tableName) throws SQLException {
return statement.executeQuery("""
SELECT
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java
index ab22f2a79e..9e031e4863 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateCsv.java
@@ -17,6 +17,7 @@
package org.apache.nifi.processors.standard;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.Test;
@@ -24,6 +25,8 @@ import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class TestValidateCsv {
private final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
@@ -99,7 +102,7 @@ public class TestValidateCsv {
runner.run();
runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("Name,Birthdate,Weight\nJohn,22/11/1954,63.2\nBob,01/03/2004,45.0");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertContentEquals("Name,Birthdate,Weight\nJohn,22/11/1954,63.2\nBob,01/03/2004,45.0");
runner.assertTransferCount(ValidateCsv.REL_INVALID, 0);
runner.clearTransferState();
@@ -109,7 +112,7 @@ public class TestValidateCsv {
runner.assertTransferCount(ValidateCsv.REL_VALID, 0);
runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertContentEquals("Name,Birthdate,Weight\nJohn,22/11/1954,63a2\nBob,01/032004,45.0");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertContentEquals("Name,Birthdate,Weight\nJohn,22/11/1954,63a2\nBob,01/032004,45.0");
runner.clearTransferState();
@@ -117,9 +120,9 @@ public class TestValidateCsv {
runner.run();
runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("Name,Birthdate,Weight\nBob,01/03/2004,45.0");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertContentEquals("Name,Birthdate,Weight\nBob,01/03/2004,45.0");
runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertContentEquals("Name,Birthdate,Weight\nJohn,22/111954,63.2");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertContentEquals("Name,Birthdate,Weight\nJohn,22/111954,63.2");
}
@Test
@@ -136,7 +139,7 @@ public class TestValidateCsv {
runner.run();
runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("#Name,Birthdate,Weight\nJohn,\"\",63.2\nBob,,45.0");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertContentEquals("#Name,Birthdate,Weight\nJohn,\"\",63.2\nBob,,45.0");
runner.assertTransferCount(ValidateCsv.REL_INVALID, 0);
}
@@ -156,12 +159,12 @@ public class TestValidateCsv {
runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("John\r\nBob\r\nTom");
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertAttributeEquals("count.total.lines", "5");
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertAttributeEquals("count.valid.lines", "3");
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertContentEquals("Bob\r\nJohn");
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertAttributeEquals("count.invalid.lines", "2");
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertAttributeEquals("count.total.lines", "5");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertContentEquals("John\r\nBob\r\nTom");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertAttributeEquals("count.total.lines", "5");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertAttributeEquals("count.valid.lines", "3");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertContentEquals("Bob\r\nJohn");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertAttributeEquals("count.invalid.lines", "2");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertAttributeEquals("count.total.lines", "5");
}
@Test
@@ -181,7 +184,7 @@ public class TestValidateCsv {
runner.enqueue("John,22/111954,abc\r\nBob,01/03/2004,45.0");
runner.run();
runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertAttributeEquals("validation.error.message",
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertAttributeEquals("validation.error.message",
"At {line=1, row=1}, '22/111954' could not be parsed as a Date at {column=2}, 'abc' could not be parsed as a Double at {column=3}");
}
@@ -350,7 +353,7 @@ public class TestValidateCsv {
runner.enqueue("test,test,testapache.org");
runner.run();
runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertAttributeEquals("validation.error.message",
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertAttributeEquals("validation.error.message",
"'testapache.org' does not match the regular expression '[a-z0-9\\._]+@[a-z0-9\\.]+' at {line=1, row=1, column=3}");
}
@@ -498,7 +501,7 @@ public class TestValidateCsv {
runner.assertTransferCount(ValidateCsv.REL_VALID, 0);
runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertContentEquals(row);
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).getFirst().assertContentEquals(row);
runner.clearTransferState();
runner.setProperty(ValidateCsv.SCHEMA, "null,null,null");
@@ -507,7 +510,7 @@ public class TestValidateCsv {
runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
runner.assertTransferCount(ValidateCsv.REL_INVALID, 0);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals(row);
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertContentEquals(row);
}
@Test
@@ -524,7 +527,23 @@ public class TestValidateCsv {
runner.run();
runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
- runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("Header 1, Header 2, Header 3\n\"Content 1a, Content 1b\", Content 2, Content 3");
+ runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).getFirst().assertContentEquals("Header 1, Header 2, Header 3\n\"Content 1a, Content 1b\", Content 2, Content 3");
runner.assertTransferCount(ValidateCsv.REL_INVALID, 0);
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("validate-csv-schema", ValidateCsv.SCHEMA.getName()),
+ Map.entry("validate-csv-header", ValidateCsv.HEADER.getName()),
+ Map.entry("validate-csv-quote", ValidateCsv.QUOTE_CHARACTER.getName()),
+ Map.entry("validate-csv-delimiter", ValidateCsv.DELIMITER_CHARACTER.getName()),
+ Map.entry("validate-csv-eol", ValidateCsv.END_OF_LINE_CHARACTER.getName()),
+ Map.entry("validate-csv-strategy", ValidateCsv.VALIDATION_STRATEGY.getName()),
+ Map.entry("validate-csv-violations", ValidateCsv.INCLUDE_ALL_VIOLATIONS.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java
index 3388b1bfd6..58b29782f0 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestValidateRecord.java
@@ -42,6 +42,7 @@ import org.apache.nifi.serialization.record.RecordField;
import org.apache.nifi.serialization.record.RecordFieldType;
import org.apache.nifi.serialization.record.RecordSchema;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -988,6 +989,29 @@ public class TestValidateRecord {
+ "The following 1 fields had values whose type did not match the schema: [/id]");
}
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("record-reader", ValidateRecord.RECORD_READER.getName()),
+ Map.entry("record-writer", ValidateRecord.RECORD_WRITER.getName()),
+ Map.entry("invalid-record-writer", ValidateRecord.INVALID_RECORD_WRITER.getName()),
+ Map.entry("allow-extra-fields", ValidateRecord.ALLOW_EXTRA_FIELDS.getName()),
+ Map.entry("strict-type-checking", ValidateRecord.STRICT_TYPE_CHECKING.getName()),
+ Map.entry("coerce-types", ValidateRecord.COERCE_TYPES.getName()),
+ Map.entry("validation-details-attribute-name", ValidateRecord.VALIDATION_DETAILS_ATTRIBUTE_NAME.getName()),
+ Map.entry("maximum-validation-details-length", ValidateRecord.MAX_VALIDATION_DETAILS_LENGTH.getName()),
+ Map.entry(SchemaAccessUtils.OLD_SCHEMA_REGISTRY_PROPERTY_NAME, SCHEMA_REGISTRY.getName()),
+ Map.entry(SchemaAccessUtils.OLD_SCHEMA_NAME_PROPERTY_NAME, SCHEMA_NAME.getName()),
+ Map.entry(SchemaAccessUtils.OLD_SCHEMA_BRANCH_NAME_PROPERTY_NAME, SCHEMA_BRANCH_NAME.getName()),
+ Map.entry(SchemaAccessUtils.OLD_SCHEMA_VERSION_PROPERTY_NAME, SCHEMA_VERSION.getName()),
+ Map.entry(SchemaAccessUtils.OLD_SCHEMA_TEXT_PROPERTY_NAME, SCHEMA_TEXT.getName()),
+ Map.entry(SchemaAccessUtils.OLD_SCHEMA_ACCESS_STRATEGY_PROPERTY_NAME, ValidateRecord.SCHEMA_ACCESS_STRATEGY.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
+
private String getSystemZoneOffsetId(final LocalDateTime inputLocalDateTime) {
final ZoneId systemDefaultZoneId = ZoneOffset.systemDefault();
final ZoneRules zoneRules = systemDefaultZoneId.getRules();
diff --git a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java
index c8aa31a90a..90dc1216a5 100644
--- a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java
+++ b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestWait.java
@@ -20,6 +20,7 @@ import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.processors.standard.TestNotify.MockCacheClient;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.MockFlowFile;
+import org.apache.nifi.util.PropertyMigrationResult;
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.BeforeEach;
@@ -60,7 +61,7 @@ public class TestWait {
}
@Test
- public void testWait() throws InitializationException {
+ public void testWait() {
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
final Map<String, String> props = new HashMap<>();
@@ -71,13 +72,13 @@ public class TestWait {
// no cache key attribute
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
- MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
ff.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
runner.clearTransferState();
}
@Test
- public void testWaitKeepInUpstreamConnection() throws InitializationException {
+ public void testWaitKeepInUpstreamConnection() {
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
runner.setProperty(Wait.WAIT_MODE, Wait.WAIT_MODE_KEEP_IN_UPSTREAM);
@@ -93,7 +94,7 @@ public class TestWait {
}
@Test
- public void testExpired() throws InitializationException, InterruptedException {
+ public void testExpired() throws InterruptedException {
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
runner.setProperty(Wait.EXPIRATION_DURATION, "100 ms");
@@ -104,7 +105,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
- MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
ff.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
runner.clearTransferState();
@@ -114,13 +115,13 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_EXPIRED, 1);
- ff = runner.getFlowFilesForRelationship(Wait.REL_EXPIRED).get(0);
+ ff = runner.getFlowFilesForRelationship(Wait.REL_EXPIRED).getFirst();
ff.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
runner.clearTransferState();
}
@Test
- public void testCounterExpired() throws InitializationException, InterruptedException, IOException {
+ public void testCounterExpired() throws InterruptedException, IOException {
runner.setProperty(Wait.RELEASE_SIGNAL_IDENTIFIER, "${releaseSignalAttribute}");
runner.setProperty(Wait.TARGET_SIGNAL_COUNT, "5");
runner.setProperty(Wait.EXPIRATION_DURATION, "100 ms");
@@ -132,7 +133,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
- MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
ff.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
runner.clearTransferState();
runner.enqueue(ff);
@@ -148,7 +149,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_EXPIRED, 1);
- ff = runner.getFlowFilesForRelationship(Wait.REL_EXPIRED).get(0);
+ ff = runner.getFlowFilesForRelationship(Wait.REL_EXPIRED).getFirst();
ff.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
// Even if wait didn't complete, signal attributes should be set
ff.assertAttributeEquals("wait.counter.total", "3");
@@ -172,7 +173,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_FAILURE, 1);
- MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_FAILURE).get(0);
+ MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_FAILURE).getFirst();
ff.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
runner.clearTransferState();
}
@@ -187,7 +188,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_FAILURE, 1);
- MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_FAILURE).get(0);
+ MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_FAILURE).getFirst();
ff.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
ff.assertAttributeNotExists("wait.counter.total");
@@ -202,9 +203,7 @@ public class TestWait {
final Map<String, String> props = new HashMap<>();
props.put("releaseSignalAttribute", "2");
runner.enqueue(new byte[]{}, props);
- final AssertionError e = assertThrows(AssertionError.class, () -> {
- runner.run();
- });
+ final AssertionError e = assertThrows(AssertionError.class, () -> runner.run());
assertInstanceOf(ProcessException.class, e.getCause());
assertInstanceOf(IOException.class, e.getCause().getCause());
service.setFailOnCalls(false);
@@ -222,7 +221,7 @@ public class TestWait {
runner.run(1, false);
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
- MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ MockFlowFile ff = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
ff.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
runner.clearTransferState();
@@ -242,7 +241,7 @@ public class TestWait {
}
@Test
- public void testReplaceAttributes() throws InitializationException, IOException {
+ public void testReplaceAttributes() throws IOException {
Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("both", "notifyValue");
cachedAttributes.put("uuid", "notifyUuid");
@@ -270,7 +269,7 @@ public class TestWait {
runner.assertAllFlowFilesTransferred(Wait.REL_SUCCESS, 1);
runner.assertTransferCount(Wait.REL_SUCCESS, 1);
- final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).get(0);
+ final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).getFirst();
outputFlowFile.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
// show a new attribute was copied from the cache
@@ -287,7 +286,7 @@ public class TestWait {
}
@Test
- public void testKeepOriginalAttributes() throws InitializationException, IOException {
+ public void testKeepOriginalAttributes() throws IOException {
Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("both", "notifyValue");
cachedAttributes.put("uuid", "notifyUuid");
@@ -312,7 +311,7 @@ public class TestWait {
runner.assertAllFlowFilesTransferred(Wait.REL_SUCCESS, 1);
runner.assertTransferCount(Wait.REL_SUCCESS, 1);
- final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).get(0);
+ final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).getFirst();
outputFlowFile.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
// show a new attribute was copied from the cache
@@ -326,7 +325,7 @@ public class TestWait {
}
@Test
- public void testWaitForTotalCount() throws InitializationException, IOException {
+ public void testWaitForTotalCount() throws IOException {
Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("both", "notifyValue");
cachedAttributes.put("uuid", "notifyUuid");
@@ -352,7 +351,7 @@ public class TestWait {
*/
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
- MockFlowFile waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ MockFlowFile waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
waitingFlowFile.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
String initialTimestamp = waitingFlowFile.getAttribute(Wait.WAIT_START_TIMESTAMP);
@@ -368,7 +367,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
// Still waiting since total count doesn't reach to 3.
- waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
waitingFlowFile.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
waitingFlowFile.assertAttributeEquals(Wait.WAIT_START_TIMESTAMP, initialTimestamp); // timestamp must remain constant
@@ -381,7 +380,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
// Still waiting since total count doesn't reach to 3.
- waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
waitingFlowFile.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
waitingFlowFile.assertAttributeEquals(Wait.WAIT_START_TIMESTAMP, initialTimestamp); // timestamp must remain constant
@@ -397,7 +396,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_SUCCESS, 1);
- final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).get(0);
+ final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).getFirst();
outputFlowFile.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
// show a new attribute was copied from the cache
@@ -412,7 +411,7 @@ public class TestWait {
}
@Test
- public void testWaitForSpecificCount() throws InitializationException, IOException {
+ public void testWaitForSpecificCount() throws IOException {
Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("both", "notifyValue");
cachedAttributes.put("uuid", "notifyUuid");
@@ -440,7 +439,7 @@ public class TestWait {
*/
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
- MockFlowFile waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ MockFlowFile waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
waitingFlowFile.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
String initialTimestamp = waitingFlowFile.getAttribute(Wait.WAIT_START_TIMESTAMP);
@@ -456,7 +455,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
// Still waiting since counter-B doesn't reach to 2.
- waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
waitingFlowFile.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
waitingFlowFile.assertAttributeEquals(Wait.WAIT_START_TIMESTAMP, initialTimestamp); // timestamp must remain constant
@@ -472,7 +471,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_WAIT, 1);
// Still waiting since total count doesn't reach to 3.
- waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).get(0);
+ waitingFlowFile = runner.getFlowFilesForRelationship(Wait.REL_WAIT).getFirst();
waitingFlowFile.assertAttributeExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be set
waitingFlowFile.assertAttributeEquals(Wait.WAIT_START_TIMESTAMP, initialTimestamp); // timestamp must remain constant
@@ -488,7 +487,7 @@ public class TestWait {
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_SUCCESS, 1);
- final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).get(0);
+ final MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).getFirst();
outputFlowFile.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
// show a new attribute was copied from the cache
@@ -542,7 +541,7 @@ public class TestWait {
*/
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_SUCCESS, 1);
- MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).get(0);
+ MockFlowFile outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).getFirst();
outputFlowFile.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
outputFlowFile.assertAttributeEquals("wait.counter.counter", "2");
@@ -559,7 +558,7 @@ public class TestWait {
runner.clearTransferState();
runner.run();
runner.assertAllFlowFilesTransferred(Wait.REL_SUCCESS, 1);
- outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).get(0);
+ outputFlowFile = runner.getFlowFilesForRelationship(Wait.REL_SUCCESS).getFirst();
outputFlowFile.assertAttributeNotExists(Wait.WAIT_START_TIMESTAMP); // timestamp must be cleared
// All counters are consumed.
outputFlowFile.assertAttributeEquals("wait.counter.counter", "0");
@@ -610,7 +609,7 @@ public class TestWait {
}
@Test
- public void testWaitBufferCount() throws InitializationException, IOException {
+ public void testWaitBufferCount() throws IOException {
Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("notified", "notified-value");
@@ -632,8 +631,7 @@ public class TestWait {
waitAttributesB.put("targetSignalCount", "3");
waitAttributesB.put("signalCounterName", "counter");
- final Map<String, String> waitAttributesBInvalid = new HashMap<>();
- waitAttributesBInvalid.putAll(waitAttributesB);
+ final Map<String, String> waitAttributesBInvalid = new HashMap<>(waitAttributesB);
waitAttributesBInvalid.remove("releaseSignalAttribute");
final TestIteration testIteration = new TestIteration();
@@ -673,7 +671,7 @@ public class TestWait {
}
@Test
- public void testReleaseMultipleFlowFiles() throws InitializationException, IOException {
+ public void testReleaseMultipleFlowFiles() throws IOException {
Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("notified", "notified-value");
@@ -731,7 +729,7 @@ public class TestWait {
}
@Test
- public void testOpenGate() throws InitializationException, IOException {
+ public void testOpenGate() throws IOException {
Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("notified", "notified-value");
@@ -786,4 +784,23 @@ public class TestWait {
assertEquals(3, signal.getCount("counter"));
assertEquals(0, signal.getReleasableCount());
}
+
+ @Test
+ void testMigrateProperties() {
+ final Map<String, String> expectedRenamed = Map.ofEntries(
+ Map.entry("distributed-cache-service", Wait.DISTRIBUTED_CACHE_SERVICE.getName()),
+ Map.entry("release-signal-id", Wait.RELEASE_SIGNAL_IDENTIFIER.getName()),
+ Map.entry("target-signal-count", Wait.TARGET_SIGNAL_COUNT.getName()),
+ Map.entry("signal-counter-name", Wait.SIGNAL_COUNTER_NAME.getName()),
+ Map.entry("wait-buffer-count", Wait.WAIT_BUFFER_COUNT.getName()),
+ Map.entry("releasable-flowfile-count", Wait.RELEASABLE_FLOWFILE_COUNT.getName()),
+ Map.entry("expiration-duration", Wait.EXPIRATION_DURATION.getName()),
+ Map.entry("attribute-copy-mode", Wait.ATTRIBUTE_COPY_MODE.getName()),
+ Map.entry("wait-mode", Wait.WAIT_MODE.getName()),
+ Map.entry("wait-penalty-duration", Wait.WAIT_PENALTY_DURATION.getName())
+ );
+
+ final PropertyMigrationResult propertyMigrationResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, propertyMigrationResult.getPropertiesRenamed());
+ }
}