This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private JsonPlaceholderAPI jsonPlaceholderAPI = new JsonPlaceholderAPI(); | |
@Test | |
public void schemaValidation() { | |
jsonPlaceholderAPI.getPostContent(1) | |
.then() | |
.body(matchesJsonSchemaInClasspath("jsonplaceholder-posts-schema.json")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"title": "Posts schema", | |
"type": "object", | |
"properties": { | |
"userId": { | |
"type": "integer" | |
}, | |
"id": { | |
"type": "integer" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |