@Test public void shouldRaiseErrorWhenFacilityWithGivenCodeDoesNotExistWhileSavingProgramSupported() throws Exception { ProgramSupported programSupported = createSupportedProgram("invalid Code", "valid Code", true, new Date()); Facility facility = new Facility(); facility.setCode("invalid Code"); doThrow(new DataException("error.facility.code.invalid")).when(facilityService).getByCode(facility); expectedEx.expect(DataException.class); expectedEx.expectMessage("error.facility.code.invalid"); service.uploadSupportedProgram(programSupported); }
public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } } }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }  }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }  List<ProgramSupported> getAllByFacilityId(Long facilityId); void updateSupportedPrograms(Facility facility); ProgramSupported getFilledByFacilityIdAndProgramId(Long facilityId, Long programId); ProgramSupported getByFacilityIdAndProgramId(Long facilityId, Long programId); void uploadSupportedProgram(ProgramSupported programSupported); ProgramSupported getProgramSupported(ProgramSupported programSupported); void notifyProgramSupportedUpdated(Facility facility); List<ProgramSupported> getActiveByFacilityId(Long facilityId); void updateForVirtualFacilities(Facility parentFacility); }
ProgramSupportedService { public void uploadSupportedProgram(ProgramSupported programSupported) { programSupported.isValid(); Facility facility = new Facility(); facility.setCode(programSupported.getFacilityCode()); facility = facilityService.getByCode(facility); programSupported.setFacilityId(facility.getId()); Program program = programService.getByCode(programSupported.getProgram().getCode()); programSupported.setProgram(program); if (programSupported.getId() == null) { repository.addSupportedProgram(programSupported); } else { repository.updateSupportedProgram(programSupported); } }  List<ProgramSupported> getAllByFacilityId(Long facilityId); void updateSupportedPrograms(Facility facility); ProgramSupported getFilledByFacilityIdAndProgramId(Long facilityId, Long programId); ProgramSupported getByFacilityIdAndProgramId(Long facilityId, Long programId); void uploadSupportedProgram(ProgramSupported programSupported); ProgramSupported getProgramSupported(ProgramSupported programSupported); void notifyProgramSupportedUpdated(Facility facility); List<ProgramSupported> getActiveByFacilityId(Long facilityId); void updateForVirtualFacilities(Facility parentFacility);  }