lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sim...@apache.org
Subject svn commit: r486627 [9/9] - in /lucene/java/trunk/contrib/gdata-server/src/gom: java/org/ java/org/apache/ java/org/apache/lucene/ java/org/apache/lucene/gdata/ java/org/apache/lucene/gdata/gom/ java/org/apache/lucene/gdata/gom/core/ java/org/apache/lu...
Date Wed, 13 Dec 2006 12:40:04 GMT
Added: lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMPersonImplTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMPersonImplTest.java?view=auto&rev=486627
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMPersonImplTest.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMPersonImplTest.java
Wed Dec 13 04:39:54 2006
@@ -0,0 +1,176 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gdata.gom.core;
+
+import java.io.StringWriter;
+
+import javax.naming.NameParser;
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.lucene.gdata.gom.GOMNamespace;
+import org.apache.lucene.gdata.gom.writer.GOMStaxWriter;
+import org.apache.lucene.gdata.gom.writer.GOMOutputWriter;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public class GOMPersonImplTest extends TestCase {
+
+	/**
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	@Override
+	protected void setUp() throws Exception {
+		// TODO Auto-generated method stub
+		super.setUp();
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMPersonImpl.writeAtomOutput(GOMWriter)'
+	 */
+	public void testWriteAtomOutput() throws XMLStreamException,
+			FactoryConfigurationError {
+		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) {
+			//
+		}
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMPersonImpl.writeRssOutput(GOMWriter)'
+	 */
+	public void testWriteRssOutput() throws XMLStreamException {
+		StringWriter stW = new StringWriter();
+		GOMOutputWriter writer = new GOMStaxWriter(stW);
+		GOMPersonImpl impl = new GOMPersonImpl();
+		impl.writeRssOutput(writer);
+		writer.flush();
+		assertEquals(0, stW.toString().length());
+	}
+
+	public void testParseAtom() {
+		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 void testProcessEndElement() {
+		GOMPersonImpl impl = new GOMPersonImpl();
+		try {
+			impl.processEndElement();
+			fail("name must be set");
+		} catch (GDataParseException e) {
+			// 
+		}
+
+	}
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMSourceImplTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMSourceImplTest.java?view=auto&rev=486627
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMSourceImplTest.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMSourceImplTest.java
Wed Dec 13 04:39:54 2006
@@ -0,0 +1,418 @@
+package org.apache.lucene.gdata.gom.core;
+
+import java.io.StringWriter;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.lucene.gdata.gom.GOMAuthor;
+import org.apache.lucene.gdata.gom.GOMCategory;
+import org.apache.lucene.gdata.gom.GOMContributor;
+import org.apache.lucene.gdata.gom.GOMElement;
+import org.apache.lucene.gdata.gom.GOMEntry;
+import org.apache.lucene.gdata.gom.GOMExtension;
+import org.apache.lucene.gdata.gom.GOMFeed;
+import org.apache.lucene.gdata.gom.GOMGenerator;
+import org.apache.lucene.gdata.gom.GOMIcon;
+import org.apache.lucene.gdata.gom.GOMId;
+import org.apache.lucene.gdata.gom.GOMLink;
+import org.apache.lucene.gdata.gom.GOMLogo;
+import org.apache.lucene.gdata.gom.GOMNamespace;
+import org.apache.lucene.gdata.gom.GOMRights;
+import org.apache.lucene.gdata.gom.GOMSource;
+import org.apache.lucene.gdata.gom.GOMSubtitle;
+import org.apache.lucene.gdata.gom.GOMTitle;
+import org.apache.lucene.gdata.gom.GOMUpdated;
+import org.apache.lucene.gdata.gom.core.GOMFeedImplTest.TestExtendsionFactory;
+import org.apache.lucene.gdata.gom.core.GOMFeedImplTest.TestExtension;
+import org.apache.lucene.gdata.gom.core.extension.GOMExtensionFactory;
+import org.apache.lucene.gdata.gom.writer.GOMOutputWriter;
+import org.apache.lucene.gdata.gom.writer.GOMStaxWriter;
+
+import junit.framework.TestCase;
+
+public class GOMSourceImplTest extends TestCase {
+
+	static final String TEST_LOCAL_NAME = "testelement";
+
+	GOMSourceImpl impl;
+
+	protected void setUp() throws Exception {
+		this.impl = new GOMSourceImpl();
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMFeedImpl.getChildParser(QName)'
+	 */
+	public void testGetChildParser() {
+
+		{
+			// 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) {
+				// 
+			}
+
+		}
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMFeedImpl.processElementValue(String)'
+	 */
+	public void testProcessElementValue() {
+		try {
+			this.impl.processElementValue("some");
+			fail("no element text");
+		} catch (GDataParseException e) {
+			//
+		}
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMFeedImpl.processEndElement()'
+	 * 
+	 * atomFeed = element atom:feed { atomCommonAttributes, (atomAuthor* &
+	 * atomCategory* & atomContributor* & atomGenerator? & atomIcon? & atomId
&
+	 * atomLink* & atomLogo? & atomRights? & atomSubtitle? & atomTitle &
+	 * atomUpdated & extensionElement*), atomEntry* }
+	 */
+	public void testProcessEndElement() {
+		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());
+		}
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMFeedImpl.GOMFeedImpl()'
+	 */
+	public void testGOMFeedImpl() {
+		GOMFeedImpl impl2 = new GOMFeedImpl();
+		assertEquals(GOMFeed.LOCALNAME, impl2.getLocalName());
+		assertEquals(GOMFeed.LOCALNAME, impl2.getQname().getLocalPart());
+		assertEquals(GOMNamespace.ATOM_NS_URI, impl2.getQname()
+				.getNamespaceURI());
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMFeedImpl.writeAtomOutput(GOMWriter)'
+	 */
+	public void testWriteAtomOutput() throws XMLStreamException,
+			FactoryConfigurationError {
+		// 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.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());
+		StringWriter stW = new StringWriter();
+		GOMOutputWriter writer = new GOMStaxWriter(stW);
+		this.impl.writeAtomOutput(writer);
+		String string = stW.toString();
+		assertTrue(string.startsWith("<" + GOMSource.LOCALNAME));
+		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));
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMFeedImpl.writeRssOutput(GOMWriter)'
+	 */
+	public void testWriteRssOutput() throws XMLStreamException,
+			FactoryConfigurationError {
+
+		StringWriter stW = new StringWriter();
+		GOMOutputWriter writer = new GOMStaxWriter(stW);
+		this.impl.writeRssOutput(writer);
+		assertEquals("", stW.toString());
+	}
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMTextConstructImplTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMTextConstructImplTest.java?view=auto&rev=486627
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMTextConstructImplTest.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/GOMTextConstructImplTest.java
Wed Dec 13 04:39:54 2006
@@ -0,0 +1,257 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gdata.gom.core;
+
+import java.io.StringWriter;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.lucene.gdata.gom.ContentType;
+import org.apache.lucene.gdata.gom.core.GOMTextContructImpl.XMLBlobContentParser;
+import org.apache.lucene.gdata.gom.writer.GOMStaxWriter;
+import org.apache.lucene.gdata.gom.writer.GOMOutputWriter;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public class GOMTextConstructImplTest extends TestCase {
+	GOMTitleImpl titleImpl;
+
+	GOMSubtitleImpl subTitleImpl;
+
+	protected void setUp() throws Exception {
+		this.titleImpl = new GOMTitleImpl();
+		this.subTitleImpl = new GOMSubtitleImpl();
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMTextContructImpl.getChildParser(QName)'
+	 */
+	public void testGetChildParser() {
+		try {
+			this.titleImpl.getChildParser(null);
+			fail("qname must not be null");
+		} catch (GDataParseException e) {
+			// 
+		}
+		try {
+			this.titleImpl.getChildParser(new QName("test"));
+			fail("no such child supported");
+		} catch (GDataParseException e) {
+			// 
+		}
+
+		try {
+			this.titleImpl.getChildParser(new QName("div"));
+			fail("content type not set");
+		} catch (GDataParseException e) {
+			// 
+		}
+		this.titleImpl.contentType = ContentType.XHTML;
+		AtomParser childParser = this.titleImpl
+				.getChildParser(new QName("div"));
+		assertNotNull(childParser);
+		assertTrue(childParser instanceof XMLBlobContentParser);
+		try {
+			this.titleImpl.getChildParser(new QName("div"));
+			fail("duplicated element");
+		} catch (GDataParseException e) {
+			// 
+		}
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMTextContructImpl.processAttribute(QName,
+	 * String)' includes Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMTextContructImpl.getContentType()
+	 */
+	public void testProcessAttribute() {
+		try {
+			this.titleImpl.processAttribute(null, "test");
+			fail("qname is null");
+		} catch (GDataParseException e) {
+			// 
+		}
+		this.titleImpl.processAttribute(new QName("type"), "text");
+		assertEquals(ContentType.TEXT, this.titleImpl.getContentType());
+		this.titleImpl.contentType = null;
+		this.titleImpl.processAttribute(new QName("type"), "html");
+		assertEquals(ContentType.HTML, this.titleImpl.getContentType());
+		this.titleImpl.contentType = null;
+		this.titleImpl.processAttribute(new QName("type"), "xhtml");
+		assertEquals(ContentType.XHTML, this.titleImpl.getContentType());
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMTextContructImpl.processElementValue(String)'
+	 */
+	public void testProcessElementValue() {
+		this.titleImpl.processElementValue("test");
+		assertEquals("test", this.titleImpl.getTextValue());
+		assertNull(this.titleImpl.htmlBuilder);
+		this.titleImpl.processAttribute(new QName("type"), "html");
+		assertNotNull(this.titleImpl.htmlBuilder);
+
+		this.titleImpl.processElementValue("test");
+		assertEquals("test", this.titleImpl.getTextValue());
+		assertEquals("test", this.titleImpl.htmlBuilder.toString());
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMTextContructImpl.processEndElement()'
+	 */
+	public void testProcessEndElement() {
+		try {
+			this.titleImpl.processEndElement();
+			fail("no content type");
+		} catch (GDataParseException e) {
+			// 
+		}
+		this.titleImpl.contentType = ContentType.TEXT;
+		this.titleImpl.processEndElement();
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMTextContructImpl.writeAtomOutput(GOMWriter)'
+	 */
+	public void testWriteAtomOutput() throws XMLStreamException,
+			FactoryConfigurationError {
+		{
+			this.titleImpl.contentType = ContentType.TEXT;
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeAtomOutput(writer);
+			assertEquals("<title type=\"text\"/>", strWriter.toString());
+		}
+		{
+			this.titleImpl.setTextValue("><hello world");
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeAtomOutput(writer);
+			assertEquals("<title type=\"text\">&gt;&lt;hello world</title>",
+					strWriter.toString());
+		}
+
+		{
+			this.titleImpl.contentType = ContentType.HTML;
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeAtomOutput(writer);
+			assertEquals("<title type=\"html\">&gt;&lt;hello world</title>",
+					strWriter.toString());
+		}
+
+		{
+			this.titleImpl.contentType = ContentType.XHTML;
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeAtomOutput(writer);
+			assertEquals("<title type=\"xhtml\">><hello world</title>",
+					strWriter.toString());
+		}
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.GOMTextContructImpl.writeRssOutput(GOMWriter)'
+	 */
+	public void testWriteRssOutput() throws XMLStreamException {
+
+		{
+			this.titleImpl.contentType = ContentType.TEXT;
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeRssOutput(writer);
+			assertEquals("<title/>", strWriter.toString());
+		}
+		{
+			this.titleImpl.setTextValue("><hello world");
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeRssOutput(writer);
+			assertEquals("<title>&gt;&lt;hello world</title>", strWriter
+					.toString());
+		}
+
+		{
+			this.titleImpl.contentType = ContentType.HTML;
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeRssOutput(writer);
+			assertEquals("<title>&gt;&lt;hello world</title>", strWriter
+					.toString());
+		}
+
+		{
+			this.titleImpl.contentType = ContentType.XHTML;
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeRssOutput(writer);
+			// no markup in rss
+			assertEquals("<title>&gt;&lt;hello world</title>", strWriter
+					.toString());
+		}
+
+		{
+			this.titleImpl.contentType = ContentType.XHTML;
+			this.titleImpl.xmlBase = "http://www.apache.org";
+			this.titleImpl.xmlLang = "en";
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.titleImpl.writeRssOutput(writer);
+			// no markup in rss
+			assertEquals(
+					"<title xml:base=\"http://www.apache.org\" xml:lang=\"en\">&gt;&lt;hello
world</title>",
+					strWriter.toString());
+		}
+
+		{
+			this.subTitleImpl.contentType = ContentType.XHTML;
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.subTitleImpl.writeRssOutput(writer);
+
+			assertEquals("<description/>", strWriter.toString());
+		}
+
+		{
+			this.subTitleImpl.contentType = ContentType.XHTML;
+			this.subTitleImpl.setTextValue("><hello world");
+			StringWriter strWriter = new StringWriter();
+			GOMOutputWriter writer = new GOMStaxWriter(strWriter);
+			this.subTitleImpl.writeRssOutput(writer);
+
+			assertEquals("<description>&gt;&lt;hello world</description>",
+					strWriter.toString());
+		}
+	}
+
+}

Added: lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/SimpleGOMElementImplTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/SimpleGOMElementImplTest.java?view=auto&rev=486627
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/SimpleGOMElementImplTest.java
(added)
+++ lucene/java/trunk/contrib/gdata-server/src/gom/test/org/apache/lucene/gdata/gom/core/SimpleGOMElementImplTest.java
Wed Dec 13 04:39:54 2006
@@ -0,0 +1,136 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gdata.gom.core;
+
+import java.io.StringWriter;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.lucene.gdata.gom.GOMNamespace;
+import org.apache.lucene.gdata.gom.writer.GOMStaxWriter;
+import org.apache.lucene.gdata.gom.writer.GOMOutputWriter;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Simon Willnauer
+ * 
+ */
+public class SimpleGOMElementImplTest extends TestCase {
+	String localName = "test";
+
+	SimpleGOMElementImpl impl;
+
+	/**
+	 * @see junit.framework.TestCase#setUp()
+	 */
+	@Override
+	protected void setUp() throws Exception {
+		this.impl = new SimpleGOMElementImpl(localName,
+				GOMNamespace.ATOM_NAMESPACE);
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.SimpleGOMElementImpl.processElementValue(String)'
+	 */
+	public void testProcessElementValue() {
+		this.impl.processElementValue("myValue");
+		assertEquals("myValue", this.impl.getTextValue());
+
+		try {
+			this.impl.processElementValue("myValue");
+			fail("duplicated");
+
+		} catch (GDataParseException e) {
+			// 
+		}
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.SimpleGOMElementImpl.processEndElement()'
+	 */
+	public void testProcessEndElement() {
+		// 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();
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.SimpleGOMElementImpl.SimpleGOMElementImpl(String,
+	 * GOMNamespace)'
+	 */
+	public void testSimpleGOMElementImpl() {
+		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);
+
+	}
+
+	/*
+	 * Test method for
+	 * 'org.apache.lucene.gdata.gom.core.SimpleGOMElementImpl.writeAtomOutput(GOMWriter)'
+	 */
+	public void testWriteAtomOutput() throws XMLStreamException,
+			FactoryConfigurationError {
+		{
+			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());
+		}
+	}
+
+}



Mime
View raw message