Search in sources :

Example 26 with UserDevfile

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)));
}
Also used : MetadataImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.MetadataImpl) 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) DevfileImpl(org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) Test(org.testng.annotations.Test)

Example 27 with UserDevfile

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;
}
Also used : UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) DevfileCreatedEvent(org.eclipse.che.api.devfile.shared.event.DevfileCreatedEvent)

Example 28 with UserDevfile

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)));
}
Also used : UserDevfile(org.eclipse.che.api.core.model.workspace.devfile.UserDevfile) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 29 with UserDevfile

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());
}
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)

Example 30 with UserDevfile

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