📄 gomentryimpltest.java
字号:
package org.apache.lucene.gdata.gom.core;/** * 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. */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.AtomMediaType;import org.apache.lucene.gdata.gom.GOMAuthor;import org.apache.lucene.gdata.gom.GOMCategory;import org.apache.lucene.gdata.gom.GOMContent;import org.apache.lucene.gdata.gom.GOMContributor;import org.apache.lucene.gdata.gom.GOMEntry;import org.apache.lucene.gdata.gom.GOMExtension;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.GOMPublished;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.GOMSummary;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.writer.GOMOutputWriter;import org.apache.lucene.gdata.gom.writer.GOMStaxWriter;import junit.framework.TestCase;public class GOMEntryImplTest extends TestCase { private static final String TEST_LOCAL_NAME = GOMFeedImplTest.TEST_LOCAL_NAME; private GOMEntryImpl impl; protected void setUp() throws Exception { super.setUp(); this.impl = new GOMEntryImpl(); } public void testSetNamespace() { 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()); } /* * Test method for * 'org.apache.lucene.gdata.gom.core.GOMEntryImpl.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()); } { // 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()); } { // 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) { // } } { // 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) { // } } { // atomSource? AtomParser parser = this.impl.getChildParser(new QName( GOMNamespace.ATOM_NS_URI, "source")); assertNotNull(parser); assertTrue(parser instanceof GOMSource); assertEquals(parser, this.impl.getSource()); try { this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI, "source")); fail("duplicated element"); } catch (GDataParseException e) { // } } { // atomSummary? AtomParser parser = this.impl.getChildParser(new QName( GOMNamespace.ATOM_NS_URI, "summary")); assertNotNull(parser); assertTrue(parser instanceof GOMSummary); assertEquals(parser, this.impl.getSummary()); try { this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI, "summary")); fail("duplicated element"); } catch (GDataParseException e) { // } } { // atomContent? AtomParser parser = this.impl.getChildParser(new QName( GOMNamespace.ATOM_NS_URI, "content")); assertNotNull(parser); assertTrue(parser instanceof GOMContent); assertEquals(parser, this.impl.getContent()); try { this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI, "content")); fail("duplicated element"); } catch (GDataParseException e) { // } } { // atomContent? AtomParser parser = this.impl.getChildParser(new QName( GOMNamespace.ATOM_NS_URI, "published")); assertNotNull(parser); assertTrue(parser instanceof GOMPublished); assertEquals(parser, this.impl.getPublished()); try { this.impl.getChildParser(new QName(GOMNamespace.ATOM_NS_URI, "published")); fail("duplicated element"); } catch (GDataParseException e) { // } } } /* * Test method for
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -