DBUnit behavior when checking view contents

53 views Asked by At

I have a DatabaseUpdateRunner class that executes SQL scripts on an Oracle database. In my unit test, I'm trying to see if a view was created as expected and check the contents.

public class Mig1OraTests extends MigOraTestsBase {

    @Test
    @DatabaseSetup(connection = ORA_DB_UNIT_CXN, value = "Mig1-i.xml")
    @ExpectedDatabase(connection = EXPECTED_ORA_DB_UNIT_CXN, value = "Mig1-e.xml",
        assertionMode = DatabaseAssertionMode.NON_STRICT_UNORDERED)
    public void whenExecuteMig1_thenPerformOpWithSuccess() {
        databaseUpdateRunner.execute();
    }
}

The problem I'm struggling with is that if I define my database connection bean with the property I think I need(so that the view is seen as a table and I can make assertions on it using the @ExpectedDatabase with a given xml)

    DatabaseConnection databaseConnection = new DatabaseConnection(dataSource.getConnection());
    DatabaseConfig config = databaseConnection.getConfig();
      config
          .setProperty(DatabaseConfig.PROPERTY_TABLE_TYPE, new String[]{"TABLE", "VIEW"});

I get this error suggesting that there are multiple instances of the view, instead of my previous org.dbunit.dataset.NoSuchTableException for MY_VIEW:

MY_VIEW
org.dbunit.database.AmbiguousTableNameException: MY_VIEW
    at org.dbunit.dataset.OrderedTableNameMap.add(OrderedTableNameMap.java:198)
    at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:244)
    at org.dbunit.database.DatabaseDataSet.getTable(DatabaseDataSet.java:329)
    at com.github.springtestdbunit.assertion.NonStrictDatabaseAssertion.assertEquals(NonStrictDatabaseAssertion.java:47)
    at com.github.springtestdbunit.DbUnitRunner.verifyExpected(DbUnitRunner.java:154)
    at com.github.springtestdbunit.DbUnitRunner.verifyExpected(DbUnitRunner.java:120)
    at com.github.springtestdbunit.DbUnitRunner.afterTestMethod(DbUnitRunner.java:86)
    at com.github.springtestdbunit.DbUnitTestExecutionListener.afterTestMethod(DbUnitTestExecutionListener.java:190)
    at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:441)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:94)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
    at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
    at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:121)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
    at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
    at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    at java.lang.Thread.run(Thread.java:750)

Mig1-i.xml structure:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <TABLE1 COL1="COL1_VL" COL2="COL2_VL"/>
    <TABLE2 COL3="COL3_VL"/>
</dataset>

Mig1-e.xml structure:

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <MY_VIEW COL1="COL1_VL" COL2="COL2_VL" COL3="COL3_VL"/>
</dataset>

Any clue how to solve this WITHOUT setting a schema?

0

There are 0 answers