Search in sources :

Example 6 with StockCardLineItemReason

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

the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn200WhenUserGetAllReasons.

@Test
public void shouldReturn200WhenUserGetAllReasons() throws Exception {
    // given
    StockCardLineItemReason reason1 = new StockCardLineItemReasonDataBuilder().build();
    StockCardLineItemReason reason2 = new StockCardLineItemReasonDataBuilder().withName("Another test reason").build();
    when(stockCardLineItemReasonService.findReasons()).thenReturn(Arrays.asList(reason1, reason2));
    // when
    ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.get(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
    // then
    resultActions.andExpect(status().isOk()).andExpect(jsonPath("$", hasSize(2)));
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ResultActions(org.springframework.test.web.servlet.ResultActions) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Example 7 with StockCardLineItemReason

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

the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn201WhenReasonSuccessfullyCreated.

@Test
public void shouldReturn201WhenReasonSuccessfullyCreated() throws Exception {
    // given
    StockCardLineItemReason createdReason = new StockCardLineItemReasonDataBuilder().withoutId().build();
    when(stockCardLineItemReasonService.saveOrUpdate(any(StockCardLineItemReason.class))).thenReturn(createdReason);
    // when
    ResultActions resultActions = mvc.perform(MockMvcRequestBuilders.post(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(createdReason)));
    // then
    resultActions.andDo(print()).andExpect(status().isCreated()).andExpect(jsonPath("$.name", is(createdReason.getName()))).andExpect(jsonPath("$.description", is(createdReason.getDescription()))).andExpect(jsonPath("$.reasonType", is(createdReason.getReasonType().toString()))).andExpect(jsonPath("$.reasonCategory", is(createdReason.getReasonCategory().toString()))).andExpect(jsonPath("$.isFreeTextAllowed", is(createdReason.getIsFreeTextAllowed())));
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ResultActions(org.springframework.test.web.servlet.ResultActions) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Example 8 with StockCardLineItemReason

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

the class ValidReasonAssignmentControllerIntegrationTest method mockedValidReasonAssignment.

private ValidReasonAssignmentDto mockedValidReasonAssignment(UUID reasonId, ReasonType reasonType) {
    StockCardLineItemReason reason = new StockCardLineItemReason();
    reason.setId(reasonId);
    reason.setReasonType(reasonType);
    ValidReasonAssignmentDto assignment = new ValidReasonAssignmentDto();
    assignment.setReason(reason);
    assignment.setProgramId(reasonId);
    assignment.setFacilityTypeId(reasonId);
    when(reasonRepository.exists(assignment.getReason().getId())).thenReturn(true);
    return assignment;
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) ValidReasonAssignmentDto(org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)

Example 9 with StockCardLineItemReason

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

the class ValidReasonAssignmentControllerIntegrationTest method shouldReturn400IfReasonNotExist.

@Test
public void shouldReturn400IfReasonNotExist() throws Exception {
    // given
    UUID reasonId = UUID.randomUUID();
    StockCardLineItemReason reason = new StockCardLineItemReason();
    reason.setId(reasonId);
    when(reasonRepository.findOne(reasonId)).thenReturn(null);
    ValidReasonAssignment assignment = new ValidReasonAssignment();
    assignment.setReason(reason);
    // 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().isBadRequest());
    verify(reasonAssignmentRepository, never()).save(any(ValidReasonAssignment.class));
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) 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 10 with StockCardLineItemReason

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

the class AdjustmentReasonValidatorIntegrationTest method incorrectReasonTypeShouldNotPassWhenEventHasNoSourceAndDestination.

@Test
public void incorrectReasonTypeShouldNotPassWhenEventHasNoSourceAndDestination() throws Exception {
    // given
    StockCardLineItemReason reason = StockCardLineItemReason.builder().reasonType(ReasonType.BALANCE_ADJUSTMENT).reasonCategory(ReasonCategory.ADJUSTMENT).isFreeTextAllowed(true).name("Balance Adjustment").build();
    StockEventDto stockEventDto = StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(reasonRepository.save(reason).getId());
    setContext(stockEventDto);
    expectedEx.expect(ValidationMessageException.class);
    expectedEx.expectMessage(ERROR_EVENT_ADJUSTMENT_REASON_TYPE_INVALID + ": " + reason.getReasonType());
    // when
    adjustmentReasonValidator.validate(stockEventDto);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)28 Test (org.junit.Test)18 StockCardLineItemReasonDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder)8 ResultActions (org.springframework.test.web.servlet.ResultActions)6 UUID (java.util.UUID)4 ValidReasonAssignment (org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment)4 UUID.randomUUID (java.util.UUID.randomUUID)3 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)3 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)2 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)2 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)2 ValidReasonAssignmentDto (org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)2 Profiler (org.slf4j.profiler.Profiler)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 List (java.util.List)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 PhysicalInventoryLineItemAdjustment (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItemAdjustment)1 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)1