Modify ONAP PAP REST classes basic checkstyle
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / components / DecisionPolicyTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.policy.pap.xacml.rest.components;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.Mockito.when;
25
26 import java.util.HashMap;
27 import java.util.LinkedList;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.UUID;
31
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;
39
40 import com.att.research.xacml.util.XACMLProperties;
41
42 public class DecisionPolicyTest {
43
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;
59
60     /**
61      * @throws java.lang.Exception
62      */
63     @Before
64     public void setUp() throws Exception {
65         logger.info("setUp: Entering");
66         System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
67
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");
78
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");
84
85         dynamicRuleAlgorithmLabels.add("test1");
86         dynamicRuleAlgorithmField1.add("testField1");
87         dynamicRuleAlgorithmCombo.add("testruleCombo");
88         dynamicRuleAlgorithmField2.add("testField2");
89
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);
97
98         policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
99         policyAdapter.setRainydayMap(treatmentMap);
100         policyAdapter.setRainyday(rainyday);
101
102         component = new DecisionPolicy(policyAdapter, null);
103
104         logger.info("setUp: exit");
105     }
106
107     /**
108      * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#savePolicies()}.
109      */
110     @Test
111     public void testSavePolicies() {
112         DecisionPolicy mockDecision = Mockito.mock(component.getClass());
113
114         Map<String, String> successMap = new HashMap<>();
115         successMap.put("success", "success");
116
117         try {
118             when(mockDecision.savePolicies()).thenReturn(successMap);
119             successMap = mockDecision.savePolicies();
120         } catch (Exception e) {
121             e.printStackTrace();
122         }
123
124         assertEquals(successMap.get("success"),"success");
125     }
126
127     /**
128      * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy#prepareToSave()}.
129      */
130     @Test
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;
136
137         try {
138             response = component.prepareToSave();
139         } catch (Exception e) {
140             logger.error("Exception Occured"+e);
141         }
142         assertTrue(response);
143     }
144 }