/** Utility method to create a REST-assured "client" in a thread-safe manner. * @return An initialized {@link RequestSender} connected to this test fixture. */ protected RequestSender when() { return this.given().when(); }
@Test public void badChildCollectionId() { given().when().get("/user/1/oops/1").then().statusCode(Status.NOT_FOUND.getStatusCode()); } }
@Test @RunAsClient @InSequence(6) public void testBasePrometheus() { given().header("Accept", TEXT_PLAIN).when().get("/metrics/base").then().statusCode(200).and() .contentType(TEXT_PLAIN).and().body(containsString("# TYPE base:thread_max_count"), containsString("base:thread_max_count{tier=\"integration\"}")); }
@Test public void testChild() throws Exception { String expected = jsonParser.getJson("/ResourceIT/testChild.json"); given().when().get("/parent/1/children/1").then().statusCode(HttpStatus.SC_OK) .body(equalTo(expected)); }
@Test public void failRootCollection() throws Exception { String expected = jsonParser.getJson("/ResourceIT/failRootCollection.json"); given().when().get("/unknown").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test public void failChild() throws Exception { String expected = jsonParser.getJson("/ResourceIT/failChild.json"); given().when().get("/parent/1/unknown").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test public void failFieldRequest() throws Exception { String expected = jsonParser.getJson("/ResourceIT/failFieldRequest.json"); given().when().get("/parent/1/id").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test void testEmbedded() { String expected = jsonParser.getJson("/EmbeddedIT/testEmbedded.json"); given().when().get("/embedded/1").then().statusCode(HttpStatus.SC_OK).body(equalTo(expected)); }
@Test public void testRootCollectionRelationships() { String expected = jsonParser.getJson("/ResourceIT/testRootCollectionRelationships.json"); given() .when().get("/parent/1/relationships/children").then().statusCode(HttpStatus.SC_OK) .body(equalTo(expected)); }
@Test public void testSubCollectionRelationships() throws Exception { String expected = jsonParser.getJson("/ResourceIT/testSubCollectionRelationships.json"); given().when().get("/parent/1/children/1/relationships/parents").then().statusCode(HttpStatus.SC_OK) .body(equalTo(expected)); }
@Test public void failRootCollectionId() { String expected = jsonParser.getJson("/ResourceIT/failRootCollectionId.json"); given().when().get("/parent/6789").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test public void parseFailure() { String expected = jsonParser.getJson("/ResourceIT/parseFailure.json"); given().when().get("company/1|apps/2/links/foo").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test @RunAsClient @InSequence(5) public void testBase() { given().header("Accept", APPLICATION_JSON).when().get("/metrics/base").then().statusCode(200).and() .contentType(MpMetricTest.APPLICATION_JSON).and().body(containsString("thread.max.count")); }
@Test(dataProvider = "like_queries") public void testSpecialCharacterLikeQuery(String filterParam, int noOfRecords) throws Exception { String actual = given().when().get(String.format("/book?%s", filterParam)).then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); assertEquals(doc.getData().get().size(), noOfRecords); }
@Test public void testRequestRootPathSuccess() throws Exception { given().when() .get("/example") .then() .statusCode(equalTo(HttpUtil.HTTP_OK)) .and() .contentType(equalTo("application/json")) .and() .body("testKey", equalTo("testValue1")); }
@Test public void testRootCollectionId() { String expected = jsonParser.getJson("/ResourceIT/testRootCollectionId.json"); String actual = given().when().get("/parent/1").then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEquals(actual, expected); }
@Test(priority = -1) public void testRootCollection() throws Exception { String actual = given().when().get("/parent").then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); assertEquals(doc.getData().get().size(), 4); }
@Test(priority = -1) public void testRootCollectionWithNoOperatorFilter() throws Exception { String actual = given().when().get("/parent?filter[parent.id][isnull]").then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); assertEquals(doc.getData().get().size(), 0); }
@Test @RunAsClient @InSequence(2) public void testTextPlainResponseContentType() { Header acceptHeader = new Header("Accept", TEXT_PLAIN); given().header(acceptHeader).when().get("/metrics").then().statusCode(200).and().contentType(TEXT_PLAIN); }
@Test void testOne2One() { String expected = jsonParser.getJson("/EmbeddedIT/testOne2One.json"); String actual = given().when().get("/right/1") .then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEqualDocuments(actual, expected); } }