add missing integration test for InventoryDatabaseAdapter

This commit is contained in:
wkrzywiec
2020-05-21 15:53:37 +02:00
parent bebd23d22b
commit 8bea3936b7

View File

@@ -0,0 +1,46 @@
package io.wkrzywiec.hexagonal.library.inventory.infrastructure;
import io.wkrzywiec.hexagonal.library.TestData;
import io.wkrzywiec.hexagonal.library.inventory.model.Book;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.jdbc.core.JdbcTemplate;
import static org.junit.jupiter.api.Assertions.assertTrue;
@DataJpaTest
public class InventoryDatabaseAdapterITCase {
@Autowired
private BookRepository bookRepository;
@Autowired
private JdbcTemplate jdbcTemplate;
private InventoryDatabaseAdapter database;
@BeforeEach
public void init() {
database = new InventoryDatabaseAdapter(bookRepository);
}
@Test
@DisplayName("Save new book in database")
public void givenBook_whenSaveIt_thenBookIsSaved() {
//given
Book homoDeusBook = TestData.homoDeusBook();
//when
database.save(homoDeusBook);
//then
Long savedBookId = jdbcTemplate.queryForObject(
"SELECT id FROM book",
Long.class);
assertTrue(savedBookId > 0);
}
}