Java Code Examples for io.restassured.response.ValidatableResponse#body()

The following examples show how to use io.restassured.response.ValidatableResponse#body() . 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: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testOperationReviewResource(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("paths.'/reviews'.get.summary", equalTo("get all the reviews"));
    vr.body("paths.'/reviews'.get.operationId", equalTo("getAllReviews"));

    vr.body("paths.'/reviews'.post.summary", equalTo("Create a Review"));
    vr.body("paths.'/reviews'.post.operationId", equalTo("createReview"));

    vr.body("paths.'/reviews/{id}'.get.summary", equalTo("Get a review with ID"));
    vr.body("paths.'/reviews/{id}'.get.operationId", equalTo("getReviewById"));

    vr.body("paths.'/reviews/{id}'.delete.summary", equalTo("Delete a Review with ID"));
    vr.body("paths.'/reviews/{id}'.delete.operationId", equalTo("deleteReview"));

    vr.body("paths.'/reviews/users/{user}'.get.summary", equalTo("Get all reviews by user"));
    vr.body("paths.'/reviews/users/{user}'.get.operationId", equalTo("getReviewByUser"));

    vr.body("paths.'/reviews/airlines/{airline}'.get.summary", equalTo("Get all reviews by airlines"));
    vr.body("paths.'/reviews/airlines/{airline}'.get.operationId", equalTo("getReviewByAirline"));

    vr.body("paths.'/reviews/{user}/{airlines}'.get.summary", equalTo("Get all reviews for an airline by User"));
    vr.body("paths.'/reviews/{user}/{airlines}'.get.operationId", equalTo("getReviewByAirlineAndUser"));
}
 
Example 3
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testTagDeclarations(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String tagsPath = "tags.find { it.name == '";
    String desc = "' }.description";
    vr.body(tagsPath + "user" + desc, equalTo("Operations about user"));
    vr.body(tagsPath + "create" + desc, equalTo("Operations about create"));
    vr.body(tagsPath + "Airlines" + desc, equalTo("All the airlines methods"));
    vr.body(tagsPath + "Availability" + desc, equalTo("All the availability methods"));
    vr.body(tagsPath + "Get Flights" + desc, equalTo("method to retrieve all flights available"));
    vr.body(tagsPath + "Get Flights" + "' }.externalDocs.description", equalTo("A list of all the flights offered by the app"));
    vr.body(tagsPath + "Get Flights" + "' }.externalDocs.url", equalTo("http://airlinesratingapp.com/ourflights"));
    vr.body(tagsPath + "Bookings" + desc, equalTo("All the bookings methods"));
    vr.body(tagsPath + "Reservations" + desc, equalTo("All the reservation methods"));
    vr.body(tagsPath + "Reviews" + desc, equalTo("All the review methods"));
    vr.body(tagsPath + "Ratings" + desc, equalTo("All the ratings methods"));
}
 
Example 4
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testEncodingResponses(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String s = "paths.'/user/{username}'.put.responses.'200'.content.'application/json'.encoding.password.";
    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));

    String t = "paths.'/user/{username}'.put.responses.'200'.content.'application/xml'.encoding.password.";
    vr.body(t + "contentType", equalTo("text/plain"));
    vr.body(t + "style", equalTo("form"));
    vr.body(t + "explode", equalTo(true));
    vr.body(t + "allowReserved", equalTo(true));
}
 
