diff options
author | lapentafd <francesco.lapenta@est.tech> | 2023-01-30 11:08:24 +0000 |
---|---|---|
committer | lapentafd <francesco.lapenta@est.tech> | 2023-01-30 11:38:17 +0000 |
commit | 1b5c2ceafbe9b62e6c697db63f36d2b965402067 (patch) | |
tree | 369a7662489ed1cb3560c247d86f0d1ec88ac5d0 /main/src/test/java | |
parent | 179fd9a931127160fb08aca517083de59c3e0c73 (diff) |
Adding PAP contract tests
Adding Contract tests, verifying the stubbed implementation.
Fixing name in application-stub.yaml
Issue-ID: POLICY-4534
Change-Id: I03d8b37ba2f57aa03ee814924b4e52dd0c643772
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'main/src/test/java')
-rw-r--r-- | main/src/test/java/org/onap/policy/pap/contract/PapContractTest.java | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/contract/PapContractTest.java b/main/src/test/java/org/onap/policy/pap/contract/PapContractTest.java new file mode 100644 index 00000000..f2440381 --- /dev/null +++ b/main/src/test/java/org/onap/policy/pap/contract/PapContractTest.java @@ -0,0 +1,104 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.pap.contract; + +import static org.junit.Assert.assertEquals; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.junit.Test; +import org.onap.policy.models.pdp.concepts.PdpGroups; +import org.onap.policy.pap.main.rest.CommonPapRestServer; +import org.springframework.test.context.ActiveProfiles; + +@ActiveProfiles({ "test", "stub" }) +public class PapContractTest extends CommonPapRestServer { + + @Test + public void testStubsHealthcheck() throws Exception { + checkStubJsonGet("healthcheck"); + checkStubJsonGet("pdps/healthcheck"); + checkStubJsonGet("components/healthcheck"); + } + + @Test + public void testStubsStatistics() throws Exception { + checkStubJsonGet("pdps/statistics"); + checkStubJsonGet("pdps/statistics/group"); + checkStubJsonGet("pdps/statistics/group/type"); + checkStubJsonGet("pdps/statistics/group/type/pdp"); + checkStubJsonGet("statistics"); + } + + @Test + public void testStubsPolicies() throws Exception { + checkStubJsonGet("policies/audit"); + checkStubJsonGet("policies/audit/group"); + checkStubJsonGet("policies/audit/group/name/version"); + checkStubJsonGet("policies/audit/name,version"); + checkStubJsonGet("policies/deployed"); + checkStubJsonGet("policies/deployed/name"); + checkStubJsonGet("policies/deployed/name/version"); + checkStubJsonGet("policies/status"); + checkStubJsonGet("policies/status/group"); + checkStubJsonGet("policies/status/group/name"); + checkStubJsonGet("policies/status/group/name/version"); + } + + @Test + public void testStubsPdps() throws Exception { + checkStubJsonGet("pdps"); + + checkStubJsonPost("pdps/groups/batch"); + checkStubJsonPost("pdps/deployments/batch"); + checkStubJsonPost("pdps/policies"); + + checkStubJsonPut("pdps/groups/my-name?state=ACTIVE"); + + checkStubJsonDelete("pdps/groups/name"); + checkStubJsonDelete("pdps/policies/name"); + checkStubJsonDelete("pdps/policies/name/versions/version"); + } + + + private void checkStubJsonGet(String url) throws Exception { + var response = super.sendRequest(url); + assertEquals(Response.Status.OK.getStatusCode(), response.get().getStatus()); + } + + private void checkStubJsonPost(String url) throws Exception { + var response = super.sendRequest(url); + PdpGroups groups = new PdpGroups(); + assertEquals(Response.Status.OK.getStatusCode(), response + .post(Entity.entity(groups, MediaType.APPLICATION_JSON)) + .getStatus()); + } + + private void checkStubJsonPut(String url) throws Exception { + var response = super.sendRequest(url); + assertEquals(Response.Status.OK.getStatusCode(), response.put(Entity.json("")).getStatus()); + } + + private void checkStubJsonDelete(String url) throws Exception { + var response = super.sendRequest(url); + assertEquals(Response.Status.OK.getStatusCode(), response.delete().getStatus()); + } + +} |