Search in sources :

Example 41 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.

the class JpaUserDevfileDao method doRemove.

@Transactional(rollbackOn = { RuntimeException.class, ServerException.class })
protected void doRemove(String id) throws ServerException {
    final EntityManager manager = managerProvider.get();
    final UserDevfileImpl devfile = manager.find(UserDevfileImpl.class, id);
    if (devfile != null) {
        eventService.publish(new BeforeDevfileRemovedEvent(new UserDevfileImpl(devfile))).propagateException();
        manager.remove(devfile);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) BeforeDevfileRemovedEvent(org.eclipse.che.api.devfile.server.event.BeforeDevfileRemovedEvent) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Transactional(com.google.inject.persist.Transactional)

Example 42 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.

the class JpaUserDevfileDao method getByNamespace.

@Transactional(rollbackOn = { ServerException.class, RuntimeException.class })
@Override
public Page<UserDevfile> getByNamespace(String namespace, int maxItems, long skipCount) throws ServerException {
    requireNonNull(namespace, "Required non-null namespace");
    try {
        final EntityManager manager = managerProvider.get();
        final List<UserDevfileImpl> list = manager.createNamedQuery("UserDevfile.getByNamespace", UserDevfileImpl.class).setParameter("namespace", namespace).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList().stream().map(UserDevfileImpl::new).collect(Collectors.toList());
        final long count = manager.createNamedQuery("UserDevfile.getByNamespaceCount", Long.class).setParameter("namespace", namespace).getSingleResult();
        return new Page<>(list, skipCount, maxItems, count);
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Page(org.eclipse.che.api.core.Page) Transactional(com.google.inject.persist.Transactional)

Example 43 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.

the class DevfileServiceTest method shouldGetUserDevfileById.

@Test
public void shouldGetUserDevfileById() throws Exception {
    final UserDevfileImpl userDevfile = TestObjectGenerator.createUserDevfile();
    when(userDevfileManager.getById(eq("id-22323"))).thenReturn(userDevfile);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/devfile/id-22323").then().extract().response();
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new UserDevfileImpl(unwrapDto(response, UserDevfileDto.class), TEST_ACCOUNT), userDevfile);
    verify(userDevfileManager).getById(eq("id-22323"));
    verify(linksInjector).injectLinks(any(), any());
}
Also used : Response(io.restassured.response.Response) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Test(org.testng.annotations.Test)

Example 44 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.

the class DevfileServiceTest method shouldOverrideIdOnUpdateUserDevfile.

@Test
public void shouldOverrideIdOnUpdateUserDevfile() throws Exception {
    // given
    final UserDevfileDto devfileDto = TestObjectGenerator.createUserDevfileDto();
    final UserDevfileImpl userDevfileImpl = new UserDevfileImpl(devfileDto, TEST_ACCOUNT);
    final String newID = NameGenerator.generate("id", 24);
    final UserDevfileImpl expectedUserDevfileImpl = new UserDevfileImpl(newID, TEST_ACCOUNT, userDevfileImpl);
    final UserDevfileDto expectedDto = org.eclipse.che.api.devfile.server.DtoConverter.asDto(expectedUserDevfileImpl);
    when(userDevfileManager.updateUserDevfile(any(UserDevfile.class))).thenReturn(expectedUserDevfileImpl);
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(DtoFactory.getInstance().toJson(devfileDto)).when().put(SECURE_PATH + "/devfile/" + newID);
    // then
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new UserDevfileImpl(unwrapDto(response, UserDevfileDto.class), TEST_ACCOUNT), expectedUserDevfileImpl);
    verify(userDevfileManager).updateUserDevfile(expectedDto);
    verify(linksInjector).injectLinks(any(), any());
}
Also used : Response(io.restassured.response.Response) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 45 with UserDevfileImpl

use of org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl in project che-server by eclipse-che.

the class DevfileServiceTest method shouldGetUserDevfilesAvailableToUser.

@Test
public void shouldGetUserDevfilesAvailableToUser() throws Exception {
    // given
    final UserDevfileDto devfileDto = TestObjectGenerator.createUserDevfileDto();
    final UserDevfileImpl userDevfileImpl = new UserDevfileImpl(devfileDto, TEST_ACCOUNT);
    doReturn(new Page<>(ImmutableList.of(userDevfileImpl), 0, 1, 1)).when(userDevfileManager).getUserDevfiles(anyInt(), anyInt(), anyList(), anyList());
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/devfile/search").then().extract().response();
    // then
    assertEquals(response.getStatusCode(), 200);
    final List<UserDevfileDto> res = unwrapDtoList(response, UserDevfileDto.class);
    assertEquals(res.size(), 1);
    assertEquals(res.get(0).withLinks(emptyList()), devfileDto);
    verify(userDevfileManager).getUserDevfiles(eq(30), eq(0), anyList(), anyList());
}
Also used : Response(io.restassured.response.Response) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) UserDevfileDto(org.eclipse.che.api.devfile.shared.dto.UserDevfileDto) Test(org.testng.annotations.Test)

Aggregations

UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)74 Test (org.testng.annotations.Test)46 UserDevfile (org.eclipse.che.api.core.model.workspace.devfile.UserDevfile)28 TestObjectGenerator.createUserDevfile (org.eclipse.che.api.devfile.server.TestObjectGenerator.createUserDevfile)18 AccountImpl (org.eclipse.che.account.spi.AccountImpl)16 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)16 TypeLiteral (com.google.inject.TypeLiteral)14 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)14 DBInitializer (org.eclipse.che.core.db.DBInitializer)14 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)14 FlywaySchemaInitializer (org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer)14 AccountDao (org.eclipse.che.account.spi.AccountDao)12 Response (io.restassured.response.Response)10 JpaAccountDao (org.eclipse.che.account.spi.jpa.JpaAccountDao)10 Pair (org.eclipse.che.commons.lang.Pair)10 PersistTestModuleBuilder (org.eclipse.che.commons.test.db.PersistTestModuleBuilder)10 Transactional (com.google.inject.persist.Transactional)8 EntityManager (javax.persistence.EntityManager)8 UserDevfileDto (org.eclipse.che.api.devfile.shared.dto.UserDevfileDto)8 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)8