2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.simulators;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.fail;
28 import org.junit.AfterClass;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
32 import org.onap.policy.rest.RestManager;
33 import org.onap.policy.rest.RestManager.Pair;
35 public class GuardSimulatorTest {
41 public static void setupSimulator() {
43 org.onap.policy.simulators.Util.buildGuardSim();
44 } catch (Exception e) {
50 public static void tearDownSimulator() {
51 HttpServletServer.factory.destroy();
55 public void testGuard() {
56 String request = makeRequest("test_actor_id", "test_op_id", "test_target", "test_clName");
57 String url = "http://localhost:" + Util.GUARDSIM_SERVER_PORT + "/pdp/api/getDecision";
58 Pair<Integer, String> response =
59 new RestManager().post(url, "testUname", "testPass", null, "application/json", request);
60 assertNotNull(response);
61 assertNotNull(response.first);
62 assertNotNull(response.second);
63 assertEquals("{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}", response.second);
65 request = makeRequest("test_actor_id", "test_op_id", "test_target", "denyGuard");
66 response = new RestManager().post(url, "testUname", "testPass", null, "application/json", request);
67 assertNotNull(response);
68 assertNotNull(response.first);
69 assertNotNull(response.second);
70 assertEquals("{\"decision\": \"DENY\", \"details\": \"Decision Deny. You asked for it\"}", response.second);
73 private static String makeRequest(String actor, String recipe, String target, String clName) {
74 return "{\"decisionAttributes\": {\"actor\": \"" + actor + "\", \"recipe\": \"" + recipe + "\""
75 + ", \"target\": \"" + target + "\", \"clname\": \"" + clName + "\"}, \"onapName\": \"PDPD\"}";