Search in sources :

Example 21 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class ResourceAggregatorTest method shouldNotReturnResourceAsExcessiveWhenResourcesHaveTheSameAmount.

@Test
public void shouldNotReturnResourceAsExcessiveWhenResourcesHaveTheSameAmount() throws Exception {
    // given
    final ResourceImpl sourceAResource = new ResourceImpl(A_RESOURCE_TYPE, 5, "unit");
    final ResourceImpl toCompareAResource = new ResourceImpl(A_RESOURCE_TYPE, 5, "unit");
    // when
    List<? extends Resource> excess = resourceAggregator.excess(singletonList(sourceAResource), singletonList(toCompareAResource));
    // then
    assertTrue(excess.isEmpty());
    verify(aResourceType, never()).deduct(any(), any());
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 22 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class ResourceAggregatorTest method shouldThrowIllegalArgumentExceptionWhenSecondListContainsResourceWithUnsupportedTypeExcessCalculation.

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

Example 23 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

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 24 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class ResourceAggregatorTest method shouldNotReturnResourceAsExcessiveWhenToCompareResourceIsGreaterThanSource.

@Test
public void shouldNotReturnResourceAsExcessiveWhenToCompareResourceIsGreaterThanSource() throws Exception {
    // given
    final ResourceImpl sourceAResource = new ResourceImpl(A_RESOURCE_TYPE, 5, "unit");
    final ResourceImpl toCompareAResource = new ResourceImpl(A_RESOURCE_TYPE, 10, "unit");
    doThrow(new NoEnoughResourcesException(emptyList(), emptyList(), emptyList())).when(aResourceType).deduct(any(), any());
    // when
    List<? extends Resource> excess = resourceAggregator.excess(singletonList(sourceAResource), singletonList(toCompareAResource));
    // then
    assertTrue(excess.isEmpty());
    verify(aResourceType).deduct(sourceAResource, toCompareAResource);
}
Also used : NoEnoughResourcesException(org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 25 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class ResourceAggregatorTest method shouldReturnResourceAsExcessiveWhenDeductedAmountGreaterThan0.

@Test
public void shouldReturnResourceAsExcessiveWhenDeductedAmountGreaterThan0() throws Exception {
    // given
    final ResourceImpl sourceAResource = new ResourceImpl(A_RESOURCE_TYPE, 5, "unit");
    final ResourceImpl toCompareAResource = new ResourceImpl(A_RESOURCE_TYPE, 3, "unit");
    final ResourceImpl excessiveAResource = new ResourceImpl(A_RESOURCE_TYPE, 2, "unit");
    when(aResourceType.deduct(any(), any())).thenReturn(excessiveAResource);
    // when
    List<? extends Resource> excess = resourceAggregator.excess(singletonList(sourceAResource), singletonList(toCompareAResource));
    // then
    assertEquals(excess.size(), 1);
    assertTrue(excess.contains(excessiveAResource));
    verify(aResourceType).deduct(sourceAResource, toCompareAResource);
}
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