Search in sources :

Example 1 with RecipeDescriptor

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

the class RecipeServiceTest method shouldBeAbleToGetRecipe.

@Test
public void shouldBeAbleToGetRecipe() throws Exception {
    final RecipeImpl recipe = new RecipeImpl().withCreator("someone2").withId("recipe123").withName("name").withType("docker").withScript("FROM ubuntu\n").withTags(asList("java", "mognodb"));
    when(recipeDao.getById(recipe.getId())).thenReturn(recipe);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().get(SECURE_PATH + "/recipe/" + recipe.getId());
    assertEquals(response.getStatusCode(), 200);
    final RecipeDescriptor descriptor = unwrapDto(response, RecipeDescriptor.class);
    assertEquals(descriptor.getId(), recipe.getId());
    assertEquals(descriptor.getName(), recipe.getName());
    assertEquals(descriptor.getType(), recipe.getType());
    assertEquals(descriptor.getScript(), recipe.getScript());
    assertEquals(descriptor.getTags(), recipe.getTags());
    assertEquals(descriptor.getCreator(), recipe.getCreator());
}
Also used : Response(com.jayway.restassured.response.Response) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) Test(org.testng.annotations.Test)

Example 2 with RecipeDescriptor

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

the class RecipeService method asRecipeDescriptor.

/**
     * Transforms {@link ManagedRecipe} to {@link RecipeDescriptor}.
     */
