Search in sources :

Example 21 with StackImpl

use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.

the class StackDaoTest method shouldUpdateStack.

@Test(dependsOnMethods = "shouldGetById")
public void shouldUpdateStack() throws Exception {
    final StackImpl stack = stacks[0];
    stack.setName("new-name");
    stack.setCreator("new-creator");
    stack.setDescription("new-description");
    stack.setScope("new-scope");
    stack.getTags().clear();
    stack.getTags().add("new-tag");
    // Remove an existing component
    stack.getComponents().remove(1);
    // Add a new component
    stack.getComponents().add(new StackComponentImpl("component3", "component3-version"));
    // Update an existing component
    final StackComponentImpl component = stack.getComponents().get(0);
    component.setName("new-name");
    component.setVersion("new-version");
    // Updating source
    final StackSourceImpl source = stack.getSource();
    source.setType("new-type");
    source.setOrigin("new-source");
    // Set a new icon
    stack.setStackIcon(new StackIcon("new-name", "new-media", "new-data".getBytes()));
    stackDao.update(stack);
    assertEquals(stackDao.getById(stack.getId()), new StackImpl(stack));
}
Also used : StackComponentImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackComponentImpl) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) StackIcon(org.eclipse.che.api.workspace.server.stack.image.StackIcon) StackSourceImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackSourceImpl) Test(org.testng.annotations.Test)

Example 22 with StackImpl

use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.

the class StackDaoTest method shouldNotCreateStackWhenSubscriberThrowsExceptionOnStackStoring.

@Test(dependsOnMethods = "shouldThrowNotFoundExceptionWhenGettingNonExistingStack", expectedExceptions = NotFoundException.class)
public void shouldNotCreateStackWhenSubscriberThrowsExceptionOnStackStoring() throws Exception {
    final StackImpl stack = createStack("new-stack", "new-stack-name");
    CascadeEventSubscriber<StackPersistedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ConflictException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, StackPersistedEvent.class);
    try {
        stackDao.create(stack);
        fail("StackDao#create had to throw conflict exception");
    } catch (ConflictException ignored) {
    }
    eventService.unsubscribe(subscriber, StackPersistedEvent.class);
    stackDao.getById(stack.getId());
}
Also used : StackPersistedEvent(org.eclipse.che.api.workspace.server.event.StackPersistedEvent) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.testng.annotations.Test)

Example 23 with StackImpl

use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.

the class StackDaoTest method createStack.

private static StackImpl createStack(String id, String name) {
    final StackImpl stack = StackImpl.builder().setId(id).setName(name).setCreator("user123").setDescription(id + "-description").setScope(id + "-scope").setTags(asList(id + "-tag1", id + "-tag2")).setComponents(asList(new StackComponentImpl(id + "-component1", id + "-component1-version"), new StackComponentImpl(id + "-component2", id + "-component2-version"))).setSource(new StackSourceImpl(id + "-type", id + "-origin")).setStackIcon(new StackIcon(id + "-icon", id + "-media-type", "0x1234567890abcdef".getBytes())).build();
    final WorkspaceConfigImpl config = createWorkspaceConfig("test");
    stack.setWorkspaceConfig(config);
    return stack;
}
Also used : StackComponentImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackComponentImpl) StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) StackIcon(org.eclipse.che.api.workspace.server.stack.image.StackIcon) WorkspaceConfigImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl) StackSourceImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackSourceImpl)

Example 24 with StackImpl

use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.

the class StackDaoTest method shouldThrowConflictExceptionWhenCreatingStackWithNameThatAlreadyExists.

@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionWhenCreatingStackWithNameThatAlreadyExists() throws Exception {
    final StackImpl stack = createStack("new-stack-id", stacks[0].getName());
    stackDao.create(stack);
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) Test(org.testng.annotations.Test)

Example 25 with StackImpl

use of org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl in project che by eclipse.

the class StackDaoTest method shouldNotRemoveStackWhenSubscriberThrowsExceptionOnStackRemoving.

@Test(dependsOnMethods = "shouldGetById")
public void shouldNotRemoveStackWhenSubscriberThrowsExceptionOnStackRemoving() throws Exception {
    final StackImpl stack = stacks[0];
    CascadeEventSubscriber<BeforeStackRemovedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, BeforeStackRemovedEvent.class);
    try {
        stackDao.remove(stack.getId());
        fail("StackDao#remove had to throw server exception");
    } catch (ServerException ignored) {
    }
    assertEquals(stackDao.getById(stack.getId()), stack);
    eventService.unsubscribe(subscriber, BeforeStackRemovedEvent.class);
}
Also used : StackImpl(org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl) ServerException(org.eclipse.che.api.core.ServerException) BeforeStackRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeStackRemovedEvent) Test(org.testng.annotations.Test)

Aggregations

StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)26 Test (org.testng.annotations.Test)15 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)5 Response (com.jayway.restassured.response.Response)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 StackIcon (org.eclipse.che.api.workspace.server.stack.image.StackIcon)4 Consumes (javax.ws.rs.Consumes)3 NotFoundException (org.eclipse.che.api.core.NotFoundException)3 StackDto (org.eclipse.che.api.workspace.shared.dto.stack.StackDto)3 TypeLiteral (com.google.inject.TypeLiteral)2 Transactional (com.google.inject.persist.Transactional)2 EntityManager (javax.persistence.EntityManager)2 POST (javax.ws.rs.POST)2 AccountImpl (org.eclipse.che.account.spi.AccountImpl)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ServerException (org.eclipse.che.api.core.ServerException)2 WorkspaceConfigImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl)2