use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonServiceTest method shouldThrowValidationExceptionWithUnavailableReasonDto.
@Test(expected = ValidationMessageException.class)
public void shouldThrowValidationExceptionWithUnavailableReasonDto() throws Exception {
// given
StockCardLineItemReason reason = new StockCardLineItemReason();
// when
reasonService.saveOrUpdate(reason);
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonServiceTest method shouldThrowExceptionWhenCreatingReasonNameIsDuplicateWithOtherOne.
@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenCreatingReasonNameIsDuplicateWithOtherOne() throws Exception {
// given
StockCardLineItemReason creatingReason = new StockCardLineItemReasonDataBuilder().withoutId().build();
StockCardLineItemReason existingReason = new StockCardLineItemReasonDataBuilder().build();
when(reasonRepository.findByName(creatingReason.getName())).thenReturn(existingReason);
// when
reasonService.saveOrUpdate(creatingReason);
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class ReceiveIssueReasonValidator method checkReason.
private void checkReason(StockEventDto event, StockEventLineItemDto lineItem, ReasonType expectedReasonType, String typeErrorKey, String categoryErrorKey) {
if (lineItem.hasReasonId()) {
StockCardLineItemReason foundReason = event.getContext().findEventReason(lineItem.getReasonId());
// that is handled by other validators
if (foundReason != null) {
checkReasonType(expectedReasonType, typeErrorKey, lineItem.getReasonId(), foundReason);
checkReasonCategory(categoryErrorKey, lineItem.getReasonId(), foundReason);
}
}
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemTest method shouldNotIncreaseSohOverIntLimit.
@Test
public void shouldNotIncreaseSohOverIntLimit() throws Exception {
// expect
exception.expectMessage("exceed.upperLimit");
// given
StockCardLineItemReason creditReason = StockCardLineItemReason.builder().reasonType(ReasonType.CREDIT).build();
int quantityToAdd = 10;
StockCardLineItem lineItem = StockCardLineItem.builder().reason(creditReason).quantity(quantityToAdd).build();
// when
lineItem.calculateStockOnHand(MAX_VALUE - quantityToAdd + 1);
}
use of org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason in project openlmis-stockmanagement by OpenLMIS.
the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn403WhenUserHasNoPermissionToManageReasons.
@Test
public void shouldReturn403WhenUserHasNoPermissionToManageReasons() throws Exception {
doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canManageReasons();
// 1.create reason
ResultActions postResults = mvc.perform(MockMvcRequestBuilders.post(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardLineItemReason())));
postResults.andExpect(status().isForbidden());
// 2.update reason
ResultActions putResults = mvc.perform(MockMvcRequestBuilders.put(STOCK_CARD_LINE_ITEM_REASON_API + "/" + UUID.randomUUID().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardLineItemReason())));
putResults.andExpect(status().isForbidden());
}
Aggregations