use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class ResourceAggregatorTest method shouldThrowConflictExceptionWhenTotalResourcesDoNotHaveEnoughAmountToDeduct.
@Test(expectedExceptions = NoEnoughResourcesException.class)
public void shouldThrowConflictExceptionWhenTotalResourcesDoNotHaveEnoughAmountToDeduct() throws Exception {
// given
final ResourceImpl aResource = new ResourceImpl(A_RESOURCE_TYPE, 111, "unit");
final ResourceImpl anotherAResource = new ResourceImpl(A_RESOURCE_TYPE, 333, "unit");
when(aResourceType.deduct(any(), any())).thenThrow(new NoEnoughResourcesException(singletonList(aResource), singletonList(anotherAResource), singletonList(new ResourceImpl(A_RESOURCE_TYPE, 222, "unit"))));
// when
resourceAggregator.deduct(singletonList(aResource), singletonList(anotherAResource));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class ResourceAggregatorTest method shouldThrowIllegalArgumentExceptionWhenTotalResourcesListContainsNotSupportedResourceOnResourcesDeduction.
@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWhenTotalResourcesListContainsNotSupportedResourceOnResourcesDeduction() throws Exception {
// given
final ResourceImpl dResource = mock(ResourceImpl.class);
when(dResource.getType()).thenReturn("resourceD");
// when
resourceAggregator.deduct(emptyList(), singletonList(dResource));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
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 che-server by eclipse-che.
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 che-server by eclipse-che.
the class ResourceAggregatorTest method shouldThrowIllegalArgumentExceptionWhenFirstListContainsResourceWithUnsupportedTypeOnIntersection.
@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWhenFirstListContainsResourceWithUnsupportedTypeOnIntersection() throws Exception {
final ResourceImpl dResource = mock(ResourceImpl.class);
when(dResource.getType()).thenReturn("resourceD");
// when
resourceAggregator.intersection(singletonList(dResource), emptyList());
}
Aggregations