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)

The idea of non backward compatible Java?

I have not been blogging much, but I have been reading. Java is somewhat disappointing of late for various reasons.  Then I stumbled across this: the_next_big_jvm_language1 from Stephen Colebourne.  It seems like an interesting idea to me.  It would take some doing, but the advantages could be huge.  It could encompass some of the best ideas and leave behind some of the old ideas we still struggle to shrug off.

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)

Diary of a cloud backup – part 5 – Many Months Later

Several months ago now I posted a series of articles about offline backup.  Its a topic that more and more people are dealing with.  The realisation that you have many gigabytes of digital media that could easily be lost combined with better broadband is prompting a move to off-site backups.  So I posted up my exploration into backing up off-site.  Recently I have had a few people ask me if I am still happy with my final choice, crashplan.

Even my mum uses it!

I am very happy with the choice.  In the original posts I managed to setup three home machines, one Linux one windows and a mackbook.  Since then I added the iMac that I keep at my parents.  This is a sign of how easy crashplan is to maintain.  In a nutshell once you have set it up, you just forget about it.  This has to be one of the most important things about backing up.  It does not require any maintenance whatsoever.  This is encouraging when your several hundred miles away from one of the machines.  I can use the web to see if its backed up, and get alerts if a period goes by and it fails.  I just checked it now, 100% backed up today.

What else?

The backup client allows you to set how much bandwidth and CPU its allowed to use.  I use the default as I have never found it hogging either.  I am probably lucky that so far several backups on different machines have not started at the same time.  If it did its easily curable.

In summary

If you have anything worthwhile keeping, and want off-site backup – get a crashplan account.  If you have friends with space, use crashplan for free and backup to each others machines.  In fact do both!

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)

Building software with .NET dependencies in 2010

I come from a Java background. So over the last decade I have moved away from managing dependencies on projects using jars in shared folders. Most professional java programmers have used Maven or Ivy. Recently I looked at Groovy and Gradle.  All well and good.  What do programmers use for .NET, WPF and Silverlite?  I have been trying to find out and there are mixed opinions.  Some write scripts to copy .dll files, others rely on the Visual Studio solutions.  None of these solutions are scalable.  I found this project: npanday Has anyone used it on a large project?  I would love to hear your views or review.  What does microsoft do?  What do you do?

Please comment here I am very interested in hearing what other programmers do for .NET dependency management.

Links for the Java world of dependency management

http://maven.apache.org/

http://ant.apache.org/ivy/

http://www.gradle.org/

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)