use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project che-server by eclipse-che.
the class UserDevfileDaoTest method shouldCreateUserDevfileWithEmptyMataName.
@Test
public void shouldCreateUserDevfileWithEmptyMataName() throws Exception {
// given
final UserDevfileImpl devfile = createUserDevfile(accounts[0]);
DevfileImpl newDevfile = new DevfileImpl(devfile.getDevfile());
MetadataImpl newMeta = new MetadataImpl();
newMeta.setGenerateName("gener-");
newDevfile.setMetadata(newMeta);
devfile.setDevfile(newDevfile);
// when
userDevfileDaoDao.create(devfile);
Optional<UserDevfile> devfileOptional = userDevfileDaoDao.getById(devfile.getId());
assertTrue(devfileOptional.isPresent());
UserDevfile actual = devfileOptional.get();
assertNull(actual.getDevfile().getMetadata().getName());
assertNotNull(actual.getDevfile().getMetadata().getGenerateName());
assertEquals(devfileOptional, Optional.of(new UserDevfileImpl(devfile)));
}
use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project devspaces-images by redhat-developer.
the class UserDevfileManager method createDevfile.
/**
* Stores {@link Devfile} instance
*
* @param userDevfile instance of user devfile which would be stored
* @return new persisted devfile instance
* @throws ConflictException when any conflict occurs (e.g Devfile with such name already exists
* for {@code owner})
* @throws NullPointerException when {@code devfile} is null
* @throws ServerException when any other error occurs
*/
public UserDevfile createDevfile(UserDevfile userDevfile) throws ServerException, NotFoundException, ConflictException {
requireNonNull(userDevfile, "Required non-null userdevfile");
requireNonNull(userDevfile.getDevfile(), "Required non-null devfile");
String name = userDevfile.getName() != null ? userDevfile.getName() : NameGenerator.generate("devfile-", 5);
UserDevfile result = userDevfileDao.create(new UserDevfileImpl(NameGenerator.generate("id-", 16), accountManager.getByName(EnvironmentContext.getCurrent().getSubject().getUserName()), name, userDevfile.getDescription(), userDevfile.getDevfile()));
LOG.debug("UserDevfile '{}' with id '{}' created by user '{}'", result.getName(), result.getId(), EnvironmentContext.getCurrent().getSubject().getUserName());
eventService.publish(new DevfileCreatedEvent(result));
return result;
}
use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project devspaces-images by redhat-developer.
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 UserDevfileManagerTest method shouldSendDevfileCreatedEventOnCreation.
@Test
public void shouldSendDevfileCreatedEventOnCreation() 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 expected = userDevfileManager.createDevfile(userDevfile);
// then
verify(eventService).publish(devfileCreatedEventCaptor.capture());
assertEquals(expected, devfileCreatedEventCaptor.getValue().getUserDevfile());
}
use of org.eclipse.che.api.core.model.workspace.devfile.UserDevfile in project devspaces-images by redhat-developer.
the class UserDevfileManagerTest method shouldBeAbleToGetUserDevfilesAvailableToUser.
@Test
public void shouldBeAbleToGetUserDevfilesAvailableToUser() throws ServerException {
// given
final UserDevfileImpl userDevfile = createUserDevfile();
final UserDevfileImpl userDevfile2 = createUserDevfile();
when(userDevfileDao.getDevfiles(2, 30, Collections.emptyList(), Collections.emptyList())).thenReturn(new Page<>(asList(userDevfile, userDevfile2), 0, 2, 2));
// when
Page<UserDevfile> actual = userDevfileManager.getUserDevfiles(2, 30, Collections.emptyList(), Collections.emptyList());
// then
assertEquals(actual.getItems().size(), 2);
}
Aggregations