Merge pull request 'hibernate-templ' (#1) from hibernate-templ into master

This commit is contained in:
Maciej 2020-06-11 19:11:42 +02:00
commit 6620dc038b
9 changed files with 76 additions and 14 deletions

View File

@ -1 +1,2 @@
docker-compose -f stack.yml up docker-compose -f stack.yml up
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id

View File

@ -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
}

View File

@ -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<Book, Long> {
}

View File

@ -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<Book> list() {
return bookRepository.findAll();
}
}

View File

@ -1,20 +1,24 @@
package com.plannaplan; package com.plannaplan;
import static org.junit.Assert.assertTrue; import java.util.List;
import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.Ignore;
import org.springframework.beans.factory.annotation.Autowired;
/** /**
* Unit test for simple App. * Unit test for simple App.
*/ */
public class AppTest public class AppTest {
{ @Autowired
/** private BookService bookService;
* Rigorous Test :-)
*/ @Ignore
@Test @Test
public void shouldAnswerWithTrue() public void whenApplicationStarts_thenHibernateCreatesInitialRecords() {
{ List<Book> books = bookService.list();
assertTrue( true );
Assert.assertEquals(books.size(), 1);
} }
} }

View File

@ -0,0 +1,6 @@
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url=jdbc:mysql://172.20.0.2:3306/test
spring.datasource.username=root
spring.datasource.password=example
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop

View File

@ -78,7 +78,8 @@
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>
<modules> <module>buisnesslogic</module> <modules>
<module>buisnesslogic</module>
<module>restservice</module> <module>restservice</module>
</modules> </modules>
</project> </project>

View File

@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.RestController;
public class TestController { public class TestController {
@GetMapping("/") @GetMapping("/")
public String xd() { public String xd() {
SampleClass xd = new SampleClass("hedhadhsbajkd"); return "<h1>xd</h1>";
return "<h1>" + xd.getXd() + "</h1>";
} }
} }

View File

@ -1,8 +1,8 @@
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url=jdbc:mariadb://localhost:3306/test spring.datasource.url=jdbc:mysql://172.20.0.2:3306/test
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=example spring.datasource.password=example
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.ddl-auto=create
server.port=1285 server.port=1285