diff options
Diffstat (limited to 'plugins')
5 files changed, 25 insertions, 17 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 04397d688..5591777eb 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 @@ -202,7 +202,7 @@ public class ApexRestClientConsumer implements ApexEventConsumer, Runnable { public void run() { try { final Response response = client.target(restConsumerProperties.getUrl()).request("application/json") - .get(); + .headers(restConsumerProperties.getHttpHeadersAsMultivaluedMap()).get(); // Check that the event request worked if (response.getStatus() != Response.Status.OK.getStatusCode()) { 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 a7e0ddd52..4113cea4b 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 @@ -183,9 +183,11 @@ public class ApexRestClientProducer implements ApexEventProducer { private Response sendEventAsRestRequest(final String event) { // We have already checked that it is a PUT or POST request if (RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())) { - return client.target(restProducerProperties.getUrl()).request("application/json").post(Entity.json(event)); + return client.target(restProducerProperties.getUrl()).request("application/json") + .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).post(Entity.json(event)); } else { - return client.target(restProducerProperties.getUrl()).request("application/json").put(Entity.json(event)); + return client.target(restProducerProperties.getUrl()).request("application/json") + .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).put(Entity.json(event)); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java index 0329d4440..b3fab9470 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParameters.java @@ -118,7 +118,7 @@ public class RestClientCarrierTechnologyParameters extends CarrierTechnologyPara /** * Check if http headers have been set for the REST request. * - * @return true if headers have beenset + * @return true if headers have been set */ public boolean checkHttpHeadersSet() { return httpHeaders != null && httpHeaders.length > 0; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java index 1498678e9..ae75dd7e5 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java @@ -147,7 +147,7 @@ public class ApexRestClientConusmerTest { consumerParameters.setCarrierTechnologyParameters(rcctp); rcctp.setUrl("http://some.place.that.does.not/exist"); SupportApexEventReceiver incomingEventReceiver = new SupportApexEventReceiver(); - + try { arcc.init("RestClientConsumer", consumerParameters, incomingEventReceiver); assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod()); @@ -163,6 +163,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); @@ -182,7 +183,7 @@ public class ApexRestClientConusmerTest { final String outString = outContent.toString(); System.setOut(stdout); - + assertTrue(outString.contains( "reception of event from URL \"http://some.place.that.does.not/exist\" failed with status code 400")); } @@ -215,6 +216,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); @@ -231,12 +233,11 @@ public class ApexRestClientConusmerTest { } catch (Exception e) { fail("test should not throw an exception"); } - + final String outString = outContent.toString(); System.setOut(stdout); - - assertTrue(outString.contains( - "received an empty event from URL \"http://some.place.that.does.not/exist\"")); + + assertTrue(outString.contains("received an empty event from URL \"http://some.place.that.does.not/exist\"")); } @Test @@ -268,6 +269,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn("").when(responseMock).readEntity(String.class); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); @@ -284,12 +286,11 @@ public class ApexRestClientConusmerTest { } catch (Exception e) { fail("test should not throw an exception"); } - + final String outString = outContent.toString(); System.setOut(stdout); - - assertTrue(outString.contains( - "received an empty event from URL \"http://some.place.that.does.not/exist\"")); + + assertTrue(outString.contains("received an empty event from URL \"http://some.place.that.does.not/exist\"")); } @Test @@ -321,6 +322,7 @@ public class ApexRestClientConusmerTest { Mockito.doReturn("This is an event").when(responseMock).readEntity(String.class); Mockito.doReturn(responseMock).when(builderMock).get(); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcc.setClient(httpClientMock); 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 3ef172427..8f0e0940b 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 @@ -161,13 +161,14 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); try { arcp.sendEvent(123, "EventName", "This is an Event"); arcp.stop(); - } catch (Exception e) { + } catch (Exception ex) { fail("test should not throw an exception"); } } @@ -197,6 +198,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); @@ -239,6 +241,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); @@ -250,14 +253,13 @@ public class ApexRestClientProducerTest { } } - @Test public void testApexRestClientProducerPostEventCacheTrace() { MockitoAnnotations.initMocks(this); ch.qos.logback.classic.Logger classicLogger = (ch.qos.logback.classic.Logger) LOGGER; classicLogger.setLevel(Level.TRACE); - + ApexRestClientProducer arcp = new ApexRestClientProducer(); assertNotNull(arcp); @@ -285,6 +287,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); @@ -321,6 +324,7 @@ public class ApexRestClientProducerTest { Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus(); Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any()); Mockito.doReturn(builderMock).when(targetMock).request("application/json"); + Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any()); Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl()); arcp.setClient(httpClientMock); |