OrganizationResourcesDistributor { public void capResources(String suborganizationId, List<? extends Resource> resourcesCaps) throws NotFoundException, ConflictException, ServerException { requireNonNull(suborganizationId, "Required non-null suborganization id"); requireNonNull(resourcesCaps, "Required non-null resources to capResources"); checkIsSuborganization(suborganizationId); resourcesCaps = resourcesCaps.stream().filter(res -> res.getAmount() != -1).collect(toList()); try (@SuppressWarnings("unused") Unlocker u = resourcesLocks.lock(suborganizationId)) { if (resourcesCaps.isEmpty()) { organizationDistributedResourcesDao.remove(suborganizationId); } else { checkResourcesAvailability(suborganizationId, resourcesCaps); organizationDistributedResourcesDao.store( new OrganizationDistributedResourcesImpl(suborganizationId, resourcesCaps)); } } } @Inject  OrganizationResourcesDistributor(
      OrganizationDistributedResourcesDao organizationDistributedResourcesDao,
      OrganizationManager organizationManager,
      ResourcesLocks resourcesLocks,
      ResourceManager resourceManager,
      ResourceAggregator resourceAggregator); @Inject void subscribe(EventService eventService); void capResources(String suborganizationId, List<? extends Resource> resourcesCaps); List<? extends Resource> getResourcesCaps(String suborganizationId); OrganizationDistributedResources get(String suborganizationId); Page<? extends OrganizationDistributedResources> getByParent(
      String organizationId, int maxItems, long skipCount);  }
@Test( expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "It is not allowed to cap resources for root organization.") public void shouldThrowConflictExceptionOnCappingResourcesForRootOrganization() throws Exception { manager.capResources(PARENT_ORG_ID, Collections.emptyList()); }
@Test(expectedExceptions = NullPointerException.class) public void shouldThrowNpeOnDistributionResourcesWithNullOrganizationId() throws Exception { manager.capResources(null, emptyList()); }
@Test(expectedExceptions = NullPointerException.class) public void shouldThrowNpeOnDistributionNullResourcesList() throws Exception { manager.capResources(ORG_ID, null); }