use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerrIntegrationTest method shouldReturn400WhenValidationFails.
@Test
public void shouldReturn400WhenValidationFails() throws Exception {
// given
Mockito.doThrow(new ValidationMessageException(new Message(ERROR_EVENT_QUANTITIES_INVALID))).when(stockEventProcessor).process(any());
// when
ResultActions resultActions = mvc.perform(post(CREATE_STOCK_EVENT_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockEventDto())));
// then
resultActions.andExpect(status().isBadRequest());
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class StockEventsControllerrIntegrationTest method shouldReturn403WhenUserHasNoPermissionToAdjustStock.
@Test
public void shouldReturn403WhenUserHasNoPermissionToAdjustStock() throws Exception {
// given
Mockito.doThrow(new PermissionMessageException(new Message(ERROR_NO_FOLLOWING_PERMISSION, STOCK_ADJUST))).when(permissionService).canAdjustStock(any(UUID.class), any(UUID.class));
StockEventDto eventDto = createNoSourceDestinationStockEventDto();
shouldReject(eventDto);
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class StockCardTemplateService method checkFieldsDuplication.
private void checkFieldsDuplication(StockCardTemplateDto templateDto) {
List<StockCardFieldDto> cardFields = templateDto.getStockCardFields();
long cardFieldCount = cardFields.stream().map(StockCardFieldDto::getName).distinct().count();
List<StockCardLineItemFieldDto> lineItemFields = templateDto.getStockCardLineItemFields();
long lineItemFieldCount = lineItemFields.stream().map(StockCardLineItemFieldDto::getName).distinct().count();
if (cardFieldCount < cardFields.size() || lineItemFieldCount < lineItemFields.size()) {
throw new ValidationMessageException(new Message(ERROR_STOCK_CARD_FIELD_DUPLICATED));
}
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class PermissionService method checkUserToken.
private ResultDto<Boolean> checkUserToken(String rightName, UUID program, UUID facility, UUID warehouse) {
UserDto user = authenticationHelper.getCurrentUser();
RightDto right = authenticationHelper.getRight(rightName);
try {
return userReferenceDataService.hasRight(user.getId(), right.getId(), program, facility, warehouse);
} catch (HttpClientErrorException httpException) {
throw new PermissionMessageException(new Message(ERROR_PERMISSION_CHECK_FAILED, httpException.getMessage()), httpException);
}
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesV2ControllerIntegrationTest method shouldReturnForbiddenIfNoPermission.
@Test
public void shouldReturnForbiddenIfNoPermission() throws Exception {
doThrow(new PermissionMessageException(new Message("no permission"))).when(stockCardSummariesService).findStockCards(any(StockCardSummariesV2SearchParams.class));
ResultActions resultActions = mvc.perform(get(API_STOCK_CARD_SUMMARIES).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).param(PAGE, String.valueOf(pageable.getPageNumber())).param(SIZE, String.valueOf(pageable.getPageSize())).param(PROGRAM_ID, params.getProgramId().toString()).param(FACILITY_ID, params.getFacilityId().toString()));
resultActions.andExpect(status().isForbidden());
}
Aggregations