+ @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());
+ }
+