Search in sources :

Example 11 with FacilityDto

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

use of org.openlmis.stockmanagement.dto.referencedata.FacilityDto in project openlmis-stockmanagement by OpenLMIS.

the class StockEventProcessContextBuilderTest method testBuildContext.

private void testBuildContext(StockEventDto stockEventDto) {
    // given
    UUID lotId = UUID.randomUUID();
    LotDto lot = new LotDto();
    lot.setId(lotId);
    StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setLotId(lotId);
    ProgramDto programDto = new ProgramDto();
    FacilityDto facilityDto = new FacilityDto();
    ArrayList<OrderableDto> approvedProductDtos = new ArrayList<>();
    when(programService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
    when(facilityService.findOne(stockEventDto.getFacilityId())).thenReturn(facilityDto);
    when(orderableReferenceDataService.findAll()).thenReturn(approvedProductDtos);
    when(lotReferenceDataService.findOne(lotId)).thenReturn(lot);
    // when
    StockEventProcessContext context = contextBuilder.buildContext(stockEventDto);
    // then
    assertThat(context.getCurrentUserId(), is(userDto.getId()));
    assertThat(context.getProgram(), is(programDto));
    assertThat(context.getFacility(), is(facilityDto));
    assertThat(context.getAllApprovedProducts(), is(approvedProductDtos));
    assertThat(context.findLot(lotId), is(lot));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) ArrayList(java.util.ArrayList) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) UUID(java.util.UUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext)

Aggregations

FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)12 UUID (java.util.UUID)8 UUID.randomUUID (java.util.UUID.randomUUID)5 Test (org.junit.Test)5 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)5 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)4 ValidSourceDestinationDto (org.openlmis.stockmanagement.dto.ValidSourceDestinationDto)4 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)4 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)4 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)3 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)3 ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)3 List (java.util.List)2 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)2 StockCardLineItemDto (org.openlmis.stockmanagement.dto.StockCardLineItemDto)2 FacilityReferenceDataService (org.openlmis.stockmanagement.service.referencedata.FacilityReferenceDataService)2 StockEventProcessContext (org.openlmis.stockmanagement.util.StockEventProcessContext)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 ArrayList (java.util.ArrayList)1