Search in sources :

Example 1 with ValidSourceDestinationDto

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

the class SourceDestinationBaseServiceTest method shouldReturnSourceAssignmentWhenSourceIsA_facilityWithoutNode.

@Test
public void shouldReturnSourceAssignmentWhenSourceIsA_facilityWithoutNode() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID sourceId = randomUUID();
    when(sourceRepository.save(any(ValidSourceAssignment.class))).thenReturn(createSourceAssignment(programId, facilityTypeId, createNode(sourceId, true)));
    FacilityDto facilityDto = new FacilityDto();
    facilityDto.setName(FACILITY_NAME);
    when(facilityReferenceDataService.exists(sourceId)).thenReturn(true);
    when(facilityReferenceDataService.findOne(sourceId)).thenReturn(facilityDto);
    when(nodeRepository.findByReferenceId(sourceId)).thenReturn(null);
    ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
    // when
    ValidSourceDestinationDto assignmentDto = validSourceService.assignSource(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(sourceId));
    assertThat(assignmentDto.getNode().isRefDataFacility(), is(true));
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) 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)

Example 2 with ValidSourceDestinationDto

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

the class SourceDestinationBaseServiceTest method shouldReturnSourceAssignmentWhenSourceIsAnOrganization.

@Test
public void shouldReturnSourceAssignmentWhenSourceIsAnOrganization() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID sourceId = randomUUID();
    when(sourceRepository.save(any(ValidSourceAssignment.class))).thenReturn(createSourceAssignment(programId, facilityTypeId, createNode(sourceId, false)));
    Organization organization = new Organization();
    organization.setName(ORGANIZATION_NAME);
    when(organizationRepository.exists(sourceId)).thenReturn(true);
    when(organizationRepository.findOne(sourceId)).thenReturn(organization);
    when(nodeRepository.findByReferenceId(sourceId)).thenReturn(null);
    ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
    // when
    ValidSourceDestinationDto assignmentDto = validSourceService.assignSource(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(sourceId));
    assertThat(assignmentDto.getNode().isRefDataFacility(), is(false));
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) 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 3 with ValidSourceDestinationDto

use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto 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 4 with ValidSourceDestinationDto

use of org.openlmis.stockmanagement.dto.ValidSourceDestinationDto 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 5 with ValidSourceDestinationDto

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

the class SourceDestinationBaseServiceTest method shouldReturnListOfSourceDtosWhenFindValidSourceAssignment.

@Test
public void shouldReturnListOfSourceDtosWhenFindValidSourceAssignment() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    doNothing().when(programFacilityTypeExistenceService).checkProgramAndFacilityTypeExist(programId, facilityTypeId);
    List<ValidSourceAssignment> validSourceAssignments = asList(createOrganizationSourceAssignment(mockedOrganizationNode("NGO")), createFacilitySourceAssignment(mockedFacilityNode("Health Center")));
    when(sourceRepository.findByProgramIdAndFacilityTypeId(programId, facilityTypeId)).thenReturn(validSourceAssignments);
    // when
    List<ValidSourceDestinationDto> validSources = validSourceService.findSources(programId, facilityTypeId);
    // then
    assertThat(validSources.size(), is(2));
    ValidSourceDestinationDto organization = validSources.get(0);
    assertThat(organization.getName(), is("NGO"));
    assertThat(organization.getIsFreeTextAllowed(), is(true));
    ValidSourceDestinationDto facility = validSources.get(1);
    assertThat(facility.getName(), is("Health Center"));
    assertThat(facility.getIsFreeTextAllowed(), is(false));
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

ValidSourceDestinationDto (org.openlmis.stockmanagement.dto.ValidSourceDestinationDto)15 UUID (java.util.UUID)13 UUID.randomUUID (java.util.UUID.randomUUID)13 Test (org.junit.Test)13 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)6 ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)6 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)2 Organization (org.openlmis.stockmanagement.domain.sourcedestination.Organization)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2