Featured Post

The great debacle of healthcare.gov

This is the first time in history when the president of the United States of America, or probably for any head of state around the world,...

Friday, February 29, 2008

WebSphere Application Server

Websphere Application Server 5.1: Test Environment Setup

1. In Configure tab
  • Enable administration console
2. In Environment tab
  • Open Java VM Settings section add any system properties you want in your application like logger class or environment information (dev, sys or prod etc.)
3. In Variables tab
  • Open Node Settings
    • set the ORACLE_JDBC_DRIVER_PATH to jdbc driver jar location
4. In Security tab
  • Open JAAS Authentication
    • Add an alias: user-auth;
      • Username : <db-user>
      • Password : <password>
5. In DataSource tab
  • Open Server Settings section
    • In JDBC Provider List set
      • Oracle JDBC provider: Oracle Thin Driver;
      • Implementation Class: OracleConnecctionPoolDataSource
  • Define DataSource after choosing the just created Provider
    • Class path = {ORACLE_JDBC_DRIVER_PATH}/<jdbc-driver>.jar
    • Data source
      • 1st Screen
        • Oracle Thin Driver
      • 2nd Screen
        • Name: jdbc/MyDataSource
        • JNDI Name: jdbc/MyDataSource
        • Component Managed Auth Alias: user-auth
        • Container managed auth alias: user-auth
      • 3rd Screen
        • Port number: <oracle-port> note: default port is 1521
        • URL:jdbc:oracle:thin:@<db-host-name>:<port>:<schema-name>
6. Completed

Useful commands:

Check out the version of installed WAS in Solaris:

$[WAS Installed location]/bin/versionInfo.sh

Thursday, February 28, 2008

A Comparative analysis of Unit Testing in isolation

What I understand about Unit Testing can be expressed using this simple statement "Unit testing is all about the testing in isolation". And that makes the Unit Testing unique from the other form of testing like Integration Testing, Functional Testing or System Testing. I don't see any debate about the goal of Unit testing but when it comes to implementation of the testing and how to isolates the System Under Test (I followed Martin Fowlers naming conventions here) there are lots of differences in opinion and implementation technics. Lets start to talk about this by showing the components of a unit test-

  1. Unit test class, usually written in JUnit framework
  2. System Under Test (SUT), the targeted class that I'm gonna unit test and
  3. Collaborators classes, SUT interacts with those classes to accomplish it's goal

To implement the Unit testing in isolation, today I'll consider three popular approaches and will try to show the comparative advantages and disadvantages from a developer point of view. Those three popular approaches to achieve the isolation are:

  1. Point cut approach
  2. Stub approach
  3. Mock approach

Point cut approach uses the Aspect Oriented Programming (AOP) technique to implement the isolation. The principal behind this is, point cut the collaborator method calls from SUT and eventually return the expected outcome from the method. Usually an Advice class is written that point-cuts the method calls. The advantages of this approach are:

  • The SUT is unaware about the point cut and can be configured externally.
  • No mock or stub objects need to be written. etc.

The disadvantages are:

  • The test data (expected outcome) are stored not in the test class itself.
  • Becomes complicated when the point-cut advice needs to provide different response for different test cases.
  • The developer needs to be aware of multiple classes and files incase use xml as configuration for point-cut
  • Not possible to verify the behavior of the calls

Stub approach stub out the collaborator by injecting the Stubbed collaborators and hence isolate the SUT from having the real collaborators method calls to be invoked. The advantages of this approach are:

  • It isolates the SUT from each collaborators replacing with Stub versions hence makes it easy to understand and maintain
  • Don't bother about how the method has been implemented i.e. overlooks the implementation detail and looks for the outcome (it is known as state verification)

The disadvantages are:

  • It doesn't perform the behavior verifications

Mock approach is more like Stub approach and uses mock objects to isolate the SUT from the collaborators by injecting the Mock collaborator objects. The hallmark difference of Mock approach from the stub approach is that the Mock approach considers the behavior test as well. So the mock approach has all the benefits of Stub approach has and has also the ability to perform the behavior verifications though some people see this one as demerits.

Now see a simple testing implementation in Mock approach using a popular Mock Testing Framework, EasyMock.

public class SampleServiceTest extends TestCase {
private SampleDao daoMock;
private MockControl daoControl;

public static void main(String[] args) {

public void setUp() {
daoControl = MockControl.createControl(SampleDao.class);
daoMock = (SampleDao)daoControl.getMock();

public void testDeleteSampleData() {
SampleDataId dataId = new SampleDataId(1);
SampleData data = new SampleData(dataId);
SampleDataAudit audit = new SampleDataAudit(sampleData);


SampleService csi = new SampleService();

Monday, February 4, 2008

In Java: That I used to get confused


Overriding Access Modifier:
In overriding, the access modifier can allow more. i.e. If the access modifier is declared as protected in the parent, the child can only change it to public.

Hiding member method:
In case of class methods, if the child class declares the same class method with the same signature (that is the combination of method name, parameter number) then it is considered as the child hides the parent's method. In that scenario, the method actually invoked depends on from where the class method is being called.
Cat cat = new Cat();
Animal animal = cat;
The Animal.classMethod() will invoke the Parent's (Animal) and the Cat.classMethod() will invoke the Child's (Cat) implementation.
This is somewhat opposite in case of instance method overriding; the method gets invoked depends on the instance of the class.

Hiding member variable:
If the child uses any member variable of the name same as in parent class, even if the types are different, the field variable is considered to be hidden by the child. In this case super keyword needs to be used to access the parent 's member variable. This is known as field hiding.