2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.pap.xacml.rest.components;
22 import static org.junit.Assert.*;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.when;
27 import java.util.HashMap;
28 import java.util.LinkedList;
29 import java.util.List;
31 import java.util.UUID;
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mockito;
37 import org.onap.policy.common.logging.flexlogger.FlexLogger;
38 import org.onap.policy.common.logging.flexlogger.Logger;
39 import org.onap.policy.rest.adapter.PolicyRestAdapter;
40 import org.onap.policy.rest.adapter.RainyDayParams;
42 import com.att.research.xacml.util.XACMLProperties;
44 public class DecisionPolicyTest {
46 private static Logger logger = FlexLogger.getLogger(DecisionPolicyTest.class);
47 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
48 RainyDayParams rainyday = new RainyDayParams();
49 Map<String, String> attributeMap = new HashMap<>();
50 Map<String, String> treatmentMap = new HashMap<>();
51 Map<String, String> settingsMap = new HashMap<>();
52 List<String> errorCodeList = new LinkedList<>();
53 List<String> treatmentList = new LinkedList<>();
54 List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
55 List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
56 List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
57 List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
58 List<Object> dynamicVariableList = new LinkedList<>();
59 List<String> dataTypeList = new LinkedList<>();
60 DecisionPolicy component = null;
63 * @throws java.lang.Exception
66 public void setUp() throws Exception {
67 logger.info("setUp: Entering");
68 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
70 policyAdapter.setPolicyName("Test.Decision_junitTest.1.xml");
71 policyAdapter.setPolicyDescription("testing");
72 policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
73 policyAdapter.setPolicyType("Decision");
74 policyAdapter.setEditPolicy(false);
75 policyAdapter.setDomainDir("src/test/resources/client.properties");
76 policyAdapter.setDomain("Test");
77 policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
78 policyAdapter.setHighestVersion(1);
79 policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
80 policyAdapter.setOnapName("MSO");
82 //rainy day attributes
83 attributeMap.put("ServiceType", "S");
84 attributeMap.put("VNFType", "V");
85 attributeMap.put("BB_ID", "testBB");
86 attributeMap.put("WorkStep", "1");
88 dynamicRuleAlgorithmLabels.add("test1");
89 dynamicRuleAlgorithmField1.add("testField1");
90 dynamicRuleAlgorithmCombo.add("testruleCombo");
91 dynamicRuleAlgorithmField2.add("testField2");
93 policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
94 policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
95 policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
96 policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
97 policyAdapter.setDynamicVariableList(dynamicVariableList);
98 policyAdapter.setDynamicSettingsMap(settingsMap);
99 policyAdapter.setDataTypeList(dataTypeList);
101 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
102 policyAdapter.setRainydayMap(treatmentMap);
103 policyAdapter.setRainyday(rainyday);
105 component = new DecisionPolicy(policyAdapter);
107 logger.info("setUp: exit");
111 * @throws java.lang.Exception
114 public void tearDown() throws Exception {
118 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
121 public void testSavePolicies() {
122 DecisionPolicy mockDecision = Mockito.mock(component.getClass());
124 Map<String, String> successMap = new HashMap<>();
125 successMap.put("success", "success");
128 when(mockDecision.savePolicies()).thenReturn(successMap);
129 successMap = mockDecision.savePolicies();
130 } catch (Exception e) {
134 assertEquals(successMap.get("success"),"success");
138 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
141 public void testPrepareToSaveRainyDay() {
142 logger.debug("test PrepareToSave Policy: enter");
143 policyAdapter.setRuleProvider("Rainy_Day");
144 component = new DecisionPolicy(policyAdapter);
145 boolean response = false;
148 response = component.prepareToSave();
149 } catch (Exception e) {
150 logger.error("Exception Occured"+e);
152 assertTrue(response);
156 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
159 public void testPrepareToSaveCustom() {
160 logger.debug("test PrepareToSave Policy: enter");
161 policyAdapter.setRuleProvider("Custom");
162 component = new DecisionPolicy(policyAdapter);
163 boolean response = false;
166 response = component.prepareToSave();
167 } catch (Exception e) {
168 logger.error("Exception Occured"+e);
170 assertTrue(response);