Search in sources :

Example 1 with Response

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

the class LinkHeaderGenerationTest method linksHeaderShouldBeCorrectlyGenerated.

@Test
public void linksHeaderShouldBeCorrectlyGenerated(ITestContext ctx) throws Exception {
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().get(SECURE_PATH + "/test/paging/test-path-param?query-param=test-query-param");
    assertEquals(response.getStatusCode(), 200);
    final String headerValue = response.getHeader("Link");
    assertNotNull(headerValue, "Link header is missing in the response");
    final Map<String, String> relToLinkMap = PagingUtil.parseLinkHeader(headerValue);
    final Set<String> expectedRels = new HashSet<>(asList("first", "last", "prev", "next"));
    assertEquals(relToLinkMap.keySet(), expectedRels, "Rels are different " + symmetricDifference(expectedRels, relToLinkMap.keySet()));
    final String expectedUri = "http://localhost:" + ctx.getAttribute(EverrestJetty.JETTY_PORT) + "/rest/private/test/paging/test-path-param";
    for (String link : relToLinkMap.values()) {
        final URI uri = URI.create(link);
        final Map<String, List<String>> params = getQueryParameters(uri.toURL());
        assertEquals(params.size(), 3);
        assertNotNull(params.get("skipCount"));
        assertNotNull(params.get("maxItems"));
        assertEquals(params.get("query-param").get(0), "test-query-param");
        assertEquals(link, expectedUri + '?' + uri.getQuery());
    }
}
Also used : Response(com.jayway.restassured.response.Response) List(java.util.List) Arrays.asList(java.util.Arrays.asList) URI(java.net.URI) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with Response

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

the class TestingServiceTest method testUnsuccessfulTestExecution.

// Asking for run a test from un-known framework.
@Test
public void testUnsuccessfulTestExecution() throws Exception {
    //given
    String query = "projectPath=/sample-project&testFramework=unknown";
    //then
    Response response = given().when().get(SERVICE_PATH_RUN_ACTION + "/?" + query);
    assertNotEquals(response.getStatusCode(), 200);
    assertEquals(response.getBody().print(), "No test frameworks found: unknown");
}
Also used : Response(com.jayway.restassured.response.Response) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 3 with Response

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

the class FactoryServiceTest method shouldThrowServerExceptionWhenProvidedFactoryDataInvalid.

@Test
public void shouldThrowServerExceptionWhenProvidedFactoryDataInvalid() throws Exception {
    final String errMessage = "eof";
    doThrow(new IOException(errMessage)).when(factoryBuilderSpy).build(any(InputStream.class));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).multiPart("factory", "any content", FACTORY_IMAGE_MIME_TYPE).expect().statusCode(500).when().post(SERVICE_PATH);
    final ServiceError err = getFromResponse(response, ServiceError.class);
    assertEquals(err.getMessage(), errMessage);
}
Also used : Response(com.jayway.restassured.response.Response) ServiceError(org.eclipse.che.api.core.rest.shared.dto.ServiceError) InputStream(java.io.InputStream) Matchers.anyString(org.mockito.Matchers.anyString) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 4 with Response

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

the class FactoryServiceTest method shouldNotThrowExceptionWhenRemoveNoExistingFactory.

@Test
public void shouldNotThrowExceptionWhenRemoveNoExistingFactory() throws Exception {
    doNothing().when(factoryManager).removeFactory(FACTORY_ID);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).param("id", FACTORY_ID).when().delete(SERVICE_PATH + "/" + FACTORY_ID);
    assertEquals(response.getStatusCode(), 204);
}
Also used : Response(com.jayway.restassured.response.Response) Test(org.testng.annotations.Test)

Example 5 with Response

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

the class FactoryServiceTest method shouldReturnFactoryImageWithGivenName.

@Test
public void shouldReturnFactoryImageWithGivenName() throws Exception {
    final byte[] imageContent = Files.readAllBytes(getImagePath());
    final FactoryImage image = new FactoryImage(imageContent, FACTORY_IMAGE_MIME_TYPE, IMAGE_NAME);
    when(factoryManager.getFactoryImages(FACTORY_ID, IMAGE_NAME)).thenReturn(ImmutableSet.of(image));
    final Response response = given().when().expect().statusCode(200).get(SERVICE_PATH + "/" + FACTORY_ID + "/image?imgId=" + IMAGE_NAME);
    assertEquals(response.getContentType(), FACTORY_IMAGE_MIME_TYPE);
    assertEquals(response.getHeader("content-length"), String.valueOf(imageContent.length));
    assertEquals(response.asByteArray(), imageContent);
}
Also used : 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