From 97a919a3be37c8e78b623ffacf9b1f22db534644 Mon Sep 17 00:00:00 2001 From: Andy LoPresto Date: Fri, 22 May 2020 10:55:48 -0700 Subject: [PATCH] NIFI-7482 Changed InvokeHTTP to be extensible. Added unit test. This closes #4291. Signed-off-by: Arpad Boda --- .../nifi/processors/standard/InvokeHTTP.java | 2 +- .../processors/standard/TestInvokeHTTP.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java index 249fb8e33e..d0cd858ecf 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java @@ -134,7 +134,7 @@ import org.joda.time.format.DateTimeFormatter; + " where the will be the form data name, will be used to fill out the multipart form parts." + " If send message body is false, the flowfile will not be sent, but any other form data will be.") }) -public final class InvokeHTTP extends AbstractProcessor { +public class InvokeHTTP extends AbstractProcessor { // flowfile attribute keys returned after reading the response public final static String STATUS_CODE = "invokehttp.status.code"; public final static String STATUS_MESSAGE = "invokehttp.status.message"; diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java index c2a68ddc40..9cabae04b0 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java @@ -16,6 +16,7 @@ */ package org.apache.nifi.processors.standard; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -273,6 +274,7 @@ public class TestInvokeHTTP extends TestInvokeHttpCommon { assertNull(regexAttributesToSendField.get(processor)); } + @Test public void testEmptyGzipHttpReponse() throws Exception { addHandler(new EmptyGzipResponseHandler()); @@ -300,6 +302,31 @@ public class TestInvokeHTTP extends TestInvokeHttpCommon { bundle.assertAttributeEquals("Content-Type", "text/plain"); } + @Test + public void testShouldAllowExtension() { + // Arrange + class ExtendedInvokeHTTP extends InvokeHTTP { + private int extendedNumber = -1; + + public ExtendedInvokeHTTP(int num) { + super(); + this.extendedNumber = num; + } + + public int extendedMethod() { + return this.extendedNumber; + } + } + + int num = Double.valueOf(Math.random() * 100).intValue(); + + // Act + ExtendedInvokeHTTP eih = new ExtendedInvokeHTTP(num); + + // Assert + assertEquals(num, eih.extendedMethod()); + } + public static class EmptyGzipResponseHandler extends AbstractHandler { @Override