diff --git a/.env-example b/.env-example new file mode 100644 index 0000000..2eba09e --- /dev/null +++ b/.env-example @@ -0,0 +1,6 @@ +DB_URL=jdbc:postgresql://localhost:5432/todo_db +DB_USERNAME=todo_dev +DB_PASSWORD=todo-123 +DB_NAME=todo_db +PGADMIN_MAIL=todo@gmail.com +PGADMIN_PASSWORD=todo123 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9e429cb..bef0298 100644 --- a/pom.xml +++ b/pom.xml @@ -2,12 +2,14 @@ 4.0.0 + org.springframework.boot spring-boot-starter-parent 3.2.2 + com.pedro rest 0.0.1-SNAPSHOT @@ -16,6 +18,7 @@ 21 + org.springframework.boot @@ -39,11 +42,17 @@ spring-boot-starter-data-jpa - - - - - + + org.postgresql + postgresql + + + + + com.h2database + h2 + test + @@ -51,23 +60,23 @@ spring-boot-starter-actuator - - - - - + + + + + - - - - - + + + + + - - - - + + + + diff --git a/src/main/java/com/pedro/rest/configuration/Properties.java b/src/main/java/com/pedro/rest/configuration/Properties.java new file mode 100644 index 0000000..211378b --- /dev/null +++ b/src/main/java/com/pedro/rest/configuration/Properties.java @@ -0,0 +1,38 @@ +package com.pedro.rest.configuration; + +import jakarta.annotation.PostConstruct; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class Properties { + + @Value("${DB_URL}") + private String dbUrl; + + @Value("${DB_USERNAME}") + private String dbUsername; + + @Value("${DB_PASSWORD}") + private String dbPassword; + + @Value("${DB_NAME}") + private String dbName; + + @Value("${PGADMIN_MAIL}") + private String pgAdminMail; + + @Value("${PGADMIN_PASSWORD}") + private String pgAdminPassord; + + @PostConstruct + public void printProperties() { + System.out.println("#### [App Properties] ####"); + System.out.println("DB_URL: " + dbUrl); + System.out.println("DB_USERNAME: " + dbUsername); + System.out.println("DB_PASSWORD: " + dbPassword); + System.out.println("DB_NAME: " + dbName); + System.out.println("PGADMIN_MAIL: " + pgAdminMail); + System.out.println("PGADMIN_PASSWORD: " + pgAdminPassord); + } +} \ No newline at end of file diff --git a/src/main/java/com/pedro/rest/model/Employee.java b/src/main/java/com/pedro/rest/model/Employee.java index aadd8ae..8a2c0de 100644 --- a/src/main/java/com/pedro/rest/model/Employee.java +++ b/src/main/java/com/pedro/rest/model/Employee.java @@ -4,10 +4,11 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; +import java.io.Serializable; import java.util.Objects; @Entity -public class Employee { +public class Employee implements Serializable { @Id @GeneratedValue private Long id; @@ -15,7 +16,8 @@ public class Employee { private String lastName; private String role; - Employee() { + // no-args constructor required by JPA spec + protected Employee() { } public Employee(String firstName, String lastName, String role) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f99a52a..9bbf851 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,14 +1,21 @@ +# Debug Spring Framework +# logging.level.org.springframework.boot=DEBUG + # Database +# Check IDE (eclipse/intellij) configuration to set .env file path spring.datasource.url=${DB_URL} spring.datasource.username=${DB_USERNAME} spring.datasource.password=${DB_PASSWORD} +spring.jpa.hibernate.ddl-auto=create-drop + # Enable SQL logging spring.datasource.log-statement=true +logging.level.org.hibernate.SQL=DEBUG # Hibernate specific: Show SQL with formatted parameters -spring.jpa.show-sql=true -spring.jpa.properties.hibernate.format_sql=true +#spring.jpa.show-sql=true +#spring.jpa.properties.hibernate.format_sql=true # Observability # management.wavefront.application.name=rest diff --git a/src/test/java/com/pedro/rest/service/impl/EmployeeServiceIntegrationTest.java b/src/test/java/com/pedro/rest/service/impl/EmployeeServiceIntegrationTest.java index 070d727..3a77062 100644 --- a/src/test/java/com/pedro/rest/service/impl/EmployeeServiceIntegrationTest.java +++ b/src/test/java/com/pedro/rest/service/impl/EmployeeServiceIntegrationTest.java @@ -14,6 +14,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.EntityModel; +import org.springframework.test.context.ActiveProfiles; import java.util.List; @@ -23,6 +24,7 @@ import static org.mockito.Mockito.verify; @SpringBootTest +@ActiveProfiles("test") public class EmployeeServiceIntegrationTest { @Autowired private EmployeeServiceImpl service; diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties new file mode 100644 index 0000000..0b67994 --- /dev/null +++ b/src/test/resources/application-test.properties @@ -0,0 +1,4 @@ +spring.datasource.url=jdbc:h2:mem:rest_db +spring.datasource.username=sa +spring.datasource.password= +spring.h2.console.enabled=true \ No newline at end of file