1

I'm trying to write integration tests for our Spring Boot app. We want to use spring-test-dbunit and dbunit to setup and teardown test data on a Postgresql 9.4.2 database with an empty schema.

After struggling with case insensitive table names, which I could easily solve by setting the DBUnit config property caseSensitiveTableNames to true, I am now having the exact same issue with column names, but I cannot figure out how to make DBUnit understand that Postgresql doesn't go well with upper case.

Here's my (simplified) dataset:

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
    <customer_status status_id="0" descripton="description" />
</dataset>

And here's my basic test case so far:

@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class })
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = IntegrationTestConfig.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@DbUnitConfiguration(databaseConnection="dbUnitDatabaseConnection")
@DatabaseSetup("classpath:datasets/authentication/oauth_setup.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = { "classpath:datasets/authentication/oauth_setup.xml" })
@DirtiesContext
public class OauthIntegrationTest {

    @Value("${local.server.port}")
    int port;

    @Test
    public void thatStuffIsHappening() {
        //here be stuff (test fails on dbunit setup)    
    }
}

And finally this is my DBUnit configuration so far:

@Import({ ControllerConfig.class, PersistenceConfig.class })
public class IntegrationTestConfig extends App {

    @Autowired
    DataSource dataSource;

    @Bean
    public DatabaseConfigBean dbUnitDatabaseConfig() {
        final DatabaseConfigBean dbConfig = new DatabaseConfigBean();
        dbConfig.setDatatypeFactory(new PostgresqlDataTypeFactory());
        dbConfig.setCaseSensitiveTableNames(true);
        return dbConfig;
    }

    @Bean
    public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() {
        final DatabaseDataSourceConnectionFactoryBean connection = new DatabaseDataSourceConnectionFactoryBean();
        connection.setDataSource(this.dataSource);
        connection.setDatabaseConfig(this.dbUnitDatabaseConfig());
        connection.setSchema("public");
        return connection;
      }
  }

Running the test ends up with this error:

org.dbunit.dataset.NoSuchColumnException: customer_status.DESCRIPTON - (Non-uppercase input column: descripton) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.

Which is correct, because all column names in PSQL are in lower case. Why is DBUnit turning them to upper case and is there a way to prevent that?

I've tried to google it, but the only thing matching my problem so far was this, but I really don't like reverting to old versions.

Any hints? I can't believe that this is a serious problem and not just me overlooking something...

Community
  • 1
  • 1
Serg Derbst
  • 444
  • 6
  • 18

1 Answers1

1

Oh my - this has just been a major facepalm issue. There was a typo in my setup.xml file. Instead of "description" I wrote "descripton".

Now it works and there is nothing wrong with anything except my typing and reading skills. ;)

Serg Derbst
  • 444
  • 6
  • 18