2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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=========================================================
21 package org.onap.policy.pap.xacml.rest.components;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.Mockito.when;
27 import com.att.research.xacml.util.XACMLProperties;
29 import java.util.HashMap;
30 import java.util.LinkedList;
31 import java.util.List;
33 import java.util.UUID;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38 import org.onap.policy.common.logging.flexlogger.FlexLogger;
39 import org.onap.policy.common.logging.flexlogger.Logger;
40 import org.onap.policy.rest.adapter.PolicyRestAdapter;
41 import org.onap.policy.rest.adapter.RainyDayParams;
43 public class DecisionPolicyTest {
45 private static Logger logger = FlexLogger.getLogger(DecisionPolicyTest.class);
46 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
47 RainyDayParams rainyday = new RainyDayParams();
48 Map<String, String> attributeMap = new HashMap<>();
49 Map<String, String> treatmentMap = new HashMap<>();
50 Map<String, String> settingsMap = new HashMap<>();
51 List<String> errorCodeList = new LinkedList<>();
52 List<String> treatmentList = new LinkedList<>();
53 List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
54 List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
55 List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
56 List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
57 List<Object> dynamicVariableList = new LinkedList<>();
58 List<String> dataTypeList = new LinkedList<>();
59 DecisionPolicy component = null;
62 * @throws java.lang.Exception
65 public void setUp() throws Exception {
66 logger.info("setUp: Entering");
67 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pap.properties");
69 policyAdapter.setPolicyName("Test.Decision_junitTest.1.xml");
70 policyAdapter.setPolicyDescription("testing");
71 policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
72 policyAdapter.setPolicyType("Decision");
73 policyAdapter.setEditPolicy(false);
74 policyAdapter.setDomainDir("Test");
75 policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
76 policyAdapter.setHighestVersion(1);
77 policyAdapter.setPolicyID("urn:xacml:policy:id:" + UUID.randomUUID());
78 policyAdapter.setOnapName("MSO");
80 // rainy day attributes
81 attributeMap.put("ServiceType", "S");
82 attributeMap.put("VNFType", "V");
83 attributeMap.put("BB_ID", "testBB");
84 attributeMap.put("WorkStep", "1");
86 dynamicRuleAlgorithmLabels.add("test1");
87 dynamicRuleAlgorithmField1.add("testField1");
88 dynamicRuleAlgorithmCombo.add("testruleCombo");
89 dynamicRuleAlgorithmField2.add("testField2");
91 policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
92 policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
93 policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
94 policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
95 policyAdapter.setDynamicVariableList(dynamicVariableList);
96 policyAdapter.setDynamicSettingsMap(settingsMap);
97 policyAdapter.setDataTypeList(dataTypeList);
99 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
100 policyAdapter.setRainydayMap(treatmentMap);
101 policyAdapter.setRainyday(rainyday);
103 component = new DecisionPolicy(policyAdapter);
105 logger.info("setUp: exit");
109 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
112 public void testSavePolicies() {
113 DecisionPolicy mockDecision = Mockito.mock(component.getClass());
115 Map<String, String> successMap = new HashMap<>();
116 successMap.put("success", "success");
119 when(mockDecision.savePolicies()).thenReturn(successMap);
120 successMap = mockDecision.savePolicies();
121 } catch (Exception e) {
125 assertEquals(successMap.get("success"), "success");
129 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
132 public void testPrepareToSaveRainyDay() {
133 logger.debug("test PrepareToSave Policy: enter");
134 policyAdapter.setRuleProvider("Rainy_Day");
135 component = new DecisionPolicy(policyAdapter);
136 boolean response = false;
139 response = component.prepareToSave();
140 } catch (Exception e) {
141 logger.error("Exception Occured" + e);
143 assertTrue(response);