From 7d418882283942c22c3cb73580e7119271bee72e Mon Sep 17 00:00:00 2001 From: Taciano Morais Silva Date: Mon, 1 May 2023 17:49:57 -0300 Subject: [PATCH] test: ajustes para testes com H2 #64 --- .../br/ufrn/dct/apf/APFApplicationTests.java | 2 +- .../controller/UserStoryControllerTest.java | 5 -- .../apf/repository/RoleRepositoryTest.java | 2 + src/test/resources/application.properties | 56 +++++++++++++++++++ src/test/resources/data.sql | 5 -- 5 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 src/test/resources/application.properties delete mode 100644 src/test/resources/data.sql diff --git a/src/test/java/br/ufrn/dct/apf/APFApplicationTests.java b/src/test/java/br/ufrn/dct/apf/APFApplicationTests.java index 2a30052..9344269 100644 --- a/src/test/java/br/ufrn/dct/apf/APFApplicationTests.java +++ b/src/test/java/br/ufrn/dct/apf/APFApplicationTests.java @@ -5,7 +5,7 @@ import org.testng.annotations.Test; @SpringBootTest -public class APFApplicationTests extends AbstractTestNGSpringContextTests{ +public class APFApplicationTests extends AbstractTestNGSpringContextTests { @Test public void contextLoads() { diff --git a/src/test/java/br/ufrn/dct/apf/controller/UserStoryControllerTest.java b/src/test/java/br/ufrn/dct/apf/controller/UserStoryControllerTest.java index dbe5a87..7e40a9e 100644 --- a/src/test/java/br/ufrn/dct/apf/controller/UserStoryControllerTest.java +++ b/src/test/java/br/ufrn/dct/apf/controller/UserStoryControllerTest.java @@ -1,7 +1,5 @@ package br.ufrn.dct.apf.controller; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.containsString; import static org.mockito.Mockito.when; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -11,11 +9,8 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.testng.annotations.Test; diff --git a/src/test/java/br/ufrn/dct/apf/repository/RoleRepositoryTest.java b/src/test/java/br/ufrn/dct/apf/repository/RoleRepositoryTest.java index b1d2f52..102225f 100644 --- a/src/test/java/br/ufrn/dct/apf/repository/RoleRepositoryTest.java +++ b/src/test/java/br/ufrn/dct/apf/repository/RoleRepositoryTest.java @@ -3,6 +3,8 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jdbc.EmbeddedDatabaseConnection; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..8c11949 --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,56 @@ +# =============================== +# = DATA SOURCE +# =============================== +#spring.datasource.url=jdbc:h2:mem:apf_db;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS apf +spring.datasource.url=jdbc:h2:mem:apf_db;DB_CLOSE_DELAY=-1;MODE=Postgres; +spring.datasource.username=sa +spring.datasource.password= +spring.datasource.driver-class-name=org.h2.Driver +spring.data.jpa.repositories.bootstrap-mode=default + +# =============================== +# = JPA / HIBERNATE +# =============================== +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.jpa.hibernate.ddl-auto=update +spring.jpa.defer-datasource-initialization=true +# spring.jpa.properties.hibernate.default_schema=apf +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true + +# Enabling H2 Console +spring.h2.console.enabled=true + +# By default enabled for Embedded Databases +spring.sql.init.mode=always +spring.sql.init.continue-on-error=true + +logging.level.br.ufrn.dct.apf=DEBUG + +# =============================== +# = Thymeleaf configurations +# =============================== +spring.thymeleaf.mode=HTML +spring.thymeleaf.cache=false + +# ---------------------------------------- +# WEB PROPERTIES +# ---------------------------------------- + +# Context path of the application. +server.servlet.context-path=/apf +# Display name of the application. +server.servlet.application-display-name=Analisador de Pontos de Função +# Define server port. +server.port=8080 + +# ============================================================== +# = Spring Security / Queries for AuthenticationManagerBuilder +# ============================================================== +spring.queries.users-query=select email, password, active from apf.user where email=? +spring.queries.roles-query=select u.email, r.role_name from apf.user u inner join apf.user_role ur on(u.user_id=ur.user_id) inner join apf.role r on(ur.role_id=r.role_id) where u.email=? + +# ============================================================= +# = Spring General +# ============================================================= +spring.main.allow-bean-definition-overriding=true diff --git a/src/test/resources/data.sql b/src/test/resources/data.sql deleted file mode 100644 index 3ee6e05..0000000 --- a/src/test/resources/data.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO role VALUES (1,'ADMIN'); -INSERT INTO role VALUES (2,'USER'); - -INSERT INTO attribution VALUES (1,'PROJECT MANAGER'); -INSERT INTO attribution VALUES (2,'PROJECT MEMBER');