diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-09-13 15:25:32 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-09-13 15:26:47 +0100 |
commit | 4cfa2e2d98f6877d54da304ef17f096284430908 (patch) | |
tree | c9452d2bf6bb96fae9c1e8e2d8ce8f8d01e69d22 /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src | |
parent | 0e23f7634e1e1fb31454c516974613335fcea1a4 (diff) |
Sonar/Checkstyle in service/plugins
Sonar and Checkstyle changes in plugins and services, and
knock on changes
Issue-ID: POLICY-1034
Change-Id: Iff7df74e54fce2c661dcc2fae75ae93d4cacfe5b
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src')
13 files changed, 258 insertions, 91 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/ApexRestRequest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequest.java index 12b9a695c..4b16d30d4 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequest.java @@ -31,32 +31,67 @@ public class ApexRestRequest { private Object event; private long timestamp; + /** + * Instantiates a new apex rest request. + * + * @param executionId the execution id + * @param eventName the event name + * @param event the event + */ public ApexRestRequest(final long executionId, final String eventName, final Object event) { this.executionId = executionId; this.eventName = eventName; this.event = event; } + /** + * Gets the execution id. + * + * @return the execution id + */ public long getExecutionId() { return executionId; } + /** + * Gets the event name. + * + * @return the event name + */ public String getEventName() { return eventName; } + /** + * Gets the event. + * + * @return the event + */ public Object getEvent() { return event; } + /** + * Gets the timestamp. + * + * @return the timestamp + */ public long getTimestamp() { return timestamp; } + /** + * Sets the timestamp. + * + * @param timestamp the new timestamp + */ public void setTimestamp(final long timestamp) { this.timestamp = timestamp; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ @Override public String toString() { return "ApexRestRequest [executionId=" + executionId + ", eventName=" + eventName + ", event=" + event 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 9998349db..dea839ebb 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 @@ -49,8 +49,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This class implements an Apex event consumer that issues a REST request and returns the REST - * response to APEX as an event. + * This class implements an Apex event consumer that issues a REST request and returns the REST response to APEX as an + * event. * * @author Liam Fallon (liam.fallon@ericsson.com) */ @@ -63,10 +63,10 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { private static final long REST_REQUESTOR_WAIT_SLEEP_TIME = 50; // The REST parameters read from the parameter service - private RESTRequestorCarrierTechnologyParameters restConsumerProperties; + private RestRequestorCarrierTechnologyParameters restConsumerProperties; // The timeout for REST requests - private long restRequestTimeout = RESTRequestorCarrierTechnologyParameters.DEFAULT_REST_REQUEST_TIMEOUT; + private long restRequestTimeout = RestRequestorCarrierTechnologyParameters.DEFAULT_REST_REQUEST_TIMEOUT; // The event receiver that will receive events from this consumer private ApexEventReceiver eventReceiver; @@ -99,25 +99,25 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { @Override public void init(final String consumerName, final EventHandlerParameters consumerParameters, - final ApexEventReceiver incomingEventReceiver) throws ApexEventException { + final ApexEventReceiver incomingEventReceiver) throws ApexEventException { this.eventReceiver = incomingEventReceiver; this.name = consumerName; // Check and get the REST Properties if (!(consumerParameters - .getCarrierTechnologyParameters() instanceof RESTRequestorCarrierTechnologyParameters)) { - final String errorMessage = - "specified consumer properties are not applicable to REST Requestor consumer (" + this.name + ")"; + .getCarrierTechnologyParameters() instanceof RestRequestorCarrierTechnologyParameters)) { + final String errorMessage = "specified consumer properties are not applicable to REST Requestor consumer (" + + this.name + ")"; LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } - restConsumerProperties = - (RESTRequestorCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + restConsumerProperties = (RestRequestorCarrierTechnologyParameters) consumerParameters + .getCarrierTechnologyParameters(); // Check if we are in peered mode if (!consumerParameters.isPeeredMode(EventHandlerPeeredMode.REQUESTOR)) { final String errorMessage = "REST Requestor consumer (" + this.name - + ") must run in peered requestor mode with a REST Requestor producer"; + + ") must run in peered requestor mode with a REST Requestor producer"; LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } @@ -125,7 +125,7 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { // Check if the HTTP method has been set if (restConsumerProperties.getHttpMethod() == null) { restConsumerProperties - .setHttpMethod(RESTRequestorCarrierTechnologyParameters.DEFAULT_REQUESTOR_HTTP_METHOD); + .setHttpMethod(RestRequestorCarrierTechnologyParameters.DEFAULT_REQUESTOR_HTTP_METHOD); } // Check if the HTTP URL has been set @@ -164,8 +164,8 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { try { incomingRestRequestQueue.add(restRequest); } catch (final Exception e) { - final String errorMessage = - "could not queue request \"" + restRequest + "\" on REST Requestor consumer (" + this.name + ")"; + final String errorMessage = "could not queue request \"" + restRequest + "\" on REST Requestor consumer (" + + this.name + ")"; LOGGER.warn(errorMessage); throw new ApexEventRuntimeException(errorMessage); } @@ -196,7 +196,7 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { } /** - * Get the number of events received to date + * Get the number of events received to date. * * @return the number of events received */ @@ -238,8 +238,8 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { while (consumerThread.isAlive() && !stopOrderedFlag) { try { // Take the next event from the queue - final ApexRestRequest restRequest = - incomingRestRequestQueue.poll(REST_REQUESTOR_WAIT_SLEEP_TIME, TimeUnit.MILLISECONDS); + final ApexRestRequest restRequest = incomingRestRequestQueue.poll(REST_REQUESTOR_WAIT_SLEEP_TIME, + TimeUnit.MILLISECONDS); if (restRequest == null) { // Poll timed out, check for request timeouts timeoutExpiredRequests(); @@ -268,7 +268,7 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { } /** - * This method times out REST requests that have expired + * This method times out REST requests that have expired. */ private void timeoutExpiredRequests() { // Hold a list of timed out requests @@ -284,8 +284,8 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { // Interrupt timed out requests and remove them from the ongoing map for (final ApexRestRequest timedoutRequest : timedoutRequestList) { - final String errorMessage = - "REST Requestor consumer (" + this.name + "), REST request timed out: " + timedoutRequest; + final String errorMessage = "REST Requestor consumer (" + this.name + "), REST request timed out: " + + timedoutRequest; LOGGER.warn(errorMessage); ongoingRestRequestMap.remove(timedoutRequest); @@ -321,7 +321,7 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { private Thread restRequestThread; /** - * Constructor, initialise the request runner with the request + * Constructor, initialise the request runner with the request. * * @param request the request this runner will issue */ @@ -341,28 +341,29 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { try { // Execute the REST request - final Response response = sendEventAsRESTRequest(); + final Response response = sendEventAsRestRequest(); // Check that the event request worked if (response.getStatus() != Response.Status.OK.getStatusCode()) { final String errorMessage = "reception of response to \"" + request + "\" from URL \"" - + restConsumerProperties.getUrl() + "\" failed with status code " + response.getStatus() - + " and message \"" + response.readEntity(String.class) + "\""; + + restConsumerProperties.getUrl() + "\" failed with status code " + + response.getStatus() + " and message \"" + response.readEntity(String.class) + + "\""; throw new ApexEventRuntimeException(errorMessage); } // Get the event we received - final String eventJSONString = response.readEntity(String.class); + final String eventJsonString = response.readEntity(String.class); // Check there is content - if (eventJSONString == null || eventJSONString.trim().length() == 0) { + if (eventJsonString == null || eventJsonString.trim().length() == 0) { final String errorMessage = "received an enpty response to \"" + request + "\" from URL \"" - + restConsumerProperties.getUrl() + "\""; + + restConsumerProperties.getUrl() + "\""; throw new ApexEventRuntimeException(errorMessage); } // Send the event into Apex - eventReceiver.receiveEvent(request.getExecutionId(), eventJSONString); + eventReceiver.receiveEvent(request.getExecutionId(), eventJsonString); synchronized (eventsReceivedLock) { eventsReceived++; @@ -376,7 +377,7 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { } /** - * Stop the REST request + * Stop the REST request. */ private void stop() { restRequestThread.interrupt(); @@ -387,21 +388,24 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { * * @return the response to the REST request */ - public Response sendEventAsRESTRequest() { + public Response sendEventAsRestRequest() { switch (restConsumerProperties.getHttpMethod()) { case GET: return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON).get(); case PUT: return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON) - .put(Entity.json(request.getEvent())); + .put(Entity.json(request.getEvent())); case POST: return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON) - .post(Entity.json(request.getEvent())); + .post(Entity.json(request.getEvent())); case DELETE: return client.target(restConsumerProperties.getUrl()).request(APPLICATION_JSON).delete(); + + default: + break; } return null; 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 721dfb683..69ad05b27 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 @@ -44,7 +44,7 @@ public class ApexRestRequestorProducer implements ApexEventProducer { private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestRequestorProducer.class); // The REST carrier properties - private RESTRequestorCarrierTechnologyParameters restProducerProperties; + private RestRequestorCarrierTechnologyParameters restProducerProperties; // The name for this producer private String name = null; @@ -68,14 +68,14 @@ public class ApexRestRequestorProducer implements ApexEventProducer { // Check and get the REST Properties if (!(producerParameters - .getCarrierTechnologyParameters() instanceof RESTRequestorCarrierTechnologyParameters)) { + .getCarrierTechnologyParameters() instanceof RestRequestorCarrierTechnologyParameters)) { final String errorMessage = "specified consumer properties are not applicable to REST requestor producer (" + this.name + ")"; LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } restProducerProperties = - (RESTRequestorCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + (RestRequestorCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); // Check if we are in peered mode if (!producerParameters.isPeeredMode(EventHandlerPeeredMode.REQUESTOR)) { 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 65eb731ed..acd5e52e8 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 @@ -37,9 +37,9 @@ import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnolo * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class RESTRequestorCarrierTechnologyParameters extends CarrierTechnologyParameters { +public class RestRequestorCarrierTechnologyParameters extends CarrierTechnologyParameters { /** The supported HTTP methods. */ - public enum HTTP_METHOD { + public enum HttpMethod { GET, PUT, POST, DELETE } @@ -55,19 +55,19 @@ public class RESTRequestorCarrierTechnologyParameters extends CarrierTechnologyP ApexRestRequestorConsumer.class.getCanonicalName(); /** The default HTTP method for request events. */ - public static final HTTP_METHOD DEFAULT_REQUESTOR_HTTP_METHOD = HTTP_METHOD.GET; + public static final HttpMethod DEFAULT_REQUESTOR_HTTP_METHOD = HttpMethod.GET; /** The default timeout for REST requests. */ public static final long DEFAULT_REST_REQUEST_TIMEOUT = 500; private String url = null; - private HTTP_METHOD httpMethod = null; + private HttpMethod httpMethod = null; /** * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter * service. */ - public RESTRequestorCarrierTechnologyParameters() { + public RestRequestorCarrierTechnologyParameters() { super(); // Set the carrier technology properties for the web socket carrier technology @@ -88,10 +88,10 @@ public class RESTRequestorCarrierTechnologyParameters extends CarrierTechnologyP /** * Sets the URL for the REST request. * - * @param incomingURL the URL + * @param incomingUrl the URL */ - public void setURL(final String incomingURL) { - this.url = incomingURL; + public void setUrl(final String incomingUrl) { + this.url = incomingUrl; } /** @@ -99,7 +99,7 @@ public class RESTRequestorCarrierTechnologyParameters extends CarrierTechnologyP * * @return the HTTP method */ - public HTTP_METHOD getHttpMethod() { + public HttpMethod getHttpMethod() { return httpMethod; } @@ -108,7 +108,7 @@ public class RESTRequestorCarrierTechnologyParameters extends CarrierTechnologyP * * @param httpMethod the HTTP method */ - public void setHttpMethod(final HTTP_METHOD httpMethod) { + public void setHttpMethod(final HttpMethod httpMethod) { this.httpMethod = httpMethod; } 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/TestRESTRequestor.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRestRequestor.java index 3db0f1467..051647339 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRESTRequestor.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRestRequestor.java @@ -48,7 +48,10 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.service.engine.main.ApexMain; -public class TestRESTRequestor { +/** + * The Class TestRestRequestor. + */ +public class TestRestRequestor { private static final String BASE_URI = "http://localhost:32801/TestRESTRequestor"; private static HttpServer server; @@ -58,6 +61,11 @@ public class TestRESTRequestor { private final PrintStream stdout = System.out; private final PrintStream stderr = System.err; + /** + * Sets the up. + * + * @throws Exception the exception + */ @BeforeClass public static void setUp() throws Exception { final ResourceConfig rc = new ResourceConfig(TestRestRequestorEndpoint.class); @@ -68,6 +76,11 @@ public class TestRESTRequestor { } } + /** + * Tear down. + * + * @throws Exception the exception + */ @AfterClass public static void tearDown() throws Exception { server.shutdownNow(); @@ -77,16 +90,27 @@ public class TestRESTRequestor { new File("src/test/resources/events/EventsOutMulti1.json").delete(); } + /** + * Reset counters. + */ @Before public void resetCounters() { TestRestRequestorEndpoint.resetCounters(); } + /** + * Test rest requestor get. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. + */ @Test - public void testRESTRequestorGet() throws MessagingException, ApexException, IOException { + public void testRestRequestorGet() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGet.json" }; + final String[] args = + { "src/test/resources/prodcons/File2RESTRequest2FileGet.json" }; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -95,7 +119,7 @@ public class TestRESTRequestor { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -115,11 +139,19 @@ public class TestRESTRequestor { assertEquals(Double.valueOf(50.0), getsSoFar); } + /** + * Test REST requestor put. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. + */ @Test - public void testRESTRequestorPut() throws MessagingException, ApexException, IOException { + public void testRestRequestorPut() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FilePut.json" }; + final String[] args = + { "src/test/resources/prodcons/File2RESTRequest2FilePut.json" }; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -128,7 +160,7 @@ public class TestRESTRequestor { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -148,11 +180,19 @@ public class TestRESTRequestor { assertEquals(Double.valueOf(50.0), putsSoFar); } + /** + * Test REST requestor post. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. + */ @Test - public void testRESTRequestorPost() throws MessagingException, ApexException, IOException { + public void testRestRequestorPost() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FilePost.json" }; + final String[] args = + { "src/test/resources/prodcons/File2RESTRequest2FilePost.json" }; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -161,7 +201,7 @@ public class TestRESTRequestor { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -181,11 +221,19 @@ public class TestRESTRequestor { assertEquals(Double.valueOf(50.0), postsSoFar); } + /** + * Test REST requestor delete. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. + */ @Test - public void testRESTRequestorDelete() throws MessagingException, ApexException, IOException { + public void testRestRequestorDelete() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileDelete.json" }; + final String[] args = + { "src/test/resources/prodcons/File2RESTRequest2FileDelete.json" }; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -194,7 +242,7 @@ public class TestRESTRequestor { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -214,11 +262,19 @@ public class TestRESTRequestor { assertEquals(Double.valueOf(50.0), deletesSoFar); } + /** + * Test REST requestor multi inputs. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. + */ @Test - public void testRESTRequestorMultiInputs() throws MessagingException, ApexException, IOException { + public void testRestRequestorMultiInputs() throws MessagingException, ApexException, IOException { final Client client = ClientBuilder.newClient(); - final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json" }; + final String[] args = + { "src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json" }; final ApexMain apexMain = new ApexMain(args); // Wait for the required amount of events to be received or for 10 seconds @@ -227,7 +283,7 @@ public class TestRESTRequestor { ThreadUtilities.sleep(100); final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") - .request("application/json").get(); + .request("application/json").get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); final String responseString = response.readEntity(String.class); @@ -249,12 +305,20 @@ public class TestRESTRequestor { ThreadUtilities.sleep(1000); } + /** + * Test REST requestor producer alone. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. + */ @Test - public void testRESTRequestorProducerAlone() throws MessagingException, ApexException, IOException { + public void testRestRequestorProducerAlone() throws MessagingException, ApexException, IOException { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json" }; + final String[] args = + { "src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json" }; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); @@ -265,16 +329,24 @@ public class TestRESTRequestor { System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains( - "REST Requestor producer (RestRequestorProducer) must run in peered requestor mode with a REST Requestor consumer")); + assertTrue(outString.contains("REST Requestor producer (RestRequestorProducer) " + + "must run in peered requestor mode with a REST Requestor consumer")); } + /** + * Test REST requestor consumer alone. + * + * @throws MessagingException the messaging exception + * @throws ApexException the apex exception + * @throws IOException Signals that an I/O exception has occurred. + */ @Test - public void testRESTRequestorConsumerAlone() throws MessagingException, ApexException, IOException { + public void testRestRequestorConsumerAlone() throws MessagingException, ApexException, IOException { System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); - final String[] args = { "src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json" }; + final String[] args = + { "src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json" }; final ApexMain apexMain = new ApexMain(args); ThreadUtilities.sleep(200); @@ -285,7 +357,7 @@ public class TestRESTRequestor { System.setOut(stdout); System.setErr(stderr); - assertTrue(outString.contains( - "peer \"RestRequestorProducer for peered mode REQUESTOR does not exist or is not defined with the same peered mode")); + assertTrue(outString.contains("peer \"RestRequestorProducer for peered mode REQUESTOR " + + "does not exist or is not defined with the same peered mode")); } } 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/TestRestRequestorEndpoint.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRestRequestorEndpoint.java index 4977b3efb..0de34eb9b 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRestRequestorEndpoint.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restrequestor/TestRestRequestorEndpoint.java @@ -34,6 +34,9 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.core.Response; +/** + * The Class TestRestRequestorEndpoint. + */ @Path("/apex") public class TestRestRequestorEndpoint { @@ -50,6 +53,9 @@ public class TestRestRequestorEndpoint { + "\"TestMatchCase\": 2,\n" + "\"TestTimestamp\": " + System.currentTimeMillis() + ",\n" + "\"TestTemperature\": 9080.866\n" + "}"; + /** + * Reset counters. + */ public static void resetCounters() { postMessagesReceived = 0; putMessagesReceived = 0; @@ -58,6 +64,11 @@ public class TestRestRequestorEndpoint { deleteMessagesReceived = 0; } + /** + * Service get stats. + * + * @return the response + */ @Path("/event/Stats") @GET public Response serviceGetStats() { @@ -71,6 +82,11 @@ public class TestRestRequestorEndpoint { .build(); } + /** + * Service get event. + * + * @return the response + */ @Path("/event/GetEvent") @GET public Response serviceGetEvent() { @@ -81,18 +97,34 @@ public class TestRestRequestorEndpoint { return Response.status(200).entity(EVENT_STRING).build(); } + /** + * Service get empty event. + * + * @return the response + */ @Path("/event/GetEmptyEvent") @GET public Response serviceGetEmptyEvent() { return Response.status(200).build(); } + /** + * Service get event bad response. + * + * @return the response + */ @Path("/event/GetEventBadResponse") @GET public Response serviceGetEventBadResponse() { return Response.status(400).build(); } + /** + * Service post request. + * + * @param jsonString the json string + * @return the response + */ @Path("/event/PostEvent") @POST public Response servicePostRequest(final String jsonString) { @@ -111,12 +143,24 @@ public class TestRestRequestorEndpoint { return Response.status(200).entity(EVENT_STRING).build(); } + /** + * Service post request bad response. + * + * @param jsonString the json string + * @return the response + */ @Path("/event/PostEventBadResponse") @POST public Response servicePostRequestBadResponse(final String jsonString) { return Response.status(400).build(); } + /** + * Service put request. + * + * @param jsonString the json string + * @return the response + */ @Path("/event/PutEvent") @PUT public Response servicePutRequest(final String jsonString) { @@ -135,6 +179,12 @@ public class TestRestRequestorEndpoint { return Response.status(200).entity(EVENT_STRING).build(); } + /** + * Service delete request. + * + * @param jsonString the json string + * @return the response + */ @Path("/event/DeleteEvent") @DELETE public Response serviceDeleteRequest(final String jsonString) { @@ -145,6 +195,12 @@ public class TestRestRequestorEndpoint { return Response.status(200).entity(EVENT_STRING).build(); } + /** + * Service delete request bad response. + * + * @param jsonString the json string + * @return the response + */ @Path("/event/DeleteEventBadResponse") @DELETE public Response serviceDeleteRequestBadResponse(final String jsonString) { diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json index 6e12c0b1f..46da3970a 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileDelete.json @@ -9,7 +9,7 @@ "engineParameters": { "executorParameters": { "MVEL": { - "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" } } } @@ -29,7 +29,7 @@ "RestRequestorConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://localhost:32801/TestRESTRequestor/apex/event/DeleteEvent", "httpMethod": "DELETE", @@ -49,7 +49,7 @@ "RestRequestorProducer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json index d0879eb73..3c1d314fe 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGet.json @@ -9,7 +9,7 @@ "engineParameters": { "executorParameters": { "MVEL": { - "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" } } } @@ -29,7 +29,7 @@ "RestRequestorConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", "httpMethod": "GET", @@ -49,7 +49,7 @@ "RestRequestorProducer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json index b957b61de..9ebe89df5 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json @@ -9,7 +9,7 @@ "engineParameters": { "executorParameters": { "MVEL": { - "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" } } } @@ -29,7 +29,7 @@ "RestRequestorConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", "httpMethod": "GET", @@ -49,7 +49,7 @@ "RestRequestorProducer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json index ba1c997f5..424d2b454 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json @@ -9,7 +9,7 @@ "engineParameters": { "executorParameters": { "MVEL": { - "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" } } } @@ -29,7 +29,7 @@ "RestRequestorConsumer0": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", "httpMethod": "GET", @@ -58,7 +58,7 @@ "RestRequestorConsumer1": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://localhost:32801/TestRESTRequestor/apex/event/GetEvent", "httpMethod": "GET", @@ -78,7 +78,7 @@ "RestRequestorProducer0": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" @@ -103,7 +103,7 @@ "RestRequestorProducer1": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json index a635e6c72..4fcbf59d9 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json @@ -9,7 +9,7 @@ "engineParameters": { "executorParameters": { "MVEL": { - "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" } } } @@ -31,7 +31,7 @@ "RestRequestorProducer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json index 9db89ce89..fe5af67ee 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/prodcons/File2RESTRequest2FilePost.json @@ -9,7 +9,7 @@ "engineParameters": { "executorParameters": { "MVEL": { - "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" } } } @@ -29,7 +29,7 @@ "RestRequestorConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://localhost:32801/TestRESTRequestor/apex/event/PostEvent", "httpMethod": "POST", @@ -49,7 +49,7 @@ "RestRequestorProducer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" 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 3eebe3d8a..e78446447 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 @@ -9,7 +9,7 @@ "engineParameters": { "executorParameters": { "MVEL": { - "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters" + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" } } } @@ -29,7 +29,7 @@ "RestRequestorConsumer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters", + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters", "parameters": { "url": "http://localhost:32801/TestRESTRequestor/apex/event/PutEvent", "httpMethod": "PUT", @@ -49,7 +49,7 @@ "RestRequestorProducer": { "carrierTechnologyParameters": { "carrierTechnology": "RESTREQUESTOR", - "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RESTRequestorCarrierTechnologyParameters" + "parameterClassName": "org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters" }, "eventProtocolParameters": { "eventProtocol": "JSON" |