Reformat ONAP-PDP-REST test cases
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / api / services / OptimizationPolicyServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP-REST
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22 package org.onap.policy.pdp.rest.api.services;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import java.io.FileInputStream;
28 import java.text.SimpleDateFormat;
29 import java.util.Arrays;
30 import java.util.Date;
31 import java.util.List;
32 import java.util.Properties;
33 import java.util.UUID;
34 import org.junit.AfterClass;
35 import org.junit.Before;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
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 OptimizationPolicyServiceTest {
43
44     OptimizationPolicyService service = null;
45
46     @BeforeClass
47     public static void setUpBeforeClass() 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
56     @Before
57     public void setUp() throws Exception {
58         PolicyParameters policyParameters = new PolicyParameters();
59         policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
60         policyParameters.setPolicyName("Test.testOOFPolicy");
61         policyParameters.setOnapName("OOF");
62         policyParameters.setRequestID(UUID.randomUUID());
63         SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
64         Date date = dateformat3.parse("15/10/2016");
65         policyParameters.setTtlDate(date);
66         policyParameters.setGuard(true);
67         policyParameters.setRiskLevel("5");
68         policyParameters.setRiskType("TEST");
69         policyParameters.setConfigBody("{\"optimization\":\"test\"}");
70         String policyName = "testOOFPolicy";
71         String policyScope = "Test";
72         service = new OptimizationPolicyService(policyName, policyScope, policyParameters, date.toString());
73     }
74
75     @AfterClass
76     public static void tearDownAfterClass() {
77         PAPServices.setPaps(null);
78         PAPServices.setJunit(false);
79     }
80
81     @Test
82     public final void testOptimizationPolicyService() {
83         assertNotNull(service);
84     }
85
86     @Test
87     public final void testGetMessage() {
88         String message = service.getMessage();
89         assertNull(message);
90     }
91
92     @Test
93     public final void testGetResult() throws PolicyException {
94         String result = service.getResult(false);
95         assertEquals("success", result);
96     }
97 }