use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class AdjustmentReasonValidatorIntegrationTest method shouldNotThrowExceptionIfEventHasNoSourceDestinationReasonId.
@Test
public void shouldNotThrowExceptionIfEventHasNoSourceDestinationReasonId() throws Exception {
// given
StockEventDto stockEventDto = StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto();
stockEventDto.getLineItems().get(0).setReasonId(null);
setContext(stockEventDto);
// when
adjustmentReasonValidator.validate(stockEventDto);
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class AdjustmentReasonValidatorIntegrationTest method shouldNotThrowErrorForEventWithNoReasonId.
@Test
public void shouldNotThrowErrorForEventWithNoReasonId() throws Exception {
// given
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.getLineItems().get(0).setReasonId(null);
setContext(stockEventDto);
// when
adjustmentReasonValidator.validate(stockEventDto);
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemTest method shouldCreateLineItemFromStockEvent.
@Test
public void shouldCreateLineItemFromStockEvent() throws Exception {
// given
StockCard stockCard = new StockCard();
stockCard.setLineItems(new ArrayList<>());
// when
UUID userId = randomUUID();
StockEventProcessContext context = new StockEventProcessContext();
context.setCurrentUserId(new LazyResource<>(() -> userId));
StockEventDto eventDto = createStockEventDto();
eventDto.setContext(context);
StockEventLineItemDto eventLineItem = eventDto.getLineItems().get(0);
eventLineItem.setStockAdjustments(singletonList(createStockAdjustment()));
UUID eventId = randomUUID();
StockCardLineItem cardLineItem = createLineItemFrom(eventDto, eventLineItem, stockCard, eventId);
// then
assertThat(cardLineItem.getSourceFreeText(), is(eventLineItem.getSourceFreeText()));
assertThat(cardLineItem.getDestinationFreeText(), is(eventLineItem.getDestinationFreeText()));
assertThat(cardLineItem.getReasonFreeText(), is(eventLineItem.getReasonFreeText()));
assertThat(cardLineItem.getDocumentNumber(), is(eventDto.getDocumentNumber()));
assertThat(cardLineItem.getSignature(), is(eventDto.getSignature()));
assertThat(cardLineItem.getQuantity(), is(eventLineItem.getQuantity()));
assertThat(cardLineItem.getReason().getId(), is(eventLineItem.getReasonId()));
assertThat(cardLineItem.getSource().getId(), is(eventLineItem.getSourceId()));
assertThat(cardLineItem.getDestination().getId(), is(eventLineItem.getDestinationId()));
assertThat(cardLineItem.getOccurredDate(), is(eventLineItem.getOccurredDate()));
assertThat(cardLineItem.getStockCard(), is(stockCard));
assertThat(cardLineItem.getOriginEvent().getId(), is(eventId));
assertThat(cardLineItem.getUserId(), is(userId));
assertEquals(cardLineItem.getStockAdjustments(), eventLineItem.stockAdjustments());
ZonedDateTime processedDate = cardLineItem.getProcessedDate();
long between = SECONDS.between(processedDate, ZonedDateTime.now());
assertThat(between, lessThan(2L));
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class OrderableLotDuplicationValidator method validate.
@Override
public void validate(StockEventDto stockEventDto) {
// duplication is not allow in physical inventory, but is allowed in adjustment
if (!stockEventDto.hasLineItems() || !stockEventDto.isPhysicalInventory()) {
return;
}
Set<OrderableLotIdentity> nonDuplicates = new HashSet<>();
Set<OrderableLotIdentity> duplicates = stockEventDto.getLineItems().stream().map(OrderableLotIdentity::identityOf).filter(lotIdentity -> !nonDuplicates.add(lotIdentity)).collect(toSet());
if (duplicates.size() > 0) {
throw new ValidationMessageException(new Message(ERROR_EVENT_ORDERABLE_LOT_DUPLICATION, duplicates));
}
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventProcessContextBuilderTest method shouldBuildContextWithUserIdFromDtoWhenClientAuthentication.
@Test
public void shouldBuildContextWithUserIdFromDtoWhenClientAuthentication() throws Exception {
StockEventDto stockEventDto = StockEventDtoDataBuilder.createStockEventDto();
stockEventDto.setUserId(userDto.getId());
when(authentication.isClientOnly()).thenReturn(true);
testBuildContext(stockEventDto);
}
Aggregations