7b9698bbacf42ebfe0115ea7135f3ccbdec7ef72
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / contract / PapContractTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2023 Nordix Foundation.
4  * Modifications Copyright (C) 2023 Bell Canada. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.policy.pap.contract;
21
22 import static org.junit.Assert.assertEquals;
23
24 import javax.ws.rs.client.Entity;
25 import javax.ws.rs.core.MediaType;
26 import javax.ws.rs.core.Response;
27 import org.junit.Test;
28 import org.onap.policy.models.pdp.concepts.PdpGroups;
29 import org.onap.policy.pap.main.rest.CommonPapRestServer;
30 import org.springframework.test.context.ActiveProfiles;
31
32 @ActiveProfiles({ "test", "stub" })
33 public class PapContractTest extends CommonPapRestServer {
34
35     @Test
36     public void testStubsHealthcheck() throws Exception {
37         checkStubJsonGet("healthcheck");
38         checkStubJsonGet("pdps/healthcheck");
39         checkStubJsonGet("components/healthcheck");
40     }
41
42     @Test
43     public void testStubsPolicies() throws Exception {
44         checkStubJsonGet("policies/audit");
45         checkStubJsonGet("policies/audit/group");
46         checkStubJsonGet("policies/audit/group/name/version");
47         checkStubJsonGet("policies/audit/name,version");
48         checkStubJsonGet("policies/deployed");
49         checkStubJsonGet("policies/deployed/name");
50         checkStubJsonGet("policies/deployed/name/version");
51         checkStubJsonGet("policies/status");
52         checkStubJsonGet("policies/status/group");
53         checkStubJsonGet("policies/status/group/name");
54         checkStubJsonGet("policies/status/group/name/version");
55     }
56
57     @Test
58     public void testStubsPdps() throws Exception {
59         checkStubJsonGet("pdps");
60
61         checkStubJsonPost("pdps/groups/batch");
62         checkStubJsonPost("pdps/deployments/batch");
63         checkStubJsonPost("pdps/policies");
64
65         checkStubJsonPut("pdps/groups/my-name?state=ACTIVE");
66
67         checkStubJsonDelete("pdps/groups/name");
68         checkStubJsonDelete("pdps/policies/name");
69         checkStubJsonDelete("pdps/policies/name/versions/version");
70     }
71
72
73     private void checkStubJsonGet(String url) throws Exception {
74         var response = super.sendRequest(url);
75         assertEquals(Response.Status.OK.getStatusCode(), response.get().getStatus());
76     }
77
78     private void checkStubJsonPost(String url) throws Exception {
79         var response = super.sendRequest(url);
80         PdpGroups groups = new PdpGroups();
81         assertEquals(Response.Status.OK.getStatusCode(), response
82                 .post(Entity.entity(groups, MediaType.APPLICATION_JSON))
83                 .getStatus());
84     }
85
86     private void checkStubJsonPut(String url) throws Exception {
87         var response = super.sendRequest(url);
88         assertEquals(Response.Status.OK.getStatusCode(), response.put(Entity.json("")).getStatus());
89     }
90
91     private void checkStubJsonDelete(String url) throws Exception {
92         var response = super.sendRequest(url);
93         assertEquals(Response.Status.OK.getStatusCode(), response.delete().getStatus());
94     }
95
96 }