Reformat ONAP-PDP-REST test cases
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / api / services / FirewallPolicyServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP-REST
4  * ================================================================================
5  * Copyright (C) 2018 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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22 package org.onap.policy.pdp.rest.api.services;
23
24 import static org.junit.Assert.*;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28 import java.io.FileInputStream;
29 import java.text.SimpleDateFormat;
30 import java.util.Arrays;
31 import java.util.Date;
32 import java.util.List;
33 import java.util.Properties;
34 import java.util.UUID;
35 import org.onap.policy.api.PolicyConfigType;
36 import org.onap.policy.api.PolicyException;
37 import org.onap.policy.api.PolicyParameters;
38
39 public class FirewallPolicyServiceTest {
40
41     FirewallPolicyService firewallPolicyService = null;
42
43     @Before
44     public void setUp() throws Exception {
45         Properties prop = new Properties();
46         prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
47         String succeeded = prop.getProperty("xacml.rest.pap.url");
48         List<String> paps = Arrays.asList(succeeded.split(","));
49         PAPServices.setPaps(paps);
50         PAPServices.setJunit(true);
51
52         PolicyParameters policyParameters = new PolicyParameters();
53         policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); // required
54         policyParameters.setPolicyName("Test.testFWPolicy"); // required
55         policyParameters.setRequestID(UUID.randomUUID());
56         SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
57         Date date = dateformat3.parse("15/10/2016");
58         policyParameters.setTtlDate(date);
59         policyParameters.setGuard(true);
60         policyParameters.setRiskLevel("5");
61         policyParameters.setRiskType("TEST");
62         policyParameters.setConfigBody("{\"configName\":\"test\"}");
63         String policyName = "testFWPolicy";
64         String policyScope = "Test";
65         firewallPolicyService = new FirewallPolicyService(policyName, policyScope, policyParameters, date.toString());
66     }
67
68     @After
69     public void tearDown() throws Exception {
70         PAPServices.setPaps(null);
71         PAPServices.setJunit(false);
72     }
73
74     @Test
75     public final void testFirewallPolicyService() {
76         assertNotNull(firewallPolicyService);
77     }
78
79     @Test
80     public final void testGetValidation() {
81         assertTrue(firewallPolicyService.getValidation());
82     }
83
84     @Test
85     public final void testGetMessage() {
86         String message = firewallPolicyService.getMessage();
87         assertNull(message);
88     }
89
90     @Test
91     public final void testGetResult() throws PolicyException {
92         firewallPolicyService.getValidation();
93         String result = firewallPolicyService.getResult(false);
94         assertEquals("success", result);
95     }
96 }