Search in sources :

Example 6 with ValidSourceAssignment

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

the class ValidSourceDestinationDataBuilder method getValidSourceAssignment.

private static ValidSourceAssignment getValidSourceAssignment(Node organizationNode) {
    ValidSourceAssignment source = new ValidSourceAssignment();
    source.setNode(organizationNode);
    return source;
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)

Example 7 with ValidSourceAssignment

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

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

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

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

the class SourceDestinationBaseServiceTest method shouldReturn400WhenSourceNotFound.

@Test(expected = ValidationMessageException.class)
public void shouldReturn400WhenSourceNotFound() throws Exception {
    // given
    UUID programId = randomUUID();
    UUID facilityTypeId = randomUUID();
    UUID sourceId = randomUUID();
    ValidSourceAssignment assignment = createSource(programId, facilityTypeId, sourceId);
    when(organizationRepository.findOne(sourceId)).thenReturn(null);
    when(nodeRepository.findByReferenceId(sourceId)).thenReturn(null);
    // when
    validSourceService.assignSource(assignment);
}
Also used : ValidSourceAssignment(org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

ValidSourceAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidSourceAssignment)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 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)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