Unitils update – TestListeners

In a previous post I got some help from Tim Ducheyne to work out a way to use a spring wired DataSource with Unitils.  He mentioned a better way was coming…

Sometime back now they added the support for TestListener which solves this issue.

Unitils – TestListerer API

I don’t work with conventional databases much now, but was intrigued to see this post explaining how to extend unitils and use TestListeners to test ldap.  Neat eh!

Extending Unitils to test LDap.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

The power of XMLUnit with google Predicate

I have been interested in XMLUnit and google collections predicate system for awhile now and recently wrote the following as part of a test.  I have removed some of the test and left just the bits that illustrate this point.

The test needs to perform a check that the result of transforming some xml is correct.  A reference file is available so we can use XMLUnit to perform a difference.  In my file there is a seconds attribute and because seconds vary with each parse we choose to ignore the value.  There are other ways to achieve this, but its more complex and uses more XMLUnit code. Using a google predicate simplifies this check.

First produce your output file and load the sample and output into strings. Normally for a test I produce a smaller sample xml file. Then using XMLUnit difference engine get all differences.

    Diff d = new Diff(expectedAsString, outputAsString);
    DetailedDiff dd = new DetailedDiff(d);
    List listOfDifferences = dd.getAllDifferences();

Next call a function to check that the only differences found are within the seconds attribute. This uses a predicates from google to perform the matching.

    assertTrue(onlyDiffsMatchThisAttributeName("seconds",listOfDifferences));
    }

    private static boolean onlyDiffsMatchThisAttributeName(final String attrName, Iterable it) {

    Iterable filtered = Iterables.filter(it, new Predicate() {

        @Override
        public boolean apply(Difference input) {

                final NodeDetail testNodeDetail = input.getTestNodeDetail();
                if (nodeDetail == null) return false;

                final Node node = nodeDetail.getNode();
                if (node == null) return false;

                final String nodeName = node.getNodeName();
                if (nodeName == null) return false;

                return !nodeName.equals(attrName);
            }
        });
        return (newArrayList(filtered).isEmpty());
    }

Note that what is happening here is the predicate is filtering away all the seconds matches. If anything remains in the list false is returned. Neat huh! :-)

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

How to link unitils to a spring wired datasource

Unitils provides its own DataSource. This causes problems if you want to use Spring IOC to inject your own. There is a way around this but its not elegant. In future versions of unitils I believe the team is going to provide better support for less intrusive methods. This post documents a way to use your own spring defined DataSource.
Continue reading

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Unit Testing with a GigaSpaceFactoryBean

I was talking to Shay Banon (Gigaspace Software Architect) he mentioned using GigaSpaceFactoryBean for writing gigaspace unit tests. I could find no examples on their site, although I concede it may be there somewhere. This shows post shows a simple example.

He also mentioned using the admin api to do full end to end integration testing.  The admin api has huge potential as its able to control gigaspace containers, deploy into them and collect statistics.  Its a powerful api.

This is documented on their site: http://www.gigaspaces.com/wiki/display/XAP7/Administration+and+Monitoring+API
Continue reading

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)