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