FileDocCategorySizeDatePackage
TestQName.javaAPI DocApache Axis 1.43786Sat Apr 22 18:57:28 BST 2006test.utils

TestQName

public class TestQName extends TestCase

Fields Summary
Constructors Summary
public TestQName(String name)

        super(name);
    
Methods Summary
protected voidsetup()

    
public static junit.framework.Testsuite()

        return new TestSuite(TestQName.class);
    
public voidtestEquals()

        QName qname1 = new QName("", "");
        QName qname2 = new QName("PREFIX", "LOCALPART");
        QName qname3 = new QName("PREFIX", "LOCALPART");
        QName qname4 = new QName("PREFIX", "DIFFLOCALPART");
        //need a fully implemented mock Element class...
        //Element elem = new MockElement();        
        ////QName qname5 = new QName("PREFIX:LOCALPART", elem);

        // the following should NOT throw a NullPointerException
        assertTrue("qname1 is the same as qname2", !qname1.equals(qname2));
       
        //Note: this test is comparing the same two QName objects as above, but
        //due to the order and the implementation of the QName.equals() method,
        //this test passes without incurring a NullPointerException. 
        assertTrue("qname2 is the same as qname1", !qname2.equals(qname1));

        assertTrue("qname2 is not the same as qname2", qname2.equals(qname3));
        assertTrue("qname3 is the same as qname4", !qname3.equals(qname4));
    
public voidtestHashCode()

        QName control = new QName("xsl", "text");
        QName compare = new QName("xsl", "text");
        QName contrast = new QName("xso", "text");
        assertEquals("control hashcode does not equal compare.hashcode", control.hashCode(), compare.hashCode());
        assertTrue("control hashcode is not equivalent to compare.hashcode", !(control.hashCode() == contrast.hashCode()));
    
public voidtestNullQname()

        QName qname1 = new QName("LOCALPART");
        QName qname2 = new QName(null, "LOCALPART");
        QName qname3 = new QName("", "LOCALPART");

        assertEquals("omitted namespace ", "LOCALPART", qname1.toString());
        assertEquals("null namespace ", "LOCALPART", qname2.toString());
        assertEquals("empty namespace ", "LOCALPART", qname3.toString());
    
public voidtestQName2StringConstructor()

        QName qname = new QName("rdf","article");
        assertNotNull("qname was null.  Something really wrong here.", qname); 
        assertEquals("Namespace URI was not 'rdf', it was: " + qname.getNamespaceURI(),
                     "rdf", qname.getNamespaceURI()); 
        assertEquals("LocalPart was not 'article', it was: " + qname.getLocalPart(),
                     "article", qname.getLocalPart()); 
    
public voidtestSerializable()

        QName q1 = new QName("Matthew", "Duftler");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);

        oos.writeObject(q1);
        oos.flush();
        oos.close();

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bais);
        QName q2 = (QName)ois.readObject();

        assertEquals("q1 is not the same as q2", q1, q2);
        assertEquals("q2 is not the same as q1", q2, q1);
    
public voidtestToString()

        QName qname = new QName("PREFIX", "LOCALPART");
        assertEquals("qname was not the same as '{PREFIX}LOCALPART', it was: " + qname.toString(),
                     "{PREFIX}LOCALPART", qname.toString());