use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldSetValidReasonAsHiddenWhenHiddenIsTrue.
@Test
public void shouldSetValidReasonAsHiddenWhenHiddenIsTrue() throws Exception {
// given1
ValidReasonAssignmentDto assignment = mockedValidReasonAssignment(UUID.randomUUID(), ReasonType.DEBIT);
assignment.setHidden(true);
// when
ResultActions resultActions = mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
// then
ArgumentCaptor<ValidReasonAssignment> assignmentCaptor = forClass(ValidReasonAssignment.class);
resultActions.andDo(print()).andExpect(status().isCreated());
verify(reasonAssignmentRepository, times(1)).save(assignmentCaptor.capture());
assertThat(assignmentCaptor.getValue().getHidden(), is(true));
}
use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldIgnoreAssignmentIdWhenRequestBodySpecifiedIt.
@Test
public void shouldIgnoreAssignmentIdWhenRequestBodySpecifiedIt() throws Exception {
// given
ValidReasonAssignmentDto assignment = mockedValidReasonAssignment(UUID.randomUUID(), ReasonType.DEBIT);
assignment.setId(UUID.randomUUID());
// when
mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
// then
ArgumentCaptor<ValidReasonAssignment> assignmentCaptor = forClass(ValidReasonAssignment.class);
verify(reasonAssignmentRepository, times(1)).save(assignmentCaptor.capture());
assertNotEquals(assignment.getId(), assignmentCaptor.getValue().getId());
}
use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldNotAssignSameReasonTwice.
@Test
public void shouldNotAssignSameReasonTwice() throws Exception {
// given
UUID reasonId = UUID.randomUUID();
StockCardLineItemReason reason = new StockCardLineItemReason();
reason.setId(reasonId);
ValidReasonAssignmentDto assignment = new ValidReasonAssignmentDto();
assignment.setReason(reason);
assignment.setProgramId(UUID.randomUUID());
assignment.setFacilityTypeId(UUID.randomUUID());
when(reasonRepository.exists(reasonId)).thenReturn(true);
when(reasonAssignmentRepository.findByProgramIdAndFacilityTypeIdAndReasonId(assignment.getProgramId(), assignment.getFacilityTypeId(), reasonId)).thenReturn(new ValidReasonAssignment());
// when
ResultActions resultActions = mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
// then
resultActions.andExpect(status().isOk());
verify(reasonAssignmentRepository, never()).save(any(ValidReasonAssignment.class));
}
use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldSetValidReasonAsShownWhenHiddenIsFalse.
@Test
public void shouldSetValidReasonAsShownWhenHiddenIsFalse() throws Exception {
// given1
ValidReasonAssignmentDto assignment = mockedValidReasonAssignment(UUID.randomUUID(), ReasonType.DEBIT);
assignment.setHidden(false);
// when
ResultActions resultActions = mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(assignment)));
// then
ArgumentCaptor<ValidReasonAssignment> assignmentCaptor = forClass(ValidReasonAssignment.class);
resultActions.andDo(print()).andExpect(status().isCreated());
verify(reasonAssignmentRepository, times(1)).save(assignmentCaptor.capture());
assertThat(assignmentCaptor.getValue().getHidden(), is(false));
}
use of org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentController method findExistingOrSaveNew.
private ResponseEntity<ValidReasonAssignmentDto> findExistingOrSaveNew(ValidReasonAssignment assignment) {
UUID programId = assignment.getProgramId();
UUID facilityTypeId = assignment.getFacilityTypeId();
UUID reasonId = assignment.getReason().getId();
ValidReasonAssignment foundAssignment = reasonAssignmentRepository.findByProgramIdAndFacilityTypeIdAndReasonId(programId, facilityTypeId, reasonId);
if (foundAssignment != null) {
return new ResponseEntity<>(reasonAssignmentDtoBuilder.build(foundAssignment), OK);
}
ValidReasonAssignmentDto assignmentDto = reasonAssignmentDtoBuilder.build(reasonAssignmentRepository.save(assignment));
return new ResponseEntity<>(assignmentDto, CREATED);
}
Aggregations