use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceTest method shouldNotDuplicateCardsForOrderableLots.
@Test
public void shouldNotDuplicateCardsForOrderableLots() {
StockEventDto event = StockEventDtoDataBuilder.createStockEventDtoWithTwoLineItems();
event.setContext(mock(StockEventProcessContext.class));
UUID savedEventId = UUID.randomUUID();
stockCardService.saveFromEvent(event, savedEventId);
verify(cardRepository).save(cardCaptor.capture());
List<StockCard> saved = cardCaptor.getValue();
assertThat(saved, hasSize(1));
StockCard card = saved.get(0);
assertThat(card.getFacilityId(), equalTo(event.getFacilityId()));
assertThat(card.getProgramId(), equalTo(event.getProgramId()));
assertThat(card.getOrderableId(), equalTo(event.getLineItems().get(0).getOrderableId()));
assertThat(card.getLotId(), equalTo(event.getLineItems().get(0).getLotId()));
assertThat(card.getOrderableId(), equalTo(event.getLineItems().get(1).getOrderableId()));
assertThat(card.getLotId(), equalTo(event.getLineItems().get(1).getLotId()));
assertThat(card.getLineItems(), hasSize(2));
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerIntegrationTest method shouldCreateStockEvent.
// POST /api/stockEvents
@Test
public void shouldCreateStockEvent() {
// given
mockHasPermissions();
mockPassValidation();
StockEventDto stockEvent = generateStockEvent();
UUID expectedId = UUID.randomUUID();
when(stockEventProcessor.process(any(StockEventDto.class))).thenReturn(expectedId);
// when
UUID result = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).body(stockEvent).when().post(RESOURCE_URL).then().statusCode(201).extract().as(UUID.class);
// then
assertEquals(expectedId, result);
assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerIntegrationTest method shouldReturnBadRequestOnCreateStockEventWhenEntityInvalid.
@Test
public void shouldReturnBadRequestOnCreateStockEventWhenEntityInvalid() {
// given
mockHasPermissions();
mockPassValidation();
StockEventDto stockEvent = generateStockEvent();
when(stockEventProcessor.process(any(StockEventDto.class))).thenThrow(new ValidationMessageException(ERROR_REASON_ASSIGNMENT_NOT_FOUND));
// when
restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).body(stockEvent).when().post(RESOURCE_URL).then().statusCode(400);
// then
assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerrIntegrationTest method shouldReturn403WhenUserHasNoPermissionToPerformPhysicalInventory.
@Test
public void shouldReturn403WhenUserHasNoPermissionToPerformPhysicalInventory() throws Exception {
// given
Mockito.doThrow(new PermissionMessageException(new Message(ERROR_NO_FOLLOWING_PERMISSION, STOCK_ADJUST))).when(permissionService).canEditPhysicalInventory(any(UUID.class), any(UUID.class));
StockEventDto dto = createNoSourceDestinationStockEventDto();
dto.getLineItems().get(0).setReasonId(null);
shouldReject(dto);
}
use of org.openlmis.stockmanagement.dto.StockEventDto in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerrIntegrationTest method shouldReturn403WhenUserHomeFacilityDoesNotSupportProvidedProgram.
@Test
public void shouldReturn403WhenUserHomeFacilityDoesNotSupportProvidedProgram() throws Exception {
// given
StockEventDto eventDto = createNoSourceDestinationStockEventDto();
Mockito.doThrow(new PermissionMessageException(new Message(ERROR_PROGRAM_NOT_SUPPORTED))).when(homeFacilityPermissionService).checkProgramSupported(eventDto.getProgramId());
shouldReject(eventDto);
}
Aggregations