2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-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.pap.xacml.rest.components;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.Mockito.when;
26 import java.util.HashMap;
27 import java.util.LinkedList;
28 import java.util.List;
30 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 import com.att.research.xacml.util.XACMLProperties;
42 public class DecisionPolicyTest {
44 private static Logger logger = FlexLogger.getLogger(DecisionPolicyTest.class);
45 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
46 RainyDayParams rainyday = new RainyDayParams();
47 Map<String, String> attributeMap = new HashMap<>();
48 Map<String, String> treatmentMap = new HashMap<>();
49 Map<String, String> settingsMap = new HashMap<>();
50 List<String> errorCodeList = new LinkedList<>();
51 List<String> treatmentList = new LinkedList<>();
52 List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
53 List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
54 List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
55 List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
56 List<Object> dynamicVariableList = new LinkedList<>();
57 List<String> dataTypeList = new LinkedList<>();
58 DecisionPolicy component = null;
61 * @throws java.lang.Exception
64 public void setUp() throws Exception {
65 logger.info("setUp: Entering");
66 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
68 policyAdapter.setPolicyName("Test.Decision_junitTest.1.xml");
69 policyAdapter.setPolicyDescription("testing");
70 policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
71 policyAdapter.setPolicyType("Decision");
72 policyAdapter.setEditPolicy(false);
73 policyAdapter.setDomainDir("Test");
74 policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
75 policyAdapter.setHighestVersion(1);
76 policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
77 policyAdapter.setOnapName("MSO");
79 //rainy day attributes
80 attributeMap.put("ServiceType", "S");
81 attributeMap.put("VNFType", "V");
82 attributeMap.put("BB_ID", "testBB");
83 attributeMap.put("WorkStep", "1");
85 dynamicRuleAlgorithmLabels.add("test1");
86 dynamicRuleAlgorithmField1.add("testField1");
87 dynamicRuleAlgorithmCombo.add("testruleCombo");
88 dynamicRuleAlgorithmField2.add("testField2");
90 policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
91 policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
92 policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
93 policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
94 policyAdapter.setDynamicVariableList(dynamicVariableList);
95 policyAdapter.setDynamicSettingsMap(settingsMap);
96 policyAdapter.setDataTypeList(dataTypeList);
98 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
99 policyAdapter.setRainydayMap(treatmentMap);
100 policyAdapter.setRainyday(rainyday);
102 component = new DecisionPolicy(policyAdapter, null);
104 logger.info("setUp: exit");
108 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
111 public void testSavePolicies() {
112 DecisionPolicy mockDecision = Mockito.mock(component.getClass());
114 Map<String, String> successMap = new HashMap<>();
115 successMap.put("success", "success");
118 when(mockDecision.savePolicies()).thenReturn(successMap);
119 successMap = mockDecision.savePolicies();
120 } catch (Exception e) {
124 assertEquals(successMap.get("success"),"success");
128 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
131 public void testPrepareToSaveRainyDay() {
132 logger.debug("test PrepareToSave Policy: enter");
133 policyAdapter.setRuleProvider("Rainy_Day");
134 component = new DecisionPolicy(policyAdapter, null);
135 boolean response = false;
138 response = component.prepareToSave();
139 } catch (Exception e) {
140 logger.error("Exception Occured"+e);
142 assertTrue(response);