Search in sources :

Example 36 with StockEventDto

use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.

the class StockEventDtoDataBuilder method createStockEventDtoWithTwoLineItems.

/**
 * Create stock event dto object for testing with two line items.
 *
 * @return created dto object.
 */
public static StockEventDto createStockEventDtoWithTwoLineItems() {
    StockEventDto stockEventDto = new StockEventDto();
    stockEventDto.setProgramId(UUID.randomUUID());
    stockEventDto.setFacilityId(UUID.randomUUID());
    UUID orderable = UUID.randomUUID();
    UUID lot = UUID.randomUUID();
    StockEventLineItemDto lineItem1 = new StockEventLineItemDto();
    lineItem1.setOrderableId(orderable);
    lineItem1.setLotId(lot);
    lineItem1.setQuantity(20);
    lineItem1.setOccurredDate(getBaseDate());
    lineItem1.setReasonId(UUID.fromString("279d55bd-42e3-438c-a63d-9c021b185dae"));
    StockEventLineItemDto lineItem2 = new StockEventLineItemDto();
    lineItem2.setOrderableId(orderable);
    lineItem2.setLotId(lot);
    lineItem2.setQuantity(10);
    lineItem2.setOccurredDate(getBaseDate());
    lineItem2.setReasonId(UUID.fromString("b7e99f5b-af04-433d-9c30-d4f90c60c47b"));
    stockEventDto.setLineItems(Arrays.asList(lineItem1, lineItem2));
    return stockEventDto;
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID)

Example 37 with StockEventDto

use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.

the class StockEventsControllerIntegrationTest method generateStockEvent.

private StockEventDto generateStockEvent() {
    StockEventDto stockEvent = new StockEventDto();
    stockEvent.setFacilityId(UUID.randomUUID());
    stockEvent.setProgramId(UUID.randomUUID());
    stockEvent.setSignature("signature");
    stockEvent.setDocumentNumber("number");
    stockEvent.setLineItems(Collections.singletonList(generateStockEventLineItem()));
    return stockEvent;
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto)

Example 38 with StockEventDto

use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.

the class StockEventsControllerrIntegrationTest method shouldReturn201WhenEventSuccessfullyCreated.

@Test
public void shouldReturn201WhenEventSuccessfullyCreated() throws Exception {
    // given
    UUID uuid = UUID.randomUUID();
    when(stockEventProcessor.process(any(StockEventDto.class))).thenReturn(uuid);
    // when
    StockEventDto stockEventDto = createStockEventDto();
    stockEventDto.getLineItems().get(0).setSourceId(null);
    stockEventDto.getLineItems().get(0).setDestinationId(null);
    ResultActions resultActions = mvc.perform(post(CREATE_STOCK_EVENT_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(stockEventDto)));
    // then
    resultActions.andDo(MockMvcResultHandlers.print()).andExpect(status().isCreated()).andExpect(content().string("\"" + uuid.toString() + "\""));
}
Also used : StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) Test(org.junit.Test)

Example 39 with StockEventDto

use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.

the class StockEventsControllerrIntegrationTest method shouldReturn400WhenValidationFails.

@Test
public void shouldReturn400WhenValidationFails() throws Exception {
    // given
    Mockito.doThrow(new ValidationMessageException(new Message(ERROR_EVENT_QUANTITIES_INVALID))).when(stockEventProcessor).process(any());
    // when
    ResultActions resultActions = mvc.perform(post(CREATE_STOCK_EVENT_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockEventDto())));
    // then
    resultActions.andExpect(status().isBadRequest());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 40 with StockEventDto

use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.

the class StockEventsControllerrIntegrationTest method shouldReturn403WhenUserHasNoPermissionToAdjustStock.

@Test
public void shouldReturn403WhenUserHasNoPermissionToAdjustStock() throws Exception {
    // given
    Mockito.doThrow(new PermissionMessageException(new Message(ERROR_NO_FOLLOWING_PERMISSION, STOCK_ADJUST))).when(permissionService).canAdjustStock(any(UUID.class), any(UUID.class));
    StockEventDto eventDto = createNoSourceDestinationStockEventDto();
    shouldReject(eventDto);
}
Also used : Message(org.openlmis.stockmanagement.util.Message) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Aggregations

StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)72 Test (org.junit.Test)65 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)44 UUID (java.util.UUID)24 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto)14 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)13 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)11 UUID.randomUUID (java.util.UUID.randomUUID)10 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)8 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)7 Message (org.openlmis.stockmanagement.util.Message)7 LocalDate (java.time.LocalDate)6 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)5 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)4 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)4 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)4 StockEventProcessContext (org.openlmis.stockmanagement.util.StockEventProcessContext)4 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)3 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)3