JUnit Canonicalization (using XOM)

import java.io.*;
import nu.xom.*;
import nu.xom.canonical.*;
import junit.framework.Assert;

public class CanonicalAssert extends Assert {

    public void assertCanonicalEquals(Document expected, Document actual) {
        
        ByteArrayOutputStream expectedBytes = new ByteArrayOutputStream();
        ByteArrayOutputStream actualBytes = new ByteArrayOutputStream();
        
        try {
            Canonicalizer expectedCanonicalizer 
              = new Canonicalizer(expectedBytes);
            expectedCanonicalizer.write(expected);
            byte[] expectedArray = expectedBytes.toByteArray();
        
            Canonicalizer actualCanonicalizer 
              = new Canonicalizer(actualBytes);
            actualCanonicalizer.write(actual);
            byte[] actualArray = actualBytes.toByteArray();
            
            assertEquals(expectedArray.length, actualArray.length);
            for (int i = 0; i < expectedArray.length; i++) {
                assertEquals(expectedArray[i], actualArray[i]);
            }
        }
        catch (IOException ex) {
            fail("IOException while canonicalizing");
        }        
        
    }    

}

Previous | Next | Top | Cafe con Leche

Copyright 2005-2007 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 23, 2005