From eadbcc976baf0ee598b0c35121c93fb71b0364d5 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Wed, 10 Jun 2020 11:15:46 +0200 Subject: [PATCH] Checkpoint --- .../src/main/java/com/plannaplan/Book.java | 26 +++++++++++++++++++ .../java/com/plannaplan/BookRepository.java | 8 ++++++ .../main/java/com/plannaplan/BookService.java | 17 ++++++++++++ .../src/test/java/com/plannaplan/AppTest.java | 20 +++++++------- 4 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 buisnesslogic/src/main/java/com/plannaplan/Book.java create mode 100644 buisnesslogic/src/main/java/com/plannaplan/BookRepository.java create mode 100644 buisnesslogic/src/main/java/com/plannaplan/BookService.java diff --git a/buisnesslogic/src/main/java/com/plannaplan/Book.java b/buisnesslogic/src/main/java/com/plannaplan/Book.java new file mode 100644 index 0000000..5440913 --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/Book.java @@ -0,0 +1,26 @@ +package com.plannaplan; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Book { + + @Id + @GeneratedValue + private Long id; + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + // standard constructors + + // standard getters and setters +} \ No newline at end of file diff --git a/buisnesslogic/src/main/java/com/plannaplan/BookRepository.java b/buisnesslogic/src/main/java/com/plannaplan/BookRepository.java new file mode 100644 index 0000000..d57bb7a --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/BookRepository.java @@ -0,0 +1,8 @@ +package com.plannaplan; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface BookRepository extends JpaRepository { +} diff --git a/buisnesslogic/src/main/java/com/plannaplan/BookService.java b/buisnesslogic/src/main/java/com/plannaplan/BookService.java new file mode 100644 index 0000000..c433d5d --- /dev/null +++ b/buisnesslogic/src/main/java/com/plannaplan/BookService.java @@ -0,0 +1,17 @@ +package com.plannaplan; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class BookService { + + @Autowired + private BookRepository bookRepository; + + public List list() { + return bookRepository.findAll(); + } +} diff --git a/buisnesslogic/src/test/java/com/plannaplan/AppTest.java b/buisnesslogic/src/test/java/com/plannaplan/AppTest.java index c2cebc0..00a920c 100644 --- a/buisnesslogic/src/test/java/com/plannaplan/AppTest.java +++ b/buisnesslogic/src/test/java/com/plannaplan/AppTest.java @@ -1,20 +1,22 @@ package com.plannaplan; -import static org.junit.Assert.assertTrue; +import java.util.List; +import org.junit.Assert; import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; /** * Unit test for simple App. */ -public class AppTest -{ - /** - * Rigorous Test :-) - */ +public class AppTest { + @Autowired + private BookService bookService; + @Test - public void shouldAnswerWithTrue() - { - assertTrue( true ); + public void whenApplicationStarts_thenHibernateCreatesInitialRecords() { + List books = bookService.list(); + + Assert.assertEquals(books.size(), 1); } }