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)));
}
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)));
}
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));
}
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");
}
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);
}
Aggregations