Search in sources :

Example 1 with Node

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);
}
Also used : ValidDestinationAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 2 with Node

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;
}
Also used : Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto)

Example 3 with 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;
}
Also used : Node(org.openlmis.stockmanagement.domain.sourcedestination.Node)

Example 4 with 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));
}
Also used : Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) Test(org.junit.Test)

Example 5 with Node

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;
}
Also used : Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) UUID(java.util.UUID)

Aggregations

Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)15 UUID (java.util.UUID)4 Test (org.junit.Test)4 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)4 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)3 ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)3 UUID.randomUUID (java.util.UUID.randomUUID)2 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)2 ValidSourceDestinationDto (org.openlmis.stockmanagement.dto.ValidSourceDestinationDto)2 List (java.util.List)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 Organization (org.openlmis.stockmanagement.domain.sourcedestination.Organization)1 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)1 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)1 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 LazyGrouping (org.openlmis.stockmanagement.util.LazyGrouping)1 LazyList (org.openlmis.stockmanagement.util.LazyList)1