diff options
author | liamfallon <liam.fallon@est.tech> | 2020-03-02 17:08:47 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2020-03-04 08:33:25 +0000 |
commit | 9e5c4b882728ebf3330568d068f109965d599410 (patch) | |
tree | 8ad948a28268b50b97946168b7a8ceab54872dc5 /plugins/plugins-event/plugins-event-carrier | |
parent | 5922128637471bfa1897b8808561000988da733d (diff) |
Preparing integration tests for Graal Javascript
Graal enforces Javascript more strictly than Nashorn does. This review
changes the tests in apex-pdp to comply with the stricter -Javascript
checking, re-enabling the integration test module.
- All log calls must be passed as strings, using toString()
- Byte/Float/Long Java types not supported in Javascript
Disable integration tests so that other changes can be brought in.
JMS integration test is disabled for now, it will be re-enabled in a
review shortly.
Issue-ID: POLICY-2106
Change-Id: I14bdb930eff735e862b51802cf72e4793cec3699
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier')
3 files changed, 37 insertions, 38 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java index aa8185fdb..a3d273dfd 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java @@ -22,9 +22,9 @@ package org.onap.policy.apex.plugins.event.carrier.restclient; import java.util.Properties; - import java.util.regex.Matcher; import java.util.regex.Pattern; + import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.core.Response; @@ -35,6 +35,7 @@ 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.engine.event.ApexPluginsEventConsumer; +import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -86,10 +87,10 @@ public class ApexRestClientConsumer extends ApexPluginsEventConsumer { // Check if the HTTP method has been set if (restConsumerProperties.getHttpMethod() == null) { - restConsumerProperties.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.GET); + restConsumerProperties.setHttpMethod(RestPluginCarrierTechnologyParameters.HttpMethod.GET); } - if (!RestClientCarrierTechnologyParameters.HttpMethod.GET.equals(restConsumerProperties.getHttpMethod())) { + if (!RestPluginCarrierTechnologyParameters.HttpMethod.GET.equals(restConsumerProperties.getHttpMethod())) { final String errorMessage = "specified HTTP method of \"" + restConsumerProperties.getHttpMethod() + "\" is invalid, only HTTP method \"GET\" " + "is supported for event reception on REST client consumer (" + this.name + ")"; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java index 3506ace3c..cf3500065 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java @@ -21,8 +21,6 @@ package org.onap.policy.apex.plugins.event.carrier.restclient; -import java.util.EnumMap; -import java.util.Map; import java.util.Optional; import java.util.Properties; import java.util.Set; @@ -33,12 +31,10 @@ import javax.ws.rs.client.Entity; import javax.ws.rs.core.Response; import org.onap.policy.apex.service.engine.event.ApexEventException; -import org.onap.policy.apex.service.engine.event.ApexPluginsEventProducer; import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException; -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.ApexPluginsEventProducer; +import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters; import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters; -import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,14 +73,14 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { // Check if the HTTP method has been set if (restProducerProperties.getHttpMethod() == null) { - restProducerProperties.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST); + restProducerProperties.setHttpMethod(RestPluginCarrierTechnologyParameters.HttpMethod.POST); } - if (!RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod()) - && !RestClientCarrierTechnologyParameters.HttpMethod.PUT + if (!RestPluginCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod()) + && !RestPluginCarrierTechnologyParameters.HttpMethod.PUT .equals(restProducerProperties.getHttpMethod())) { final String errorMessage = "specified HTTP method of \"" + restProducerProperties.getHttpMethod() - + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supproted " + + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supported " + "for event sending on REST client producer (" + this.name + ")"; LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); @@ -97,6 +93,7 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { /** * {@inheritDoc}. */ + @Override public void sendEvent(final long executionId, final Properties executionProperties, final String eventName, final Object event) { super.sendEvent(executionId, executionProperties, eventName, event); @@ -106,15 +103,17 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { Set<String> names = restProducerProperties.getKeysFromUrl(); Set<String> inputProperty = executionProperties.stringPropertyNames(); + // @formatter:off names.stream().map(Optional::of).forEach(op -> op.filter(inputProperty::contains) .orElseThrow(() -> new ApexEventRuntimeException( - "key\"" + op.get() + "\"specified on url \"" + restProducerProperties.getUrl() - + "\"not found in execution properties passed by the current policy")) + "key \"" + op.get() + "\" specified on url \"" + restProducerProperties.getUrl() + + "\" not found in execution properties passed by the current policy")) ); untaggedUrl = names.stream().reduce(untaggedUrl, (acc, str) -> acc.replace("{" + str + "}", (String) executionProperties.get(str))); + // @formatter:on } // Send the event as a REST request @@ -131,7 +130,7 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { if (LOGGER.isTraceEnabled()) { LOGGER.trace("event sent from engine using {} to URL {} with HTTP {} : {} and response {} ", this.name, - untaggedUrl, restProducerProperties.getHttpMethod(), event, response); + untaggedUrl, restProducerProperties.getHttpMethod(), event, response); } } @@ -152,7 +151,7 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { */ private Response sendEventAsRestRequest(final String untaggedUrl, final String event) { // We have already checked that it is a PUT or POST request - if (RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())) { + if (RestPluginCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())) { return client.target(untaggedUrl).request("application/json") .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).post(Entity.json(event)); } else { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java index b67a339aa..ce688d62d 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; -import ch.qos.logback.classic.Level; - import java.util.Properties; import javax.ws.rs.client.Client; @@ -47,6 +45,8 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.qos.logback.classic.Level; + /** * Test the ApexRestClientProducer class. * @@ -77,8 +77,8 @@ public class ApexRestClientProducerTest { fail("test should throw an exception here"); } catch (ApexEventException e) { assertEquals( - "specified producer properties are not applicable to REST client producer (RestClientProducer)", - e.getMessage()); + "specified producer properties are not applicable to REST client producer (RestClientProducer)", + e.getMessage()); } RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters(); @@ -89,8 +89,10 @@ public class ApexRestClientProducerTest { assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod()); fail("test should throw an exception here"); } catch (ApexEventException e) { - assertEquals("specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\" and \"PUT\" " - + "are supproted for event sending on REST client producer (RestClientConsumer)", e.getMessage()); + assertEquals( + "specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\" and \"PUT\" " + + "are supported for event sending on REST client producer (RestClientConsumer)", + e.getMessage()); } rcctp.setHttpMethod(null); @@ -109,7 +111,6 @@ public class ApexRestClientProducerTest { assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); arcp.stop(); - rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.PUT); arcp.init("RestClientConsumer", producerParameters); assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.PUT, rcctp.getHttpMethod()); @@ -171,7 +172,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); - //test property not found + // test property not found rcctp.setUrl("http://some.place2.that.{key}.not/{tag}and.again.{tag}"); Properties properties = new Properties(); properties.put("tag", "exist"); @@ -180,11 +181,9 @@ public class ApexRestClientProducerTest { arcp.stop(); fail("test should throw an exception"); } catch (Exception e) { - assertEquals( - "key\"key\"specified on url " - + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\"not found " - + "in execution properties passed by the current policy", - e.getMessage()); + assertEquals("key \"key\" specified on url " + + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\" not found " + + "in execution properties passed by the current policy", e.getMessage()); } } @@ -234,8 +233,8 @@ public class ApexRestClientProducerTest { rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST); ApexEventConsumer consumer = new ApexFileEventConsumer(); - SynchronousEventCache cache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, - 1000); + SynchronousEventCache cache = + new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, 1000); arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, cache); assertEquals(cache, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); arcp.init("RestClientConsumer", producerParameters); @@ -271,8 +270,8 @@ public class ApexRestClientProducerTest { rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST); ApexEventConsumer consumer = new ApexFileEventConsumer(); - SynchronousEventCache cache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, - 1000); + SynchronousEventCache cache = + new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, 1000); arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, cache); assertEquals(cache, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS)); arcp.init("RestClientConsumer", producerParameters); @@ -320,9 +319,9 @@ public class ApexRestClientProducerTest { fail("test should throw an exception here"); } catch (Exception e) { assertEquals( - "send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" " - + "failed with status code 400 and message \"null\", event:\n" + "This is an Event", - e.getMessage()); + "send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" " + + "failed with status code 400 and message \"null\", event:\n" + "This is an Event", + e.getMessage()); } } }
\ No newline at end of file |