Add PAP Policy parameter builder xacml policy
[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",
64                 "policyType=Config"}, UUID.randomUUID(), "Config");
65         assertEquals("success", response);
66     }
67
68     @Test
69     public final void testGetActiveVersion() {
70         String activeVersion = papServices.getActiveVersion("test", "Config_", "test.testpolicy", "Config",
71                 UUID.randomUUID());
72         assertNull(activeVersion);
73     }
74
75     @Test
76     public final void testPushPolicy() throws PolicyException {
77         StdPDPPolicy selectedPolicy = papServices.pushPolicy("test", "Config_", "test.testpolicy", "Config", "default"
78                 , UUID.randomUUID());
79         assertNull(selectedPolicy);
80     }
81
82 }