/** * {@inheritDoc} */ @Override public AlertingDefinition updateAlertingDefinition(AlertingDefinition alertingDefinition) throws BusinessException { try { return ciManager.updateAlertingDefinition(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(expectedExceptions = BusinessException.class) public void updateAlertingDefinitionNoId() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); manager.updateAlertingDefinition(alertingDefinition); } }
@Test(expectedExceptions = { TechnicalException.class }) public void ioExceptionThrown() throws BusinessException, JAXBException, IOException { doThrow(IOException.class).when(ciManager).updateAlertingDefinition(firstAlertingDefinition); ciService.updateAlertingDefinition(firstAlertingDefinition); } }
@Test public void updateAlertingDefinition() throws BusinessException, JAXBException, IOException { when(ciManager.updateAlertingDefinition(firstAlertingDefinition)).thenReturn(firstAlertingDefinition); AlertingDefinition alertingDefinition = ciService.updateAlertingDefinition(firstAlertingDefinition); assertThat(alertingDefinition, is(firstAlertingDefinition)); }
@Test(expectedExceptions = { TechnicalException.class }) public void jaxbExceptionThrown() throws BusinessException, JAXBException, IOException { doThrow(JAXBException.class).when(ciManager).updateAlertingDefinition(firstAlertingDefinition); ciService.updateAlertingDefinition(firstAlertingDefinition); }
@Test(expectedExceptions = BusinessException.class) public void updateAlertingDefinitionNotExisting() throws Exception { AlertingDefinition alertingDefinition = new AlertingDefinition(); alertingDefinition.setId("not-existing"); manager.updateAlertingDefinition(alertingDefinition); }
@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 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); }