Search in sources :

Example 11 with NewRecipe

use of org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe in project che by eclipse.

the class RecipeServiceTest method shouldThrowBadRequestExceptionOnCreateRecipeWithNewRecipeWhichDoesNotHaveType.

@Test
public void shouldThrowBadRequestExceptionOnCreateRecipeWithNewRecipeWhichDoesNotHaveType() {
    final NewRecipe newRecipe = newDto(NewRecipe.class).withScript("FROM ubuntu\n");
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(newRecipe).when().post(SECURE_PATH + "/recipe");
    assertEquals(response.getStatusCode(), 400);
    assertEquals(unwrapDto(response, ServiceError.class).getMessage(), "Recipe type required");
}
Also used : Response(com.jayway.restassured.response.Response) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe) Test(org.testng.annotations.Test)

Example 12 with NewRecipe

use of org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe in project che by eclipse.

the class RecipePartPresenterTest method recipeShouldBeSaved.

@Test
public void recipeShouldBeSaved() throws Exception {
    NewRecipe newRecipe = mock(NewRecipe.class);
    List<String> tags = Collections.singletonList("tag");
    when(dtoFactory.createDto(NewRecipe.class)).thenReturn(newRecipe);
    when(newRecipe.withType(anyString())).thenReturn(newRecipe);
    when(newRecipe.withScript(anyString())).thenReturn(newRecipe);
    when(newRecipe.withName(anyString())).thenReturn(newRecipe);
    when(newRecipe.withTags(Matchers.<List<String>>any())).thenReturn(newRecipe);
    when(service.createRecipe(newRecipe)).thenReturn(recipeDescriptorPromise);
    when(recipesContainerPresenter.getEditorPanel(Matchers.<RecipeWidget>any())).thenReturn(recipeEditorPanel);
    RecipeUpdate recipeUpdate = mock(RecipeUpdate.class);
    when(dtoFactory.createDto(RecipeUpdate.class)).thenReturn(recipeUpdate);
    when(recipeUpdate.withType(anyString())).thenReturn(recipeUpdate);
    when(recipeUpdate.withId(anyString())).thenReturn(recipeUpdate);
    when(recipeUpdate.withScript(anyString())).thenReturn(recipeUpdate);
    when(recipeUpdate.withName(anyString())).thenReturn(recipeUpdate);
    when(recipeUpdate.withTags(Matchers.<List<String>>any())).thenReturn(recipeUpdate);
    when(recipeDescriptor1.getId()).thenReturn("id");
    when(recipeDescriptor1.getName()).thenReturn("name");
    when(recipeDescriptor1.getScript()).thenReturn("script");
    when(recipeDescriptor1.getTags()).thenReturn(tags);
    when(service.updateRecipe(recipeUpdate)).thenReturn(savedRecipeDescriptorPromise);
    when(recipeDescriptor1.getType()).thenReturn(RECIPE_TYPE);
    when(recipeEditorPanel.getScript()).thenReturn("script");
    when(recipeEditorPanel.getTags()).thenReturn(tags);
    when(recipeEditorPanel.getName()).thenReturn("name");
    recipePartPresenter.onNewButtonClicked();
    verify(recipeDescriptorPromise).then(operationDescriptorCaptor.capture());
    operationDescriptorCaptor.getValue().apply(recipeDescriptor1);
    recipePartPresenter.onSaveButtonClicked();
    verify(service).updateRecipe(recipeUpdate);
    verify(savedRecipeDescriptorPromise).then(savedDescriptorCaptor.capture());
    savedDescriptorCaptor.getValue().apply(recipeDescriptor1);
    verify(recipeDescriptor1).setScript("script");
    verify(recipeDescriptor1).setTags(recipeDescriptor1.getTags());
    verify(notificationManager).notify(eq("Recipe \"name\" was saved."));
}
Also used : RecipeUpdate(org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate) Matchers.anyString(org.mockito.Matchers.anyString) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe) Test(org.junit.Test)

Aggregations

NewRecipe (org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)12 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 Response (com.jayway.restassured.response.Response)4 Test (org.testng.annotations.Test)4 RecipeDescriptor (org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)2 ArrayList (java.util.ArrayList)1 RecipeUpdate (org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate)1 OperationException (org.eclipse.che.api.promises.client.OperationException)1 DisplayMode (org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode)1 RecipeEditorPanel (org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.editor.RecipeEditorPanel)1