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

GOMLinkImplTest

public class GOMLinkImplTest extends TestCase
author
Simon Willnauer

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

see
junit.framework.TestCase#setUp()

		impl = new GOMLinkImpl();
	
public voidtestCommonFields()

		assertNotNull(this.impl.getQname());
		QName qname = this.impl.getQname();
		assertEquals(qname, new QName(GOMLink.LOCALNAME));
		assertEquals(qname.getLocalPart(), this.impl.getLocalName());
	
public voidtestProcessAttribute()

		// title
		this.impl.processAttribute(new QName("title"), "title");
		assertEquals("title", this.impl.getTitle());
		try {
			this.impl.processAttribute(new QName("title"), "title");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}

		// hreflang
		this.impl.processAttribute(new QName("hreflang"), "hreflang");
		assertEquals("hreflang", this.impl.getHrefLang());
		try {
			this.impl.processAttribute(new QName("hreflang"), "hreflang");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}

		// href
		this.impl.processAttribute(new QName("href"), "href");
		assertEquals("href", this.impl.getHref());
		try {
			this.impl.processAttribute(new QName("href"), "href");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}
		// type
		this.impl.processAttribute(new QName("type"), "type");
		assertEquals("type", this.impl.getType());
		try {
			this.impl.processAttribute(new QName("type"), "type");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}

		// lenght
		try {
			this.impl.processAttribute(new QName("length"), "noint");
			fail("must be an integer");
		} catch (GDataParseException e) {
			// 
		}

		this.impl.processAttribute(new QName("length"), "1");
		assertEquals(new Integer(1), this.impl.getLength());
		try {
			this.impl.processAttribute(new QName("length"), "1");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}

		// 
		// rel
		this.impl.processAttribute(new QName("rel"), "relation");
		assertEquals("relation", this.impl.getRel());
		try {
			this.impl.processAttribute(new QName("rel"), "relation");
			fail("duplicated attribute");
		} catch (GDataParseException e) {
			// 
		}

	
public voidtestProcessElementValue()

		try {
			this.impl.processElementValue("hello world");
			fail("no content");
		} catch (GDataParseException e) {
			// TODO: handle exception
		}
	
public voidtestProcessEndElement()

		try {
			this.impl.processEndElement();
			fail("href is requiered but not set");
		} catch (GDataParseException e) {
			// 
		}

		this.impl.setHref("/helloworld");
		try {
			this.impl.processEndElement();
			fail("href is not an absolute url");
		} catch (GDataParseException e) {
			// 
		}
		this.impl.xmlBase = "http://url";
		this.impl.processEndElement();
		this.impl.xmlBase = null;
		this.impl.setHref("http://www.apache.org");
		this.impl.processEndElement();

	
public voidtestWriteAtomOutput()

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.writeAtomOutput(writer);
			assertEquals("<link href=\"\"/>", strWriter.toString());
		}
		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.setHref("test");
			this.impl.setHrefLang("test1");
			this.impl.setLength(2);
			this.impl.setRel("NEXT");
			this.impl.setTitle("myTitle");
			this.impl.setType("myType");
			this.impl.writeAtomOutput(writer);
			assertTrue(strWriter.toString().contains("href=\"test\""));
			assertTrue(strWriter.toString().contains("title=\"myTitle\""));
			assertTrue(strWriter.toString().contains("hreflang=\"test1\""));
			assertTrue(strWriter.toString().contains("type=\"myType\""));
			assertTrue(strWriter.toString().contains("rel=\"NEXT\""));
			assertTrue(strWriter.toString().contains("length=\"2\""));
		}
	
public voidtestWriteRssOutput()

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.writeRssOutput(writer);
			assertEquals("", strWriter.toString());
		}

		{
			this.impl.setHref("test");
			this.impl.setType("testType");
			this.impl.setRel("enclosure");
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.writeRssOutput(writer);
			assertEquals("<enclosure type=\"testType\" href=\"test\"/>",
					strWriter.toString());
		}

		{
			this.impl.setRel("comments");
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.writeRssOutput(writer);
			assertEquals("<comments>test</comments>", strWriter.toString());
		}

		{
			this.impl.setRel("alternate");
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.writeRssOutput(writer);
			assertEquals("<link>test</link>", strWriter.toString());
		}