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("Test");
76 policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
77 policyAdapter.setHighestVersion(1);
78 policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
79 policyAdapter.setOnapName("MSO");
81 //rainy day attributes
82 attributeMap.put("ServiceType", "S");
83 attributeMap.put("VNFType", "V");
84 attributeMap.put("BB_ID", "testBB");
85 attributeMap.put("WorkStep", "1");
87 dynamicRuleAlgorithmLabels.add("test1");
88 dynamicRuleAlgorithmField1.add("testField1");
89 dynamicRuleAlgorithmCombo.add("testruleCombo");
90 dynamicRuleAlgorithmField2.add("testField2");
92 policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
93 policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
94 policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
95 policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
96 policyAdapter.setDynamicVariableList(dynamicVariableList);
97 policyAdapter.setDynamicSettingsMap(settingsMap);
98 policyAdapter.setDataTypeList(dataTypeList);
100 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
101 policyAdapter.setRainydayMap(treatmentMap);
102 policyAdapter.setRainyday(rainyday);
104 component = new DecisionPolicy(policyAdapter);
106 logger.info("setUp: exit");
110 * @throws java.lang.Exception
113 public void tearDown() throws Exception {
117 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
120 public void testSavePolicies() {
121 DecisionPolicy mockDecision = Mockito.mock(component.getClass());
123 Map<String, String> successMap = new HashMap<>();
124 successMap.put("success", "success");
127 when(mockDecision.savePolicies()).thenReturn(successMap);
128 successMap = mockDecision.savePolicies();
129 } catch (Exception e) {
133 assertEquals(successMap.get("success"),"success");
137 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
140 public void testPrepareToSaveRainyDay() {
141 logger.debug("test PrepareToSave Policy: enter");
142 policyAdapter.setRuleProvider("Rainy_Day");
143 component = new DecisionPolicy(policyAdapter);
144 boolean response = false;
147 response = component.prepareToSave();
148 } catch (Exception e) {
149 logger.error("Exception Occured"+e);
151 assertTrue(response);
155 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
158 public void testPrepareToSaveCustom() {
159 logger.debug("test PrepareToSave Policy: enter");
160 policyAdapter.setRuleProvider("Custom");
161 component = new DecisionPolicy(policyAdapter);
162 boolean response = false;
165 response = component.prepareToSave();
166 } catch (Exception e) {
167 logger.error("Exception Occured"+e);
169 assertTrue(response);