Skip to content

Instantly share code, notes, and snippets.

View slawekradzyminski's full-sized avatar

Slawek Radzyminski slawekradzyminski

View GitHub Profile
import org.fluentlenium.adapter.FluentTestNg;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
private static final String URL = "http://jsonplaceholder.typicode.com";
public Response getPostContent(int postNumber) {
return given()
.contentType(JSON)
.when()
.get(format("%s/posts/%s", URL, Integer.toString(postNumber)));
}
private JsonPlaceholderAPI jsonPlaceholderAPI = new JsonPlaceholderAPI();
@Test
public void testGetPostTitle() {
jsonPlaceholderAPI.getPostContent(1)
.then()
.body("title", equalTo("sunt aut facere repellat provident occaecati excepturi optio reprehenderit"));
}
private JsonPlaceholderAPI jsonPlaceholderAPI = new JsonPlaceholderAPI();
@Test
public void schemaValidation() {
jsonPlaceholderAPI.getPostContent(1)
.then()
.body(matchesJsonSchemaInClasspath("jsonplaceholder-posts-schema.json"));
}
{
"title": "Posts schema",
"type": "object",
"properties": {
"userId": {
"type": "integer"
},
"id": {
"type": "integer"
},
private final RestAssuredConfig restAssuredConfig = RestAssured.config()
.encoderConfig(encoderConfig()
.defaultContentCharset("UTF-8"));
public Response putNewPost(User user, int postNumber) {
return given()
.config(restAssuredConfig)
.contentType(JSON)
.body(user)
private JsonPlaceholderAPI jsonPlaceholderAPI = new JsonPlaceholderAPI();
@Test
public void testPutMethod() {
User user = new User(1, "foo", "bar", 1);
jsonPlaceholderAPI.putNewPost(user, 1)
.then()
.statusCode(SC_OK);
}
public class User {
private int id;
private final String title;
private final String body;
private final int userId;
public User(int id, String title, String body, int userId) {
this.id = id;
this.title = title;
private static final int BROWSER_MOB_PROXY_PORT = 9191;
protected BrowserMobProxyServer server;
@BeforeClass
public void startBMP() {
server = new BrowserMobProxyServer();
server.start(BROWSER_MOB_PROXY_PORT);
server.setHarCaptureTypes(CaptureType.getHeaderCaptureTypes());
}