Search in sources :

Example 1 with NewRecipe

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

the class RecipeServiceTest method shouldThrowBadRequestExceptionOnCreateRecipeWithNewRecipeWhichDoesNotHaveScript.

@Test
public void shouldThrowBadRequestExceptionOnCreateRecipeWithNewRecipeWhichDoesNotHaveScript() {
    final NewRecipe newRecipe = newDto(NewRecipe.class).withType("docker");
    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 script 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 2 with NewRecipe

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

the class RecipeServiceTest method shouldThrowBadRequestExceptionWhenCreatingRecipeWithoutName.

@Test
public void shouldThrowBadRequestExceptionWhenCreatingRecipeWithoutName() {
    final NewRecipe newRecipe = newDto(NewRecipe.class).withType("docker").withScript("script");
    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 name 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 3 with NewRecipe

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

the class RecipePartPresenterTest method secondRecipeShouldBeCreated.

@Test
public void secondRecipeShouldBeCreated() throws Exception {
    NewRecipe newRecipe = mock(NewRecipe.class);
    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);
    when(recipesContainerPresenter.getEditorStubPanel()).thenReturn(stubPanel);
    recipePartPresenter.onNewButtonClicked();
    verify(recipeDescriptorPromise).then(operationDescriptorCaptor.capture());
    operationDescriptorCaptor.getValue().apply(recipeDescriptor1);
    when(recipeDescriptor1.getName()).thenReturn("name");
    recipePartPresenter.onCloneButtonClicked();
    verify(recipeDescriptor1).getType();
    verify(recipeDescriptor1).getScript();
    verify(recipeDescriptor1).getTags();
    verify(newRecipe).withType(RECIPE_TYPE);
    verify(newRecipe).withScript("script");
    verify(newRecipe).withName("name");
    assertTrue(newRecipe.getTags().isEmpty());
    verify(service, times(2)).createRecipe(newRecipe);
    verify(recipeDescriptorPromise, times(2)).then(operationDescriptorCaptor.capture());
    operationDescriptorCaptor.getValue().apply(recipeDescriptor1);
    verify(recipePartView, times(2)).addRecipe(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter, times(2)).addRecipePanel(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter, times(2)).showEditorPanel(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter, times(2)).getEditorPanel(Matchers.<RecipeWidget>any());
    verify(recipeEditorPanel, times(2)).setDelegate(recipePartPresenter);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe) Test(org.junit.Test)

Example 4 with NewRecipe

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

the class RecipePartPresenterTest method firstRecipeShouldBeCreated.

@Test
public void firstRecipeShouldBeCreated() throws Exception {
    NewRecipe newRecipe = mock(NewRecipe.class);
    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);
    when(recipeEditorPanel.getName()).thenReturn("name");
    recipePartPresenter.onNewButtonClicked();
    verify(service).createRecipe(newRecipe);
    verify(newRecipe).withType(RECIPE_TYPE);
    verify(newRecipe).withScript("script");
    verify(newRecipe).withName("name");
    verify(stubPanel, times(2)).getName();
    verify(stubPanel).getTags();
    assertTrue(newRecipe.getTags().isEmpty());
    verify(recipeDescriptorPromise).then(operationDescriptorCaptor.capture());
    operationDescriptorCaptor.getValue().apply(recipeDescriptor1);
    verify(recipePartView).addRecipe(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter).addRecipePanel(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter).showEditorPanel(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter).getEditorPanel(Matchers.<RecipeWidget>any());
    verify(recipeEditorPanel).setDelegate(recipePartPresenter);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe) Test(org.junit.Test)

Example 5 with NewRecipe

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

the class RecipePartPresenterTest method notificationShouldBeShowedWhenCreationIsFailed.

@Test
public void notificationShouldBeShowedWhenCreationIsFailed() throws Exception {
    NewRecipe newRecipe = mock(NewRecipe.class);
    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);
    when(recipeEditorPanel.getName()).thenReturn("name");
    recipePartPresenter.onNewButtonClicked();
    verify(service).createRecipe(newRecipe);
    verify(newRecipe).withType(RECIPE_TYPE);
    verify(newRecipe).withScript("script");
    verify(newRecipe).withName("name");
    verify(stubPanel, times(2)).getName();
    verify(stubPanel).getTags();
    assertTrue(newRecipe.getTags().isEmpty());
    verify(recipeDescriptorPromise).then(operationDescriptorCaptor.capture());
    operationDescriptorCaptor.getValue().apply(recipeDescriptor1);
    verify(recipePartView).addRecipe(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter).addRecipePanel(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter).showEditorPanel(Matchers.<RecipeWidget>any());
    verify(recipesContainerPresenter).getEditorPanel(Matchers.<RecipeWidget>any());
    verify(recipeEditorPanel).setDelegate(recipePartPresenter);
    PromiseError promiseError = mock(PromiseError.class);
    when(promiseError.getMessage()).thenReturn("text");
    verify(recipeDescriptorPromise).catchError(operationErrorArgumentCaptor.capture());
    operationErrorArgumentCaptor.getValue().apply(promiseError);
    verify(notificationManager).notify(anyString(), anyString(), any(StatusNotification.Status.class), any(DisplayMode.class));
}
Also used : DisplayMode(org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode) PromiseError(org.eclipse.che.api.promises.client.PromiseError) 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