-
1. Re: Preconfiguring embedded Glassfish
aslak May 25, 2010 11:58 AM (in response to pnizio)Thank you!
I don't know to much about GlassFish, but new in Alpha2 is container configuration. The GlassFish container can be pointed to a specific instanceRoot, in that instanceRoot you can put what ever you want. I would assume you could place your resources file there.
For the configuration options see http://docs.jboss.org/arquillian/reference/latest/en-US/html_single/#container.glassfish-embedded-30
and http://docs.jboss.org/arquillian/reference/latest/en-US/html_single/#containers.configuration for how to configure Arquillian.
This covers how it could be done pre Alpha2, but now you can use the Configuration instead of changing the DeployableContainer.
http://locrianmode.blogspot.com/2010/03/integration-testing-jpa-and-ejb-3-with.html
-
2. Re: Preconfiguring embedded Glassfish
alrubinger May 25, 2010 12:02 PM (in response to pnizio)I'm also curious about the GFv3 deployment vs. configuration mechanism. Is it possible to drop your "sun-resources.xml" somewhere inside of your JAR/WAR/EAR? Or deployed on its own, separately?
S,
ALR
-
3. Re: Preconfiguring embedded Glassfish
locrianmode May 25, 2010 11:38 PM (in response to pnizio)1 of 1 people found this helpfulHi Piotr,
Glassfish embedded/full will refer to a domain.xml file where can specify datasources, connection pools etc. that you can use for your tests.
1) Configure the test container by placing arquillian.xml in the root classpath (of your tests). Arquillian will build the configuration from this file instead of using the defaults. (applicable with trunk or Alpha2 versions, as Aslak mentioned)
Sample arquillian.xml
<?xml version="1.0"?> <arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:glassfish="urn:arq:org.jboss.arquillian.glassfish.embedded30"> <glassfish:container> <glassfish:bindPort>9090</glassfish:bindPort> <glassfish:instanceRoot>src/test/glassfish</glassfish:instanceRoot> <glassfish:autoDelete>false</glassfish:autoDelete> </glassfish:container> </arquillian>
2) You will want the embedded GlassFish container instance root to be at a fixed location so that you can setup your connection pools, jndi resources and other stuff in the domain.xml file e.g. src/test/glassfish/config/domain.xml (create folder manually if you have to) You can copy from your GlassFish installation e.g. ${glassfish}/glassfish/domains/domain1/config/domain.xml and edit where necessary.
Example section with the jndi datasource setup for a test database
<domain> <applications /> <resources> <jdbc-resource jndi-name="jdbc/helpdesk" pool-name="HelpdeskPool" object-type="user" enabled="true"/> <jdbc-connection-pool datasource-classname="org.h2.jdbcx.JdbcDataSource" name="HelpdeskPool" res-type="javax.sql.DataSource"> <property name="Password" value="helpdesk"/> <property name="User" value="helpdesk"/> <property name="serverName" value="localhost"/> <property name="DatabaseName" value="helpdesk"/> <property name="url" value="jdbc:h2:tcp://localhost/~/helpdesk"/> </jdbc-connection-pool> </resources> . . </domain>
Now, for example, you can refer to the test datasource e.g. jdbc/helpdesk from your persistence.xml
-
4. Re: Preconfiguring embedded Glassfish
pnizio May 26, 2010 6:30 AM (in response to locrianmode)Aslak, Iskandar > Thank you! That's exactly what I need and what Arquillian lacked in my opinion
Andrew > I recently did some research in this topic and it seems it is not possible for Glassfish to automatically configure resources from sun-resources.xml bundled in archive together with an app. At least I couldn't find it in the docs and my attempts of putting the file in META-INF inside a jar and deploying it failed (no resources were created). AFAIK the only reasons for keeping that file in a project are:
- facilitating resource creation using CLI ('asadmin create-resources' command)
- allowing the IDE <-> AppServer integration plugin to create resources before deploying the app (as it is done e.g. in NetBeans)
-
5. Re: Preconfiguring embedded Glassfish
aslak May 26, 2010 7:22 AM (in response to pnizio)Piotr Nizio wrote:
Aslak, Iskandar > Thank you! That's exactly what I need and what Arquillian lacked in my opinion
We have a couple of issues that should improve this:
-
6. Re: Preconfiguring embedded Glassfish
aslak May 26, 2010 8:17 AM (in response to aslak)If any of your guys are interested in contributing to Arquillian, this issue might be right up your alley.
https://jira.jboss.org/browse/ARQ-156
-
7. Re: Preconfiguring embedded Glassfish
dan.j.allen May 27, 2010 1:01 AM (in response to locrianmode) -
8. Re: Preconfiguring embedded Glassfish
meetoblivion May 30, 2010 11:34 AM (in response to dan.j.allen)so one question/request i've had is if it's at all possible to not put the domain.xml under source - e.g. whend oing the build have arquillian point to a location on the file system not necessarily on the classpath to make glassfish? What we'd end up doing is having an admin go in and create the necessary JMS/JDBC/JNDI resources and point to that during our builds. This would all be assuming that the build is local of course.
-
9. Re: Preconfiguring embedded Glassfish
aslak May 30, 2010 1:34 PM (in response to meetoblivion)If I understand you correctly, that is what the instanceRoot option gives you.
http://docs.jboss.org/arquillian/reference/latest/en-US/html_single/#container.glassfish-embedded-30
instanceRoot can be pointed to your GlassFish 3.0 install Domain folder, e.g, /opt/glassfish/domains/domain1
-
10. Re: Preconfiguring embedded Glassfish
locrianmode Jun 4, 2010 1:27 PM (in response to aslak)Gave it a go
Profile for JUnit and TestNG examples. For TestNG, bsh.jar needs to be included in GlassFish e.g. ${glassfish}/glassfish/domains/domain/lib
<profile> <id>glassfish-remote-30</id> <dependencies> <dependency> <groupId>org.jboss.arquillian.container</groupId> <artifactId>arquillian-glassfish-remote-30</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>org.jboss.ejb3</groupId> <artifactId>jboss-ejb3-api</artifactId> <version>3.1.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <!-- JUnit examples--> <include>com/acme/ejb/*</include> <include>com/acme/ejb31/*</include> <include>com/acme/cdi/*</include> <include>com/acme/cdi/payment/*</include> <include>com/acme/cdi/random/*</include> <include>com/acme/web/*</include> <!-- TestNG examples --> <!-- <include>com/acme/ejb/*</include> <include>com/acme/cdi/*</include> <include>com/acme/cdi/payment/*</include> <include>com/acme/jpa/*</include> --> </includes> </configuration> </plugin> </plugins> </build> </profile>
-
glassfish-remote-30.zip 22.5 KB
-
-
11. Re: Preconfiguring embedded Glassfish
aslak Jun 5, 2010 11:11 AM (in response to locrianmode)Excellent Iskandar!
Reviewing the patch, and will get it in for Alpha-3
-
12. Re: Preconfiguring embedded Glassfish
dan.j.allen Jun 7, 2010 1:28 PM (in response to aslak)Better yet, with my latest patch on ARQ-156, you can now supply a sun-resources.xml file that will be passed to the add-resources asadmin command before the Embedded GlassFish instance is started. So you can work with a fresh instance and still get all the JMS/JDBC/JNDI resources you want!
Here's a preview, starting with the Arquillian configuration:
<arquillian xmlns="http://jboss.com/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gf="urn:arq:org.jboss.arquillian.glassfish.embedded30"> <gf:container> <gf:resourcesXml>src/test/resources/sun-resources.xml</gf:resourcesXml> </gf:container> </arquillian>
Here is the sun-resources.xml file that configures an embedded Derby instance named jdbc/tests:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_4.dtd"> <resources> <jdbc-resource pool-name="TestsEmbeddedDerbyPool" jndi-name="jdbc/tests"/> <jdbc-connection-pool name="TestsEmbeddedDerbyPool" res-type="javax.sql.DataSource" datasource-classname="org.apache.derby.jdbc.EmbeddedDataSource" is-isolation-level-guaranteed="false"> <property name="databaseName" value="target/databases/derby"/> <property name="createDatabase" value="create"/> </jdbc-connection-pool> </resources>
If you add a JDBC driver to your test classpath, such as H2, you have the option of using it instead of embedded Derby:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_4.dtd"> <resources> <jdbc-resource pool-name="TestsEmbeddedH2Pool" jndi-name="jdbc/tests"/> <jdbc-connection-pool name="TestsEmbeddedH2Pool" res-type="javax.sql.DataSource" datasource-classname="org.h2.jdbcx.JdbcDataSource"> <property name="user" value="sa"/> <property name="password" value=""/> <property name="url" value="jdbc:h2:file:target/databases/h2/db"/> </jdbc-connection-pool> </resources>
Excited for Alpha3 yet?
-
13. Re: Preconfiguring embedded Glassfish
locrianmode Jun 8, 2010 12:30 AM (in response to dan.j.allen)Testing with GlassFish containers made cleaner. This is neat!
Really looking forward to Alpha3 -
14. Re: Preconfiguring embedded Glassfish
dan.j.allen Jun 8, 2010 12:31 AM (in response to locrianmode)Indeed! I'm working to ensure that regardless of what container you are targeting, there is an easy way to configure resources. I'm working on a tutorial that will cover JBoss AS as well.
I'm also hoping that the JSR 88 container is a foot in the door for other containers to be supported (hint, WebLogic). While there is a benefit to using something more advanced than JSR 88, it gets the job done.