@Test public void saveStateHistoryShouldSaveWhenAllParamIsRightAndCreationDateIsExisting() { firstStateHistoryDtoWithStateDto.setCreationDate(presentDate); given(statesRepository.findOne(FIRST_ID)).willReturn(firstStateEntity); given(converterService.convert(firstStateHistoryDtoWithStateDto, StatesHistoryEntity.class)) .willReturn(firstStatesHistoryEntity); given(statesHistoryRepository.saveAndFlush(firstStatesHistoryEntity)) .willReturn(firstStatesHistoryEntity); Long result = statesHistoryService.saveStateHistory(firstStateHistoryDtoWithStateDto); assertThat(result, notNullValue()); assertThat(result, equalTo(FIRST_ID)); assertThat(firstStatesHistoryEntity.getCreationDate(), equalTo(presentDate)); then(statesRepository).should().findOne(FIRST_ID); then(converterService).should() .convert(firstStateHistoryDtoWithStateDto, StatesHistoryEntity.class); then(statesHistoryRepository).should().saveAndFlush(firstStatesHistoryEntity); then(applicationsService).should() .saveOrUpdate(firstStateHistoryDtoWithStateDto.getApplicationDTO()); }
@Transactional @Override public Long saveStateHistory(StateHistoryDTO state) { Assert.notNull(state); Assert.notNull(state.getStateDTO()); Assert.notNull(state.getStateDTO().getId()); StatesEntity statesEntity = statesRepository.findOne(state.getStateDTO().getId()); Assert.notNull(statesEntity); StatesHistoryEntity statesHistoryEntity = converterService.convert(state, StatesHistoryEntity.class); statesHistoryEntity .setCreationDate(state.getCreationDate() == null ? new Date() : state.getCreationDate()); applicationsService.saveOrUpdate(state.getApplicationDTO()); return statesHistoryRepository.saveAndFlush(statesHistoryEntity).getId(); }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional @Override public Long saveStateHistory(StateHistoryDTO state) { Assert.notNull(state); Assert.notNull(state.getStateDTO()); Assert.notNull(state.getStateDTO().getId()); StatesEntity statesEntity = statesRepository.findOne(state.getStateDTO().getId()); Assert.notNull(statesEntity); StatesHistoryEntity statesHistoryEntity = converterService.convert(state, StatesHistoryEntity.class); statesHistoryEntity .setCreationDate(state.getCreationDate() == null ? new Date() : state.getCreationDate()); applicationsService.saveOrUpdate(state.getApplicationDTO()); return statesHistoryRepository.saveAndFlush(statesHistoryEntity).getId(); } }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional @Override public Long saveStateHistory(StateHistoryDTO state) { Assert.notNull(state); Assert.notNull(state.getStateDTO()); Assert.notNull(state.getStateDTO().getId()); StatesEntity statesEntity = statesRepository.findOne(state.getStateDTO().getId()); Assert.notNull(statesEntity); StatesHistoryEntity statesHistoryEntity = converterService.convert(state, StatesHistoryEntity.class); statesHistoryEntity .setCreationDate(state.getCreationDate() == null ? new Date() : state.getCreationDate()); applicationsService.saveOrUpdate(state.getApplicationDTO()); return statesHistoryRepository.saveAndFlush(statesHistoryEntity).getId(); }  }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional @Override public Long saveStateHistory(StateHistoryDTO state) { Assert.notNull(state); Assert.notNull(state.getStateDTO()); Assert.notNull(state.getStateDTO().getId()); StatesEntity statesEntity = statesRepository.findOne(state.getStateDTO().getId()); Assert.notNull(statesEntity); StatesHistoryEntity statesHistoryEntity = converterService.convert(state, StatesHistoryEntity.class); statesHistoryEntity .setCreationDate(state.getCreationDate() == null ? new Date() : state.getCreationDate()); applicationsService.saveOrUpdate(state.getApplicationDTO()); return statesHistoryRepository.saveAndFlush(statesHistoryEntity).getId(); }  @Transactional @Override void deleteStateHistoriesByApplication(ApplicationDTO applicationDTO); @Transactional @Override Long saveStateHistory(StateHistoryDTO state); @Transactional(readOnly = true) @Override List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId); }
StatesHistoryServiceImpl implements StatesHistoryService { @Transactional @Override public Long saveStateHistory(StateHistoryDTO state) { Assert.notNull(state); Assert.notNull(state.getStateDTO()); Assert.notNull(state.getStateDTO().getId()); StatesEntity statesEntity = statesRepository.findOne(state.getStateDTO().getId()); Assert.notNull(statesEntity); StatesHistoryEntity statesHistoryEntity = converterService.convert(state, StatesHistoryEntity.class); statesHistoryEntity .setCreationDate(state.getCreationDate() == null ? new Date() : state.getCreationDate()); applicationsService.saveOrUpdate(state.getApplicationDTO()); return statesHistoryRepository.saveAndFlush(statesHistoryEntity).getId(); }  @Transactional @Override void deleteStateHistoriesByApplication(ApplicationDTO applicationDTO); @Transactional @Override Long saveStateHistory(StateHistoryDTO state); @Transactional(readOnly = true) @Override List<StateHistoryDTO> getStateHistoriesByApplicationId(Long applicationId);  }