Search in sources :

Example 1 with StockEventDto

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));
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

Example 2 with StockEventDto

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());
}
Also used : StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with StockEventDto

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());
}
Also used : ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 4 with StockEventDto

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);
}
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)

Example 5 with StockEventDto

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);
}
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) 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