79ca2e6465a65bf473346357ff61a973bd794037
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / api / services / OptimizationPolicyServiceTest.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.List;
29 import java.util.Properties;
30 import java.util.UUID;
31
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.api.PolicyConfigType;
36 import org.onap.policy.api.PolicyException;
37 import org.onap.policy.api.PolicyParameters;
38
39 public class OptimizationPolicyServiceTest {
40
41         OptimizationPolicyService service = null;
42
43         @Before
44         public void setUp() throws Exception {
45                 Properties prop = new Properties();
46                 prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
47                 String succeeded = prop.getProperty("xacml.rest.pap.url");
48                 List<String> paps = Arrays.asList(succeeded.split(","));
49                 PAPServices.setPaps(paps);
50                 PAPServices.setJunit(true);
51                 prop.clear();
52                 
53                 PolicyParameters policyParameters = new PolicyParameters();
54         policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
55         policyParameters.setPolicyName("Test.testOOFPolicy");
56                 policyParameters.setOnapName("OOF");
57         policyParameters.setRequestID(UUID.randomUUID());
58         SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
59                 Date date = dateformat3.parse("15/10/2016");
60                 policyParameters.setTtlDate(date);
61                 policyParameters.setGuard(true);
62                 policyParameters.setRiskLevel("5");
63                 policyParameters.setRiskType("TEST");
64                 policyParameters.setConfigBody("{\"optimization\":\"test\"}");
65                 String policyName = "testOOFPolicy";
66                 String policyScope = "Test";
67                 service = new OptimizationPolicyService(policyName, policyScope, policyParameters, date.toString());
68         }
69
70         @After
71         public void tearDown() throws Exception {
72         }
73
74         @Test
75         public final void testOptimizationPolicyService() {
76                 assertNotNull(service);
77         }
78
79         @Test
80         public final void testGetMessage() {
81                 String message = service.getMessage();
82                 assertNull(message);
83         }
84
85         @Test
86         public final void testGetResult() throws PolicyException {
87                 String result = service.getResult(false);
88                 assertEquals("success",result);
89         }
90
91 }