Skip to content

Commit

Permalink
HAI Profile overhaul
Browse files Browse the repository at this point in the history
Remove the profiles from Configuration and IntegrationTestConfiguration.
Configuration is enabled by default, and we import
IntegrationTestConfiguration explicitly when we use it.

This frees us to use the test profile in all tests, especially
integration tests. This means we can use application-test.properties for
configuring the test environment. This on turn means we don't have to
configure the main application.properties specifically for tests and we
can use production-safe defaults.
  • Loading branch information
corvidian committed Aug 31, 2023
1 parent bf9f250 commit b98718f
Show file tree
Hide file tree
Showing 35 changed files with 39 additions and 42 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ services:
HAITATON_EMAIL_FILTER_USE: false
CLAMAV_BASE_URL: http://clamav-api:3030
HAITATON_TESTDATA_ENABLED: true
HAITATON_FEATURE_HANKE_EDITING: true
HAITATON_FEATURE_USER_MANAGEMENT: true
depends_on:
- db
- clamav-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private const val BASE_URL = "/hankkeet"

@WebMvcTest(HankeController::class, properties = ["haitaton.features.hanke-editing=false"])
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME, roles = ["haitaton-user"])
class HankeControllerHankeEditingDisabledITests(@Autowired override val mockMvc: MockMvc) :
ControllerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private const val BASE_URL = "/hankkeet"
*/
@WebMvcTest(HankeController::class)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME, roles = ["haitaton-user"])
class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : ControllerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
internal class HankeRepositoryITests : DatabaseTest() {

@Autowired private lateinit var hankeRepository: HankeRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private const val NAME_SOMETHING = "Som Et Hing"

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(USER_NAME)
class HankeServiceITests : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
internal class HanketunnusServiceImplITest : DatabaseTest() {

@Autowired lateinit var hanketunnusService: HanketunnusService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ import io.sentry.protocol.SentryId
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Profile
import org.springframework.context.event.ContextRefreshedEvent
import org.springframework.context.event.EventListener
import org.springframework.jdbc.core.JdbcOperations
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.web.SecurityFilterChain

@TestConfiguration
@Profile("itest")
@EnableConfigurationProperties(GdprProperties::class, FeatureFlags::class)
class IntegrationTestConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Testcontainers
@ActiveProfiles("default")
@ActiveProfiles("test")
@AutoConfigureMockMvc
class SpringdocITest(@Autowired override val mockMvc: MockMvc) : ControllerTest, DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers

@WebMvcTest(StatusController::class)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
class StatusControllerITests(@Autowired val mockMvc: MockMvc) {

@Autowired lateinit var jdbcOperations: JdbcOperations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private const val BASE_URL = "/hakemukset"

@WebMvcTest(ApplicationController::class)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
class ApplicationControllerITest(@Autowired override val mockMvc: MockMvc) : ControllerTest {

@Autowired private lateinit var applicationService: ApplicationService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private val dataWithoutAreas = AlluDataFactory.createCableReportApplicationData(

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default", "emailtest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class ApplicationServiceITest : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

@WebMvcTest(ApplicationAttachmentController::class)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class ApplicationAttachmentControllerITest(@Autowired override val mockMvc: MockMvc) :
ControllerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private const val ALLU_ID = 42

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
@TestPropertySource(locations = ["classpath:application-test.properties"])
class ApplicationAttachmentServiceITest : DatabaseTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@TestPropertySource(locations = ["classpath:application-test.properties"])
class FileScanClientITest : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

@WebMvcTest(HankeAttachmentController::class)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class HankeAttachmentControllerITests(@Autowired override val mockMvc: MockMvc) : ControllerTest {

Expand Down Expand Up @@ -198,7 +198,7 @@ class HankeAttachmentControllerITests(@Autowired override val mockMvc: MockMvc)
properties = ["haitaton.features.hanke-editing=false"]
)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class HankeAttachmentControllerHankeEditingDisabledITests(
@Autowired override val mockMvc: MockMvc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
@TestPropertySource(locations = ["classpath:application-test.properties"])
class HankeAttachmentServiceITests : DatabaseTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPat

@WebMvcTest(PublicHankeController::class)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
class PublicHankeControllerITests(@Autowired override val mockMvc: MockMvc) : ControllerTest {

@Autowired private lateinit var hankeService: HankeService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.testcontainers.junit.jupiter.Testcontainers
"[email protected];[email protected]"
]
)
@ActiveProfiles("default", "emailtest")
@ActiveProfiles("test")
class EmailSenderServiceFilterITest : DatabaseTest() {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private const val APPLICATION_IDENTIFIER = "JS2300001"

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default", "emailtest")
@ActiveProfiles("test")
class EmailSenderServiceITest : DatabaseTest() {

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private const val USERID = "test-user"

@WebMvcTest(controllers = [GdprController::class], properties = ["haitaton.gdpr.disabled=false"])
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERID)
class GdprControllerITests(@Autowired var mockMvc: MockMvc) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private const val USERID = "test-user"

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(USERID)
class GdprServiceITest : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
internal class GeometriatDaoImplITest : DatabaseTest() {

private val expectedPolygonArea = 1707f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(username = "test", roles = ["haitaton-user"])
internal class GeometriatServiceImplITest : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.testcontainers.junit.jupiter.Testcontainers
// Thus, have to use this test containers -way, which uses the proper PostgreSQL.
@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
class AuditLogServiceITests : DatabaseTest() {

@Autowired private lateinit var entityManager: EntityManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
private const val USERNAME = "testUser"
private const val HANKE_TUNNUS = HankeFactory.defaultHankeTunnus

@WebMvcTest(
HankeKayttajaController::class,
properties = ["haitaton.features.user-management=true"],
)
@WebMvcTest(HankeKayttajaController::class)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class HankeKayttajaControllerITest(@Autowired override val mockMvc: MockMvc) : ControllerTest {

Expand Down Expand Up @@ -341,7 +338,7 @@ class HankeKayttajaControllerITest(@Autowired override val mockMvc: MockMvc) : C
properties = ["haitaton.features.user-management=false"],
)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class HankeKayttajaControllerFeatureDisabledITest(@Autowired override val mockMvc: MockMvc) :
ControllerTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const val kayttajaTunnistePattern = "[a-zA-z0-9]{24}"

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class HankeKayttajaServiceITest : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(username = "test7358")
class PermissionServiceITest : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private const val BASE_URL = "/testdata"
properties = ["haitaton.testdata.enabled=false"],
)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class TestDataControllerDisabledITest(@Autowired override val mockMvc: MockMvc) : ControllerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private const val BASE_URL = "/testdata"
properties = ["haitaton.testdata.enabled=true"],
)
@Import(IntegrationTestConfiguration::class)
@ActiveProfiles("itest")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class TestDataControllerEnabledITest(@Autowired override val mockMvc: MockMvc) : ControllerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private const val USERNAME = "testUser"
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
properties = ["haitaton.testdata.enabled=true"],
)
@ActiveProfiles("default")
@ActiveProfiles("test")
@WithMockUser(USERNAME)
class TestDataServiceITest : DatabaseTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.testcontainers.junit.jupiter.Testcontainers

@Testcontainers
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("default")
@ActiveProfiles("test")
internal class TormaystarkasteluTormaysServicePGITest : DatabaseTest() {

@Autowired private lateinit var geometriatDao: GeometriatDao
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Profile
import org.springframework.http.client.reactive.ReactorClientHttpConnector
import org.springframework.jdbc.core.JdbcOperations
import org.springframework.web.reactive.function.client.WebClient
import reactor.netty.http.client.HttpClient

@Configuration
@Profile("default")
@EnableConfigurationProperties(
GdprProperties::class,
FeatureFlags::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ haitaton.gdpr.delete-scope=${HAITATON_GDPR_DELETE_SCOPE:haitaton.gdprdelete}
#logging.level.org.springframework.security=DEBUG

# Disable endpoints that are e.g. in development and should not be in production.
haitaton.features.hanke-editing=${HAITATON_FEATURE_HANKE_EDITING:true}
haitaton.features.user-management=${HAITATON_FEATURE_USER_MANAGEMENT:true}
haitaton.features.hanke-editing=${HAITATON_FEATURE_HANKE_EDITING:false}
haitaton.features.user-management=${HAITATON_FEATURE_USER_MANAGEMENT:false}

# For dev and test environments, enable the testdata controller for resetting data
haitaton.testdata.enabled=${HAITATON_TESTDATA_ENABLED:false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ spring.mail.properties.mail.smtp.auth=false
spring.mail.properties.mail.smtp.starttls.enable=false
spring.mail.properties.mail.smtp.starttls.required=false
spring.mail.properties.mail.debug=false
haitaton.clamav.baseUrl=http://localhost:6789
haitaton.features.hanke-editing=true
haitaton.features.user-management=true

0 comments on commit b98718f

Please sign in to comment.