2 * ============LICENSE_START=======================================================
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
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.*;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.Mockito.when;
26 import java.util.HashMap;
29 import java.util.UUID;
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;
39 import com.att.research.xacml.util.XACMLProperties;
42 public class FirewallConfigPolicyTest {
44 private static Logger logger = FlexLogger.getLogger(FirewallConfigPolicyTest.class);
45 PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
46 Map<String, String> attributeMap = new HashMap<>();
47 FirewallConfigPolicy component = null;
48 FirewallConfigPolicy mockFWConfig = null;
52 * @throws java.lang.Exception
55 public void setUp() throws Exception {
56 logger.info("setup: enter");
57 System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME,"xacml.pap.properties");
59 policyAdapter.setPolicyName("FWjunitTest");
60 policyAdapter.setPolicyDescription("test");
61 policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
62 policyAdapter.setPolicyType("Config");
63 policyAdapter.setConfigPolicyType("Firewall Config");
64 policyAdapter.setEditPolicy(false);
65 policyAdapter.setDomainDir("src/test/resources/client.properties");
66 policyAdapter.setDomain("Test");
67 policyAdapter.setNewFileName("Test.Config_FW_junitTest.1.xml");
68 policyAdapter.setHighestVersion(1);
69 policyAdapter.setVersion(String.valueOf(1));
70 policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
71 policyAdapter.setRuleID("");
72 policyAdapter.setConfigName("testname");
73 policyAdapter.setGuard("True");
74 policyAdapter.setRiskLevel("3");
75 policyAdapter.setRiskType("RiskTest");
76 policyAdapter.setSecurityZone("CraigSecurityZone");
77 policyAdapter.setUserId("API");
79 attributeMap.put("testJunits", "test");
80 policyAdapter.setDynamicFieldConfigAttributes(attributeMap);
82 component = new FirewallConfigPolicy(policyAdapter);
83 mockFWConfig = Mockito.mock(FirewallConfigPolicy.class);
84 logger.info("setUp: exit");
89 * @throws java.lang.Exception
92 public void tearDown() throws Exception {
96 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy#savePolicies()}.
99 public void testSavePolicies() {
100 Map<String, String> successMap = new HashMap<>();
101 successMap.put("success", "success");
103 when(mockFWConfig.savePolicies()).thenReturn(successMap);
104 successMap = mockFWConfig.savePolicies();
105 } catch (Exception e) {
106 logger.error("Exception Occured"+e);
111 * Test method for {@link org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy#prepareToSave()}.
114 public void testPrepareToSave() {
115 logger.debug("test prepareToSave Policy: enter");
117 boolean response = false;
119 when(mockFWConfig.prepareToSave()).thenReturn(true);
120 response = mockFWConfig.prepareToSave();
121 } catch (Exception e) {
122 logger.error("Exception Occured"+e);
124 assertTrue(response);