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