diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 98739a3..c1738af 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -40,6 +40,7 @@ dependencies { testImplementation("org.springframework.boot:spring-boot-starter-validation-test") testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test") testRuntimeOnly("org.junit.platform:junit-platform-launcher") + testImplementation("org.springframework.boot:spring-boot-starter-test") } dependencyManagement { diff --git a/backend/src/test/java/com/vaessl/app/ApplicationTests.java b/backend/src/test/java/com/vaessl/app/ApplicationTests.java index c96df68..2e60da2 100644 --- a/backend/src/test/java/com/vaessl/app/ApplicationTests.java +++ b/backend/src/test/java/com/vaessl/app/ApplicationTests.java @@ -1,13 +1,29 @@ package com.vaessl.app; +import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.DataSource; + import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import static org.assertj.core.api.Assertions.assertThat; @SpringBootTest +@ActiveProfiles("test") class ApplicationTests { - @Test - void contextLoads() { - } + @Autowired + private DataSource dataSource; + @Test + void connectionToTestDbWorks() throws SQLException { + try (Connection connection = dataSource.getConnection()) { + assertThat(connection.getMetaData().getURL()).contains("vaessl_test"); + } + + } } diff --git a/backend/src/test/resources/application-test.yaml b/backend/src/test/resources/application-test.yaml new file mode 100644 index 0000000..b415c9d --- /dev/null +++ b/backend/src/test/resources/application-test.yaml @@ -0,0 +1,9 @@ +spring: + datasource: + url : ${DB_TEST_URL} + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + driver-class-name: ${PG_DRIVER_CLASS_NAME} + jpa: + hibernate: + ddl-auto: create-drop \ No newline at end of file