/** * {@inheritDoc} */ @Override public AlertingDefinition createAlertingDefinition(AlertingDefinition alertingDefinition) throws BusinessException { try { return ciManager.createAlertingDefinition(alertingDefinition); } catch (JAXBException e) { throw new TechnicalException("Update the alerting definition.", ConfigurationInterfaceErrorCodeEnum.JAXB_MARSHALLING_OR_DEMARSHALLING_FAILED, e); } catch (IOException e) { throw new TechnicalException("Update the alerting definition.", ConfigurationInterfaceErrorCodeEnum.INPUT_OUTPUT_OPERATION_FAILED, e); } }
@Test public void createAlertingDefinition() throws BusinessException, JAXBException, IOException { when(ciManager.createAlertingDefinition(firstAlertingDefinition)).thenReturn(firstAlertingDefinition); AlertingDefinition returnedDefinition = ciService.createAlertingDefinition(firstAlertingDefinition); assertThat(returnedDefinition, is(firstAlertingDefinition)); }
@Test(expectedExceptions = { TechnicalException.class }) public void jaxbExceptionThrown() throws BusinessException, JAXBException, IOException { doThrow(JAXBException.class).when(ciManager).createAlertingDefinition(firstAlertingDefinition); ciService.createAlertingDefinition(firstAlertingDefinition); }
@Test(expectedExceptions = { TechnicalException.class }) public void ioExceptionThrown() throws BusinessException, JAXBException, IOException { doThrow(IOException.class).when(ciManager).createAlertingDefinition(firstAlertingDefinition); ciService.createAlertingDefinition(firstAlertingDefinition); }
@Test public void deleteAlertingDefinition() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); manager.deleteAlertingDefinition(alertingDefinition); assertThat(manager.getAlertingDefinitions(), not(hasItem(alertingDefinition))); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher, times(2)).publishEvent(captor.capture()); assertThat(captor.getAllValues().get(0), is(instanceOf(AbstractAlertingDefinitionEvent.AlertingDefinitionCreatedEvent.class))); assertThat(captor.getAllValues().get(1), is(instanceOf(AbstractAlertingDefinitionEvent.AlertingDefinitionDeletedEvent.class))); }
@Test public void createAlertingDefinitionCheckId() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); alertingDefinition = manager.createAlertingDefinition(alertingDefinition); assertThat(alertingDefinition.getId(), is(not(nullValue()))); assertThat(alertingDefinition.getCreatedDate(), is(not(nullValue()))); }
@Test public void createAlertingDefinitionExists() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); alertingDefinition = manager.createAlertingDefinition(alertingDefinition); assertThat(manager.getAlertingDefinitions(), hasItem(alertingDefinition)); } }
@Test public void getAlertingDefinitions() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); AlertingDefinition returnedDefinition = manager.createAlertingDefinition(alertingDefinition); List<AlertingDefinition> alertingDefinitions = manager.getAlertingDefinitions(); assertThat(alertingDefinitions, hasItem(returnedDefinition)); }
@Test public void updateAlertingDefinition() throws BusinessException, JAXBException, IOException { String newName = "newName"; AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); alertingDefinition.setName(newName); AlertingDefinition updated = manager.updateAlertingDefinition(alertingDefinition); assertThat(updated.getName(), is(newName)); assertThat(updated.getRevision(), is(2)); assertThat(alertingDefinition.getUpdatedDate(), is(greaterThanOrEqualTo(alertingDefinition.getCreatedDate()))); ArgumentCaptor<ApplicationEvent> captor = ArgumentCaptor.forClass(ApplicationEvent.class); verify(eventPublisher, times(2)).publishEvent(captor.capture()); assertThat(captor.getAllValues().get(0), is(instanceOf(AbstractAlertingDefinitionEvent.AlertingDefinitionCreatedEvent.class))); assertThat(captor.getAllValues().get(1), is(instanceOf(AbstractAlertingDefinitionEvent.AlertingDefinitionUpdateEvent.class))); }
@Test(expectedExceptions = BusinessException.class) public void getAlertingDefinitionNotExisting() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); AlertingDefinition returnedDefinition = manager.getAlertingDefinition("unknown_id"); } }
@Test public void getAlertingDefinition() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); AlertingDefinition returnedDefinition = manager.getAlertingDefinition(alertingDefinition.getId()); assertThat(alertingDefinition.getId(), equalTo(returnedDefinition.getId())); }
@Test(expectedExceptions = BusinessException.class) public void updateAlertingDefinitionRevisionFailed() throws BusinessException, JAXBException, IOException { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setName("test"); manager.createAlertingDefinition(alertingDefinition); AlertingDefinition clone = new AlertingDefinition(); clone.setId(alertingDefinition.getId()); manager.updateAlertingDefinition(alertingDefinition); manager.updateAlertingDefinition(clone); }