Search in sources :

Example 6 with PermissionMessageException

use of org.openlmis.stockmanagement.exception.PermissionMessageException 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 7 with PermissionMessageException

use of org.openlmis.stockmanagement.exception.PermissionMessageException 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)

Example 8 with PermissionMessageException

use of org.openlmis.stockmanagement.exception.PermissionMessageException in project openlmis-stockmanagement by OpenLMIS.

the class ReasonConfigurationOptionsControllerIntegrationTest method shouldThrow403.

private void shouldThrow403(String api) throws Exception {
    // given
    doThrow(new PermissionMessageException(new Message("some error"))).when(permissionService).canManageReasons();
    // when
    ResultActions resultActions = mvc.perform(get(api).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE));
    // then
    resultActions.andExpect(status().isForbidden());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException)

Example 9 with PermissionMessageException

use of org.openlmis.stockmanagement.exception.PermissionMessageException in project openlmis-stockmanagement by OpenLMIS.

the class StockCardControllerIntegrationTest method shouldReturn403WhenUserDoesNotHavePermissionToViewCardSummaries.

@Test
public void shouldReturn403WhenUserDoesNotHavePermissionToViewCardSummaries() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    doThrow(new PermissionMessageException(new Message("no permission"))).when(permissionService).canViewStockCard(programId, facilityId);
    // when
    ResultActions resultActions = mvc.perform(get(API_STOCK_CARD_SUMMARIES).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).param("program", programId.toString()).param("facility", facilityId.toString()));
    // then
    resultActions.andExpect(status().isForbidden());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 10 with PermissionMessageException

use of org.openlmis.stockmanagement.exception.PermissionMessageException 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)

Aggregations

PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)13 Message (org.openlmis.stockmanagement.util.Message)13 Test (org.junit.Test)11 ResultActions (org.springframework.test.web.servlet.ResultActions)7 UUID (java.util.UUID)5 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)3 StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto)3 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)3 UUID.randomUUID (java.util.UUID.randomUUID)1 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)1 Organization (org.openlmis.stockmanagement.domain.sourcedestination.Organization)1 StockCardTemplate (org.openlmis.stockmanagement.domain.template.StockCardTemplate)1 RightDto (org.openlmis.stockmanagement.dto.referencedata.RightDto)1 UserDto (org.openlmis.stockmanagement.dto.referencedata.UserDto)1 StockCardSummariesV2SearchParams (org.openlmis.stockmanagement.service.StockCardSummariesV2SearchParams)1 StockCardSummariesV2SearchParamsDataBuilder (org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder)1 BaseWebTest (org.openlmis.stockmanagement.web.BaseWebTest)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1