From 8031775dd3449335845ff9585b0d7eafe1c122b3 Mon Sep 17 00:00:00 2001 From: GeorgeC Date: Thu, 14 Nov 2024 11:48:30 -0500 Subject: [PATCH] Add @ActiveProfiles("test") to unit tests This is only necessary for unit test that do not use the postgres database. This will eliminate the spam from the DataSourceVerifier. --- .../dictionary/datasource/DataSourceVerifier.java | 11 ++++++----- .../dictionary/concept/ConceptControllerTest.java | 2 ++ .../concept/ConceptDecoratorServiceTest.java | 3 ++- .../concept/ConceptServiceIntegrationTest.java | 2 ++ .../dictionary/concept/ConceptServiceTest.java | 2 ++ .../dictionary/dashboard/DashboardConfigTest.java | 2 ++ .../dictionary/dashboard/DashboardControllerTest.java | 2 ++ .../dictionary/dashboard/DashboardServiceTest.java | 2 ++ .../dictionary/dataset/DatasetRepositoryTest.java | 2 -- .../dictionary/dataset/DatasetServiceTest.java | 2 ++ .../dictionary/facet/FacetControllerTest.java | 2 ++ .../avillach/dictionary/facet/FacetServiceTest.java | 2 ++ .../dictionary/facet/FilterPreProcessorTest.java | 2 ++ .../avillach/dictionary/info/InfoControllerTest.java | 2 ++ 14 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/harvard/dbmi/avillach/dictionary/datasource/DataSourceVerifier.java b/src/main/java/edu/harvard/dbmi/avillach/dictionary/datasource/DataSourceVerifier.java index 9e36308..e3fc2a5 100644 --- a/src/main/java/edu/harvard/dbmi/avillach/dictionary/datasource/DataSourceVerifier.java +++ b/src/main/java/edu/harvard/dbmi/avillach/dictionary/datasource/DataSourceVerifier.java @@ -3,15 +3,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Service; import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; -@Service +@Profile("!test") +@Configuration public class DataSourceVerifier { private static final Logger LOG = LoggerFactory.getLogger(DataSourceVerifier.class); @@ -28,11 +30,10 @@ public void verifyDataSourceConnection() { try (Connection connection = dataSource.getConnection()) { if (connection != null) { LOG.info("Datasource connection verified successfully."); - } else { - LOG.info("Failed to obtain a connection from the datasource."); } } catch (SQLException e) { - LOG.info("Error verifying datasource connection: {}", e.getMessage()); + LOG.info("Failed to obtain a connection from the datasource."); + LOG.debug("Error verifying datasource connection: {}", e.getMessage()); } } diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptControllerTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptControllerTest.java index a5d5fe6..363c180 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptControllerTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptControllerTest.java @@ -16,12 +16,14 @@ import org.springframework.data.domain.Pageable; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; import java.util.List; import java.util.Map; import java.util.Optional; @SpringBootTest(properties = {"concept.tree.max_depth=1"}) +@ActiveProfiles("test") class ConceptControllerTest { @MockBean diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptDecoratorServiceTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptDecoratorServiceTest.java index 6800f57..c543f27 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptDecoratorServiceTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptDecoratorServiceTest.java @@ -10,12 +10,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; -import javax.print.attribute.DocAttributeSet; import java.util.Optional; @SpringBootTest +@ActiveProfiles("test") class ConceptDecoratorServiceTest { @MockBean diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceIntegrationTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceIntegrationTest.java index e51ac7b..5bef7ba 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceIntegrationTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceIntegrationTest.java @@ -8,6 +8,7 @@ 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 org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.testcontainers.containers.PostgreSQLContainer; @@ -21,6 +22,7 @@ @Testcontainers @SpringBootTest +@ActiveProfiles("test") class ConceptServiceIntegrationTest { @Autowired diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceTest.java index 0238e0c..610ba94 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/concept/ConceptServiceTest.java @@ -13,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.data.domain.Pageable; +import org.springframework.test.context.ActiveProfiles; import java.util.List; import java.util.Map; @@ -20,6 +21,7 @@ @SpringBootTest +@ActiveProfiles("test") class ConceptServiceTest { @MockBean diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardConfigTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardConfigTest.java index 397a055..c5e280f 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardConfigTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardConfigTest.java @@ -4,10 +4,12 @@ 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 java.util.List; @SpringBootTest +@ActiveProfiles("test") class DashboardConfigTest { @Autowired diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardControllerTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardControllerTest.java index ec11139..116e284 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardControllerTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardControllerTest.java @@ -8,10 +8,12 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; import java.util.List; @SpringBootTest +@ActiveProfiles("test") class DashboardControllerTest { @MockBean private DashboardService service; diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardServiceTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardServiceTest.java index 1825e21..03255bd 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardServiceTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dashboard/DashboardServiceTest.java @@ -6,11 +6,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; import java.util.List; import java.util.Map; @SpringBootTest +@ActiveProfiles("test") class DashboardServiceTest { @MockBean DashboardRepository repository; diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetRepositoryTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetRepositoryTest.java index 036a36d..03f169d 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetRepositoryTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetRepositoryTest.java @@ -1,6 +1,5 @@ package edu.harvard.dbmi.avillach.dictionary.dataset; -import edu.harvard.dbmi.avillach.dictionary.facet.FacetRepository; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -15,7 +14,6 @@ import java.util.Map; import java.util.Optional; -import static org.junit.jupiter.api.Assertions.*; @Testcontainers @SpringBootTest diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetServiceTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetServiceTest.java index 22b8f12..8580060 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetServiceTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/dataset/DatasetServiceTest.java @@ -6,11 +6,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; import java.util.Map; import java.util.Optional; @SpringBootTest +@ActiveProfiles("test") class DatasetServiceTest { @MockBean diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetControllerTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetControllerTest.java index 331f176..96ea6eb 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetControllerTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetControllerTest.java @@ -9,11 +9,13 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; import java.util.List; import java.util.Optional; @SpringBootTest +@ActiveProfiles("test") class FacetControllerTest { @MockBean diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetServiceTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetServiceTest.java index e9c3aab..3b8775f 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetServiceTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FacetServiceTest.java @@ -8,12 +8,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.ActiveProfiles; import java.util.List; import java.util.Map; import java.util.Optional; @SpringBootTest +@ActiveProfiles("test") class FacetServiceTest { @MockBean private FacetRepository repository; diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java index 6d3d452..70e90a5 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/facet/FilterPreProcessorTest.java @@ -8,11 +8,13 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.MethodParameter; import org.springframework.http.HttpInputMessage; +import org.springframework.test.context.ActiveProfiles; import org.testcontainers.shaded.com.fasterxml.jackson.databind.type.SimpleType; import java.util.List; @SpringBootTest +@ActiveProfiles("test") class FilterPreProcessorTest { @Autowired diff --git a/src/test/java/edu/harvard/dbmi/avillach/dictionary/info/InfoControllerTest.java b/src/test/java/edu/harvard/dbmi/avillach/dictionary/info/InfoControllerTest.java index d401db4..53345a1 100644 --- a/src/test/java/edu/harvard/dbmi/avillach/dictionary/info/InfoControllerTest.java +++ b/src/test/java/edu/harvard/dbmi/avillach/dictionary/info/InfoControllerTest.java @@ -6,12 +6,14 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; import java.util.List; import java.util.UUID; @SpringBootTest +@ActiveProfiles("test") class InfoControllerTest { @Autowired