@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 validateConnectionJsonio() throws Exception { SerPropertiesDto propertiesDto = buildTestDataStoreSerProps(); given().accept(APPLICATION_JSON_UTF8_VALUE) // .with().content(propertiesDto) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .when()// .post(getVersionPrefix() + "/runtimes/check")// .then()// .statusCode(HttpStatus.OK.value()).log().ifError() // .assertThat().body(notNullValue())// .assertThat().body(instanceOf(String.class)); }
@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\"}")); }
@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 @RunAsClient @InSequence(2) public void testSharedCounter() { Header acceptJson = new Header("Accept", APPLICATION_JSON); given().header(acceptJson).get("/metrics/application").then() .assertThat().body("countMe2", equalTo(1)) .assertThat().body("'org.eclipse.microprofile.metrics.test.MetricAppBean2.meterMe2'.count", equalTo(1)) .assertThat().body("timeMe2.count", equalTo(1)); }
@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 public void testCreateBuilding() throws InterruptedException { // given String payload = "{\"name\":\"testBuilding\"}"; // expect String createdId = given() .body(payload) .contentType("application/json") .when() .post("/building") .then() .statusCode(201) .extract().header("X-Created-Id"); // and when() .get("/building/" + createdId) .then() .statusCode(200) .body("name", is("testBuilding")); }
.post("/property") .then() .assertThat() .statusCode(HttpStatus.SC_CREATED) .extract() .path("data.id"); .post("/property") .then() .assertThat() .statusCode(HttpStatus.SC_CREATED) .extract() .path("data.id"); .get("/property/" + id1) .then() .assertThat() .statusCode(HttpStatus.SC_OK) .body("data.relationships.myStuff.data.type", equalTo("tractor"), "data.relationships.myStuff.data.id", equalTo("1")); .get("/property/" + id2) .then() .assertThat() .statusCode(HttpStatus.SC_OK) .body("data.relationships.myStuff.data.type", equalTo("smartphone"), "data.relationships.myStuff.data.id", equalTo("1")); .get("/property/" + id1 + "?include=myStuff")
@Test public void testMultiplesTMs() { given().log().all() .get("/q2/txnmgr/name").then().statusCode(200).assertThat() .body("name", equalTo("txnmgr") ); given().log().all() .get("/v2/q2/txnmgr/name").then().statusCode(200).assertThat() .body("name", equalTo("txnmgr2") ); } }
.when() .get(location) .then().assertThat() .statusCode(isSuccessful()) .and().contentType(not(TEXT_TURTLE)) .extract().response();
/** * Should return the specification UI. * * @param testContext * @throws Exception */ @Test public void testGetSpecUi(TestContext testContext) throws Exception { final String body = given() .log().everything() .accept(ContentType.TEXT) .when() .get(OpenApiPluginImpl.SPECIFICATION_PATH + "/") .then() .log().everything() .statusCode(HttpUtil.HTTP_OK) .extract().asString(); testContext.assertTrue(body.contains("</html>")); }
@Test @RunAsClient @InSequence(10) public void testBaseMetadata() { Header wantJson = new Header("Accept", APPLICATION_JSON); given().header(wantJson).options("/metrics/base").then().statusCode(200).and() .contentType(MpMetricTest.APPLICATION_JSON); }
@Test(priority = 22) public void addRelationshipChild() { String request = jsonParser.getJson("/ResourceIT/addRelationshipChild.req.json"); String expected = jsonParser.getJson("/ResourceIT/addRelationshipChild.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/parent/5/children/6/relationships/parents") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .header(HttpHeaders.CONTENT_LENGTH, (String) null); String response = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/5/children/6") .then() .statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEqualDocuments(response, expected); }
/** * Should return the example from the specification when the script triggers an HTTP 201 Created status code. * * @throws Exception */ @Test public void testServeScriptedExample() throws Exception { given() .log().everything() // JSON content type in 'Accept' header matches specification example .accept(ContentType.JSON) .when() .put("/simple/apis") .then() .log().everything() .statusCode(HttpUtil.HTTP_CREATED) .body("result", equalTo("success")) .header("MyHeader","MyHeaderValue"); }
@Test(priority = 1) public void testPatchAttrSingle() throws Exception { String request = jsonParser.getJson("/ResourceIT/testPatchAttrSingle.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/2") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .header(HttpHeaders.CONTENT_LENGTH, (String) null); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/2") .then() .statusCode(HttpStatus.SC_OK) .contentType(JSONAPI_CONTENT_TYPE) .extract().response().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); Data<Resource> data = doc.getData(); Resource resource = data.getSingleValue(); assertEquals(resource.getAttributes().get("firstName"), "syzygy"); assertEquals(resource.getRelationships().size(), 2); assertEquals(resource.getRelationships().get("children").getData().get().size(), 2); }
@Test public void badChildCollectionId() { given().when().get("/user/1/oops/1").then().statusCode(Status.NOT_FOUND.getStatusCode()); } }
@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)))); } }
@Test(priority = 10) public void testPatchRelNoUpdateDirect() throws Exception { String request = jsonParser.getJson("/ResourceIT/testPatchRelNoUpdateDirect.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/4/relationships/children") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .header(HttpHeaders.CONTENT_LENGTH, (String) null); }
protected void validate(Tote result) throws Exception { Response response = (Response)result.get("response"); if(b("log", false)){ response.then().log().all();
@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); }