Example 5
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testHeaderInAPIResponse(String type) {
    ValidatableResponse vr = callEndpoint(type);

    // Headers within APIResponse
    String responseHeader1 = "paths.'/reviews/{id}'.get.responses.'200'.headers.responseHeader1";
    vr.body(responseHeader1, notNullValue());
    vr.body(responseHeader1 + ".description", equalTo("Max rate"));
    vr.body(responseHeader1 + ".required", equalTo(true));
    vr.body(responseHeader1 + ".deprecated", equalTo(true));
    vr.body(responseHeader1 + ".allowEmptyValue", equalTo(true));
    vr.body(responseHeader1 + ".style", equalTo("simple"));
    vr.body(responseHeader1 + ".schema.type", equalTo("integer"));

    String responseHeader2 = "paths.'/reviews/{id}'.get.responses.'200'.headers.responseHeader2";
    vr.body(responseHeader2, notNullValue());
    vr.body(responseHeader2 + ".description", equalTo("Input value"));
    vr.body(responseHeader2 + ".required", equalTo(true));
    vr.body(responseHeader2 + ".deprecated", equalTo(true));
    vr.body(responseHeader2 + ".allowEmptyValue", equalTo(true));
    vr.body(responseHeader2 + ".style", equalTo("simple"));
    vr.body(responseHeader2 + ".schema.type", equalTo("string"));
}
 
Example 6
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 6 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testAPIResponses(String type) {
    ValidatableResponse vr = callEndpoint(type);
    // @APIResponse annotations nested within @APIResponses
    vr.body("paths.'/bookings/{id}'.get.responses", aMapWithSize(2));
    vr.body("paths.'/bookings/{id}'.get.responses.'200'.description", equalTo("Booking retrieved"));
    vr.body("paths.'/bookings/{id}'.get.responses.'404'.description", equalTo("Booking not found"));

    vr.body("paths.'/reviews/users/{user}'.get.responses", aMapWithSize(2));
    vr.body("paths.'/reviews/users/{user}'.get.responses.'200'.description", equalTo("Review(s) retrieved"));
    vr.body("paths.'/reviews/users/{user}'.get.responses.'404'.description", equalTo("Review(s) not found"));

    vr.body("paths.'/user/{username}'.put.responses", aMapWithSize(3));
    vr.body("paths.'/user/{username}'.put.responses.'200'.description", equalTo("User updated successfully"));
    vr.body("paths.'/user/{username}'.put.responses.'400'.description", equalTo("Invalid user supplied"));
    vr.body("paths.'/user/{username}'.put.responses.'404'.description", equalTo("User not found"));
}
 
Example 7
Source File: ModelReaderAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testExampleObject(String type) {
    ValidatableResponse vr = callEndpoint(type);
    // Example in Components
    vr.body("components.examples.review.summary", equalTo("External review example"));
    vr.body("components.examples.review.description", equalTo("This example exemplifies the content on our site."));
    vr.body("components.examples.review.externalValue", equalTo("http://foo.bar/examples/review-example.json"));
}
 
Example 8
Source File: FilterTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testFilterLink(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("filterLink - The username corresponding to provided user id"));
}
 
Example 9
Source File: ModelReaderAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testTagsInOperations(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("paths.'/availability'.get.tags", containsInAnyOrder("Get Flights", "Availability"));
    vr.body("paths.'/modelReader/bookings'.get.tags", containsInAnyOrder("bookings"));
}
 
Example 10
Source File: ApplicationPathTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testPathItems(String type) {
    ValidatableResponse vr = this.callEndpoint(type);
    vr.body("paths.'/restapi/v1/apppaths'.get", org.hamcrest.Matchers.notNullValue());
    vr.body("paths.'/apppaths'.get", org.hamcrest.Matchers.nullValue());
}
 
Example 11
Source File: FilterTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testFilterHeader(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String maxRate = "components.headers.Max-Rate";
    vr.body(maxRate + ".description", equalTo("filterHeader - Maximum rate"));
    vr.body(maxRate + ".required", equalTo(true));
    vr.body(maxRate + ".deprecated", equalTo(true));
    vr.body(maxRate + ".allowEmptyValue", equalTo(true));
    vr.body(maxRate + ".style", equalTo("simple"));
    vr.body(maxRate + ".schema.type", equalTo("integer"));
}
 
