diff options
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test')
12 files changed, 969 insertions, 6 deletions
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 + } + } +} |