Search in sources :

Example 11 with ValidSourceDestinationDto

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

the class ValidSourceDestinationControllerIntegrationTest method return201WhenAssignSourceSuccessfully.

@Test
public void return201WhenAssignSourceSuccessfully() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID sourceId = randomUUID();
    ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
    ValidSourceDestinationDto validSourceDestinationDto = new ValidSourceDestinationDto();
    validSourceDestinationDto.setProgramId(programId);
    validSourceDestinationDto.setFacilityTypeId(facilityTypeId);
    validSourceDestinationDto.setNode(assignment.getNode());
    when(validSourceService.assignSource(assignment)).thenReturn(validSourceDestinationDto);
    // when
    ResultActions resultActions = mvc.perform(post(API_VALID_SOURCES).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
    // then
    resultActions.andExpect(status().isCreated()).andExpect(jsonPath(PROGRAM_EXP, is(programId.toString()))).andExpect(jsonPath(FACILITY_TYPE_EXP, is(facilityTypeId.toString()))).andExpect(jsonPath(NODE_REFERENCE_ID_EXP, is(sourceId.toString())));
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 12 with ValidSourceDestinationDto

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

the class ValidSourceDestinationControllerIntegrationTest method shouldGetValidSourcesOrDestinationsByProgramAndFacilityType.

@Test
public void shouldGetValidSourcesOrDestinationsByProgramAndFacilityType() throws Exception {
    // given
    ValidSourceDestinationDto destinationAssignmentDto = new ValidSourceDestinationDto();
    destinationAssignmentDto.setId(randomUUID());
    destinationAssignmentDto.setName("CHW");
    destinationAssignmentDto.setIsFreeTextAllowed(true);
    ValidSourceDestinationDto sourceDestination = destinationAssignmentDto;
    UUID program = randomUUID();
    UUID facilityType = randomUUID();
    when(validSourceService.findSources(program, facilityType)).thenReturn(singletonList(sourceDestination));
    when(validDestinationService.findDestinations(program, facilityType)).thenReturn(singletonList(sourceDestination));
    verifyZeroInteractions(permissionService);
    // 1. perform valid destinations
    performSourcesOrDestinations(program, facilityType, sourceDestination, API_VALID_DESTINATIONS);
    // 2. perform valid sources
    performSourcesOrDestinations(program, facilityType, sourceDestination, API_VALID_SOURCES);
}
Also used : ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 13 with ValidSourceDestinationDto

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

the class ValidSourceDestinationControllerIntegrationTest method shouldReturn200WhenSourceAssignmentAlreadyExist.

@Test
public void shouldReturn200WhenSourceAssignmentAlreadyExist() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID sourceId = randomUUID();
    ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
    ValidSourceDestinationDto validSourceDestinationDto = new ValidSourceDestinationDto();
    validSourceDestinationDto.setProgramId(programId);
    validSourceDestinationDto.setFacilityTypeId(facilityTypeId);
    validSourceDestinationDto.setNode(assignment.getNode());
    when(validSourceService.findByProgramFacilitySource(assignment)).thenReturn(validSourceDestinationDto);
    // when
    ResultActions resultActions = mvc.perform(post(API_VALID_SOURCES).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
    // then
    resultActions.andExpect(status().isOk()).andExpect(jsonPath(PROGRAM_EXP, is(programId.toString()))).andExpect(jsonPath(FACILITY_TYPE_EXP, is(facilityTypeId.toString()))).andExpect(jsonPath(NODE_REFERENCE_ID_EXP, is(sourceId.toString())));
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 14 with ValidSourceDestinationDto

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

the class ValidSourceDestinationControllerIntegrationTest method return201WhenAssignDestinationSuccessfully.

@Test
public void return201WhenAssignDestinationSuccessfully() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityTypeId = UUID.randomUUID();
    UUID destinationId = UUID.randomUUID();
    ValidDestinationAssignment assignment = createDestination(programId, facilityTypeId, destinationId);
    ValidSourceDestinationDto validSourceDestinationDto = new ValidSourceDestinationDto();
    validSourceDestinationDto.setProgramId(programId);
    validSourceDestinationDto.setFacilityTypeId(facilityTypeId);
    validSourceDestinationDto.setNode(assignment.getNode());
    when(validDestinationService.assignDestination(assignment)).thenReturn(validSourceDestinationDto);
    // when
    ResultActions resultActions = mvc.perform(post(API_VALID_DESTINATIONS).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
    // then
    resultActions.andExpect(status().isCreated()).andExpect(jsonPath(PROGRAM_EXP, is(programId.toString()))).andExpect(jsonPath(FACILITY_TYPE_EXP, is(facilityTypeId.toString()))).andExpect(jsonPath(NODE_REFERENCE_ID_EXP, is(destinationId.toString())));
}
Also used : ValidDestinationAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment) ValidSourceDestinationDto(org.openlmis.stockmanagement.dto.ValidSourceDestinationDto) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 15 with ValidSourceDestinationDto

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

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