Example 12
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testExtensionParsing(String type) {
    ValidatableResponse vr = callEndpoint(type);

    vr.body("paths.'/'.get.'x-string-property'", equalTo("string-value"));
    vr.body("paths.'/'.get.'x-boolean-property'", equalTo(Boolean.TRUE));
    vr.body("paths.'/'.get.'x-number-property'", equalTo(117));
    vr.body("paths.'/'.get.'x-object-property'.'property-1'", equalTo("value-1"));
    vr.body("paths.'/'.get.'x-object-property'.'property-3'.'prop-3-1'", equalTo(17));
    vr.body("paths.'/'.get.'x-string-array-property'[1]", equalTo("two"));
    vr.body("paths.'/'.get.'x-object-array-property'[1].name", equalTo("item-2"));
}
 
Example 13
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testTagsInOperations(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("paths.'/availability'.get.tags", containsInAnyOrder("Get Flights", "Availability"));
    vr.body("paths.'/bookings'.get.tags", containsInAnyOrder("bookings"));
    vr.body("paths.'/bookings'.post.tags", containsInAnyOrder("Bookings", "Reservations"));
    vr.body("paths.'/bookings/{id}'.get.tags", containsInAnyOrder("Bookings", "Reservations"));
    vr.body("paths.'/bookings/{id}'.put.tags", containsInAnyOrder("Bookings", "Reservations"));
    // no tag - class Tag was overwritten with empty Tag
    vr.body("paths.'/bookings/{id}'.delete.tags", not(hasSize(greaterThan(0))));
    vr.body("paths.'/reviews'.get.tags", containsInAnyOrder("Reviews", "Ratings"));
    vr.body("paths.'/reviews'.post.tags", containsInAnyOrder("Reviews"));
    vr.body("paths.'/reviews/{id}'.get.tags", containsInAnyOrder("Reviews", "Ratings"));
    vr.body("paths.'/reviews/{id}'.delete.tags", containsInAnyOrder("Reviews", "Ratings"));
    vr.body("paths.'/reviews/users/{user}'.get.tags", containsInAnyOrder("Reviews", "Ratings"));
    vr.body("paths.'/reviews/airlines/{airline}'.get.tags", containsInAnyOrder("Reviews", "Ratings"));
    vr.body("paths.'/reviews/{user}/{airlines}'.get.tags", containsInAnyOrder("Reviews", "Ratings"));
    vr.body("paths.'/user'.post.tags", containsInAnyOrder("user", "create"));
    vr.body("paths.'/user/createWithArray'.post.tags", containsInAnyOrder("user", "create"));
    vr.body("paths.'/user/createWithList'.post.tags", containsInAnyOrder("user", "create"));
    vr.body("paths.'/user/{username}'.get.tags", containsInAnyOrder("user"));
    vr.body("paths.'/user/{username}'.put.tags", containsInAnyOrder("user"));
    vr.body("paths.'/user/{username}'.delete.tags", containsInAnyOrder("user"));
    vr.body("paths.'/user/{id}'.get.tags", containsInAnyOrder("user"));
    // empty tag was defined
    vr.body("paths.'/user/login'.get.tags", not(hasSize(greaterThan(0))));
    // no tag was defined
    vr.body("paths.'/user/logout'.get.tags", not(hasSize(greaterThan(0))));
    vr.body("paths.'/'.get.tags", containsInAnyOrder("Airlines"));
}
 
Example 14
Source File: ModelReaderAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testContact(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("info.contact.name", equalTo("AirlinesRatingApp API Support"));
    vr.body("info.contact.url", equalTo("http://exampleurl.com/contact"));
    vr.body("info.contact.email", equalTo("[email protected]"));
}
 
Example 15
Source File: ModelReaderAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testLicense(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("info.license.name", equalTo("Apache 2.0"));
    vr.body("info.license.url", equalTo("http://www.apache.org/licenses/LICENSE-2.0.html"));
}
 
Example 16
Source File: ModelReaderAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testSecuritySchemes(String type) {
    ValidatableResponse vr = callEndpoint(type);
    String s = "components.securitySchemes";
    vr.body(s, hasKey("httpTestScheme"));
}
 
