93fde841d6f52039650b81172191aff7780fd87e
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / api / services / PAPServicesTest.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.util.Arrays;
26 import java.util.List;
27 import java.util.Properties;
28 import java.util.UUID;
29
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.policy.api.PolicyException;
34 import org.onap.policy.xacml.std.pap.StdPAPPolicy;
35 import org.onap.policy.xacml.std.pap.StdPDPPolicy;
36
37 public class PAPServicesTest {
38
39         PAPServices papServices = null;
40
41         @Before
42         public void setUp() throws Exception {
43                 PAPServices.setJunit(true);
44                 Properties prop = new Properties();
45                 prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
46                 String succeeded = prop.getProperty("xacml.rest.pap.url");
47                 List<String> paps = Arrays.asList(succeeded.split(","));
48                 PAPServices.setPaps(paps);
49                 papServices = new PAPServices();
50
51         }
52
53         @After
54         public void tearDown() throws Exception {
55                 PAPServices.setPaps(null);
56                 PAPServices.setJunit(false);
57         }
58
59         @Test
60         public final void testCallPAP() throws PolicyException {
61                 StdPAPPolicy newPAPPolicy = new StdPAPPolicy();
62                 String response = null;
63                 response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation=create", "apiflag=api", "policyType=Config"}, UUID.randomUUID(), "Config");
64                 assertEquals("success",response);
65         }
66
67         @Test
68         public final void testGetActiveVersion() {
69             String activeVersion = papServices.getActiveVersion("test", "Config_", "test.testpolicy", "Config", UUID.randomUUID());
70             assertNull(activeVersion);
71         }
72
73         @Test
74         public final void testPushPolicy() throws PolicyException {
75         StdPDPPolicy selectedPolicy = papServices.pushPolicy("test", "Config_", "test.testpolicy", "Config", "default", UUID.randomUUID());
76         assertNull(selectedPolicy);
77         }
78
79 }