Friday, October 7, 2011

How to test primefaces component with JSFUnit2

As you may know JSFUnit 2.0.0.Beta 2 is Out!

After successfully execute the JSFUnit2 getting started example on jboss as7, i've triyed the the integration between JSFUnit and primefaces (since it's my favorite JSF components library ;-)
First i've included the primefaces library into my test war archive in the deployement method using MavenDependencyResolver (for further details see this blog entry)

If you do not use Maven you can just put the primefaces librairy in a lib folder under WEB-INF folder and add this line to the deployement method :

.addAsWebInfResource(new File("src/main/webapp/WEB-INF/lib/primefaces-2.2.jar"),"lib/primefaces-2.2.jar")

Second, i've modifed the index.xhtml as bellow:

After that i executed my mvn install but i got the error "PrimeFaces" is not defined... humm... may be primefaces resources wasn't injected ...

I've just added the "h:head" tag to the index.xhtml file and my test succed !!!!! witch means that the primefaces resources was included automatically and JSFUnit recognize it now ...

Note that the component test is based on components client ID, so be prudent on your component testing !!

For example if you want to test the calendar component by trying the the setValue method on your test class with the id you have gave to your p:calendar (), you get the error :

java.lang.IllegalArgumentException: This method can not be used on components of type com.gargoylesoftware.htmlunit.html.HtmlSpan

it's normal because the setValue is used for input field not for span ;-) so you should use setValue ("date_input", VALUE) instead of setValue("date",VALUE)
[Tips: you can use Firebug to inspect elements and see their client id]

I'm adding the full example for p:calendar here based on the getting starded example

Test page:

Test method:
public void testInitialPage(JSFServerSession server, JSFClientSession client)
throws IOException {

// Set the param and submit
String sDate = new Date().toString();
client.setValue("date_input", sDate);"submit_button");

// Assert that the greeting component is in the component tree and rendered
UIComponent greeting = server.findComponent("greeting");

// Test a managed bean using EL. We cheat and use the request object.

you can download the full example here

The test was done using primefaces2.2,JSF 2.0, JSFUnit2Beta2, Maven3, Jboss as7

Saturday, October 1, 2011

How to use Hibernate 3 as JPA provider in JBoss AS7

Jboss AS7 come with Hibernate 4 (even if it still in beta :-)! if you still use hibernate 3 as JPA provider in your application and you want to deploy it in Jboss AS7 ... you may know it's possible ... Humm yes you can do it just by creating a module for hibernate3 under your Jboss AS7 (how powerful server is !). So you just need to:

* Create a folder in AS7_HOME\modules\org\hibernate\3 for slot 3 to hold your hibernate 3 jars.

* Copy the hibernate 3 associated jars into this folder. For example:


* Create the AS7_HOME/modules/org/hibernate/3/module.xml file with contents :

That's it, your module now is available on your jboss 7 server, all you nedd to link it with your application is to add the followed property to your persistence unit :

Note the org.hibernate:3 on your property ;-)

Tuesday, September 27, 2011

How to use Shrinkwrap MavenDependencyResolver

If you use Maven to build your application and you want to test it with Arquillian, Be sure that you will be looking for a way to include some of your libraries (artifact) from Maven into your archive file (war, ear...).

In this article we show you how to use the Shrinkwrap MavenDependencyResolver to read artifact from pom file using the maven setting file.

For this purpose you just need to add your maven setting file in a folder mvn_settings under src/test/ressources and add this entry in your @Deployment method !


For further details about Resolver extension in ShrinkWrap, refer to:

Saturday, September 24, 2011

JSFUnit 2.0.0.Beta 2 is Out

The Beta 2 version for JSFUnit2 is available from the middle of this month (September) with a fully support for junit 4, JSF2 and Arquillian , for more details check this blog entry and the release note

Have a look at this related getting started example and enjoy it!!

Friday, September 23, 2011

How to configure Arquillian with a remote Jboss AS7

If you want to use Arquillian to connect and run against a remote(different JVM, different machine) running previous version of Jboss server, you need to use JNDI properties for that !

In Jboss AS 7, the file is not used... So If you have set the managementAddress configuration option to where the management api is bound, Arquillian should read out from the server (remote or local jvm/machine) where the ip_adress/port_number are bound.

All this configuration is done in the arquillian.xml file as bellow:


For JBoss AS 7.0.0.Final, you need to configure the jmx protocol used by adding:


under the container tag ...

Monday, August 29, 2011

How it's easy to configure ports in Jboss AS7

If you want to change/configure your ports server on Jboss AS7, all you need is to modify entries under socket-binding-group for standalone.xml and socket-binding-groups for domain.xml, for example in standalone.xml:

Very easiest way! doens't it ?

Sunday, August 28, 2011

Ldap Realm configuration on Jboss AS7

In Jboss 6 and lower the ldap Realm was configured in the login-config.xml file like :


On jboss 7 the ldap Realm configuration has a little changed, it become on the standalone.xml (or in domain.xml) as a security domain under :
As bellow:


Note that the xml parser has changed in Jboss 7, so you should convert every module-option tag so that the lowest level data element for the module-option tag was replaced by the attribute value= and the tag was converted to a self-closing tag, for example:



For our blog ldap directory, the wall configuration become :


needs to be changed to:

else ModuleClassLoader won't load the com.sun.jndi.ldap.LdapCtxFactory which is needed in ldap authentication modules, and obviously you ll need on classpath.