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

GOMFeedImplTest

public class GOMFeedImplTest extends TestCase

Fields Summary
static final String
TEST_LOCAL_NAME
GOMFeedImpl
impl
Constructors Summary
Methods Summary
protected voidsetUp()


	     
		this.impl = new GOMFeedImpl();
	
public voidtestGOMFeedImpl()

		GOMFeedImpl impl2 = new GOMFeedImpl();
		assertEquals(GOMFeed.LOCALNAME, impl2.getLocalName());
		assertEquals(GOMFeed.LOCALNAME, impl2.getQname().getLocalPart());
		assertEquals(GOMNamespace.ATOM_NS_URI, impl2.getQname()
				.getNamespaceURI());
	
public voidtestGetChildParser()


		{
			// atomAuthor*
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "author"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMAuthor);
			assertEquals(1, this.impl.getAuthors().size());
			this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
					"author"));
			assertEquals(2, this.impl.getAuthors().size());
		}

		{
			// atomCategory*
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "category"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMCategory);
			assertEquals(1, this.impl.getCategories().size());
			this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
					"category"));
			assertEquals(2, this.impl.getCategories().size());
		}

		{
			// atomContributor*
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "contributor"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMContributor);
			assertEquals(1, this.impl.getContributor().size());
			this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
					"contributor"));
			assertEquals(2, this.impl.getContributor().size());
		}
		{
			// atomGenerator?
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "generator"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMGenerator);
			assertSame(parser, this.impl.getGenerator());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"generator"));
				fail("one or zero");
			} catch (GDataParseException e) {
				// 
			}
		}

		{
			// atomIcon?
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "icon"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMIcon);
			assertSame(parser, this.impl.getIcon());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"icon"));
				fail("one or zero");
			} catch (GDataParseException e) {
				// 
			}

		}

		{
			// atomId
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "id"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMId);
			assertSame(parser, this.impl.getId());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"id"));
				fail("exactly one time ");
			} catch (GDataParseException e) {
				// 
			}

		}

		{
			// atomLink*
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "link"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMLink);
			assertEquals(1, this.impl.getLinks().size());
			this.impl
					.getChildParser(new QName(GOMNamespace.ATOM_NS_URI, "link"));
			assertEquals(2, this.impl.getLinks().size());

		}

		{
			// atomLogo?
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "logo"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMLogo);
			assertSame(parser, this.impl.getLogo());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"logo"));
				fail("zero or one");
			} catch (GDataParseException e) {
				// 
			}

		}

		{
			// atomRights?
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "rights"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMRights);
			assertSame(parser, this.impl.getRights());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"rights"));
				fail("zero or one");
			} catch (GDataParseException e) {
				// 
			}

		}

		{
			// atomSubtitle?
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "subtitle"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMSubtitle);
			assertSame(parser, this.impl.getSubtitle());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"subtitle"));
				fail("zero or one");
			} catch (GDataParseException e) {
				// 
			}

		}

		{
			// atomTitle
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "title"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMTitle);
			assertSame(parser, this.impl.getTitle());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"title"));
				fail("exactly one time ");
			} catch (GDataParseException e) {
				// 
			}

		}

		{
			// atomUpdated
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "updated"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMUpdated);
			assertSame(parser, this.impl.getUpdated());
			try {
				this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
						"updated"));
				fail("exactly one time ");
			} catch (GDataParseException e) {
				// 
			}

		}

		{
			// atomEntry*
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.ATOM_NS_URI, "entry"));
			assertNotNull(parser);
			assertTrue(parser instanceof GOMEntry);
			assertEquals(1, this.impl.getEntries().size());
			this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI,
					"entry"));
			assertEquals(2, this.impl.getEntries().size());

		}

		// openSearch
		{
			// startIndex
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.OPENSEARCH_NS_URI, "startIndex"));
			assertNotNull(parser);

		}
		{
			// startIndex
			AtomParser parser = this.impl.getChildParser(new QName(
					GOMNamespace.OPENSEARCH_NS_URI, "itemsPerPage"));
			assertNotNull(parser);

		}

	
public voidtestGetExtensions()


		{
			List<GOMExtension> extensions = this.impl.getExtensions();
			assertNotNull(extensions);
			assertEquals(0, extensions.size());
		}
		QName name = new QName(TEST_LOCAL_NAME);
		this.impl.setExtensionFactory(new TestExtendsionFactory());

		AtomParser childParser = this.impl.getChildParser(name);
		assertTrue(childParser instanceof TestExtension);
		List<GOMExtension> extensions = this.impl.getExtensions();
		assertNotNull(extensions);
		assertEquals(1, extensions.size());
		assertSame(childParser, extensions.get(0));
	
