Search in sources :

Example 6 with NewRecipe

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

the class RecipePartPresenterTest method recipeShouldBeDeleted.

@Test
public void recipeShouldBeDeleted() 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(recipeDescriptor1.getId()).thenReturn("id");
    when(service.removeRecipe(anyString())).thenReturn(deletePromise);
    recipePartPresenter.onNewButtonClicked();
    verify(recipeDescriptorPromise).then(operationDescriptorCaptor.capture());
    operationDescriptorCaptor.getValue().apply(recipeDescriptor1);
    recipePartPresenter.onDeleteButtonClicked();
    verify(deletePromise).then(deleteCaptor.capture());
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe) Test(org.junit.Test)

Example 7 with NewRecipe

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

the class SshCategoryPresenter method createTargetRecipe.

/**
     * Create a new target recipe and save it.
     */
private void createTargetRecipe() {
    List<String> tags = new ArrayList<>();
    tags.add(this.getCategory());
    NewRecipe newRecipe = dtoFactory.createDto(NewRecipe.class).withName(selectedTarget.getName()).withType(getCategory()).withScript("{" + "\"host\": \"" + selectedTarget.getHost() + "\", " + "\"port\": \"" + selectedTarget.getPort() + "\", " + "\"username\": \"" + selectedTarget.getUserName() + "\", " + "\"password\": \"" + selectedTarget.getPassword() + "\"" + "}").withTags(tags);
    Promise<RecipeDescriptor> createRecipe = recipeServiceClient.createRecipe(newRecipe);
    createRecipe.then(new Operation<RecipeDescriptor>() {

        @Override
        public void apply(RecipeDescriptor recipe) throws OperationException {
            onTargetSaved(recipe);
        }
    });
    createRecipe.catchError(new Operation<PromiseError>() {

        @Override
        public void apply(PromiseError arg) throws OperationException {
            dialogFactory.createMessageDialog("Error", machineLocale.targetsViewSaveError(), null).show();
        }
    });
}
Also used : PromiseError(org.eclipse.che.api.promises.client.PromiseError) ArrayList(java.util.ArrayList) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) OperationException(org.eclipse.che.api.promises.client.OperationException) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)

Example 8 with NewRecipe

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

the class RecipePartPresenter method onCloneButtonClicked.

/** {@inheritDoc} */
@Override
public void onCloneButtonClicked() {
    RecipeDescriptor selectedRecipeDescriptor = recipes.get(selectedRecipe);
    String recipeName = NameGenerator.generateCopy(selectedRecipeDescriptor.getName(), recipes.keySet());
    NewRecipe newRecipe = dtoFactory.createDto(NewRecipe.class).withType(selectedRecipeDescriptor.getType()).withScript(selectedRecipeDescriptor.getScript()).withName(recipeName).withTags(selectedRecipeDescriptor.getTags());
    createRecipe(newRecipe);
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)

Example 9 with NewRecipe

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

the class RecipePartPresenter method onNewButtonClicked.

/** {@inheritDoc} */
@Override
public void onNewButtonClicked() {
    RecipeEditorPanel stubPanel = recipesContainerPresenter.getEditorStubPanel();
    String recipeName = NameGenerator.generateCustomRecipeName(recipes.keySet());
    List<String> tags = stubPanel.getTags();
    if (recipes.isEmpty() && !stubPanel.getName().isEmpty()) {
        recipeName = stubPanel.getName();
        stubPanel.setTags(Collections.<String>emptyList());
    }
    NewRecipe newRecipe = dtoFactory.createDto(NewRecipe.class).withType(RECIPE_TYPE).withScript(resources.recipeTemplate().getText()).withName(recipeName).withTags(tags);
    createRecipe(newRecipe);
}
Also used : RecipeEditorPanel(org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.editor.RecipeEditorPanel) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)

Example 10 with NewRecipe

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

the class RecipeServiceTest method shouldCreateNewRecipe.

@Test
public void shouldCreateNewRecipe() throws Exception {
    final NewRecipe newRecipe = newDto(NewRecipe.class).withType("docker").withName("name").withScript("FROM ubuntu\n").withTags(asList("java", "mongo"));
    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(), 201);
    verify(recipeDao).create(any(RecipeImpl.class));
    final RecipeDescriptor descriptor = unwrapDto(response, RecipeDescriptor.class);
    assertNotNull(descriptor.getId());
    assertEquals(descriptor.getName(), newRecipe.getName());
    assertEquals(descriptor.getCreator(), USER_ID);
    assertEquals(descriptor.getScript(), newRecipe.getScript());
    assertEquals(descriptor.getTags(), newRecipe.getTags());
}
Also used : Response(com.jayway.restassured.response.Response) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) NewRecipe(org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe) Test(org.testng.annotations.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