summaryrefslogtreecommitdiffstats
path: root/controlloop/common/simulators/src/test/java
diff options
context:
space:
mode:
authorCharles Cole <cc847m@att.com>2017-12-07 12:17:17 -0600
committerCharles Cole <cc847m@att.com>2017-12-07 12:17:49 -0600
commit7cdedcbc4074ea117ce6b489e3f7d5f9e31dc9b2 (patch)
treed1eadf3737d15f9fe6de9fa6a6eccf16069e59fe /controlloop/common/simulators/src/test/java
parentbd7ee8043627c74f6ea2145dde279313da58261d (diff)
Remove guard dependency from simulators
Removed the deendency on guard from the guard simulator tests so that the guard simulator can be used to test guard functionality. Issue-ID: POLICY-490 Change-Id: Ie67abb85e9844c412c483b1bbf3fb4aa21f3530a Signed-off-by: Charles Cole <cc847m@att.com>
Diffstat (limited to 'controlloop/common/simulators/src/test/java')
-rw-r--r--controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java39
1 files changed, 22 insertions, 17 deletions
diff --git a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
index 696e2a60d..86e2c8cf9 100644
--- a/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
+++ b/controlloop/common/simulators/src/test/java/org/onap/policy/simulators/GuardSimulatorTest.java
@@ -24,12 +24,11 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.drools.http.server.HttpServletServer;
-import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.drools.utils.LoggerUtil;
-import org.onap.policy.guard.PolicyGuardXacmlHelper;
-import org.onap.policy.guard.PolicyGuardXacmlRequestAttributes;
-import org.onap.policy.guard.Util;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -44,16 +43,6 @@ public class GuardSimulatorTest {
} catch (Exception e) {
fail(e.getMessage());
}
- //
- // Set guard properties
- //
- org.onap.policy.guard.Util.setGuardEnvProps("http://localhost:6669/pdp/api/getDecision",
- "python",
- "test",
- "python",
- "test",
- "TEST");
-
}
@AfterClass
@@ -63,8 +52,24 @@ public class GuardSimulatorTest {
@Test
public void testGuard() {
- PolicyGuardXacmlRequestAttributes request = new PolicyGuardXacmlRequestAttributes("clname_id", "actor_id", "operation_id", "target_id", "request_id");
- String xacmlResponse = new PolicyGuardXacmlHelper().callPDP(request);
- assertNotNull(xacmlResponse);
+ String request = makeRequest("test_actor_id", "test_op_id", "test_target", "test_clName");
+ String url = "http://localhost:" + Util.GUARDSIM_SERVER_PORT + "/pdp/api/getDecision";
+ Pair<Integer, String> response = RESTManager.post(url, "testUname", "testPass", null, "application/json", request);
+ assertNotNull(response);
+ assertNotNull(response.a);
+ assertNotNull(response.b);
+ assertEquals("{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}", response.b);
+
+ request = makeRequest("test_actor_id", "test_op_id", "test_target", "denyGuard");
+ response = RESTManager.post(url, "testUname", "testPass", null, "application/json", request);
+ assertNotNull(response);
+ assertNotNull(response.a);
+ assertNotNull(response.b);
+ assertEquals("{\"decision\": \"DENY\", \"details\": \"Decision Deny. You asked for it\"}", response.b);
+ }
+
+ private static String makeRequest (String actor, String recipe, String target, String clName) {
+ return "{\"decisionAttributes\": {\"actor\": \"" + actor + "\", \"recipe\": \"" + recipe + "\""
+ + ", \"target\": \"" + target + "\", \"clname\": \"" + clName + "\"}, \"onapName\": \"PDPD\"}";
}
}