public voidtestGetSetItemsPerPage()

		assertEquals(GOMFeedImpl.DEFAULT_ITEMS_PER_PAGE, this.impl
				.getItemsPerPage());
		this.impl.setItemsPerPage(5);
		assertEquals(5, this.impl.getItemsPerPage());
		this.impl.setItemsPerPage(-5);
		assertEquals(5, this.impl.getItemsPerPage());

	
public voidtestGetSetStartIndex()

		assertEquals(GOMFeedImpl.DEFAULT_START_INDEX, this.impl.getStartIndex());
		this.impl.setStartIndex(5);
		assertEquals(5, this.impl.getStartIndex());
		this.impl.setStartIndex(-5);
		assertEquals(5, this.impl.getStartIndex());
	
public voidtestProcessElementValue()

		try {
			this.impl.processElementValue("some");
			fail("no element text");
		} catch (GDataParseException e) {
			//
		}

	
public voidtestProcessEndElement()

		this.impl.addAuthor(new GOMAuthorImpl());
		this.impl.setId(new GOMIdImpl());
		this.impl.setUpdated(new GOMUpdatedImpl());
		this.impl.setTitle(new GOMTitleImpl());

		this.impl.processEndElement();
		{
			// author missing
			this.impl.getAuthors().clear();
			try {
				this.impl.processEndElement();
				fail("missing elements");
			} catch (GDataParseException e) {
				// 
			}
			this.impl.addAuthor(new GOMAuthorImpl());
		}

		{
			// id missing
			this.impl.setId(null);
			try {
				this.impl.processEndElement();
				fail("missing elements");
			} catch (GDataParseException e) {
				// 
			}
			this.impl.setId(new GOMIdImpl());
		}

		{
			// title missing
			this.impl.setTitle(null);
			try {
				this.impl.processEndElement();
				fail("missing elements");
			} catch (GDataParseException e) {
				// 
			}
			this.impl.setTitle(new GOMTitleImpl());
		}
		{
			// updated missing
			this.impl.setUpdated(null);
			try {
				this.impl.processEndElement();
				fail("missing elements");
			} catch (GDataParseException e) {
				// 
			}
			this.impl.setUpdated(new GOMUpdatedImpl());
		}

		/*
		 * atom:feed elements MUST NOT contain more than one atom:link element
		 * with a rel attribute value of "alternate" that has the same
		 * combination of type and hreflang attribute values.
		 */

		{
			// two identical alternate links missing
			GOMLink link = new GOMLinkImpl();
			link.setRel("alternate");
			link.setHrefLang("http://www.apache.org");
			link.setType("text/html");
			this.impl.addLink(link);
			// one is allowed
			this.impl.processEndElement();
			// add a second link
			link = new GOMLinkImpl();
			this.impl.addLink(link);
			link.setRel("next");
			link.setHrefLang("http://www.apache.org");
			link.setType("text/html");
			// one is alternate the other is next
			this.impl.processEndElement();

			// a second "identical" alternate link
			link = new GOMLinkImpl();
			this.impl.addLink(link);
			link.setRel("alternate");
			link.setHrefLang("http://www.apache.org");
			link.setType("text/html");
			try {
				this.impl.processEndElement();
				fail("missing elements");
			} catch (GDataParseException e) {
				// 
			}
			this.impl.setUpdated(new GOMUpdatedImpl());
		}

	
public voidtestSetExtensionFactory()

		QName name = new QName(TEST_LOCAL_NAME);
		try {
			this.impl.getChildParser(name);
			fail("no child hander for this qname");
		} catch (GDataParseException e) {
			// 
		}

		this.impl.setExtensionFactory(new TestExtendsionFactory());

		AtomParser childParser = this.impl.getChildParser(name);
		assertTrue(childParser instanceof TestExtension);

	
public voidtestSetNamespace()

		assertEquals(0, this.impl.getNamespaces().size());
		assertNotNull(this.impl.getDefaultNamespace());
		this.impl.addNamespace(GOMNamespace.ATOM_NAMESPACE);
		assertSame(GOMNamespace.ATOM_NAMESPACE, this.impl.getDefaultNamespace());
		this.impl.addNamespace(GOMNamespace.OPENSEARCH_NAMESPACE);
		assertEquals(1, this.impl.getNamespaces().size());
		assertSame(GOMNamespace.OPENSEARCH_NAMESPACE, this.impl.getNamespaces()
				.get(0));

		// detect defaul ns
		this.impl.addNamespace(new GOMNamespace(GOMNamespace.ATOM_NS_URI, ""));
		assertEquals(1, this.impl.getNamespaces().size());
	
