Adding PAP contract tests 64/133064/1
authorlapentafd <francesco.lapenta@est.tech>
Mon, 30 Jan 2023 11:08:24 +0000 (11:08 +0000)
committerlapentafd <francesco.lapenta@est.tech>
Mon, 30 Jan 2023 11:38:17 +0000 (11:38 +0000)
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>
main/src/main/resources/application-stub.yaml
main/src/test/java/org/onap/policy/pap/contract/PapContractTest.java [new file with mode: 0644]

index b509fd6..a0b7f00 100644 (file)
@@ -1,3 +1,3 @@
 spring:
     application:
-        name: "policy-api-stub"
\ No newline at end of file
+        name: "policy-pap-stub"
\ No newline at end of file
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 (file)
index 0000000..f244038
--- /dev/null
@@ -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());
+    }
+
+}