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());
}
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();
}
});
}
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);
}
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);
}
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());
}
Aggregations