Search in sources :

Example 6 with ValidReasonAssignment

use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.

the class ValidReasonAssignmentRepositoryIntegrationTest method shouldThrowExceptionWhenSaveDuplicatedValidReason.

@Test(expected = PersistenceException.class)
public void shouldThrowExceptionWhenSaveDuplicatedValidReason() throws Exception {
    ValidReasonAssignment validReasonAssignment = generateInstance();
    repository.save(validReasonAssignment);
    ValidReasonAssignment duplicateValidReason = new ValidReasonAssignment(PROGRAM_ID, FACILITY_TYPE_ID, false, validReasonAssignment.getReason());
    repository.save(duplicateValidReason);
    entityManager.flush();
}
Also used : ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) Test(org.junit.Test)

Example 7 with ValidReasonAssignment

use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryAdjustmentReasonsValidatorTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    setContext(stockEventDto);
    when(validReasonRepository.findByProgramIdAndFacilityTypeIdAndReasonId(any(UUID.class), any(UUID.class), any(UUID.class))).thenReturn(new ValidReasonAssignment());
    stubFacilityType();
    when(stockEventDto.isPhysicalInventory()).thenReturn(true);
}
Also used : ValidReasonAssignment(org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment) UUID(java.util.UUID) Before(org.junit.Before)

Example 8 with ValidReasonAssignment

use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment 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 9 with ValidReasonAssignment

use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment 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 10 with ValidReasonAssignment

use of org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment 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)

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