java - Automatically creation of test databases using Maven -
i integrated postgresql first jax-rs project , wondering how can setup databases test application using maven. managed create database , tables need before test phase starts, not able fill tables test data. missing guide tells me how setup spozz_db_testdata.xml
file. know how add rows use primitive types string or integer, binary data?
any solution or tips help.
current spozz_db_testdata.xml
<?xml version='1.0' encoding='utf-8'?> <dataset> <avatars /> <users /> <spots /> <spot_revisions /> <spot_images /> <comments /> </dataset>
pom.xml
<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>net.avedo.spozz</groupid> <artifactid>spozz-webservice</artifactid> <version>0.0.1-snapshot</version> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <jetty.version>9.1.0.v20131115</jetty.version> <jersey.version>1.8</jersey.version> <junit.version>4.11</junit.version> <apache.commons.version>1.3.2</apache.commons.version> <apache.http.version>4.3.2</apache.http.version> <jsp.version>2.5</jsp.version> <maven.compiler.plugin.version>2.5.1</maven.compiler.plugin.version> <sql.maven.plugin.version>1.5</sql.maven.plugin.version> <postgresql.jdbc.version>9.1-901.jdbc4</postgresql.jdbc.version> </properties> <dependencies> ... <!-- postgresql --> <dependency> <groupid>postgresql</groupid> <artifactid>postgresql</artifactid> <version>${postgresql.jdbc.version}</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> ... <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>sql-maven-plugin</artifactid> <version>${sql.maven.plugin.version}</version> <dependencies> <!-- specify dependent jdbc driver here --> <dependency> <groupid>postgresql</groupid> <artifactid>postgresql</artifactid> <version>${postgresql.jdbc.version}</version> </dependency> </dependencies> <!-- common configuration shared executions --> <configuration> <driver>org.postgresql.driver</driver> <url>jdbc:postgresql://localhost:5432:spozz_db</url> <username>postgres</username> <password>root</password> <!-- can comment out username/password configurations , have maven them in settings.xml using ${settingskey} --> <settingskey>sensiblekey</settingskey> <!-- executions ignored if -dmaven.test.skip=true --> <skip>${maven.test.skip}</skip> </configuration> <executions> <execution> <id>drop-schema-before-test-if-any</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <!-- need database drop targeted 1 --> <url>jdbc:postgresql://localhost:5432:postgres</url> <autocommit>true</autocommit> <sqlcommand>drop schema spozz cascade</sqlcommand> <!-- ignore error when database not available --> <onerror>continue</onerror> </configuration> </execution> <execution> <id>create-schema</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <autocommit>true</autocommit> <srcfiles> <srcfile>src/main/sql/spozz-schema.sql</srcfile> </srcfiles> </configuration> </execution> </executions> </plugin> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>dbunit-maven-plugin</artifactid> <version>1.0-beta-3</version> <dependencies> <!-- specify dependent jdbc driver here --> <dependency> <groupid>postgresql</groupid> <artifactid>postgresql</artifactid> <version>${postgresql.jdbc.version}</version> </dependency> </dependencies> <!-- common configuration shared executions --> <configuration> <driver>org.postgresql.driver</driver> <url>jdbc:postgresql://localhost:5432:spozz_db</url> <username>postgres</username> <password>root</password> <!-- can comment out username/password configurations , have maven them in settings.xml using ${settingskey} --> <settingskey>sensiblekey</settingskey> <!-- executions ignored if -dmaven.test.skip=true --> <skip>${maven.test.skip}</skip> </configuration> <executions> <execution> <phase>test-compile</phase> <goals> <goal>operation</goal> </goals> <!-- specific configurations --> <configuration> <type>clean_insert</type> <src>src/test/resources/spozz_db_testdata.xml</src> </configuration> </execution> </executions> </plugin> ... </plugins> </build> </project>
Comments
Post a Comment