Java Code Examples for io.restassured.response.Response#statusCode()
The following examples show how to use
io.restassured.response.Response#statusCode() .
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: SetupTracksTestDataUtilityTest.java From tracksrestcasestudy with MIT License | 6 votes |
private String createProjectViaAPIForUser( RandomDataGenerator wordGenerator, Project aProject, TracksApi normalTracksUser) { String newProjectName = aProject.name() + " " + wordGenerator.randomWord(); System.out.println(newProjectName); Response response = normalTracksUser.createProject(newProjectName); String projectId = null; if(response.statusCode()==201) { projectId = new TracksResponseProcessor(response). getIdFromLocation(); } return projectId; }
Example 2
Source File: FruitsEndpointTest.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
private void deleteIfExist(String tenantPrefix, String fruitName) { Response response = given().param("type", "name").param("value", fruitName).when().get(tenantPrefix + "/fruitsFindBy"); if (response.statusCode() == 200) { Fruit fruit = response.as(Fruit.class); given() .when().delete(tenantPrefix + "/fruits/" + fruit.getId()) .then() .statusCode(204); } }
Example 3
Source File: FruitsEndpointTest.java From quarkus-quickstarts with Apache License 2.0 | 5 votes |
private Fruit find(String tenantPrefix, String fruitName) { Response response = given().param("type", "name").param("value", fruitName).when().get(tenantPrefix + "/fruitsFindBy"); if (response.statusCode() == 404) { return null; } if (response.statusCode() == 200) { Fruit fruit = response.as(Fruit.class); return fruit; } throw new IllegalStateException("Unknown status finding '" + fruitName + ": " + response); }
Example 4
Source File: TracksApi_v2_2.java From tracksrestcasestudy with MIT License | 5 votes |
private Response postMessageTo(String msg, String endpoint, String contentType) { Response ret = given(). // if I .auth().basic(authUser, authPassword). // then it sends a request without authentication headers to the serve // to see what authentication the server asks for // before sending the request with the authentication header // this effectively sends two messages //auth().basic(authUser, authPassword). // If I add the authorisation header myself then... // Only one message is sent, but if the authentication scheme changes // Then I have to handle it, and I have to encode the username/password myself //header(new Header("Authorization", "Basic dXNlcjpiaXRuYW1p")). // Or if I use preemptive mode rather than 'challenge' mode // It works the way I 'expected' auth().preemptive().basic(authUser, authPassword). content(msg).contentType(contentType). when(). post("http://" + url + endpoint). andReturn(); // ignore CREATED UNAUTHORIZED CONFLICT if(ret.statusCode()!=201 && ret.statusCode()!=401 && ret.statusCode()!=409 ){ System.out.println("POTENTIAL BUG - " + ret.statusCode() + " FOR " + endpoint + "\n" + msg ); } return ret; }
Example 5
Source File: HttpMessageSender.java From tracksrestcasestudy with MIT License | 5 votes |
private Response postMessageTo(String msg, String endpoint, String contentType, Map<String, String> cookieJar){ URL theEndPointUrl = createEndPointURL(url, endpoint); Response ret = given(). auth().preemptive(). basic(authUser, authPassword). body(msg). contentType(contentType). cookies(cookieJar). when(). post(theEndPointUrl.toExternalForm()). andReturn(); // ignore CREATED UNAUTHORIZED CONFLICT if( ret.statusCode()!=201 && ret.statusCode()!=401 && ret.statusCode()!=409 ){ System.out.println("POTENTIAL BUG - " + ret.statusCode() + " FOR " + endpoint + "\n" + msg ); } return setLastResponse(ret); }
Example 6
Source File: BaseMethods.java From akita with Apache License 2.0 | 5 votes |
/** * Получает body из ответа и сохраняет в переменную * * @param variableName имя переменной, в которую будет сохранен ответ * @param response ответ от http запроса */ public void getBodyAndSaveToVariable(String variableName, Response response) { if (response.statusCode() >= 200 && response.statusCode() < 300) { akitaScenario.setVar(variableName, response.getBody().asString()); akitaScenario.write("Тело ответа : \n" + new Prettifier().getPrettifiedBodyIfPossible(response, response)); } else { fail("Некорректный ответ на запрос: " + new Prettifier().getPrettifiedBodyIfPossible(response, response)); } }
Example 7
Source File: RestApiActions.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Sends delete request to specified resource. * If delete request successful, removes entity from TestRunStorage. * * @param path Id of resource */ public ApiResponse delete( String path ) { Response response = this.given() .when() .delete( path ); if ( response.statusCode() == 200 ) { TestRunStorage.removeEntity( endpoint, path ); } return new ApiResponse( response ); }