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