Skip to content

Spring Konfiguration

all4one edited this page Dec 11, 2017 · 2 revisions

dbUnitBurner mit Spring konfigurieren

Testklasse

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:application-context.xml" })
public class RecipeRepositoryIT {

    @Inject @Rule 
    public DbUnitRule dbUnitRule;

    @Test
    @UsingDataSet(value = { "/sample/prepare.json" })
    @ShouldMatchDataSet(
        value = { "/sample/afterInsertNewRecipe.json" },
        orderBy = { "RECIPE.UUID", "INGREDIENT.ID" })
    public void shouldBeInsertNewRecipe() {
        // write your test ...
    }
}

Spring "application-context.xml"

<bean name="rule" class="org.anderes.edu.dbunitburner.DbUnitRule">
     <constructor-arg ref="databaseTester"></constructor-arg>
</bean>

<bean name="databaseTester" class="org.dbunit.DataSourceDatabaseTester">
     <constructor-arg ref="dataSource"></constructor-arg>
</bean>

<!-- Data Source: Hier am Beispiel Derby Embedded --> 
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" /> 
     <property name="url" value="jdbc:derby:memory:testDB;create=true" /> 
     <property name="username" value="" /> 
     <property name="password" value="" /> 
</bean>

mit CustomDataTypeFactory

<bean name="rule" class="org.anderes.edu.dbunitburner.DbUnitRule">
    <constructor-arg ref="dataSource"></constructor-arg>
    <constructor-arg ref="customDataTypeFactory"></constructor-arg>
</bean>
    
<bean name="customDataTypeFactory" class="org.anderes.edu.dbunitburner.DerbyDateDataTypeFactory"></bean>