/** * Perform a GET request to a <code>path</code>. Normally the path doesn't have to be fully-qualified e.g. you don't need to * specify the path as <tt>http://localhost:8080/path</tt>. In this case it's enough to use <tt>/path</tt>. * * @param path The path to send the request to. * @param pathParams The path parameters. * @return The response of the GET request. */ public static Response get(String path, Map<String, ?> pathParams) { return given().get(path, pathParams); }
/** * Perform a GET request to a <code>url</code>. * * @param url The url to send the request to. * @return The response of the GET request. */ public static Response get(URL url) { return given().get(url); }
/** * Perform a GET request to a <code>path</code>. Normally the path doesn't have to be fully-qualified e.g. you don't need to * specify the path as <tt>http://localhost:8080/path</tt>. In this case it's enough to use <tt>/path</tt>. * * @param path The path to send the request to. * @param pathParams The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do <code>get("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);</code>. * @return The response of the GET request. */ public static Response get(String path, Object... pathParams) { return given().get(path, pathParams); }
/** * Perform a GET request to a <code>uri</code>. * * @param uri The uri to send the request to. * @return The response of the GET request. */ public static Response get(URI uri) { return given().get(uri); }
/** * Perform a GET request to the statically configured path (by default <code>http://localhost:8080</code>). * * @return The response of the GET request. */ public static Response get() { return given().get(); }
@InSequence(23) public void testApplicationMeterUnitPrometheus() { given().header("Accept", TEXT_PLAIN).when().get("/metrics/application/meterMeA") .then().statusCode(200) .and() .body(containsString("meter_me_a_total")) .body(containsString("meter_me_a_rate_per_second")) .body(containsString("meter_me_a_one_min_rate_per_second")) .body(containsString("meter_me_a_five_min_rate_per_second")) .body(containsString("meter_me_a_fifteen_min_rate_per_second")); }
@Test public void badChildCollectionId() { given().when().get("/user/1/oops/1").then().statusCode(Status.NOT_FOUND.getStatusCode()); } }
@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 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 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 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(priority = 8) public void testGetRelEmptyColl() { String expected = jsonParser.getJson("/ResourceIT/testGetRelEmptyColl.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/4/relationships/children") .then() .statusCode(HttpStatus.SC_OK) .body(equalTo(expected)); }
@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 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(priority = 8) public void testGetNestedSingleInclude() throws IOException { String expected = jsonParser.getJson("/ResourceIT/testGetNestedSingleInclude.json"); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/2?include=children.friends") .then() .statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEqualDocuments(actual, expected); }
@Test(priority = 8) public void testGetWithTrailingSlash() { String expected = jsonParser.getJson("/ResourceIT/testGetWithTrailingSlash.json"); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/") .then() .statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEqualDocuments(actual, expected); }