-
Notifications
You must be signed in to change notification settings - Fork 0
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
10 changed files
with
94 additions
and
4 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
File renamed without changes.
File renamed without changes.
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
47 changes: 47 additions & 0 deletions
47
products-service/src/test/java/de/slash/productsservice/ProductControllerIT.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,47 @@ | ||
package de.slash.productsservice; | ||
|
||
import de.slash.productsservice.product.Product; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.graphql.test.tester.HttpGraphQlTester; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@SpringBootTest() | ||
@ActiveProfiles("test") | ||
@Transactional | ||
@AutoConfigureHttpGraphQlTester | ||
class ProductControllerIT { | ||
|
||
@Autowired | ||
HttpGraphQlTester httpGraphQlTester; | ||
|
||
@Test | ||
void getProduct() { | ||
Product product = httpGraphQlTester.document( | ||
"query GetProduct {" + | ||
" getProduct(id: \"2\") {" + | ||
" id" + | ||
" name" + | ||
" price" + | ||
" }" + | ||
"}") | ||
.execute() | ||
.errors() | ||
.verify() | ||
.path("getProduct") | ||
.entity(Product.class) | ||
.get(); | ||
assertNotNull(product); | ||
assertEquals(2L, product.getId()); | ||
assertEquals("The Dark Forest", product.getName()); | ||
assertEquals(BigDecimal.valueOf(10.99), product.getPrice()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
products-service/src/test/resources/application-test.properties
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,7 @@ | ||
##Datasource## | ||
spring.datasource.url=jdbc:h2:~/graphql-demo-db/test/products-service | ||
spring.datasource.username=admin | ||
spring.datasource.password=admin | ||
|
||
##Liquibase## | ||
spring.liquibase.change-log=classpath:/db/changelog/test/db.changelog-master.xml |
9 changes: 9 additions & 0 deletions
9
products-service/src/test/resources/db/changelog/test/1_create_schema.sql
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,9 @@ | ||
--changeset xxSlashxx:1 | ||
|
||
CREATE TABLE product ( | ||
id INT PRIMARY KEY, | ||
name VARCHAR(100) NOT NULL, | ||
price NUMERIC(8,2) NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE product_id_seq; |
5 changes: 5 additions & 0 deletions
5
products-service/src/test/resources/db/changelog/test/2_insert_products.sql
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,5 @@ | ||
--changeset xxSlashxx:2 | ||
|
||
insert into product values (NEXT VALUE FOR product_id_seq, 'The Three Body Problem', '13.99'); | ||
insert into product values (NEXT VALUE FOR product_id_seq, 'The Dark Forest', '10.99'); | ||
insert into product values (NEXT VALUE FOR product_id_seq, 'Death''s End', '10.99'); |
7 changes: 7 additions & 0 deletions
7
products-service/src/test/resources/db/changelog/test/db.changelog-master.xml
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,7 @@ | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
|
||
<include file="classpath:db/changelog/test/1_create_schema.sql" relativeToChangelogFile="false"/> | ||
<include file="classpath:db/changelog/test/2_insert_products.sql" relativeToChangelogFile="false"/> | ||
</databaseChangeLog> |