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