use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnSourceAssignmentWhenSourceIsA_facilityWithoutNode.
@Test
public void shouldReturnSourceAssignmentWhenSourceIsA_facilityWithoutNode() throws Exception {
// given
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
UUID sourceId = randomUUID();
when(sourceRepository.save(any(ValidSourceAssignment.class))).thenReturn(createSourceAssignment(programId, facilityTypeId, createNode(sourceId, true)));
FacilityDto facilityDto = new FacilityDto();
facilityDto.setName(FACILITY_NAME);
when(facilityReferenceDataService.exists(sourceId)).thenReturn(true);
when(facilityReferenceDataService.findOne(sourceId)).thenReturn(facilityDto);
when(nodeRepository.findByReferenceId(sourceId)).thenReturn(null);
ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
// when
ValidSourceDestinationDto assignmentDto = validSourceService.assignSource(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(sourceId));
assertThat(assignmentDto.getNode().isRefDataFacility(), is(true));
}
use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnSourceAssignmentWhenSourceIsAnOrganization.
@Test
public void shouldReturnSourceAssignmentWhenSourceIsAnOrganization() throws Exception {
// given
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
UUID sourceId = randomUUID();
when(sourceRepository.save(any(ValidSourceAssignment.class))).thenReturn(createSourceAssignment(programId, facilityTypeId, createNode(sourceId, false)));
Organization organization = new Organization();
organization.setName(ORGANIZATION_NAME);
when(organizationRepository.exists(sourceId)).thenReturn(true);
when(organizationRepository.findOne(sourceId)).thenReturn(organization);
when(nodeRepository.findByReferenceId(sourceId)).thenReturn(null);
ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
// when
ValidSourceDestinationDto assignmentDto = validSourceService.assignSource(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(sourceId));
assertThat(assignmentDto.getNode().isRefDataFacility(), is(false));
}
use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto 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.dto.ValidSourceDestinationDto 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.dto.ValidSourceDestinationDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnListOfSourceDtosWhenFindValidSourceAssignment.
@Test
public void shouldReturnListOfSourceDtosWhenFindValidSourceAssignment() throws Exception {
// given
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
doNothing().when(programFacilityTypeExistenceService).checkProgramAndFacilityTypeExist(programId, facilityTypeId);
List<ValidSourceAssignment> validSourceAssignments = asList(createOrganizationSourceAssignment(mockedOrganizationNode("NGO")), createFacilitySourceAssignment(mockedFacilityNode("Health Center")));
when(sourceRepository.findByProgramIdAndFacilityTypeId(programId, facilityTypeId)).thenReturn(validSourceAssignments);
// when
List<ValidSourceDestinationDto> validSources = validSourceService.findSources(programId, facilityTypeId);
// then
assertThat(validSources.size(), is(2));
ValidSourceDestinationDto organization = validSources.get(0);
assertThat(organization.getName(), is("NGO"));
assertThat(organization.getIsFreeTextAllowed(), is(true));
ValidSourceDestinationDto facility = validSources.get(1);
assertThat(facility.getName(), is("Health Center"));
assertThat(facility.getIsFreeTextAllowed(), is(false));
}
Aggregations