Search in sources :

Example 56 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class ResourceAggregatorTest method shouldReturnIntersectionOfTwoResourcesLists.

@Test
public void shouldReturnIntersectionOfTwoResourcesLists() throws Exception {
    // given
    final ResourceImpl aResource = new ResourceImpl(A_RESOURCE_TYPE, 123, "unit");
    final ResourceImpl bResource = new ResourceImpl(B_RESOURCE_TYPE, 123, "unit");
    final ResourceImpl anotherBResource = new ResourceImpl(B_RESOURCE_TYPE, 321, "unit");
    final ResourceImpl cResource = new ResourceImpl(C_RESOURCE_TYPE, 321, "unit");
    // when
    List<? extends Resource> intersection = resourceAggregator.intersection(asList(aResource, bResource), asList(anotherBResource, cResource));
    // then
    assertEquals(intersection.size(), 2);
    assertTrue(intersection.contains(bResource));
    assertTrue(intersection.contains(anotherBResource));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 57 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class ResourceAggregatorTest method shouldThrowConflictExceptionWhenTotalResourcesDoNotContainsRequiredResourcesAtAll.

@Test(expectedExceptions = NoEnoughResourcesException.class)
public void shouldThrowConflictExceptionWhenTotalResourcesDoNotContainsRequiredResourcesAtAll() throws Exception {
    // given
    final ResourceImpl aResource = new ResourceImpl(A_RESOURCE_TYPE, 123, "unit");
    final ResourceImpl bResource = new ResourceImpl(B_RESOURCE_TYPE, 321, "unit");
    // when
    resourceAggregator.deduct(singletonList(aResource), singletonList(bResource));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 58 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class ResourceAggregatorTest method shouldThrowIllegalArgumentExceptionWhenTryingToAggregateNotSupportedResource.

@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWhenTryingToAggregateNotSupportedResource() throws Exception {
    // given
    final ResourceImpl dResource = mock(ResourceImpl.class);
    when(dResource.getType()).thenReturn("resourceD");
    // when
    resourceAggregator.aggregateByType(singletonList(dResource));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 59 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class ResourceAggregatorTest method shouldTestResourcesAggregationByTypes.

@Test
public void shouldTestResourcesAggregationByTypes() throws Exception {
    // given
    final ResourceImpl aResource = new ResourceImpl(A_RESOURCE_TYPE, 123, "unit");
    final ResourceImpl bResource = new ResourceImpl(B_RESOURCE_TYPE, 123, "unit");
    final ResourceImpl anotherBResource = new ResourceImpl(B_RESOURCE_TYPE, 321, "unit");
    final ResourceImpl aggregatedBResources = new ResourceImpl(B_RESOURCE_TYPE, 444, "unit");
    when(bResourceType.aggregate(any(), any())).thenReturn(aggregatedBResources);
    // when
    final Map<String, Resource> aggregatedResources = resourceAggregator.aggregateByType(asList(aResource, bResource, anotherBResource));
    // then
    verify(bResourceType).aggregate(eq(bResource), eq(anotherBResource));
    verify(aResourceType, never()).aggregate(any(), any());
    assertEquals(aggregatedResources.size(), 2);
    assertTrue(aggregatedResources.containsKey(A_RESOURCE_TYPE));
    assertTrue(aggregatedResources.containsValue(aResource));
    assertTrue(aggregatedResources.containsKey(B_RESOURCE_TYPE));
    assertTrue(aggregatedResources.containsValue(aggregatedBResources));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) Test(org.testng.annotations.Test)

Example 60 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class ResourceAggregatorTest method shouldReturnMinResourcesWhenTheyContainsMinusOneValue.

@Test
public void shouldReturnMinResourcesWhenTheyContainsMinusOneValue() throws Exception {
    // given
    final ResourceImpl aResource = new ResourceImpl(A_RESOURCE_TYPE, -1, "unit");
    final ResourceImpl bResource = new ResourceImpl(B_RESOURCE_TYPE, -1, "unit");
    final ResourceImpl minAResource = new ResourceImpl(A_RESOURCE_TYPE, 250, "unit");
    final ResourceImpl minBResource = new ResourceImpl(B_RESOURCE_TYPE, 500, "unit");
    // when
    List<? extends Resource> min = resourceAggregator.min(asList(aResource, minAResource, minBResource, bResource));
    // then
    assertEquals(min.size(), 2);
    assertTrue(min.contains(minAResource));
    assertTrue(min.contains(minBResource));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Aggregations

ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)138 Test (org.testng.annotations.Test)116 Resource (org.eclipse.che.multiuser.resource.model.Resource)24 NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)20 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)20 ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)14 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)12 NotFoundException (org.eclipse.che.api.core.NotFoundException)10 AccountManager (org.eclipse.che.account.api.AccountManager)8 Account (org.eclipse.che.account.shared.model.Account)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)8 ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)8 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)8 Response (io.restassured.response.Response)6 Optional (java.util.Optional)6 Inject (javax.inject.Inject)6 Provider (javax.inject.Provider)6 Singleton (javax.inject.Singleton)6 Pages (org.eclipse.che.api.core.Pages)6