Search in sources :

Example 61 with UserDevfileImpl

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

the class DevfileServiceTest method shouldBeAbleToUpdateUserDevfile.

@Test
public void shouldBeAbleToUpdateUserDevfile() throws Exception {
    // given
    final UserDevfileDto devfileDto = TestObjectGenerator.createUserDevfileDto();
    final UserDevfileImpl userDevfileImpl = new UserDevfileImpl(devfileDto, TEST_ACCOUNT);
    when(userDevfileManager.updateUserDevfile(any(UserDevfile.class))).thenReturn(userDevfileImpl);
    // 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/" + devfileDto.getId());
    // then
    assertEquals(response.getStatusCode(), 200);
    assertEquals(new UserDevfileImpl(unwrapDto(response, UserDevfileDto.class), TEST_ACCOUNT), userDevfileImpl);
    verify(userDevfileManager).updateUserDevfile(devfileDto);
    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) Test(org.testng.annotations.Test)

Example 62 with UserDevfileImpl

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

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)

Example 63 with UserDevfileImpl

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

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 64 with UserDevfileImpl

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

the class UserDevfileManagerTest method shouldRemoveUserDevfile.

@Test
public void shouldRemoveUserDevfile() throws Exception {
    // given
    final UserDevfileImpl userDevfile = createUserDevfile();
    // when
    userDevfileManager.removeUserDevfile(userDevfile.getId());
    // then
    verify(userDevfileDao).remove(userDevfile.getId());
}
Also used : UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Test(org.testng.annotations.Test)

Example 65 with UserDevfileImpl

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

the class UserDevfileManagerTest method shouldThrowNotFoundIfUserDevfileIsNotFoundOnUpdate.

@Test(expectedExceptions = NotFoundException.class)
public void shouldThrowNotFoundIfUserDevfileIsNotFoundOnUpdate() throws Exception {
    // given
    final UserDevfileImpl userDevfile = createUserDevfile();
    Mockito.doReturn(Optional.empty()).when(userDevfileDao).update(any(UserDevfileImpl.class));
    // when
    userDevfileManager.updateUserDevfile(userDevfile);
}
Also used : UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) 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