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