2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.pdp.rest.api.services;
22 import static org.junit.Assert.*;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import java.io.FileInputStream;
27 import java.text.SimpleDateFormat;
28 import java.util.Arrays;
29 import java.util.Date;
30 import java.util.List;
31 import java.util.Properties;
32 import java.util.UUID;
33 import org.onap.policy.api.PolicyConfigType;
34 import org.onap.policy.api.PolicyException;
35 import org.onap.policy.api.PolicyParameters;
37 public class FirewallPolicyServiceTest {
39 FirewallPolicyService firewallPolicyService = null;
43 public void setUp() throws Exception {
44 Properties prop = new Properties();
45 prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
46 String succeeded = prop.getProperty("xacml.rest.pap.url");
47 List<String> paps = Arrays.asList(succeeded.split(","));
48 PAPServices.setPaps(paps);
49 PAPServices.setJunit(true);
51 PolicyParameters policyParameters = new PolicyParameters();
52 policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); //required
53 policyParameters.setPolicyName("Test.testFWPolicy"); //required
54 policyParameters.setRequestID(UUID.randomUUID());
55 SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
56 Date date = dateformat3.parse("15/10/2016");
57 policyParameters.setTtlDate(date);
58 policyParameters.setGuard(true);
59 policyParameters.setRiskLevel("5");
60 policyParameters.setRiskType("TEST");
61 policyParameters.setConfigBody("{\"configName\":\"test\"}");
62 String policyName = "testFWPolicy";
63 String policyScope = "Test";
64 firewallPolicyService = new FirewallPolicyService(policyName, policyScope, policyParameters, date.toString());
68 public void tearDown() throws Exception {
69 PAPServices.setPaps(null);
70 PAPServices.setJunit(false);
74 public final void testFirewallPolicyService() {
75 assertNotNull(firewallPolicyService);
79 public final void testGetValidation() {
80 assertTrue(firewallPolicyService.getValidation());
84 public final void testGetMessage() {
85 String message = firewallPolicyService.getMessage();
90 public final void testGetResult() throws PolicyException {
91 firewallPolicyService.getValidation();
92 String result = firewallPolicyService.getResult(false);
93 assertEquals("success",result);