aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-07-30 17:37:07 +0000
committerGerrit Code Review <gerrit@onap.org>2018-07-30 17:37:07 +0000
commitdf417ab0b34912e153532373fd2c0af33e4b2179 (patch)
treeb0d6b154dce7b17d1ce213784cddb11203151b62
parent0bc973535236386a30a49ca4bd77320ad29f9f47 (diff)
parent2bfd20329d25cfa7b06639e759ab4cd9fbceb4b9 (diff)
Merge "Add test case for plugin event carrier RESTServer"
-rw-r--r--testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java47
1 files changed, 33 insertions, 14 deletions
diff --git a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java
index 5ac714673..b0bcac439 100644
--- a/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java
+++ b/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java
@@ -59,10 +59,7 @@ public class TestRESTServer {
final Client client = ClientBuilder.newClient();
- // Wait for the required amount of events to be received or for 10 seconds
for (int i = 0; i < 20; i++) {
- ThreadUtilities.sleep(100);
-
final Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
.request("application/json").put(Entity.json(getEvent()));
@@ -85,10 +82,7 @@ public class TestRESTServer {
final Client client = ClientBuilder.newClient();
- // Wait for the required amount of events to be received or for 10 seconds
for (int i = 0; i < 20; i++) {
- ThreadUtilities.sleep(100);
-
final Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
.request("application/json").post(Entity.json(getEvent()));
@@ -105,16 +99,46 @@ public class TestRESTServer {
}
@Test
+ public void testRESTServerGetStatus() throws MessagingException, ApexException, IOException {
+ final String[] args = {"src/test/resources/prodcons/RESTServerJsonEvent.json"};
+ final ApexMain apexMain = new ApexMain(args);
+
+ final Client client = ClientBuilder.newClient();
+
+ // trigger 10 POST & PUT events
+ for (int i = 0; i < 10; i++) {
+ final Response postResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
+ .request("application/json").post(Entity.json(getEvent()));
+ final Response putResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
+ .request("application/json").put(Entity.json(getEvent()));
+ assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
+ assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
+ }
+
+ final Response statResponse =
+ client.target("http://localhost:23324/apex/FirstConsumer/Status").request("application/json").get();
+
+ assertEquals(Response.Status.OK.getStatusCode(), statResponse.getStatus());
+ final String responseString = statResponse.readEntity(String.class);
+
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
+ assertEquals("[FirstConsumer]", jsonMap.get("INPUTS"));
+ assertEquals(1.0, jsonMap.get("STAT"));
+ assertEquals(10.0, jsonMap.get("POST"));
+ assertEquals(10.0, jsonMap.get("PUT"));
+
+ apexMain.shutdown();
+ }
+
+ @Test
public void testRESTServerMultiInputs() throws MessagingException, ApexException, IOException {
final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventMultiIn.json"};
final ApexMain apexMain = new ApexMain(args);
final Client client = ClientBuilder.newClient();
- // Wait for the required amount of events to be received or for 10 seconds
for (int i = 0; i < 20; i++) {
- ThreadUtilities.sleep(100);
-
final Response firstResponse = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
.request("application/json").post(Entity.json(getEvent()));
@@ -286,10 +310,7 @@ public class TestRESTServer {
final Client client = ClientBuilder.newClient();
- // Wait for the required amount of events to be received or for 10 seconds
for (int i = 0; i < 20; i++) {
- ThreadUtilities.sleep(100);
-
final Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
.request("application/json").put(Entity.json(getEvent()));
@@ -301,10 +322,8 @@ public class TestRESTServer {
assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
assertEquals("Test slogan for External Event0", jsonMap.get("TestSlogan"));
assertTrue(((String) jsonMap.get("exceptionMessage")).contains("caused by: / by zero"));
-
}
-
apexMain.shutdown();
}