First thing is to configure the pom.xml for the Arquillian and Glassfish Embedded dependencies :
1. Add versioning as a property, i've used Arquillian 1.0.0.CR5.
- <properties>
- <arquillian.version>1.0.0.CR5</arquillian.version>
- </properties>
2. we need following dependencies :
- org.jboss.arquillian.junit
- org.jboss.shrinkwrap
- <dependency>
- <groupId>org.jboss.arquillian.junit</groupId>
- <artifactId>arquillian-junit-container</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-api</artifactId>
- <scope>test</scope>
- </dependency>
3. we need also the dependencies for embedded glassfish, therefore i have created a profile :
- <profile>
- <id>glassfish-embedded-3</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <dependencies>
- <dependency>
- <groupId>org.jboss.arquillian.container</groupId>
- <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
- <version>1.0.0.Final-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.glassfish.extras</groupId>
- <artifactId>glassfish-embedded-all</artifactId>
- <version>3.2-b06</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- </profile>
As repository for the dependencies i've used JBOSS public repository:
- <repository>
- <id>JBOSS_NEXUS</id>
- <url>http://repository.jboss.org/nexus/content/groups/public</url>
- </repository>
And we are now able to run Arquillian tests, but before running our first tests we should configure arquillian.xml described as below.
We need to define a container as default on arquillian.xml, my configuration file look like :
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <arquillian xmlns="http://www.jboss.org/arquillian-1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.jboss.org/arquillian-1.0 http://jboss.org/schema/arquillian/arquillian-1.0.xsd">
- <engine>
- <property name="deploymentExportPath">target/</property>
- </engine>
- <container qualifier="glassfish" default="true">
- <configuration>
- <property name="configurationXml">file:src/test/resources/domain.xml</property>
- <property name="bindHttpPort">18080</property>
- </configuration>
- </container>
- </arquillian>
<property name="configurationXml">file:src/test/resources/domain.xml</property>
This property is needed to configure domain.xml for embedded glassfish another way may be to define the path of the sun-resources.xml.
Next step is creating/copying the domain.xml for embedded glassfish, i've copied the domain.xml from my own glassfish. But be sure, that you have configured a http-listener, otherwise you will get an error.
I've changed my http-listener-1 port to 18080, if you don't change it, you can remove this tag and arquillian uses the default port. But i recommend to change this post on your domain.xml, because it may conflict with other services.
After configuring the arquillian.xml, we need to configure our domain.xml, you can find more details about this configuration file on glassfish homepage, but as a sample, i will put my configuration file,
http://pastebin.com/83Zm4PnK
I've created a data source using HSQLDB on my domain.xml :
- <resources>
- <jdbc-resource pool-name="HsqldbPool" jndi-name="jdbc/sample" object-type="user" enabled="true"/>
- <jdbc-connection-pool is-isolation-level-guaranteed="false" name="HsqldbPool" driver-classname="org.hsqldb.jdbcDriver" res-type="java.sql.Driver">
- <property value="9001" name="PortNumber" />
- <property value="" name="Password" />
- <property value="sa" name="User" />
- <property value="localhost" name="serverName" />
- <property value="jdbc:hsqldb:mem:foobar" name="URL" />
- </jdbc-connection-pool>
- </resources>
and added it to the servers
- <server name="server" config-ref="server-config">
- <resource-ref ref="jdbc/sample" />
- </server>
and renamed http-listener-2 to http-listener to get a http-listener, my network-listener configuration on domain.xml:
- <network-listeners>
- <network-listener port="18080" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool" />
- <network-listener port="13478" protocol="http-listener" transport="tcp" name="http-listener" thread-pool="http-thread-pool" />
- <network-listener port="14848" protocol="admin-listener" transport="tcp" name="admin-listener" thread-pool="http-thread-pool" />
- </network-listeners>
And we should configure our persistence.xml on META-INF/persistence.xml, if it doesn't exist, you can create it :
- <?xml version="1.0" encoding="UTF-8"?>
- <persistence version="1.0"
- xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://java.sun.com/xml/ns/persistence
- http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
- <persistence-unit name="sample" transaction-type="JTA">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <jta-data-source>jdbc/sample</jta-data-source>
- <class>com.citecompany.model.User</class>
- <class>com.citecompany.model.ScheduledTime</class>
- <properties>
- <property name="hibernate.hbm2ddl.auto" value="create-drop" />
- <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
- <property name="hibernate.show_sql" value="true" />
- </properties>
- </persistence-unit>
- </persistence>
As you remember we are created a data-source named "jdbc/sample", we are using it for our data source.
Ready to go :) Our project is ready to run Arquillian tests, next step will be creating a JPA based Testing.
Keine Kommentare:
Kommentar veröffentlichen