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

GOMTextConstructImplTest

public class GOMTextConstructImplTest extends TestCase
author
Simon Willnauer

Fields Summary
GOMTitleImpl
titleImpl
GOMSubtitleImpl
subTitleImpl
Constructors Summary
Methods Summary
protected voidsetUp()

		this.titleImpl = new GOMTitleImpl();
		this.subTitleImpl = new GOMSubtitleImpl();
	
public voidtestGetChildParser()

		try {
			this.titleImpl.getChildParser(null);
			fail("qname must not be null");
		} catch (GDataParseException e) {
			// 
		}
		try {
			this.titleImpl.getChildParser(new QName("test"));
			fail("no such child supported");
		} catch (GDataParseException e) {
			// 
		}

		try {
			this.titleImpl.getChildParser(new QName("div"));
			fail("content type not set");
		} catch (GDataParseException e) {
			// 
		}
		this.titleImpl.contentType = ContentType.XHTML;
		AtomParser childParser = this.titleImpl
				.getChildParser(new QName("div"));
		assertNotNull(childParser);
		assertTrue(childParser instanceof XMLBlobContentParser);
		try {
			this.titleImpl.getChildParser(new QName("div"));
			fail("duplicated element");
		} catch (GDataParseException e) {
			// 
		}

	
public voidtestProcessAttribute()

		try {
			this.titleImpl.processAttribute(null, "test");
			fail("qname is null");
		} catch (GDataParseException e) {
			// 
		}
		this.titleImpl.processAttribute(new QName("type"), "text");
		assertEquals(ContentType.TEXT, this.titleImpl.getContentType());
		this.titleImpl.contentType = null;
		this.titleImpl.processAttribute(new QName("type"), "html");
		assertEquals(ContentType.HTML, this.titleImpl.getContentType());
		this.titleImpl.contentType = null;
		this.titleImpl.processAttribute(new QName("type"), "xhtml");
		assertEquals(ContentType.XHTML, this.titleImpl.getContentType());

	
public voidtestProcessElementValue()

		this.titleImpl.processElementValue("test");
		assertEquals("test", this.titleImpl.getTextValue());
		assertNull(this.titleImpl.htmlBuilder);
		this.titleImpl.processAttribute(new QName("type"), "html");
		assertNotNull(this.titleImpl.htmlBuilder);

		this.titleImpl.processElementValue("test");
		assertEquals("test", this.titleImpl.getTextValue());
		assertEquals("test", this.titleImpl.htmlBuilder.toString());

	
public voidtestProcessEndElement()

		try {
			this.titleImpl.processEndElement();
			fail("no content type");
		} catch (GDataParseException e) {
			// 
		}
		this.titleImpl.contentType = ContentType.TEXT;
		this.titleImpl.processEndElement();
	
public voidtestWriteAtomOutput()

		{
			this.titleImpl.contentType = ContentType.TEXT;
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeAtomOutput(writer);
			assertEquals("<title type=\"text\"/>", strWriter.toString());
		}
		{
			this.titleImpl.setTextValue("><hello world");
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeAtomOutput(writer);
			assertEquals("<title type=\"text\">><hello world</title>",
					strWriter.toString());
		}

		{
			this.titleImpl.contentType = ContentType.HTML;
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeAtomOutput(writer);
			assertEquals("<title type=\"html\">><hello world</title>",
					strWriter.toString());
		}

		{
			this.titleImpl.contentType = ContentType.XHTML;
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeAtomOutput(writer);
			assertEquals("<title type=\"xhtml\">><hello world</title>",
					strWriter.toString());
		}

	
public voidtestWriteRssOutput()


		{
			this.titleImpl.contentType = ContentType.TEXT;
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeRssOutput(writer);
			assertEquals("<title/>", strWriter.toString());
		}
		{
			this.titleImpl.setTextValue("><hello world");
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeRssOutput(writer);
			assertEquals("<title>><hello world</title>", strWriter
					.toString());
		}

		{
			this.titleImpl.contentType = ContentType.HTML;
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeRssOutput(writer);
			assertEquals("<title>><hello world</title>", strWriter
					.toString());
		}

		{
			this.titleImpl.contentType = ContentType.XHTML;
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeRssOutput(writer);
			// no markup in rss
			assertEquals("<title>><hello world</title>", strWriter
					.toString());
		}

		{
			this.titleImpl.contentType = ContentType.XHTML;
			this.titleImpl.xmlBase = "http://www.apache.org";
			this.titleImpl.xmlLang = "en";
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.titleImpl.writeRssOutput(writer);
			// no markup in rss
			assertEquals(
					"<title xml:base=\"http://www.apache.org\" xml:lang=\"en\">><hello world</title>",
					strWriter.toString());
		}

		{
			this.subTitleImpl.contentType = ContentType.XHTML;
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.subTitleImpl.writeRssOutput(writer);

			assertEquals("<description/>", strWriter.toString());
		}

		{
			this.subTitleImpl.contentType = ContentType.XHTML;
			this.subTitleImpl.setTextValue("><hello world");
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.subTitleImpl.writeRssOutput(writer);

			assertEquals("<description>><hello world</description>",
					strWriter.toString());
		}