use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseService method findOrCreateNode.
private Node findOrCreateNode(UUID referenceId, boolean isRefDataFacility) {
Node node = nodeRepository.findByReferenceId(referenceId);
if (node == null) {
node = new Node();
node.setReferenceId(referenceId);
node.setRefDataFacility(isRefDataFacility);
return nodeRepository.save(node);
}
return node;
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemTest method shouldDecreaseSohOfLineItemWhenIssueTo.
@Test
public void shouldDecreaseSohOfLineItemWhenIssueTo() throws Exception {
// given
StockCardLineItem lineItem = StockCardLineItem.builder().destination(new Node()).quantity(15).build();
// when
lineItem.calculateStockOnHand(15);
// then
assertThat(lineItem.getStockOnHand(), is(0));
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.
the class SourceDestinationBaseServiceTest method shouldReturnSourceDtoWhenFoundExistingOne.
@Test
public void shouldReturnSourceDtoWhenFoundExistingOne() throws Exception {
UUID programId = randomUUID();
UUID facilityTypeId = randomUUID();
UUID sourceId = randomUUID();
ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
Node node = createNode(sourceId, true);
when(nodeRepository.findByReferenceId(sourceId)).thenReturn(node);
when(facilityReferenceDataService.findOne(sourceId)).thenReturn(new FacilityDto());
when(sourceRepository.findByProgramIdAndFacilityTypeIdAndNodeId(programId, facilityTypeId, node.getId())).thenReturn(createSourceAssignment(programId, facilityTypeId, node));
// when
ValidSourceDestinationDto foundDto = validSourceService.findByProgramFacilitySource(assignment);
assertThat(foundDto.getProgramId(), is(programId));
assertThat(foundDto.getFacilityTypeId(), is(facilityTypeId));
assertThat(foundDto.getNode().getReferenceId(), is(sourceId));
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 mockedOrganizationNode.
private Node mockedOrganizationNode(String name) {
Organization organization = new Organization();
organization.setName(name);
organization.setId(randomUUID());
when(organizationRepository.findOne(organization.getId())).thenReturn(organization);
Node node = new Node();
node.setRefDataFacility(false);
node.setId(randomUUID());
node.setReferenceId(organization.getId());
return node;
}
use of org.openlmis.stockmanagement.domain.sourcedestination.Node in project openlmis-stockmanagement by OpenLMIS.
the class ValidDestinationAssignmentDataBuilder method createDestination.
/**
* Create a valid destination assignment.
*
* @param programId program ID
* @param facilityTypeId facility type ID
* @param destinationId destination ID
* @return valid destination assignment
*/
public static ValidDestinationAssignment createDestination(UUID programId, UUID facilityTypeId, UUID destinationId) {
Node node = new Node();
node.setReferenceId(destinationId);
ValidDestinationAssignment assignment = new ValidDestinationAssignment();
assignment.setProgramId(programId);
assignment.setFacilityTypeId(facilityTypeId);
assignment.setNode(node);
return assignment;
}
Aggregations