-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
207 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ subprojects { | |
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
|
||
javadoc { | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
layout: post | ||
title: "RestAssured" | ||
--- | ||
|
||
TODO: Write doc for integration with RESTAssured |
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
162 changes: 162 additions & 0 deletions
162
sample-apps/everything-app/src/test/java/org/example/app/RestAssuredTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/** | ||
* | ||
*/ | ||
package org.example.app; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static io.restassured.http.ContentType.JSON; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.microshed.testing.SharedContainerConfig; | ||
import org.microshed.testing.jupiter.MicroShedTest; | ||
|
||
@MicroShedTest | ||
@SharedContainerConfig(AppContainerConfig.class) | ||
public class RestAssuredTest { | ||
|
||
@Test | ||
public void testCreatePerson() { | ||
given() | ||
.queryParam("name", "Hank") | ||
.queryParam("age", 45) | ||
.contentType(JSON) | ||
.when() | ||
.post("/") | ||
.then() | ||
.statusCode(200) | ||
.contentType(JSON); | ||
} | ||
|
||
@Test | ||
public void testMinSizeName() { | ||
long minSizeNameId = given() | ||
.queryParam("name", "Bob") | ||
.queryParam("age", 42) | ||
.contentType(JSON) | ||
.when() | ||
.post("/") | ||
.then() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.extract() | ||
.as(long.class); | ||
|
||
Person p = given() | ||
.pathParam("personId", minSizeNameId) | ||
.when() | ||
.get("/{personId}") | ||
.then() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.extract() | ||
.as(Person.class); | ||
assertEquals("Bob", p.name); | ||
assertEquals(42, p.age); | ||
assertEquals(minSizeNameId, p.id); | ||
} | ||
|
||
@Test | ||
public void testMinAge() { | ||
long minAgeId = given() | ||
.queryParam("name", "Newborn") | ||
.queryParam("age", 0) | ||
.contentType(JSON) | ||
.when() | ||
.post("/") | ||
.then() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.extract() | ||
.as(long.class); | ||
|
||
Person p = given() | ||
.pathParam("personId", minAgeId) | ||
.when() | ||
.get("/{personId}") | ||
.then() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.extract() | ||
.as(Person.class); | ||
assertEquals("Newborn", p.name); | ||
assertEquals(0, p.age); | ||
assertEquals(minAgeId, p.id); | ||
} | ||
|
||
@Test | ||
public void testGetPerson() { | ||
long bobId = given() | ||
.queryParam("name", "Bob") | ||
.queryParam("age", 24) | ||
.contentType(JSON) | ||
.when() | ||
.post("/") | ||
.then() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.extract() | ||
.as(long.class); | ||
|
||
Person bob = given() | ||
.pathParam("personId", bobId) | ||
.when() | ||
.get("/{personId}") | ||
.then() | ||
.statusCode(200) | ||
.contentType(JSON) | ||
.extract() | ||
.as(Person.class); | ||
assertEquals("Bob", bob.name); | ||
assertEquals(24, bob.age); | ||
assertNotNull(bob.id); | ||
} | ||
|
||
@Test | ||
public void testGetUnknownPerson() { | ||
given() | ||
.pathParam("personId", -1L) | ||
.when() | ||
.get("/{personId}") | ||
.then() | ||
.statusCode(404); | ||
} | ||
|
||
@Test | ||
public void testCreateBadPersonNullName() { | ||
given() | ||
.queryParam("name", (Object[]) null) | ||
.queryParam("age", 5) | ||
.contentType(JSON) | ||
.when() | ||
.post("/") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
@Test | ||
public void testCreateBadPersonNegativeAge() { | ||
given() | ||
.queryParam("name", "NegativeAgePersoN") | ||
.queryParam("age", -1) | ||
.contentType(JSON) | ||
.when() | ||
.post("/") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
@Test | ||
public void testCreateBadPersonNameTooLong() { | ||
given() | ||
.queryParam("name", "NameTooLongPersonNameTooLongPersonNameTooLongPerson") | ||
.queryParam("age", 5) | ||
.contentType(JSON) | ||
.when() | ||
.post("/") | ||
.then() | ||
.statusCode(400); | ||
} | ||
|
||
} |