-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
2d55c35
commit ee3ec2f
Showing
11 changed files
with
227 additions
and
6 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
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
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
91 changes: 91 additions & 0 deletions
91
bootstrap/src/test/java/eu/happycoders/shop/bootstrap/e2e/CartTest.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,91 @@ | ||
package eu.happycoders.shop.bootstrap.e2e; | ||
|
||
import static eu.happycoders.shop.adapter.in.web.HttpTestCommons.TEST_PORT; | ||
import static eu.happycoders.shop.adapter.in.web.cart.CartsControllerAssertions.assertThatResponseIsCart; | ||
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.LED_LIGHTS; | ||
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.MONITOR_DESK_MOUNT; | ||
import static io.restassured.RestAssured.given; | ||
import static jakarta.ws.rs.core.Response.Status.NO_CONTENT; | ||
|
||
import eu.happycoders.shop.model.cart.Cart; | ||
import eu.happycoders.shop.model.cart.NotEnoughItemsInStockException; | ||
import eu.happycoders.shop.model.customer.CustomerId; | ||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
class CartTest extends EndToEndTest { | ||
|
||
private static final CustomerId TEST_CUSTOMER_ID = new CustomerId(61157); | ||
private static final String CARTS_PATH = "/carts/" + TEST_CUSTOMER_ID.value(); | ||
|
||
@Test | ||
@Order(1) | ||
void givenAnEmptyCart_addLineItem_addsTheLineItemAndReturnsTheCartWithTheAddedItem() | ||
throws NotEnoughItemsInStockException { | ||
Response response = | ||
given() | ||
.port(TEST_PORT) | ||
.queryParam("productId", LED_LIGHTS.id().value()) | ||
.queryParam("quantity", 3) | ||
.post(CARTS_PATH + "/line-items") | ||
.then() | ||
.extract() | ||
.response(); | ||
|
||
Cart expectedCart = new Cart(TEST_CUSTOMER_ID); | ||
expectedCart.addProduct(LED_LIGHTS, 3); | ||
|
||
assertThatResponseIsCart(response, expectedCart); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
void givenACartWithOneLineItem_addLineItem_addsTheLineItemAndReturnsACartWithTwoLineItems() | ||
throws NotEnoughItemsInStockException { | ||
Response response = | ||
given() | ||
.port(TEST_PORT) | ||
.queryParam("productId", MONITOR_DESK_MOUNT.id().value()) | ||
.queryParam("quantity", 1) | ||
.post(CARTS_PATH + "/line-items") | ||
.then() | ||
.extract() | ||
.response(); | ||
|
||
Cart expectedCart = new Cart(TEST_CUSTOMER_ID); | ||
expectedCart.addProduct(LED_LIGHTS, 3); | ||
expectedCart.addProduct(MONITOR_DESK_MOUNT, 1); | ||
|
||
assertThatResponseIsCart(response, expectedCart); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
void givenACartWithTwoLineItems_getCart_returnsTheCart() throws NotEnoughItemsInStockException { | ||
Response response = given().port(TEST_PORT).get(CARTS_PATH).then().extract().response(); | ||
|
||
Cart expectedCart = new Cart(TEST_CUSTOMER_ID); | ||
expectedCart.addProduct(LED_LIGHTS, 3); | ||
expectedCart.addProduct(MONITOR_DESK_MOUNT, 1); | ||
|
||
assertThatResponseIsCart(response, expectedCart); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
void givenACartWithTwoLineItems_delete_returnsStatusCodeNoContent() { | ||
given().port(TEST_PORT).delete(CARTS_PATH).then().statusCode(NO_CONTENT.getStatusCode()); | ||
} | ||
|
||
@Test | ||
@Order(5) | ||
void givenAnEmptiedCart_getCart_returnsAnEmptyCart() { | ||
Response response = given().port(TEST_PORT).get(CARTS_PATH).then().extract().response(); | ||
|
||
assertThatResponseIsCart(response, new Cart(TEST_CUSTOMER_ID)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
bootstrap/src/test/java/eu/happycoders/shop/bootstrap/e2e/EndToEndTest.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,23 @@ | ||
package eu.happycoders.shop.bootstrap.e2e; | ||
|
||
import static eu.happycoders.shop.adapter.in.web.HttpTestCommons.TEST_PORT; | ||
|
||
import eu.happycoders.shop.bootstrap.Launcher; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
class EndToEndTest { | ||
|
||
private static Launcher launcher; | ||
|
||
@BeforeAll | ||
static void init() { | ||
launcher = new Launcher(); | ||
launcher.startOnPort(TEST_PORT); | ||
} | ||
|
||
@AfterAll | ||
static void stop() { | ||
launcher.stop(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
bootstrap/src/test/java/eu/happycoders/shop/bootstrap/e2e/FindProductsTest.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,30 @@ | ||
package eu.happycoders.shop.bootstrap.e2e; | ||
|
||
import static eu.happycoders.shop.adapter.in.web.HttpTestCommons.TEST_PORT; | ||
import static eu.happycoders.shop.adapter.in.web.product.ProductsControllerAssertions.assertThatResponseIsProductList; | ||
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.COMPUTER_MONITOR; | ||
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.MONITOR_DESK_MOUNT; | ||
import static io.restassured.RestAssured.given; | ||
|
||
import io.restassured.response.Response; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class FindProductsTest extends EndToEndTest { | ||
|
||
@Test | ||
void givenTestProductsAndAQuery_findProducts_returnsMatchingProducts() { | ||
String query = "monitor"; | ||
|
||
Response response = | ||
given() | ||
.port(TEST_PORT) | ||
.queryParam("query", query) | ||
.get("/products") | ||
.then() | ||
.extract() | ||
.response(); | ||
|
||
assertThatResponseIsProductList(response, List.of(COMPUTER_MONITOR, MONITOR_DESK_MOUNT)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
bootstrap/src/test/java/eu/happycoders/shop/bootstrap/e2e/GetProductTest.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,25 @@ | ||
package eu.happycoders.shop.bootstrap.e2e; | ||
|
||
import static eu.happycoders.shop.adapter.in.web.HttpTestCommons.TEST_PORT; | ||
import static eu.happycoders.shop.adapter.in.web.product.ProductsControllerAssertions.assertThatResponseIsProduct; | ||
import static eu.happycoders.shop.adapter.out.persistence.DemoProducts.PLASTIC_SHEETING; | ||
import static io.restassured.RestAssured.given; | ||
|
||
import io.restassured.response.Response; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class GetProductTest extends EndToEndTest { | ||
|
||
@Test | ||
void givenATestProduct_getProduct_returnsTheProduct() { | ||
Response response = | ||
given() | ||
.port(TEST_PORT) | ||
.get("/products/" + PLASTIC_SHEETING.id().value()) | ||
.then() | ||
.extract() | ||
.response(); | ||
|
||
assertThatResponseIsProduct(response, PLASTIC_SHEETING); | ||
} | ||
} |
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