diff options
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java')
3 files changed, 134 insertions, 11 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 index 559d2dba8..dc55c06f7 100644 --- 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 @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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========================================================= */ @@ -24,6 +25,8 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; +import java.util.Properties; + /** * Test the ApexRestRequest class. */ @@ -34,11 +37,14 @@ public class ApexRestRequestTest { final String eventName = "EventName"; final String eventString = "The Event String"; - ApexRestRequest rr = new ApexRestRequest(1, eventName, eventString); + Properties properties = new Properties(); + properties.put("key", "value"); + ApexRestRequest rr = new ApexRestRequest(1, properties, eventName, eventString); assertEquals(1, rr.getExecutionId()); assertEquals(eventName, rr.getEventName()); assertEquals(eventString, rr.getEvent()); + assertEquals(properties, rr.getExecutionProperties()); rr.setTimestamp(1234567); assertEquals(1234567, rr.getTimestamp()); 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 index 44e020381..ac1af67dd 100644 --- 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 @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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========================================================= */ @@ -28,9 +29,12 @@ 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.engine.event.ApexEventRuntimeException; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; +import java.util.Properties; + /** * Test the ApexRestRequestorConsumer class. * @@ -125,7 +129,7 @@ public class ApexRestRequestorConsumerTest { try { consumer.init(consumerName, consumerParameters, incomingEventReceiver); consumer.start(); - ApexRestRequest request = new ApexRestRequest(123, "EventName", "Event body"); + ApexRestRequest request = new ApexRestRequest(123, null,"EventName", "Event body"); consumer.processRestRequest(request); ThreadUtilities.sleep(2000); consumer.stop(); @@ -134,4 +138,67 @@ public class ApexRestRequestorConsumerTest { fail("test should not throw an exception"); } } + + @Test + public void testApexRestRequestorConsumerUrlUpdate() { + 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.{site}.{site}.{net}"); + consumerParameters.setPeerTimeout(EventHandlerPeeredMode.REQUESTOR, 2000); + Properties properties = new Properties(); + properties.put("site", "onap"); + properties.put("net", "org"); + try { + consumer.init(consumerName, consumerParameters, incomingEventReceiver); + consumer.start(); + ApexRestRequest request = new ApexRestRequest(123, properties,"EventName", "Event body"); + consumer.processRestRequest(request); + ThreadUtilities.sleep(2000); + consumer.stop(); + assertEquals(0, consumer.getEventsReceived()); + } catch (Exception aee) { + fail("test should not throw an exception"); + } + } + + @Test + public void testApexRestRequestorConsumerUrlUpdateError() { + 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.{site}.{net}"); + consumerParameters.setPeerTimeout(EventHandlerPeeredMode.REQUESTOR, 2000); + Properties properties = new Properties(); + properties.put("site", "onap"); + try { + consumer.init(consumerName, consumerParameters, incomingEventReceiver); + consumer.start(); + ApexRestRequest request = new ApexRestRequest(123, properties,"EventName", "Event body"); + consumer.processRestRequest(request); + ThreadUtilities.sleep(2000); + consumer.stop(); + assertEquals(0, consumer.getEventsReceived()); + } catch (Exception 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/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 index 7be42e264..68c6811b4 100644 --- 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 @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * 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========================================================= */ @@ -31,6 +32,8 @@ import org.onap.policy.apex.service.parameters.ApexParameterHandler; import org.onap.policy.apex.service.parameters.ApexParameters; import org.onap.policy.common.parameters.ParameterException; +import java.util.Set; + /** * Test REST Requestor carrier technology parameters. */ @@ -143,4 +146,51 @@ public class RestRequestorCarrierTechnologyParametersTest { + "[url=http://some.where, httpMethod=DELETE, httpHeaders=[[aaa, bbb], [ccc, ddd]]]", rrctp.toString()); } + + @Test + public void testUrlValidation() { + RestRequestorCarrierTechnologyParameters rrctp = + new RestRequestorCarrierTechnologyParameters(); + + rrctp.setUrl("http://some.where.no.tag.in.url"); + assertEquals("http://some.where.no.tag.in.url", 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]); + + assertEquals(true, rrctp.validateTagInUrl()); + + rrctp.setUrl("http://{place}.{that}/is{that}.{one}"); + assertEquals(true, rrctp.validateTagInUrl()); + + Set<String> keymap = rrctp.getKeysFromUrl(); + assertEquals(true, keymap.contains("place")); + assertEquals(true, keymap.contains("that")); + assertEquals(true, keymap.contains("one")); + + rrctp.setUrl("http://{place.{that}/{is}.{not}/{what}.{exist}"); + assertEquals(false, rrctp.validateTagInUrl()); + rrctp.setUrl("http://{place}.{that}/{is}.{not}/{what}.{exist"); + assertEquals(false, rrctp.validateTagInUrl()); + rrctp.setUrl("http://place.that/is.not/what.{exist"); + assertEquals(false, rrctp.validateTagInUrl()); + rrctp.setUrl("http://place}.{that}/{is}.{not}/{what}.{exist}"); + assertEquals(false, rrctp.validateTagInUrl()); + rrctp.setUrl("http://{place}.{that}/is}.{not}/{what}.{exist}"); + assertEquals(false, rrctp.validateTagInUrl()); + rrctp.setUrl("http://{place}.{that}/{}.{not}/{what}.{exist}"); + assertEquals(false, rrctp.validateTagInUrl()); + rrctp.setUrl("http://{place}.{that}/{ }.{not}/{what}.{exist}"); + assertEquals(false, rrctp.validateTagInUrl()); + } + } |