Search in sources :

Example 1 with FreeResourcesLimitImpl

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

the class FreeResourcesLimitServiceTest method shouldReturnResourcesLimits.

@Test
public void shouldReturnResourcesLimits() throws Exception {
    FreeResourcesLimit resourcesLimit1 = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    FreeResourcesLimit resourcesLimit2 = new FreeResourcesLimitImpl("account321", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 2000, "unit")));
    doReturn(new Page<>(Arrays.asList(resourcesLimit1, resourcesLimit2), 1, 2, 2)).when(freeResourcesLimitManager).getAll(anyInt(), anyInt());
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/free?skipCount=1&maxItems=5");
    assertEquals(response.statusCode(), 200);
    final List<FreeResourcesLimitDto> freeResourcesLimits = unwrapDtoList(response, FreeResourcesLimitDto.class);
    assertEquals(freeResourcesLimits.size(), 2);
    assertTrue(freeResourcesLimits.contains(DtoConverter.asDto(resourcesLimit1)));
    assertTrue(freeResourcesLimits.contains(DtoConverter.asDto(resourcesLimit2)));
    verify(freeResourcesLimitManager).getAll(5, 1);
}
Also used : Response(io.restassured.response.Response) FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) FreeResourcesLimit(org.eclipse.che.multiuser.resource.model.FreeResourcesLimit) FreeResourcesLimitDto(org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto) Test(org.testng.annotations.Test)

Example 2 with FreeResourcesLimitImpl

use of org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl 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");
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) Test(org.testng.annotations.Test)

Example 3 with FreeResourcesLimitImpl

use of org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl 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");
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) Test(org.testng.annotations.Test)

Example 4 with FreeResourcesLimitImpl

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

the class FreeResourceManagerTest method shouldStoreFreeResourcesLimit.

@Test
public void shouldStoreFreeResourcesLimit() throws Exception {
    // given
    ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
    FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
    ResourceDto resourceDto = DtoFactory.newDto(ResourceDto.class).withAmount(1).withType(TEST_RESOURCE_TYPE).withUnit("unit");
    FreeResourcesLimitDto freeResourcesLimitDto = DtoFactory.newDto(FreeResourcesLimitDto.class).withAccountId("account123").withResources(singletonList(resourceDto));
    // when
    FreeResourcesLimit storedLimit = manager.store(freeResourcesLimitDto);
    // then
    assertEquals(storedLimit, resourcesLimitImpl);
    verify(freeResourcesLimitDao).store(resourcesLimitImpl);
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) FreeResourcesLimit(org.eclipse.che.multiuser.resource.model.FreeResourcesLimit) FreeResourcesLimitDto(org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto) ResourceDto(org.eclipse.che.multiuser.resource.shared.dto.ResourceDto) Test(org.testng.annotations.Test)

Example 5 with FreeResourcesLimitImpl

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

the class JpaFreeResourcesLimitDao method doStore.

@Transactional(rollbackOn = { RuntimeException.class, ConflictException.class })
protected void doStore(FreeResourcesLimitImpl resourcesLimit) throws ConflictException {
    EntityManager manager = managerProvider.get();
    try {
        final FreeResourcesLimitImpl existedLimit = doGet(resourcesLimit.getAccountId());
        existedLimit.setResources(resourcesLimit.getResources());
        manager.flush();
    } catch (NoResultException n) {
        try {
            manager.persist(resourcesLimit);
            manager.flush();
        } catch (IntegrityConstraintViolationException e) {
            throw new ConflictException(format("The specified account '%s' does not exist", resourcesLimit.getAccountId()));
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ConflictException(org.eclipse.che.api.core.ConflictException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Aggregations

FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)40 Test (org.testng.annotations.Test)26 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)20 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)10 AccountImpl (org.eclipse.che.account.spi.AccountImpl)8 TypeLiteral (com.google.inject.TypeLiteral)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 Response (io.restassured.response.Response)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)6 DBInitializer (org.eclipse.che.core.db.DBInitializer)6 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)6 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)6 FreeResourcesLimitDao (org.eclipse.che.multiuser.resource.spi.FreeResourcesLimitDao)6 JpaFreeResourcesLimitDao (org.eclipse.che.multiuser.resource.spi.jpa.JpaFreeResourcesLimitDao)6 HashMap (java.util.HashMap)4 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)4 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 SystemPermissionsImpl (org.eclipse.che.multiuser.api.permission.server.model.impl.SystemPermissionsImpl)4 SystemPermissionsDaoTest (org.eclipse.che.multiuser.api.permission.server.spi.tck.SystemPermissionsDaoTest)4