{"id":18863604,"url":"https://github.com/neiljbrown/restassured-example","last_synced_at":"2025-04-14T13:06:27.072Z","repository":{"id":89469404,"uuid":"115734837","full_name":"neiljbrown/restassured-example","owner":"neiljbrown","description":"An example of how to use the REST-assured library to write black-box, functional tests for REST APIs in Java.","archived":false,"fork":false,"pushed_at":"2018-06-09T20:56:11.000Z","size":83,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T02:11:11.739Z","etag":null,"topics":["api","examples","rest","restassured","test-automation","testing","testing-tools","wiremock"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neiljbrown.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-29T15:51:41.000Z","updated_at":"2024-03-07T09:53:43.000Z","dependencies_parsed_at":"2023-03-08T21:30:53.669Z","dependency_job_id":null,"html_url":"https://github.com/neiljbrown/restassured-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neiljbrown%2Frestassured-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neiljbrown%2Frestassured-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neiljbrown%2Frestassured-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neiljbrown%2Frestassured-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neiljbrown","download_url":"https://codeload.github.com/neiljbrown/restassured-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886314,"owners_count":21177643,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","examples","rest","restassured","test-automation","testing","testing-tools","wiremock"],"created_at":"2024-11-08T04:37:59.704Z","updated_at":"2025-04-14T13:06:27.062Z","avatar_url":"https://github.com/neiljbrown.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# REST-assured Example\n\n## Overview\nThis project provides an example of how to use the [REST-assured](http://rest-assured.io/) library to write black-box, \nfunctional tests for REST APIs in Java.\n\nREST-assured is a Java library that aims to make it simpler to write out-of-process, functional tests for REST APIs, \nthat are written in Java (or other JVM languages). It runs on top of existing Java testing frameworks (JUnit), and \nincludes a DSL for building API requests and asserting API responses.\n   \nIn this example project, REST-assured is used to implement a suite of functional tests for a couple of REST APIs \nhosted by an imaginary User service that supports creating and retrieving a resource/entity known as a (user) 'realm', \nvia HTTP POST and GET methods. An outline spec. of these APIs is included below. \n    \n## Code\nThe example REST-assured test cases are implemented in Java (8.x) using JUnit (4.x), REST-assured (3.x) and AssertJ.\n\nThe tests can be found in two Java classes in the project's src/main/test/java folder:\n* com.neiljbrown.service.user.CreateRealmApiTest - Test suite for the [Create Realm API](#createRealm)\n* com.neiljbrown.service.user.GetRealmApiTest - Test suite for the [Get Realm API](#createRealm)\n\nThe APIs under test have been stubbed-out (using the [WireMock](http://wiremock.org/) library). This makes the example \ntests simple to run, by avoiding a dependency on a real API service having been deployed, and needing to be \nrunning in a separate process. For the purposes of this project you can ignore the stubbing and use of WireMock.\n\n## Building and Running the Examples \nThe example tests can be compiled and run from within the comfort of your IDE (or from the command line using \nGradle).\n\nFirst ensure you have JDK 8+ installed.  \n\nThen cd to the directory into which you cloned/checked-out the project and use the supplied Gradle build script to \ngenerate an IDE project for either Eclipse or IntelliJ IDEA, using one of the following commands  \n``./gradlew eclipse`` or ``./gradlew idea`` \n\nImport the generated project into your IDE. \n\nOpen the project in your IDE and run the tests contained in one of the aforementioned test classes as you would a \nJUnit test. \n\nTo compile and run the tests from the command line enter the command ``./gradlew test`` \n\n## Debugging the Examples\nYou can debug execution of the tests from within your IDE by setting breakpoints as you would with any other JUnit test.\n\nThe example tests also support logging of the HTTP requests and responses which they make to the console, using \nREST-assured's underlying logging support. By default only failed requests and responses are logged (which is also the\nREST-assured default). You can additionally enable logging of successful requests and responses by setting the Java \nsystem property 'qatest.alwaysLogReqAndResp' to 'true', e.g. java ... -Dqatest.alwaysLogReqAndResp=true. \n\nAn example of an HTTP request and response logged by REST-assured is shown below -   \n```\nRequest method:\tPOST\nRequest URI:\thttp://localhost:52650/user/realm\nProxy:          \u003cnone\u003e\nRequest params:\t\u003cnone\u003e\nQuery params:\t\u003cnone\u003e\nForm params:\t\u003cnone\u003e\nPath params:\t\u003cnone\u003e\nHeaders:        Accept=application/xml\n                Content-Type=application/xml; charset=ISO-8859-1\nCookies:        \u003cnone\u003e\nMultiparts:     \u003cnone\u003e\nBody:\n\u003crealm name=\"realm-0be9c302-69e8-4e49-9fae-72d9e119bb1e\"\u003e\n  \u003cdescription\u003eiNuZRnYHQNvGIgxKnnBmfLbzuPvuRlpdIilHhFxmpKAKCaUMBlkYQePxcHJkfcEFqwhFyWcXLnWEDMUMTHXhBEzHyyIdipHceXhovqarMpPZUGCcpCKtGDRmJLckMuHmHYbNOCzdAAzvuLsBxucrmMnLFWbDvwsyZFNlEkzZRzBVJFUunXkDIjPnwoPlKceuOjwMsLOUPXdbKwQWmKoTIxXqTadTkEyxhfkATjsQkfElnPSZVwKSfXRfDyWaogUQ\u003c/description\u003e\n\u003c/realm\u003e\n```\n\n## API Specification\nThis section contains the spec. of the couple of APIs for which the tests have been written.\n\nThe APIs specified support creating, retrieving and deleting a (User) Realm.\n \n### Realm Resource\nA (User) Realm is a context for the registration and authentication of a user.  The resource comprises the following \nfields. All fields are mandatory unless otherwise stated.\n\n|Field Name|Description \u0026 Constraints|\n|----------|-------------------------|\n|id|Unique, system-generated identifier for the realm. An integer value in the range 1 to 9999.\n|name|Unique name of the realm. Serves as an alias for the realm ID. Max length of 100 chars.|\n|description|Description of the realm. Optional. Max length of 255 chars.| \n|key|System generated encryption key. Fixed length 32 char hex-encoded string.|\n\n### Resource Representation\nThe APIs only support producing and consuming XML representations of a Realm. The schema for this representation, \nspecified by example, is as follows -  \n\n```xml\n\u003crealm id=\"123\" name=\"Acme\"\u003e \n  \u003cdescription\u003eRealm for authenticated users of Acme corp.\u003c/description\u003e \n  \u003ckey\u003e92f1aea4bb92c3661a9c85ee81503e28\u003c/key\u003e\t\t\t\t\t\n\u003c/realm\u003e\t\t\t\t\n```\n\n### API Error Handling\nThe APIs report errors by returning an HTTP response with a status code in the 4xx (client) or 5xx (server) range. An\n “error” resource may also be returned in the response body to distinguish errors reported by the API, and to \nfurther classify an error. An error resource contains a unique code and a message. The error code is a unique string \nin camel-case intended for interpretation by API clients. An example HTTP response for an error returned by the APIs \nis shown below -\n\n```\nHTTP/1.1 404 Not Found \nContent-type: application/xml; charset=utf-8 \n...\n\u003cerror\u003e\t\t\t\t\t\t\n  \u003ccode\u003eRealmNotFound\u003c/code\u003e\n  \u003cmessage\u003eRealm [123] not found.\u003c/message\u003e\t \n\u003c/error\u003e\n```\n\n### \u003ca name=\"createRealm\"\u003e\u003c/a\u003e Create Realm API\nCreates a new realm including the generation of an encryption key. \n\n#### Supported Methods\n|Method|URL|\n|------|---|\n|POST|http://{host}:8080/user/realm|\n\n#### Example Request\n```\nPOST /user/realm HTTP/1.1 \nContent-Type: application/xml; charset=utf-8\n\n\u003crealm name=“{name}”\u003e \n  \u003c!-- Optional --\u003e\n  \u003cdescription\u003e{description}\u003c/description\u003e\n\u003c/realm\u003e\n```\n#### Example Success Response\n```\nHTTP/1.1 201 Created \nContent-Type: application/xml; charset=utf-8 \n\t\t\t\t\t\t\t\t\n\u003crealm id=“{id}” name=“{name}”\u003e \n  \u003cdescription\u003e{description}\u003c/description\u003e \n  \u003ckey\u003e{key}\u003c/key\u003e\n\u003c/realm\u003e\n```\n\n#### Example Error Response\nIf the mandatory realm name is not supplied or if supplied is blank/empty:\t\t\t\t\t\n```\nHTTP/1.1 400 Bad Request \nContent-type: application/xml; charset=utf-8 \n\n\u003cerror\u003e \n  \u003ccode\u003eMissingRealmName\u003c/code\u003e\t\n  \u003cmessage\u003eRealm name is mandatory and must be supplied.\u003c/message\u003e\t\n\u003c/error\u003e\n```\n\t\nIf the requested realm name matches the name of an existing realm.\n```\nHTTP/1.1 400 Bad Request \nContent-type: application/xml; charset=utf-8 \n\t\t\t\t\t\t\n\u003cerror\u003e \n  \u003ccode\u003eDuplicateRealmName\u003c/code\u003e\n  \u003cmessage\u003eDuplicate realm name [{realmName}].\u003c/message\u003e\t\n\u003c/error\u003e \n```\n\nIf the requested realm name is longer than 100 chars.\n```\nHTTP/1.1 400 Bad Request \nContent-type: application/xml; charset=utf-8 \n\t\t\t\t\t\t\n\u003cerror\u003e \n  \u003ccode\u003eInvalidRealmName\u003c/code\u003e\n  \u003cmessage\u003eRealm name should not be longer than 100 chars.\u003c/message\u003e\t\n\u003c/error\u003e \n```\n\nIf the requested realm description is longer than 255 chars.\n```\nHTTP/1.1 400 Bad Request \nContent-type: application/xml; charset=utf-8 \n\t\t\t\t\t\t\n\u003cerror\u003e \n  \u003ccode\u003eInvalidRealmDescription\u003c/code\u003e\n  \u003cmessage\u003eRealm description should not be longer than 255 chars.\u003c/message\u003e\n\u003c/error\u003e\n```\n\nOther error responses\n\n|HTTP Status Code \u0026 Phrase|Cause|\n|-------------------------|-----|\n|415 Unsupported Media Type|The entity supplied in the body of the request cannot be processed in the media-type specified in the Content-Type request header.|\n\n\n### \u003ca name=\"getRealm\"\u003e\u003c/a\u003e Get Realm API\nReturns the details of an individual realm, identified by its unique id.\n\n#### Supported Methods\n|Method|URL|\n|------|---|\n|GET|http://{host}:8080/user/realm/{realmId}|\n\n#### Example Request\n```\nGET /user/realm/{realmId} HTTP/1.1 \nAccept: application/xml\t\t\t\t\t\t\n```\n#### Example Success Response\n```\nHTTP/1.1 200 OK \nContent-Type: application/xml; charset=utf-8\n \n\u003crealm id=“{id}” name=“{name}”\u003e \n  \u003cdescription\u003e{description}\u003c/description\u003e \n   \u003ckey\u003e{key}\u003c/key\u003e\t\t\t\t\t\t\n\u003c/realm\u003e\t\t\t\t\n```\n\n#### Example Error Response\nIf the requested realm id is not an integer value ­or if it is an integer value larger than the allowed maximum (9999).\t\t\t\t\t\n```\nHTTP/1.1 400 Bad Request \nContent-type: application/xml; charset=utf-8 \n\n\u003cerror\u003e \n  \u003ccode\u003eInvalidRealmId\u003c/code\u003e\n  \u003cmessage\u003eInvalid realm id [{realmId}].\u003c/message\u003e\t\t\t\t\n\u003c/error\u003e\n```\n\nIf the requested realm id does not identify an existing realm.\n```\t\t\t\t\t\t\nHTTP/1.1 404 Not Found \nContent-type: application/xml; charset=utf-8 \n\n\u003cerror\u003e\t\t\t\t\t\t\n  \u003ccode\u003eRealmNotFound\u003c/code\u003e\n  \u003cmessage\u003eRealm [123] not found.\u003c/message\u003e\t \n\u003c/error\u003e\n```\n\n### Delete Realm API\nDeletes a user realm by id.  \n\n#### Supported Methods\n|Method|URL|\n|------|---|\n|DELETE|http://{host}:8080/user/realm/{realmId}|\n\n#### Example Request\n```\nDELETE /user/realm/{realmId} HTTP/1.1\n```\n\n#### Example Success Response\n```\nHTTP/1.1 204 No Content \nDate: Tue, 15 Nov 2017 08:12:31 GMT\n```\n\n#### Example Error Response\nIf the requested realm id is not an integer value ­\n```\t\t\t\t\t\t\nHTTP/1.1 400 Bad Request \nContent-type: application/xml; charset=utf-8 \n\n\u003cerror\u003e \n  \u003ccode\u003eInvalidRealmId\u003c/code\u003e\n  \u003cmessage\u003eInvalid realm id [{realmId}].\u003c/message\u003e\t\t\t\t\n\u003c/error\u003e\n```\n\n### Common Errors\nThe following error responses that could be returned by any of the APIs above:\n\n|HTTP Status Code \u0026 Phrase|Cause|\n|-------------------------|-----|\n|405 Method Not Allowed|The specified HTTP method is not supported for the requested resource.|\n|406 Not Acceptable|The requested resource cannot be returned in the media-type specified by  the Accept header.|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneiljbrown%2Frestassured-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneiljbrown%2Frestassured-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneiljbrown%2Frestassured-example/lists"}