Skip to content

Commit

Permalink
Added integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xxSlashxx committed Dec 28, 2024
1 parent db309e5 commit 67a7e3b
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 4 deletions.
15 changes: 15 additions & 0 deletions products-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@
<version>1.18.34</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.graphql</groupId>
<artifactId>spring-graphql-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions products-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
spring.application.name=products-service

##Datasource##
spring.datasource.url=jdbc:h2:~/products-service
spring.datasource.url=jdbc:h2:~/graphql-demo-db/prod/products-service
spring.datasource.username=admin
spring.datasource.password=admin

##Liquibase##
spring.liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml
spring.liquibase.change-log=classpath:/db/changelog/prod/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
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/1_create_schema.sql" relativeToChangelogFile="false"/>
<include file="classpath:db/changelog/2_insert_products.sql" relativeToChangelogFile="false"/>
<include file="classpath:db/changelog/prod/1_create_schema.sql" relativeToChangelogFile="false"/>
<include file="classpath:db/changelog/prod/2_insert_products.sql" relativeToChangelogFile="false"/>
</databaseChangeLog>
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());
}
}
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
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;
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');
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>

0 comments on commit 67a7e3b

Please sign in to comment.