Search in sources :

Example 1 with ValidDestinationAssignment

use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method shouldReturnDestinationAssignmentWhenDestinationIsA_organization.

@Test
public void shouldReturnDestinationAssignmentWhenDestinationIsA_organization() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID destinationId = randomUUID();
    when(destinationRepository.save(any(ValidDestinationAssignment.class))).thenReturn(createDestinationAssignment(programId, facilityTypeId, createNode(destinationId, false)));
    Organization organization = new Organization();
    organization.setName(ORGANIZATION_NAME);
    when(organizationRepository.exists(destinationId)).thenReturn(true);
    when(organizationRepository.findOne(destinationId)).thenReturn(organization);
    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(true));
    assertThat(assignmentDto.getName(), is(ORGANIZATION_NAME));
    assertThat(assignmentDto.getNode().getReferenceId(), is(destinationId));
    assertThat(assignmentDto.getNode().isRefDataFacility(), is(false));
}
Also used : ValidDestinationAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment) Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 2 with ValidDestinationAssignment

use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment 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 3 with ValidDestinationAssignment

use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method shouldReturnListOfDestinationDtosWhenFindValidDestinationAssignment.

@Test
public void shouldReturnListOfDestinationDtosWhenFindValidDestinationAssignment() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    doNothing().when(programFacilityTypeExistenceService).checkProgramAndFacilityTypeExist(programId, facilityTypeId);
    List<ValidDestinationAssignment> validDestinationAssignments = asList(createOrganizationDestination(mockedOrganizationNode("CHW")), createFacilityDestination(mockedFacilityNode("Balaka District Hospital")));
    when(destinationRepository.findByProgramIdAndFacilityTypeId(programId, facilityTypeId)).thenReturn(validDestinationAssignments);
    // when
    List<ValidSourceDestinationDto> validDestinations = validDestinationService.findDestinations(programId, facilityTypeId);
    // then
    assertThat(validDestinations.size(), is(2));
    ValidSourceDestinationDto organization = validDestinations.get(0);
    assertThat(organization.getName(), is("CHW"));
    assertThat(organization.getIsFreeTextAllowed(), is(true));
    ValidSourceDestinationDto facility = validDestinations.get(1);
    assertThat(facility.getName(), is("Balaka District Hospital"));
    assertThat(facility.getIsFreeTextAllowed(), is(false));
}
Also used : ValidDestinationAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 4 with ValidDestinationAssignment

use of org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment in project openlmis-stockmanagement by OpenLMIS.

the class SourceDestinationBaseServiceTest method createDestinationAssignment.

private ValidDestinationAssignment createDestinationAssignment(UUID programId, UUID facilityTypeId, Node node) {
    ValidDestinationAssignment assignment = new ValidDestinationAssignment();
    assignment.setNode(node);
    assignment.setProgramId(programId);
    assignment.setFacilityTypeId(facilityTypeId);
    return assignment;
}
Also used : ValidDestinationAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)

Example 5 with ValidDestinationAssignment

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

Aggregations

ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)11 UUID (java.util.UUID)8 UUID.randomUUID (java.util.UUID.randomUUID)7 Test (org.junit.Test)7 ValidSourceDestinationDto (org.openlmis.stockmanagement.dto.ValidSourceDestinationDto)6 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)3 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)3 ResultActions (org.springframework.test.web.servlet.ResultActions)2 List (java.util.List)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)1 Organization (org.openlmis.stockmanagement.domain.sourcedestination.Organization)1 ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)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 LazyGrouping (org.openlmis.stockmanagement.util.LazyGrouping)1 LazyList (org.openlmis.stockmanagement.util.LazyList)1 LazyResource (org.openlmis.stockmanagement.util.LazyResource)1