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;
26 import com.att.research.xacml.util.XACMLProperties;
27 import java.util.HashMap;
28 import java.util.LinkedList;
29 import java.util.List;
31 import java.util.UUID;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.onap.policy.common.logging.flexlogger.FlexLogger;
36 import org.onap.policy.common.logging.flexlogger.Logger;
37 import org.onap.policy.rest.adapter.PolicyRestAdapter;
38 import org.onap.policy.rest.adapter.RainyDayParams;
40 public class DecisionPolicyTest {
42 private static Logger logger = FlexLogger.getLogger(DecisionPolicyTest.class);
43 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
44 RainyDayParams rainyday = new RainyDayParams();
45 Map<String, String> attributeMap = new HashMap<>();
46 Map<String, String> treatmentMap = new HashMap<>();
47 Map<String, String> settingsMap = new HashMap<>();
48 List<String> errorCodeList = new LinkedList<>();
49 List<String> treatmentList = new LinkedList<>();
50 List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
51 List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
52 List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
53 List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
54 List<Object> dynamicVariableList = new LinkedList<>();
55 List<String> dataTypeList = new LinkedList<>();
56 DecisionPolicy component = null;
59 * @throws java.lang.Exception
62 public void setUp() throws Exception {
63 logger.info("setUp: Entering");
64 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
66 policyAdapter.setPolicyName("Test.Decision_junitTest.1.xml");
67 policyAdapter.setPolicyDescription("testing");
68 policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
69 policyAdapter.setPolicyType("Decision");
70 policyAdapter.setEditPolicy(false);
71 policyAdapter.setDomainDir("Test");
72 policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
73 policyAdapter.setHighestVersion(1);
74 policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
75 policyAdapter.setOnapName("MSO");
77 //rainy day attributes
78 attributeMap.put("ServiceType", "S");
79 attributeMap.put("VNFType", "V");
80 attributeMap.put("BB_ID", "testBB");
81 attributeMap.put("WorkStep", "1");
83 dynamicRuleAlgorithmLabels.add("test1");
84 dynamicRuleAlgorithmField1.add("testField1");
85 dynamicRuleAlgorithmCombo.add("testruleCombo");
86 dynamicRuleAlgorithmField2.add("testField2");
88 policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
89 policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
90 policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
91 policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
92 policyAdapter.setDynamicVariableList(dynamicVariableList);
93 policyAdapter.setDynamicSettingsMap(settingsMap);
94 policyAdapter.setDataTypeList(dataTypeList);
96 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
97 policyAdapter.setRainydayMap(treatmentMap);
98 policyAdapter.setRainyday(rainyday);
100 component = new DecisionPolicy(policyAdapter);
102 logger.info("setUp: exit");
106 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
109 public void testSavePolicies() {
110 DecisionPolicy mockDecision = Mockito.mock(component.getClass());
112 Map<String, String> successMap = new HashMap<>();
113 successMap.put("success", "success");
116 when(mockDecision.savePolicies()).thenReturn(successMap);
117 successMap = mockDecision.savePolicies();
118 } catch (Exception e) {
122 assertEquals(successMap.get("success"),"success");
126 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
129 public void testPrepareToSaveRainyDay() {
130 logger.debug("test PrepareToSave Policy: enter");
131 policyAdapter.setRuleProvider("Rainy_Day");
132 component = new DecisionPolicy(policyAdapter);
133 boolean response = false;
136 response = component.prepareToSave();
137 } catch (Exception e) {
138 logger.error("Exception Occured"+e);
140 assertTrue(response);