private RecipeDescriptor asRecipeDescriptor(ManagedRecipe recipe) {
    final RecipeDescriptor descriptor = DtoFactory.getInstance().createDto(RecipeDescriptor.class).withId(recipe.getId()).withName(recipe.getName()).withType(recipe.getType()).withScript(recipe.getScript()).withCreator(recipe.getCreator()).withTags(recipe.getTags());
    final UriBuilder builder = getServiceContext().getServiceUriBuilder();
    final Link removeLink = LinksHelper.createLink("DELETE", builder.clone().path(getClass(), "removeRecipe").build(recipe.getId()).toString(), LINK_REL_REMOVE_RECIPE);
    final Link scriptLink = LinksHelper.createLink("GET", builder.clone().path(getClass(), "getRecipeScript").build(recipe.getId()).toString(), TEXT_PLAIN, LINK_REL_GET_RECIPE_SCRIPT);
    descriptor.setLinks(asList(scriptLink, removeLink));
    return descriptor;
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 3 with RecipeDescriptor

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

the class CreateWorkspacePresenter method show.

/**
     * Shows special dialog window which allows set up workspace which will be created.
     *
     * @param workspaces
     *         list of existing workspaces
     */
public void show(List<WorkspaceDto> workspaces, final Callback<Component, Exception> callback) {
    this.callback = callback;
    workspacesNames.clear();
    for (WorkspaceDto workspace : workspaces) {
        workspacesNames.add(workspace.getConfig().getName());
    }
    Promise<List<RecipeDescriptor>> recipes = recipeService.getAllRecipes();
    recipes.then(new Operation<List<RecipeDescriptor>>() {

        @Override
        public void apply(List<RecipeDescriptor> recipeDescriptors) throws OperationException {
            CreateWorkspacePresenter.this.recipes = recipeDescriptors;
        }
    });
    String workspaceName = browserAddress.getWorkspaceName();
    view.setWorkspaceName(workspaceName);
    validateCreateWorkspaceForm();
    view.show();
}
Also used : WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 4 with RecipeDescriptor

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

the class NameGeneratorTest method generateCustomRecipeName3.

@Test
public void generateCustomRecipeName3() throws Exception {
    String newName = "RECIPE-11";
    RecipeWidget environment3 = mock(RecipeWidget.class);
    RecipeWidget environment4 = mock(RecipeWidget.class);
    RecipeWidget environment5 = mock(RecipeWidget.class);
    RecipeWidget environment6 = mock(RecipeWidget.class);
    RecipeWidget environment7 = mock(RecipeWidget.class);
    RecipeWidget environment8 = mock(RecipeWidget.class);
    RecipeWidget environment9 = mock(RecipeWidget.class);
    RecipeWidget environment10 = mock(RecipeWidget.class);
    RecipeDescriptor recipeDescriptor3 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor4 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor5 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor6 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor7 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor8 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor9 = mock(RecipeDescriptor.class);
    RecipeDescriptor recipeDescriptor10 = mock(RecipeDescriptor.class);
    when(recipe1.getDescriptor()).thenReturn(recipeDescriptor1);
    when(recipe2.getDescriptor()).thenReturn(recipeDescriptor2);
    when(environment3.getDescriptor()).thenReturn(recipeDescriptor3);
    when(environment4.getDescriptor()).thenReturn(recipeDescriptor4);
    when(environment5.getDescriptor()).thenReturn(recipeDescriptor5);
    when(environment6.getDescriptor()).thenReturn(recipeDescriptor6);
    when(environment7.getDescriptor()).thenReturn(recipeDescriptor7);
    when(environment8.getDescriptor()).thenReturn(recipeDescriptor8);
    when(environment9.getDescriptor()).thenReturn(recipeDescriptor9);
    when(environment10.getDescriptor()).thenReturn(recipeDescriptor10);
    when(recipeDescriptor1.getName()).thenReturn("RECIPE-1");
    when(recipeDescriptor2.getName()).thenReturn("RECIPE-2");
    when(recipeDescriptor3.getName()).thenReturn("RECIPE-3");
    when(recipeDescriptor4.getName()).thenReturn("RECIPE-4");
    when(recipeDescriptor5.getName()).thenReturn("RECIPE-5");
    when(recipeDescriptor6.getName()).thenReturn("RECIPE-6");
    when(recipeDescriptor7.getName()).thenReturn("RECIPE-7");
    when(recipeDescriptor8.getName()).thenReturn("RECIPE-8");
    when(recipeDescriptor9.getName()).thenReturn("RECIPE-9");
    when(recipeDescriptor10.getName()).thenReturn("RECIPE-10");
    HashSet<RecipeWidget> recipes = new HashSet<>(Arrays.asList(recipe1, recipe2, environment3, environment4, environment5, environment6, environment7, environment8, environment9, environment10));
    String generated = NameGenerator.generateCustomRecipeName(recipes);
    assertEquals(newName, generated);
}
Also used : RecipeDescriptor(org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor) RecipeWidget(org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.entry.RecipeWidget) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with RecipeDescriptor

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

the class SshCategoryPresenter method updateTargetRecipe.

/**
     * Updates as existent target recipe and save it.
     */
private void updateTargetRecipe() {
    RecipeUpdate recipeUpdate = dtoFactory.createDto(RecipeUpdate.class).withId(selectedTarget.getRecipe().getId()).withName(sshView.getTargetName()).withType(selectedTarget.getRecipe().getType()).withTags(selectedTarget.getRecipe().getTags()).withDescription(selectedTarget.getRecipe().getDescription()).withScript("{" + "\"host\": \"" + selectedTarget.getHost() + "\", " + "\"port\": \"" + selectedTarget.getPort() + "\", " + "\"username\": \"" + selectedTarget.getUserName() + "\", " + "\"password\": \"" + selectedTarget.getPassword() + "\"" + "}");
    Promise<RecipeDescriptor> updateRecipe = recipeServiceClient.updateRecipe(recipeUpdate);
    updateRecipe.then(new Operation<RecipeDescriptor>() {

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

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

Aggregations

RecipeDescriptor (org.eclipse.che.api.machine.shared.dto.recipe.RecipeDescriptor)15 OperationException (org.eclipse.che.api.promises.client.OperationException)6 ArrayList (java.util.ArrayList)4 NewRecipe (org.eclipse.che.api.machine.shared.dto.recipe.NewRecipe)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 Response (com.jayway.restassured.response.Response)2 List (java.util.List)2 RecipeUpdate (org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate)2 RecipeEditorPanel (org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.editor.RecipeEditorPanel)2 Test (org.testng.annotations.Test)2 JSONObject (com.google.gwt.json.client.JSONObject)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 Machine (org.eclipse.che.api.core.model.machine.Machine)1 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)1 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1 Operation (org.eclipse.che.api.promises.client.Operation)1