From 463113b161d8ecc6fef75fc3354dee8494be8c2b Mon Sep 17 00:00:00 2001 From: Alexey Zinchenko Date: Sat, 18 May 2019 00:16:18 +0300 Subject: [PATCH] Added simple integration test. --- pom.xml | 6 +++ .../carrepair/CarRepairApplicationTests.java | 17 -------- .../ClientRepositoryIntegrationTest.java | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+), 17 deletions(-) delete mode 100644 src/test/java/com/github/prominence/carrepair/CarRepairApplicationTests.java create mode 100644 src/test/java/com/github/prominence/carrepair/ClientRepositoryIntegrationTest.java diff --git a/pom.xml b/pom.xml index a2c620d..5c75c82 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,12 @@ mapstruct-jdk8 1.3.0.Final + + com.h2database + h2 + test + 1.4.199 + org.webjars diff --git a/src/test/java/com/github/prominence/carrepair/CarRepairApplicationTests.java b/src/test/java/com/github/prominence/carrepair/CarRepairApplicationTests.java deleted file mode 100644 index 5ed0951..0000000 --- a/src/test/java/com/github/prominence/carrepair/CarRepairApplicationTests.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.github.prominence.carrepair; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class CarRepairApplicationTests { - - @Test - public void contextLoads() { - } - -} - diff --git a/src/test/java/com/github/prominence/carrepair/ClientRepositoryIntegrationTest.java b/src/test/java/com/github/prominence/carrepair/ClientRepositoryIntegrationTest.java new file mode 100644 index 0000000..1d5a3f5 --- /dev/null +++ b/src/test/java/com/github/prominence/carrepair/ClientRepositoryIntegrationTest.java @@ -0,0 +1,39 @@ +package com.github.prominence.carrepair; + +import com.github.prominence.carrepair.model.domain.Client; +import com.github.prominence.carrepair.repository.ClientRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +@RunWith(SpringRunner.class) +@DataJpaTest +public class ClientRepositoryIntegrationTest { + + @Autowired + private TestEntityManager entityManager; + + @Autowired + private ClientRepository clientRepository; + + @Test + public void whenFindById_thenReturnClient() { + // given + Client client = new Client("firstName", "middleName", "lastName", "123456789"); + entityManager.persist(client); + entityManager.flush(); + + // when + Client found = clientRepository.findById(client.getId()).get(); + + // then + assertThat(found.hashCode()).isEqualTo(client.hashCode()); + } + +} +