diff --git a/distribution/src/test/java/com/predic8/membrane/tutorials/orchestration/OrchestrationTutorialTest.java b/distribution/src/test/java/com/predic8/membrane/tutorials/orchestration/OrchestrationTutorialTest.java index 11fbdd6e86..c500d1f4a9 100644 --- a/distribution/src/test/java/com/predic8/membrane/tutorials/orchestration/OrchestrationTutorialTest.java +++ b/distribution/src/test/java/com/predic8/membrane/tutorials/orchestration/OrchestrationTutorialTest.java @@ -17,7 +17,10 @@ import org.junit.jupiter.api.Test; import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.notNullValue; public class OrchestrationTutorialTest extends AbstractOrchestrationTutorialTest { @@ -27,23 +30,17 @@ protected String getTutorialYaml() { } @Test - void books_areReturnedById() { + void latestProductCopy_isCreatedWithFixedPrice() { // @formatter:off given() .when() - .get("http://localhost:2000/books/{id}", "OL29474405M") + .post("http://localhost:2000/products/latest/copy") .then() - .statusCode(200) - .body("title", equalTo("So Long, and Thanks for All the Fish")) - .body("author", equalTo("Douglas Adams")); - - given() - .when() - .get("http://localhost:2000/books/{id}", "OL26333978M") - .then() - .statusCode(200) - .body("title", equalTo("Foucault's pendulum")) - .body("author", equalTo("Umberto Eco")); + .statusCode(201) + .body("id", notNullValue()) + .body("name", notNullValue()) + .body("price", equalTo(5)) + .body("name", containsString("Copy")); // @formatter:on } diff --git a/distribution/tutorials/orchestration/30-Orchestration.yaml b/distribution/tutorials/orchestration/30-Orchestration.yaml index 816026d662..8da2e19c01 100644 --- a/distribution/tutorials/orchestration/30-Orchestration.yaml +++ b/distribution/tutorials/orchestration/30-Orchestration.yaml @@ -2,35 +2,30 @@ # # Tutorial: Orchestration # -# Shows how to create an API that combines two backend calls into one API. -# 1) Fetch a book by id. -# 2) Use the author key from the book payload to fetch the author. +# Shows how to create an API that combines multiple backend calls into one API. +# 1) Fetch the newest product from fruitshop. +# 2) Create a new product with a copy of this product and a fixed price of 5. # # Try: -# curl localhost:2000/books/OL29474405M -# curl localhost:2000/books/OL26333978M +# curl -X POST localhost:2000/products/latest/copy api: port: 2000 path: - uri: /books/{id} + uri: /products/latest/copy flow: - request: - call: - url: https://openlibrary.org/books/${pathParam.id}.json - - setProperty: - name: title - value: ${$.title} - language: jsonpath - - call: - url: https://openlibrary.org${$.authors[0].key}.json - language: jsonpath + url: https://api.predic8.de/shop/v2/products?sort=id&order=desc&limit=1 - template: contentType: application/json src: | { - "title": ${property.title}, - "author": ${jsonPath('$.name')} + "name": ${jsonPath('$.products[0].name') + ' Copy'}, + "price": 5 } + - call: + method: POST + url: https://api.predic8.de/shop/v2/products - return: - status: 200 + status: 201