You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by mraible <ma...@raibledesigns.com> on 2006/08/24 20:08:43 UTC

Re: Does anyone know how to use the maven DBUnit plugin?



Ray Tsang wrote:
> 
> i'm using dbunit ant task to load initial data.. i have something like
> the following in profiles section of the pom.xml.  it will execute
> when `mvn -DloadData=true`
> 
> <profile>
>       <id>dbunit-load-data</id>
>       <activation>
>         <property>
>           <name>loadData</name>
>           <value>true</value>
>         </property>
>       </activation>
>       <build>
>         <plugins>
>           <plugin>
>             <artifactId>maven-antrun-plugin</artifactId>
>             <executions>
>               <execution>
>                 <id>process-classes</id>
>                 <phase>process-classes</phase>
>                 <goals>
>                   <goal>run</goal>
>                 </goals>
>                 <configuration>
>                   <tasks>
>                     <property value="CLEAN_INSERT" name="operation" />
>                     <property value="src/test/sql/test-data.xml"
> name="file" />
>                     <taskdef name="dbunit"
>                       classname="org.dbunit.ant.DbUnitTask" />
>                     <dbunit driver="${database.driver}"
>                       url="${database.url}"
>                       userid="${database.username}"
>                       password="${database.password}"
>                       supportBatchStatement="false">
>                       <operation type="${operation}"
>                         src="${file}" format="xml" />
>                     </dbunit>
>                   </tasks>
>                 </configuration>
>               </execution>
>             </executions>
>             <dependencies>
>           <dependency>
>             <groupId>${database.dependency.groupId}</groupId>
>             <artifactId>${database.dependency.artifactId}</artifactId>
>             <version>${database.dependency.version}</version>
>           </dependency>
>           <dependency>
>             <groupId>dbunit</groupId>
>             <artifactId>dbunit</artifactId>
>             <version>2.1</version>
>           </dependency>
>           <dependency>
>             <groupId>ant</groupId>
>             <artifactId>ant-nodeps</artifactId>
>             <version>1.6.5</version>
>             <scope>compile</scope>
>           </dependency>
>           <dependency>
>             <groupId>com.sun</groupId>
>             <artifactId>tools</artifactId>
>             <version>1.5</version>
>             <scope>system</scope>
>             <systemPath>${java.home}/../lib/tools.jar</systemPath>
>           </dependency>
>         </dependencies>
>           </plugin>
>         </plugins>
>       </build>
>     </profile>
> 

I'm using a similar setup (see XML below), but having a couple of issues. 

1. Is it possible to have the task invoked at the beginning of the "test"
phase?  Using <phase>test</phase> invokes it after running all the tests.  I
want it to run before. Using <phase>test-compile</phase> works, but seems to
be one phase behind what I want. 

2. How do I load a properties file in to set the ${...} properties?  It
tried <property
file="${project.build.sourceResources}/database.properties"/> and it doesn't
work.I get the following error:

Embedded error: Class Not Found: JDBC driver ${jdbc.driverClassName} could
not be loaded


            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>test-compile</phase>
                        <configuration>
                            <tasks>
                                <property
file="${project.build.sourceResources}/database.properties"/>
                                <condition property="operation"
value="MSSQL_CLEAN_INSERT" else="CLEAN_INSERT">
                                    <equals arg1="${database.type}"
arg2="sqlserver"/>
                                </condition>

                                <property name="file"
value="resources/dbunit/sample-data.xml"/>
                                <taskdef name="dbunit"
classname="org.dbunit.ant.DbUnitTask"/>
                                <dbunit driver="${jdbc.driverClassName}"
                                        supportBatchStatement="false"
url="${jdbc.url}"
                                        userid="${jdbc.username}"
password="${jdbc.password}">
                                    <operation type="${operation}"
src="${file}" format="xml"/>
                                </dbunit>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>dbunit</groupId>
                        <artifactId>dbunit</artifactId>
                        <version>2.1</version>
                    </dependency>
                </dependencies>
            </plugin>

Thanks,

Matt

P.S. Anyone know if a DbUnit plugin that's being developed for M2?
-- 
View this message in context: http://www.nabble.com/Does-anyone-know-how-to-use-the-maven-DBUnit-plugin--tf1857895.html#a5969492
Sent from the Maven - Users forum at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org