use of org.openlmis.stockmanagement.dto.referencedata.FacilityDto 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.referencedata.FacilityDto 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.referencedata.FacilityDto in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method mockedFacilityNode.
private Node mockedFacilityNode(String name) {
FacilityDto facilityDto = new FacilityDto();
facilityDto.setName(name);
facilityDto.setId(randomUUID());
when(facilityReferenceDataService.findOne(facilityDto.getId())).thenReturn(facilityDto);
Node node = new Node();
node.setRefDataFacility(true);
node.setReferenceId(facilityDto.getId());
return node;
}
use of org.openlmis.stockmanagement.dto.referencedata.FacilityDto 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.referencedata.FacilityDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldGetRefdataAndConvertOrganizationsWhenFindStockCard.
@Test
public void shouldGetRefdataAndConvertOrganizationsWhenFindStockCard() throws Exception {
// given
UUID userId = randomUUID();
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.getLineItems().get(0).setLotId(randomUUID());
// 1. mock ref data service
FacilityDto cardFacility = new FacilityDto();
FacilityDto sourceFacility = new FacilityDto();
ProgramDto programDto = new ProgramDto();
OrderableDto orderableDto = new OrderableDto();
LotDto lotDto = new LotDto();
when(facilityReferenceDataService.findOne(stockEventDto.getFacilityId())).thenReturn(cardFacility);
when(facilityReferenceDataService.findOne(fromString("e6799d64-d10d-4011-b8c2-0e4d4a3f65ce"))).thenReturn(sourceFacility);
when(programReferenceDataService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
when(orderableReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getOrderableId())).thenReturn(orderableDto);
when(lotReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getLotId())).thenReturn(lotDto);
// 2. there is an existing stock card with line items
StockEvent savedEvent = save(stockEventDto, userId);
// when
StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
StockCardDto foundCardDto = stockCardService.findStockCardById(savedCard.getId());
// then
assertThat(foundCardDto.getFacility(), is(cardFacility));
assertThat(foundCardDto.getProgram(), is(programDto));
assertThat(foundCardDto.getOrderable(), is(orderableDto));
assertThat(foundCardDto.getLot(), is(lotDto));
StockCardLineItemDto lineItemDto = foundCardDto.getLineItems().get(0);
assertThat(lineItemDto.getSource(), is(sourceFacility));
assertThat(lineItemDto.getDestination().getName(), is("NGO"));
}
Aggregations