@Test public void testMultipleReporters() throws Exception { /* * This test checks that reports from multiple reporters are aggregated * correctly. There are two reporters that report: * r1: ioc1 = C, ioc2 = D * r2: ioc1 = C, ioc2 = C, ioc3 = D * * The expected result is that there should be three IocState objects * with the correct states. ioc3/r1 should be reported as DISCONNECTED. */ _im.setReporterServices(Arrays.asList(_r1, _r2)); MonitorReport report = _im.getReport(); assertEquals(2, report.getInterconnectionServers().size()); assertTrue(report.getInterconnectionServers().contains("r1")); assertTrue(report.getInterconnectionServers().contains("r2")); List<MonitorItem> is = report.getItems(); assertEquals(3, is.size()); assertTrue(containsState(is, "ioc1", "r1", IocConnectionState.CONNECTED)); assertTrue(containsState(is, "ioc1", "r2", IocConnectionState.CONNECTED)); assertTrue(containsState(is, "ioc2", "r1", IocConnectionState.DISCONNECTED)); assertTrue(containsState(is, "ioc2", "r2", IocConnectionState.CONNECTED)); assertTrue(containsState(is, "ioc3", "r1", IocConnectionState.DISCONNECTED)); assertTrue(containsState(is, "ioc3", "r2", IocConnectionState.DISCONNECTED)); }
@Test public void testSingleReporter() throws Exception { _im.setReporterServices(Arrays.asList(_r1)); MonitorReport report = _im.getReport(); assertEquals(1, report.getInterconnectionServers().size()); assertTrue(report.getInterconnectionServers().contains("r1")); List<MonitorItem> is = report.getItems(); assertEquals(2, is.size()); assertTrue(containsState(is, "ioc1", "r1", IocConnectionState.CONNECTED)); assertTrue(containsState(is, "ioc2", "r1", IocConnectionState.DISCONNECTED)); }
@Test public void testListenersAreNotified() throws Exception { IReportListener listener = Mockito.mock(IReportListener.class); _im.addListener(listener); _im.setReporterServices(Arrays.asList(_r1)); Mockito.verify(listener).onReportUpdated(); _im.setReporterServices(Collections.<IIocConnectionReporter>emptyList()); Mockito.verify(listener, Mockito.times(2)).onReportUpdated(); // after the listener is removed, it must not be notified any longer _im.removeListener(listener); _im.setReporterServices(Arrays.asList(_r1)); Mockito.verifyNoMoreInteractions(listener); }
@Test public void testNoReportersAdded() throws Exception { // No reporters configured, so report should be empty MonitorReport report = _im.getReport(); assertTrue(report.getInterconnectionServers().isEmpty()); assertTrue(report.getItems().isEmpty()); }