Search in sources :

Example 16 with PhysicalInventoryDto

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

the class PhysicalInventoryValidatorTest method shouldRejectWhenIdMismatch.

@Test(expected = ValidationMessageException.class)
public void shouldRejectWhenIdMismatch() {
    PhysicalInventoryDto inventory = newInventory();
    validator.validateDraft(inventory, randomUUID());
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) Test(org.junit.Test)

Example 17 with PhysicalInventoryDto

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

the class PhysicalInventoryValidatorTest method shouldRejectWhenEmptyDraftHasNoProgram.

@Test(expected = ValidationMessageException.class)
public void shouldRejectWhenEmptyDraftHasNoProgram() {
    PhysicalInventoryDto physicalInventoryDto = new PhysicalInventoryDto();
    physicalInventoryDto.setFacilityId(UUID.randomUUID());
    validator.validateEmptyDraft(physicalInventoryDto);
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) Test(org.junit.Test)

Example 18 with PhysicalInventoryDto

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

the class PhysicalInventoryControllerIntegrationTest method shouldCreateEmptyDraftWhenValid.

// POST /api/physicalInventories
@Test
public void shouldCreateEmptyDraftWhenValid() {
    // given
    PhysicalInventoryDto request = generateDraft();
    PhysicalInventoryDto expectedDraft = new PhysicalInventoryDto();
    expectedDraft.setProgramId(request.getProgramId());
    expectedDraft.setFacilityId(request.getFacilityId());
    expectedDraft.setId(UUID.randomUUID());
    when(physicalInventoryService.createNewDraft(request)).thenReturn(expectedDraft);
    // when
    PhysicalInventoryDto result = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).body(request).when().post(RESOURCE_URL).then().statusCode(201).extract().as(PhysicalInventoryDto.class);
    // then
    assertEquals(expectedDraft, result);
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) Test(org.junit.Test)

Example 19 with PhysicalInventoryDto

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

the class PhysicalInventoryControllerIntegrationTest method shouldSaveDraftWhenValid.

// PUT /api/physicalInventories/{id}
@Test
public void shouldSaveDraftWhenValid() {
    // given
    UUID physicalInventoryId = UUID.randomUUID();
    PhysicalInventoryDto expectedDraft = generatePhysicalInventory();
    when(physicalInventoryService.saveDraft(expectedDraft, physicalInventoryId)).thenReturn(expectedDraft);
    // when
    PhysicalInventoryDto result = restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).pathParam("id", physicalInventoryId).contentType(APPLICATION_JSON).body(expectedDraft).when().put(ID_URL).then().statusCode(200).extract().as(PhysicalInventoryDto.class);
    // then
    assertEquals(expectedDraft, result);
    assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Also used : PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with PhysicalInventoryDto

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

the class PhysicalInventoryValidatorTest method shouldRejectWhenLineItemHasNoOrderable.

@Test(expected = ValidationMessageException.class)
public void shouldRejectWhenLineItemHasNoOrderable() {
    // given
    PhysicalInventoryDto inventory = newInventory();
    inventory.setLineItems(Collections.singletonList(new PhysicalInventoryLineItemDto()));
    doNothing().when(vvmValidator).validate(eq(inventory.getLineItems()), anyString(), eq(false));
    // when
    validator.validateDraft(inventory, inventory.getId());
    // then
    verify(vvmValidator, atLeastOnce()).validate(eq(inventory.getLineItems()), anyString(), eq(false));
}
Also used : PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) 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