2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.pdp.rest.api.services;
22 import static org.junit.Assert.*;
24 import java.io.FileInputStream;
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.LinkedList;
28 import java.util.List;
30 import java.util.Properties;
31 import java.util.UUID;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.policy.api.AttributeType;
37 import org.onap.policy.api.PolicyClass;
38 import org.onap.policy.api.PolicyException;
39 import org.onap.policy.api.PolicyParameters;
41 public class DecisionPolicyServiceTest {
43 DecisionPolicyService service = null;
46 public void setUp() throws Exception {
47 Properties prop = new Properties();
48 prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
49 String succeeded = prop.getProperty("xacml.rest.pap.url");
50 List<String> paps = Arrays.asList(succeeded.split(","));
51 PAPServices.setPaps(paps);
52 PAPServices.junit = true;
54 PolicyParameters policyParameters = new PolicyParameters();
55 policyParameters.setPolicyClass(PolicyClass.Decision);
56 policyParameters.setPolicyName("Test.testDecisionPolicy");
57 policyParameters.setOnapName("MSO");
58 policyParameters.setPolicyDescription("This is a sample Decision policy UPDATE example with Settings");
60 Map<String, String> configAttributes = new HashMap<>();
61 configAttributes.put("Template", "UpdateTemplate");
62 configAttributes.put("controller", "default");
63 configAttributes.put("SamPoll", "30");
64 configAttributes.put("value", "abcd");
65 Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
66 attributes.put(AttributeType.MATCHING, configAttributes);
67 Map<String, String> settingsMap = new HashMap<>();
68 settingsMap.put("server", "5");
69 attributes.put(AttributeType.SETTINGS, settingsMap);
70 policyParameters.setAttributes(attributes);
72 List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
73 List<String> dynamicRuleAlgorithmFunctions = new LinkedList<>();
74 List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
75 List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
76 dynamicRuleAlgorithmLabels = Arrays.asList("A1","A2","A3","A4","A5","A6","A7");
77 dynamicRuleAlgorithmField1 = Arrays.asList("S_server","cap","cobal","A2","Config","A4","A1");
78 dynamicRuleAlgorithmFunctions = Arrays.asList("integer-equal","string-contains","integer-equal","and","integer-greater-than","or","and");
79 dynamicRuleAlgorithmField2 = Arrays.asList("90","ca","90","A3","45","A5","A6");
80 policyParameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
81 policyParameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
82 policyParameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions);
83 policyParameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
85 policyParameters.setRequestID(UUID.randomUUID());
86 policyParameters.setGuard(true);
87 policyParameters.setRiskLevel("5");
88 policyParameters.setRiskType("TEST");
89 String policyName = "testDecisionPolicy";
90 String policyScope = "Test";
91 service = new DecisionPolicyService(policyName, policyScope, policyParameters);
95 public void tearDown() throws Exception {
96 PAPServices.setPaps(null);
97 PAPServices.junit = false;
101 public final void testDecisionPolicyService() {
102 assertNotNull(service);
106 public final void testGetValidation() {
107 assertTrue(service.getValidation());
111 public final void testGetMessage() {
112 String message = service.getMessage();
113 assertNull(message); }
116 public final void testGetResult() throws PolicyException {
117 service.getValidation();
118 String result = service.getResult(false);
119 assertEquals("success",result); }