aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-interactions/model-simulators/pom.xml15
-rw-r--r--models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java31
-rw-r--r--models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java12
-rw-r--r--models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java38
4 files changed, 69 insertions, 27 deletions
diff --git a/models-interactions/model-simulators/pom.xml b/models-interactions/model-simulators/pom.xml
index 41faf89b8..52025f4b4 100644
--- a/models-interactions/model-simulators/pom.xml
+++ b/models-interactions/model-simulators/pom.xml
@@ -63,10 +63,15 @@
<artifactId>gson</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <artifactId>sdnc</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <dependency>
+ <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
+ <artifactId>sdnc</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models-decisions</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java
index e79b563df..a2a06a4fb 100644
--- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java
+++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/GuardSimulatorJaxRs.java
@@ -21,34 +21,49 @@
package org.onap.policy.simulators;
+import java.util.Collections;
+import java.util.Map;
+
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
-import org.json.JSONObject;
+import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.models.decisions.concepts.DecisionResponse;
-@Path("/pdp/api")
+@Path("/policy/pdpx/v1")
public class GuardSimulatorJaxRs {
public static final String DENY_CLNAME = "denyGuard";
/**
* Get a guard decision.
- *
+ *
* @param req the request
* @return the response
*/
@POST
- @Path("/getDecision")
+ @Path("/decision")
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json")
- public String getGuardDecision(String req) {
- String clName = new JSONObject(req).getJSONObject("decisionAttributes").getString("clname");
+ public DecisionResponse getGuardDecision(DecisionRequest req) {
+ @SuppressWarnings("unchecked")
+ Map<String, String> guard = (Map<String, String>) req.getResource().get("guard");
+ String clName = guard.get("clName");
+ DecisionResponse response = new DecisionResponse();
if (DENY_CLNAME.equals(clName)) {
- return "{\"decision\": \"DENY\", \"details\": \"Decision Deny. You asked for it\"}";
+ response.setStatus("Deny");
+ response.setAdvice(Collections.emptyMap());
+ response.setObligations(Collections.emptyMap());
+ response.setPolicies(Collections.emptyList());
+ return response;
} else {
- return "{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}";
+ response.setStatus("Permit");
+ response.setAdvice(Collections.emptyMap());
+ response.setObligations(Collections.emptyMap());
+ response.setPolicies(Collections.emptyList());
+ return response;
}
}
}
diff --git a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java
index 99f9017a2..e5ee65004 100644
--- a/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java
+++ b/models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java
@@ -24,6 +24,7 @@ package org.onap.policy.simulators;
import java.io.IOException;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.network.NetworkUtil;
public class Util {
@@ -38,7 +39,7 @@ public class Util {
public static final int VFCSIM_SERVER_PORT = 6668;
public static final int GUARDSIM_SERVER_PORT = 6669;
public static final int SDNCSIM_SERVER_PORT = 6670;
-
+
private static final String CANNOT_CONNECT = "cannot connect to port ";
private static final String LOCALHOST = "localhost";
@@ -48,7 +49,7 @@ public class Util {
/**
* Build an A&AI simulator.
- *
+ *
* @return the simulator
* @throws InterruptedException if a thread is interrupted
* @throws IOException if an IO errror occurs
@@ -85,7 +86,7 @@ public class Util {
/**
* Build an SO simulator.
- *
+ *
* @return the simulator
* @throws InterruptedException if a thread is interrupted
* @throws IOException if an IO errror occurs
@@ -103,7 +104,7 @@ public class Util {
/**
* Build a VFC simulator.
- *
+ *
* @return the simulator
* @throws InterruptedException if a thread is interrupted
* @throws IOException if an IO errror occurs
@@ -121,7 +122,7 @@ public class Util {
/**
* Build a guard simulator.
- *
+ *
* @return the simulator
* @throws InterruptedException if a thread is interrupted
* @throws IOException if an IO errror occurs
@@ -129,6 +130,7 @@ public class Util {
public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, LOCALHOST,
GUARDSIM_SERVER_PORT, "/", false, true);
+ testServer.setSerializationProvider(GsonMessageBodyHandler.class.getName());
testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName());
testServer.waitedStart(5000);
if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
diff --git a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
index c99798077..58f748dd5 100644
--- a/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
+++ b/models-interactions/model-simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
@@ -8,9 +8,9 @@
* 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.
@@ -25,14 +25,22 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
+import java.util.HashMap;
+import java.util.Map;
+
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.models.decisions.concepts.DecisionResponse;
import org.onap.policy.rest.RestManager;
import org.onap.policy.rest.RestManager.Pair;
public class GuardSimulatorTest {
+ private static final StandardCoder coder = new StandardCoder();
/**
* Set up test class.
@@ -52,26 +60,38 @@ public class GuardSimulatorTest {
}
@Test
- public void testGuard() {
+ public void testGuard() throws CoderException {
String request = makeRequest("test_actor_id", "test_op_id", "test_target", "test_clName");
- String url = "http://localhost:" + Util.GUARDSIM_SERVER_PORT + "/pdp/api/getDecision";
+ String url = "http://localhost:" + Util.GUARDSIM_SERVER_PORT + "/policy/pdpx/v1/decision";
Pair<Integer, String> response =
new RestManager().post(url, "testUname", "testPass", null, "application/json", request);
assertNotNull(response);
assertNotNull(response.first);
assertNotNull(response.second);
- assertEquals("{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}", response.second);
+
+ DecisionResponse decision = coder.decode(response.second, DecisionResponse.class);
+ assertEquals("Permit", decision.getStatus());
request = makeRequest("test_actor_id", "test_op_id", "test_target", "denyGuard");
response = new RestManager().post(url, "testUname", "testPass", null, "application/json", request);
assertNotNull(response);
assertNotNull(response.first);
assertNotNull(response.second);
- assertEquals("{\"decision\": \"DENY\", \"details\": \"Decision Deny. You asked for it\"}", response.second);
+ decision = coder.decode(response.second, DecisionResponse.class);
+ assertEquals("Deny", decision.getStatus());
}
- private static String makeRequest(String actor, String recipe, String target, String clName) {
- return "{\"decisionAttributes\": {\"actor\": \"" + actor + "\", \"recipe\": \"" + recipe + "\""
- + ", \"target\": \"" + target + "\", \"clname\": \"" + clName + "\"}, \"onapName\": \"PDPD\"}";
+ private static String makeRequest(String actor, String recipe, String target, String clName) throws CoderException {
+ Map<String, String> guard = new HashMap<String, String>();
+ guard.put("actor", actor);
+ guard.put("recipe", recipe);
+ guard.put("target", target);
+ guard.put("clName", clName);
+ Map<String, Object> resource = new HashMap<String, Object>();
+ resource.put("guard", guard);
+ DecisionRequest request = new DecisionRequest();
+ request.setResource(resource);
+
+ return coder.encode(request);
}
}