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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations