From 287cca15a34a2d758b4125c4a37e4ee38d2bdbdd Mon Sep 17 00:00:00 2001
From: Gerald Madlmayr
Date: Wed, 7 Nov 2018 00:17:42 +0100
Subject: [PATCH] Allow Enums in DataMaps (#505)
* Fixes bug in #475, add relevant Tests (#504)
* Adding more Tests for XML parsing/mapping (#504)
* Add more list tests (#504)
* Cleanup documentation of tests (#504)
* Adding asserts in GenericXmlTests (#504)
* Try-with-resources Java6 Style (#504)
* Replace Heise feed with Custom feed, set encoding for reading file (#504)
* Use Guava for reading resource file (#504)
* delete commented out code (#504)
* Improve JavaDoc of Tests (#504)
* Change method of asserting enums (#504)
* Minor fixes in JavaDoc (#504)
* Rename Test methods (#504)
* Fix Typo in JavaDoc (#504)
* Remove irrelevant annotation, clean up test case (#504)
* Fix incorrect/missing annotations, improve instanceof annotations (#504)
---
.../java/com/google/api/client/xml/Xml.java | 1 +
.../com/google/api/client/xml/AtomTest.java | 270 +++++++-
.../api/client/xml/GenericXmlListTest.java | 467 ++++++++++++++
.../google/api/client/xml/GenericXmlTest.java | 392 +++++++++++-
.../google/api/client/xml/XmlEnumTest.java | 197 ++++--
.../google/api/client/xml/XmlListTest.java | 410 ++++++++++++
.../xml/XmlNamespaceDictionaryTest.java | 102 ++-
.../com/google/api/client/xml/XmlTest.java | 605 ++++++++++++++++--
.../src/test/resources/sample-atom.xml | 1 +
.../com/google/api/client/util/DataMap.java | 1 -
10 files changed, 2242 insertions(+), 204 deletions(-)
create mode 100644 google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java
create mode 100644 google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java
create mode 100644 google-http-client-xml/src/test/resources/sample-atom.xml
diff --git a/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java b/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java
index a0f0b95d2..935eee30b 100644
--- a/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java
+++ b/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java
@@ -94,6 +94,7 @@ public static XmlPullParser createParser() throws XmlPullParserException {
/**
* Shows a debug string representation of an element data object of key/value pairs.
+ *
*
* It will make up something for the element name and XML namespaces. If those are known, it is
* better to use {@link XmlNamespaceDictionary#toStringOf(String, Object)}.
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java
index 65515f321..84f4bac91 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java
@@ -14,26 +14,56 @@
package com.google.api.client.xml;
-import com.google.api.client.http.HttpHeaders;
-import com.google.api.client.xml.atom.Atom;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.net.URL;
import java.util.List;
-import junit.framework.TestCase;
import org.junit.Assert;
+import org.junit.Test;
+import org.xmlpull.v1.XmlPullParser;
+import com.google.api.client.http.HttpHeaders;
+import com.google.api.client.http.xml.atom.AtomFeedParser;
+import com.google.api.client.util.Charsets;
+import com.google.api.client.util.Key;
+import com.google.api.client.xml.atom.AbstractAtomFeedParser;
+import com.google.api.client.xml.atom.Atom;
+import com.google.common.io.Resources;
/**
* Tests {@link Atom}.
*
* @author Yaniv Inbar
+ * @author Gerald Madlmayr
*/
-public class AtomTest extends TestCase {
+public class AtomTest {
- @SuppressWarnings("unchecked")
+
+ private static final String SAMPLE_FEED = " Example Feed 2003-12-13T18:31:02Z " +
+ "John Doe urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6" +
+ " Atom-Powered Robots Run Amok urn:uuid:1225c695-cfb8-4ebb-aaaa" +
+ "-80da344efa6a 2003-12-13T18:30:02Z Some text" +
+ ". Atom-Powered Robots Run Amok! urn:uuid:1225c695-cfb8-4ebb" +
+ "-aaaa-80da344efa62 2003-12-13T18:32:02Z Some " +
+ "other text. ";
+
+ /**
+ * Test for checking the Slug Header
+ */
+ @Test
public void testSetSlugHeader() {
HttpHeaders headers = new HttpHeaders();
assertNull(headers.get("Slug"));
subtestSetSlugHeader(headers, "value", "value");
- subtestSetSlugHeader(
- headers, " !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~", " !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~");
+ subtestSetSlugHeader(headers, " !\"#$&'()*+,-./:;<=>?@[\\]^_`{|}~", " !\"#$&'()*+,-./:;" +
+ "<=>?@[\\]^_`{|}~");
subtestSetSlugHeader(headers, "%D7%99%D7%A0%D7%99%D7%91", "יניב");
subtestSetSlugHeader(headers, null, null);
}
@@ -44,8 +74,230 @@ public void subtestSetSlugHeader(HttpHeaders headers, String expectedValue, Stri
if (value == null) {
assertNull(headers.get("Slug"));
} else {
- Assert.assertArrayEquals(
- new String[] {expectedValue}, ((List) headers.get("Slug")).toArray());
+ Assert.assertArrayEquals(new String[]{expectedValue},
+ ((List) headers.get("Slug")).toArray());
}
}
+
+ /**
+ * This tests parses a simple Atom Feed given as a constant. All elements are asserted, to see if
+ * everything works fine. For parsing a dedicated {@link AtomFeedParser} is used.
+ *
+ * The purpose of this test is to test the {@link AtomFeedParser#parseFeed} and {@link
+ * AtomFeedParser#parseNextEntry} and see if the mapping of the XML element to the entity classes
+ * is done correctly.
+ */
+ @Test
+ public void testAtomFeedUsingCustomizedParser() throws Exception {
+ XmlPullParser parser = Xml.createParser();
+ // Wired. Both, the InputStream for the FeedParser and the XPP need to be set (?)
+ parser.setInput(new StringReader(SAMPLE_FEED));
+ InputStream stream = new ByteArrayInputStream(SAMPLE_FEED.getBytes());
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ AbstractAtomFeedParser atomParser = new AtomFeedParser(namespaceDictionary,
+ parser, stream, Feed.class, FeedEntry.class);
+
+ Feed feed = (Feed) atomParser.parseFeed();
+ assertEquals("John Doe", feed.author.name);
+ assertEquals("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6", feed.id);
+ assertEquals("2003-12-13T18:31:02Z", feed.updated);
+ assertEquals("Example Feed", feed.title);
+ assertEquals("http://example.org/", feed.link.href);
+
+ FeedEntry entry1 = (FeedEntry) atomParser.parseNextEntry();
+ //assertNotNull(feed.entry);
+ assertEquals("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a", entry1.id);
+ assertEquals("2003-12-13T18:30:02Z", entry1.updated);
+ assertEquals("Some text.", entry1.summary);
+ assertEquals("Atom-Powered Robots Run Amok", entry1.title);
+ assertEquals("http://example.org/2003/12/13/atom03", entry1.link.href);
+
+ FeedEntry entry2 = (FeedEntry) atomParser.parseNextEntry();
+ assertEquals("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa62", entry2.id);
+ assertEquals("2003-12-13T18:32:02Z", entry2.updated);
+ assertEquals("Some other text.", entry2.summary);
+ assertEquals("Atom-Powered Robots Run Amok!", entry2.title);
+ assertEquals("http://example.org/2003/12/13/atom02", entry2.link.href);
+
+ FeedEntry entry3 = (FeedEntry) atomParser.parseNextEntry();
+ assertNull(entry3);
+
+ atomParser.close();
+ }
+
+ /**
+ * Tests of a constant string to see if the data structure can be parsed using the standard
+ * method {@link Xml#parseElement}
+ *
+ * The purpose of this test is to assert, if the parsed elements are correctly parsed using a
+ * {@link AtomFeedParser}.
+ */
+ @Test
+ public void testAtomFeedUsingStandardParser() throws Exception {
+ Feed feed = new Feed();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(SAMPLE_FEED));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, feed, namespaceDictionary, null);
+ assertNotNull(feed);
+ assertEquals(2, feed.entry.length);
+
+ assertEquals("John Doe", feed.author.name);
+ assertEquals("urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6", feed.id);
+ assertEquals("2003-12-13T18:31:02Z", feed.updated);
+ assertEquals("Example Feed", feed.title);
+ assertEquals("http://example.org/", feed.link.href);
+
+ FeedEntry entry1 = feed.entry[0];
+ //assertNotNull(feed.entry);
+ assertEquals("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a", entry1.id);
+ assertEquals("2003-12-13T18:30:02Z", entry1.updated);
+ assertEquals("Some text.", entry1.summary);
+ assertEquals("Atom-Powered Robots Run Amok", entry1.title);
+ assertEquals("http://example.org/2003/12/13/atom03", entry1.link.href);
+
+ FeedEntry entry2 = feed.entry[1];
+ assertEquals("urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa62", entry2.id);
+ assertEquals("2003-12-13T18:32:02Z", entry2.updated);
+ assertEquals("Some other text.", entry2.summary);
+ assertEquals("Atom-Powered Robots Run Amok!", entry2.title);
+ assertEquals("http://example.org/2003/12/13/atom02", entry2.link.href);
+ }
+
+ /**
+ * Read an XML ATOM Feed from a file to a string and assert if all the {@link FeedEntry}s are
+ * present. No detailed assertion of each element
+ *
+ * The purpose of this test is to read a bunch of elements which contain additional elements
+ * (HTML in this case), that are not part of the {@link FeedEntry} and to see if there is an issue
+ * if we parse some more entries.
+ */
+ @Test
+ public void testSampleFeedParser() throws Exception {
+ XmlPullParser parser = Xml.createParser();
+ URL url = Resources.getResource("sample-atom.xml");
+ String read = Resources.toString(url, Charsets.UTF_8);
+ parser.setInput(new StringReader(read));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ AbstractAtomFeedParser atomParser = new AtomFeedParser(namespaceDictionary,
+ parser, new ByteArrayInputStream(read.getBytes()), Feed.class, FeedEntry.class);
+ Feed feed = (Feed) atomParser.parseFeed();
+ assertNotNull(feed);
+
+ // validate feed 1 -- Long Content
+ FeedEntry entry = (FeedEntry) atomParser.parseNextEntry();
+ assertNotNull(entry);
+ assertNotNull(entry.id);
+ assertNotNull(entry.title);
+ assertNotNull(entry.summary);
+ assertNotNull(entry.link);
+ assertNotNull(entry.updated);
+ assertNotNull(entry.content);
+ assertEquals(5000, entry.content.length());
+
+ // validate feed 2 -- Special Charts
+ entry = (FeedEntry) atomParser.parseNextEntry();
+ assertNotNull(entry);
+ assertNotNull(entry.id);
+ assertNotNull(entry.title);
+ assertNotNull(entry.summary);
+ assertNotNull(entry.link);
+ assertNotNull(entry.updated);
+ assertNotNull(entry.content);
+ assertEquals("aäb cde fgh ijk lmn oöpoöp tuü vwx yz AÄBC DEF GHI JKL MNO ÖPQ RST UÜV WXYZ " +
+ "!\"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¼× {} aäb cde fgh ijk lmn oöp qrsß tuü vwx yz " +
+ "AÄBC DEF GHI JKL MNO", entry.content);
+
+ // validate feed 3 -- Missing Content
+ entry = (FeedEntry) atomParser.parseNextEntry();
+ assertNotNull(entry);
+ assertNotNull(entry.id);
+ assertNotNull(entry.title);
+ assertNotNull(entry.summary);
+ assertNotNull(entry.link);
+ assertNotNull(entry.updated);
+ assertNull(entry.content);
+
+ // validate feed 4 -- Missing Updated
+ entry = (FeedEntry) atomParser.parseNextEntry();
+ assertNotNull(entry);
+ assertNotNull(entry.id);
+ assertNotNull(entry.title);
+ assertNotNull(entry.summary);
+ assertNotNull(entry.link);
+ assertNull(entry.updated);
+ assertNotNull(entry.content);
+
+ // validate feed 5
+ entry = (FeedEntry) atomParser.parseNextEntry();
+ assertNotNull(entry);
+ assertNotNull(entry.id);
+ assertNotNull(entry.title);
+ assertNull(entry.summary);
+ assertNotNull(entry.link);
+ assertNotNull(entry.updated);
+ assertNotNull(entry.content);
+
+ // validate feed 6
+ entry = (FeedEntry) atomParser.parseNextEntry();
+ assertNull(entry);
+
+ atomParser.close();
+ }
+
+ /**
+ * Feed Element to map the XML to
+ */
+ public static class Feed {
+ @Key
+ private String title;
+ @Key
+ private Link link;
+ @Key
+ private String updated;
+ @Key
+ private Author author;
+ @Key
+ private String id;
+ @Key
+ private FeedEntry[] entry;
+ }
+
+ /**
+ * Author Element as part of the {@link Feed} Element to map the XML to. As this is sub-element,
+ * this needs to be public.
+ */
+ public static class Author {
+ @Key
+ private String name;
+ }
+
+ /**
+ * Link Element as part of the {@link Feed} Element to map the XML to. As this is sub-element,
+ * this needs to be public.
+ */
+ public static class Link {
+ @Key("@href")
+ private String href;
+ }
+
+ /**
+ * Entry Element to cover the Entries of a Atom {@link Feed}. As this is sub-element,
+ * this needs to be public.
+ */
+ public static class FeedEntry {
+ @Key
+ private String title;
+ @Key
+ private Link link;
+ @Key
+ private String updated;
+ @Key
+ private String summary;
+ @Key
+ private String id;
+ @Key
+ private String content;
+ }
}
+
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java
new file mode 100644
index 000000000..6d2ec0769
--- /dev/null
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java
@@ -0,0 +1,467 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * Licensed 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 com.google.api.client.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.junit.Test;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlSerializer;
+import com.google.api.client.util.ArrayMap;
+import com.google.api.client.util.Key;
+
+/**
+ * Tests List and Arrays of {@link GenericXml}.
+ *
+ * Tests are copies from {@link XmlListTest}, but the dedicated classes are derived from {@link
+ * GenericXml}
+ *
+ *
+ * @author Gerald Madlmayr
+ */
+
+public class GenericXmlListTest {
+
+
+ private static final String MULTI_TYPE_WITH_CLASS_TYPE = "content1rep10" +
+ "rep11value1content2rep20rep21"
+ + "value2content3rep30rep31" +
+ "value3";
+ private static final String MULTIPLE_STRING_ELEMENT = "rep1rep2";
+ private static final String MULTIPLE_INTEGER_ELEMENT = "12";
+ private static final String ARRAY_TYPE_WITH_PRIMITIVE_ADDED_NESTED = "1something2";
+ private static final String MULTIPLE_ENUM_ELEMENT = "ENUM_1ENUM_2";
+ private static final String COLLECTION_OF_ARRAY = "abcd";
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseArrayTypeWithClassType() throws Exception {
+ ArrayWithClassTypeGeneric xml = new ArrayWithClassTypeGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTI_TYPE_WITH_CLASS_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertNotNull(xml.rep);
+ XmlTest.AnyType[] rep = xml.rep;
+ assertNotNull(rep);
+ assertEquals(3, rep.length);
+ ArrayList> elem0 = (ArrayList>) rep[0].elem;
+ assertEquals(1, elem0.size());
+ assertEquals("content1", elem0.get(0)
+ .get("text()"));
+ ArrayList> elem1 = (ArrayList>) rep[1].elem;
+ assertEquals(1, elem1.size());
+ assertEquals("content2", elem1.get(0)
+ .get("text()"));
+ ArrayList> elem2 = (ArrayList>) rep[2].elem;
+ assertEquals(1, elem2.size());
+ assertEquals("content3", elem2.get(0)
+ .get("text()"));
+
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTI_TYPE_WITH_CLASS_TYPE, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link XmlTest.AnyType}
+ * objects.
+ */
+ @Test
+ public void testParseCollectionWithClassType() throws Exception {
+ CollectionWithClassTypeGeneric xml = new CollectionWithClassTypeGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTI_TYPE_WITH_CLASS_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertNotNull(xml.rep);
+ Collection rep = xml.rep;
+ assertNotNull(rep);
+ assertEquals(3, rep.size());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTI_TYPE_WITH_CLASS_TYPE, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseMultiGenericWithClassType() throws Exception {
+ MultiGenericWithClassType xml = new MultiGenericWithClassType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTI_TYPE_WITH_CLASS_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ GenericXml[] rep = xml.rep;
+ assertNotNull(rep);
+ assertEquals(3, rep.length);
+ assertEquals("text()", ((ArrayMap) (rep[0].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getKey(0));
+ assertEquals("content1", ((ArrayMap) (rep[0].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getValue(0));
+ assertEquals("text()", ((ArrayMap) (rep[1].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getKey(0));
+ assertEquals("content2", ((ArrayMap) (rep[1].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getValue(0));
+ assertEquals("text()", ((ArrayMap) (rep[2].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getKey(0));
+ assertEquals("content3", ((ArrayMap) (rep[2].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getValue(0));
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTI_TYPE_WITH_CLASS_TYPE, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseMultiGenericWithClassTypeGeneric() throws Exception {
+ MultiGenericWithClassTypeGeneric xml = new MultiGenericWithClassTypeGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTI_TYPE_WITH_CLASS_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ GenericXml[] rep = xml.rep;
+ assertNotNull(rep);
+ assertEquals(3, rep.length);
+ assertEquals("text()", ((ArrayMap) (rep[0].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getKey(0));
+ assertEquals("content1", ((ArrayMap) (rep[0].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getValue(0));
+ assertEquals("text()", ((ArrayMap) (rep[1].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getKey(0));
+ assertEquals("content2", ((ArrayMap) (rep[1].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getValue(0));
+ assertEquals("text()", ((ArrayMap) (rep[2].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getKey(0));
+ assertEquals("content3", ((ArrayMap) (rep[2].values()
+ .toArray(new ArrayList[]{})[0].get(0))).getValue(0));
+
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTI_TYPE_WITH_CLASS_TYPE, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link String}.
+ */
+ @Test
+ public void testParseCollectionTypeString() throws Exception {
+ CollectionTypeStringGeneric xml = new CollectionTypeStringGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_STRING_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals("rep1", xml.rep.toArray(new String[]{})[0]);
+ assertEquals("rep2", xml.rep.toArray(new String[]{})[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_STRING_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link String} objects.
+ */
+ @Test
+ public void testParseArrayTypeString() throws Exception {
+ ArrayTypeStringGeneric xml = new ArrayTypeStringGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_STRING_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals("rep1", xml.rep[0]);
+ assertEquals("rep2", xml.rep[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_STRING_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link Integer} objects.
+ */
+ @Test
+ public void testParseCollectionTypeInteger() throws Exception {
+ CollectionTypeIntegerGeneric xml = new CollectionTypeIntegerGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_INTEGER_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals(1, xml.rep.toArray(new Integer[]{})[0].intValue());
+ assertEquals(2, xml.rep.toArray(new Integer[]{})[1].intValue());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_INTEGER_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link Integer} objects.
+ */
+ @Test
+ public void testParseArrayTypeInteger() throws Exception {
+ ArrayTypeIntegerGeneric xml = new ArrayTypeIntegerGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_INTEGER_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals(1, xml.rep[0].intValue());
+ assertEquals(2, xml.rep[1].intValue());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_INTEGER_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@code int} types.
+ */
+ @Test
+ public void testParseArrayTypeInt() throws Exception {
+ ArrayTypeIntGeneric xml = new ArrayTypeIntGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_INTEGER_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals(1, xml.rep[0]);
+ assertEquals(2, xml.rep[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_INTEGER_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link Enum} objects.
+ */
+ @Test
+ public void testParseCollectionTypeWithEnum() throws Exception {
+ CollectionTypeEnumGeneric xml = new CollectionTypeEnumGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_ENUM_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_1, xml.rep.toArray(new XmlEnumTest.AnyEnum[]{})[0]);
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_2, xml.rep.toArray(new XmlEnumTest.AnyEnum[]{})[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_ENUM_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link Enum} objects.
+ */
+ @Test
+ public void testParseArrayTypeWithEnum() throws Exception {
+ ArrayTypeEnumGeneric xml = new ArrayTypeEnumGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_ENUM_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_1, xml.rep[0]);
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_2, xml.rep[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_ENUM_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose is to have an Array of {@link java.lang.reflect.ParameterizedType} elements.
+ */
+ @Test
+ public void testParseToArrayOfArrayMaps() throws Exception {
+ ArrayOfArrayMapsTypeGeneric xml = new ArrayOfArrayMapsTypeGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(COLLECTION_OF_ARRAY));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals("a", xml.rep[0].getValue(0));
+ assertEquals("a", xml.rep[0].getKey(0));
+ assertEquals("b", xml.rep[0].getValue(1));
+ assertEquals("b", xml.rep[0].getKey(1));
+ assertEquals("c", xml.rep[1].getValue(0));
+ assertEquals("c", xml.rep[1].getKey(0));
+ assertEquals("d", xml.rep[1].getValue(1));
+ assertEquals("d", xml.rep[1].getKey(1));
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(COLLECTION_OF_ARRAY, out.toString());
+ }
+
+ /**
+ * The purpose is to have a Collection of {@link java.lang.reflect.ParameterizedType} elements.
+ */
+ @Test
+ public void testParseToCollectionOfArrayMaps() throws Exception {
+ CollectionOfArrayMapsTypeGeneric xml = new CollectionOfArrayMapsTypeGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(COLLECTION_OF_ARRAY));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals("a", xml.rep.toArray(new ArrayMap[]{})[0].getValue(0));
+ assertEquals("a", xml.rep.toArray(new ArrayMap[]{})[0].getKey(0));
+ assertEquals("b", xml.rep.toArray(new ArrayMap[]{})[0].getValue(1));
+ assertEquals("b", xml.rep.toArray(new ArrayMap[]{})[0].getKey(1));
+ assertEquals("c", xml.rep.toArray(new ArrayMap[]{})[1].getValue(0));
+ assertEquals("c", xml.rep.toArray(new ArrayMap[]{})[1].getKey(0));
+ assertEquals("d", xml.rep.toArray(new ArrayMap[]{})[1].getValue(1));
+ assertEquals("d", xml.rep.toArray(new ArrayMap[]{})[1].getKey(1));
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(COLLECTION_OF_ARRAY, out.toString());
+ }
+
+ private static class CollectionOfArrayMapsTypeGeneric extends GenericXml {
+ @Key
+ public Collection> rep;
+ }
+
+ private static class ArrayOfArrayMapsTypeGeneric extends GenericXml {
+ @Key
+ public ArrayMap[] rep;
+ }
+
+ private static class ArrayWithClassTypeGeneric extends GenericXml {
+ @Key
+ public XmlTest.AnyType[] rep;
+ }
+
+ private static class CollectionWithClassTypeGeneric extends GenericXml {
+ @Key
+ public Collection rep;
+ }
+
+ private static class MultiGenericWithClassType {
+ @Key
+ public GenericXml[] rep;
+ }
+
+ private static class MultiGenericWithClassTypeGeneric extends GenericXml {
+ @Key
+ public GenericXml[] rep;
+ }
+
+ private static class CollectionTypeStringGeneric extends GenericXml {
+ @Key
+ public Collection rep;
+ }
+
+ private static class ArrayTypeStringGeneric extends GenericXml {
+ @Key
+ public String[] rep;
+ }
+
+ private static class CollectionTypeIntegerGeneric extends GenericXml {
+ @Key
+ public Collection rep;
+ }
+
+ private static class ArrayTypeIntegerGeneric extends GenericXml {
+ @Key
+ public Integer[] rep;
+ }
+
+ private static class ArrayTypeIntGeneric extends GenericXml {
+ @Key
+ public int[] rep;
+ }
+
+ private static class CollectionTypeEnumGeneric extends GenericXml {
+ @Key
+ public Collection rep;
+ }
+
+ private static class ArrayTypeEnumGeneric extends GenericXml {
+ @Key
+ public XmlEnumTest.AnyEnum[] rep;
+ }
+
+}
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java
index d8c57918e..0c98646b3 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java
@@ -14,47 +14,401 @@
package com.google.api.client.xml;
-import com.google.api.client.util.ArrayMap;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.StringReader;
+import java.util.ArrayList;
import java.util.Collection;
-import junit.framework.TestCase;
+import java.util.List;
+import java.util.Map;
+import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+import com.google.api.client.util.ArrayMap;
+import com.google.api.client.util.Key;
/**
* Tests {@link GenericXml}.
*
+ * Tests are copies from {@link XmlTest}, but the dedicated Objects are derived from {@link
+ * GenericXml}
+ *
* @author Yaniv Inbar
+ * @author Gerald Madlmayr
*/
-public class GenericXmlTest extends TestCase {
+public class GenericXmlTest {
- public GenericXmlTest() {
- }
+ private static final String XML = "OneTwo";
+ private static final String ANY_GENERIC_TYPE_XML = "rep1rep2content";
+ private static final String SIMPLE_XML = "test";
+ private static final String SIMPLE_XML_NUMERIC = "1";
+ private static final String ANY_TYPE_XML = "contentrep1rep2content";
+ private static final String ANY_TYPE_XML_PRIMITIVE_INT = "112" +
+ "";
+ private static final String ANY_TYPE_XML_PRIMITIVE_STR = "1+11+12" +
+ "+1";
+ private static final String ALL_TYPE = "";
+ private static final String ANY_TYPE_XML_NESTED_ARRAY = "contentrep1
rep2
rep3
rep4
content";
- public GenericXmlTest(String name) {
- super(name);
+ public GenericXmlTest() {
}
- private static final String XML =
- "One"
- + "Two";
-
+ /**
+ * The purpose of this test is to parse the given XML into a {@link GenericXml} Object that has no
+ * fixed structure.
+ */
@SuppressWarnings("unchecked")
- public void testParse() throws Exception {
+ @Test
+ public void testParseToGenericXml() throws Exception {
GenericXml xml = new GenericXml();
XmlPullParser parser = Xml.createParser();
parser.setInput(new StringReader(XML));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
Xml.parseElement(parser, xml, namespaceDictionary, null);
- ArrayMap expected =
- ArrayMap.of("gd", "http://schemas.google.com/g/2005", "", "http://www.w3.org/2005/Atom");
+ ArrayMap expected = ArrayMap.of("gd", "http://schemas.google.com/g/2005", "",
+ "http://www.w3.org/2005/Atom");
assertEquals(expected, namespaceDictionary.getAliasToUriMap());
assertEquals("feed", xml.name);
Collection foo = (Collection) xml.get("entry");
- // TODO(yanivi): check contents of foo
assertEquals(2, foo.size());
+ ArrayMap singleElementOne = ArrayMap.of("text()", "One");
+ List> testOne = new ArrayList>();
+ testOne.add(singleElementOne);
+ assertEquals("abc", foo.toArray(new ArrayMap[]{})[0].get("@gd:etag"));
+ assertEquals(testOne, foo.toArray(new ArrayMap[]{})[0].get("title"));
+ ArrayMap singleElementTwoAttrib = ArrayMap.of("@attribute", "someattribute",
+ "text()", "Two");
+ //ArrayMap singleElementTwoValue =ArrayMap.of();
+ List> testTwo = new ArrayList>();
+ testTwo.add(singleElementTwoAttrib);
+ //testTwo.add(singleElementTwoValue);
+ assertEquals("def", foo.toArray(new ArrayMap[]{})[1].get("@gd:etag"));
+ assertEquals(testTwo, foo.toArray(new ArrayMap[]{})[1].get("title"));
+ }
+
+ /**
+ * The purpose of this test is map a generic XML to an element inside a dedicated element.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseAnyGenericType() throws Exception {
+ AnyGenericType xml = new AnyGenericType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_GENERIC_TYPE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertTrue(xml.attr instanceof String);
+ Collection repList = (Collection) xml.elem.get("rep");
+ assertEquals(2, repList.size());
+ Collection repValue = (Collection) xml.elem.get("value");
+ assertEquals(1, repValue.size());
+ // 1st rep element
+ assertEquals("@attr", ((Map.Entry) repList.toArray(new ArrayMap[]{})[0].entrySet()
+ .toArray(new Map.Entry[]{})[0]).getKey());
+ assertEquals("param1", ((Map.Entry) repList.toArray(new ArrayMap[]{})[0].entrySet()
+ .toArray(new Map.Entry[]{})[0]).getValue());
+ assertEquals("text()", ((Map.Entry) repList.toArray(new ArrayMap[]{})[0].entrySet()
+ .toArray(new Map.Entry[]{})[1]).getKey());
+ assertEquals("rep1", ((Map.Entry) repList.toArray(new ArrayMap[]{})[0].entrySet()
+ .toArray(new Map.Entry[]{})[1]).getValue());
+ // 2nd rep element
+ assertEquals("@attr", ((Map.Entry) repList.toArray(new ArrayMap[]{})[1].entrySet()
+ .toArray(new Map.Entry[]{})[0]).getKey());
+ assertEquals("param2", ((Map.Entry) repList.toArray(new ArrayMap[]{})[1].entrySet()
+ .toArray(new Map.Entry[]{})[0]).getValue());
+ assertEquals("text()", ((Map.Entry) repList.toArray(new ArrayMap[]{})[1].entrySet()
+ .toArray(new Map.Entry[]{})[1]).getKey());
+ assertEquals("rep2", ((Map.Entry) repList.toArray(new ArrayMap[]{})[1].entrySet()
+ .toArray(new Map.Entry[]{})[1]).getValue());
+ // value element
+ assertEquals("text()", ((Map.Entry) repValue.toArray(new ArrayMap[]{})[0].entrySet()
+ .toArray(new Map.Entry[]{})[0]).getKey());
+ assertEquals("content", ((Map.Entry) repValue.toArray(new ArrayMap[]{})[0].entrySet()
+ .toArray(new Map.Entry[]{})[0]).getValue());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_GENERIC_TYPE_XML, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseSimpleTypeAsValueString() throws Exception {
+ SimpleTypeStringGeneric xml = new SimpleTypeStringGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(SIMPLE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(1, xml.values().size());
+ assertEquals("test", xml.values().toArray()[0]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("test", out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseSimpleTypeAsValueInteger() throws Exception {
+ SimpleTypeNumericGeneric xml = new SimpleTypeNumericGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(SIMPLE_XML_NUMERIC));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(1, xml.values().size());
+ assertEquals(1, xml.values().toArray()[0]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("1", out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseToAnyType() throws Exception {
+ processAnyTypeGeneric(ANY_TYPE_XML);
+ }
+
+ /**
+ * The purpose of this test is to map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseToAnyTypeMissingField() throws Exception {
+ AnyTypeMissingFieldGeneric xml = new AnyTypeMissingFieldGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(4, xml.values().size());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("contentcontentrep1rep2", out.toString());
+ }
+
+ /**
+ * The purpose of this test isto map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseToAnyTypeAdditionalField() throws Exception {
+ AnyTypeAdditionalFieldGeneric xml = new AnyTypeAdditionalFieldGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(4, xml.values().size());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_XML, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseToAnyTypePrimitiveInt() throws Exception {
+ AnyTypePrimitiveIntGeneric xml = new AnyTypePrimitiveIntGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML_PRIMITIVE_INT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(3, xml.values().size());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_XML_PRIMITIVE_INT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseToAnyTypeStringOnly() throws Exception {
+ AnyTypePrimitiveStringGeneric xml = new AnyTypePrimitiveStringGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML_PRIMITIVE_STR));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(3, xml.values().size());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_XML_PRIMITIVE_STR, out.toString());
+ }
+
+ /**
+ * The purpose of this tests is to test the mapping of an XML to an object without any overlap. In
+ * this case all the objects are stored in the {@link GenericXml#values} field.
+ */
+ @Test
+ public void testParseIncorrectMapping() throws Exception {
+ AnyTypeGeneric xml = new AnyTypeGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ALL_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(6, xml.values().size());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("", out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map a {@link GenericXml} to the String element in the
+ * object.
+ */
+ @Test
+ public void testParseAnyTypeWithNestedElementArrayMap() throws Exception {
+ processAnyTypeGeneric(ANY_TYPE_XML_NESTED_ARRAY);
+ }
+
+ private void processAnyTypeGeneric(final String anyTypeXmlNestedArray) throws XmlPullParserException, IOException {
+ AnyTypeGeneric xml = new AnyTypeGeneric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(anyTypeXmlNestedArray));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertNotNull(xml);
+ assertEquals(4, xml.values()
+ .size());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(anyTypeXmlNestedArray, out.toString());
+ }
+
+ private static class AnyGenericType {
+ @Key("@attr")
+ public Object attr;
+ @Key
+ public GenericXml elem;
}
+
+ private static class SimpleTypeStringGeneric extends GenericXml {
+ @Key("text()")
+ public String value;
+ }
+
+ private static class SimpleTypeNumericGeneric extends GenericXml {
+ @Key("text()")
+ public int value;
+ }
+
+ private static class AnyTypeGeneric extends GenericXml {
+ @Key("@attr")
+ public Object attr;
+ @Key
+ public Object elem;
+ @Key
+ public Object rep;
+ @Key
+ public ValueTypeGeneric value;
+ }
+
+ private static class AnyTypeMissingFieldGeneric extends GenericXml {
+ @Key("@attr")
+ public Object attr;
+ @Key
+ public Object elem;
+ @Key
+ public ValueTypeGeneric value;
+ }
+
+ private static class AnyTypeAdditionalFieldGeneric extends GenericXml {
+ @Key("@attr")
+ public Object attr;
+ @Key
+ public Object elem;
+ @Key
+ public Object rep;
+ @Key
+ public Object additionalField;
+ @Key
+ public ValueTypeGeneric value;
+ }
+
+ public static class ValueTypeGeneric extends GenericXml {
+ @Key("text()")
+ public Object content;
+ }
+
+ private static class AnyTypePrimitiveIntGeneric extends GenericXml {
+ @Key("text()")
+ public int value;
+ @Key("@attr")
+ public int attr;
+ @Key
+ public int[] intArray;
+ }
+
+ private static class AnyTypePrimitiveStringGeneric extends GenericXml {
+ @Key("text()")
+ public String value;
+ @Key("@attr")
+ public String attr;
+ @Key
+ public String[] strArray;
+ }
+
+
}
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java
index 1e0d79182..2d250a11d 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java
@@ -1,64 +1,55 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * Licensed 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 com.google.api.client.xml;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.ArrayList;
+import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
import com.google.api.client.util.Key;
import com.google.api.client.util.Value;
-import junit.framework.TestCase;
-
-public class XmlEnumTest extends TestCase {
-
- public enum AnyEnum {
- @Value ENUM_1,
- @Value ENUM_2
- }
-
- public static class AnyType {
- @Key("@attr")
- public Object attr;
- @Key
- public Object elem;
- @Key
- public Object rep;
- @Key("@anyEnum")
- public XmlEnumTest.AnyEnum anyEnum;
- @Key
- public XmlEnumTest.AnyEnum anotherEnum;
- @Key
- public ValueType value;
- }
-
- public static class AnyTypeEnumElementOnly {
- @Key
- public XmlEnumTest.AnyEnum elementEnum;
- }
-
- public static class AnyTypeEnumAttributeOnly {
- @Key("@attributeEnum")
- public XmlEnumTest.AnyEnum attributeEnum;
- }
-
- public static class ValueType {
- @Key("text()")
- public XmlEnumTest.AnyEnum content;
- }
-
- private static final String XML =
- ""
- + "ENUM_2contentrep1rep2ENUM_1";
-
- private static final String XML_ENUM_ELEMENT_ONLY = "ENUM_2";
-
- private static final String XML_ENUM_ATTRIBUTE_ONLY = "";
-
- private static final String XML_ENUM_INCORRECT = "ENUM_3";
-
- @SuppressWarnings("cast")
- public void testParse_anyType() throws Exception {
+/**
+ * Tests {@link Xml}.
+ *
+ * @author Gerald Madlmayr
+ */
+public class XmlEnumTest {
+
+ private static final String XML = "ENUM_2contentrep1rep2ENUM_1";
+ private static final String XML_ENUM_ELEMENT_ONLY = "ENUM_2";
+ private static final String XML_ENUM_ATTRIBUTE_ONLY = "";
+ private static final String XML_ENUM_INCORRECT = "ENUM_3";
+ private static final String XML_ENUM_ELEMENT_ONLY_NESTED = "ENUM_2something";
+
+
+ @Test
+ public void testParseAnyType() throws Exception {
AnyType xml = new AnyType();
XmlPullParser parser = Xml.createParser();
parser.setInput(new StringReader(XML));
@@ -67,13 +58,13 @@ public void testParse_anyType() throws Exception {
assertTrue(xml.attr instanceof String);
assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList>);
assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList>);
- assertTrue(xml.value instanceof ValueType);
- assertTrue(xml.value.content instanceof XmlEnumTest.AnyEnum);
- assertTrue(xml.anyEnum instanceof XmlEnumTest.AnyEnum);
- assertTrue(xml.anotherEnum instanceof XmlEnumTest.AnyEnum);
- assertTrue(xml.anyEnum.equals(AnyEnum.ENUM_1));
- assertTrue(xml.anotherEnum.equals(AnyEnum.ENUM_2));
- assertTrue(xml.value.content.equals(AnyEnum.ENUM_1));
+ assertNotNull(xml.value);
+ assertNotNull(xml.value.content);
+ assertNotNull(xml.anyEnum);
+ assertNotNull(xml.anotherEnum);
+ assertEquals(xml.anyEnum, AnyEnum.ENUM_1);
+ assertEquals(xml.anotherEnum, AnyEnum.ENUM_2);
+ assertEquals(xml.value.content, AnyEnum.ENUM_1);
// serialize
XmlSerializer serializer = Xml.createSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -82,30 +73,59 @@ public void testParse_anyType() throws Exception {
assertEquals(XML, out.toString());
}
- public void testParse_enumElementType() throws Exception {
- XmlEnumTest.AnyTypeEnumElementOnly xml = new XmlEnumTest.AnyTypeEnumElementOnly();
+ /**
+ * The purpose of this test is to parse an XML element to an objects's field.
+ */
+ @Test
+ public void testParseToEnumElementType() throws Exception {
+ assertEquals(XML_ENUM_ELEMENT_ONLY, testStandardXml(XML_ENUM_ELEMENT_ONLY));
+ }
+
+ /**
+ * The purpose of this test is to parse an XML element to an objects's field, whereas
+ * there are additional nested elements in the tag.
+ */
+ @Test
+ public void testParseToEnumElementTypeWithNestedElement() throws Exception {
+ assertEquals(XML_ENUM_ELEMENT_ONLY, testStandardXml(XML_ENUM_ELEMENT_ONLY_NESTED));
+ }
+
+ /**
+ * Private Method to handle standard parsing and mapping to {@link AnyTypeEnumElementOnly}.
+ *
+ * @param xmlString XML String that needs to be mapped to {@link AnyTypeEnumElementOnly}.
+ * @return returns the serialized string of the XML object.
+ * @throws Exception thrown if there is an issue processing the XML.
+ */
+ private String testStandardXml(final String xmlString) throws Exception {
+ AnyTypeEnumElementOnly xml = new AnyTypeEnumElementOnly();
XmlPullParser parser = Xml.createParser();
- parser.setInput(new StringReader(XML_ENUM_ELEMENT_ONLY));
+ parser.setInput(new StringReader(xmlString));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
Xml.parseElement(parser, xml, namespaceDictionary, null);
- assertTrue(xml.elementEnum instanceof XmlEnumTest.AnyEnum);
- assertTrue(xml.elementEnum.equals(AnyEnum.ENUM_2));
+ assertNotNull(xml.elementEnum);
+ assertEquals(xml.elementEnum, AnyEnum.ENUM_2);
// serialize
XmlSerializer serializer = Xml.createSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.setOutput(out, "UTF-8");
namespaceDictionary.serialize(serializer, "any", xml);
- assertEquals(XML_ENUM_ELEMENT_ONLY, out.toString());
+ return out.toString();
+
}
+ /**
+ * The purpose of this test is to parse an XML attribute to an object's field.
+ */
+ @Test
public void testParse_enumAttributeType() throws Exception {
XmlEnumTest.AnyTypeEnumAttributeOnly xml = new XmlEnumTest.AnyTypeEnumAttributeOnly();
XmlPullParser parser = Xml.createParser();
parser.setInput(new StringReader(XML_ENUM_ATTRIBUTE_ONLY));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
Xml.parseElement(parser, xml, namespaceDictionary, null);
- assertTrue(xml.attributeEnum instanceof XmlEnumTest.AnyEnum);
- assertTrue(xml.attributeEnum.equals(AnyEnum.ENUM_1));
+ assertNotNull(xml.attributeEnum);
+ assertEquals(xml.attributeEnum, AnyEnum.ENUM_1);
// serialize
XmlSerializer serializer = Xml.createSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -114,19 +134,60 @@ public void testParse_enumAttributeType() throws Exception {
assertEquals(XML_ENUM_ATTRIBUTE_ONLY, out.toString());
}
+ /**
+ * The purpose of this test is to parse an XML element to an object's field which is an
+ * enumeration, whereas the enumeration element does not exist.
+ */
+ @Test
public void testParse_enumElementTypeIncorrect() throws Exception {
XmlEnumTest.AnyTypeEnumElementOnly xml = new XmlEnumTest.AnyTypeEnumElementOnly();
XmlPullParser parser = Xml.createParser();
parser.setInput(new StringReader(XML_ENUM_INCORRECT));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
- try{
+ try {
Xml.parseElement(parser, xml, namespaceDictionary, null);
// fail test, if there is no exception
fail();
- } catch (final IllegalArgumentException e){
+ } catch (final IllegalArgumentException e) {
assertEquals("given enum name ENUM_3 not part of enumeration", e.getMessage());
}
+ }
+
+ public enum AnyEnum {
+ @Value ENUM_1,
+ @Value ENUM_2
+ }
+
+ private static class AnyType {
+ @Key("@attr")
+ private Object attr;
+ @Key
+ private Object elem;
+ @Key
+ private Object rep;
+ @Key("@anyEnum")
+ private XmlEnumTest.AnyEnum anyEnum;
+ @Key
+ private XmlEnumTest.AnyEnum anotherEnum;
+ @Key
+ private ValueType value;
+ }
+ private static class AnyTypeEnumElementOnly {
+ @Key
+ private XmlEnumTest.AnyEnum elementEnum;
+ }
+
+ private static class AnyTypeEnumAttributeOnly {
+ @Key("@attributeEnum")
+ private AnyEnum attributeEnum;
}
+ /**
+ * Needs to be public, this is referenced in another element.
+ */
+ public static class ValueType {
+ @Key("text()")
+ private XmlEnumTest.AnyEnum content;
+ }
}
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java
new file mode 100644
index 000000000..a53c4df12
--- /dev/null
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * Licensed 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 com.google.api.client.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.junit.Test;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlSerializer;
+import com.google.api.client.util.ArrayMap;
+import com.google.api.client.util.Key;
+
+
+/**
+ * Tests Lists of various data types parsed in {@link Xml}.
+ *
+ * @author Gerald Madlmayr
+ */
+public class XmlListTest {
+
+ private static final String MULTI_TYPE_WITH_CLASS_TYPE = "content1rep10rep11value1content2rep20rep21value2content3rep30rep31value3";
+ private static final String MULTIPLE_STRING_ELEMENT = "rep1rep2";
+ private static final String MULTIPLE_STRING_ELEMENT_IN_COLLECTION = "rep1rep2";
+ private static final String MULTIPLE_INTEGER_ELEMENT = "12";
+ private static final String MULTIPLE_ENUM_ELEMENT = "ENUM_1ENUM_2";
+ private static final String COLLECTION_OF_ARRAY = "abcd";
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testParseArrayTypeWithClassType() throws Exception {
+ ArrayWithClassType xml = new ArrayWithClassType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTI_TYPE_WITH_CLASS_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertNotNull(xml.rep);
+ XmlTest.AnyType[] rep = xml.rep;
+ assertNotNull(rep);
+ assertEquals(3, rep.length);
+ ArrayList> elem0 = (ArrayList>) rep[0].elem;
+ assertEquals(1, elem0.size());
+ assertEquals("content1", elem0.get(0)
+ .get("text()"));
+ ArrayList> elem1 = (ArrayList>) rep[1].elem;
+ assertEquals(1, elem1.size());
+ assertEquals("content2", elem1.get(0)
+ .get("text()"));
+ ArrayList> elem2 = (ArrayList>) rep[2].elem;
+ assertEquals(1, elem2.size());
+ assertEquals("content3", elem2.get(0)
+ .get("text()"));
+
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTI_TYPE_WITH_CLASS_TYPE, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link XmlTest.AnyType}
+ * objects.
+ */
+ @Test
+ public void testParseCollectionWithClassType() throws Exception {
+ CollectionWithClassType xml = new CollectionWithClassType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTI_TYPE_WITH_CLASS_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertNotNull(xml.rep);
+ Collection rep = xml.rep;
+ assertNotNull(rep);
+ assertEquals(3, rep.size());
+
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTI_TYPE_WITH_CLASS_TYPE, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link String}.
+ */
+ @Test
+ public void testParseCollectionTypeString() throws Exception {
+ CollectionTypeString xml = new CollectionTypeString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_STRING_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals("rep1", xml.rep.toArray(new String[]{})[0]);
+ assertEquals("rep2", xml.rep.toArray(new String[]{})[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_STRING_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link String} objects.
+ */
+ @Test
+ public void testParseArrayTypeString() throws Exception {
+ ArrayTypeString xml = new ArrayTypeString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_STRING_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals("rep1", xml.rep[0]);
+ assertEquals("rep2", xml.rep[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_STRING_ELEMENT, out.toString());
+ }
+ /**
+ * The purpose of this test is to map an XML with a sub element of a {@link Collection} of
+ * {@link String} objects.
+ */
+ @Test
+ public void testParseAnyTypeWithACollectionString() throws Exception {
+ AnyTypeWithCollectionString xml = new AnyTypeWithCollectionString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_STRING_ELEMENT_IN_COLLECTION));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertNotNull(xml.coll);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_STRING_ELEMENT_IN_COLLECTION, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link Integer} objects.
+ */
+ @Test
+ public void testParseCollectionTypeInteger() throws Exception {
+ CollectionTypeInteger xml = new CollectionTypeInteger();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_INTEGER_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals(1, xml.rep.toArray(new Integer[]{})[0].intValue());
+ assertEquals(2, xml.rep.toArray(new Integer[]{})[1].intValue());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_INTEGER_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link Integer} objects.
+ */
+ @Test
+ public void testParseArrayTypeInteger() throws Exception {
+ ArrayTypeInteger xml = new ArrayTypeInteger();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_INTEGER_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals(1, xml.rep[0].intValue());
+ assertEquals(2, xml.rep[1].intValue());
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_INTEGER_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@code int} types.
+ */
+ @Test
+ public void testParseArrayTypeInt() throws Exception {
+ ArrayTypeInt xml = new ArrayTypeInt();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_INTEGER_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals(1, xml.rep[0]);
+ assertEquals(2, xml.rep[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_INTEGER_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with a {@link Collection} of {@link Enum} objects.
+ */
+ @Test
+ public void testParseCollectionTypeWithEnum() throws Exception {
+ CollectionTypeEnum xml = new CollectionTypeEnum();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_ENUM_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_1, xml.rep.toArray(new XmlEnumTest.AnyEnum[]{})[0]);
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_2, xml.rep.toArray(new XmlEnumTest.AnyEnum[]{})[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_ENUM_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map an XML with an Array of {@link Enum} objects.
+ */
+ @Test
+ public void testParseArrayTypeWithEnum() throws Exception {
+ ArrayTypeEnum xml = new ArrayTypeEnum();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MULTIPLE_ENUM_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_1, xml.rep[0]);
+ assertEquals(XmlEnumTest.AnyEnum.ENUM_2, xml.rep[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(MULTIPLE_ENUM_ELEMENT, out.toString());
+ }
+
+ /**
+ * The purpose is to have an Array of {@link java.lang.reflect.ParameterizedType} elements.
+ */
+ @Test
+ public void testParseToArrayOfArrayMaps() throws Exception {
+ ArrayOfArrayMapsType xml = new ArrayOfArrayMapsType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(COLLECTION_OF_ARRAY));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.length);
+ assertEquals("a", xml.rep[0].getValue(0));
+ assertEquals("a", xml.rep[0].getKey(0));
+ assertEquals("b", xml.rep[0].getValue(1));
+ assertEquals("b", xml.rep[0].getKey(1));
+ assertEquals("c", xml.rep[1].getValue(0));
+ assertEquals("c", xml.rep[1].getKey(0));
+ assertEquals("d", xml.rep[1].getValue(1));
+ assertEquals("d", xml.rep[1].getKey(1));
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(COLLECTION_OF_ARRAY, out.toString());
+ }
+
+ /**
+ * The purpose is to have an Collection of {@link java.lang.reflect.ParameterizedType} elements.
+ */
+ @Test
+ public void testParseToCollectionOfArrayMaps() throws Exception {
+ CollectionOfArrayMapsType xml = new CollectionOfArrayMapsType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(COLLECTION_OF_ARRAY));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(2, xml.rep.size());
+ assertEquals("a", xml.rep.toArray(new ArrayMap[]{})[0].getValue(0));
+ assertEquals("a", xml.rep.toArray(new ArrayMap[]{})[0].getKey(0));
+ assertEquals("b", xml.rep.toArray(new ArrayMap[]{})[0].getValue(1));
+ assertEquals("b", xml.rep.toArray(new ArrayMap[]{})[0].getKey(1));
+ assertEquals("c", xml.rep.toArray(new ArrayMap[]{})[1].getValue(0));
+ assertEquals("c", xml.rep.toArray(new ArrayMap[]{})[1].getKey(0));
+ assertEquals("d", xml.rep.toArray(new ArrayMap[]{})[1].getValue(1));
+ assertEquals("d", xml.rep.toArray(new ArrayMap[]{})[1].getKey(1));
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(COLLECTION_OF_ARRAY, out.toString());
+ }
+
+ private static class CollectionOfArrayMapsType {
+ @Key
+ public Collection> rep;
+ }
+
+ private static class ArrayOfArrayMapsType {
+ @Key
+ public ArrayMap[] rep;
+ }
+
+ private static class ArrayWithClassType {
+ @Key
+ public XmlTest.AnyType[] rep;
+ }
+
+ private static class CollectionWithClassType {
+ @Key
+ public Collection rep;
+ }
+
+ /**
+ * Needs to be public, this is referenced in another element.
+ */
+ public static class CollectionTypeString {
+ @Key
+ public Collection rep;
+ }
+
+ private static class ArrayTypeString {
+ @Key
+ public String[] rep;
+ }
+
+ private static class AnyTypeWithCollectionString {
+ @Key
+ public CollectionTypeString coll;
+ }
+
+ private static class CollectionTypeInteger {
+ @Key
+ public Collection rep;
+ }
+
+ private static class ArrayTypeInteger {
+ @Key
+ public Integer[] rep;
+ }
+
+ private static class ArrayTypeInt {
+ @Key
+ public int[] rep;
+ }
+
+ private static class CollectionTypeEnum {
+ @Key
+ public Collection rep;
+ }
+
+ private static class ArrayTypeEnum {
+ @Key
+ public XmlEnumTest.AnyEnum[] rep;
+ }
+
+}
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java
index 051b6e5ec..4c03f7028 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java
@@ -14,14 +14,14 @@
package com.google.api.client.xml;
-import com.google.api.client.util.Key;
-import com.google.api.client.xml.atom.Atom;
-import com.google.common.collect.ImmutableMap;
import java.io.StringWriter;
import java.util.Collection;
import java.util.TreeSet;
-import junit.framework.TestCase;
import org.xmlpull.v1.XmlSerializer;
+import com.google.api.client.util.Key;
+import com.google.api.client.xml.atom.Atom;
+import com.google.common.collect.ImmutableMap;
+import junit.framework.TestCase;
/**
* Tests {@link XmlNamespaceDictionary}.
@@ -30,6 +30,19 @@
*/
public class XmlNamespaceDictionaryTest extends TestCase {
+ private static final String EXPECTED = "OneTwo";
+ private static final String EXPECTED_EMPTY_MAP = "";
+ private static final String EXPECTED_EMPTY_MAP_NS_UNDECLARED = "";
+ private static final String EXPECTED_EMPTY_MAP_ATOM_NS = "";
+ private static final String EXPECTED_UNKNOWN_NS = "One" +
+ "Two";
+
public XmlNamespaceDictionaryTest() {
}
@@ -37,29 +50,10 @@ public XmlNamespaceDictionaryTest(String name) {
super(name);
}
- private static final String EXPECTED =
- "" + ""
- + "One"
- + "Two";
-
- private static final String EXPECTED_EMPTY_MAP =
- "" + "";
-
- private static final String EXPECTED_EMPTY_MAP_NS_UNDECLARED =
- "" + "";
-
- private static final String EXPECTED_EMPTY_MAP_ATOM_NS =
- "" + "";
-
- private static final String EXPECTED_UNKNOWN_NS =
- "" + "" + "One"
- + "Two";
-
public void testSet() {
XmlNamespaceDictionary dictionary = new XmlNamespaceDictionary();
- dictionary.set("", "http://www.w3.org/2005/Atom").set("gd", "http://schemas.google.com/g/2005");
+ dictionary.set("", "http://www.w3.org/2005/Atom")
+ .set("gd", "http://schemas.google.com/g/2005");
assertEquals("http://www.w3.org/2005/Atom", dictionary.getUriForAlias(""));
assertEquals("", dictionary.getAliasForUri("http://www.w3.org/2005/Atom"));
dictionary.set("", "http://www.w3.org/2006/Atom");
@@ -77,10 +71,12 @@ public void testSet() {
dictionary.set(null, null);
assertEquals("http://schemas.google.com/g/2005", dictionary.getUriForAlias("foo"));
dictionary.set("foo", null);
- assertTrue(dictionary.getAliasToUriMap().isEmpty());
- dictionary.set("foo", "http://schemas.google.com/g/2005").set(
- null, "http://schemas.google.com/g/2005");
- assertTrue(dictionary.getAliasToUriMap().isEmpty());
+ assertTrue(dictionary.getAliasToUriMap()
+ .isEmpty());
+ dictionary.set("foo", "http://schemas.google.com/g/2005")
+ .set(null, "http://schemas.google.com/g/2005");
+ assertTrue(dictionary.getAliasToUriMap()
+ .isEmpty());
}
public void testSerialize() throws Exception {
@@ -156,30 +152,6 @@ public void testSerialize_emptyMapNsUndeclared() throws Exception {
assertEquals(EXPECTED_EMPTY_MAP_NS_UNDECLARED, writer.toString());
}
- public static class Entry implements Comparable {
- @Key
- public String title;
-
- @Key("@gd:etag")
- public String etag;
-
- public Entry(String title, String etag) {
- super();
- this.title = title;
- this.etag = etag;
- }
-
- public int compareTo(Entry other) {
- return title.compareTo(other.title);
- }
- }
-
- public static class Feed {
- @Key("entry")
- public Collection entries;
-
- }
-
public void testSerialize_errorOnUnknown() throws Exception {
Entry entry = new Entry("One", "abc");
StringWriter writer = new StringWriter();
@@ -222,4 +194,28 @@ public void testSerialize_unknown() throws Exception {
assertEquals(EXPECTED_UNKNOWN_NS, namespaceDictionary.toStringOf("feed", feed));
}
+ public static class Entry implements Comparable {
+ @Key
+ public String title;
+
+ @Key("@gd:etag")
+ public String etag;
+
+ public Entry(String title, String etag) {
+ super();
+ this.title = title;
+ this.etag = etag;
+ }
+
+ public int compareTo(Entry other) {
+ return title.compareTo(other.title);
+ }
+ }
+
+ public static class Feed {
+ @Key("entry")
+ public Collection entries;
+
+ }
+
}
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java
index 033d3e1ba..0462a2c3b 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java
@@ -14,106 +14,376 @@
package com.google.api.client.xml;
-import com.google.api.client.util.ArrayMap;
-import com.google.api.client.util.Key;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.ArrayList;
-import java.util.Map;
-import junit.framework.TestCase;
+import java.util.Collection;
+import java.util.List;
+import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
+import com.google.api.client.util.ArrayMap;
+import com.google.api.client.util.Key;
/**
* Tests {@link Xml}.
*
* @author Yaniv Inbar
+ * @author Gerald Madlmayr
*/
-public class XmlTest extends TestCase {
+public class XmlTest {
- public static class AnyType {
- @Key("@attr")
- public Object attr;
- @Key
- public Object elem;
- @Key
- public Object rep;
- @Key
- public ValueType value;
+
+ private static final String SIMPLE_XML = "test";
+ private static final String SIMPLE_XML_NUMERIC = "1";
+ private static final String START_WITH_TEXT = "start_with_text";
+ private static final String MISSING_END_ELEMENT = "" +
+ "missing_end_element";
+ private static final String START_WITH_END_ELEMENT = "
start_with_end_elemtn";
+ private static final String START_WITH_END_ELEMENT_NESTED = "
start_with_end_element_nested";
+ private static final String ANY_TYPE_XML = "contentrep1rep2" +
+ "content";
+ private static final String ANY_TYPE_MISSING_XML = "contentcontent";
+ private static final String ANY_TYPE_XML_PRIMITIVE_INT = "112" +
+ "";
+ private static final String ANY_TYPE_XML_PRIMITIVE_STR = "1+11+12" +
+ "+1";
+ private static final String NESTED_NS = "2011-08-09T04:38" +
+ ":14.017Z";
+ private static final String NESTED_NS_SERIALIZED = "2011-08-09T04:38:14.017Z";
+ private static final String INF_TEST = "-INFINF-INFINF" +
+ "";
+ private static final String ALL_TYPE = "";
+ private static final String ALL_TYPE_WITH_DATA = "" +
+ "ENUM_1ENUM_2TitleTest
112str1arr1arr2";
+ private static final String ANY_TYPE_XML_NESTED_ARRAY = "contentrep1
rep2
rep3
rep4
content";
+
+ /**
+ * The purpose of this test is to map a single element to a single field of a
+ * destination object. In this case the object mapped is a {@link String}; no namespace used.
+ */
+ @Test
+ public void testParseSimpleTypeAsValueString() throws Exception {
+ SimpleTypeString xml = new SimpleTypeString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(SIMPLE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals("test", xml.value);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("test", out.toString());
}
- public static class ValueType {
- @Key("text()")
- public Object content;
+ /**
+ * The purpose of this test is to map a single element to a single field of a
+ * destination object. In this is it is not an object but a {@code int}. no namespace
+ * used.
+ */
+ @Test
+ public void testParseSimpleTypeAsValueInteger() throws Exception {
+ SimpleTypeNumeric xml = new SimpleTypeNumeric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(SIMPLE_XML_NUMERIC));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(1, xml.value);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("1", out.toString());
+ }
+
+ /**
+ * Negative test to check for text without a start-element.
+ */
+ @Test
+ public void testWithTextFail() throws Exception {
+ SimpleTypeString xml = new SimpleTypeString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(START_WITH_TEXT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ try {
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ fail();
+ } catch (final Exception e) {
+ assertEquals("only whitespace content allowed before start tag and not s (position: " +
+ "START_DOCUMENT seen s... @1:22)", e.getMessage()
+ .trim());
+ }
+ }
+
+ /**
+ * Negative test to check for missing end-element.
+ */
+ @Test
+ public void testWithMissingEndElementFail() throws Exception {
+ SimpleTypeString xml = new SimpleTypeString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(MISSING_END_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ try {
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ fail();
+ } catch (final Exception e) {
+ assertEquals("no more data available - expected end tag to close start tag from line 1, parser stopped on START_TAG seen ...missing_end_element... @1:54", e.getMessage()
+ .trim());
+ }
+ }
+
+ /**
+ * Negative test with that start with a end-element.
+ */
+ @Test
+ public void testWithEndElementStarting() throws Exception {
+ SimpleTypeString xml = new SimpleTypeString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(START_WITH_END_ELEMENT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ try {
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ fail();
+ } catch (final Exception e) {
+ assertEquals("expected start tag name and not / (position: START_DOCUMENT seen "
- + "contentrep1rep2content";
+ /**
+ * Negative test with that start with a end element tag nested in an started element.
+ */
+ @Test
+ public void testWithEndElementNested() throws Exception {
+ SimpleTypeString xml = new SimpleTypeString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(START_WITH_END_ELEMENT_NESTED));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ try {
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ fail();
+ } catch (final Exception e) {
+ assertEquals("end tag name must match start tag name from line 1 (position:" +
+ " START_TAG seen ...... @1:39)", e.getMessage()
+ .trim());
+ }
+ }
- @SuppressWarnings("cast")
- public void testParse_anyType() throws Exception {
+ /**
+ * Negative test that maps a string to an integer and causes an exception.
+ */
+ @Test
+ public void testFailMappingOfDataType() throws Exception {
+ SimpleTypeNumeric xml = new SimpleTypeNumeric();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(SIMPLE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ try {
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ fail();
+ } catch (final Exception e) {
+ assertEquals("For input string: \"test\"", e.getMessage()
+ .trim());
+ }
+ }
+
+ /**
+ * The purpose of this tests it to test the {@link Key} Annotation for mapping of elements and
+ * attributes. All elements/attributes are matched.
+ */
+ @Test
+ public void testParseToAnyType() throws Exception {
AnyType xml = new AnyType();
XmlPullParser parser = Xml.createParser();
- parser.setInput(new StringReader(XML));
+ parser.setInput(new StringReader(ANY_TYPE_XML));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
Xml.parseElement(parser, xml, namespaceDictionary, null);
assertTrue(xml.attr instanceof String);
assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList>);
assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList>);
- assertTrue(xml.value instanceof ValueType);
+ assertNotNull(xml.value);
assertTrue(xml.value.content instanceof String);
// serialize
XmlSerializer serializer = Xml.createSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.setOutput(out, "UTF-8");
namespaceDictionary.serialize(serializer, "any", xml);
- assertEquals(XML, out.toString());
+ assertEquals(ANY_TYPE_XML, out.toString());
}
- public static class ArrayType extends GenericXml {
- @Key
- public Map[] rep;
+ /**
+ * The purpose of this tests it to test the {@link Key} annotation for mapping of elements and
+ * attributes. The matched object misses some field that are present int the XML ('elem' is
+ * missing and therefore ignored).
+ */
+ @Test
+ public void testParseToAnyTypeMissingField() throws Exception {
+ AnyTypeMissingField xml = new AnyTypeMissingField();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertTrue(xml.attr instanceof String);
+ assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList>);
+ assertNotNull(xml.value);
+ assertTrue(xml.value.content instanceof String);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_MISSING_XML, out.toString());
}
- private static final String ARRAY_TYPE =
- ""
- + "rep1rep2";
-
- public void testParse_arrayType() throws Exception {
- ArrayType xml = new ArrayType();
+ /**
+ * The purpose of this tests it to test the {@link Key} Annotation for mapping of elements and
+ * attributes. The matched object has an additional field, that will not be used and stays {@code
+ * null}.
+ */
+ @Test
+ public void testParseToAnyTypeAdditionalField() throws Exception {
+ AnyTypeAdditionalField xml = new AnyTypeAdditionalField();
XmlPullParser parser = Xml.createParser();
- parser.setInput(new StringReader(ARRAY_TYPE));
+ parser.setInput(new StringReader(ANY_TYPE_XML));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
Xml.parseElement(parser, xml, namespaceDictionary, null);
- // check type
- Map[] rep = xml.rep;
- assertEquals(2, rep.length);
- ArrayMap map0 = (ArrayMap) rep[0];
- assertEquals(1, map0.size());
- assertEquals("rep1", map0.get("text()"));
- ArrayMap map1 = (ArrayMap) rep[1];
- assertEquals(1, map1.size());
- assertEquals("rep2", map1.get("text()"));
+ assertTrue(xml.attr instanceof String);
+ assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList>);
+ assertNotNull(xml.value);
+ assertNull(xml.additionalField);
+ assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList>);
+ assertTrue(xml.value.content instanceof String);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_XML, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to see, if there is an exception of the parameter 'destination' in
+ * {@link Xml#parseElement} is {@code null}. The parser internally will skip mapping of the XML
+ * structure, but will parse it anyway.
+ */
+ @Test
+ public void testParseToAnyTypeWithNullDestination() throws Exception {
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, null, namespaceDictionary, null);
+ }
+
+ /**
+ * The purpose of this test is to see, if parsing works with a {@link Xml.CustomizeParser}.
+ * The XML will be mapped to {@link AnyType}.
+ */
+ @Test
+ public void testParseAnyTypeWithCustomParser() throws Exception {
+ AnyType xml = new AnyType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, new Xml.CustomizeParser());
+ assertTrue(xml.attr instanceof String);
+ assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList>);
+ assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList>);
+ assertNotNull(xml.value);
+ assertTrue(xml.value.content instanceof String);
// serialize
XmlSerializer serializer = Xml.createSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.setOutput(out, "UTF-8");
namespaceDictionary.serialize(serializer, "any", xml);
- assertEquals(ARRAY_TYPE, out.toString());
+ assertEquals(ANY_TYPE_XML, out.toString());
}
- private static final String NESTED_NS =
- ""
- + "2011-08-09T04:38:14.017Z"
- + "";
+ /**
+ * The purpose of this test it to parse elements which will be mapped to a
+ * {@link javax.lang.model.type.PrimitiveType}. Therefore {@code int}s are mapped to attributes,
+ * elements and element arrays.
+ */
+ @Test
+ public void testParseToAnyTypePrimitiveInt() throws Exception {
+ AnyTypePrimitiveInt xml = new AnyTypePrimitiveInt();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML_PRIMITIVE_INT));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, new Xml.CustomizeParser());
+ assertEquals(1, xml.value);
+ assertEquals(2, xml.attr);
+ assertEquals(2, xml.intArray.length);
+ assertEquals(1, xml.intArray[0]);
+ assertEquals(2, xml.intArray[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_XML_PRIMITIVE_INT, out.toString());
+ }
- private static final String NESTED_NS_SERIALIZED =
- "" + "2011-08-09T04:38:14.017Z"
- + "";
+ /**
+ * The purpose of this test it to parse elements which will be mapped to a Java
+ * {@link javax.lang.model.type.PrimitiveType}. Therefore {@code int}s are mapped to attributes,
+ * elements and element arrays.
+ */
+ @Test
+ public void testParseToAnyTypeStringOnly() throws Exception {
+ AnyTypePrimitiveString xml = new AnyTypePrimitiveString();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML_PRIMITIVE_STR));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, new Xml.CustomizeParser());
+ assertEquals("1+1", xml.value);
+ assertEquals("2+1", xml.attr);
+ assertEquals(2, xml.strArray.length);
+ assertEquals("1+1", xml.strArray[0]);
+ assertEquals("2+1", xml.strArray[1]);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_XML_PRIMITIVE_STR, out.toString());
+ }
- public void testParse_nestedNs() throws Exception {
+ /**
+ * The purpose of this test is to map nested elements with a namespace attribute.
+ */
+ @Test
+ public void testParseOfNestedNs() throws Exception {
XmlPullParser parser = Xml.createParser();
parser.setInput(new StringReader(NESTED_NS));
XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
@@ -127,4 +397,231 @@ public void testParse_nestedNs() throws Exception {
namespaceDictionary.serialize(serializer, "any", xml);
assertEquals(NESTED_NS_SERIALIZED, out.toString());
}
+
+ /**
+ * The purpose of this test is to map the infinity values of both {@code doubles} and
+ * {@code floats}.
+ */
+ @Test
+ public void testParseInfiniteValues() throws Exception {
+ AnyTypeInf xml = new AnyTypeInf();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(INF_TEST));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(Double.NEGATIVE_INFINITY, xml.dblInfNeg, 0.0001);
+ assertEquals(Double.POSITIVE_INFINITY, xml.dblInfPos, 0.0001);
+ assertEquals(Float.NEGATIVE_INFINITY, xml.fltInfNeg, 0.0001);
+ assertEquals(Float.POSITIVE_INFINITY, xml.fltInfPos, 0.0001);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(INF_TEST, out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map multiple different data types in a single test, without
+ * data. (explorative)
+ */
+ @Test
+ public void testParseEmptyElements() throws Exception {
+ AllType xml = new AllType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ALL_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertEquals(0, xml.integer);
+ // TODO: Shouldn't array size == 0? (currently generated via a = new x[1]).
+ assertEquals(1, xml.stringArray.length);
+ assertEquals(1, xml.anyEnum.length);
+ assertNotNull(xml.genericXml);
+ assertNotNull(xml.integerCollection);
+ assertNull(xml.str);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("0", out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map multiple different data types in a single test, with data.
+ * (explorative)
+ */
+ @Test
+ public void testParseAllElements() throws Exception {
+ AllType xml = new AllType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ALL_TYPE_WITH_DATA));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ALL_TYPE_WITH_DATA, out.toString());
+ }
+
+ /**
+ * The purpose of this tests is to map a completely unrelated XML to a given destination object.
+ * (explorative)
+ */
+ @Test
+ public void testParseIncorrectMapping() throws Exception {
+ AnyType xml = new AnyType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ALL_TYPE));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary().set("", "");
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ // check type
+ assertNull(xml.elem);
+ assertNull(xml.value);
+ assertNull(xml.rep);
+ assertNull(xml.rep);
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals("", out.toString());
+ }
+
+ /**
+ * The purpose of this test is to map the sub elements of an {@link ArrayMap} again to an {@link
+ * ArrayMap}.
+ */
+ @Test
+ public void testParseAnyTypeWithNestedElementArrayMap() throws Exception {
+ AnyType xml = new AnyType();
+ XmlPullParser parser = Xml.createParser();
+ parser.setInput(new StringReader(ANY_TYPE_XML_NESTED_ARRAY));
+ XmlNamespaceDictionary namespaceDictionary = new XmlNamespaceDictionary();
+ Xml.parseElement(parser, xml, namespaceDictionary, null);
+ assertTrue(xml.attr instanceof String);
+ assertTrue(xml.elem.toString(), xml.elem instanceof ArrayList>);
+ assertTrue(xml.rep.toString(), xml.rep instanceof ArrayList>);
+ assertNotNull(xml.value);
+ assertTrue(xml.value.content instanceof String);
+ assertEquals(1, ((Collection>) xml.elem).size());
+ assertEquals(2, ((Collection>) xml.rep).size());
+ assertEquals(1, ((Collection>) xml.rep).toArray(new ArrayMap[]{})[0].size());
+ assertEquals(1, ((Collection>) xml.rep).toArray(new ArrayMap[]{})[1].size());
+ assertEquals("rep1",
+ ((ArrayList>) ((ArrayList>) xml.rep).toArray(new ArrayMap[]{})[0].get("p")).toArray(new ArrayMap[]{})[0].getValue(0));
+ assertEquals("rep2",
+ ((ArrayList>) ((ArrayList>) xml.rep).toArray(new ArrayMap[]{})[0].get("p")).toArray(new ArrayMap[]{})[1].getValue(0));
+ assertEquals("rep3",
+ ((ArrayList>) ((ArrayList>) xml.rep).toArray(new ArrayMap[]{})[1].get("p")).toArray(new ArrayMap[]{})[0].getValue(0));
+ assertEquals("rep4",
+ ((ArrayList>) ((ArrayList>) xml.rep).toArray(new ArrayMap[]{})[1].get("p")).toArray(new ArrayMap[]{})[1].getValue(0));
+
+ // serialize
+ XmlSerializer serializer = Xml.createSerializer();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializer.setOutput(out, "UTF-8");
+ namespaceDictionary.serialize(serializer, "any", xml);
+ assertEquals(ANY_TYPE_XML_NESTED_ARRAY, out.toString());
+ }
+
+ public static class SimpleTypeString {
+ @Key("text()")
+ public String value;
+ }
+
+ public static class SimpleTypeNumeric {
+ @Key("text()")
+ public int value;
+ }
+
+ public static class AnyType {
+ @Key("@attr")
+ public Object attr;
+ @Key
+ public Object elem;
+ @Key
+ public Object rep;
+ @Key
+ public ValueType value;
+ }
+
+ public static class AnyTypeMissingField {
+ @Key("@attr")
+ public Object attr;
+ @Key
+ public Object elem;
+ @Key
+ public ValueType value;
+ }
+
+ public static class AnyTypeAdditionalField {
+ @Key("@attr")
+ public Object attr;
+ @Key
+ public Object elem;
+ @Key
+ public Object rep;
+ @Key
+ public Object additionalField;
+ @Key
+ public ValueType value;
+ }
+
+ public static class ValueType {
+ @Key("text()")
+ public Object content;
+ }
+
+ public static class AnyTypePrimitiveInt {
+ @Key("text()")
+ public int value;
+ @Key("@attr")
+ public int attr;
+ @Key
+ public int[] intArray;
+ }
+
+ public static class AnyTypePrimitiveString {
+ @Key("text()")
+ public String value;
+ @Key("@attr")
+ public String attr;
+ @Key
+ public String[] strArray;
+ }
+
+ private static class AnyTypeInf {
+ @Key
+ public double dblInfNeg;
+ @Key
+ public double dblInfPos;
+ @Key
+ public float fltInfNeg;
+ @Key
+ public float fltInfPos;
+ }
+
+ private static class AllType {
+ @Key
+ public int integer;
+ @Key
+ public String str;
+ @Key
+ public GenericXml genericXml;
+ @Key
+ public XmlEnumTest.AnyEnum[] anyEnum;
+ @Key
+ public String[] stringArray;
+ @Key
+ public List integerCollection;
+ }
}
+
diff --git a/google-http-client-xml/src/test/resources/sample-atom.xml b/google-http-client-xml/src/test/resources/sample-atom.xml
new file mode 100644
index 000000000..1d370a4dd
--- /dev/null
+++ b/google-http-client-xml/src/test/resources/sample-atom.xml
@@ -0,0 +1 @@
+World Of Sample News online NewsEverything about Computers and ATOM Parsers2018-10-14T10:00:00+02:00https://www.world-of-sample-news.com/newsticker/https://www.world-of-sample-news.com/icons/svg/logos/svg/World Of Sample Newsonline.svgCopyright (c) 2018 World Of Sample News MedienWorld Of Sample News onlineTitle 01: Standard Blind Text with 5000 chars Contenthttps://world-of-sample-news.com/-41704982018-10-14T10:00:00+02:002018-10-14T10:00:00+02:00Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequatLorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id purus. Ut varius tincidunt libero. Phasellus dolor. Maecenas vestibulum mollis diam. Pellentesque ut neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. In ac felis quis tortor malesuada pretium. Pellentesque auctor neque nec urna. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Aenean viverra rhoncus pede. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non enim eleifend felis pretium feugiat. Vivamus quis mi. Phasellus a est. Phasellus magna. In hac habitasse platea dictumst. Curabitur at lacus ac velit ornare lobortis. Curabitur a felis in nunc fringilla tristique. Morbi mattis ullamcorper velit. Phasellus gravida semper nisi. Nullam vel sem. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Sed hendrerit. Morbi ac felis. Nunc egestas, augue at pellentesque laoreet, felis eros vehicula leo, at malesuada velit leo quis pede. Donec interdum, metus et hendrerit aliquet, dolor diam sagittis ligula, eget egestas libero turpis vel mi. Nunc nulla. Fusce risus nisl, viverra et, tempor et, pretium in, sapien. Donec venenatis vulputate lorem. Morbi nec metus. Phasellus blandit leo ut odio. Maecenas ullamcorper, dui et placerat feugiat, eros pede varius nisi, condimentum viverra felis nunc et lorem. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. In auctor lobortis lacus. Quisque libero metus, condimentum nec, tempor a, commodo mollis, magna. Vestibulum ullamcorper mauris at ligulTitle 02: Blind Text with oöpoöp Charshttps://world-of-sample-news.com/-41881152018-10-14T09:00:00+02:002018-10-14T09:00:00+02:00aäb cde fgh ijk lmn oöpoöp tuü vwx yz AÄBC DEF GHI JKL MNO ÖPQ RST UÜV WXYZ !"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¼× {} aäb cde fgh ijk lmn oöp qrsß tuü vwx yz AÄBC DEF GHI JKL MNOaäb cde fgh ijk lmn oöpoöp tuü vwx yz AÄBC DEF GHI JKL MNO ÖPQ RST UÜV WXYZ !"§ $%& /() =?* '<> #|; ²³~ @`´ ©«» ¼× {} aäb cde fgh ijk lmn oöp qrsß tuü vwx yz AÄBC DEF GHI JKL MNOTitle 03: Atom-Powered Robots Run Amok, No Content!urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa622003-12-13T18:32:02ZSummary 03: Some other text.Title 04: Atom-Powered Robots Run Amok!urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa62Summary 04: Some other text.Content 04: Some more ContentTitle 05: Atom-Powered Robots Run Amok, No Summary!urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa622003-12-13T18:32:02ZContent 05: Some more Content
\ No newline at end of file
diff --git a/google-http-client/src/main/java/com/google/api/client/util/DataMap.java b/google-http-client/src/main/java/com/google/api/client/util/DataMap.java
index cf234d15c..3432c1827 100644
--- a/google-http-client/src/main/java/com/google/api/client/util/DataMap.java
+++ b/google-http-client/src/main/java/com/google/api/client/util/DataMap.java
@@ -43,7 +43,6 @@ final class DataMap extends AbstractMap {
DataMap(Object object, boolean ignoreCase) {
this.object = object;
classInfo = ClassInfo.of(object.getClass(), ignoreCase);
- Preconditions.checkArgument(!classInfo.isEnum());
}
@Override