diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-11-06 12:02:46 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-11-07 12:41:09 +0000 |
commit | 53d8916cc60d97e2ce7ae345f8cc25f5602567da (patch) | |
tree | ee2f3a8e543c31993c51a58257354ccffb648dfe /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap | |
parent | 9dc414a0cabc9074e87a7c9cd5c3e5ceee733e5a (diff) |
Refactor unit test data
There were many copies of test policies and examples
strewn through the Apex unit tests. This change cleans
up the unit tests so that a single version of all example
policies is used in all tests.
Also added a new relative file root command line parameter
to Apex to allow the root of relative paths in configuration
files to be set.
Apologies for the size of this review but unfortunately
all of this must be done in one shot.
Issue-ID: POLICY-1252
Change-Id: Ibbb18fbf18e3897a1c61301d0a65e62bc643a0e9
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap')
2 files changed, 24 insertions, 13 deletions
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 051647339..1ace80906 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 @@ -113,15 +113,20 @@ public class TestRestRequestor { { "src/test/resources/prodcons/File2RESTRequest2FileGet.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); - final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") + response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") .request("application/json").get(); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + if (Response.Status.OK.getStatusCode() != response.getStatus()) { + break; + } + final String responseString = response.readEntity(String.class); @SuppressWarnings("unchecked") @@ -136,6 +141,8 @@ public class TestRestRequestor { apexMain.shutdown(); client.close(); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + assertEquals(Double.valueOf(50.0), getsSoFar); } @@ -156,13 +163,18 @@ public class TestRestRequestor { // Wait for the required amount of events to be received or for 10 seconds Double putsSoFar = 0.0; + + Response response = null; for (int i = 0; i < 40; i++) { ThreadUtilities.sleep(100); - final Response response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") + response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats") .request("application/json").get(); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + if (Response.Status.OK.getStatusCode() != response.getStatus()) { + break; + } + final String responseString = response.readEntity(String.class); @SuppressWarnings("unchecked") @@ -177,6 +189,7 @@ public class TestRestRequestor { apexMain.shutdown(); client.close(); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals(Double.valueOf(50.0), putsSoFar); } 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 0de34eb9b..860127a7b 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 @@ -47,11 +47,9 @@ public class TestRestRequestorEndpoint { private static int getMessagesReceived = 0; private static int deleteMessagesReceived = 0; - private static String EVENT_STRING = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.sample.events\",\n" - + "\"name\": \"Event0100\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + getMessagesReceived - + "\",\n" + "\"target\": \"apex\",\n" + "\"TestSlogan\": \"Test slogan for External Event0\",\n" - + "\"TestMatchCase\": 2,\n" + "\"TestTimestamp\": " + System.currentTimeMillis() + ",\n" - + "\"TestTemperature\": 9080.866\n" + "}"; + private static String EVENT_STRING = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.events\",\n" + + "\"name\": \"ResponseEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + + getMessagesReceived + "\",\n" + "\"target\": \"apex\",\n" + "\"intPar\": 9080\n" + "}"; /** * Reset counters. @@ -76,10 +74,10 @@ public class TestRestRequestorEndpoint { statMessagesReceived++; } return Response.status(200) - .entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": " - + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + ",\"DELETE\": " - + deleteMessagesReceived + "}") - .build(); + .entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + + ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + + ",\"DELETE\": " + deleteMessagesReceived + "}") + .build(); } /** |