2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
7 * Modifications Copyright (C) 2022-2023 Nordix Foundation.
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.policy.pap.main.rest.e2e;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
28 import jakarta.ws.rs.client.Invocation;
29 import jakarta.ws.rs.core.GenericType;
30 import jakarta.ws.rs.core.Response;
31 import java.util.List;
32 import org.junit.jupiter.api.BeforeEach;
33 import org.junit.jupiter.api.Test;
34 import org.onap.policy.models.pap.concepts.PolicyStatus;
35 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
36 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
38 class PolicyStatusTest extends End2EndBase {
39 private static final String POLICY_NAME = "onap.restart.tca";
40 private static final String POLICY_TYPE_NAME = "onap.policies.monitoring.cdap.tca.hi.lo.app";
41 private static final String VERSION = "1.0.0";
42 private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
43 private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status";
47 public void setUp() throws Exception {
48 addPdpPolicyStatus("policyStatus.json");
53 void testQueryAllDeployedPolicies() throws Exception {
54 Invocation.Builder invocationBuilder = sendRequest(POLICY_STATUS_ENDPOINT);
55 Response rawresp = invocationBuilder.get();
56 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
58 List<PolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
59 assertEquals(1, resp.size());
60 checkAssertions(resp.get(0));
64 void testQueryDeployedPolicies() throws Exception {
65 String uri = POLICY_STATUS_ENDPOINT + "/onap.restart.tca";
67 Invocation.Builder invocationBuilder = sendRequest(uri);
68 Response rawresp = invocationBuilder.get();
69 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
71 List<PolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
72 assertEquals(1, resp.size());
73 checkAssertions(resp.get(0));
77 void testQueryDeployedPolicy() throws Exception {
78 String uri = POLICY_STATUS_ENDPOINT + "/onap.restart.tca/1.0.0";
80 Invocation.Builder invocationBuilder = sendRequest(uri);
81 Response rawresp = invocationBuilder.get();
82 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
84 PolicyStatus status = rawresp.readEntity(PolicyStatus.class);
85 checkAssertions(status);
89 void testGetStatusOfAllDeployedPolicies() throws Exception {
90 Invocation.Builder invocationBuilder = sendRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT);
91 Response rawresp = invocationBuilder.get();
92 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
94 List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
95 assertEquals(1, resp.size());
96 checkAssertionsForDeploymentStatus(resp.get(0));
100 void testGetStatusOfDeployedPolicies() throws Exception {
101 String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca";
103 Invocation.Builder invocationBuilder = sendRequest(uri);
104 Response rawresp = invocationBuilder.get();
105 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
107 List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
108 assertEquals(1, resp.size());
109 checkAssertionsForDeploymentStatus(resp.get(0));
113 void testGetStatusOfDeployedPolicy() throws Exception {
114 String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca/1.0.0";
116 Invocation.Builder invocationBuilder = sendRequest(uri);
117 Response rawresp = invocationBuilder.get();
118 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
120 PdpPolicyStatus status = rawresp.readEntity(PdpPolicyStatus.class);
121 checkAssertionsForDeploymentStatus(status);
125 private void checkAssertions(PolicyStatus status) {
126 assertEquals(POLICY_NAME, status.getPolicyId());
127 assertEquals(VERSION, status.getPolicyVersion());
128 assertEquals(POLICY_TYPE_NAME, status.getPolicyTypeId());
129 assertEquals(VERSION, status.getPolicyTypeVersion());
130 assertEquals(0, status.getFailureCount());
131 assertEquals(1, status.getIncompleteCount());
132 assertEquals(0, status.getSuccessCount());
135 private void checkAssertionsForDeploymentStatus(PdpPolicyStatus status) {
136 assertEquals(POLICY_NAME, status.getPolicy().getName());
137 assertEquals(VERSION, status.getPolicy().getVersion());
138 assertEquals(POLICY_TYPE_NAME, status.getPolicyType().getName());
139 assertEquals(VERSION, status.getPolicyType().getVersion());
140 assertEquals("policyStatus", status.getPdpGroup());
141 assertEquals("pdpB_1", status.getPdpId());
142 assertEquals("pdpTypeB", status.getPdpType());
143 assertEquals(State.WAITING, status.getState());
144 assertTrue(status.isDeploy());