use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnListOfDestinationDtosWhenFindValidDestinationAssignment.
@Test
public void shouldReturnListOfDestinationDtosWhenFindValidDestinationAssignment() throws Exception {
// given
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
doNothing().when(programFacilityTypeExistenceService).checkProgramAndFacilityTypeExist(programId, facilityTypeId);
List<ValidDestinationAssignment> validDestinationAssignments = asList(createOrganizationDestination(mockedOrganizationNode("CHW")), createFacilityDestination(mockedFacilityNode("Balaka District Hospital")));
when(destinationRepository.findByProgramIdAndFacilityTypeId(programId, facilityTypeId)).thenReturn(validDestinationAssignments);
// when
List<ValidSourceDestinationDto> validDestinations = validDestinationService.findDestinations(programId, facilityTypeId);
// then
assertThat(validDestinations.size(), is(2));
ValidSourceDestinationDto organization = validDestinations.get(0);
assertThat(organization.getName(), is("CHW"));
assertThat(organization.getIsFreeTextAllowed(), is(true));
ValidSourceDestinationDto facility = validDestinations.get(1);
assertThat(facility.getName(), is("Balaka District Hospital"));
assertThat(facility.getIsFreeTextAllowed(), is(false));
}
use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnDestinationAssignmentWhenDestinationIsA_facilityWithoutNode.
@Test
public void shouldReturnDestinationAssignmentWhenDestinationIsA_facilityWithoutNode() throws Exception {
// given
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
UUID destinationId = randomUUID();
when(destinationRepository.save(any(ValidDestinationAssignment.class))).thenReturn(createDestinationAssignment(programId, facilityTypeId, createNode(destinationId, true)));
FacilityDto facilityDto = new FacilityDto();
facilityDto.setName(FACILITY_NAME);
when(facilityReferenceDataService.exists(destinationId)).thenReturn(true);
when(facilityReferenceDataService.findOne(destinationId)).thenReturn(facilityDto);
when(nodeRepository.findByReferenceId(destinationId)).thenReturn(null);
ValidDestinationAssignment assignment = createDestination(programId, facilityTypeId, destinationId);
// when
ValidSourceDestinationDto assignmentDto = validDestinationService.assignDestination(assignment);
// then
assertThat(assignmentDto.getProgramId(), is(programId));
assertThat(assignmentDto.getFacilityTypeId(), is(facilityTypeId));
assertThat(assignmentDto.getIsFreeTextAllowed(), is(false));
assertThat(assignmentDto.getName(), is(FACILITY_NAME));
assertThat(assignmentDto.getNode().getReferenceId(), is(destinationId));
assertThat(assignmentDto.getNode().isRefDataFacility(), is(true));
}
use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidSourceDestinationController method assignDestination.
/**
* Assign a destination to a program and facility type.
* If valid destination assignment ID is specified, ID will be ignored.
*
* @return the assigned destination and program and facility type.
*/
@RequestMapping(value = "/validDestinations", method = POST)
public ResponseEntity<ValidSourceDestinationDto> assignDestination(@RequestBody ValidDestinationAssignment assignment) {
LOGGER.debug("Try to assign destinations");
permissionService.canManageStockDestinations();
ValidSourceDestinationDto destinationDto = validDestinationService.findByProgramFacilityDestination(assignment);
if (destinationDto != null) {
return new ResponseEntity<>(destinationDto, OK);
}
return new ResponseEntity<>(validDestinationService.assignDestination(assignment), CREATED);
}
use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidSourceDestinationController method assignSource.
/**
* Assign a source to program and facility type.
* If valid source assignment ID is specified, ID will be ignored.
*
* @return the assigned source and program and facility type.
*/
@RequestMapping(value = "/validSources", method = POST)
public ResponseEntity<ValidSourceDestinationDto> assignSource(@RequestBody ValidSourceAssignment assignment) {
LOGGER.debug("Try to assign source");
permissionService.canManageStockSources();
ValidSourceDestinationDto foundAssignmentDto = validSourceService.findByProgramFacilitySource(assignment);
if (foundAssignmentDto != null) {
return new ResponseEntity<>(foundAssignmentDto, OK);
}
return new ResponseEntity<>(validSourceService.assignSource(assignment), CREATED);
}
use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidSourceDestinationControllerIntegrationTest method shouldReturn200WhenDestinationAssignmentAlreadyExist.
@Test
public void shouldReturn200WhenDestinationAssignmentAlreadyExist() throws Exception {
// given
UUID programId = UUID.randomUUID();
UUID facilityTypeId = UUID.randomUUID();
UUID destinationId = UUID.randomUUID();
ValidDestinationAssignment assignment = createDestination(programId, facilityTypeId, destinationId);
ValidSourceDestinationDto validSourceDestinationDto = new ValidSourceDestinationDto();
validSourceDestinationDto.setProgramId(programId);
validSourceDestinationDto.setFacilityTypeId(facilityTypeId);
validSourceDestinationDto.setNode(assignment.getNode());
when(validDestinationService.findByProgramFacilityDestination(assignment)).thenReturn(validSourceDestinationDto);
// when
ResultActions resultActions = mvc.perform(post(API_VALID_DESTINATIONS).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
// then
resultActions.andExpect(status().isOk()).andExpect(jsonPath(PROGRAM_EXP, is(programId.toString()))).andExpect(jsonPath(FACILITY_TYPE_EXP, is(facilityTypeId.toString()))).andExpect(jsonPath(NODE_REFERENCE_ID_EXP, is(destinationId.toString())));
}
Aggregations