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;
28 import java.io.FileInputStream;
29 import java.text.SimpleDateFormat;
30 import java.util.Arrays;
31 import java.util.Date;
32 import java.util.List;
33 import java.util.Properties;
34 import java.util.UUID;
36 import org.junit.AfterClass;
37 import org.junit.Before;
38 import org.junit.BeforeClass;
39 import org.junit.Test;
40 import org.onap.policy.api.PolicyConfigType;
41 import org.onap.policy.api.PolicyException;
42 import org.onap.policy.api.PolicyParameters;
44 public class OptimizationPolicyServiceTest {
46 OptimizationPolicyService service = null;
49 public static void setUpBeforeClass() throws Exception {
50 Properties prop = new Properties();
51 prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
52 String succeeded = prop.getProperty("xacml.rest.pap.url");
53 List<String> paps = Arrays.asList(succeeded.split(","));
54 PAPServices.setPaps(paps);
55 PAPServices.setJunit(true);
59 public void setUp() throws Exception {
60 PolicyParameters policyParameters = new PolicyParameters();
61 policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
62 policyParameters.setPolicyName("Test.testOOFPolicy");
63 policyParameters.setOnapName("OOF");
64 policyParameters.setRequestID(UUID.randomUUID());
65 SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
66 Date date = dateformat3.parse("15/10/2016");
67 policyParameters.setTtlDate(date);
68 policyParameters.setGuard(true);
69 policyParameters.setRiskLevel("5");
70 policyParameters.setRiskType("TEST");
71 policyParameters.setConfigBody("{\"optimization\":\"test\"}");
72 String policyName = "testOOFPolicy";
73 String policyScope = "Test";
74 service = new OptimizationPolicyService(policyName, policyScope, policyParameters, date.toString());
78 public static void tearDownAfterClass() {
79 PAPServices.setPaps(null);
80 PAPServices.setJunit(false);
84 public final void testOptimizationPolicyService() {
85 assertNotNull(service);
89 public final void testGetMessage() {
90 String message = service.getMessage();
95 public final void testGetResult() throws PolicyException {
96 String result = service.getResult(false);
97 assertEquals("success",result);