aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2018-12-04 22:36:39 +0000
committerliamfallon <liam.fallon@est.tech>2018-12-04 23:16:15 +0000
commitc01eff1ee4aff0cc4b177a0bab5c6b96a9efb647 (patch)
treec288edaa37524db429dc2af2e86f5d678cd4c415
parentdc2e6900325c0e69e7efb0346602d29ee634fbea (diff)
Support HTTP headers in REST Requestor
Change-Id: Iea4211e7d3324f5ea6244f45c91241a4067d8d33 Issue-ID: POLICY-1222 Signed-off-by: liamfallon <liam.fallon@est.tech>
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java22
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java2
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParameters.java117
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java49
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java137
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java145
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java146
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java (renamed from plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/RestRequestorTest.java)52
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java (renamed from plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/RestRequestorEndpointTest.java)4
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json75
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json6
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json90
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json89
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json92
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json90
15 files changed, 1092 insertions, 24 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java
index 7d6c60ca1..746fc85c4 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java
@@ -22,6 +22,7 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
@@ -144,11 +145,17 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable {
throw new ApexEventException(errorMessage, e);
}
- // Set the peer timeout to the default value if its not set
+ // Set the requestor timeout
if (consumerParameters.getPeerTimeout(EventHandlerPeeredMode.REQUESTOR) != 0) {
restRequestTimeout = consumerParameters.getPeerTimeout(EventHandlerPeeredMode.REQUESTOR);
}
+ // Check if HTTP headers has been set
+ if (restConsumerProperties.checkHttpHeadersSet()) {
+ LOGGER.debug("REST Requestor consumer has http headers ({}): {}", this.name,
+ Arrays.deepToString(restConsumerProperties.getHttpHeaders()));
+ }
+
// Initialize the HTTP client
client = ClientBuilder.newClient();
}
@@ -163,10 +170,10 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable {
// Push the event onto the queue for handling
try {
incomingRestRequestQueue.add(restRequest);
- } catch (final Exception e) {
+ } catch (final Exception requestException) {
final String errorMessage = "could not queue request \"" + restRequest + "\" on REST Requestor consumer ("
+ this.name + ")";
- LOGGER.warn(errorMessage, e);
+ LOGGER.warn(errorMessage, requestException);
throw new ApexEventRuntimeException(errorMessage);
}
}
@@ -386,23 +393,28 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable {
/**
* Execute the REST request.
*
+ *
* @return the response to the REST request
*/
public Response sendEventAsRestRequest() {
switch (restConsumerProperties.getHttpMethod()) {
case GET:
- return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON).get();
+ return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON)
+ .headers(restConsumerProperties.getHttpHeadersAsMultivaluedMap()).get();
case PUT:
return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON)
+ .headers(restConsumerProperties.getHttpHeadersAsMultivaluedMap())
.put(Entity.json(request.getEvent()));
case POST:
return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON)
+ .headers(restConsumerProperties.getHttpHeadersAsMultivaluedMap())
.post(Entity.json(request.getEvent()));
case DELETE:
- return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON).delete();
+ return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON)
+ .headers(restConsumerProperties.getHttpHeadersAsMultivaluedMap()).delete();
default:
break;
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java
index 69ad05b27..4985fe16f 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java
@@ -70,7 +70,7 @@ public class ApexRestRequestorProducer implements ApexEventProducer {
if (!(producerParameters
.getCarrierTechnologyParameters() instanceof RestRequestorCarrierTechnologyParameters)) {
final String errorMessage =
- "specified consumer properties are not applicable to REST requestor producer (" + this.name + ")";
+ "specified producer properties are not applicable to REST requestor producer (" + this.name + ")";
LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParameters.java
index acd5e52e8..d8009eeef 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParameters.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParameters.java
@@ -20,23 +20,34 @@
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
+import java.util.Arrays;
+
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+// @formatter:off
/**
* Apex parameters for REST as an event carrier technology with Apex issuing a REST request and receiving a REST
* response.
*
* <p>The parameters for this plugin are:
* <ol>
- * <li>url: The URL that the Apex Rest Requestor will connect to over REST for REST request sending. This parameter is
- * mandatory.
- * <li>httpMethod: The HTTP method to use when making requests over REST, legal values are GET (default), POST, PUT, and
- * DELETE.
+ * <li>url: The URL that the Apex Rest Requestor will connect to over REST for REST request sending.
+ * This parameter is mandatory.
+ * <li>httpMethod: The HTTP method to use when making requests over REST, legal values are GET (default),
+ * POST, PUT, and DELETE.
* <li>restRequestTimeout: The time in milliseconds to wait for a REST request to complete.
+ * <li>restRequestHeader: The necessary header needed
* </ol>
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
+//@formatter:on
public class RestRequestorCarrierTechnologyParameters extends CarrierTechnologyParameters {
/** The supported HTTP methods. */
public enum HttpMethod {
@@ -47,12 +58,12 @@ public class RestRequestorCarrierTechnologyParameters extends CarrierTechnologyP
public static final String RESTREQUESTOR_CARRIER_TECHNOLOGY_LABEL = "RESTREQUESTOR";
/** The producer plugin class for the REST carrier technology. */
- public static final String RESTREQUSTOR_EVENT_PRODUCER_PLUGIN_CLASS =
- ApexRestRequestorProducer.class.getCanonicalName();
+ public static final String RESTREQUSTOR_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestRequestorProducer.class
+ .getCanonicalName();
/** The consumer plugin class for the REST carrier technology. */
- public static final String RESTREQUSTOR_EVENT_CONSUMER_PLUGIN_CLASS =
- ApexRestRequestorConsumer.class.getCanonicalName();
+ public static final String RESTREQUSTOR_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestRequestorConsumer.class
+ .getCanonicalName();
/** The default HTTP method for request events. */
public static final HttpMethod DEFAULT_REQUESTOR_HTTP_METHOD = HttpMethod.GET;
@@ -60,12 +71,16 @@ public class RestRequestorCarrierTechnologyParameters extends CarrierTechnologyP
/** The default timeout for REST requests. */
public static final long DEFAULT_REST_REQUEST_TIMEOUT = 500;
+ // Commonly occurring strings
+ private static final String HTTP_HEADERS = "httpHeaders";
+
private String url = null;
private HttpMethod httpMethod = null;
+ private String[][] httpHeaders = null;
/**
- * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
- * service.
+ * Constructor to create a REST carrier technology parameters instance and regiaaaster the instance with the
+ * parameter service.
*/
public RestRequestorCarrierTechnologyParameters() {
super();
@@ -112,14 +127,92 @@ public class RestRequestorCarrierTechnologyParameters extends CarrierTechnologyP
this.httpMethod = httpMethod;
}
+ /**
+ * Check if http headers have been set for the REST request.
+ *
+ * @return true if headers have beenset
+ */
+ public boolean checkHttpHeadersSet() {
+ return httpHeaders != null && httpHeaders.length > 0;
+ }
+
+ /**
+ * Gets the http headers for the REST request.
+ *
+ * @return the headers
+ */
+ public String[][] getHttpHeaders() {
+ return httpHeaders;
+ }
+
+ /**
+ * Gets the http headers for the REST request as a multivalued map.
+ *
+ * @return the headers
+ */
+ public MultivaluedMap<String, Object> getHttpHeadersAsMultivaluedMap() {
+ if (httpHeaders == null) {
+ return null;
+ }
+
+ // Load the HTTP headers into the map
+ MultivaluedMap<String, Object> httpHeaderMap = new MultivaluedHashMap<>();
+
+ for (String[] httpHeader : httpHeaders) {
+ httpHeaderMap.putSingle(httpHeader[0], httpHeader[1]);
+ }
+
+ return httpHeaderMap;
+ }
+
+ /**
+ * Sets the header for the REST request.
+ *
+ * @param httpHeaders the incoming HTTP headers
+ */
+ public void setHttpHeaders(final String[][] httpHeaders) {
+ this.httpHeaders = httpHeaders;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GroupValidationResult validate() {
+ final GroupValidationResult result = super.validate();
+
+ if (httpHeaders == null) {
+ return result;
+ }
+
+ for (String[] httpHeader : httpHeaders) {
+ if (httpHeader == null) {
+ result.setResult(HTTP_HEADERS, ValidationStatus.INVALID, "HTTP header array entry is null");
+ } else if (httpHeader.length != 2) {
+ result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
+ "HTTP header array entries must have one key and one value: "
+ + Arrays.deepToString(httpHeader));
+ } else if (!ParameterValidationUtils.validateStringParameter(httpHeader[0])) {
+ result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
+ "HTTP header key is null or blank: " + Arrays.deepToString(httpHeader));
+ } else if (!ParameterValidationUtils.validateStringParameter(httpHeader[1])) {
+ result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
+ "HTTP header value is null or blank: " + Arrays.deepToString(httpHeader));
+ }
+ }
+
+ return result;
+ }
+
/*
* (non-Javadoc)
*
- * @see java.lang.Object#toString()
+ * @see new LinkedHashMap<>()java.lang.Object#toString()
*/
@Override
public String toString() {
- return "RESTRequestorCarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + "]";
+ return "RESTRequestorCarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + ", httpHeaders="
+ + Arrays.deepToString(httpHeaders) + "]";
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java
new file mode 100644
index 000000000..559d2dba8
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.event.carrier.restrequestor;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+/**
+ * Test the ApexRestRequest class.
+ */
+public class ApexRestRequestTest {
+
+ @Test
+ public void testApexRestRequest() {
+ final String eventName = "EventName";
+ final String eventString = "The Event String";
+
+ ApexRestRequest rr = new ApexRestRequest(1, eventName, eventString);
+
+ assertEquals(1, rr.getExecutionId());
+ assertEquals(eventName, rr.getEventName());
+ assertEquals(eventString, rr.getEvent());
+
+ rr.setTimestamp(1234567);
+ assertEquals(1234567, rr.getTimestamp());
+
+ assertEquals("ApexRestRequest [executionId=1, eventName=EventName, event=The Event String, timestamp=1234567]",
+ rr.toString());
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
new file mode 100644
index 000000000..44e020381
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.event.carrier.restrequestor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+/**
+ * Test the ApexRestRequestorConsumer class.
+ *
+ */
+public class ApexRestRequestorConsumerTest {
+ @Test
+ public void testApexRestRequestorConsumerSetup() {
+ ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer();
+ assertNotNull(consumer);
+
+ String consumerName = "ConsumerName";
+
+ EventHandlerParameters consumerParameters = new EventHandlerParameters();
+ ApexEventReceiver incomingEventReceiver = null;
+
+ try {
+ consumer.init(consumerName, consumerParameters, incomingEventReceiver);
+ fail("test should throw an exception here");
+ } catch (ApexEventException aee) {
+ assertEquals("specified consumer properties are not applicable to REST Requestor consumer (ConsumerName)",
+ aee.getMessage());
+ }
+
+ RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
+ consumerParameters.setCarrierTechnologyParameters(rrctp);
+ try {
+ consumer.init(consumerName, consumerParameters, incomingEventReceiver);
+ fail("test should throw an exception here");
+ } catch (ApexEventException aee) {
+ assertEquals("REST Requestor consumer (ConsumerName) must run in peered requestor mode "
+ + "with a REST Requestor producer", aee.getMessage());
+ }
+
+ consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
+ rrctp.setHttpMethod(null);
+ try {
+ consumer.init(consumerName, consumerParameters, incomingEventReceiver);
+ fail("test should throw an exception here");
+ } catch (ApexEventException aee) {
+ assertEquals("no URL has been specified on REST Requestor consumer (ConsumerName)", aee.getMessage());
+ }
+
+ rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET);
+ rrctp.setUrl("ZZZZ");
+ try {
+ consumer.init(consumerName, consumerParameters, incomingEventReceiver);
+ fail("test should throw an exception here");
+ } catch (ApexEventException aee) {
+ assertEquals("invalid URL has been specified on REST Requestor consumer (ConsumerName)", aee.getMessage());
+ }
+
+ rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET);
+ rrctp.setUrl("http://www.onap.org");
+ consumerParameters.setPeerTimeout(EventHandlerPeeredMode.REQUESTOR, 0);
+
+ try {
+ consumer.init(consumerName, consumerParameters, incomingEventReceiver);
+ } catch (ApexEventException aee) {
+ fail("test should not throw an exception");
+ }
+
+ try {
+ consumer.processRestRequest(null);
+ fail("test should throw an exception here");
+ } catch (Exception ex) {
+ assertEquals("could not queue request \"null\" on REST Requestor consumer (ConsumerName)",
+ ex.getMessage());
+ }
+
+ assertEquals("ConsumerName", consumer.getName());
+ assertEquals(0, consumer.getEventsReceived());
+ assertEquals(null, consumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testApexRestRequestorConsumerRequest() {
+ ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer();
+ assertNotNull(consumer);
+
+ String consumerName = "ConsumerName";
+
+ EventHandlerParameters consumerParameters = new EventHandlerParameters();
+ ApexEventReceiver incomingEventReceiver = null;
+ RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
+ consumerParameters.setCarrierTechnologyParameters(rrctp);
+ consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
+ rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET);
+ rrctp.setUrl("http://www.onap.org");
+ consumerParameters.setPeerTimeout(EventHandlerPeeredMode.REQUESTOR, 0);
+
+ // Test should time out requests
+ try {
+ consumer.init(consumerName, consumerParameters, incomingEventReceiver);
+ consumer.start();
+ ApexRestRequest request = new ApexRestRequest(123, "EventName", "Event body");
+ consumer.processRestRequest(request);
+ ThreadUtilities.sleep(2000);
+ consumer.stop();
+ assertEquals(0, consumer.getEventsReceived());
+ } catch (ApexEventException aee) {
+ fail("test should not throw an exception");
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java
new file mode 100644
index 000000000..136c189db
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java
@@ -0,0 +1,145 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.event.carrier.restrequestor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventConsumer;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
+import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+/**
+ * Test the ApexRestRequestorProducer class.
+ */
+public class ApexRestRequestorProducerTest {
+
+ @Test
+ public void testApexRestRequestorProducerMethods() {
+ ApexRestRequestorProducer producer = new ApexRestRequestorProducer();
+ assertNotNull(producer);
+
+ String producerName = "ProducerName";
+ EventHandlerParameters producerParameters = new EventHandlerParameters();
+
+ try {
+ producer.init(producerName, producerParameters);
+ } catch (ApexEventException aee) {
+ assertEquals("specified producer properties are not applicable to REST requestor producer (ProducerName)",
+ aee.getMessage());
+ }
+
+ RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
+ producerParameters.setCarrierTechnologyParameters(rrctp);
+ try {
+ producer.init(producerName, producerParameters);
+ fail("test should throw an exception here");
+ } catch (ApexEventException aee) {
+ assertEquals("REST Requestor producer (ProducerName) must run in peered requestor mode "
+ + "with a REST Requestor consumer", aee.getMessage());
+ }
+
+ producerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
+ rrctp.setUrl("ZZZZ");
+ try {
+ producer.init(producerName, producerParameters);
+ fail("test should throw an exception here");
+ } catch (ApexEventException aee) {
+ assertEquals("URL may not be specified on REST Requestor producer (ProducerName)", aee.getMessage());
+ }
+
+ rrctp.setUrl(null);
+ rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET);
+ try {
+ producer.init(producerName, producerParameters);
+ fail("test should throw an exception here");
+ } catch (ApexEventException aee) {
+ assertEquals("HTTP method may not be specified on REST Requestor producer (ProducerName)",
+ aee.getMessage());
+ }
+
+ rrctp.setHttpMethod(null);
+ try {
+ producer.init(producerName, producerParameters);
+ producer.stop();
+ } catch (ApexEventException aee) {
+ fail("test should not throw an exception here");
+ }
+
+ assertEquals("ProducerName", producer.getName());
+ assertEquals(0, producer.getEventsSent());
+ assertEquals(null, producer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ }
+
+ @Test
+ public void testApexRestRequestorProducerRequest() {
+ ApexRestRequestorProducer producer = new ApexRestRequestorProducer();
+
+ String producerName = "ProducerName";
+ EventHandlerParameters producerParameters = new EventHandlerParameters();
+
+ RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
+ producerParameters.setCarrierTechnologyParameters(rrctp);
+ producerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
+ rrctp.setUrl(null);
+ rrctp.setHttpMethod(null);
+
+ try {
+ producer.init(producerName, producerParameters);
+ producer.stop();
+ } catch (ApexEventException aee) {
+ fail("test should not throw an exception here");
+ }
+
+ String eventName = "EventName";
+ String event = "This is the event";
+
+ try {
+ producer.sendEvent(12345, eventName, event);
+ fail("test should throw an exception here");
+ } catch (Exception aee) {
+ assertEquals("send of event to URL \"null\" failed, REST response consumer is not defined\n"
+ + "This is the event", aee.getMessage());
+ }
+
+ ApexEventConsumer consumer = new ApexFileEventConsumer();
+ SynchronousEventCache eventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer,
+ producer, 1000);
+ producer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, eventCache);
+
+ PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, consumer, producer);
+ producer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
+ try {
+ producer.sendEvent(12345, eventName, event);
+ fail("test should throw an exception here");
+ } catch (Exception aee) {
+ assertEquals("send of event to URL \"null\" failed, REST response consumer "
+ + "is not an instance of ApexRestRequestorConsumer\n" + "This is the event",
+ aee.getMessage());
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
new file mode 100644
index 000000000..7be42e264
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
@@ -0,0 +1,146 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.plugins.event.carrier.restrequestor;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
+import org.onap.policy.apex.service.parameters.ApexParameterHandler;
+import org.onap.policy.apex.service.parameters.ApexParameters;
+import org.onap.policy.common.parameters.ParameterException;
+
+/**
+ * Test REST Requestor carrier technology parameters.
+ */
+public class RestRequestorCarrierTechnologyParametersTest {
+
+ @Test
+ public void testRestRequestorCarrierTechnologyParametersBadList() {
+ ApexCommandLineArguments arguments = new ApexCommandLineArguments();
+ arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json");
+ arguments.setRelativeFileRoot(".");
+
+ try {
+ new ApexParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (ParameterException pe) {
+ assertTrue(pe.getMessage().contains("HTTP header array entry is null\n parameter"));
+ assertTrue(pe.getMessage().trim().endsWith("HTTP header array entry is null"));
+ }
+ }
+
+ @Test
+ public void testRestRequestorCarrierTechnologyParametersNotKvPairs() {
+ ApexCommandLineArguments arguments = new ApexCommandLineArguments();
+ arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json");
+ arguments.setRelativeFileRoot(".");
+
+ try {
+ new ApexParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (ParameterException pe) {
+ assertTrue(pe.getMessage()
+ .contains("HTTP header array entries must have one key and one value: [aaa, bbb, ccc]"));
+ assertTrue(pe.getMessage().trim()
+ .endsWith("HTTP header array entries must have one key and one value: [aaa]"));
+ }
+ }
+
+ @Test
+ public void testRestRequestorCarrierTechnologyParametersNulls() {
+ ApexCommandLineArguments arguments = new ApexCommandLineArguments();
+ arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json");
+ arguments.setRelativeFileRoot(".");
+
+ try {
+ new ApexParameterHandler().getParameters(arguments);
+ fail("test should throw an exception here");
+ } catch (ParameterException pe) {
+ assertTrue(pe.getMessage().contains("HTTP header key is null or blank: [null, bbb]"));
+ assertTrue(pe.getMessage().trim().endsWith("HTTP header value is null or blank: [ccc, null]"));
+ }
+ }
+
+ @Test
+ public void testRestRequestorCarrierTechnologyParametersOk() {
+ ApexCommandLineArguments arguments = new ApexCommandLineArguments();
+ arguments.setConfigurationFilePath("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json");
+ arguments.setRelativeFileRoot(".");
+
+ try {
+ ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
+
+ RestRequestorCarrierTechnologyParameters rrctp0 = (RestRequestorCarrierTechnologyParameters) parameters
+ .getEventInputParameters().get("RestRequestorConsumer0").getCarrierTechnologyParameters();
+ assertEquals(0, rrctp0.getHttpHeaders().length);
+
+ RestRequestorCarrierTechnologyParameters rrctp1 = (RestRequestorCarrierTechnologyParameters) parameters
+ .getEventInputParameters().get("RestRequestorConsumer1").getCarrierTechnologyParameters();
+ assertEquals(3, rrctp1.getHttpHeaders().length);
+ assertEquals("bbb", rrctp1.getHttpHeadersAsMultivaluedMap().get("aaa").get(0));
+ assertEquals("ddd", rrctp1.getHttpHeadersAsMultivaluedMap().get("ccc").get(0));
+ assertEquals("fff", rrctp1.getHttpHeadersAsMultivaluedMap().get("eee").get(0));
+ } catch (ParameterException pe) {
+ fail("test should not throw an exception");
+ }
+ }
+
+ @Test
+ public void testGettersAndSetters() {
+ RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
+
+ rrctp.setUrl("http://some.where");
+ assertEquals("http://some.where", rrctp.getUrl());
+
+ String[][] httpHeaders = new String[2][2];
+ httpHeaders[0][0] = "aaa";
+ httpHeaders[0][1] = "bbb";
+ httpHeaders[1][0] = "ccc";
+ httpHeaders[1][1] = "ddd";
+
+ rrctp.setHttpHeaders(httpHeaders);
+ assertEquals("aaa", rrctp.getHttpHeaders()[0][0]);
+ assertEquals("bbb", rrctp.getHttpHeaders()[0][1]);
+ assertEquals("ccc", rrctp.getHttpHeaders()[1][0]);
+ assertEquals("ddd", rrctp.getHttpHeaders()[1][1]);
+
+ rrctp.setHttpHeaders(null);
+ assertFalse(rrctp.checkHttpHeadersSet());
+
+ String[][] httpHeadersZeroLength = new String[0][0];
+ rrctp.setHttpHeaders(httpHeadersZeroLength);
+ assertFalse(rrctp.checkHttpHeadersSet());
+
+ rrctp.setHttpHeaders(httpHeaders);
+ assertTrue(rrctp.checkHttpHeadersSet());
+
+ rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.DELETE);
+ assertEquals(RestRequestorCarrierTechnologyParameters.HttpMethod.DELETE, rrctp.getHttpMethod());
+
+ assertEquals("RESTRequestorCarrierTechnologyParameters "
+ + "[url=http://some.where, httpMethod=DELETE, httpHeaders=[[aaa, bbb], [ccc, ddd]]]",
+ rrctp.toString());
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/RestRequestorTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
index 7abed5a41..a9dfd8dc5 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/RestRequestorTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.apps.uservice.test.adapt.restrequestor;
+package org.onap.policy.apex.plugins.event.carrier.restrequestor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -68,7 +68,7 @@ public class RestRequestorTest {
*/
@BeforeClass
public static void setUp() throws Exception {
- final ResourceConfig rc = new ResourceConfig(RestRequestorEndpointTest.class);
+ final ResourceConfig rc = new ResourceConfig(SupportRestRequestorEndpoint.class);
server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
while (!server.isStarted()) {
@@ -95,7 +95,7 @@ public class RestRequestorTest {
*/
@Before
public void resetCounters() {
- RestRequestorEndpointTest.resetCounters();
+ SupportRestRequestorEndpoint.resetCounters();
}
/**
@@ -147,6 +147,52 @@ public class RestRequestorTest {
}
/**
+ * Test rest requestor get empty.
+ *
+ * @throws MessagingException the messaging exception
+ * @throws ApexException the apex exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ @Test
+ public void testRestRequestorGetEmpty() throws MessagingException, ApexException, IOException {
+ final Client client = ClientBuilder.newClient();
+
+ final String[] args =
+ { "src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json" };
+ final ApexMain apexMain = new ApexMain(args);
+
+ Response response = null;
+
+ // Wait for the required amount of events to be received or for 10 seconds
+ Double getsSoFar = 0.0;
+ for (int i = 0; i < 40; i++) {
+ ThreadUtilities.sleep(100);
+
+ response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats")
+ .request("application/json").get();
+
+ if (Response.Status.OK.getStatusCode() != response.getStatus()) {
+ break;
+ }
+
+ final String responseString = response.readEntity(String.class);
+
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
+ getsSoFar = Double.valueOf(jsonMap.get("GET").toString());
+
+ if (getsSoFar >= 50.0) {
+ break;
+ }
+ }
+
+ apexMain.shutdown();
+ client.close();
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ }
+
+ /**
* Test REST requestor put.
*
* @throws MessagingException the messaging exception
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/RestRequestorEndpointTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java
index f84b6a703..8380d0a61 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/RestRequestorEndpointTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.apex.apps.uservice.test.adapt.restrequestor;
+package org.onap.policy.apex.plugins.event.carrier.restrequestor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -38,7 +38,7 @@ import javax.ws.rs.core.Response;
* The Class TestRestRequestorEndpoint.
*/
@Path("/apex")
-public class RestRequestorEndpointTest {
+public class SupportRestRequestorEndpoint {
private static Object counterLock = new Object();
private static int postMessagesReceived = 0;
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json
new file mode 100644
index 000000000..16baced07
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json
@@ -0,0 +1,75 @@
+{
+ "engineServiceParameters": {
+ "name": "MyApexEngine",
+ "version": "0.0.1",
+ "id": 45,
+ "instanceCount": 4,
+ "deploymentPort": 12561,
+ "policyModelFileName": "src/test/resources/policymodels/RequestorModel.json",
+ "engineParameters": {
+ "executorParameters": {
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ }
+ }
+ },
+ "eventInputParameters": {
+ "FileConsumer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "FILE",
+ "parameters": {
+ "fileName": "src/test/resources/events/EventsIn.json"
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ }
+ },
+ "RestRequestorConsumer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEmptyEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer",
+ "requestorTimeout": 2000
+ }
+ },
+ "eventOutputParameters": {
+ "RestRequestorProducer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer",
+ "requestorTimeout": 2000
+ },
+ "FileProducer": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "FILE",
+ "parameters": {
+ "fileName": "src/test/resources/events/EventsOut.json"
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "BasicEvent"
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json
index ac418e623..c66051ce5 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePut.json
@@ -33,7 +33,11 @@
"parameters": {
"url": "http://localhost:32801/TestRESTRequestor/apex/event/PutEvent",
"httpMethod": "PUT",
- "restRequestTimeout": 2000
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ["Content-Type", "application/json"],
+ ["Date", "Tue, 4 Dec 2018 14:57:12 GMT"]
+ ]
}
},
"eventProtocolParameters": {
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json
new file mode 100644
index 000000000..c71911aab
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json
@@ -0,0 +1,90 @@
+{
+ "engineServiceParameters": {
+ "name": "MyApexEngine",
+ "version": "0.0.1",
+ "id": 45,
+ "instanceCount": 4,
+ "deploymentPort": 12561,
+ "policyModelFileName": "src/test/resources/policymodels/RequestorModel.json",
+ "engineParameters": {
+ "executorParameters": {
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ }
+ }
+ },
+ "eventInputParameters": {
+ "RestRequestorConsumer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ["aaa", "bbb"],
+ ["ccc", "ddd"],
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorConsumer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ,
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer1",
+ "requestorTimeout": 2000
+ }
+ },
+ "eventOutputParameters": {
+ "RestRequestorProducer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorProducer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer1",
+ "requestorTimeout": 2000
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json
new file mode 100644
index 000000000..dc63c5884
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json
@@ -0,0 +1,89 @@
+{
+ "engineServiceParameters": {
+ "name": "MyApexEngine",
+ "version": "0.0.1",
+ "id": 45,
+ "instanceCount": 4,
+ "deploymentPort": 12561,
+ "policyModelFileName": "src/test/resources/policymodels/RequestorModel.json",
+ "engineParameters": {
+ "executorParameters": {
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ }
+ }
+ },
+ "eventInputParameters": {
+ "RestRequestorConsumer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ["aaa", "bbb", "ccc"]
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorConsumer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ["aaa"]
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer1",
+ "requestorTimeout": 2000
+ }
+ },
+ "eventOutputParameters": {
+ "RestRequestorProducer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorProducer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer1",
+ "requestorTimeout": 2000
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json
new file mode 100644
index 000000000..9992e4f28
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json
@@ -0,0 +1,92 @@
+{
+ "engineServiceParameters": {
+ "name": "MyApexEngine",
+ "version": "0.0.1",
+ "id": 45,
+ "instanceCount": 4,
+ "deploymentPort": 12561,
+ "policyModelFileName": "src/test/resources/policymodels/RequestorModel.json",
+ "engineParameters": {
+ "executorParameters": {
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ }
+ }
+ },
+ "eventInputParameters": {
+ "RestRequestorConsumer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ [null, "bbb"],
+ ["ccc", "ddd"]
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorConsumer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ["aaa", "bbb"],
+ ["ccc", null],
+ ["eee", "fff"]
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer1",
+ "requestorTimeout": 2000
+ }
+ },
+ "eventOutputParameters": {
+ "RestRequestorProducer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorProducer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer1",
+ "requestorTimeout": 2000
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json
new file mode 100644
index 000000000..e8a25c9fb
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json
@@ -0,0 +1,90 @@
+{
+ "engineServiceParameters": {
+ "name": "MyApexEngine",
+ "version": "0.0.1",
+ "id": 45,
+ "instanceCount": 4,
+ "deploymentPort": 12561,
+ "policyModelFileName": "src/test/resources/policymodels/RequestorModel.json",
+ "engineParameters": {
+ "executorParameters": {
+ "JAVASCRIPT": {
+ "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters"
+ }
+ }
+ }
+ },
+ "eventInputParameters": {
+ "RestRequestorConsumer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorConsumer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters",
+ "parameters": {
+ "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent",
+ "httpMethod": "GET",
+ "restRequestTimeout": 2000,
+ "httpHeaders" : [
+ ["aaa", "bbb"],
+ ["ccc", "ddd"],
+ ["eee", "fff"]
+ ]
+ }
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "ResponseEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorProducer1",
+ "requestorTimeout": 2000
+ }
+ },
+ "eventOutputParameters": {
+ "RestRequestorProducer0": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer0",
+ "requestorTimeout": 2000
+ },
+ "RestRequestorProducer1": {
+ "carrierTechnologyParameters": {
+ "carrierTechnology": "RESTREQUESTOR",
+ "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters"
+ },
+ "eventProtocolParameters": {
+ "eventProtocol": "JSON"
+ },
+ "eventNameFilter": "RequestEvent",
+ "requestorMode": true,
+ "requestorPeer": "RestRequestorConsumer1",
+ "requestorTimeout": 2000
+ }
+ }
+}