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

GOMCategoryTest

public class GOMCategoryTest extends TestCase
author
Simon Willnauer

Fields Summary
private QName
qname
GOMCategoryImpl
cat
Constructors Summary
Methods Summary
protected voidsetUp()


	     
		this.cat = new GOMCategoryImpl();
	
protected voidtearDown()

		super.tearDown();
	
public voidtestProcessAttribute()

		try {
			this.cat.processAttribute(null, "test");
			fail("qname is null");
		} catch (GDataParseException e) {
			// 
		}
		{
			QName name = new QName("term");
			this.cat.processAttribute(name, "helloworld");
			assertEquals("helloworld", this.cat.getTerm());

			try {
				this.cat.processAttribute(name, "helloworld");
				fail("duplicated attribute");
			} catch (GDataParseException e) {
				// 
			}
		}

		{
			QName name = new QName("scheme");
			this.cat.processAttribute(name, "helloworld1");
			assertEquals("helloworld1", this.cat.getScheme());

			try {
				this.cat.processAttribute(name, "helloworld1");
				fail("duplicated attribute");
			} catch (GDataParseException e) {
				// 
			}
		}

		{
			QName name = new QName("label");
			this.cat.processAttribute(name, "John Cleese");
			assertEquals("John Cleese", this.cat.getLabel());

			try {
				this.cat.processAttribute(name, "John Cleese");
				fail("duplicated attribute");
			} catch (GDataParseException e) {
				// 
			}
		}

	
public voidtestProcessElementValue()

		try {
			this.cat.processElementValue(null);
			fail("element value is null");
		} catch (GDataParseException e) {
			// 
		}

		try {
			this.cat.processElementValue("and again");
			fail("can't contain a text value");
		} catch (GDataParseException e) {
			//
			assertNull(this.cat.getTextValue());
		}

	
public voidtestProcessEndElement()

		try {
			this.cat.processEndElement();
			fail("term is not set");
		} catch (GDataParseException e) {
			// 
		}
		this.cat.setTerm("my Term");
		this.cat.processEndElement();
		this.cat.setScheme("test");

		try {
			this.cat.processEndElement();
			fail("scheme is not a absoulte uri");
		} catch (GDataParseException e) {
			// 
		}

		this.cat.setScheme("/test");

		try {
			this.cat.processEndElement();
			fail("scheme is not a absoulte uri and no xmlbase is set");
		} catch (GDataParseException e) {
			// 
		}
		{
			this.cat.xmlBase = "http://www.apache.org";
			this.cat.processEndElement();
		}

		{
			this.cat.xmlBase = null;
			this.cat.setScheme("http://www.apache.org/test");
			this.cat.processEndElement();
		}

	
public voidtestWriteAtomOutput()

		try {
			this.cat.writeAtomOutput(null);
			fail("wirter is null");
		} catch (NullPointerException e) {
			// 
		}
		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.cat.writeAtomOutput(writer);
			assertEquals("<category term=\"\"/>", strWriter.toString());

		}

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.cat.term = "test";
			this.cat.writeAtomOutput(writer);
			assertEquals("<category term=\"test\"/>", strWriter.toString());

		}

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.cat.label = "python";
			this.cat.scheme = "monty";

			this.cat.writeAtomOutput(writer);
			assertEquals(
					"<category term=\"test\" scheme=\"monty\" label=\"python\"/>",
					strWriter.toString());

		}

	
public voidtestWriteRssOutput()

		try {
			this.cat.writeRssOutput(null);
			fail("wirter is null");
		} catch (NullPointerException e) {
			// 
		}

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.cat.writeRssOutput(writer);
			assertEquals("<category domain=\"\"/>", strWriter.toString());
		}

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.cat.scheme = "www.apache.org";
			this.cat.writeRssOutput(writer);
			assertEquals("<category domain=\"www.apache.org\"/>", strWriter
					.toString());
		}

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.cat.scheme = "www.apache.org";
			this.cat.term = "Goo Data";
			this.cat.writeRssOutput(writer);
			assertEquals(
					"<category domain=\"www.apache.org\">Goo Data</category>",
					strWriter.toString());
		}

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.cat.scheme = "www.apache.org";
			this.cat.term = "Goo Data";
			this.cat.label = "ignore";
			this.cat.writeRssOutput(writer);
			assertEquals(
					"<category domain=\"www.apache.org\">Goo Data</category>",
					strWriter.toString());
		}