2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.pdp.rest.api.services;
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;
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;
46 public class BRMSParamPolicyServiceTest {
48 BRMSParamPolicyService service = null;
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);
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");
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);
82 String policyName = "testBRMSPolicy";
83 String policyScope = "Test";
84 service = new BRMSParamPolicyService(policyName, policyScope, policyParameters, date.toString());
88 public static void tearDownAfterClass() {
89 PAPServices.setPaps(null);
90 PAPServices.setJunit(false);
94 public final void testFirewallPolicyService() {
95 assertNotNull(service);
99 public final void testGetValidation() {
100 assertTrue(service.getValidation());
104 public final void testGetMessage() {
105 String message = service.getMessage();
110 public final void testGetResult() throws PolicyException {
111 service.getValidation();
112 String result = service.getResult(false);
113 assertEquals("success", result);