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;
}
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;
}
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() + "\""));
}
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());
}
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);
}
Aggregations