Java Code Examples for io.restassured.RestAssured#get()
The following examples show how to use
io.restassured.RestAssured#get() .
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: RestApiLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void whenUpdateCreatedReview_thenUpdated() { // create final BookReview review = createRandomReview(); final String location = createReviewAsUri(review); // update review.setRating(4); Response response = RestAssured.given().contentType(MediaType.APPLICATION_JSON_VALUE).body(review).put(location); assertEquals(HttpStatus.OK.value(), response.getStatusCode()); // check if changes saved response = RestAssured.get(location); assertEquals(HttpStatus.OK.value(), response.getStatusCode()); assertEquals(4, response.jsonPath().getInt("rating")); }
Example 2
Source File: CustomResourceFieldTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Test public void test() { String url = getBaseUri() + "country/ch"; io.restassured.response.Response getResponse = RestAssured.get(url); Assert.assertEquals(200, getResponse.getStatusCode()); getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Schweiz")); getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland")); String patchData = "{'data':{'id':'ch','type':'country','attributes':{'deText':'Test','enText':'Switzerland','ctlActCd':true}}}" .replaceAll("'", "\""); Response patchResponse = RestAssured.given().body(patchData.getBytes()).header("content-type", JsonApiMediaType.APPLICATION_JSON_API) .when().patch(url); patchResponse.then().statusCode(HttpStatus.SC_OK); getResponse = RestAssured.get(url); Assert.assertEquals(200, getResponse.getStatusCode()); getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Test")); getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland")); }
Example 3
Source File: JsonApiActionResponseTest.java From katharsis-framework with Apache License 2.0 | 6 votes |
@Test public void testInvokeRepositoryActionWithException() { // resources should be received in json api format String url = getBaseUri() + "schedules/repositoryActionWithException?msg=hello"; io.restassured.response.Response response = RestAssured.get(url); Assert.assertEquals(403, response.getStatusCode()); System.out.println("body: " + response.body().asString()); response.then().assertThat().body("errors[0].status", Matchers.equalTo("403")); // check filters ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class); Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class)); DocumentFilterContext actionContext = contexts.getAllValues().get(0); Assert.assertEquals("GET", actionContext.getMethod()); Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath); }
Example 4
Source File: OAuth2SwaggerLiveTest.java From spring-security-oauth with MIT License | 5 votes |
@Test public void whenVerifySwaggerDocIsWorking_thenOK() { Response response = RestAssured.get(URL_PREFIX + "/v2/api-docs"); assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatusCode()); response = RestAssured.given().header("Authorization", "Bearer " + tokenValue).get(URL_PREFIX + "/v2/api-docs"); assertEquals(HttpStatus.OK.value(), response.getStatusCode()); }
Example 5
Source File: FooPageableLiveTest.java From tutorials with MIT License | 5 votes |
@Override @Test public void whenResourcesAreRetrievedPaged_then200IsReceived() { this.create(); final Response response = RestAssured.get(getPageableURL() + "?page=0&size=10"); assertThat(response.getStatusCode(), is(200)); }
Example 6
Source File: JPASpecificationLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { final Response response = RestAssured.get(URL_PREFIX + "firstName:john,lastName:doe"); final String result = response.body() .asString(); assertTrue(result.contains(userJohn.getEmail())); assertFalse(result.contains(userTom.getEmail())); }
Example 7
Source File: JPASpecificationLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFirstNameSuffix_whenGettingListOfUsers_thenCorrect() { final Response response = RestAssured.get(URL_PREFIX + "firstName:*n"); final String result = response.body() .asString(); assertTrue(result.contains(userJohn.getEmail())); assertFalse(result.contains(userTom.getEmail())); }
Example 8
Source File: SpringBootBootstrapLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenGetCreatedBookById_thenOK() { final Book book = createRandomBook(); final String location = createBookAsUri(book); final Response response = RestAssured.get(location); assertEquals(HttpStatus.OK.value(), response.getStatusCode()); assertEquals(book.getTitle(), response.jsonPath() .get("title")); }
Example 9
Source File: SpringBootBootstrapLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenGetBooksByTitle_thenOK() { final Book book = createRandomBook(); createBookAsUri(book); final Response response = RestAssured.get(API_ROOT + "/title/" + book.getTitle()); assertEquals(HttpStatus.OK.value(), response.getStatusCode()); assertTrue(response.as(List.class) .size() > 0); }
Example 10
Source File: AbstractBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenLastPageOfResourcesIsRetrieved_thenNoNextPageIsDiscoverable() { create(); create(); create(); final Response first = RestAssured.get(getURL() + "?page=0&size=2"); final String uriToLastPage = extractURIByRel(first.getHeader(HttpHeaders.LINK), "last"); final Response response = RestAssured.get(uriToLastPage); final String uriToNextPage = extractURIByRel(response.getHeader(HttpHeaders.LINK), "next"); assertNull(uriToNextPage); }
Example 11
Source File: RestAssuredAdvancedLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenMeasureResponseTime_thenOK(){ Response response = RestAssured.get("/users/eugenp"); long timeInMS = response.time(); long timeInS = response.timeIn(TimeUnit.SECONDS); assertEquals(timeInS, timeInMS/1000); }
Example 12
Source File: RestApiLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenGetCreatedBookById_thenOK() { final Book book = createRandomBook(); final String location = createBookAsUri(book); final Response response = RestAssured.get(location); assertEquals(HttpStatus.OK.value(), response.getStatusCode()); assertEquals(book.getTitle(), response.jsonPath().get("title")); }
Example 13
Source File: JPASpecificationLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFirstOrFirstNameAndAge_whenGettingAdvListOfUsers_thenCorrect() { final Response response = RestAssured.get(ADV_URL_PREFIX + "( firstName:john OR firstName:tom ) AND age>22"); final String result = response.body() .asString(); assertFalse(result.contains(userJohn.getEmail())); assertTrue(result.contains(userTom.getEmail())); }
Example 14
Source File: RestApiLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenDeleteCreatedBook_thenOk() { // create final Book book = createRandomBook(); final String location = createBookAsUri(book); // delete Response response = RestAssured.delete(location); assertEquals(HttpStatus.NO_CONTENT.value(), response.getStatusCode()); // confirm it was deleted response = RestAssured.get(location); assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatusCode()); }
Example 15
Source File: JPASpecificationLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFirstNameSubstring_whenGettingListOfUsers_thenCorrect() { final Response response = RestAssured.get(URL_PREFIX + "firstName:*oh*"); final String result = response.body() .asString(); assertTrue(result.contains(userJohn.getEmail())); assertFalse(result.contains(userTom.getEmail())); }
Example 16
Source File: RestApiLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenDeleteCreatedReview_thenOk() { // create final BookReview review = createRandomReview(); final String location = createReviewAsUri(review); // delete Response response = RestAssured.delete(location); assertEquals(HttpStatus.NO_CONTENT.value(), response.getStatusCode()); // confirm it was deleted response = RestAssured.get(location); assertEquals(HttpStatus.NOT_FOUND.value(), response.getStatusCode()); }
Example 17
Source File: AbstractBasicLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() { create(); final Response response = RestAssured.get(getURL() + "?page=0&size=10"); assertFalse(response.body().as(List.class).isEmpty()); }
Example 18
Source File: JPASpecificationLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenFirstOrLastName_whenGettingListOfUsers_thenCorrect() { final Response response = RestAssured.get(EURL_PREFIX + "firstName:john,'lastName:doe"); final String result = response.body() .asString(); assertTrue(result.contains(userJohn.getEmail())); assertTrue(result.contains(userTom.getEmail())); }
Example 19
Source File: AbstractDiscoverabilityLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void whenResourceIsRetrieved_thenUriToGetAllResourcesIsDiscoverable() { // Given final String uriOfExistingResource = createAsUri(); // When final Response getResponse = RestAssured.get(uriOfExistingResource); // Then final String uriToAllResources = HTTPLinkHeaderUtil.extractURIByRel(getResponse.getHeader("Link"), "collection"); final Response getAllResponse = RestAssured.get(uriToAllResources); assertThat(getAllResponse.getStatusCode(), is(200)); }
Example 20
Source File: GridApi.java From teasy with MIT License | 5 votes |
String getNodeIp() { String gridApiUrl = hubUrl.getProtocol() + "://" + hubUrl.getHost() + ":" + hubUrl.getPort() + "/grid/api/"; if (RestAssured.get(gridApiUrl).getStatusCode() != 200) return hubUrl.getHost(); Response response = RestAssured.get(gridApiUrl + "testsession?session=" + sessionId); try { return new URL(response.jsonPath().get("proxyId")).getHost(); } catch (MalformedURLException e) { Report.jenkins("MalformedURLException in getNodeIp " + e.getMessage()); } throw new RuntimeException("Cannot get node id by session from grid api."); }