aboutsummaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-vcpe/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'examples/examples-onap-vcpe/src/test/java')
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSim.java59
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSimEndpoint.java137
2 files changed, 196 insertions, 0 deletions
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSim.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSim.java
new file mode 100644
index 000000000..a821462f6
--- /dev/null
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSim.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.domains.onap.vcpe;
+
+import java.net.URI;
+
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+
+public class AAIAndGuardSim {
+ private static final String BASE_URI = "http://192.168.144.235:54321/AAIAndGuardSim";
+ private HttpServer server;
+
+ public AAIAndGuardSim() {
+ final ResourceConfig rc = new ResourceConfig(AAIAndGuardSimEndpoint.class);
+ server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
+
+ while (!server.isStarted()) {
+ ThreadUtilities.sleep(50);
+ }
+ }
+
+ public void tearDown() throws Exception {
+ server.shutdown();
+ }
+
+ public static void main(final String[] args) throws Exception {
+ final AAIAndGuardSim sim = new AAIAndGuardSim();
+
+ while (true) {
+ try {
+ Thread.sleep(100);
+ } catch (final InterruptedException e) {
+ break;
+ }
+ }
+ sim.tearDown();
+ }
+}
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSimEndpoint.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSimEndpoint.java
new file mode 100644
index 000000000..6c7f7db19
--- /dev/null
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AAIAndGuardSimEndpoint.java
@@ -0,0 +1,137 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.domains.onap.vcpe;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.google.gson.Gson;
+
+import java.util.Map;
+import java.util.Random;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+
+
+@Path("/sim")
+public class AAIAndGuardSimEndpoint {
+
+ private static int postMessagesReceived = 0;
+ private static int putMessagesReceived = 0;
+ private static int statMessagesReceived = 0;
+ private static int getMessagesReceived = 0;
+
+ @Path("/pdp/api/Stats")
+ @GET
+ public Response serviceGetStats() {
+ statMessagesReceived++;
+ return Response.status(200).entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
+ + ",\"POST\": " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
+ }
+
+ @Path("/pdp/api/getDecision")
+ @POST
+ public Response serviceGuardPostRequest(final String jsonString) {
+ postMessagesReceived++;
+
+ if (postMessagesReceived % 2 == 0) {
+ return Response.status(200).entity("{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}")
+ .build();
+ } else {
+ return Response.status(200).entity("{\"decision\": \"DENY\", \"details\": \"Decision Denied. NOK :-(\"}")
+ .build();
+ }
+ }
+
+ @Path("/event/GetEvent")
+ @GET
+ public Response serviceGetEvent() {
+ final Random rand = new Random();
+ final int nextMatchCase = rand.nextInt(4);
+ final String nextEventName = "Event0" + rand.nextInt(2) + "00";
+
+ final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.sample.events\",\n" + "\"name\": \""
+ + nextEventName + "\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + getMessagesReceived
+ + "\",\n" + "\"target\": \"apex\",\n" + "\"TestSlogan\": \"Test slogan for External Event0\",\n"
+ + "\"TestMatchCase\": " + nextMatchCase + ",\n" + "\"TestTimestamp\": " + System.currentTimeMillis()
+ + ",\n" + "\"TestTemperature\": 9080.866\n" + "}";
+
+ getMessagesReceived++;
+
+ return Response.status(200).entity(eventString).build();
+ }
+
+ @Path("/event/GetEmptyEvent")
+ @GET
+ public Response serviceGetEmptyEvent() {
+ return Response.status(200).build();
+ }
+
+ @Path("/event/GetEventBadResponse")
+ @GET
+ public Response serviceGetEventBadResponse() {
+ return Response.status(400).build();
+ }
+
+ @Path("/event/PostEvent")
+ @POST
+ public Response servicePostRequest(final String jsonString) {
+ postMessagesReceived++;
+
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
+ assertTrue(jsonMap.containsKey("name"));
+ assertEquals("0.0.1", jsonMap.get("version"));
+ assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
+ assertEquals("Act", jsonMap.get("source"));
+ assertEquals("Outside", jsonMap.get("target"));
+
+ return Response.status(200).entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
+ + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
+ }
+
+ @Path("/event/PostEventBadResponse")
+ @POST
+ public Response servicePostRequestBadResponse(final String jsonString) {
+ return Response.status(400).build();
+ }
+
+ @Path("/event/PutEvent")
+ @PUT
+ public Response servicePutRequest(final String jsonString) {
+ putMessagesReceived++;
+
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
+ assertTrue(jsonMap.containsKey("name"));
+ assertEquals("0.0.1", jsonMap.get("version"));
+ assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
+ assertEquals("Act", jsonMap.get("source"));
+ assertEquals("Outside", jsonMap.get("target"));
+
+ return Response.status(200).entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
+ + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
+ }
+}