Search in sources :

Example 6 with ValidReasonAssignmentDto

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));
}
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 7 with ValidReasonAssignmentDto

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

Example 8 with ValidReasonAssignmentDto

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

Example 9 with ValidReasonAssignmentDto

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));
}
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 10 with ValidReasonAssignmentDto

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

ValidReasonAssignmentDto (org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)12 Test (org.junit.Test)9 ValidReasonAssignment (org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment)8 ResultActions (org.springframework.test.web.servlet.ResultActions)5 UUID (java.util.UUID)4 UUID.randomUUID (java.util.UUID.randomUUID)3 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)2 ValidReasonAssignmentDataBuilder (org.openlmis.stockmanagement.testutils.ValidReasonAssignmentDataBuilder)2 ResponseEntity (org.springframework.http.ResponseEntity)1