FileDocCategorySizeDatePackage
ArbitraryGOMXmlTest.javaAPI DocApache Lucene 2.1.05240Wed Feb 14 10:45:58 GMT 2007org.apache.lucene.gdata.gom.core

ArbitraryGOMXmlTest

public class ArbitraryGOMXmlTest extends TestCase
author
Simon Willnauer

Fields Summary
private ArbitraryGOMXml
arbXML
private QName
name
Constructors Summary
Methods Summary
protected voidsetUp()


	     
		super.setUp();

		arbXML = new ArbitraryGOMXml(name);
	
protected voidtearDown()

		super.tearDown();
	
public voidtestArbitraryGOMXml()

		try {
			new ArbitraryGOMXml(null);
			fail("qname is null");
		} catch (IllegalArgumentException e) {

		}
		ArbitraryGOMXml xml = new ArbitraryGOMXml(name);
		assertEquals(name, xml.getQname());
		assertEquals(name.getLocalPart(), xml.getLocalName());
	
public voidtestGetChildParser()


		try {
			this.arbXML.getChildParser(null);
			fail("qname is null");
		} catch (GDataParseException e) {
			assertEquals(0, this.arbXML.getChildren().size());
		}
		AtomParser childParser = this.arbXML.getChildParser(this.name);
		assertTrue(childParser instanceof ArbitraryGOMXml);

		assertEquals(name, ((ArbitraryGOMXml) childParser).getQname());
		assertEquals(name.getLocalPart(), ((ArbitraryGOMXml) childParser)
				.getLocalName());
		assertEquals(1, this.arbXML.getChildren().size());
	
public voidtestProcessAttribute()

		try {
			this.arbXML.processAttribute(null, "test");
			fail("qname is null");

		} catch (GDataParseException e) {
			assertTrue(this.arbXML.getAttributes().size() == 0);
		}
		this.arbXML.processAttribute(name, "testme");
		{
			List<GOMAttribute> attributes = this.arbXML.getAttributes();
			assertTrue(attributes.size() == 1);
			GOMAttribute attribute = attributes.get(0);
			assertNotNull(attribute);
			assertEquals(name, attribute.getQname());
			assertEquals(name.getLocalPart(), attribute.getLocalName());
			assertEquals("testme", attribute.getTextValue());
		}

		{
			this.arbXML.processAttribute(name, null);
			List<GOMAttribute> attributes = this.arbXML.getAttributes();
			assertTrue(attributes.size() == 2);
			GOMAttribute attribute = attributes.get(1);
			assertNotNull(attribute);
			assertEquals(name, attribute.getQname());
			assertEquals(name.getLocalPart(), attribute.getLocalName());
			assertEquals("", attribute.getTextValue());
		}
	
public voidtestProcessElementValue()

		try {
			this.arbXML.processElementValue(null);
			fail("name is null");
		} catch (GDataParseException e) {
			// 
		}
		this.arbXML.processElementValue("test value");

		try {
			this.arbXML.processElementValue("test value");
			fail("value is already set");
		} catch (GDataParseException e) {
			//
		}
		assertEquals("test value", this.arbXML.getTextValue());

	
public voidtestWriteAtomOutput()

		{
			StringWriter writer = new StringWriter();
			GOMOutputWriter w = new GOMStaxWriter(writer);
			this.arbXML.writeAtomOutput(w);
			assertNotNull(w.toString());
			assertEquals("<" + this.name.getLocalPart() + "/>", writer
					.toString());
		}
		try {
			this.arbXML.writeAtomOutput(null);
			fail("writer is null");

		} catch (NullPointerException e) {
			// 
		}
		{
			this.arbXML.processAttribute(name, "testme1");
			this.arbXML.processElementValue("testme2");
			StringWriter writer = new StringWriter();
			GOMOutputWriter w = new GOMStaxWriter(writer);
			this.arbXML.writeAtomOutput(w);
			assertEquals("<" + this.name.getLocalPart()
					+ " testme=\"testme1\">" + "testme2" + "</"
					+ this.name.getLocalPart() + ">", writer.toString());
		}