@Test public void shouldThrowExceptionIfCHWIsAlreadyRegistered() throws Exception { Agent agent = make(a(defaultCHW)); Facility facility = mock(Facility.class); whenNew(Facility.class).withNoArguments().thenReturn(facility); when(facilityService.getByCode(facility)).thenReturn(facility); expectedException.expect(DataException.class); expectedException.expectMessage("error.agent.already.registered"); restAgentService.create(agent, user.getId()); }
@Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); } }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }  }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }  @Transactional void create(Agent agent, Long userId); void update(Agent agent, Long userId); }
RestAgentService { @Transactional public void create(Agent agent, Long userId) { agent.validate(); if (getExistingFacilityForCode(agent.getAgentCode()) != null) { throw new DataException("error.agent.already.registered"); } Facility facility = createFacilityFrom(agent); facility.setCreatedBy(userId); facility.setModifiedBy(userId); facilityService.save(facility); programSupportedService.updateSupportedPrograms(facility); saveRequisitionGroupMembers(facility, userId); }  @Transactional void create(Agent agent, Long userId); void update(Agent agent, Long userId);  }