@Test public void shouldSaveMappingIfAllCorrect() throws Exception { Long facilityId = 99L; Program program = new Program(); program.setPush(false); Long programId = 1L; requisitionGroupProgramSchedule.setDropOffFacility(facility(dropOffFacility.getCode())); when(requisitionGroupMapper.getIdForCode(requisitionGroupProgramSchedule.getRequisitionGroup().getCode())).thenReturn(1L); when(programRepository.getIdByCode(requisitionGroupProgramSchedule.getProgram().getCode())).thenReturn(programId); when(programRepository.getById(programId)).thenReturn(program); when(processingScheduleMapper.getIdForCode(requisitionGroupProgramSchedule.getProcessingSchedule().getCode())).thenReturn(1L); when(facilityMapper.getIdForCode(dropOffFacility.getCode())).thenReturn(facilityId); repository.insert(requisitionGroupProgramSchedule); verify(requisitionGroupProgramScheduleMapper).insert(requisitionGroupProgramSchedule); verify(requisitionGroupMapper).getIdForCode(requisitionGroupProgramSchedule.getRequisitionGroup().getCode()); verify(programRepository).getIdByCode(requisitionGroupProgramSchedule.getProgram().getCode()); verify(processingScheduleMapper).getIdForCode(requisitionGroupProgramSchedule.getProcessingSchedule().getCode()); verify(facilityMapper).getIdForCode(dropOffFacility.getCode()); assertThat(requisitionGroupProgramSchedule.getProcessingSchedule().getId(), is(1L)); assertThat(requisitionGroupProgramSchedule.getProgram().getId(), is(1L)); assertThat(requisitionGroupProgramSchedule.getRequisitionGroup().getId(), is(1L)); assertThat(requisitionGroupProgramSchedule.isDirectDelivery(), is(false)); assertThat(requisitionGroupProgramSchedule.getDropOffFacility().getId(), is(facilityId)); }
public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } @Autowired  RequisitionGroupProgramScheduleRepository(
    RequisitionGroupProgramScheduleMapper requisitionGroupProgramScheduleMapper,
    RequisitionGroupMapper requisitionGroupMapper,
    ProgramRepository programRepository,
    ProcessingScheduleMapper processingScheduleMapper,
    FacilityMapper facilityMapper); }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } @Autowired  RequisitionGroupProgramScheduleRepository(
    RequisitionGroupProgramScheduleMapper requisitionGroupProgramScheduleMapper,
    RequisitionGroupMapper requisitionGroupMapper,
    ProgramRepository programRepository,
    ProcessingScheduleMapper processingScheduleMapper,
    FacilityMapper facilityMapper); void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); void update(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupAndProgram(Long requisitionGroupId, Long programId); List<Long> getProgramIDsForRequisitionGroup(Long requisitionGroupId); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupCodeAndProgramCode(String requisitionGroupCode, String programCode); List<RequisitionGroupProgramSchedule> getByRequisitionGroupId(Long requisitionGroupId); void deleteRequisitionGroupProgramSchedulesFor(Long requisitionGroupId); }
RequisitionGroupProgramScheduleRepository { public void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule) { populateIdsForRequisitionProgramScheduleEntities(requisitionGroupProgramSchedule); validateRequisitionGroupSchedule(requisitionGroupProgramSchedule); validateProgramType(requisitionGroupProgramSchedule); try { mapper.insert(requisitionGroupProgramSchedule); } catch (DuplicateKeyException e) { throw new DataException("error.duplicate.requisition.group.program.combination"); } } @Autowired  RequisitionGroupProgramScheduleRepository(
    RequisitionGroupProgramScheduleMapper requisitionGroupProgramScheduleMapper,
    RequisitionGroupMapper requisitionGroupMapper,
    ProgramRepository programRepository,
    ProcessingScheduleMapper processingScheduleMapper,
    FacilityMapper facilityMapper); void insert(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); void update(RequisitionGroupProgramSchedule requisitionGroupProgramSchedule); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupAndProgram(Long requisitionGroupId, Long programId); List<Long> getProgramIDsForRequisitionGroup(Long requisitionGroupId); RequisitionGroupProgramSchedule getScheduleForRequisitionGroupCodeAndProgramCode(String requisitionGroupCode, String programCode); List<RequisitionGroupProgramSchedule> getByRequisitionGroupId(Long requisitionGroupId); void deleteRequisitionGroupProgramSchedulesFor(Long requisitionGroupId);  }