Search in sources :

Example 11 with ValidReasonAssignment

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));
}
Also used : ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 12 with ValidReasonAssignment

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));
}
Also used : ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 13 with ValidReasonAssignment

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));
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Example 14 with ValidReasonAssignment

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);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder)

Example 15 with ValidReasonAssignment

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto) UUID(java.util.UUID)

Aggregations

ValidReasonAssignment (org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment)17 Test (org.junit.Test)12 ValidReasonAssignmentDto (org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)8 ResultActions (org.springframework.test.web.servlet.ResultActions)7 UUID (java.util.UUID)6 UUID.randomUUID (java.util.UUID.randomUUID)4 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)4 StockCardLineItemReasonDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder)2 ValidReasonAssignmentDataBuilder (org.openlmis.stockmanagement.testutils.ValidReasonAssignmentDataBuilder)2 Before (org.junit.Before)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1