Search in sources :

Example 61 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class RecipeServiceTest method shouldBeAbleToSearchRecipes.

@Test
public void shouldBeAbleToSearchRecipes() throws Exception {
    final RecipeImpl recipe1 = new RecipeImpl().withId("id1").withCreator(USER_ID).withType("docker").withScript("script1 content").withTags(asList("java"));
    final RecipeImpl recipe2 = new RecipeImpl().withId("id2").withCreator(USER_ID).withType("docker").withScript("script2 content").withTags(asList("java", "mongodb"));
    when(recipeDao.search(eq("user123"), eq(asList("java", "mongodb")), eq("docker"), any(int.class), any(int.class))).thenReturn(asList(recipe1, recipe2));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().queryParameter("tags", asList("java", "mongodb")).queryParameter("type", "docker").get(SECURE_PATH + "/recipe");
    assertEquals(response.getStatusCode(), 200);
    assertEquals(unwrapDtoList(response, RecipeDescriptor.class).size(), 2);
}
Also used : Response(com.jayway.restassured.response.Response) Test(org.testng.annotations.Test)

Example 62 with Response

use of com.jayway.restassured.response.Response 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 63 with Response

use of com.jayway.restassured.response.Response 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 64 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class RecipeServiceTest method shouldThrowBadRequestExceptionWhenUpdatingRecipeWithNullId.

@Test
public void shouldThrowBadRequestExceptionWhenUpdatingRecipeWithNullId() throws Exception {
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(newDto(RecipeUpdate.class)).when().put(SECURE_PATH + "/recipe");
    assertEquals(response.getStatusCode(), 400);
}
Also used : Response(com.jayway.restassured.response.Response) RecipeUpdate(org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate) Test(org.testng.annotations.Test)

Example 65 with Response

use of com.jayway.restassured.response.Response in project che by eclipse.

the class RecipeServiceTest method shouldBeAbleToUpdateRecipe.

@Test
public void shouldBeAbleToUpdateRecipe() throws Exception {
    final RecipeImpl recipe = new RecipeImpl().withId("id").withCreator(USER_ID).withType("docker").withScript("script1 content").withTags(asList("java"));
    final RecipeImpl updatedRecipe = new RecipeImpl(recipe).withType("new-type").withScript("new script content").withTags(asList("java", "mongodb"));
    when(recipeDao.update(any())).thenReturn(updatedRecipe);
    RecipeUpdate update = newDto(RecipeUpdate.class).withId(recipe.getId()).withType("new-type").withScript("new script content").withTags(asList("java", "mongodb"));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(update).when().put(SECURE_PATH + "/recipe");
    assertEquals(response.getStatusCode(), 200);
    verify(recipeDao).update(any(RecipeImpl.class));
}
Also used : RecipeUpdate(org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate) Response(com.jayway.restassured.response.Response) Test(org.testng.annotations.Test)

Aggregations

Response (com.jayway.restassured.response.Response)169 Test (org.testng.annotations.Test)129 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)35 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)31 Test (org.junit.Test)31 Matchers.anyString (org.mockito.Matchers.anyString)21 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)19 CswTestCommons.getMetacardIdFromCswInsertResponse (org.codice.ddf.itests.common.csw.CswTestCommons.getMetacardIdFromCswInsertResponse)15 IOException (java.io.IOException)14 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)14 XPathExpressionException (javax.xml.xpath.XPathExpressionException)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 Factory (org.eclipse.che.api.core.model.factory.Factory)11 FactoryDto (org.eclipse.che.api.factory.shared.dto.FactoryDto)11 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)11 DtoFactory (org.eclipse.che.dto.server.DtoFactory)11 WorkspaceDto (org.eclipse.che.api.workspace.shared.dto.WorkspaceDto)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 InputStream (java.io.InputStream)6