2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pap.xacml.rest.components;
25 import static org.junit.Assert.*;
26 import static org.mockito.Mockito.when;
28 import com.att.research.xacml.util.XACMLProperties;
30 import java.util.HashMap;
31 import java.util.LinkedList;
32 import java.util.List;
34 import java.util.UUID;
36 import org.junit.After;
37 import org.junit.Before;
38 import org.junit.Test;
39 import org.mockito.Mockito;
40 import org.onap.policy.common.logging.flexlogger.FlexLogger;
41 import org.onap.policy.common.logging.flexlogger.Logger;
42 import org.onap.policy.rest.adapter.PolicyRestAdapter;
44 public class ActionPolicyTest {
46 private static Logger logger = FlexLogger.getLogger(ActionPolicyTest.class);
47 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
48 List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
49 List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
50 List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
51 List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
52 Map<String, String> attributeMap = new HashMap<>();
53 ActionPolicy component = null;
56 * @throws java.lang.Exception
59 public void setUp() throws Exception {
60 logger.info("setUp: Entering");
61 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pap.properties");
63 dynamicRuleAlgorithmLabels.add("test");
64 dynamicRuleAlgorithmField1.add("testField1");
65 dynamicRuleAlgorithmCombo.add("testCombo");
66 dynamicRuleAlgorithmField2.add("testField2");
68 policyAdapter.setPolicyName("Test.Action_junitTest");
69 policyAdapter.setPolicyDescription("test");
70 policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
71 policyAdapter.setPolicyType("Action");
72 policyAdapter.setEditPolicy(false);
73 policyAdapter.setDomainDir("Test");
74 policyAdapter.setNewFileName("Test.Action_junitTest.1.xml");
75 policyAdapter.setHighestVersion(1);
76 policyAdapter.setPolicyID("urn:xacml:policy:id:" + UUID.randomUUID());
78 policyAdapter.setActionDictHeader("");
79 policyAdapter.setActionDictType("REST");
80 policyAdapter.setActionDictUrl("onap.org");
81 policyAdapter.setActionDictMethod("GET");
82 policyAdapter.setActionAttribute("test");
83 policyAdapter.setActionBody("test");
85 policyAdapter.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
86 policyAdapter.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
87 policyAdapter.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
88 policyAdapter.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
90 attributeMap.put("java", "test");
91 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
93 component = new ActionPolicy(policyAdapter, null);
95 logger.info("setUp: exit");
100 * {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#savePolicies()}.
103 public void testSavePolicies() {
104 ActionPolicy mockAction = Mockito.mock(component.getClass());
106 Map<String, String> successMap = new HashMap<>();
108 successMap.put("success", "success");
111 when(mockAction.savePolicies()).thenReturn(successMap);
112 successMap = mockAction.savePolicies();
113 } catch (Exception e) {
114 logger.error("Exception Occured" + e);
116 assertEquals(successMap.get("success"), "success");
121 * {@link org.openecomp.policy.pap.xacml.rest.components.ActionPolicy#prepareToSave()}.
124 public void testPrepareToSave() {
125 logger.debug("test PrepareToSave Policy: enter");
126 boolean response = true;
129 response = component.prepareToSave();
130 } catch (Exception e) {
131 logger.error("Exception Occured" + e);
133 assertTrue(response);