Adding deployment metrics to PAP
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / e2e / PdpGroupDeployTest.java
index 549ae20..df749a8 100644 (file)
@@ -3,6 +3,8 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +22,7 @@
 
 package org.onap.policy.pap.main.rest.e2e;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
@@ -34,7 +37,6 @@ import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
 import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
@@ -47,32 +49,23 @@ import org.onap.policy.models.pdp.concepts.DeploymentGroup;
 import org.onap.policy.models.pdp.concepts.DeploymentGroups;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.pap.main.PapConstants;
+import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1;
 
 public class PdpGroupDeployTest extends End2EndBase {
     private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch";
     private static final String DEPLOY_POLICIES_ENDPOINT = "pdps/policies";
     private static final String DEPLOY_SUBGROUP = "pdpTypeA";
 
-    /**
-     * Starts Main and adds policies to the DB.
-     *
-     * @throws Exception if an error occurs
-     */
-    @BeforeClass
-    public static void setUpBeforeClass() throws Exception {
-        End2EndBase.setUpBeforeClass();
-
-        addToscaPolicyTypes("monitoring.policy-type.yaml");
-        addToscaPolicies("monitoring.policy.yaml");
-    }
-
     /**
      * Sets up.
      */
+    @Override
     @Before
     public void setUp() throws Exception {
+        addToscaPolicyTypes("monitoring.policy-type.yaml");
+        addToscaPolicies("monitoring.policy.yaml");
         super.setUp();
 
         context = new End2EndContext();
@@ -90,7 +83,7 @@ public class PdpGroupDeployTest extends End2EndBase {
         status11.setPdpType(DEPLOY_SUBGROUP);
         status11.setPdpSubgroup(DEPLOY_SUBGROUP);
 
-        List<ToscaPolicyIdentifier> idents = Arrays.asList(new ToscaPolicyIdentifier("onap.restart.tca", "1.0.0"));
+        List<ToscaConceptIdentifier> idents = Arrays.asList(new ToscaConceptIdentifier("onap.restart.tca", "1.0.0"));
         status11.setPolicies(idents);
 
         PdpStatus status12 = new PdpStatus();
@@ -113,7 +106,7 @@ public class PdpGroupDeployTest extends End2EndBase {
         Entity<DeploymentGroups> entity = Entity.entity(groups, MediaType.APPLICATION_JSON);
         Response rawresp = invocationBuilder.post(entity);
         PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
         assertNull(resp.getErrorDetails());
 
         context.await();
@@ -124,9 +117,13 @@ public class PdpGroupDeployTest extends End2EndBase {
         // repeat - should be OK
         rawresp = invocationBuilder.post(entity);
         resp = rawresp.readEntity(PdpGroupDeployResponse.class);
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+        assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+        assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
         assertNull(resp.getErrorDetails());
 
+        assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(2);
+
         // repeat with unknown group - should fail
         DeploymentGroup group = groups.getGroups().get(0);
         group.setName("unknown-group");
@@ -147,9 +144,9 @@ public class PdpGroupDeployTest extends End2EndBase {
         status11.setPdpType(DEPLOY_SUBGROUP);
         status11.setPdpSubgroup(DEPLOY_SUBGROUP);
 
-        final ToscaPolicyIdentifier ident = new ToscaPolicyIdentifier("onap.restart.tcaB", "1.0.0");
+        final ToscaConceptIdentifier ident = new ToscaConceptIdentifier("onap.restart.tcaB", "1.0.0");
 
-        List<ToscaPolicyIdentifier> idents = Arrays.asList(ident);
+        List<ToscaConceptIdentifier> idents = Arrays.asList(ident);
         status11.setPolicies(idents);
 
         PdpStatus status12 = new PdpStatus();
@@ -173,14 +170,17 @@ public class PdpGroupDeployTest extends End2EndBase {
             notifications.add(msg);
         });
 
+        assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(0);
+
         Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
 
         PdpDeployPolicies policies = loadJsonFile("deployPoliciesReq2.json", PdpDeployPolicies.class);
         Entity<PdpDeployPolicies> entity = Entity.entity(policies, MediaType.APPLICATION_JSON);
         Response rawresp = invocationBuilder.post(entity);
         PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
-        System.out.println(resp.getErrorDetails());
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+        assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+        assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
         assertNull(resp.getErrorDetails());
 
         context.await();
@@ -205,7 +205,9 @@ public class PdpGroupDeployTest extends End2EndBase {
         // repeat - should be OK
         rawresp = invocationBuilder.post(entity);
         resp = rawresp.readEntity(PdpGroupDeployResponse.class);
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
         assertNull(resp.getErrorDetails());
+
+        assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(2);
     }
 }