@Test public void loadingEvent() { AbstractAlertingDefinitionEvent event = new AlertingDefinitionLoadedEvent(this, Arrays.asList(definitionOne, definitionTwo)); alertingScheduler.onApplicationEvent(event); verifyZeroInteractions(thresholdChecker, executorService, definitionOne, definitionTwo); assertThat(getAlertingStates(), hasSize(2)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionOne)); assertThat(getAlertingStates().get(1).getAlertingDefinition(), equalTo(definitionTwo)); }
@Test public void deletedEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); assertThat(getAlertingStates(), hasSize(1)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionDeletedEvent(this, definitionOne); when(definitionOne.getId()).thenReturn("id"); alertingScheduler.onApplicationEvent(event); verify(definitionOne, times(2)).getId(); verifyNoMoreInteractions(definitionOne); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(0)); }
@Test public void createEvent() { AbstractAlertingDefinitionEvent event = new AlertingDefinitionCreatedEvent(this, definitionOne); alertingScheduler.onApplicationEvent(event); verifyZeroInteractions(thresholdChecker, executorService, definitionOne); assertThat(getAlertingStates(), hasSize(1)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionOne)); }
@Test public void deletedEventAlertActive() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); assertThat(getAlertingStates(), hasSize(1)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionDeletedEvent(this, definitionOne); when(definitionOne.getId()).thenReturn("id"); Alert alertMock = mock(Alert.class); // set manually because it would done by the threshold checker which is also mocked getAlertingStates().get(0).setAlert(alertMock); alertingScheduler.onApplicationEvent(event); ArgumentCaptor<AlertClosingReason> reasonCapture = ArgumentCaptor.forClass(AlertClosingReason.class); verify(alertMock, times(1)).close(any(Long.class), reasonCapture.capture()); verify(definitionOne, times(2)).getId(); verifyNoMoreInteractions(definitionOne); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(0)); assertThat(reasonCapture.getValue(), equalTo(AlertClosingReason.ALERTING_DEFINITION_DELETED)); }
@Test public void updateUnknownEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionUpdateEvent(this, definitionTwo); when(definitionOne.getId()).thenReturn("id"); when(definitionTwo.getId()).thenReturn("id_2"); alertingScheduler.onApplicationEvent(event); assertThat(getAlertingStates(), hasSize(1)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionOne)); verify(definitionOne).getId(); verify(definitionTwo).getId(); verifyNoMoreInteractions(definitionOne, definitionTwo); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); } }
@Test public void updateEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionOne)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionUpdateEvent(this, definitionTwo); when(definitionOne.getId()).thenReturn("id"); when(definitionTwo.getId()).thenReturn("id"); alertingScheduler.onApplicationEvent(event); verify(definitionOne).getId(); verify(definitionTwo).getId(); verifyNoMoreInteractions(definitionOne, definitionTwo); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); assertThat(getAlertingStates().get(0).getAlertingDefinition(), equalTo(definitionTwo)); }
@Test public void updateEventAlertActive() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionUpdateEvent(this, definitionOne); when(definitionOne.getId()).thenReturn("id"); Alert alertMock = mock(Alert.class); // set manually because it would done by the threshold checker which is also mocked getAlertingStates().get(0).setAlert(alertMock); alertingScheduler.onApplicationEvent(event); verify(alertMock, times(1)).setAlertingDefinition(definitionOne); verify(definitionOne, times(2)).getId(); verifyNoMoreInteractions(definitionOne); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); }
@Test public void deletedUnknownEvent() { alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); assertThat(getAlertingStates(), hasSize(1)); AbstractAlertingDefinitionEvent event = new AlertingDefinitionDeletedEvent(this, definitionTwo); when(definitionOne.getId()).thenReturn("id"); alertingScheduler.onApplicationEvent(event); verify(definitionOne).getId(); verify(definitionTwo).getId(); verifyNoMoreInteractions(definitionOne, definitionTwo); verifyZeroInteractions(thresholdChecker, executorService); assertThat(getAlertingStates(), hasSize(1)); }