diff options
author | Dinh Danh Le <dinh.danh.le@ericsson.com> | 2018-07-28 23:01:04 +0100 |
---|---|---|
committer | Dinh Danh Le <dinh.danh.le@ericsson.com> | 2018-07-30 08:57:12 +0100 |
commit | 2bfd20329d25cfa7b06639e759ab4cd9fbceb4b9 (patch) | |
tree | 028b1d75231da8098a403dc602f43b314464fc03 /testsuites/integration/integration-uservice-test | |
parent | 7ab23ab0a54a6391f4c6bb37733fe10fc9e33a3f (diff) |
Add test case for plugin event carrier RESTServer
Change-Id: Ia81a35e359c1f7072f4a39db871076d478dd7dab
Signed-off-by: Dinh Danh Le <dinh.danh.le@ericsson.com>
Issue-ID: POLICY-954
Diffstat (limited to 'testsuites/integration/integration-uservice-test')
-rw-r--r-- | testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/apps/uservice/test/adapt/restserver/TestRESTServer.java | 47 |
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(); } |