Read DBUnit configuration from Spring properties
See original GitHub issueIt seems that #483 does not cover the case where DBRider is used on a @SpringBootTest
and should use the Spring Properties from that test’s Spring context for its configuration. I’m not sure but I don’t think these Spring Context Properties are made into System Properties (they’re not environment properties obviously, since they can be read in a lot of ways by Spring). I think DBRider would have to rely on Spring’s EL (or some other Spring API) to resolve those properties against the running test Sping Context.
E.g.: SomeTest.java
@SpringBootTest
@DBRider
@DataSet("datasets/some-dataset.xml")
public class SomeTest {
...
}
dbunit.yml
caseInsensitiveStrategy: !!com.github.database.rider.core.api.configuration.Orthography 'LOWERCASE'
columnSensing: true
properties:
batchedStatements: true
schema: ${spring.datasource.username}
With DBRider v1.34.0, I get the error:
...
Caused by: org.dbunit.dataset.NoSuchTableException: The table 'sometable' does not exist in schema '${spring.datasource.username}'
at app//org.dbunit.database.search.AbstractMetaDataBasedSearchCallback.getNodes(AbstractMetaDataBasedSearchCallback.java:186)
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Spring Test DBUnit – Introduction - GitHub Pages
The databaseConnection attribute allows you to specify a specific bean name from the Spring Context that contains the database connection.
Read more >Configuring Separate Spring DataSource for Tests - Baeldung
A quick, practical tutorial on how to configure a separate data source for testing in a Spring application.
Read more >Load spring boot app properties from database - Stack Overflow
The setApplicationContext method fetches above bean from the context, extracts the configured values as java Properties class, converts these to a ...
Read more >Accessing application properties with Spring Boot properties API
If you prefer to use Spring Boot @ConfigurationProperties annotated class to access application properties instead of @ConfigMapping or a MicroProfile ...
Read more >“How-to” Guides - Spring
This section includes topics about setting and reading properties and configuration settings and their interaction with Spring Boot applications ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see, we could do that in
rider-spring
as we don’t want to depend on spring in rider-core. It would be nice to do such integration in rider-junit5 module as we also have some integration there.Ok I see our misunderstanding now. Let me try to explain.
Spring can load its configuration properties in a lot of different ways. Them being system properties is only one of a lot of options. They can be specified via properties files, yaml files, command-line arguments, configuration servers, custom implementations, etc. etc. There’s even a very elaborate way and order for overriding them. In our specific case, we generate test-configuration files that we load into our
@SpringBootTest
s, but in order to play nice, DBRider should rely on Spring to resolve these properties. That’s why I proposed to rely on Spring’s EL when a Spring Context is available. As a fallback, when Spring is not available, DBRider could use its own implementation to read System and Environment properties (as it does now).So in order to integrate well into the Spring ecosystem, what we’d need is:
What we have now is: