Search in sources :

Example 1 with RecipePersistedEvent

use of org.eclipse.che.api.machine.server.event.RecipePersistedEvent in project che by eclipse.

the class JpaRecipeDao method doCreate.

@Transactional(rollbackOn = { RuntimeException.class, ApiException.class })
protected void doCreate(RecipeImpl recipe) throws ConflictException, ServerException {
    EntityManager manage = managerProvider.get();
    manage.persist(recipe);
    manage.flush();
    eventService.publish(new RecipePersistedEvent(recipe)).propagateException();
}
Also used : EntityManager(javax.persistence.EntityManager) RecipePersistedEvent(org.eclipse.che.api.machine.server.event.RecipePersistedEvent) Transactional(com.google.inject.persist.Transactional)

Example 2 with RecipePersistedEvent

use of org.eclipse.che.api.machine.server.event.RecipePersistedEvent in project che by eclipse.

the class RecipeDaoTest method shouldNotCreateRecipeWhenSubscriberThrowsExceptionOnRecipeStoring.

@Test(dependsOnMethods = "shouldThrowNotFoundExceptionWhenGettingNonExistingRecipe", expectedExceptions = NotFoundException.class)
public void shouldNotCreateRecipeWhenSubscriberThrowsExceptionOnRecipeStoring() throws Exception {
    final RecipeImpl recipe = createRecipe(0);
    CascadeEventSubscriber<RecipePersistedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ConflictException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, RecipePersistedEvent.class);
    try {
        recipeDao.create(recipe);
        fail("RecipeDao#create had to throw conflict exception");
    } catch (ConflictException ignored) {
    }
    eventService.unsubscribe(subscriber, RecipePersistedEvent.class);
    recipeDao.getById(recipe.getId());
}
Also used : ConflictException(org.eclipse.che.api.core.ConflictException) RecipePersistedEvent(org.eclipse.che.api.machine.server.event.RecipePersistedEvent) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) Test(org.testng.annotations.Test)

Aggregations

RecipePersistedEvent (org.eclipse.che.api.machine.server.event.RecipePersistedEvent)2 Transactional (com.google.inject.persist.Transactional)1 EntityManager (javax.persistence.EntityManager)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)1 Test (org.testng.annotations.Test)1