1

This is my setup for integration testing with spring and embedded database H2

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd">

    <jdbc:embedded-database id="dataSource" type="H2" />

    <jdbc:initialize-database data-source="dataSource">
        <jdbc:script location="classpath:sql/globalParams.sql"/>
        <jdbc:script location="classpath:sql/customersGroupView.sql"/>
        <jdbc:script location="classpath:sql/recentIntegrationsTableAndTrigger.sql"/>
        <jdbc:script location="classpath:sql/insertIntegrationDate.sql"/>
        <jdbc:script location="classpath:sql/toCharRoutine.sql"/>
    </jdbc:initialize-database>
</beans>

Abstract parent of integration tests

@ContextConfiguration(locations = [
    "classpath:com/dhl/dcc/dcc-core.xml",
    "classpath:com/dhl/dcc/test-security.xml",
    "classpath:com/dhl/dcc/dcc-audit.xml",
    "classpath:com/dhl/dcc/test-dataSource.xml",
    "classpath:com/dhl/dcc/test-beans.xml",
    "classpath:com/dhl/dcc/dcc-forms.xml"
])
public abstract class AbstractIntegrationTestCase extends AbstractTransactionalJUnit4SpringContextTests {

and in core cofiguration of entity manager factory

<property name="generateDdl" value="${dcc.orm.generateDdl:false}"/>

property dcc.orm.generateDdl is set to true in properties.

It worked well (database schema was generated from classes annotated @Entity) but now i separated domain model into its own project and added this project as dependency in Maven. After that my integration tests starting to fail because of missing db schema. How do i configure where should embedded database look for a domain model? Thanks.

edit: entity factory configuration

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="persistenceUnitName" value="DCC"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="${dcc.orm.generateDdl:false}"/>
                <property name="showSql" value="${dcc.orm.showSql:false}"/>
                <property name="databasePlatform" value="${dcc.orm.dialect}"/>
            </bean>
        </property>
    </bean>
4

1 に答える 1