Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions micro-springboot/insurance-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.11</version>
<version>4.0.3</version>
<relativePath />
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -43,17 +43,17 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.16</version>
<version>3.0.2</version>
</dependency>

<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data-3.4</artifactId>
<artifactId>blaze-persistence-integration-spring-data-4.0</artifactId>
<version>${blaze.version}</version>
</dependency>
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-hibernate-6.2</artifactId>
<artifactId>blaze-persistence-integration-hibernate-7.1</artifactId>
<version>${blaze.version}</version>
<scope>runtime</scope>
</dependency>
Expand All @@ -68,6 +68,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.blazebit.persistence.view.spi.EntityViewConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

Expand All @@ -27,7 +26,7 @@ public static void main(String[] args) {

@Bean
RestTemplate restTemplate() {
return new RestTemplateBuilder().build();
return new RestTemplate();
}

@PersistenceUnit
Expand Down
14 changes: 7 additions & 7 deletions micro-springboot/insurance-service/src/main/resources/import.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
insert into insurance(personId, type, amount) values(1, 'MEDICAL', 1000);
insert into insurance(personId, type, amount) values(2, 'MEDICAL', 800);
insert into insurance(personId, type, amount) values(3, 'LIFE', 30000);
insert into insurance(personId, type, amount) values(4, 'LIFE', 20000);
insert into insurance(personId, type, amount) values(5, 'MEDICAL', 1500);
insert into insurance(personId, type, amount) values(6, 'LIFE', 50000);
insert into insurance(personId, type, amount) values(7, 'LIFE', 50000);
insert into insurance(person_id, type, amount) values(1, 'MEDICAL', 1000);
insert into insurance(person_id, type, amount) values(2, 'MEDICAL', 800);
insert into insurance(person_id, type, amount) values(3, 'LIFE', 30000);
insert into insurance(person_id, type, amount) values(4, 'LIFE', 20000);
insert into insurance(person_id, type, amount) values(5, 'MEDICAL', 1500);
insert into insurance(person_id, type, amount) values(6, 'LIFE', 50000);
insert into insurance(person_id, type, amount) values(7, 'LIFE', 50000);
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@
import org.instancio.Instancio;
import org.instancio.Select;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import pl.redhat.samples.insurance.domain.Insurance;

import java.util.List;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Testcontainers
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class InsuranceControllerTests {

@Autowired
TestRestTemplate restTemplate;
@LocalServerPort
int port;

WebTestClient webTestClient;

@BeforeEach
void setUp() {
webTestClient = WebTestClient.bindToServer()
.baseUrl("http://localhost:" + port)
.build();
}

@Container
@ServiceConnection
Expand All @@ -33,9 +42,14 @@ void add() {
Insurance insurance = Instancio.of(Insurance.class)
.ignore(Select.field("id"))
.create();
insurance = restTemplate.postForObject("/insurances", insurance, Insurance.class);
Assertions.assertNotNull(insurance);
Assertions.assertNotNull(insurance.getId());
Insurance saved = webTestClient.post().uri("/insurances")
.bodyValue(insurance)
.exchange()
.expectStatus().isOk()
.expectBody(Insurance.class)
.returnResult().getResponseBody();
Assertions.assertNotNull(saved);
Assertions.assertNotNull(saved.getId());
}

@Test
Expand All @@ -45,25 +59,42 @@ void updateAndGet() {
Insurance insurance = Instancio.of(Insurance.class)
.set(Select.field("id"), id)
.create();
restTemplate.put("/insurances", insurance);
Insurance updated = restTemplate.getForObject("/insurances/{id}", Insurance.class, id);
Assertions.assertNotNull(insurance);
Assertions.assertNotNull(insurance.getId());
Assertions.assertEquals(id, insurance.getId());
webTestClient.put().uri("/insurances")
.bodyValue(insurance)
.exchange();
Insurance updated = webTestClient.get().uri("/insurances/{id}", id)
.exchange()
.expectStatus().isOk()
.expectBody(Insurance.class)
.returnResult().getResponseBody();
Assertions.assertNotNull(updated);
Assertions.assertNotNull(updated.getId());
Assertions.assertEquals(id, updated.getId());
}

@Test
@Order(3)
void getAll() {
Insurance[] insurances = restTemplate.getForObject("/insurances", Insurance[].class);
Assertions.assertEquals(1, insurances.length);
List<Insurance> insurances = webTestClient.get().uri("/insurances")
.exchange()
.expectStatus().isOk()
.expectBodyList(Insurance.class)
.hasSize(8)
.returnResult().getResponseBody();
Assertions.assertNotNull(insurances);
Assertions.assertEquals(8, insurances.size());
}

@Test
@Order(4)
void deleteAndGet() {
restTemplate.delete("/insurances/{id}", 1);
Insurance insurance = restTemplate.getForObject("/insurances/{id}", Insurance.class, 1);
webTestClient.delete().uri("/insurances/{id}", 1)
.exchange()
.expectStatus().isOk();
Insurance insurance = webTestClient.get().uri("/insurances/{id}", 1)
.exchange()
.expectBody(Insurance.class)
.returnResult().getResponseBody();
Assertions.assertNull(insurance);
}

Expand Down
13 changes: 9 additions & 4 deletions micro-springboot/person-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.11</version>
<version>4.0.3</version>
<relativePath />
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -47,17 +47,17 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.16</version>
<version>3.0.2</version>
</dependency>

<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-spring-data-3.4</artifactId>
<artifactId>blaze-persistence-integration-spring-data-4.0</artifactId>
<version>${blaze.version}</version>
</dependency>
<dependency>
<groupId>com.blazebit</groupId>
<artifactId>blaze-persistence-integration-hibernate-6.2</artifactId>
<artifactId>blaze-persistence-integration-hibernate-7.1</artifactId>
<version>${blaze.version}</version>
<scope>runtime</scope>
</dependency>
Expand All @@ -72,6 +72,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,33 @@
import org.instancio.Instancio;
import org.instancio.Select;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import pl.redhat.samples.person.domain.Person;

import java.util.List;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Testcontainers
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class PersonControllerTests {

@Autowired
TestRestTemplate restTemplate;
@LocalServerPort
int port;

WebTestClient webTestClient;

@BeforeEach
void setUp() {
webTestClient = WebTestClient.bindToServer()
.baseUrl("http://localhost:" + port)
.build();
}

@Container
@ServiceConnection
Expand All @@ -31,9 +42,14 @@ void add() {
Person person = Instancio.of(Person.class)
.ignore(Select.field("id"))
.create();
person = restTemplate.postForObject("/persons", person, Person.class);
Assertions.assertNotNull(person);
Assertions.assertNotNull(person.getId());
Person saved = webTestClient.post().uri("/persons")
.bodyValue(person)
.exchange()
.expectStatus().isOk()
.expectBody(Person.class)
.returnResult().getResponseBody();
Assertions.assertNotNull(saved);
Assertions.assertNotNull(saved.getId());
}

@Test
Expand All @@ -43,8 +59,15 @@ void updateAndGet() {
Person person = Instancio.of(Person.class)
.set(Select.field("id"), id)
.create();
restTemplate.put("/persons", person);
Person updated = restTemplate.getForObject("/persons/{id}", Person.class, id);
webTestClient.put().uri("/persons")
.bodyValue(person)
.exchange()
.expectStatus().isOk();
Person updated = webTestClient.get().uri("/persons/{id}", id)
.exchange()
.expectStatus().isOk()
.expectBody(Person.class)
.returnResult().getResponseBody();
Assertions.assertNotNull(updated);
Assertions.assertNotNull(updated.getId());
Assertions.assertEquals(id, updated.getId());
Expand All @@ -53,15 +76,26 @@ void updateAndGet() {
@Test
@Order(3)
void getAll() {
Person[] persons = restTemplate.getForObject("/persons", Person[].class);
Assertions.assertEquals(1, persons.length);
List<Person> persons = webTestClient.get().uri("/persons")
.exchange()
.expectStatus().isOk()
.expectBodyList(Person.class)
.hasSize(1)
.returnResult().getResponseBody();
Assertions.assertNotNull(persons);
Assertions.assertEquals(1, persons.size());
}

@Test
@Order(4)
void deleteAndGet() {
restTemplate.delete("/persons/{id}", 1);
Person person = restTemplate.getForObject("/persons/{id}", Person.class, 1);
webTestClient.delete().uri("/persons/{id}", 1)
.exchange()
.expectStatus().isOk();
Person person = webTestClient.get().uri("/persons/{id}", 1)
.exchange()
.expectBody(Person.class)
.returnResult().getResponseBody();
Assertions.assertNull(person);
}

Expand Down
2 changes: 1 addition & 1 deletion micro-springboot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<properties>
<testcontainers.version>1.21.4</testcontainers.version>
<blaze.version>1.6.11</blaze.version>
<blaze.version>1.6.18</blaze.version>
<sonar.moduleKey>${project.artifactId}</sonar.moduleKey>
</properties>

Expand Down