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

GOMContentImplTest

public class GOMContentImplTest extends TestCase
author
Simon Willnauer

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

		super.setUp();
		this.impl = new GOMContentImpl();
	
public voidtestGOMContentImpl()

		GOMContentImpl impl2 = new GOMContentImpl();
		assertEquals(GOMContent.LOCALNAME, impl2.getLocalName());
		assertEquals(GOMContent.LOCALNAME, impl2.getQname().getLocalPart());
		assertEquals(GOMNamespace.ATOM_NS_URI, impl2.getQname()
				.getNamespaceURI());

	
public voidtestGetChildParser()

		try {
			this.impl.getChildParser(new QName("test"));
			fail("no blob specified");
		} catch (GDataParseException e) {
			// 
		}

		this.impl.setAtomMediaType(AtomMediaType.XML);
		AtomParser childParser = this.impl.getChildParser(new QName("test"));
		assertNotNull(childParser);
		assertTrue(childParser instanceof XMLBlobContentParser);

	
public voidtestProcessAttribute()

		try {
			this.impl.processAttribute(null, "test");
			fail("qname is null");
		} catch (GDataParseException e) {
			// 
		}
		try {
			this.impl.processAttribute(new QName("test"), null);
			fail("value is null");
		} catch (GDataParseException e) {
			// 
		}
		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI, "type"),
				"text/xml");
		assertSame(AtomMediaType.XML, this.impl.getAtomMediaType());
		try {
			this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI,
					"type"), "text/xml");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}
		this.impl.setAtomMediaType(null);
		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI, "type"),
				"text/plain");
		assertSame(AtomMediaType.TEXT, this.impl.getAtomMediaType());

		this.impl.setAtomMediaType(null);
		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI, "type"),
				"image/jpeg");
		assertSame(AtomMediaType.BINARY, this.impl.getAtomMediaType());

		// test if super is called
		this.impl.setAtomMediaType(null);
		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI, "type"),
				"xhtml");
		assertNull(this.impl.getAtomMediaType());
		assertSame(ContentType.XHTML, this.impl.getContentType());

		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI, "src"),
				"test");
		assertEquals("test", this.impl.getSrc());
		try {
			this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI,
					"src"), "text/xml");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}

	
public voidtestProcessElementValue()

		assertNull(this.impl.getTextValue());
		this.impl.processElementValue("test");
		assertEquals("test", this.impl.getTextValue());
		this.impl.setSrc("http://www.apache.org");
		try {
			this.impl.processElementValue("test");
			fail("src is set no element value allowed");
		} catch (GDataParseException e) {
			// 
		}

	
public voidtestProcessEndElement()

		try {
			this.impl.processEndElement();
			fail("no type attribute");
		} catch (GDataParseException e) {
			// 
		}
		this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI, "type"),
				"text/plain");
		this.impl.processEndElement();
		this.impl.setSrc("http://www.apache.org");
		this.impl.processEndElement();

		this.impl.setSrc("/test");
		try {
			this.impl.processEndElement();
			fail("must be absolut uri");
		} catch (GDataParseException e) {
			// 
		}
		this.impl.xmlBase = "http://www.apache.org";
		this.impl.processEndElement();
	
public voidtestWriteAtomOutput()

		{
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeAtomOutput(writer);
			assertEquals("<content type=\"text\"/>", stW.toString());
		}

		{
			this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI,
					"type"), "image/jpeg");
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeAtomOutput(writer);
			assertEquals("<content type=\"image/jpeg\"/>", stW.toString());
		}

		{
			this.impl.setSrc("http://www.apache.org");
			this.impl.setTextValue("hello world");
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeAtomOutput(writer);
			assertEquals(
					"<content type=\"image/jpeg\" src=\"http://www.apache.org\"/>",
					stW.toString());
		}

		{
			this.impl.setSrc(null);
			this.impl.setTextValue("hello world");
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeAtomOutput(writer);
			assertEquals("<content type=\"image/jpeg\">hello world</content>",
					stW.toString());
		}

	
public voidtestWriteRssOutputGOMOutputWriter()

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

		{
			this.impl.setSrc("http://www.apache.org");
			this.impl.setAtomMediaType(AtomMediaType.TEXT);
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeRssOutput(writer);
			assertEquals("<link>http://www.apache.org</link>", stW.toString());
		}

		{
			this.impl.setSrc(null);
			this.impl.setAtomMediaType(AtomMediaType.TEXT);
			this.impl.setTextValue("test");
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeRssOutput(writer);
			assertEquals("<description>test</description>", stW.toString());
		}

		{
			this.impl.setAtomMediaType(null);

			this.impl.processAttribute(new QName(GOMNamespace.ATOM_NS_URI,
					"type"), "image/jpeg");
			StringWriter stW = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(stW);
			this.impl.writeRssOutput(writer);
			assertEquals("<content type=\"image/jpeg\">test</content>", stW
					.toString());
		}