use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project che-server by eclipse-che.
the class ResourceManager method getResourceDetails.
/**
* Returns detailed information about resources which given account can use.
*
* @param accountId account id
* @return detailed information about resources which can be used by given account
* @throws NotFoundException when account with specified id was not found
* @throws ServerException when some exception occurs
*/
public ResourcesDetails getResourceDetails(String accountId) throws NotFoundException, ServerException {
final List<ProvidedResources> resources = new ArrayList<>();
for (ResourcesProvider resourcesProvider : resourcesProviders) {
resources.addAll(resourcesProvider.getResources(accountId));
}
final List<Resource> allResources = resources.stream().flatMap(providedResources -> providedResources.getResources().stream()).collect(Collectors.toList());
return new ResourcesDetailsImpl(accountId, resources, new ArrayList<>(resourceAggregator.aggregateByType(allResources).values()));
}
use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project che-server by eclipse-che.
the class FreeResourcesProviderTest method shouldNotProvideDefaultResourcesForAccountIfDefaultResourcesProviderProvidesEmptyList.
@Test
public void shouldNotProvideDefaultResourcesForAccountIfDefaultResourcesProviderProvidesEmptyList() throws Exception {
// given
when(accountManager.getById(any())).thenReturn(account);
when(defaultResourcesProvider.getResources(any())).thenReturn(emptyList());
doThrow(new NotFoundException("not found")).when(freeResourcesLimitManager).get(any());
// when
List<ProvidedResources> result = provider.getResources("user123");
// then
assertTrue(result.isEmpty());
}
use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project che-server by eclipse-che.
the class FreeResourcesProviderTest method shouldProvideResourcesFromFreeResourcesLimitIfItExists.
@Test
public void shouldProvideResourcesFromFreeResourcesLimitIfItExists() throws Exception {
// given
when(account.getType()).thenReturn("anotherTestType");
when(accountManager.getById(any())).thenReturn(account);
when(freeResourcesLimitManager.get(any())).thenReturn(new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
// when
List<ProvidedResources> result = provider.getResources("account123");
// then
assertEquals(result.size(), 1);
ProvidedResources providedResources = result.get(0);
assertEquals(providedResources, new ProvidedResourcesImpl(FreeResourcesProvider.FREE_RESOURCES_PROVIDER, "account123", "account123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
verify(freeResourcesLimitManager).get("account123");
}
use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project che-server by eclipse-che.
the class FreeResourcesProviderTest method shouldRewriteDefaultResourcesWithFreeResourcesLimitIfItExists.
@Test
public void shouldRewriteDefaultResourcesWithFreeResourcesLimitIfItExists() throws Exception {
// given
when(accountManager.getById(any())).thenReturn(account);
when(freeResourcesLimitManager.get(any())).thenReturn(new FreeResourcesLimitImpl("user123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
// when
List<ProvidedResources> result = provider.getResources("user123");
// then
assertEquals(result.size(), 1);
ProvidedResources providedResources = result.get(0);
assertEquals(providedResources, new ProvidedResourcesImpl(FreeResourcesProvider.FREE_RESOURCES_PROVIDER, "user123", "user123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 12345, TEST_RESOURCE_UNIT))));
verify(freeResourcesLimitManager).get("user123");
}
use of org.eclipse.che.multiuser.resource.model.ProvidedResources in project che-server by eclipse-che.
the class FreeResourcesProviderTest method shouldProvideDefaultResourcesIfThereAreProviderForThisAccountType.
@Test
public void shouldProvideDefaultResourcesIfThereAreProviderForThisAccountType() throws Exception {
// given
when(accountManager.getById(any())).thenReturn(account);
when(freeResourcesLimitManager.get(any())).thenThrow(new NotFoundException("not found"));
when(defaultResourcesProvider.getResources(any())).thenReturn(singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1020, TEST_RESOURCE_UNIT)));
// when
List<ProvidedResources> result = provider.getResources("user123");
// then
assertEquals(result.size(), 1);
ProvidedResources providedResources = result.get(0);
assertEquals(providedResources, new ProvidedResourcesImpl(FreeResourcesProvider.FREE_RESOURCES_PROVIDER, null, "user123", -1L, -1L, singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1020, TEST_RESOURCE_UNIT))));
verify(freeResourcesLimitManager).get("user123");
}
Aggregations