public voidtestWriteAtomOutput()

		// write a whole feed and check if all elements are written
		this.impl.addAuthor(new GOMAuthorImpl());
		this.impl.addCategory(new GOMCategoryImpl());
		this.impl.addContributor(new GOMContributorImpl());
		this.impl.addLink(new GOMLinkImpl());
		this.impl.addNamespace(GOMNamespace.OPENSEARCH_NAMESPACE);
		this.impl.setGenerator(new GOMGeneratorImpl());
		this.impl.setIcon(new GOMIconImpl());
		this.impl.setId(new GOMIdImpl());
		this.impl.setLogo(new GOMLogoImpl());
		this.impl.setRights(new GOMRightsImpl());
		this.impl.setSubtitle(new GOMSubtitleImpl());
		this.impl.setTitle(new GOMTitleImpl());
		this.impl.setUpdated(new GOMUpdatedImpl());
		this.impl.extensions.add(new TestExtension());
		this.impl.addNamespace(GOMNamespace.OPENSEARCH_NAMESPACE);
		StringWriter stW = new StringWriter();
		GOMOutputWriter writer = new GOMStaxWriter(stW);
		this.impl.writeAtomOutput(writer);
		String string = stW.toString();
		assertTrue(string.contains("xmlns:openSearch"));
		assertTrue(string.contains("xmlns=\"http://www.w3.org/2005/Atom\""));
		assertTrue(string.contains("<" + GOMAuthor.LOCALNAME));
		assertTrue(string.contains("<" + GOMCategory.LOCALNAME));
		assertTrue(string.contains("<" + GOMContributor.LOCALNAME));
		assertTrue(string.contains("<" + GOMLink.LOCALNAME));
		assertTrue(string.contains("<" + GOMGenerator.LOCALNAME));
		assertTrue(string.contains("<" + GOMIcon.LOCALNAME));
		assertTrue(string.contains("<" + GOMId.LOCALNAME));
		assertTrue(string.contains("<" + GOMLogo.LOCALNAME));
		assertTrue(string.contains("<" + GOMRights.LOCALNAME));
		assertTrue(string.contains("<" + GOMSubtitle.LOCALNAME));
		assertTrue(string.contains("<" + GOMTitle.LOCALNAME));
		assertTrue(string.contains("<" + GOMUpdated.LOCALNAME));
		assertTrue(string.contains("<openSearch:itemsPerPage>"));
		assertTrue(string.contains("<openSearch:startIndex>"));
		assertTrue(string.contains("<test"));
	
public voidtestWriteRssOutput()

		// write a whole feed and check if all elements are written
		this.impl.addAuthor(new GOMAuthorImpl());
		this.impl.addCategory(new GOMCategoryImpl());
		this.impl.addContributor(new GOMContributorImpl());
		GOMLinkImpl impl2 = new GOMLinkImpl();
		impl2.setHref("test");
		impl2.setRel("alternate");
		this.impl.addLink(impl2);
		this.impl.addNamespace(GOMNamespace.OPENSEARCH_NAMESPACE);
		this.impl.setGenerator(new GOMGeneratorImpl());
		this.impl.setIcon(new GOMIconImpl());
		this.impl.setId(new GOMIdImpl());
		this.impl.setLogo(new GOMLogoImpl());
		this.impl.setRights(new GOMRightsImpl());
		this.impl.setSubtitle(new GOMSubtitleImpl());
		this.impl.setTitle(new GOMTitleImpl());
		this.impl.setUpdated(new GOMUpdatedImpl());
		this.impl.addNamespace(GOMNamespace.ATOM_NAMESPACE);
		this.impl.addNamespace(GOMNamespace.OPENSEARCH_NAMESPACE);
		this.impl.extensions.add(new TestExtension());
		StringWriter stW = new StringWriter();
		GOMOutputWriter writer = new GOMStaxWriter(stW);
		this.impl.writeRssOutput(writer);

		String string = stW.toString();
		assertTrue(string.contains("xmlns:openSearch"));
		assertTrue(string.contains("xmlns:atom"));
		// TODO
		// assertTrue(string.contains("<language"));
		assertTrue(string.contains("<" + GOMCategory.LOCALNAME));
		// author
		assertTrue(string.contains("<managingEditor"));
		assertTrue(string.contains("<" + GOMLink.LOCALNAME));
		assertTrue(string.contains("<" + GOMGenerator.LOCALNAME));
		assertTrue(string.contains("<image><url"));
		assertTrue(string.contains("<atom:" + GOMId.LOCALNAME));

		assertTrue(string.contains("<copyright"));
		assertTrue(string.contains("<" + GOMTitle.LOCALNAME));
		assertTrue(string.contains("<lastBuildDate"));
		assertTrue(string.contains("<openSearch:itemsPerPage>"));
		assertTrue(string.contains("<openSearch:startIndex>"));
		assertTrue(string.contains("<atom:test"));