use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentControllerIntegrationTest method shouldReturn400IfReasonIdIsNull.
@Test
public void shouldReturn400IfReasonIdIsNull() throws Exception {
// when
ResultActions resultActions = mvc.perform(post(VALID_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new ValidReasonAssignment())));
// then
resultActions.andExpect(status().isBadRequest());
verify(reasonAssignmentRepository, never()).save(any(ValidReasonAssignment.class));
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment 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.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentRepositoryIntegrationTest method shouldReturnValidReasonWithProgramAndFacilityTypeAndReasonTypes.
@Test
public void shouldReturnValidReasonWithProgramAndFacilityTypeAndReasonTypes() throws Exception {
ValidReasonAssignment validReasonAssignment = generateInstance();
repository.save(validReasonAssignment);
StockCardLineItemReason newReason = new StockCardLineItemReasonDataBuilder().withoutId().withName("Damage").withDebitType().build();
reasonRepository.save(newReason);
ValidReasonAssignment newAssignment = new ValidReasonAssignment(PROGRAM_ID, FACILITY_TYPE_ID, false, newReason);
repository.save(newAssignment);
List<StockCardLineItemReason> reasons = Arrays.asList(validReasonAssignment.getReason(), newReason);
List<ValidReasonAssignment> validReasonAssignments = repository.findByProgramIdAndFacilityTypeIdAndReasonIn(PROGRAM_ID, FACILITY_TYPE_ID, reasons);
assertThat(validReasonAssignments.size(), is(2));
assertThat(validReasonAssignments, hasItems(validReasonAssignment, newAssignment));
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentRepositoryIntegrationTest method generateInstance.
@Override
ValidReasonAssignment generateInstance() throws Exception {
int instanceNumber = getNextInstanceNumber();
StockCardLineItemReason reason = new StockCardLineItemReasonDataBuilder().withoutId().withName("Name" + instanceNumber).withCreditType().build();
reasonRepository.save(reason);
return new ValidReasonAssignment(PROGRAM_ID, FACILITY_TYPE_ID, false, reason);
}
use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment 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