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