io.restassured.response.ValidatableResponse Java Examples
The following examples show how to use
io.restassured.response.ValidatableResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelReaderAppTest.java From microprofile-open-api with Apache License 2.0 | 6 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testServer(String type) { ValidatableResponse vr = callEndpoint(type); vr.body("servers", hasSize(2)); vr.body("servers.url", hasSize(2)); String url = "https://{username}.gigantic-server.com:{port}/{basePath}"; String serverPath = "servers.find { it.url == '" + url + "' }"; vr.body(serverPath + ".description", equalTo("The production API server")); vr.body(serverPath + ".variables", aMapWithSize(4)); vr.body(serverPath + ".variables.username.description", equalTo("Reviews of the app by users")); vr.body(serverPath + ".variables.username.default", equalTo("user1")); vr.body(serverPath + ".variables.username.enum", containsInAnyOrder("user1", "user2")); vr.body(serverPath + ".variables.port.description", equalTo("Booking data")); vr.body(serverPath + ".variables.port.default", equalTo("8443")); vr.body(serverPath + ".variables.user.description", equalTo("User data")); vr.body(serverPath + ".variables.user.default", equalTo("user")); vr.body(serverPath + ".variables.basePath.default", equalTo("v2")); url = "https://test-server.com:80/basePath"; serverPath = "servers.find { it.url == '" + url + "' }"; vr.body(serverPath + ".description", equalTo("The test API server")); }
Example #2
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 6 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testAPIResponse(String type) { ValidatableResponse vr = callEndpoint(type); // @APIResponse at method level vr.body("paths.'/availability'.get.responses", aMapWithSize(2)); vr.body("paths.'/availability'.get.responses.'200'.description", equalTo("successful operation")); vr.body("paths.'/availability'.get.responses.'404'.description", equalTo("No available flights found")); vr.body("paths.'/bookings'.post.responses", aMapWithSize(1)); vr.body("paths.'/bookings'.post.responses.'201'.description", equalTo("Booking created")); vr.body("paths.'/user/{username}'.delete.responses", aMapWithSize(3)); vr.body("paths.'/user/{username}'.delete.responses.'200'.description", equalTo("User deleted successfully")); vr.body("paths.'/user/{username}'.delete.responses.'400'.description", equalTo("Invalid username supplied")); vr.body("paths.'/user/{username}'.delete.responses.'404'.description", equalTo("User not found")); }
Example #3
Source File: ResourcesFilterRateLimiterIT.java From pay-publicapi with MIT License | 6 votes |
@Test public void cancelPayment_whenRateLimitIsReached_shouldReturn429Response() throws Exception { connectorMockClient.respondOk_whenCancelCharge(CHARGE_ID, GATEWAY_ACCOUNT_ID); List<Callable<ValidatableResponse>> tasks = Arrays.asList( () -> postCancelPaymentResponse(API_KEY), () -> postCancelPaymentResponse(API_KEY), () -> postCancelPaymentResponse(API_KEY) ); List<ValidatableResponse> finishedTasks = invokeAll(tasks); assertThat(finishedTasks, hasItem(aResponse(204))); assertThat(finishedTasks, hasItem(anErrorResponse())); }
Example #4
Source File: PaymentRefundsResourceIT.java From pay-publicapi with MIT License | 6 votes |
private void assertRefundsResponse(ValidatableResponse paymentRefundsResponse) { paymentRefundsResponse .statusCode(200) .contentType(JSON) .body("payment_id", is(CHARGE_ID)) .body("_links.self.href", is(paymentRefundsLocationFor(CHARGE_ID))) .body("_links.payment.href", is(paymentLocationFor(configuration.getBaseUrl(), CHARGE_ID))) .body("_embedded.refunds.size()", is(2)) .body("_embedded.refunds[0].refund_id", is("100")) .body("_embedded.refunds[0].created_date", is(CREATED_DATE)) .body("_embedded.refunds[0].amount", is(100)) .body("_embedded.refunds[0].status", is("available")) .body("_embedded.refunds[0]._links.size()", is(2)) .body("_embedded.refunds[0]._links.self.href", is(paymentRefundLocationFor(CHARGE_ID, "100"))) .body("_embedded.refunds[0]._links.payment.href", is(paymentLocationFor(configuration.getBaseUrl(), CHARGE_ID))) .body("_embedded.refunds[1].refund_id", is("300")) .body("_embedded.refunds[1].created_date", is(CREATED_DATE)) .body("_embedded.refunds[1].amount", is(300)) .body("_embedded.refunds[1].status", is("pending")) .body("_embedded.refunds[1]._links.size()", is(2)) .body("_embedded.refunds[1]._links.self.href", is(paymentRefundLocationFor(CHARGE_ID, "300"))) .body("_embedded.refunds[1]._links.payment.href", is(paymentLocationFor(configuration.getBaseUrl(), CHARGE_ID))); }
Example #5
Source File: PrometheusStandaloneCanaryAnalysisTest.java From kayenta with Apache License 2.0 | 6 votes |
@Test public void canaryAnalysisIsSuccessful() { String canaryAnalysisExecutionId = steps.createCanaryAnalysis( "cpu-successful-analysis-case", "prometheus-account", "minio-store-account", "canary-configs/prometheus/integration-test-cpu.json"); ValidatableResponse response = steps.waitUntilCanaryAnalysisCompleted(canaryAnalysisExecutionId); response .body("executionStatus", is("SUCCEEDED")) .body("canaryAnalysisExecutionResult.hasWarnings", is(false)) .body("canaryAnalysisExecutionResult.didPassThresholds", is(true)) .body( "canaryAnalysisExecutionResult.canaryScoreMessage", is("Final canary score 100.0 met or exceeded the pass score threshold.")); }
Example #6
Source File: PrometheusStandaloneCanaryAnalysisTest.java From kayenta with Apache License 2.0 | 6 votes |
@Test public void canaryAnalysisIsFailed() { String canaryAnalysisExecutionId = steps.createCanaryAnalysis( "cpu-marginal-analysis-case", "prometheus-account", "minio-store-account", "canary-configs/prometheus/integration-test-cpu.json"); ValidatableResponse response = steps.waitUntilCanaryAnalysisCompleted(canaryAnalysisExecutionId); response .body("executionStatus", is("TERMINAL")) .body("canaryAnalysisExecutionResult.hasWarnings", is(false)) .body("canaryAnalysisExecutionResult.didPassThresholds", is(false)) .body( "canaryAnalysisExecutionResult.canaryScoreMessage", is("Final canary score 0.0 is not above the marginal score threshold.")); }
Example #7
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 6 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testSecurityScheme(String type) { ValidatableResponse vr = callEndpoint(type); String http = "components.securitySchemes.httpSchemeForTest."; vr.body(http + "type", equalTo("http")); vr.body(http + "description", equalTo("user security scheme")); vr.body(http + "scheme", equalTo("testScheme")); String booking = "components.securitySchemes.bookingSecurityScheme."; vr.body(booking + "type", equalTo("openIdConnect")); vr.body(booking + "description", equalTo("Security Scheme for booking resource")); vr.body(booking + "openIdConnectUrl", equalTo("http://openidconnect.com/testurl")); String auth = "components.securitySchemes.airlinesRatingApp_auth."; vr.body(auth + "type", equalTo("apiKey")); vr.body(auth + "description", equalTo("authentication needed to access Airlines app")); vr.body(auth + "name", equalTo("api_key")); vr.body(auth + "in", equalTo("header")); String reviewoauth2 = "components.securitySchemes.reviewoauth2."; vr.body(reviewoauth2 + "type", equalTo("oauth2")); vr.body(reviewoauth2 + "description", equalTo("authentication needed to create and delete reviews")); }
Example #8
Source File: SearchAPIIT.java From molgenis with GNU Lesser General Public License v3.0 | 6 votes |
@ParameterizedTest() @MethodSource("provideMutationsCases") void testSearchMutations( String id, String attribute, String operator, String value, Integer count, List<String> contains, String comment) { ValidatableResponse response = doQuery("search_mutations", attribute, operator, value); if (contains.size() > 0) { var ids = response.extract().jsonPath().getList("items.data.ID").stream().collect(toSet()); assertThat(id, ids, hasItems(contains.toArray())); } if (count != null) { assertEquals(count, response.extract().path("page.totalElements"), id); } }
Example #9
Source File: ModelReaderAppTest.java From microprofile-open-api with Apache License 2.0 | 6 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testComponents(String type) { ValidatableResponse vr = callEndpoint(type); // Tests to ensure that the reusable items declared using the // @Components annotation (within @OpenAPIDefinition) exist. // Each of these item types are tested elsewhere, so no need to test the // content of them here. vr.body("components.schemas.Bookings", notNullValue()); vr.body("components.schemas.Airlines", notNullValue()); vr.body("components.schemas.AirlinesRef", notNullValue()); vr.body("components.responses.FoundAirlines", notNullValue()); vr.body("components.responses.FoundBookings", notNullValue()); vr.body("components.parameters.departureDate", notNullValue()); vr.body("components.parameters.username", notNullValue()); vr.body("components.examples.review", notNullValue()); vr.body("components.examples.user", notNullValue()); vr.body("components.requestBodies.review", notNullValue()); vr.body("components.headers.Max-Rate", notNullValue()); vr.body("components.headers.Request-Limit", notNullValue()); vr.body("components.securitySchemes.httpTestScheme", notNullValue()); vr.body("components.links.UserName", notNullValue()); }
Example #10
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 6 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testLink(String type) { ValidatableResponse vr = callEndpoint(type); String s = "paths.'/user/{id}'.get.responses.'200'.links.'User name'."; vr.body(s + "operationId", equalTo("getUserByName")); vr.body(s + "description", equalTo("The username corresponding to provided user id")); String t = "paths.'/user/{id}'.get.responses.'200'.links.Review."; vr.body(t + "operationRef", equalTo("/db/reviews/{userName}")); vr.body(t + "description", equalTo("The reviews provided by user")); String k = "paths.'/reviews'.post.responses.'201'.links.Review."; vr.body(k + "operationId", equalTo("getReviewById")); vr.body(k + "description", equalTo("get the review that was added")); }
Example #11
Source File: ConfluentCompatApiTest.java From apicurio-registry with Apache License 2.0 | 6 votes |
/** * Endpoint: /subjects/(string: subject)/versions */ @Test public void testCreateSubject() throws Exception { final String SUBJECT = "subject1"; // POST ValidatableResponse res = given() .when() .contentType(ContentTypes.COMPAT_SCHEMA_REGISTRY_STABLE_LATEST) .body(SCHEMA_SIMPLE_WRAPPED) .post("/ccompat/subjects/{subject}/versions", SUBJECT) .then() .statusCode(200) .body("id", Matchers.allOf(Matchers.isA(Integer.class), Matchers.greaterThanOrEqualTo(0))); /*int id = */res.extract().jsonPath().getInt("id"); this.waitForArtifact(SUBJECT); // Verify given() .when() .get("/artifacts/{artifactId}", SUBJECT) .then() .statusCode(200) .body("", equalTo(new JsonPath(SCHEMA_SIMPLE).getMap(""))); }
Example #12
Source File: PetStoreAppTest.java From microprofile-open-api with Apache License 2.0 | 6 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testAPIResponseSchema(String type) { ValidatableResponse vr = callEndpoint(type); String path = dereference(vr, "paths.'/pet/{petId}'.post.responses.'204'"); // The response is present vr.body(path, notNullValue()); vr.body(path, hasEntry("description", "No Content")); String schemaPath = dereference(vr, path) + ".content.'text/csv'.schema"; // The schema is present vr.body(schemaPath, notNullValue()); String schemaObject = dereference(vr, schemaPath); vr.body(schemaObject, allOf(aMapWithSize(3), hasEntry(equalTo("required"), notNullValue()), hasEntry(equalTo("type"), equalTo("object")), hasEntry(equalTo("properties"), notNullValue()))); }
Example #13
Source File: FilterTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testFilterSchema(String type) { ValidatableResponse vr = callEndpoint(type); final String response201Path = "paths.'/streams'.post.responses.'201'"; vr.body(response201Path + ".content.'application/json'.schema.description", equalTo("filterSchema - subscription information")); }
Example #14
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testOAuthFlows(String type) { ValidatableResponse vr = callEndpoint(type); String t = "components.securitySchemes.reviewoauth2.flows"; vr.body(t, hasKey("implicit")); vr.body(t, hasKey("authorizationCode")); vr.body(t, hasKey("password")); vr.body(t, hasKey("clientCredentials")); }
Example #15
Source File: CreatePaymentIT.java From pay-publicapi with MIT License | 5 votes |
protected ValidatableResponse postPaymentResponse(String payload) { return given().port(app.getLocalPort()) .body(payload) .accept(JSON) .contentType(JSON) .header(AUTHORIZATION, "Bearer " + PaymentResourceITestBase.API_KEY) .post(PAYMENTS_PATH) .then(); }
Example #16
Source File: GetPaymentIT.java From pay-publicapi with MIT License | 5 votes |
private void assertErrorEventsResponse(ValidatableResponse response) throws IOException { InputStream body = response .statusCode(500) .contentType(JSON).extract() .body().asInputStream(); JsonAssert.with(body) .assertThat("$.*", hasSize(2)) .assertThat("$.code", is("P0398")) .assertThat("$.description", is("Downstream system error")); }
Example #17
Source File: ModelReaderAppTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testInfo(String type) { ValidatableResponse vr = callEndpoint(type); vr.body("info.title", equalTo("AirlinesRatingApp API")); vr.body("info.version", equalTo("1.0")); vr.body("info.termsOfService", equalTo("http://airlinesratingapp.com/terms")); }
Example #18
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testEncodingRequestBody(String type) { ValidatableResponse vr = callEndpoint(type); String s = "paths.'/user'.post.requestBody.content.'application/json'.encoding.email."; vr.body(s + "contentType", equalTo("text/plain")); vr.body(s + "style", equalTo("form")); vr.body(s + "explode", equalTo(true)); vr.body(s + "allowReserved", equalTo(true)); }
Example #19
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testOAuthScope(String type) { ValidatableResponse vr = callEndpoint(type); String implicit = "components.securitySchemes.reviewoauth2.flows.implicit."; vr.body(implicit + "scopes.'write:reviews'", equalTo("create a review")); String client = "components.securitySchemes.reviewoauth2.flows.clientCredentials."; vr.body(client + "scopes.'read:reviews'", equalTo("search for a review")); }
Example #20
Source File: RestControllerV2APIIT.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testRetrieveEntityIncludingCategories() { ValidatableResponse response = given(testUserToken) .param("includeCategories", newArrayList("true")) .param("attrs", newArrayList("xcategorical_value")) .get(API_V2 + "V2_API_TypeTestAPIV2/1") .then(); response.statusCode(OKE); response.body( "_meta.attributes[0].categoricalOptions.id", Matchers.hasItems("ref1", "ref2", "ref3")); }
Example #21
Source File: PaymentsRefundsResourceAmountValidationIT.java From pay-publicapi with MIT License | 5 votes |
private ValidatableResponse postPaymentRefundAndThen(String bearerToken, String chargeId, String payload) { return given().port(app.getLocalPort()) .body(payload) .accept(JSON) .contentType(JSON) .header(AUTHORIZATION, "Bearer " + bearerToken) .post(PAYMENTS_PATH + chargeId + "/refunds") .then(); }
Example #22
Source File: AppTestBase.java From microprofile-open-api with Apache License 2.0 | 5 votes |
public ValidatableResponse callEndpoint(String type) { ValidatableResponse vr; if ("JSON".equals(type)) { vr = given().accept(ContentType.JSON).when().get("/openapi").then().statusCode(200); } else { // It seems there is no standard for YAML vr = given().filter(YAML_FILTER).accept(ContentType.ANY).when().get("/openapi").then().statusCode(200); } return vr; }
Example #23
Source File: AppTestBase.java From microprofile-open-api with Apache License 2.0 | 5 votes |
/** * Lookup the object at the provided path in the response and if the object * is a reference (contains a $ref property), return the reference path. If the * object is not a reference, return the input path. * * @param vr the response * @param path a path which may be a reference object (containing a $ref) * @return the path the object references if present, else the input path */ public static String dereference(ValidatableResponse vr, String path) { ExtractableResponse<Response> response = vr.extract(); String ref = response.path(path + ".$ref"); if (ref != null) { return ref.replaceFirst("^#/?", "").replace('/', '.'); } else { return path; } }
Example #24
Source File: TransactionsResourceIT.java From pay-publicapi with MIT License | 5 votes |
private ValidatableResponse searchTransactions(Map<String, String> queryParams) { return given().port(app.getLocalPort()) .accept(JSON) .contentType(JSON) .header(AUTHORIZATION, "Bearer " + API_KEY) .queryParams(queryParams) .get("/v1/transactions") .then(); }
Example #25
Source File: ModelReaderAppTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testOperationBookingResource(String type) { ValidatableResponse vr = callEndpoint(type); vr.body("paths.'/modelReader/bookings'.get.summary", equalTo("Retrieve all bookings for current user")); vr.body("paths.'/modelReader/bookings'.get.operationId", equalTo("getAllBookings")); vr.body("paths.'/modelReader/bookings'.post.summary", equalTo("Create a booking")); vr.body("paths.'/modelReader/bookings'.post.description", equalTo("Create a new booking record with the booking information provided.")); vr.body("paths.'/modelReader/bookings'.post.operationId", equalTo("createBooking")); }
Example #26
Source File: RestControllerV1APIIT.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testGetEntityTypePost() { ValidatableResponse response = given(testUserToken) .contentType(APPLICATION_JSON) .body("{}") .when() .post(API_V1 + "V1_API_TypeTestRefAPIV1/meta?_method=GET") .then(); validateGetEntityType(response); }
Example #27
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testExternalDocumentation(String type) { ValidatableResponse vr = callEndpoint(type); vr.body("externalDocs.description", equalTo("instructions for how to deploy this app")); vr.body("externalDocs.url", containsString("README.md")); }
Example #28
Source File: AirlinesAppTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testRestClientNotPickedUp(String type) { ValidatableResponse vr = callEndpoint(type); //We should not be picking up interfaces annotated with @RegisterRestClient vr.body("paths.'/player/{playerId}'", equalTo(null)); }
Example #29
Source File: FilterTest.java From microprofile-open-api with Apache License 2.0 | 5 votes |
@RunAsClient @Test(dataProvider = "formatProvider") public void testFilterCallback(String type) { ValidatableResponse vr = callEndpoint(type); final String callbacksPath = "paths.'/streams'.post.callbacks.onData.'{$request.query.callbackUrl}/data'.post"; vr.body(callbacksPath + ".description", equalTo("filterCallback - callback post operation")); }
Example #30
Source File: RestControllerV1APIIT.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
@Test void testRetrieveEntityCollectionResponse() { ValidatableResponse response = given(testUserToken) .contentType(APPLICATION_JSON) .when() .get(API_V1 + "V1_API_Items") .then(); validateRetrieveEntityCollectionResponse(response); }