use of org.openlmis.stockmanagement.domain.sourcedestination.Node 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.Node 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.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method createNode.
private Node createNode(UUID referenceId, boolean isRefDataFacility) {
Node node = new Node();
node.setReferenceId(referenceId);
node.setId(randomUUID());
node.setRefDataFacility(isRefDataFacility);
return node;
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemTest method shouldIncreaseSohOfLineItemWhenReceiveFrom.
@Test
public void shouldIncreaseSohOfLineItemWhenReceiveFrom() throws Exception {
// given
StockCardLineItem lineItem = StockCardLineItem.builder().source(new Node()).quantity(15).build();
// when
lineItem.calculateStockOnHand(15);
// then
assertThat(lineItem.getStockOnHand(), is(30));
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseService method findAssignment.
/**
* Try to find an existing assignment.
*
* @param assignment source or destination assignment
* @param repository assignment repository
* @param <T> assignment type
* @return assignment dto or null if not found.
*/
protected <T extends SourceDestinationAssignment> ValidSourceDestinationDto findAssignment(T assignment, SourceDestinationAssignmentRepository<T> repository) {
UUID programId = assignment.getProgramId();
UUID facilityTypeId = assignment.getFacilityTypeId();
Node foundNode = findExistingNode(assignment, programId, facilityTypeId);
if (foundNode != null) {
T foundAssignment = repository.findByProgramIdAndFacilityTypeIdAndNodeId(programId, facilityTypeId, foundNode.getId());
if (foundAssignment != null) {
return createAssignmentDto(foundAssignment);
}
}
return null;
}
Aggregations