value is not a valid option

Note to myself:

never forget to add equals and hashcode method when using a h:selectOneMenu and when making a double combo

or you will be having ‘value is not a valid option ‘ errors.


Unit testing seam application

I have worked on projects that uses Spring and unit testing with Spring was quite easy. Now I am working on Seam projects, so I wondered how can I do unit tests for my Repository classes with JPA.
I had some problems but here is a working environment in the end. ( it may have a few misunderstanding, I need to review it from the ref doc )

We have the regular src/main folder in our project.

under src/main, we have java and resources folder under as usual. I have jsut added the persistence.xml under resources/META-INF and it is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns=""

		<persistence-unit name="testUnit" transaction-type="RESOURCE_LOCAL">
			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
			<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/eniyiyemektest?charSet=utf-8"/>
			<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
			<property name="hibernate.connection.username" value="user"/>
			<property name="hibernate.connection.password" value="pass"/>
			<property name="" value="create"/>
			<property name="" value="true"/>


and that is it. My components.xml is in under resources folder also. And it is as :

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns=""

    <core:manager conversation-timeout="120000" 

	<!-- Persistence -->
    <transaction:entity-transaction entity-manager="#{entityManager}"/>
    <persistence:entity-manager-factory name="testUnit"/>
    <persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{testUnit}"/>

so I am ready to write my tests. under src/test/java/my/package I add this following test code.

public class UserRepositoryTest extends SeamTest{

public void testUserCreation() throws Exception{
new FacesRequest(){
protected void invokeApplication() throws Exception {
User user = new User();
user.setEmail( "" );
user.setPassword( "password" );
user.setFirstname( "firstname" );
user.setLastname( "lastname" );

Assert.assertNull( user.getId() );
UserRepository repo = (UserRepository) getInstance( "userRepository" );
Assert.assertNotNull( repo );

repo.create( user );

Assert.assertNotNull( user.getId() );


and that is it. Small important checks are:

  • Do not forget to extend from SeamTest class
  • Use testNG not junit, I don’t why but junit didn’t work
  • Use FacesRequest to run the tests, somwhow if you use ComponentTest class to run the tests ( which makes more sense also ) the transactions is not automatically done.