-
Notifications
You must be signed in to change notification settings - Fork 21
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
2a0952b
commit 440b8a3
Showing
6 changed files
with
103 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
federation-jvm.version = 2.1.0 | ||
graphql-java.version = 19.2 |
43 changes: 43 additions & 0 deletions
43
products-subgraph/src/test/java/com/example/products/ProductsApplicationTest.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,43 @@ | ||
package com.example.products; | ||
|
||
import com.example.products.model.Product; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.graphql.test.tester.HttpGraphQlTester; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class ProductsApplicationTest { | ||
|
||
@LocalServerPort | ||
int serverPort; | ||
|
||
@Test | ||
public void verifiesProductQuery() { | ||
WebTestClient testClient = WebTestClient.bindToServer() | ||
.baseUrl("http://localhost:" + serverPort + "/graphql") | ||
.build(); | ||
HttpGraphQlTester tester = HttpGraphQlTester.create(testClient); | ||
|
||
String query = """ | ||
query ProductById($productId: ID!) { | ||
product(id: $productId) { | ||
id | ||
name | ||
description | ||
} | ||
} | ||
"""; | ||
|
||
// new Product("1","Saturn V", "The Original Super Heavy-Lift Rocket!"), | ||
tester.document(query) | ||
.variable("productId", "1") | ||
.execute() | ||
.path("product") | ||
.entity(Product.class) | ||
.isEqualTo(new Product("1","Saturn V", "The Original Super Heavy-Lift Rocket!")); | ||
} | ||
} |
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,2 @@ | ||
federation-jvm.version = 2.1.0 | ||
graphql-java.version = 19.2 |
48 changes: 48 additions & 0 deletions
48
reviews-subgraph/src/test/java/com/example/reviews/ReviewsApplicationTest.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,48 @@ | ||
package com.example.reviews; | ||
|
||
import com.example.reviews.model.Review; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.graphql.test.tester.HttpGraphQlTester; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class ReviewsApplicationTest { | ||
|
||
@LocalServerPort | ||
int serverPort; | ||
|
||
@Test | ||
public void verifiesProductQuery() { | ||
WebTestClient testClient = WebTestClient.bindToServer() | ||
.baseUrl("http://localhost:" + serverPort + "/graphql") | ||
.build(); | ||
HttpGraphQlTester tester = HttpGraphQlTester.create(testClient); | ||
|
||
String query = """ | ||
query Entities($representations: [_Any!]!) { | ||
_entities(representations: $representations) { | ||
...on Product { | ||
id | ||
reviews { | ||
id | ||
text | ||
starRating | ||
} | ||
} | ||
} | ||
} | ||
"""; | ||
|
||
tester.document(query) | ||
.variable("representations", List.of(Map.of("__typename", "Product", "id", "5"))) | ||
.execute() | ||
.path("_entities[0].id").entity(String.class).isEqualTo("5") | ||
.path("_entities[0].reviews[0]") | ||
.entity(Review.class) | ||
.isEqualTo(new Review("1050", "Amazing! Would Fly Again!", 5)); | ||
} | ||
} |