Thursday, August 27, 2009

Map boolean in Hibernate

How can you map Y/N in database as boolean in Java with Hibernate?

1. Java
private boolean trainingOnly;
// getters and setters

2. DB
training_only VARCHAR(1) DEFAULT 'N',

3. hbm.xml
<property name="trainingOnly" type="yes_no">
<column name="training_only" length="1" />
</property>

Monday, August 24, 2009

Increase Selenium timeout value

I am testing a slow loading page with Selenium (html recorded by Selenium IDE) but it always fails due to timeout. The default timeout value is 300000, i.e., 30 seconds. I know, I know - it is plenty of time and something needs to be done to that page. The question here, however, is how to increase Selenium's timeout to get the test passed.

I can specify the timeout value at the beginning of the html script like

<tr>
<td>setTimeout</td>
<td>600000</td>
<td></td>
</tr>

Now the test passed happily.

Friday, August 21, 2009

Spring test & JUnit

Spring 2.5.x works with JUnit 4.4 but not JUnit 4.5+. You will run into org/junit/Assume$AssumptionViolatedException. This was fixed in Spring 3.0.

http://jira.springframework.org/browse/SPR-5145

Maven test resources

In a Maven project, it is recommended that you keep your test resources in src/test/resources, separate from src/main/resources. However, a lot of times, or most of the time, the resources are pretty much the same, such as service.xml, dao.xml, log4j.properties etc. When you work on a new DAO in TDD fashion, you would add the definition in src/test/dao.xml first and copy it to src/main/dao.xml once it works as expected. It becomes a hassle to maintain both places. I would say why not share the main resources with test. You can do it literally this way: tell test to use main as resouces.

<testResources>
<testResource>
<filtering>false</filtering>
<directory>src/mail/resources</directory>
</testResource>
</testResources>

Spring ContextLoaderListener ClassNotFoundException

I ran a Java web application with Maven, Tomcat in Eclipse. When the application started, Eclipse console has the exception:
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Of course, I did not forget to define Spring dependency in Maven pom.xml. But when I checked the deployment at
ECLIPSE_WORKSPACE\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\APPLICATION\WEB-INF\lib
, there was no Jar indeed. So it looked like something went wrong with Eclipse/Tomcat/Maven deployment.

I did a couple of things to make it work.
1. Get rid of duplicated classes. For example, the dependency on spring-aspects also brings in spring-beans and spring-core, which are already part of spring dependency. Tip: use "mvn dependency:tree" to the dependency tree. So I need to exclcude it by
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>2.5.6</version>
<!-- exclude spring-beans which is part of spring-2.5.6.jar -->
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
2. Right click project > Maven > Update Project Configuration. Disable and re-enable Maven dependency management if necessary.

Now I found all the required jars in the right place. I started the application and no error!

This seems to be a glitch with Eclipse Maven plugin. I need to keep an eye on it.

Thursday, July 30, 2009

Search Documentum including old version

A document in documentum is versioned. By default, documentum only searches the current version of documents. To include old version, add (all) in the query like this example.

select * from opp_assessment(all)
where ref_doc_num = '0919999980028b06'

Wednesday, July 22, 2009

Escape in JSTL XML tag

In JSTL XML tag, if the data has characters like "<", it will be escaped by default. To turn it off, set escapeXml to false.

<x:out select="$n/STATUS" escapeXml="false" />