Improve ONAP-PDP-REST JUnit test case independency
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / api / services / BRMSParamPolicyServiceTest.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.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.io.FileInputStream;
30 import java.text.SimpleDateFormat;
31 import java.util.Arrays;
32 import java.util.Date;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Properties;
37 import java.util.UUID;
38
39 import org.junit.AfterClass;
40 import org.junit.Before;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43 import org.onap.policy.api.AttributeType;
44 import org.onap.policy.api.PolicyConfigType;
45 import org.onap.policy.api.PolicyException;
46 import org.onap.policy.api.PolicyParameters;
47
48 public class BRMSParamPolicyServiceTest {
49
50         BRMSParamPolicyService service = null;
51
52         @BeforeClass
53         public static void setUpBeforeClass() throws Exception {
54                 Properties prop = new Properties();
55                 prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
56                 String succeeded = prop.getProperty("xacml.rest.pap.url");
57                 List<String> paps = Arrays.asList(succeeded.split(","));
58                 PAPServices.setPaps(paps);
59                 PAPServices.setJunit(true);
60         }
61
62         @Before
63         public void setUp() throws Exception {
64                 PolicyParameters policyParameters = new PolicyParameters();
65         policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
66         policyParameters.setPolicyName("Test.testBRMSPolicy");
67         policyParameters.setRequestID(UUID.randomUUID());
68         SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
69                 Date date = dateformat3.parse("15/10/2016");
70                 policyParameters.setTtlDate(date);
71                 policyParameters.setGuard(true);
72                 policyParameters.setRiskLevel("5");
73                 policyParameters.setRiskType("TEST");
74
75         Map<String, String> ruleAttributes = new HashMap<>();
76         ruleAttributes.put("templateName", "Sample");
77         ruleAttributes.put("controller", "default");
78         ruleAttributes.put("SamPoll", "300");
79         ruleAttributes.put("value", "abcd");
80         Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
81         attributes.put(AttributeType.RULE, ruleAttributes);
82         policyParameters.setAttributes(attributes);
83
84                 String policyName = "testBRMSPolicy";
85                 String policyScope = "Test";
86                 service = new BRMSParamPolicyService(policyName, policyScope, policyParameters, date.toString());
87         }
88
89         @AfterClass
90         public static void tearDownAfterClass() {
91                 PAPServices.setPaps(null);
92                 PAPServices.setJunit(false);
93         }
94
95         @Test
96         public final void testFirewallPolicyService() {
97                 assertNotNull(service);
98         }
99
100         @Test
101         public final void testGetValidation() {
102                 assertTrue(service.getValidation());
103         }
104
105         @Test
106         public final void testGetMessage() {
107                 String message = service.getMessage();
108                 assertNull(message);
109         }
110
111         @Test
112         public final void testGetResult() throws PolicyException {
113                 service.getValidation();
114                 String result = service.getResult(false);
115                 assertEquals("success",result);
116         }
117
118
119 }