zonkyio / embedded-database-spring-test

A library for creating isolated embedded databases for Spring-powered integration tests.
Apache License 2.0
397 stars 35 forks source link

db rider with zonkyio embedded postgresql #270

Closed alex123asd123asd closed 2 weeks ago

alex123asd123asd commented 3 months ago

Hello. Does it possible to use db rider with zonkyio embedded postgresql? I have tried, but without success - @DataSet annotation throws an exception that table does not exist.

tomix26 commented 3 months ago

Hi, thanks for the comment. I've just tested it and it seems that this combination works fine. Technically, it should be possible to use the embedded database library with any tool that accesses the database using Spring's dataSource bean.

However, proper configuration is essential for proper operation. Make sure you have the caseSensitiveTableNames flag enabled and that your schema name is set up correctly. In my case, the annotations below were enough to get it working.

@DBRider
@DBUnit(caseSensitiveTableNames = true, escapePattern = "\"?\"", schema = "test")
alex123asd123asd commented 3 months ago

Cool it works. Thank you for your help :)

@Sql("/datasets/init.sql")
@ExtendWith(DBUnitExtension.class)
@SpringJUnitConfig(DbTestConfig.class)
@DBUnit(caseSensitiveTableNames = true)
@AutoConfigureEmbeddedDatabase(provider = ZONKY)
class CddAlertRepositoryImplV2IntegrationTest {

    @Autowired
    MyRepository myRepository;

    Info INFO = Info.builder()
            .x("x")
            .y("y")
            .z("z")
            .build();

    @Test
    @DataSet("/datasets/data.xml")
    void test() {
        var data = myRepository.getData(INFO);
        var expected = ...;
        assertEquals(expected, data);
    }

}
tomix26 commented 2 weeks ago

Glad to hear it 👍