summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java22
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java6
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java14
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java3
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java7
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java3
6 files changed, 53 insertions, 2 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java b/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java
index 3b7f7e16..cc1f74b4 100644
--- a/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/notification/DeploymentStatusTest.java
@@ -26,6 +26,7 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -33,13 +34,16 @@ import java.util.Map;
import java.util.Set;
import lombok.NonNull;
import org.apache.commons.lang3.builder.CompareToBuilder;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.policy.common.utils.services.Registry;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pap.concepts.PolicyNotification;
import org.onap.policy.models.pap.concepts.PolicyStatus;
@@ -47,6 +51,7 @@ import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.PdpPolicyStatusBuilder;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.notification.StatusAction.Action;
import org.onap.policy.pap.main.service.PolicyStatusService;
@@ -81,6 +86,22 @@ public class DeploymentStatusTest {
private DeploymentStatus tracker;
/**
+ * Set up the meter registry for tests.
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ Registry.register(PapConstants.REG_METER_REGISTRY, new SimpleMeterRegistry());
+ }
+
+ /**
+ * Tear down the meter registry after tests.
+ */
+ @AfterClass
+ public static void tearDownAfterClass() {
+ Registry.unregister(PapConstants.REG_METER_REGISTRY);
+ }
+
+ /**
* Sets up.
*/
@Before
@@ -97,6 +118,7 @@ public class DeploymentStatusTest {
.deploy(true)
.state(State.SUCCESS);
// @formatter:on
+
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java
index 153a2bfa..b5667145 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java
@@ -30,6 +30,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import io.micrometer.core.instrument.MeterRegistry;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@@ -92,6 +93,7 @@ public class ProviderSuper {
protected PdpModifyRequestMap reqmap;
protected ToscaPolicy policy1;
protected PapStatisticsManager statsmanager;
+ protected MeterRegistry meterRegistry;
/**
* Configures DAO, captors, and various mocks.
@@ -109,6 +111,8 @@ public class ProviderSuper {
policy1 = loadPolicy("policy.json");
statsmanager = mock(PapStatisticsManager.class);
+ meterRegistry = mock(MeterRegistry.class);
+
List<PdpGroup> groups = loadGroups("groups.json");
when(pdpGroupService.getFilteredPdpGroups(any())).thenReturn(groups);
@@ -119,6 +123,8 @@ public class ProviderSuper {
Registry.register(PapConstants.REG_PDP_MODIFY_LOCK, lockit);
Registry.register(PapConstants.REG_PDP_MODIFY_MAP, reqmap);
Registry.register(PapConstants.REG_STATISTICS_MANAGER, statsmanager);
+ Registry.register(PapConstants.REG_METER_REGISTRY, meterRegistry);
+
}
/**
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java
index 9c9f36ad..575e33ff 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java
@@ -22,6 +22,7 @@
package org.onap.policy.pap.main.rest.e2e;
+import io.micrometer.core.instrument.MeterRegistry;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -34,12 +35,14 @@ import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.PrometheusUtils;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroups;
import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
@@ -81,6 +84,15 @@ public abstract class End2EndBase extends CommonPapRestServer {
@Autowired
public ToscaServiceTemplateService toscaService;
+ @Autowired
+ public MeterRegistry meterRegistry;
+
+ public String deploymentsCounterName = "pap_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC;
+ public String[] deploymentSuccessTag = {PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.DEPLOY_OPERATION,
+ PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()};
+ public String[] unDeploymentSuccessTag = {PrometheusUtils.OPERATION_METRIC_LABEL,
+ PrometheusUtils.UNDEPLOY_OPERATION, PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()};
+
/**
* Tears down.
*/
@@ -95,7 +107,7 @@ public abstract class End2EndBase extends CommonPapRestServer {
}
context = null;
}
-
+ meterRegistry.clear();
super.tearDown();
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
index e3ad0044..a8387881 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
@@ -22,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;
@@ -149,6 +150,8 @@ public class PdpGroupDeleteTest extends End2EndBase {
assertEquals(0, deleted.getIncompleteCount());
assertEquals(new ToscaConceptIdentifier("onap.restart.tcaB", "1.0.0"), deleted.getPolicy());
+ assertThat(meterRegistry.counter(deploymentsCounterName, unDeploymentSuccessTag).count()).isEqualTo(2);
+
rawresp = invocationBuilder.delete();
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
index cdb1fa9d..df749a88 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
@@ -22,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;
@@ -121,6 +122,8 @@ public class PdpGroupDeployTest extends End2EndBase {
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");
@@ -167,6 +170,8 @@ 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);
@@ -202,5 +207,7 @@ public class PdpGroupDeployTest extends End2EndBase {
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
+
+ assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(2);
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java b/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
index 2204392a..c11af694 100644
--- a/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
+++ b/main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;
@@ -93,7 +94,7 @@ public class TestPapActivator {
final PapParameterGroup parGroup = new CommonTestData().getPapParameterGroup(6969);
activator = new PapActivator(parGroup, new PolicyNotifier(null), new PdpHeartbeatListener(),
- new PdpModifyRequestMap(null, null, null, null, null));
+ new PdpModifyRequestMap(null, null, null, null, null), new SimpleMeterRegistry());
}