Policy API Junit tests
[policy/api.git] / main / src / test / java / org / onap / policy / api / main / rest / TestApiRestServer.java
index 6d49efd..665616b 100644 (file)
@@ -53,8 +53,9 @@ import org.junit.After;
 import org.junit.Test;
 import org.onap.policy.api.main.exception.PolicyApiException;
 import org.onap.policy.api.main.parameters.CommonTestData;
-import org.onap.policy.api.main.parameters.RestServerParameters;
 import org.onap.policy.api.main.startstop.Main;
+import org.onap.policy.common.endpoints.http.server.RestServer;
+import org.onap.policy.common.endpoints.parameters.RestServerParameters;
 import org.onap.policy.common.endpoints.report.HealthCheckReport;
 import org.onap.policy.common.gson.GsonMessageBodyHandler;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -136,10 +137,23 @@ public class TestApiRestServer {
     private static final String OPS_POLICIES_VFIREWALL_VERSION = "policytypes/"
         + "onap.policies.controlloop.Guard/versions/1.0.0/policies/operational.modifyconfig/versions/1";
 
+    private static final String GET_DEPLOYED_VERSION_OF_POLICY =
+            "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app/versions/"
+        + "1.0.0/policies/onap.restart.tca/versions/deployed";
+    private static final String GET_LATEST_VERSION_OF_OPERATIONAL_POLICY =
+            "policytypes/onap.policies.controlloop.Operational/versions/"
+            + "1.0.0/policies/operational.scaleout/versions/latest";
+    private static final String GET_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY =
+            "policytypes/onap.policies.controlloop.Operational/versions/"
+            + "1.0.0/policies/operational.scaleout/versions/3";
+    private static final String DEL_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY =
+            "policytypes/onap.policies.controlloop.Operational/versions/1.0.0/"
+                    + "policies/operational.scaleout/versions/1";
+
     private static final String KEYSTORE = System.getProperty("user.dir") + "/src/test/resources/ssl/policy-keystore";
     private static final CommonTestData COMMON_TEST_DATA = new CommonTestData();
     private Main main;
-    private ApiRestServer restServer;
+    private RestServer restServer;
     private StandardCoder standardCoder = new StandardCoder();
     private int port;
 
@@ -199,14 +213,14 @@ public class TestApiRestServer {
         port = NetworkUtil.allocPort();
         final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
         restServerParams.setName(CommonTestData.API_GROUP_NAME);
-        restServer = new ApiRestServer(restServerParams);
+        restServer = new RestServer(restServerParams, null, ApiRestController.class);
         try {
             restServer.start();
             final Invocation.Builder invocationBuilder = sendHttpRequest(HEALTHCHECK_ENDPOINT);
             final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
             validateHealthCheckReport(NAME, SELF, false, 500, NOT_ALIVE, report);
             assertTrue(restServer.isAlive());
-            assertTrue(restServer.toString().startsWith("ApiRestServer [servers="));
+            assertTrue(restServer.toString().startsWith("RestServer [servers="));
         } catch (final Exception exp) {
             LOGGER.error("testHealthCheckFailure failed", exp);
             fail("Test should not throw an exception");
@@ -252,7 +266,7 @@ public class TestApiRestServer {
         port = NetworkUtil.allocPort();
         final RestServerParameters restServerParams = new CommonTestData().getRestServerParameters(false, port);
         restServerParams.setName(CommonTestData.API_GROUP_NAME);
-        restServer = new ApiRestServer(restServerParams);
+        restServer = new RestServer(restServerParams, null, ApiRestController.class);
         try {
             restServer.start();
             final Invocation.Builder invocationBuilder = sendHttpRequest(STATISTICS_ENDPOINT);
@@ -620,6 +634,42 @@ public class TestApiRestServer {
         }).doesNotThrowAnyException();
     }
 
+    @Test
+    public void testGetDeployedVersionsOfPolicy() {
+        assertThatCode(() -> {
+            main = startApiService(true);
+            Response rawResponse = readResource(GET_DEPLOYED_VERSION_OF_POLICY, true);
+            assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+        }).doesNotThrowAnyException();
+    }
+
+    @Test
+    public void testGetLatestVersionOfOperationalPolicy() {
+        assertThatCode(() -> {
+            main = startApiService(true);
+            Response rawResponse = readResource(GET_LATEST_VERSION_OF_OPERATIONAL_POLICY, true);
+            assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+        }).doesNotThrowAnyException();
+    }
+
+    @Test
+    public void testGetSpecificVersionOfOperationalPolicy() {
+        assertThatCode(() -> {
+            main = startApiService(true);
+            Response rawResponse = readResource(GET_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY, true);
+            assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+        }).doesNotThrowAnyException();
+    }
+
+    @Test
+    public void testDeleteSpecificVersionOfOperationalPolicy() {
+        assertThatCode(() -> {
+            main = startApiService(true);
+            Response rawResponse = deleteResource(DEL_SPECIFIC_VERSION_OF_OPERATIONAL_POLICY, true);
+            assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
+        }).doesNotThrowAnyException();
+    }
+
     private Response createResource(String endpoint, String resourceName, boolean http) throws Exception {
 
         ToscaServiceTemplate rawServiceTemplate = standardCoder.decode(