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));
}
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));
}
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));
}
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));
}
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));
}
Aggregations