Search in sources :

Example 6 with PhysicalInventoryDto

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

the class PhysicalInventoryServiceTest method shouldLeavePreviousSohAsNullWhenSubmitPhysicalInventoryIfNoStockCardFound.

@Test
public void shouldLeavePreviousSohAsNullWhenSubmitPhysicalInventoryIfNoStockCardFound() throws Exception {
    PhysicalInventoryDto physicalInventoryDto = newInventoryForSubmit();
    when(stockCardRepository.findByProgramIdAndFacilityIdAndOrderableIdAndLotId(physicalInventoryDto.getProgramId(), physicalInventoryDto.getFacilityId(), lineItemDto.getOrderableId(), lineItemDto.getLotId())).thenReturn(null);
    physicalInventoryService.submitPhysicalInventory(physicalInventoryDto, UUID.randomUUID());
    verify(physicalInventoryRepository, times(1)).save(inventoryArgumentCaptor.capture());
    verify(stockCard, never()).shallowCopy();
    verifyPhysicalInventorySavedWithoutSohAndAsDraft();
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) Test(org.junit.Test)

Example 7 with PhysicalInventoryDto

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

the class PhysicalInventoryControllerIntegrationTest method generateDraft.

private PhysicalInventoryDto generateDraft() {
    PhysicalInventoryDto inventory = new PhysicalInventoryDto();
    inventory.setFacilityId(UUID.randomUUID());
    inventory.setProgramId(UUID.randomUUID());
    return inventory;
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto)

Example 8 with PhysicalInventoryDto

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

the class PhysicalInventoryControllerIntegrationTest method shouldGetChosenDraftWhenExists.

// GET /api/physicalInventories
@Test
public void shouldGetChosenDraftWhenExists() {
    // given
    PhysicalInventoryDto expectedDraft = generatePhysicalInventory();
    UUID programId = expectedDraft.getProgramId();
    UUID facilityId = expectedDraft.getFacilityId();
    when(physicalInventoryService.findPhysicalInventory(programId, facilityId, true)).thenReturn(Collections.singletonList(expectedDraft));
    // when
    List resultCollection = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).queryParam(PROGRAM_PARAM, programId).queryParam(FACILITY_PARAM, facilityId).queryParam("isDraft", true).when().get(RESOURCE_URL).then().statusCode(200).extract().as(List.class);
    // then
    assertEquals(1, resultCollection.size());
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID) Test(org.junit.Test)

Example 9 with PhysicalInventoryDto

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

the class PhysicalInventoryControllerIntegrationTest method shouldReturnBadRequestOnCreateEmptyDraftWhenEntityInvalid.

@Test
public void shouldReturnBadRequestOnCreateEmptyDraftWhenEntityInvalid() {
    // given
    PhysicalInventoryDto expectedDraft = generateDraft();
    when(physicalInventoryService.createNewDraft(expectedDraft)).thenThrow(new ValidationMessageException(ERROR_PROGRAM_ID_MISSING));
    // when
    restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).body(expectedDraft).when().post(RESOURCE_URL).then().statusCode(400);
    // then
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) Test(org.junit.Test)

Example 10 with PhysicalInventoryDto

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

the class PhysicalInventoryControllerIntegrationTest method shouldReturnOnePhysicalInventory.

// GET /api/physicalInventories/{id}
@Test
public void shouldReturnOnePhysicalInventory() {
    // given
    PhysicalInventoryDto expectedInventory = generatePhysicalInventory();
    UUID piId = UUID.randomUUID();
    when(physicalInventoriesRepository.findOne(piId)).thenReturn(expectedInventory.toPhysicalInventoryForDraft());
    // when
    PhysicalInventoryDto response = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).pathParam("id", piId).when().get(ID_URL).then().statusCode(200).extract().as(expectedInventory.getClass());
    // then
    assertEquals(expectedInventory.getId(), response.getId());
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)28 Test (org.junit.Test)20 UUID (java.util.UUID)11 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)7 UUID.randomUUID (java.util.UUID.randomUUID)5 PhysicalInventoryLineItemDto (org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)3 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)3 List (java.util.List)2 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)2 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Random (java.util.Random)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 PhysicalInventoryLineItem (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem)1 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)1 ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS)1 ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED)1