diff --git a/data/data-jdbc-h2-kotlin/src/test/java/com/example/data/jdbc/h2/kotlin/DataJdbcTests.java b/data/data-jdbc-h2-kotlin/src/test/java/com/example/data/jdbc/h2/kotlin/DataJdbcTests.java new file mode 100644 index 00000000..99b6c875 --- /dev/null +++ b/data/data-jdbc-h2-kotlin/src/test/java/com/example/data/jdbc/h2/kotlin/DataJdbcTests.java @@ -0,0 +1,39 @@ +package com.example.data.jdbc.h2.kotlin; + +import com.example.data.jdbc.h2.kotlin.model.Author; +import com.example.data.jdbc.h2.kotlin.model.Book; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest; +import org.springframework.jdbc.core.JdbcTemplate; +import java.util.Set; + +@DataJdbcTest +class DataJdbcTests { + + @Autowired + private JdbcTemplate jdbcTemplate; + + @Autowired + private AuthorRepository authorRepository; + + @Test + void shouldHaveSchema() { + Assertions.assertThatNoException().isThrownBy(() -> jdbcTemplate.execute("SELECT * FROM author")); + } + + @Test + void shouldSaveAndLoad() { + + var book1 = new Book(null, "book-1"); + var author1 = new Author(null, "author-1", Set.of(book1)); + authorRepository.save(author1); + var found = authorRepository.queryFindByName("author-1"); + Assertions.assertThat(found).isNotNull(); + Assertions.assertThat(found.getId()).isNotNull(); + Assertions.assertThat(found.getName()).isEqualTo("author-1"); + Assertions.assertThat(found.getBooks()).hasSize(1); + } + +} diff --git a/data/data-jdbc-h2-kotlin/src/test/kotlin/com/example/data/jdbc/h2/kotlin/DataJdbcTests.kt b/data/data-jdbc-h2-kotlin/src/test/kotlin/com/example/data/jdbc/h2/kotlin/DataJdbcTests.kt deleted file mode 100644 index 925ec51f..00000000 --- a/data/data-jdbc-h2-kotlin/src/test/kotlin/com/example/data/jdbc/h2/kotlin/DataJdbcTests.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.example.data.jdbc.h2.kotlin - -import com.example.data.jdbc.h2.kotlin.model.Author -import com.example.data.jdbc.h2.kotlin.model.Book -import org.assertj.core.api.Assertions -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest -import org.springframework.jdbc.core.JdbcTemplate -import java.util.Set - -@DataJdbcTest -class DataJdbcTests { - @Autowired - private lateinit var jdbcTemplate: JdbcTemplate - - @Autowired - private lateinit var authorRepository: AuthorRepository - - @Test - fun shouldHaveSchema() { - Assertions.assertThatCode { jdbcTemplate.execute("SELECT * FROM author") } - .doesNotThrowAnyException() - } - - @Test - fun shouldSaveAndLoad() { - val book1 = Book(null, "book-1") - val author1 = Author(null, "author-1", Set.of(book1)) - authorRepository.save(author1) - val found = authorRepository.queryFindByName("author-1") - assertThat(found).isNotNull() - checkNotNull(found) - assertThat(found.id).isNotNull() - assertThat(found.name).isEqualTo("author-1") - assertThat(found.books).hasSize(1) - } -}