Search in sources :

Example 36 with FreeResourcesLimitImpl

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

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)

Example 37 with FreeResourcesLimitImpl

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

the class FreeResourceManagerTest method shouldReturnFreeResourcesLimitForSpecifiedAccount.

@Test
public void shouldReturnFreeResourcesLimitForSpecifiedAccount() throws Exception {
    // given
    ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
    FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
    when(freeResourcesLimitDao.get(any())).thenReturn(resourcesLimitImpl);
    // when
    FreeResourcesLimit fetchedLimit = manager.get("account123");
    // then
    assertEquals(fetchedLimit, resourcesLimitImpl);
    verify(freeResourcesLimitDao).get("account123");
}
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) Test(org.testng.annotations.Test)

Example 38 with FreeResourcesLimitImpl

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

the class FreeResourcesLimitServiceTest method shouldStoreResourcesLimit.

@Test
public void shouldStoreResourcesLimit() throws Exception {
    FreeResourcesLimit toCreate = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    FreeResourcesLimit created = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    when(freeResourcesLimitManager.store(any())).thenReturn(created);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(DtoConverter.asDto(toCreate)).when().post(SECURE_PATH + "/resource/free");
    assertEquals(response.statusCode(), 201);
    final FreeResourcesLimitDto result = unwrapDto(response, FreeResourcesLimitDto.class);
    assertEquals(DtoConverter.asDto(created), result);
    verify(freeResourcesLimitManager).store(DtoConverter.asDto(toCreate));
    verify(resourcesLimitValidator).check(any());
}
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 39 with FreeResourcesLimitImpl

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

the class FreeResourcesLimitServiceTest method shouldReturnResourcesLimitForGivenAccount.

@Test
public void shouldReturnResourcesLimitForGivenAccount() throws Exception {
    FreeResourcesLimit resourcesLimit = new FreeResourcesLimitImpl("account123", singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    when(freeResourcesLimitManager.get("account123")).thenReturn(resourcesLimit);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/resource/free/account123");
    assertEquals(response.statusCode(), 200);
    final FreeResourcesLimitDto fetchedLimit = unwrapDto(response, FreeResourcesLimitDto.class);
    assertEquals(fetchedLimit, DtoConverter.asDto(resourcesLimit));
    verify(freeResourcesLimitManager).get("account123");
}
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 40 with FreeResourcesLimitImpl

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

the class FreeResourcesLimitManager method store.

/**
 * Stores (creates new one or updates existed) free resource limit.
 *
 * @param freeResourcesLimit resources limit to store
 * @return stored resources limit
 * @throws NullPointerException when {@code freeResourcesLimit} is null
 * @throws NotFoundException when resources limit contains resource with non supported type
 * @throws ConflictException when the specified account doesn't exist
 * @throws ServerException when any other error occurs
 */
public FreeResourcesLimit store(FreeResourcesLimit freeResourcesLimit) throws NotFoundException, ConflictException, ServerException {
    requireNonNull(freeResourcesLimit, "Required non-null free resources limit");
    final FreeResourcesLimitImpl toStore = new FreeResourcesLimitImpl(freeResourcesLimit);
    freeResourcesLimitDao.store(toStore);
    return toStore;
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)

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