Example 17
Source File: ModelReaderAppTest.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@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 18
Source File: GetPaymentIT.java    From pay-publicapi with MIT License 4 votes vote down vote up
private void assertPaymentWithMoto(ValidatableResponse response) {
    response.body("moto", is(true));
}
 
Example 19
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@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"));

    // Testing @Servers and @Server defined on top of a class with @Server
    // defined in an operation
    // org.eclipse.microprofile.openapi.apps.airlines.resources.ReviewResource
    vr.body("paths.'/reviews/{id}'.delete.servers", hasSize(3));
    vr.body("paths.'/reviews/{id}'.delete.servers.url", hasSize(3));

    url = "https://gigantic-server.com:443";
    serverPath = "paths.'/reviews/{id}'.delete.servers.find { it.url == '" + url + "' }";
    vr.body(serverPath + ".description", equalTo("Secure server"));

    url = "http://gigantic-server.com:80";
    serverPath = "paths.'/reviews/{id}'.delete.servers.find { it.url == '" + url + "' }";
    vr.body(serverPath + ".description", equalTo("Unsecure server"));
    vr.body(serverPath + ".variables", not(hasSize(greaterThan(0))));

    url = "{protocol}://test-server.com";
    serverPath = "paths.'/reviews/{id}'.delete.servers.find { it.url == '" + url + "' }";
    vr.body(serverPath + ".description", equalTo("The production API server"));
    vr.body(serverPath + ".variables", aMapWithSize(1));
    vr.body(serverPath + ".variables.protocol.default", equalTo("https"));
    vr.body(serverPath + ".variables.protocol.enum", containsInAnyOrder("http", "https"));

    // Testing two @Server defined in an @operation annotation on a method
    // org.eclipse.microprofile.openapi.apps.airlines.resources.ReviewResource.createReview(Review)
    vr.body("paths.'/reviews'.post.servers", hasSize(2));
    vr.body("paths.'/reviews'.post.servers.url", hasSize(2));
    url = "localhost:9080/{proxyPath}/reviews/id";
    serverPath = "paths.'/reviews'.post.servers.find { it.url == '" + url + "' }";
    vr.body(serverPath + ".description", equalTo("view of all the reviews"));
    vr.body(serverPath + ".variables", aMapWithSize(1));
    vr.body(serverPath + ".variables.proxyPath.description", equalTo("Base path of the proxy"));
    vr.body(serverPath + ".variables.proxyPath.default", equalTo("proxy"));
    url = "http://random.url/reviews";
    serverPath = "paths.'/reviews'.post.servers.find { it.url == '" + url + "' }";
    vr.body(serverPath + ".description", equalTo("random text"));

    // Testing two @Server defined on top of a class
    // org.eclipse.microprofile.openapi.apps.airlines.resources.BookingResource
    vr.body("paths.'/bookings'.get.servers", hasSize(2));
    vr.body("paths.'/bookings'.get.servers.url", hasSize(2));

    url = "http://gigantic-server.com:80";
    serverPath = "paths.'/bookings'.get.servers.find { it.url == '" + url + "' }";
    vr.body(serverPath + ".description", equalTo("Unsecure server"));
    vr.body(serverPath + ".variables", not(hasSize(greaterThan(0))));

    url = "https://gigantic-server.com:443";
    serverPath = "paths.'/bookings'.get.servers.find { it.url == '" + url + "' }";
    vr.body(serverPath + ".description", equalTo("Secure server"));
    vr.body(serverPath + ".variables", not(hasSize(greaterThan(0))));
}
 
Example 20
Source File: AirlinesAppTest.java    From microprofile-open-api with Apache License 2.0 4 votes vote down vote up
@RunAsClient
@Test(dataProvider = "formatProvider")
public void testVersion(String type) {
    ValidatableResponse vr = callEndpoint(type);
    vr.body("openapi", startsWith("3.0."));
}