question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Read DBUnit configuration from Spring properties

See original GitHub issue

It 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:open
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rmpestanocommented, Aug 31, 2022

I see, we could do that inrider-springas 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.

0reactions
netmikeycommented, Aug 31, 2022

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 @SpringBootTests, 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:

graph TD;
    P["properties file"]-->Spring;
    Y["yaml file"]-->Spring;
    C["command-line argument"]-->Spring;
    ETC["..."]-->Spring;
    E["environment variable"]-->Spring;
    S["system property"]-->Spring;
    Spring-->DBRider;

What we have now is:

graph TD;
    P["properties file"]-->Spring;
    Y["yaml file"]-->Spring;
    C["command-line argument"]-->Spring;
    ETC["..."]-->Spring;
    E["environment variable"]-->Spring;
    S["system property"]-->Spring;
    E-->DBRider;
    S-->DBRider;
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found