Search in sources :

Example 11 with UserDevfile

use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project che-server by eclipse-che.

the class UserDevfileManager method getById.

/**
 * Gets UserDevfile by given id.
 *
 * @param id userdevfile identifier
 * @return userdevfile instance
 * @throws NullPointerException when {@code id} is null
 * @throws NotFoundException when userdevfile with given id not found
 * @throws ServerException when any server errors occurs
 */
public UserDevfile getById(String id) throws NotFoundException, ServerException {
    requireNonNull(id);
    Optional<UserDevfile> result = userDevfileDao.getById(id);
    return result.orElseThrow(() -> new NotFoundException(format("Devfile with id '%s' doesn't exist", id)));
}
Also used : UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 12 with UserDevfile

use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project devspaces-images by redhat-developer.

the class MultiuserJpaUserDevfileDaoTest method shouldFindDevfilesByByPermissions.

@Test
public void shouldFindDevfilesByByPermissions() throws Exception {
    EnvironmentContext expected = EnvironmentContext.getCurrent();
    expected.setSubject(new SubjectImpl("user", users.get(0).getId(), "token", false));
    List<UserDevfile> results = dao.getDevfiles(30, 0, Collections.emptyList(), Collections.emptyList()).getItems();
    assertEquals(results.size(), 2);
    assertTrue(results.contains(userDevfiles.get(0)));
    assertTrue(results.contains(userDevfiles.get(1)));
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) TestObjectGenerator.createUserDevfile(org.eclipse.che.multiuser.permission.devfile.server.TestObjectGenerator.createUserDevfile) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Test(org.testng.annotations.Test)

Example 13 with UserDevfile

use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project devspaces-images by redhat-developer.

the class DevfileServiceTest method shouldThrowNotFoundExceptionWhenUpdatingNonExistingUserDevfile.

@Test
public void shouldThrowNotFoundExceptionWhenUpdatingNonExistingUserDevfile() throws Exception {
    // given
    final UserDevfile userDevfile = DtoConverter.asDto(TestObjectGenerator.createUserDevfile("devfile-name"));
    doThrow(new NotFoundException(format("User devfile with id %s is not found.", USER_DEVFILE_ID))).when(userDevfileManager).updateUserDevfile(any(UserDevfile.class));
    // when
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType(APPLICATION_JSON).body(DtoFactory.getInstance().toJson(userDevfile)).when().put(SECURE_PATH + "/devfile/" + USER_DEVFILE_ID);
    // then
    assertEquals(response.getStatusCode(), 404);
    assertEquals(unwrapDto(response, ServiceError.class).getMessage(), format("User devfile with id %s is not found.", USER_DEVFILE_ID));
}
Also used : Response(io.restassured.response.Response) UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.testng.annotations.Test)

Example 14 with UserDevfile

use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project devspaces-images by redhat-developer.

the class UserDevfileManagerTest method shouldGetUserDevfileById.

@Test
public void shouldGetUserDevfileById() throws Exception {
    // given
    final Optional<UserDevfile> toFetch = Optional.of(createUserDevfile());
    when(userDevfileDao.getById(eq("id123"))).thenReturn(toFetch);
    // when
    final UserDevfile fetched = userDevfileManager.getById("id123");
    // then
    assertEquals(fetched, toFetch.get());
    verify(userDevfileDao).getById("id123");
}
Also used : UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) TestObjectGenerator.createUserDevfile(org.eclipse.che.api.devfile.server.TestObjectGenerator.createUserDevfile) Test(org.testng.annotations.Test)

Example 15 with UserDevfile

use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project devspaces-images by redhat-developer.

the class UserDevfileManagerTest method shouldGenerateUserDevfileIdOnCreation.

@Test
public void shouldGenerateUserDevfileIdOnCreation() throws Exception {
    // given
    final UserDevfileImpl userDevfile = new UserDevfileImpl(null, TEST_ACCOUNT, createUserDevfile());
    when(userDevfileDao.create(any(UserDevfileImpl.class))).thenAnswer(invocationOnMock -> invocationOnMock.getArguments()[0]);
    // when
    UserDevfile actual = userDevfileManager.createDevfile(userDevfile);
    // then
    verify(userDevfileDao).create(userDevfileArgumentCaptor.capture());
    assertFalse(isNullOrEmpty(userDevfileArgumentCaptor.getValue().getId()));
    assertEquals(new UserDevfileImpl(null, TEST_ACCOUNT, actual), userDevfile);
}
Also used : UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) TestObjectGenerator.createUserDevfile(org.eclipse.che.api.devfile.server.TestObjectGenerator.createUserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Test(org.testng.annotations.Test)

Aggregations

UserDevfile (org.eclipse.che.api.core.model.workspace.devfile.UserDevfile)34 Test (org.testng.annotations.Test)24 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)22 TestObjectGenerator.createUserDevfile (org.eclipse.che.api.devfile.server.TestObjectGenerator.createUserDevfile)20 NotFoundException (org.eclipse.che.api.core.NotFoundException)10 Pair (org.eclipse.che.commons.lang.Pair)8 ImmutableSet (com.google.common.collect.ImmutableSet)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 Collectors.toList (java.util.stream.Collectors.toList)4 Inject (javax.inject.Inject)4 ConflictException (org.eclipse.che.api.core.ConflictException)3 Page (org.eclipse.che.api.core.Page)3 ServerException (org.eclipse.che.api.core.ServerException)3 Beta (com.google.common.annotations.Beta)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Splitter (com.google.common.base.Splitter)2 Supplier (com.google.common.base.Supplier)2 ImmutableList (com.google.common.collect.ImmutableList)2