[R1] Add active profile for test

This commit is contained in:
Mirna Gama 2024-01-04 15:49:49 -03:00 committed by Mirna Gama
parent 1c21a0b0c8
commit cf9a11971e
4 changed files with 21 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
@ -25,6 +26,7 @@ import com.mirna.hospitalmanagementapi.domain.enums.Specialty;
@SpringBootTest @SpringBootTest
@AutoConfigureMockMvc(addFilters = false) @AutoConfigureMockMvc(addFilters = false)
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ActiveProfiles("test")
public class DoctorControllerTest { public class DoctorControllerTest {
@Autowired @Autowired

View File

@ -9,6 +9,7 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle; import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import com.mirna.hospitalmanagementapi.HospitalManagementApiApplication; import com.mirna.hospitalmanagementapi.HospitalManagementApiApplication;
import com.mirna.hospitalmanagementapi.application.services.DoctorServiceImpl; import com.mirna.hospitalmanagementapi.application.services.DoctorServiceImpl;
@ -26,6 +27,7 @@ import jakarta.validation.ConstraintViolationException;
*/ */
@SpringBootTest(classes = HospitalManagementApiApplication.class) @SpringBootTest(classes = HospitalManagementApiApplication.class)
@TestInstance(Lifecycle.PER_CLASS) @TestInstance(Lifecycle.PER_CLASS)
@ActiveProfiles("test")
public class DoctorServiceTest { public class DoctorServiceTest {
@Autowired @Autowired

View File

@ -9,6 +9,7 @@ import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle; import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import com.mirna.hospitalmanagementapi.HospitalManagementApiApplication; import com.mirna.hospitalmanagementapi.HospitalManagementApiApplication;
import com.mirna.hospitalmanagementapi.application.usecase.doctor.AddDoctorUseCase; import com.mirna.hospitalmanagementapi.application.usecase.doctor.AddDoctorUseCase;
@ -25,6 +26,7 @@ import com.mirna.hospitalmanagementapi.domain.repositories.DoctorRepository;
*/ */
@SpringBootTest(classes = HospitalManagementApiApplication.class) @SpringBootTest(classes = HospitalManagementApiApplication.class)
@TestInstance(Lifecycle.PER_CLASS) @TestInstance(Lifecycle.PER_CLASS)
@ActiveProfiles("test")
public class AddDoctorUseCaseTest { public class AddDoctorUseCaseTest {
@Autowired @Autowired

View File

@ -0,0 +1,15 @@
# datasource
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
# jpa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
# h2
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console