Sunday, June 14, 2009

Using MySQL connection pool in Glassfish V3

I tried with a simple data source in Spring, but it isn't meant for production environments. So I wanted to move from:

<bean id="simpleDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/database"/>
<property name="username" value="database"/>
<property name="password" value="s3cr3t"/>
</bean>

to:

<bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/databasePool" />
</bean>

where jdbc/databasePool is configured in Glassfish. The reason for this is that the connection handling is a lot better when using a proper connection pool.

First we need to install the mysql library in Glassfish. I use Ubuntu so:

sudo apt-get install libmysql-java

then I linked it into the Glassfish classpath:

sudo -u glassfish ln -s /usr/share/java/mysql.jar /opt/glassfishv3-prelude/glassfish/lib/mysql.jar

If you don't use the Ubuntu just add the mysql.jar to the /opt/glassfishv3-prelude/glassfish/lib folder.

Then restart the server to get it added to the classpath. (Look at my previous post for further instructions.)

Then install the connection-pool:

./asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlDataSource --allownoncomponentcallers=true --property user=database:password=s3cr3t:DatabaseName=database:ServerName=localhost:port=3306 database-pool

The --allownoncomponentcallers=true parameter is important to let Spring access the resource directly.

Test the connection:

./asadmin ping-connection-pool database-pool

To make it avaliable to the spring configuration:

./asadmin create-jdbc-resource --connectionpoolid database-pool jdbc/databasePool

That's it! Good luck!

Friday, May 22, 2009

Installing Glassfish V3 on Ubuntu

I've been using Tomcat for some time but I'd like to use Glassfish V3 instead as I think it's (going to be) an amazing application server. This is a tutorial based on how I installed it on Ubuntu 9.04 Jaunty Jackalope.


If you haven't install JDK6 do that first.
sudo apt-get install sun-java6-jdk
Get glassfish (I use the zip file as the sh file didn't complete the download).
wget http://download.java.net/glassfish/v3-prelude/release/glassfish-v3-prelude.zip
Unziping glassfish (I didn't have unzip so I installed it first by running: sudo apt-get install unzip )
sudo unzip glassfish-v3-prelude.zip
Move it to the opt folder
sudo mv glassfishv3-prelude /opt
First add a glassfish system user
sudo useradd --system glassfish -d /opt/glassfishv3-prelude
Set admin group
sudo chgrp -R admin /opt/glassfishv3-prelude
Set glassfish as the owner
sudo chown -R glassfish glassfishv3-prelude
Go into the install directory
cd glassfishv3-prelude
Set the executable files:
sudo chmod -R +x bin/ sudo chmod -R +x glassfish/bin/
Start the default glassfish domain (domain1)
sudo -u glassfish bin/asadmin start-domain domain1
To have Glassfish start automatically when you start Ubuntu. You need to add a glassfish file to the /etc/init.d/ folder. Pick you favorite editor (I use vim).
sudo vim /etc/init.d/glassfish
Enter the following:
#! /bin/sh

GLASSFISHPATH=/opt/glassfishv3-prelude/bin

case "$1" in
start)
echo "starting glassfish from $GLASSFISHPATH"
sudo -u glassfish $GLASSFISHPATH/asadmin start-domain domain1
;;
restart)
$0 stop
$0 start
;;
stop)
echo "stopping glassfish from $GLASSFISHPATH"
sudo -u glassfish $GLASSFISHPATH/asadmin stop-domain domain1
;;
*)
echo $"usage: $0 {start|stop|restart}"
exit 3
;;
esac
:

Changing the users rights
sudo chmod a+x /etc/init.d/glassfish
Then install it on all runlevels:
sudo update-rc.d glassfish defaults
That is it! I hope this tutorial was helpfull.

I got help from all around the world to complete this tutorial but special thanks to computing with jasper.

Wednesday, June 25, 2008

concordion:run

I just became a committer at Concordion.org and I'm really happy for the confidence.

The basic questions: What have I committed?

The answer is: concordion:run which is a way to run another Concordion testes form this test. An example (would be handy right about now):

check this test

code:

<html>...<body> ... <a href="checkThis.html" concordion:run="concordion">check this test</a> ... </body></html>

This test will run the "checkThis.html" concordion test.

You might think that it doesn't matter what you put in attribute value. That it's just there for completeness and the story would end there, but that’s not the case.

One to rule them all

I think that a lot of people have invested a lot of time and effort in learning other frameworks like FIT, CubicTest and so on. So why can’t we just write Concordion tests like this:

