Search in sources :

Example 26 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonServiceTest method shouldThrowExceptionWhenUpdatingReasonNameIsDuplicateWithOtherOne.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenUpdatingReasonNameIsDuplicateWithOtherOne() throws Exception {
    // given
    StockCardLineItemReason updatingReason = new StockCardLineItemReasonDataBuilder().build();
    StockCardLineItemReason existingReason = new StockCardLineItemReasonDataBuilder().build();
    when(reasonRepository.findByName(updatingReason.getName())).thenReturn(existingReason);
    // when
    reasonService.saveOrUpdate(updatingReason);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Example 27 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonServiceTest method shouldSaveReasonWhenPassNullValueValidation.

@Test
public void shouldSaveReasonWhenPassNullValueValidation() throws Exception {
    // when
    StockCardLineItemReason reason = new StockCardLineItemReasonDataBuilder().withoutId().build();
    reasonService.saveOrUpdate(reason);
    // then
    verify(reasonRepository, times(1)).save(reason);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockCardLineItemReasonDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder) Test(org.junit.Test)

Example 28 with StockCardLineItemReason

use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.

the class FreeTextValidatorTest method shouldFailWhenReasonFreeTextNotAllowedButExist.

@Test
public void shouldFailWhenReasonFreeTextNotAllowedButExist() throws Exception {
    StockCardLineItemReason mockReason = mock(StockCardLineItemReason.class);
    when(reasonRepository.findOne(any(UUID.class))).thenReturn(mockReason);
    when(mockReason.getIsFreeTextAllowed()).thenReturn(false);
    StockEventDto eventDto = createNoSourceDestinationStockEventDto();
    eventDto.getLineItems().get(0).setReasonId(fromString("e3fc3cf3-da18-44b0-a220-77c985202e06"));
    eventDto.getLineItems().get(0).setReasonFreeText("reason free text");
    setContext(eventDto);
    exception.expect(ValidationMessageException.class);
    exception.expectMessage(containsString(ERROR_REASON_FREE_TEXT_NOT_ALLOWED));
    freeTextValidator.validate(eventDto);
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Aggregations

StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)28 Test (org.junit.Test)18 StockCardLineItemReasonDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemReasonDataBuilder)8 ResultActions (org.springframework.test.web.servlet.ResultActions)6 UUID (java.util.UUID)4 ValidReasonAssignment (org.openlmis.stockmanagement.domain.reason.ValidReasonAssignment)4 UUID.randomUUID (java.util.UUID.randomUUID)3 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)3 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)2 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)2 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)2 ValidReasonAssignmentDto (org.openlmis.stockmanagement.dto.ValidReasonAssignmentDto)2 Profiler (org.slf4j.profiler.Profiler)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 List (java.util.List)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 PhysicalInventoryLineItemAdjustment (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItemAdjustment)1 ValidDestinationAssignment (org.openlmis.stockmanagement.domain.sourcedestination.ValidDestinationAssignment)1