A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Sample XMLUnit test class

import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import java.util.HashMap;
import org.custommonkey.xmlunit.*;

public class MyTest extends XMLTestCase {
    private HttpClient client;
    private String pageTitle = "something";
  
    protected void setUp() {
         client = new HttpClient();        
        // declare XML namespaces
        HashMap m = new HashMap();
        m.put("agg", "http://www.bbc.co.uk/aggregation/1.0");
        m.put("atom", "http://www.w3.org/2005/Atom");
        NamespaceContext ctx = new SimpleNamespaceContext(m);
        XMLUnit.setXpathNamespaceContext(ctx);
    }

    public void testVersion() throws Exception {
        String pageXML = getXML("http://example.com/version");
        assertXpathEvaluatesTo("2010-07-29", "/version/release-date", pageXML);
    }
  
    public void testTitle() throws Exception {
        String pageXML = getXML("http://example.com/test");
        assertXpathEvaluatesTo("items about "+pageTitle, "/agg:page//atom:feed/atom:title[1]", pageXML);
    }
  
     private String getXML(String uri) throws IOException {
        GetMethod method = new GetMethod(uri);
        int statusCode = client.executeMethod(method);
        assertEquals("HTTP GET " + uri, HttpStatus.SC_OK, statusCode); // 200 OK
        return method.getResponseBodyAsString();
     }

     public void TearDown() {
     }

}