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())));
}
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);
}
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())));
}
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())));
}
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);
}
Aggregations