Given users in the database when Bob logs in with password "password" and changes password to "secret" then the password is "secret".

code:

<html>
...
<body>
...
<p>
<a href="../fit/userSetup.html" concordion:run="fit">Given users in the database </a>
when <span concordion:set="#user">Bob</span> <a href="../cubictest/login.aat" concordion:run="cubictest">logs in</a> with password "<span concordion:set="#password">password</span>"
and <a href="../cubictest/changePassword.aat"
concordion:run="cubictest">changes password </a> to "<span concordion:set="#newpassword">secret</span>" then the password is "<span concordion:assertEquals="passwordFor(#user)">secret</span>".
</p>
...
</body>
</html>

I've just used FIT to set up the database as I had that functionality in a fit test already, then I used concordion to set what user to log in with in CubicTest and changed the username with CubicTest before I used Concordion to check the database to see if the new password was set. The functionality isn’t there yet, but it’s coming.

Saturday, June 14, 2008

CubicTest 1.8.6 is just released

The vision of CubicTest is to be the leading functional Web Testing IDE. The 1.8.6 release is a great step towards that vision.

There are a lot of different functional web testing frameworks out there but CubicTest stands out. What truly makes CubicTest different is its ability to clearly communicate web interaction to a wide variety of stakeholders. You don’t have to be a programmer to understand CubicTest as it focuses on testing "what you see" on the page, and not "testing the HTML source". It strongly supports principles like DRY and test first. DRY or Don’t Repeat Yourself is made easy with features like “Commons”, parameterization and abstraction through subtests. CubicTest was designed to be used with test first methodologies with features like graphical modeling and html export.

CubicTest uses the power of outstanding frameworks like Selenium and Watir to drive the tests but in a graphical way which make these frameworks easier to understand and use. Prior to the 1.8.6 release CubicTest users haven’t been able to use the full power of Selenium. Now that is changed and in the near future it will change for Watir as well. The new “Custom Test Step” feature enables that functionality.

The new features in the CubicTest 1.8.6 release:

  • Support for frames – now you may model frames in the graphical test editor
  • Internationalization support – one test may be launched with different languages to make it easy to support multilingual web sites
  • Custom test steps with debug possibilities – now CubicTest isn’t limited to only the elements and possibilities in the editing palette but to the limitation in the underlying test framework like Selenium and Watir
  • Capturing HTML and image of failing test page – whenever a test fails in the new launcher CubicTest records the HTML source code and take a screenshot

I hope you like it!

Monday, May 5, 2008

SpecTool 2.0 - solutions

I think that there are two ways to specify a requirement that can be executed by a computer. First we got a natural API or we got the XHTML way.

API

To use an API for specification requires a DSL(Domain Specific Language) and a natural language interface for nontechnical persons to understand what is going on. At least without being thought how it works. The advantage is that it is code. It makes it a lot easier to use for programmers. Most IDEs (like eclipse) will report syntax errors and got good refactoring support which is an advantage.

For this kind of tests I think that we have (most of) the technology that we need. I think that the main focus should be in establishing good patterns and give better understanding.

XHTML

To write specifications in xhtml gives a lot of flexibility in presentation. It is possible to use tables (frameworks like FIT, Concordion), plain text (Concordion) or what ever that fits the problem. This requires fixtures on different frameworks to bridge the gap between specifications and code. This abstraction is good in the sence that it keeps specifications "stable" despite changes in the domain model. I think that this is good.

The problem with tools like Concordion and FIT is that they don't work well together. I think that having a framework that is an umbrella framework to the current frameworks is the way to go. So I can use FIT for some database setup and runt the webtests in CubicTest and do some checks in Concordion. I should be able take some data from one of the frameworks over to another to make these work seamleasly together. The umbrella framework should also support the ide of tags to support the ide of structuring the sepecifications.

Sunday, April 6, 2008

10 ways to screw up with Scrum and XP

Henrik Kniberg has published his slides from the 10 ways to screw up with Scrum and XP presentation he held at JavaForum conference in Malmö. I wasn't there but the slides are excelent. I hope you enjoy them as much as I do!

Sunday, March 30, 2008

Agile means that tests are second class citizens

The Agile Manifesto states working software over comprehensive documentation. Working software is what the customer really wants and will always be the first class citizen in agile methodologies. Your tests is part of your documentation (at least to some extent). Hence tests are second class citizens.

By the way I would not like to develop software without tests.