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

SimpleGOMElementImplTest

public class SimpleGOMElementImplTest extends TestCase
author
Simon Willnauer

Fields Summary
String
localName
SimpleGOMElementImpl
impl
Constructors Summary
Methods Summary
protected voidsetUp()

see
junit.framework.TestCase#setUp()


	  	 
	
	     
		this.impl = new SimpleGOMElementImpl(localName,
				GOMNamespace.ATOM_NAMESPACE);
	
public voidtestProcessElementValue()

		this.impl.processElementValue("myValue");
		assertEquals("myValue", this.impl.getTextValue());

		try {
			this.impl.processElementValue("myValue");
			fail("duplicated");

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

		// depends validator
		this.impl.processEndElement();
		this.impl
				.setValidator(new GOMFeedImpl.PositiveIntegerValidator("test"));
		try {
			this.impl.processEndElement();
			fail("value is null");
		} catch (GDataParseException e) {
			assertTrue(e.getMessage().indexOf("requires a element value") > 0);
		}
		this.impl.setTextValue("1");
		this.impl.processEndElement();

	
public voidtestSimpleGOMElementImpl()

		try {
			new SimpleGOMElementImpl(null, GOMNamespace.ATOM_NAMESPACE);
			fail("localname is null");
		} catch (IllegalArgumentException e) {
			// 
		}
		try {
			new SimpleGOMElementImpl("test", null);
			fail("namespace is null");
		} catch (IllegalArgumentException e) {
			// 
		}

		SimpleGOMElementImpl impl2 = new SimpleGOMElementImpl(this.localName,
				GOMNamespace.ATOM_NAMESPACE);
		assertEquals(impl2.getQname().getNamespaceURI(),
				GOMNamespace.ATOM_NS_URI);
		assertEquals(impl2.getQname().getPrefix(), GOMNamespace.ATOM_NS_PREFIX);
		assertEquals(impl2.getQname().getLocalPart(), this.localName);
		assertEquals(impl2.getLocalName(), this.localName);

	
public voidtestWriteAtomOutput()

		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.writeAtomOutput(writer);
			assertEquals("<atom:" + this.localName + "/>", strWriter.toString());
		}
		{
			StringWriter strWriter = new StringWriter();
			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
			this.impl.setTextValue("hello world");
			this.impl.writeAtomOutput(writer);
			assertEquals("<atom:" + this.localName + ">hello world</atom:"
					+ this.localName + ">", strWriter.toString());
		}