Search in sources :

Example 21 with Message

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());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 22 with Message

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);
}
Also used : Message(org.openlmis.stockmanagement.util.Message) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 23 with Message

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));
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockCardLineItemFieldDto(org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto)

Example 24 with Message

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);
    }
}
Also used : RightDto(org.openlmis.stockmanagement.dto.referencedata.RightDto) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Message(org.openlmis.stockmanagement.util.Message) UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException)

Example 25 with Message

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());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) StockCardSummariesV2SearchParams(org.openlmis.stockmanagement.service.StockCardSummariesV2SearchParams) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test) BaseWebTest(org.openlmis.stockmanagement.web.BaseWebTest)

Aggregations

Message (org.openlmis.stockmanagement.util.Message)35 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)19 Test (org.junit.Test)13 PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)13 ResultActions (org.springframework.test.web.servlet.ResultActions)9 UUID (java.util.UUID)8 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)6 StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto)4 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)4 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)3 IOException (java.io.IOException)2 JasperTemplate (org.openlmis.stockmanagement.domain.JasperTemplate)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)2 StockCardTemplate (org.openlmis.stockmanagement.domain.template.StockCardTemplate)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1