2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.pdp.rest.api.services;
22 import static org.junit.Assert.*;
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;
31 import java.util.Properties;
32 import java.util.UUID;
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;
42 public class BRMSParamPolicyServiceTest {
44 BRMSParamPolicyService service = null;
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.junit = true;
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");
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);
75 String policyName = "testBRMSPolicy";
76 String policyScope = "Test";
77 service = new BRMSParamPolicyService(policyName, policyScope, policyParameters, date.toString());
81 public void tearDown() throws Exception {
85 public final void testFirewallPolicyService() {
86 assertNotNull(service);
90 public final void testGetValidation() {
91 assertTrue(service.getValidation());
95 public final void testGetMessage() {
96 String message = service.getMessage();
101 public final void testGetResult() throws PolicyException {
102 service.getValidation();
103 String result = service.getResult(false);
104 assertEquals("success",result);