Search in sources :

Example 1 with UserDevfile

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

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 2 with UserDevfile

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

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)

Example 3 with UserDevfile

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

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)

Example 4 with UserDevfile

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

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 5 with UserDevfile

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

the class UserDevfileDaoTest method shouldNotUpdateWorkspaceWhichDoesNotExist.

@Test
public void shouldNotUpdateWorkspaceWhichDoesNotExist() throws Exception {
    // given
    final UserDevfileImpl userDevfile = devfiles[0];
    userDevfile.setId("non-existing-devfile");
    // when
    Optional<UserDevfile> result = userDevfileDaoDao.update(userDevfile);
    // then
    assertFalse(result.isPresent());
}
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