Search in sources :

Example 6 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplatesControllerIntegrationTest method shouldReturn403WhenCreateTemplatePermissionNotFound.

@Test
public void shouldReturn403WhenCreateTemplatePermissionNotFound() throws Exception {
    // given
    Mockito.doThrow(new PermissionMessageException(new Message(ERROR_NO_FOLLOWING_PERMISSION, STOCK_CARD_TEMPLATES_MANAGE))).when(permissionService).canCreateStockCardTemplate();
    // when
    ResultActions resultActions = mvc.perform(post(STOCK_CARD_TEMPLATE_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardTemplate())));
    // then
    resultActions.andExpect(status().isForbidden());
}
Also used : StockCardTemplate(org.openlmis.stockmanagement.domain.template.StockCardTemplate) Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 7 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplatesControllerIntegrationTest method throwValidationExceptionWith.

private void throwValidationExceptionWith(String exceptionKey) throws Exception {
    // given
    Mockito.doThrow(new ValidationMessageException(new Message(exceptionKey, "some id"))).when(stockCardTemplateService).saveOrUpdate(any());
    // when
    ResultActions resultActions = mvc.perform(post(STOCK_CARD_TEMPLATE_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardTemplate())));
    // then
    resultActions.andExpect(status().isBadRequest());
}
Also used : StockCardTemplate(org.openlmis.stockmanagement.domain.template.StockCardTemplate) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) ResultActions(org.springframework.test.web.servlet.ResultActions)

Example 8 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class StockEventsControllerrIntegrationTest method shouldReturn403WhenUserHasNoPermissionToPerformPhysicalInventory.

@Test
public void shouldReturn403WhenUserHasNoPermissionToPerformPhysicalInventory() throws Exception {
    // given
    Mockito.doThrow(new PermissionMessageException(new Message(ERROR_NO_FOLLOWING_PERMISSION, STOCK_ADJUST))).when(permissionService).canEditPhysicalInventory(any(UUID.class), any(UUID.class));
    StockEventDto dto = createNoSourceDestinationStockEventDto();
    dto.getLineItems().get(0).setReasonId(null);
    shouldReject(dto);
}
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 9 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class StockEventsControllerrIntegrationTest method shouldReturn403WhenUserHomeFacilityDoesNotSupportProvidedProgram.

@Test
public void shouldReturn403WhenUserHomeFacilityDoesNotSupportProvidedProgram() throws Exception {
    // given
    StockEventDto eventDto = createNoSourceDestinationStockEventDto();
    Mockito.doThrow(new PermissionMessageException(new Message(ERROR_PROGRAM_NOT_SUPPORTED))).when(homeFacilityPermissionService).checkProgramSupported(eventDto.getProgramId());
    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) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 10 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldThrowPermissionExceptionIfUserHasNoPermissionToViewCard.

@Test(expected = PermissionMessageException.class)
public void shouldThrowPermissionExceptionIfUserHasNoPermissionToViewCard() throws Exception {
    // given
    StockEvent savedEvent = save(createStockEventDto(), randomUUID());
    doThrow(new PermissionMessageException(new Message("some error"))).when(permissionService).canViewStockCard(savedEvent.getProgramId(), savedEvent.getFacilityId());
    // when
    UUID savedCardId = stockCardRepository.findByOriginEvent(savedEvent).getId();
    stockCardService.findStockCardById(savedCardId);
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) Message(org.openlmis.stockmanagement.util.Message) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

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