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

GOMPersonImplTest

public class GOMPersonImplTest extends TestCase
author
Simon Willnauer

Fields Summary
Constructors Summary
Methods Summary
protected voidsetUp()

see
junit.framework.TestCase#setUp()

		// TODO Auto-generated method stub
		super.setUp();
	
public voidtestParseAtom()

		GOMPersonImpl impl = new GOMPersonImpl();
		QName name = new QName(GOMNamespace.ATOM_NS_URI, "name");
		AtomParser childParser = impl.getChildParser(name);
		String nameValue = "simonw";
		{
			assertTrue(childParser instanceof GOMPersonImpl.NameParser);

			childParser.processElementValue(nameValue);
			childParser.processEndElement();
			assertEquals(impl.getName(), nameValue);
			try {
				childParser.processElementValue(nameValue);
				childParser.processEndElement();
				fail("duplicated element");

			} catch (GDataParseException e) {
				// 

			}
		}
		{
			name = new QName(GOMNamespace.ATOM_NS_URI, "uri");
			childParser = impl.getChildParser(name);
			assertTrue(childParser instanceof GOMPersonImpl.UriParser);

			childParser.processElementValue(nameValue);
			childParser.processEndElement();
			assertEquals(impl.getUri(), nameValue);

			try {
				childParser.processElementValue(nameValue);
				childParser.processEndElement();
				fail("duplicated element");

			} catch (GDataParseException e) {
				// 

			}

		}
		{
			name = new QName(GOMNamespace.ATOM_NS_URI, "email");
			childParser = impl.getChildParser(name);
			assertTrue(childParser instanceof GOMPersonImpl.EmailParser);

			childParser.processElementValue(nameValue);
			childParser.processEndElement();
			assertEquals(impl.getEmail(), nameValue);

			try {
				childParser.processElementValue(nameValue);
				childParser.processEndElement();
				fail("duplicated element");

			} catch (GDataParseException e) {
				// 

			}
		}

	
public voidtestProcessEndElement()

		GOMPersonImpl impl = new GOMPersonImpl();
		try {
			impl.processEndElement();
			fail("name must be set");
		} catch (GDataParseException e) {
			// 
		}

	
public voidtestWriteAtomOutput()

		StringWriter stW = new StringWriter();
		GOMOutputWriter writer = new GOMStaxWriter(stW);
		GOMPersonImpl impl = new GOMPersonImpl();
		impl.writeRssOutput(writer);
		writer.flush();
		writer.close();

		// test with name
		stW = new StringWriter();
		writer = new GOMStaxWriter(stW);
		impl.setName("test");
		impl.writeAtomOutput(writer);
		writer.flush();
		assertEquals("<person><name>test</name></person>", stW.toString());

		writer.close();

		// test with name
		stW = new StringWriter();
		writer = new GOMStaxWriter(stW);
		impl.setEmail("simonw@apache.org");
		impl.setUri("http://www.apache.org");
		impl.writeAtomOutput(writer);
		writer.flush();
		assertEquals(
				"<person><name>test</name><email>simonw@apache.org</email><uri>http://www.apache.org</uri></person>",
				stW.toString());
		try {
			impl.writeAtomOutput(null);
			fail("must not be null");

		} catch (GDataParseException e) {
			//
		}
	
public voidtestWriteRssOutput()

		StringWriter stW = new StringWriter();
		GOMOutputWriter writer = new GOMStaxWriter(stW);
		GOMPersonImpl impl = new GOMPersonImpl();
		impl.writeRssOutput(writer);
		writer.flush();
		assertEquals(0, stW.toString().length());