This is an automated email from the ASF dual-hosted git repository.
chriss pushed a commit to branch support/nifi-1.x
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/support/nifi-1.x by this push:
new 2faac7d26e NIFI-11778 fix PutElasticsearchJsonTest for Java 8
2faac7d26e is described below
commit 2faac7d26eeceeee2e24f50cd7b8ad35f0f09f6c
Author: Chris Sampson <[email protected]>
AuthorDate: Tue Aug 29 09:58:25 2023 +0100
NIFI-11778 fix PutElasticsearchJsonTest for Java 8
---
.../apache/nifi/processors/elasticsearch/JsonUtils.java | 12 +++++++-----
.../elasticsearch/PutElasticsearchJsonTest.java | 15 +++++++--------
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/JsonUtils.java
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/JsonUtils.java
index a1d097a976..745c792caf 100644
---
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/JsonUtils.java
+++
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/JsonUtils.java
@@ -31,6 +31,13 @@ public class JsonUtils {
private static final ObjectMapper MAPPER = new ObjectMapper();
private JsonUtils() {}
+ @Deprecated // Use Files.readString when no longer need to support Java 8
+ static String readString(final Path path) throws IOException {
+ try (Stream<String> lines = Files.lines(path)) {
+ return lines.collect(Collectors.joining("\n"));
+ }
+ }
+
static String toJson(Object object) {
try {
return MAPPER.writeValueAsString(object);
@@ -56,11 +63,6 @@ public class JsonUtils {
}
}
- static String readString(final Path path) throws IOException {
- try (Stream<String> lines = Files.lines(path)) {
- return lines.collect(Collectors.joining("\n"));
- }
- }
static List<String> readListOfMapsAsIndividualJson(String json) {
return readListOfMaps(json).stream()
.map(JsonUtils::prettyPrint)
diff --git
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJsonTest.java
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJsonTest.java
index 3ccee86693..4f8c3df5d5 100644
---
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJsonTest.java
+++
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJsonTest.java
@@ -28,7 +28,6 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
@@ -62,10 +61,10 @@ public class PutElasticsearchJsonTest extends
AbstractPutElasticsearchTest<PutEl
@BeforeAll
public static void setUpBeforeClass() throws Exception {
- sampleErrorResponse =
Files.readString(Paths.get(TEST_COMMON_DIR,"sampleErrorResponse.json"));
- flowFileContents = Files.readString(Paths.get(TEST_DIR,
"flowFileContents.json"));
- script = Files.readString(Paths.get(TEST_DIR,"script.json"));
- dynamicTemplates =
Files.readString(Paths.get(TEST_COMMON_DIR,"dynamicTemplates.json"));
+ sampleErrorResponse =
JsonUtils.readString(Paths.get(TEST_COMMON_DIR,"sampleErrorResponse.json"));
+ flowFileContents = JsonUtils.readString(Paths.get(TEST_DIR,
"flowFileContents.json"));
+ script = JsonUtils.readString(Paths.get(TEST_DIR,"script.json"));
+ dynamicTemplates =
JsonUtils.readString(Paths.get(TEST_COMMON_DIR,"dynamicTemplates.json"));
expectedScript = new LinkedHashMap<>();
expectedScript.put("_source", "some script");
expectedScript.put("language", "painless");
@@ -324,7 +323,7 @@ public class PutElasticsearchJsonTest extends
AbstractPutElasticsearchTest<PutEl
runner.setProperty(PutElasticsearchJson.BATCH_SIZE, "100");
runner.setProperty(PutElasticsearchJson.NOT_FOUND_IS_SUCCESSFUL,
"true");
clientService.setResponse(IndexOperationResponse.fromJsonResponse(sampleErrorResponse));
- List<String> values =
JsonUtils.readListOfMapsAsIndividualJson(Files.readString(BATCH_WITH_ERROR));
+ List<String> values =
JsonUtils.readListOfMapsAsIndividualJson(JsonUtils.readString(BATCH_WITH_ERROR));
values.forEach(val -> runner.enqueue(val));
runner.assertValid();
runner.run();
@@ -365,7 +364,7 @@ public class PutElasticsearchJsonTest extends
AbstractPutElasticsearchTest<PutEl
runner.setProperty(PutElasticsearchJson.NOT_FOUND_IS_SUCCESSFUL,
"false");
runner.setProperty(PutElasticsearchJson.OUTPUT_ERROR_RESPONSES,
"true");
clientService.setResponse(IndexOperationResponse.fromJsonResponse(sampleErrorResponse));
- List<String> values =
JsonUtils.readListOfMapsAsIndividualJson(Files.readString(BATCH_WITH_ERROR));
+ List<String> values =
JsonUtils.readListOfMapsAsIndividualJson(JsonUtils.readString(BATCH_WITH_ERROR));
values.forEach(val -> runner.enqueue(val));
runner.assertValid();
runner.run();
@@ -416,7 +415,7 @@ public class PutElasticsearchJsonTest extends
AbstractPutElasticsearchTest<PutEl
runner.setProperty(PutElasticsearchJson.LOG_ERROR_RESPONSES, "false");
runner.setProperty(PutElasticsearchJson.BATCH_SIZE, "100");
clientService.setResponse(IndexOperationResponse.fromJsonResponse(sampleErrorResponse));
- for (final String val :
JsonUtils.readListOfMapsAsIndividualJson(Files.readString(Paths.get(TEST_DIR,
"batchWithoutError.json")))) {
+ for (final String val :
JsonUtils.readListOfMapsAsIndividualJson(JsonUtils.readString(Paths.get(TEST_DIR,
"batchWithoutError.json")))) {
runner.enqueue(val);
}