use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnDestinationAssignmentWhenDestinationIsA_organization.
@Test
public void shouldReturnDestinationAssignmentWhenDestinationIsA_organization() throws Exception {
// given
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
UUID destinationId = randomUUID();
when(destinationRepository.save(any(ValidDestinationAssignment.class))).thenReturn(createDestinationAssignment(programId, facilityTypeId, createNode(destinationId, false)));
Organization organization = new Organization();
organization.setName(ORGANIZATION_NAME);
when(organizationRepository.exists(destinationId)).thenReturn(true);
when(organizationRepository.findOne(destinationId)).thenReturn(organization);
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(true));
assertThat(assignmentDto.getName(), is(ORGANIZATION_NAME));
assertThat(assignmentDto.getNode().getReferenceId(), is(destinationId));
assertThat(assignmentDto.getNode().isRefDataFacility(), is(false));
}
use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnDestinationDtoWhenFoundExistingOne.
@Test
public void shouldReturnDestinationDtoWhenFoundExistingOne() throws Exception {
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
UUID destinationId = randomUUID();
ValidDestinationAssignment assignment = createDestination(programId, facilityTypeId, destinationId);
Node node = createNode(destinationId, true);
when(nodeRepository.findByReferenceId(destinationId)).thenReturn(node);
when(facilityReferenceDataService.findOne(destinationId)).thenReturn(new FacilityDto());
when(destinationRepository.findByProgramIdAndFacilityTypeIdAndNodeId(programId, facilityTypeId, node.getId())).thenReturn(createDestinationAssignment(programId, facilityTypeId, node));
// when
ValidSourceDestinationDto foundDto = validDestinationService.findByProgramFacilityDestination(assignment);
assertThat(foundDto.getProgramId(), is(programId));
assertThat(foundDto.getFacilityTypeId(), is(facilityTypeId));
assertThat(foundDto.getNode().getReferenceId(), is(destinationId));
verify(programFacilityTypeExistenceService, times(1)).checkProgramAndFacilityTypeExist(programId, facilityTypeId);
}
use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment 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.domain.sourcedestination.ValidDestinationAssignment in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method createDestinationAssignment.
private ValidDestinationAssignment createDestinationAssignment(UUID programId, UUID facilityTypeId, Node node) {
ValidDestinationAssignment assignment = new ValidDestinationAssignment();
assignment.setNode(node);
assignment.setProgramId(programId);
assignment.setFacilityTypeId(facilityTypeId);
return assignment;
}
use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment 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));
}
Aggregations