Dec 23 2011

Using TestNG to write a Data-Driven test that depends on the output of another Data-Driven test

Category: java,open source,testUlrich Palha @ 3:50 pm

Testing Requirements

I have a number of web services that return a status code and an XML payload. For each of these web services, I would like to write tests that meet the following criteria:

  1. Test requirements
    1. Verify that the web service returns the correct status code based on the inputs (testWebserviceStatus)
    2. If the status code is correct, then I would like to verify 1 or more properties of the payload. Every property is independent, so I would like to have each property verification run as a separate test (testWebserviceProperties)
  2. Other requrements
    1. The ability to add/remove the list of web services to test and add/remove the list of properties to verify for each service without updating the test code.
    2. If testWebServiceStatus fails, then its associated testWebserviceProperties should be skipped
    3. The test report should clearly show the success failure of each testWebservice/testWebserviceProperty test along with the web service/property that was being tested

Continue reading “Using TestNG to write a Data-Driven test that depends on the output of another Data-Driven test”

Tags: , , , , ,


Dec 16 2011

Java library performance optimzation using local references to final members: should you use it?

Category: javaUlrich Palha @ 9:37 am

Mysterious java idiom

While I was browsing through the java.util.concurrent source code, I noticed widespread use of the following idiom

    private final ReentrantLock mainLock = new ReentrantLock();
        ...
        //local reference to final member variable
        final ReentrantLock mainLock = this.mainLock; 
        mainLock.lock(); 
        try {
            ...     
        } finally {
            mainLock.unlock();
    }

Given that member mainLock is final, I could not understand the benefit of declaring a local reference. Continue reading “Java library performance optimzation using local references to final members: should you use it?”

Tags: , , ,


Dec 09 2011

HTML Parsers and other libraries: don’t write your own till you know, and have tested, what already exists

Category: java,open sourceUlrich Palha @ 3:53 pm

It seemed simple…

I needed to extract some HTML content for one of the projects I was working on. It seemed easy enough to retrieve the content and parse out the title tag, so I quickly threw together the following code to retrieve the title tag. Continue reading “HTML Parsers and other libraries: don’t write your own till you know, and have tested, what already exists”

Tags: , , ,


Nov 19 2011

How to run your Java application as a windows service using Commons Daemon Procrun

Category: javaUlrich Palha @ 1:40 am

Overview

Apache Commons Daemon is made of 2 parts. One written in C that makes the interface to the operating system and the other in Java that provides the Daemon API. Both Win32 and UNIX like platforms are supported, but for this article I will only focus on the former and show you how to use Procrun to run your java application as a windows service.

Prerequisites

If  you want to run the sample application, you will need Java 6 and Maven installed. GIT is also recommended.
Continue reading “How to run your Java application as a windows service using Commons Daemon Procrun”

Tags: , ,