PermissionsManager { public void storePermission(Permissions permissions) throws ServerException, ConflictException, NotFoundException { final String domainId = permissions.getDomainId(); final String instanceId = permissions.getInstanceId(); final String userId = permissions.getUserId(); try (@SuppressWarnings("unused") Unlocker unlocker = updateLocks.writeLock(firstNonNull(instanceId, domainId))) { final PermissionsDao<? extends AbstractPermissions> permissionsDao = getPermissionsDao(domainId); if (!permissions.getActions().contains(SET_PERMISSIONS) && userHasLastSetPermissions(permissionsDao, userId, instanceId)) { throw new ConflictException( "Can't edit permissions because there is not any another user " + "with permission 'setPermissions'"); } store(permissionsDao, userId, instanceId, permissions); } } @Inject  PermissionsManager(
      EventService eventService, Set<PermissionsDao<? extends AbstractPermissions>> daos); void storePermission(Permissions permissions); AbstractPermissions get(String userId, String domainId, String instanceId); @SuppressWarnings("unchecked") Page<AbstractPermissions> getByInstance(
      String domainId, String instanceId, int maxItems, long skipCount); void remove(String userId, String domainId, String instanceId); boolean exists(String userId, String domainId, String instanceId, String action); void checkActionsSupporting(String domainId, List<String> actions); List<AbstractPermissionsDomain> getDomains(); AbstractPermissionsDomain<? extends AbstractPermissions> getDomain(String domain);  }
@Test( expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Domain with id 'test' doesn't support following action\\(s\\): unsupported") public void shouldNotStorePermissionsWhenItHasUnsupportedAction() throws Exception { final Permissions permissions = DtoFactory.newDto(PermissionsDto.class) .withUserId("user") .withDomainId("test") .withInstanceId("test123") .withActions(singletonList("unsupported")); permissionsManager.storePermission(permissions); }