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

GOMGenereatorImplTest

public class GOMGenereatorImplTest extends TestCase

Fields Summary
private GOMGeneratorImpl
impl
Constructors Summary
Methods Summary
protected voidsetUp()

		this.impl = new GOMGeneratorImpl();
	
public voidtestGOMGeneratorImpl()

		this.impl = new GOMGeneratorImpl();
		assertEquals(GOMGenerator.LOCALNAME, this.impl.getLocalName());
		assertEquals(GOMGenerator.LOCALNAME, this.impl.getQname()
				.getLocalPart());
		assertEquals(GOMNamespace.ATOM_NS_URI, this.impl.getQname()
				.getNamespaceURI());
	
public voidtestProcessAttribute()

		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI, "uri"),
				"test");
		assertEquals("test", this.impl.getUri());
		try {
			this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI,
					"uri"), "test");
			fail("duplicated");
		} catch (GDataParseException e) {

		}
		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI,
				"version"), "test");
		assertEquals("test", this.impl.getGeneratorVersion());

		try {
			this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI,
					"version"), "test");
			fail("duplicated");
		} catch (GDataParseException e) {

		}

		// check call to super.processAttribute
		this.impl.processAttribute(new QName(GOMNamespace.XML_NS_URI, "base",
				GOMNamespace.XML_NS_PREFIX), "test");
		assertEquals("test", this.impl.xmlBase);

		try {
			this.impl.processAttribute(null, "test");
			fail("qname is null");
		} catch (IllegalArgumentException e) {
			// 
		}
		try {
			this.impl.processAttribute(new QName(GOMNamespace.XML_NS_URI,
					"base", GOMNamespace.XML_NS_PREFIX), null);
			fail("value is null");
		} catch (IllegalArgumentException e) {
			// 
		}

	
public voidtestProcessElementValue()

		this.impl.processElementValue("myGenerator");
		assertEquals("myGenerator", this.impl.getTextValue());

		try {
			this.impl.processElementValue("testme");
			fail("duplicated");

		} catch (GDataParseException e) {
			//
		}

	
public voidtestProcessEndElement()

		this.impl.processEndElement();
		{
			this.impl.setUri("some invalid uri");
			try {
				this.impl.processEndElement();
				fail("must be an absolute uri");
			} catch (GDataParseException e) {
				// 
			}

		}
		{
			this.impl.setUri("/uri");
			try {
				this.impl.processEndElement();
				fail("must be an absolute uri or xml:base must be set");
			} catch (GDataParseException e) {
				// 
			}

		}
		this.impl.xmlBase = "http://apache.org";
		this.impl.processEndElement();

		this.impl.xmlBase = null;
		this.impl.setUri("http://apache.org/uri");
		this.impl.processEndElement();
	
public voidtestWriteAtomOutput()

		{
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeAtomOutput(writer);
			assertEquals("<" + this.impl.getLocalName() + "/>", stW.toString());
		}

		{
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.setTextValue("Lucene");
			this.impl.writeAtomOutput(writer);
			assertEquals("<" + this.impl.getLocalName() + ">Lucene</"
					+ this.impl.getLocalName() + ">", stW.toString());
		}
		{
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.setUri("http://apache.org");
			this.impl.writeAtomOutput(writer);
			assertEquals("<" + this.impl.getLocalName()
					+ " uri=\"http://apache.org\">Lucene</"
					+ this.impl.getLocalName() + ">", stW.toString());
		}

		{
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.setGeneratorVersion("1");
			this.impl.writeAtomOutput(writer);
			assertEquals("<" + this.impl.getLocalName()
					+ " uri=\"http://apache.org\" version=\"1\">Lucene</"
					+ this.impl.getLocalName() + ">", stW.toString());
		}
	
public voidtestWriteRssOutput()

		{
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.setTextValue("Lucene");
			this.impl.writeRssOutput(writer);
			assertEquals("<" + this.impl.getLocalName() + ">Lucene</"
					+ this.impl.getLocalName() + ">", stW.toString());
		}

		{
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.setUri("http://apache.org");
			this.impl.setGeneratorVersion("1");
			this.impl.writeRssOutput(writer);
			assertEquals("<" + this.impl.getLocalName() + ">Lucene</"
					+ this.impl.getLocalName() + ">", stW.toString());
		}