use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class ResourceAggregatorTest method shouldThrowIllegalArgumentExceptionWhenResourcesToDeductListContainsNotSupportedResourceOnResourcesDeduction.
@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWhenResourcesToDeductListContainsNotSupportedResourceOnResourcesDeduction() throws Exception {
// given
final ResourceImpl dResource = mock(ResourceImpl.class);
when(dResource.getType()).thenReturn("resourceD");
// when
resourceAggregator.deduct(singletonList(dResource), emptyList());
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class ResourceAggregatorTest method shouldReturnMinResources.
@Test
public void shouldReturnMinResources() throws Exception {
// given
final ResourceImpl aResource = new ResourceImpl(A_RESOURCE_TYPE, 100, "unit");
final ResourceImpl bResource = new ResourceImpl(B_RESOURCE_TYPE, 1000, "unit");
final ResourceImpl minBResource = new ResourceImpl(B_RESOURCE_TYPE, 500, "unit");
final ResourceImpl anotherBResource = new ResourceImpl(B_RESOURCE_TYPE, 2000, "unit");
// when
List<? extends Resource> min = resourceAggregator.min(asList(aResource, bResource, minBResource, anotherBResource));
// then
assertEquals(min.size(), 2);
assertTrue(min.contains(aResource));
assertTrue(min.contains(minBResource));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class FreeResourceManagerTest method shouldStoreFreeResourcesLimit.
@Test
public void shouldStoreFreeResourcesLimit() throws Exception {
// given
ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
ResourceDto resourceDto = DtoFactory.newDto(ResourceDto.class).withAmount(1).withType(TEST_RESOURCE_TYPE).withUnit("unit");
FreeResourcesLimitDto freeResourcesLimitDto = DtoFactory.newDto(FreeResourcesLimitDto.class).withAccountId("account123").withResources(singletonList(resourceDto));
// when
FreeResourcesLimit storedLimit = manager.store(freeResourcesLimitDto);
// then
assertEquals(storedLimit, resourcesLimitImpl);
verify(freeResourcesLimitDao).store(resourcesLimitImpl);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class FreeResourcesProvider method getResources.
@Override
public List<ProvidedResources> getResources(String accountId) throws ServerException, NotFoundException {
Map<String, ResourceImpl> freeResources = new HashMap<>();
String limitId = null;
try {
FreeResourcesLimit resourcesLimit = freeResourcesLimitManager.get(accountId);
for (Resource resource : resourcesLimit.getResources()) {
freeResources.put(resource.getType(), new ResourceImpl(resource));
}
limitId = resourcesLimit.getAccountId();
} catch (NotFoundException ignored) {
// there is no resources limit for given account
}
// add default resources which are not specified by limit
for (ResourceImpl resource : getDefaultResources(accountId)) {
freeResources.putIfAbsent(resource.getType(), resource);
}
if (!freeResources.isEmpty()) {
return singletonList(new ProvidedResourcesImpl(FREE_RESOURCES_PROVIDER, limitId, accountId, -1L, -1L, freeResources.values()));
} else {
return emptyList();
}
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class FreeResourcesProvider method getDefaultResources.
private List<ResourceImpl> getDefaultResources(String accountId) throws NotFoundException, ServerException {
List<ResourceImpl> defaultResources = new ArrayList<>();
final Account account = accountManager.getById(accountId);
final DefaultResourcesProvider defaultResourcesProvider = defaultResourcesProviders.get(account.getType());
if (defaultResourcesProvider != null) {
defaultResources.addAll(defaultResourcesProvider.getResources(accountId));
}
return defaultResources;
}
Aggregations