summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorisaac <isaac.adorno@att.com>2022-01-25 14:21:19 -0600
committerisaac <isaac.adorno@att.com>2022-02-23 09:46:27 -0600
commit445d27d85dda4e23c593fc9c604bfe9cb68f8516 (patch)
tree101e43d65307ea513bd5606c91120ea5c222e91b /main/src/test
parentfca2e06f2a01c03ba0d12271defaec0b5ab13ba5 (diff)
Adding statistics to PDP Heartbeat Messages
Issue-ID: POLICY-3034 Signed-off-by: isaac <isaac.adorno@att.com> Change-Id: I495da4178b9715ec710fdc790f08faef0fc456d5
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java51
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java19
2 files changed, 54 insertions, 16 deletions
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
index 0b8d1404..d8dc2ee3 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021-2022 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,23 +26,32 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.util.Arrays;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.pdpx.main.comm.XacmlPdpUpdatePublisher;
import org.onap.policy.pdpx.main.rest.XacmlPdpApplicationManager;
+import org.onap.policy.pdpx.main.rest.XacmlPdpStatisticsManager;
import org.onap.policy.pdpx.main.startstop.XacmlPdpActivator;
@RunWith(MockitoJUnitRunner.class)
@@ -70,7 +79,6 @@ public class XacmlStateTest {
pdpName = XacmlState.PDP_NAME;
XacmlPdpActivator.setCurrent(act);
-
state = new XacmlState(appmgr, GROUP, PDP_TYPE);
}
@@ -107,6 +115,45 @@ public class XacmlStateTest {
}
@Test
+ public void testGetStatistics() {
+ XacmlPdpStatisticsManager statmgr = new XacmlPdpStatisticsManager();
+ XacmlPdpStatisticsManager.setCurrent(statmgr);
+
+ ToscaPolicy policy1 = mock(ToscaPolicy.class);
+ ToscaPolicy policy2 = mock(ToscaPolicy.class);
+ ToscaConceptIdentifier ident = new ToscaConceptIdentifier("undeployed", "2.3.4");
+ when(policy2.getIdentifier()).thenReturn(ident);
+
+ PdpUpdate message = new PdpUpdate();
+ message.setPoliciesToBeDeployed(Arrays.asList(policy1));
+ message.setPoliciesToBeUndeployed(Arrays.asList(policy2.getIdentifier()));
+
+ TopicSinkClient client = Mockito.mock(TopicSinkClient.class);
+ XacmlPdpUpdatePublisher publisher = new XacmlPdpUpdatePublisher(client, state, appmgr);
+ publisher.handlePdpUpdate(message);
+
+ PdpStatistics stats = state.getStatistics();
+ assertTrue(stats != null);
+ assertEquals(GROUP, stats.getPdpGroupName());
+ assertEquals(stats.getPolicyDeployCount(), 1);
+ assertEquals(stats.getPolicyDeploySuccessCount(), 1);
+ assertEquals(stats.getPolicyDeployFailCount(), 0);
+ assertEquals(stats.getPolicyUndeployCount(), 1);
+ assertEquals(stats.getPolicyUndeployFailCount(), 1);
+ assertEquals(stats.getPolicyUndeploySuccessCount(), 0);
+
+ PdpStatistics test = new PdpStatistics();
+ test.setTimeStamp(stats.getTimeStamp());
+ test.setPdpGroupName(GROUP);
+ test.setPolicyDeployCount(1);
+ test.setPolicyDeploySuccessCount(1);
+ test.setPolicyUndeployCount(1);
+ test.setPolicyUndeployFailCount(1);
+
+ assertEquals(stats.toString(), test.toString());
+ }
+
+ @Test
public void testUpdateInternalStatePdpStateChange() {
PdpStateChange req = new PdpStateChange();
req.setName(pdpName);
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java
index 1edaab34..872bec15 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpUpdatePublisherTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021-2022 AT&T Intellectual Property. 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.
@@ -102,6 +102,7 @@ public class XacmlPdpUpdatePublisherTest {
private PdpUpdate failurePdpUpdate;
private XacmlPdpUpdatePublisher publisher;
+ private XacmlPdpStatisticsManager statmgr;
/**
@@ -150,13 +151,13 @@ public class XacmlPdpUpdatePublisherTest {
when(client.send(any())).thenReturn(true);
publisher = new XacmlPdpUpdatePublisher(client, state, appmgr);
+
+ statmgr = new XacmlPdpStatisticsManager();
+ XacmlPdpStatisticsManager.setCurrent(statmgr);
}
@Test
public void testHandlePdpUpdate() throws XacmlApplicationException {
- XacmlPdpStatisticsManager statmgr = new XacmlPdpStatisticsManager();
- XacmlPdpStatisticsManager.setCurrent(statmgr);
-
publisher.handlePdpUpdate(update);
// two removed
@@ -254,16 +255,6 @@ public class XacmlPdpUpdatePublisherTest {
}
@Test
- public void testHandlePdpUpdate_NullStats() {
- XacmlPdpStatisticsManager.setCurrent(null);
-
- // should work without throwing an exception
- publisher.handlePdpUpdate(update);
-
- verify(client).send(status);
- }
-
- @Test
public void testHandlePdpUpdate_SendFail() {
when(client.send(any())).thenReturn(false);