use of io.restassured.response.Response in project okapi by folio-org.
the class TenantRATest method test1.
@Test
public void test1() {
RestAssured.port = port;
RestAssuredClient c;
Response r;
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants//modules").then().statusCode(404);
String superTenantDoc = "{" + LS + " \"id\" : \"supertenant\"," + LS + " \"name\" : \"supertenant\"," + LS + " \"description\" : \"Okapi built-in super tenant\"" + LS + "}";
String superTenantList = "[ " + superTenantDoc + " ]";
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().log().ifValidationFails().statusCode(200).body(equalTo(superTenantList));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// Check that we can not delete the superTenant
c = api.createRestAssured3();
c.given().delete("/_/proxy/tenants/supertenant").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String badId = "{" + LS + " \"id\" : \"Bad Id with Spaces and Specials: ?%!\"," + LS + " \"name\" : \"roskilde\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(badId).post("/_/proxy/tenants").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc = "{" + LS + " \"id\" : \"roskilde\"," + LS + " \"name\" : \"roskilde\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(doc)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String location = r.getHeader("Location");
// post again, fail because of duplicate
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc).post("/_/proxy/tenants").then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").get("/_/proxy/tenants/roskilde/modules/foo").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get(location).then().statusCode(200).body(equalTo(doc));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get(location + "none").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
final String tenantList = "[ " + doc + ", " + superTenantDoc + " ]";
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().log().ifValidationFails().statusCode(200).body(equalTo(tenantList));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().statusCode(200).body(equalTo(superTenantList));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc3BadJson = "{" + LS + " \"id\" : \"roskildedk\"," + LS;
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc3BadJson).post("/_/proxy/tenants").then().statusCode(400);
String doc3 = "{" + LS + " \"id\" : \"roskildedk\"," + LS + " \"name\" : \"roskilde\"," + LS + " \"description\" : \"Roskilde bibliotek\"" + LS + "}";
c = api.createRestAssured3();
Response r3 = c.given().header("Content-Type", "application/json").body(doc3).post("/_/proxy/tenants").then().statusCode(201).body(equalTo(doc3)).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String location3 = r3.getHeader("Location");
logger.debug("location3 = " + location3);
final String tenantList3 = "[ " + doc3 + ", " + superTenantDoc + " ]";
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().statusCode(200).body(equalTo(tenantList3));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc4BadJson = "{" + LS + " \"id\" : \"roskildedk\"," + LS;
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc4BadJson).put(location3).then().statusCode(400);
String doc4badId = "{" + LS + " \"id\" : \"roskildedk2\"," + LS + " \"name\" : \"Roskildes Real Name\"," + LS + " \"description\" : \"Roskilde bibliotek with a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc4badId).put(location3).then().statusCode(400);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc4 = "{" + LS + " \"id\" : \"roskildedk\"," + LS + " \"name\" : \"Roskildes Real Name\"," + LS + " \"description\" : \"Roskilde bibliotek with a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc4).put(location3).then().statusCode(200).body(equalTo(doc4));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location3 + "notThere").then().statusCode(404);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String doc5 = "{" + LS + " \"id\" : \"roskildedk\"," + LS + " \"name\" : \"Roskildes Real Name\"," + LS + " \"description\" : \"Roskilde bibliotek with a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(doc5).put(location3).then().statusCode(200);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
String superdoc2 = "{" + LS + " \"id\" : \"supertenant\"," + LS + " \"name\" : \"The Real Super Tenant\"," + LS + " \"description\" : \"With a better description\"" + LS + "}";
c = api.createRestAssured3();
c.given().header("Content-Type", "application/json").body(superdoc2).put("/_/proxy/tenants/supertenant").then().statusCode(200);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
c = api.createRestAssured3();
c.given().get("/_/proxy/tenants").then().statusCode(200).body(equalTo("[ " + superdoc2 + " ]"));
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// server-side generated Id
String doc6 = "{" + LS + " \"name\" : \"Ringsted\"," + LS + " \"description\" : \"Ringsted description\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc6).post("/_/proxy/tenants").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
location3 = r.getHeader("Location");
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
// no name
String doc7 = "{" + LS + " \"id\" : \"ringsted\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc7).post("/_/proxy/tenants").then().statusCode(201).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
location3 = r.getHeader("Location");
c = api.createRestAssured3();
r = c.given().get("/_/proxy/tenants/ringsted").then().statusCode(200).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
Assert.assertEquals(doc7, r.body().asString());
String doc8 = "{" + LS + " \"id\" : \"ringsted\"," + LS + " \"name\" : \"Ringsted\"" + LS + "}";
c = api.createRestAssured3();
r = c.given().header("Content-Type", "application/json").body(doc8).put(location3).then().statusCode(200).extract().response();
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
JsonObject j = new JsonObject(r.body().asString());
Assert.assertEquals("Ringsted", j.getString("name"));
Assert.assertEquals("ringsted", j.getString("id"));
c = api.createRestAssured3();
c.given().delete(location3).then().statusCode(204);
Assert.assertTrue("raml: " + c.getLastReport().toString(), c.getLastReport().isEmpty());
}
use of io.restassured.response.Response in project spring-cloud-netflix by spring-cloud.
the class WireMockRestAssuredRequestAdapter method filter.
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext context) {
Map<String, Object> configuration = getConfiguration(requestSpec, context);
configuration.put("contract.jsonPaths", this.jsonPaths.keySet());
Response response = context.next(requestSpec, responseSpec);
if (requestSpec.getBody() != null && !this.jsonPaths.isEmpty()) {
String actual = new String((byte[]) requestSpec.getBody());
for (JsonPath jsonPath : this.jsonPaths.values()) {
new JsonPathValue(jsonPath, actual).assertHasValue(Object.class, "an object");
}
}
if (this.builder != null) {
this.builder.willReturn(getResponseDefinition(response));
StubMapping stubMapping = this.builder.build();
MatchResult match = stubMapping.getRequest().match(new WireMockRestAssuredRequestAdapter(requestSpec));
assertThat(match.isExactMatch()).as("wiremock did not match request").isTrue();
configuration.put("contract.stubMapping", stubMapping);
}
return response;
}
use of io.restassured.response.Response in project vertigo by KleeGroup.
the class WebServiceManagerTest method testDownloadNotModifiedFile.
@Test
public void testDownloadNotModifiedFile() throws ParseException {
final DateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
// Sans préciser le if-Modified-Since, le serveur retourne le fichier
final Response response = loggedAndExpect(given().queryParam("id", 10)).header("Content-Type", Matchers.equalToIgnoringCase("image/png")).header("Content-Disposition", Matchers.equalToIgnoringCase("attachment;filename=\"image10.png\";filename*=UTF-8''image10.png")).header("Content-Length", Matchers.equalTo("27039")).statusCode(HttpStatus.SC_OK).when().get("/test/downloadNotModifiedFile");
final String lastModified = response.getHeader("Last-Modified");
final Date lastModifiedDate = httpDateFormat.parse(lastModified);
final String now = httpDateFormat.format(new Date());
// On test avec le if-Modified-Since now : le server test mais ne retourne pas le fichier
loggedAndExpect(given().queryParam("id", 10).header("if-Modified-Since", now)).statusCode(HttpStatus.SC_NOT_MODIFIED).when().get("/test/downloadNotModifiedFile");
// On test avec le if-Modified-Since 10 min avant le lastModified : le server test et retourne le fichier
final String beforeLastModified = httpDateFormat.format(new DateBuilder(lastModifiedDate).addMinutes(-10).build());
loggedAndExpect(given().queryParam("id", 10).header("if-Modified-Since", beforeLastModified)).header("Content-Type", Matchers.equalToIgnoringCase("image/png")).header("Content-Disposition", Matchers.equalToIgnoringCase("attachment;filename=\"image10.png\";filename*=UTF-8''image10.png")).header("Content-Length", Matchers.equalTo("27039")).statusCode(HttpStatus.SC_OK).when().get("/test/downloadNotModifiedFile");
}
use of io.restassured.response.Response in project vertigo by KleeGroup.
the class WebServiceManagerTest method doGetServerSideObject.
private Map<String, Object> doGetServerSideObject() throws ParseException {
final Map<String, Object> contact = doCreateContact();
final Long oldConId = (Long) contact.get("conId");
final Response getResponse = loggedAndExpect().statusCode(HttpStatus.SC_OK).when().get("/test/filtered/" + oldConId);
final String serverToken = getResponse.body().path("serverToken");
contact.put("serverToken", serverToken);
return contact;
}
use of io.restassured.response.Response in project vertx-openshift-it by cescoffier.
the class CircuitBreakerIT method assertGreeting.
private void assertGreeting(String expected) {
Response response = greetingResponse();
response.then().statusCode(200).body("content", equalTo(expected));
}
Aggregations