Quero testar a classe Properties sem a anotação @SpringBootTest. Mas não funciona. Como posso consertar? Estou usando Kotlin, Spring Boot 2.7.18
@ActiveProfiles("test")
@ExtendWith(SpringExtension::class)
@ContextConfiguration(classes = [TestConfig::class])
class AESTest {
@Autowired
lateinit var properties: TestAESProperty
@Test
fun decrypt() {
assertEquals(properties.key, "hello")
assertEquals(properties.iv, "world")
}
}
@TestConfiguration
@EnableConfigurationProperties(TestAESProperty::class)
class TestConfig {
}
@ConstructorBinding
@ConfigurationProperties(prefix = "common.test.aes")
data class TestAESProperty(
val key: String,
val iv: String,
)
---- aplicação-teste.yml ----------
spring:
config:
activate:
on-profile: test
common:
test:
aes:
key: hello
iv: world
Mas, os erros abaixo ocorrem.
Failed to bind properties under 'common.test.aes' to TestAESProperty
Parameter specified as non-null is null: method TestAESProperty.<init>, parameter key
Error creating bean with name 'TestAESProperty'
Could not bind properties to 'TestAESProperty' : prefix=common.test.aes, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'common.test.aes' to TestAESProperty
Quero vincular dados do arquivo 'application-test.yml' porque ele pode ser mais seguro com o AWS Service Manager.