/** * {@inheritDoc} */ @Override public Alert getAlert(String alertId) { return alertRegistry.getAlert(alertId); }
/** * {@inheritDoc} */ @Override public List<Alert> getBusinessTransactionAlerts() { return alertRegistry.getBusinessTransactionAlerts(); }
/** * {@inheritDoc} */ @Override public List<Alert> getAlerts() { return alertRegistry.getAlerts(); }
@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)); }
/** * {@inheritDoc} */ @Override public void onApplicationEvent(AbstractAlertingDefinitionEvent event) { if (event == null) { return; } switch (event.getType()) { case LOADED: loadedAlertingDefinitions(event); break; case ADDED: createdAlertingDefinition(event); break; case REMOVED: deletedAlertingDefinition(event); break; case UPDATE: updatedAlertingDefinition(event); break; default: break; } }
@Test public void thresholdCheckerThrowsException() throws Exception { AlertingDefinition definitionOne = mock(AlertingDefinition.class); alertingScheduler.onApplicationEvent(new AlertingDefinitionCreatedEvent(this, definitionOne)); doThrow(RuntimeException.class).when(thresholdChecker).checkThreshold(any(AlertingState.class)); alertingScheduler.run(); verify(thresholdChecker).checkThreshold(any(AlertingState.class)); verifyNoMoreInteractions(thresholdChecker); verifyZeroInteractions(executorService); } }
@Test public void noAlertActive() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(false); lifecycleManager.valid(alertingState); verify(alertingState).isAlertActive(); verifyNoMoreInteractions(alertingState); verifyZeroInteractions(alertingActionService); }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void nullAlert() { Alert alert = null; alertRegistry.registerAlert(alert); }
@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 alertingStateNull() { lifecycleManager.noData(null); verifyZeroInteractions(alertingActionService); } }
@Test public void alertingStateNull() { lifecycleManager.valid(null); verifyZeroInteractions(alertingActionService); } }
@Test public void alertingStateNull() { lifecycleManager.violation(null, 0); verifyZeroInteractions(alertingActionService); } }
@Test public void nullEvent() { alertingScheduler.onApplicationEvent(null); verifyZeroInteractions(thresholdChecker, executorService); }
@Test public void noAlertingStates() throws Exception { alertingScheduler.run(); verifyZeroInteractions(thresholdChecker); verifyZeroInteractions(executorService); }
@Test public void deactivate() { alertingScheduler.active = false; alertingScheduler.updateState(); verifyZeroInteractions(thresholdChecker); verifyZeroInteractions(executorService); }
@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 getUnknownAlert() { Alert alert = alertRegistry.getAlert("unknown-id"); assertThat(alert, is(nullValue())); }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void alertIdIsNull() throws Exception { Alert testAlert = Mockito.mock(Alert.class); alertRegistry.registerAlert(testAlert); }
@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)); }
@Test public void getByNull() { Alert alert = alertRegistry.getAlert(null); assertThat(alert, is(nullValue())); } }