b93cca36d4576bfb40e61380e0762d50a7bbccad
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / components / ActionPolicyTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
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
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.*;
23 import static org.mockito.Mockito.when;
24
25 import java.util.HashMap;
26 import java.util.LinkedList;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.UUID;
30
31 import org.junit.After;
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
39 import com.att.research.xacml.util.XACMLProperties;
40
41
42 public class ActionPolicyTest {
43         
44         private static Logger logger = FlexLogger.getLogger(ActionPolicyTest.class);
45         PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
46         List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
47         List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
48         List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
49         List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
50         Map<String, String> attributeMap = new HashMap<>();
51         ActionPolicy component = null;
52
53
54         /**
55          * @throws java.lang.Exception
56          */
57         @Before
58         public void setUp() throws Exception {
59                 logger.info("setUp: Entering");
60                 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"src/test/resources/xacml.pap.properties");
61
62                 dynamicRuleAlgorithmLabels.add("test");
63                 dynamicRuleAlgorithmField1.add("testField1");
64                 dynamicRuleAlgorithmCombo.add("testCombo");
65                 dynamicRuleAlgorithmField2.add("testField2");
66                 
67                 policyAdapter.setPolicyName("Test.Action_junitTest");
68                 policyAdapter.setPolicyDescription("test");
69                 policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
70                 policyAdapter.setPolicyType("Action");
71                 policyAdapter.setEditPolicy(false);
72                 policyAdapter.setDomainDir("src/test/resources/client.properties");
73                 policyAdapter.setDomain("Test");
74                 policyAdapter.setNewFileName("Test.Action_junitTest.1.xml");
75                 policyAdapter.setHighestVersion(1);
76                 policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
77                 
78                 policyAdapter.setActionDictHeader("");
79                 policyAdapter.setActionDictType("REST");
80                 policyAdapter.setActionDictUrl("onap.org");
81                 policyAdapter.setActionDictMethod("GET");
82                 policyAdapter.setActionAttribute("test");
83                 policyAdapter.setActionBody("test");
84                 
85                 policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
86                 policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
87                 policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
88                 policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
89                 
90                 attributeMap.put("java", "test");
91                 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
92                 
93                 component = new ActionPolicy(policyAdapter);
94
95         logger.info("setUp: exit");
96         }
97
98         /**
99          * @throws java.lang.Exception
100          */
101         @After
102         public void tearDown() throws Exception {
103         }
104
105 /*      *//**
106          * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#savePolicies()}.
107          */
108         @Test
109         public void testSavePolicies() {
110         ActionPolicy mockAction = Mockito.mock(component.getClass());
111                 
112         Map<String, String> successMap = new HashMap<>();
113         
114                 successMap.put("success", "success");
115
116         try {
117                 when(mockAction.savePolicies()).thenReturn(successMap);
118                 successMap = mockAction.savePolicies();
119                 } catch (Exception e) {
120                         logger.error("Exception Occured"+e);
121                 }
122                 assertEquals(successMap.get("success"),"success");              
123         }
124
125         /**
126          * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#prepareToSave()}.
127          */
128         @Test
129         public void testPrepareToSave() {
130                 logger.debug("test PrepareToSave Policy: enter");
131                 boolean response = true;
132                 
133                 try {
134                         response = component.prepareToSave();
135                 } catch (Exception e) {
136                         logger.error("Exception Occured"+e);
137                 }
138                 assertTrue(response);   
139                 
140         }
141
142 }