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