Search in sources :

Example 1 with PermissionMessageException

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

the class StockCardSummariesServiceTest method shouldThrowExceptionIfNoPermission.

@Test(expected = PermissionMessageException.class)
public void shouldThrowExceptionIfNoPermission() {
    StockCardSummariesV2SearchParams params = new StockCardSummariesV2SearchParamsDataBuilder().build();
    doThrow(new PermissionMessageException(new Message("no permission"))).when(permissionService).canViewStockCard(params.getProgramId(), params.getFacilityId());
    stockCardSummariesService.findStockCards(params);
}
Also used : Message(org.openlmis.stockmanagement.util.Message) StockCardSummariesV2SearchParamsDataBuilder(org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 2 with PermissionMessageException

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

the class ReportsControllerIntegrationTest method return403WhenUserHasNoPermissionToViewStockCard.

@Test
public void return403WhenUserHasNoPermissionToViewStockCard() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canViewStockCard(programId, facilityId);
    // when
    ResultActions resultActions = mvc.perform(get(CARD_SUMMARY_REPORT).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 3 with PermissionMessageException

use of org.openlmis.stockmanagement.exception.PermissionMessageException 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());
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 4 with PermissionMessageException

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

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

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