/** * Perform a PUT request to a <code>uri</code>. * * @param uri The uri to send the request to. * @return The response of the request. */ public static Response put(URI uri) { return given().put(uri); }
/** * Perform a PUT request to a <code>path</code>. Normally the path doesn't have to be fully-qualified e.g. you don't need to * specify the path as <tt>http://localhost:8080/path</tt>. In this case it's enough to use <tt>/path</tt>. * * @param path The path to send the request to. * @param pathParams The path parameters. E.g. if path is "/book/{hotelId}/{roomNumber}" you can do <code>put("/book/{hotelName}/{roomNumber}", "Hotels R Us", 22);</code>. * @return The response of the request. */ public static Response put(String path, Object... pathParams) { return given().put(path, pathParams); }
/** * Perform a PUT request to the statically configured path (by default <code>http://localhost:8080</code>). * * @return The response of the request. */ public static Response put() { return given().put(); }
/** * Perform a PUT request to a <code>url</code>. * * @param url The url to send the request to. * @return The response of the request. */ public static Response put(URL url) { return given().put(url); }
private void putPageUnderAisleId(String aisleId) { RequestSpecification instance = given() .spec(prepareApplicationJsonHeaders()) .header(HttpHeaders.AUTHORIZATION, verifiableToken(Roles.WRITE_MERCHANDISING)) .body(readResource(NAMED_PAGE_CONTENT_FILE, String.format("%s.html", TEST_PAGE.value()), AISLE_TEST_LOCATION)); if (aisleId != null) { instance.put(AISLE_HTML_URL, aisleId) } else { instance.put(ROOT_AISLE_HTML_URL) } instance.then() .statusCode(200) .body(not(isEmptyOrNullString())) .body(JSON_RESPONSE_MESSAGE, not(isEmptyOrNullString())); }
break; case "put": response = spec.put(endPoint); break; case "get":
public static Response send(RequestSpecification request, String methodPath, HttpMethodType methodType) { Response response = null; SystemProxy.setupProxy(); switch (methodType) { case HEAD: response = request.head(methodPath); break; case GET: response = request.get(methodPath); break; case PUT: response = request.put(methodPath); break; case POST: response = request.post(methodPath); break; case DELETE: response = request.delete(methodPath); break; case PATCH: response = request.patch(methodPath); break; default: throw new RuntimeException("MethodType is not specified for the API method: " + methodPath); } return response; }
.body(getResponse.asByteArray()) .when() .put(resourceUri); if (!isSuccessful().matches(ifMatchResponse.getStatusCode())) { throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(), .body(getResponse.asByteArray()) .when() .put(resourceUri); if (isSuccessful().matches(noIfMatchResponse.getStatusCode())) {
protected Response expectPut4xxStatus(String invalidProp) { // Get the resource. String resourceUri = getResourceUri(); Response getResponse = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(resourceUri); String eTag = getResponse.getHeader(ETAG); Model m = getResponse.as(Model.class, new RdfObjectMapper(resourceUri)); modifyProperty(m, resourceUri, invalidProp); Response putResponse = buildBaseRequestSpecification() .contentType(TEXT_TURTLE) .header(IF_MATCH, eTag) .body(m, new RdfObjectMapper(resourceUri)) .when() .put(resourceUri); if (isSuccessful().matches(putResponse.getStatusCode())) { throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(), "Skipping test because PUT request was successful.", skipLog); } assertThat(putResponse.statusCode(), is4xxRange()); return putResponse; }
.body(originalModel, new RdfObjectMapper(resourceUri)) // relative URI .when() .put(resourceUri);
.contentType(TEXT_TURTLE).header(IF_MATCH, eTag) .body(model, new RdfObjectMapper("")) // keep URIs relative .when().put(resourceUri); if (!isSuccessful().matches(put.getStatusCode())) { throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(),
.body(objectMapper.writeValueAsString(new UpdateTodoRequest("testupdate", false, 0))) .when() .put(baseUrl() + "/todos/{id}", id) .then() .statusCode(200);
.body(objectMapper.writeValueAsString(new UpdateTodoRequest("testupdate", false, 0))) .when() .put(todoServiceBaseUrl() + "/todos/{id}", id) .then() .statusCode(200);
/** * Should return the example from the specification when the script triggers an HTTP 201 Created status code. * * @throws Exception */ @Test public void testServeScriptedExample() throws Exception { given() .log().everything() // JSON content type in 'Accept' header matches specification example .accept(ContentType.JSON) .when() .put("/simple/apis") .then() .log().everything() .statusCode(HttpUtil.HTTP_CREATED) .body("result", equalTo("success")) .header("MyHeader","MyHeaderValue"); }