public T ifError() { if (response.statusCode() >= 400) { return logResponse(LogDetail.ALL); } return (T) this; }
@Override public void success(Response s, Response response) { new JSONObject(new String(((TypedByteArray) response.getBody()).getBytes())) }
Connection.Response response = null; try { response = Jsoup.connect(bad_url) .userAgent("Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5") .timeout(100000) .ignoreHttpErrors(true) .execute(); } catch (IOException e) { System.out.println("io - "+e); } System.out.println("Status code = " + response.statusCode()); System.out.println("Status msg = " + response.statusMessage());
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) { Response response = ctx.next(requestSpec, responseSpec); final int statusCode = response.statusCode(); if (matcher.matches(statusCode)) { ResponsePrinter.print(response, response, stream, logDetail, shouldPrettyPrint); final byte[] responseBody; if (logDetail == BODY || logDetail == ALL) { responseBody = response.asByteArray(); } else { responseBody = null; } response = cloneResponseIfNeeded(response, responseBody); } return response; }
@Test(priority = 3) public void testPatchAttrList() throws Exception { String request = jsonParser.getJson("/ResourceIT/testPatchAttrList.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/3") .then() .statusCode(HttpStatus.SC_BAD_REQUEST); }
@Test public void badChildCollectionId() { given().when().get("/user/1/oops/1").then().statusCode(Status.NOT_FOUND.getStatusCode()); } }
@Test @InSequence(1) public void shouldBeAbleToCreateAttachment() throws Exception { // Attachment is not a top level resource, so in the test we hardcode the known location uri_attachment = new URL(base, "api/attachment").toExternalForm(); AttachmentType conf = getCreateAttachment(); uri_attachmentInstance = given(). contentType(ATTACHMENT_MEDIA_TYPE). body(conf). then(). statusCode(Status.CREATED.getStatusCode()). when(). post(uri_attachment). header("Location"); }
Response r = given() .contentType("application/json"). body(json). when(). post(""); ResponseBody body = r.getBody(); if (body != null) { JsonPath path = body.jsonPath(); if (path != null) { int successful = path.get("_shards.successful"); if (successful > 0) { listener.getLogger().println("Event updated"); return true; } else if (path.get("error") != null){ listener.error("Elasticsearch response: "+path.get("error.reason"));
@Test @RunAsClient @InSequence(19) public void testApplicationMetadataItems() { Header wantJson = new Header("Accept", APPLICATION_JSON); JsonPath jsonPath = given().header(wantJson).options("/metrics/application").jsonPath(); Map<String, Object> elements = jsonPath.getMap("."); List<String> missing = new ArrayList<>(); Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.APPLICATION); for (String item : names.keySet()) { if (!elements.containsKey(item)) { missing.add(item); } } assertTrue("Following application items are missing: " + Arrays.toString(missing.toArray()), missing.isEmpty()); }
@Test public void testInitializePropertiesJsonio() throws Exception { Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataSetSerProps()) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/uispec"); assertNotNull(response); String content = response.asString(); assertEquals(getMockDatasetMainFormUISpecs(), content); }
@Test public void testValidatePropertiesJsonio() throws Exception { ObjectNode validationResult = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreSerProps()) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/validate").as(ObjectNode.class); assertNotNull(validationResult); assertEquals("OK", validationResult.get("status").textValue()); }
@Test public void testExceptionThrowingBean() { // Ensure web exception from bean gets bubbled up given() .accept(JSONAPI_CONTENT_TYPE) .get("/exceptionThrowingBean/1") .then() .statusCode(Status.GONE.getStatusCode()); }
@Test @InSequence(0) public void shouldNotBeAbleToLocateAttachmentRoot() throws Exception { given(). then(). contentType(BASE_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("root"). body("link.find {it.@rel == 'attachment'}.size()", equalTo(0)). when(). get(new URL(base, "api/").toExternalForm()). body(); }
public static OAuth2AccessToken getPasswordGrantAccessToken(String username, String password) { return given() .when() .contentType(APPLICATION_FORM_URLENCODED_VALUE) .formParam("grant_type", "password") .formParam("username", username) .formParam("password", password) .formParam("client_id", CLIENT_ID_ADMIN) .formParam("client_secret", CLIENT_SECRET_ADMIN) .post("/oauth/token") .as(OAuth2AccessToken.class); }
@Test public void testGetVersion() throws Exception { Response r = given().accept(APPLICATION_JSON_UTF8_VALUE) // .expect() // .statusCode(200).log().ifError() // .with().port(localServerPort) // .get(getVersionPrefix() + "/version"); r.then() // .statusCode(HttpStatus.OK.value()).log().ifError() // .contentType(APPLICATION_JSON_UTF8_VALUE); // We don't care what values are returned as long as they are filled. JsonPath jsonPathEvaluator = r.jsonPath(); assertThat(jsonPathEvaluator.get("version"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); assertThat(jsonPathEvaluator.get("commit"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); assertThat(jsonPathEvaluator.get("time"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); } }
public boolean isServerStarted() { try { RestAssuredConfig config = RestAssured.config().httpClient(RestAssuredConfig.config().getHttpClientConfig().setParam("CONNECTION_MANAGER_TIMEOUT", 1000)); return RestAssured.given().config(config).baseUri(getBaseUri()).basePath("/mockserver").get("/").statusCode() == 200; } catch (Exception e) { return false; } }
final byte[] binary = buildBaseRequestSpecification() .header(ACCEPT, mimeType) .expect() .statusCode(HttpStatus.SC_OK) .contentType(mimeType) .header(ETAG, HeaderMatchers.isValidEntityTag()) .when() .get(response.getHeader(LOCATION)) .body().asByteArray(); assertEquals(expectedMD5, HashUtils.md5sum(binary), "md5sum"); } finally { buildBaseRequestSpecification().delete(response.getHeader(LOCATION));
@Test @RunAsClient @InSequence(21) public void testApplicationTagJson() { JsonPath jsonPath = given().header("Accept", APPLICATION_JSON) .when() .options("/metrics/application/purple").jsonPath(); String tags = jsonPath.getString("purple.tags"); assertNotNull(tags); assertTrue(tags.contains("app=myShop")); assertTrue(tags.contains("tier=integration")); }