com.google.api.client.util.ArrayMap Java Examples

The following examples show how to use com.google.api.client.util.ArrayMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleVideosInterface.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
private String generateParamsString(Optional<Map<String, String>> params) throws IOException {
  Map<String, String> updatedParams = new ArrayMap<>();
  if (params.isPresent()) {
    updatedParams.putAll(params.get());
  }

  // getAccessToken will return null when the token needs to be refreshed
  if (credential.getAccessToken() == null) {
    credential.refreshToken();
  }

  updatedParams.put(ACCESS_TOKEN_KEY, Preconditions.checkNotNull(credential.getAccessToken()));

  List<String> orderedKeys = updatedParams.keySet().stream().collect(Collectors.toList());
  Collections.sort(orderedKeys);

  List<String> paramStrings = new ArrayList<>();
  for (String key : orderedKeys) {
    String k = key.trim();
    String v = updatedParams.get(key).trim();

    paramStrings.add(k + "=" + v);
  }
  return String.join("&", paramStrings);
}
 
Example #2
Source File: GooglePhotosInterface.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
private String generateParamsString(Optional<Map<String, String>> params) {
  Map<String, String> updatedParams = new ArrayMap<>();
  if (params.isPresent()) {
    updatedParams.putAll(params.get());
  }

  updatedParams.put(ACCESS_TOKEN_KEY, Preconditions.checkNotNull(credential.getAccessToken()));

  List<String> orderedKeys = updatedParams.keySet().stream().collect(Collectors.toList());
  Collections.sort(orderedKeys);

  List<String> paramStrings = new ArrayList<>();
  for (String key : orderedKeys) {
    String k = key.trim();
    String v = updatedParams.get(key).trim();

    paramStrings.add(k + "=" + v);
  }

  return String.join("&", paramStrings);
}
 
Example #3
Source File: AbstractJsonFactoryTest.java    From google-http-java-client with Apache License 2.0 6 votes vote down vote up
public void testParser_hashmapForMapType() throws Exception {
  // parse
  JsonFactory factory = newFactory();
  JsonParser parser;
  parser = factory.createJsonParser(MAP_TYPE);
  parser.nextToken();
  @SuppressWarnings("unchecked")
  HashMap<String, ArrayList<ArrayMap<String, ArrayMap<String, BigDecimal>>>> result =
      parser.parse(HashMap.class);
  // serialize
  assertEquals(MAP_TYPE, factory.toString(result));
  // check parsed result
  ArrayList<ArrayMap<String, ArrayMap<String, BigDecimal>>> value = result.get("value");
  ArrayMap<String, ArrayMap<String, BigDecimal>> firstMap = value.get(0);
  ArrayMap<String, BigDecimal> map1 = firstMap.get("map1");
  BigDecimal integer = map1.get("k1");
  assertEquals(1, integer.intValue());
}
 
Example #4
Source File: DataflowMetricsTest.java    From beam with Apache License 2.0 6 votes vote down vote up
private MetricUpdate makeDistributionMetricUpdate(
    String name,
    String namespace,
    String step,
    Long sum,
    Long count,
    Long min,
    Long max,
    boolean tentative) {
  MetricUpdate update = new MetricUpdate();
  ArrayMap<String, BigDecimal> distribution = ArrayMap.create();
  distribution.add("count", new BigDecimal(count));
  distribution.add("mean", new BigDecimal(sum / count));
  distribution.add("sum", new BigDecimal(sum));
  distribution.add("min", new BigDecimal(min));
  distribution.add("max", new BigDecimal(max));
  update.setDistribution(distribution);
  return setStructuredName(update, name, namespace, step, tentative);
}
 
Example #5
Source File: XmlListTest.java    From google-http-java-client with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #6
Source File: GenericXmlListTest.java    From google-http-java-client with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example #7
Source File: GoogleAtom.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Compute the patch object of key/value pairs from the given original and patched objects, adding
 * a {@code @gd:fields} key for the fields mask.
 *
 * @param patched patched object
 * @param original original object
 * @return patch object of key/value pairs
 */
public static Map<String, Object> computePatch(Object patched, Object original) {
  FieldsMask fieldsMask = new FieldsMask();
  ArrayMap<String, Object> result = computePatchInternal(fieldsMask, patched, original);
  if (fieldsMask.numDifferences != 0) {
    result.put("@gd:fields", fieldsMask.buf.toString());
  }
  return result;
}
 
Example #8
Source File: AbstractJsonFactoryTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void testParser_heterogeneousSchema_genericJson() throws Exception {
  JsonFactory factory = newFactory();
  JsonParser parser = factory.createJsonParser(DOG_EXTRA_INFO);
  AnimalGenericJson dog = parser.parse(AnimalGenericJson.class);
  assertEquals(DOG_EXTRA_INFO_ORDERED, factory.toString(dog));
  assertEquals(DogGenericJson.class, dog.getClass());
  assertEquals("Fido", dog.name);
  assertEquals("dog", dog.type);
  assertEquals(4, dog.numberOfLegs);
  assertEquals(3, ((DogGenericJson) dog).tricksKnown);
  assertEquals("this is not being used!", dog.get("unusedInfo"));
  BigDecimal foo = ((BigDecimal) ((ArrayMap<String, Object>) dog.get("unused")).get("foo"));
  assertEquals(200, foo.intValue());
}
 
Example #9
Source File: UrlEncodedContentTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
public void testWriteTo() throws IOException {
  subtestWriteTo("a=x", ArrayMap.of("a", "x"));
  subtestWriteTo("noval", ArrayMap.of("noval", ""));
  subtestWriteTo("multi=a&multi=b&multi=c", ArrayMap.of("multi", Arrays.asList("a", "b", "c")));
  subtestWriteTo("multi=a&multi=b&multi=c", ArrayMap.of("multi", new String[] {"a", "b", "c"}));
  // https://github.com/googleapis/google-http-java-client/issues/202
  final Map<String, String> params = new LinkedHashMap<String, String>();
  params.put("username", "un");
  params.put("password", "password123;{}");
  subtestWriteTo("username=un&password=password123%3B%7B%7D", params);
}
 
Example #10
Source File: UrlEncodedParserTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
public void testParse_encoding() {
  ArrayMap<String, Object> actual = new ArrayMap<String, Object>();
  UrlEncodedParser.parse("q=%20", actual);
  ArrayMap<String, Object> expected = ArrayMap.create();
  expected.add("q", Collections.singletonList(" "));
  assertEquals(expected, actual);
}
 
Example #11
Source File: UrlEncodedParserTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
public void testParse_map() {
  ArrayMap<String, Object> actual = new ArrayMap<String, Object>();
  UrlEncodedParser.parse("p=4&q=1&a=x&p=3&b=y&c=z&d=v&q=2&p=5&noval1&noval2=", actual);
  ArrayMap<String, Object> expected = ArrayMap.create();
  expected.add("p", Arrays.asList("4", "3", "5"));
  expected.add("q", Arrays.asList("1", "2"));
  expected.add("a", Collections.singletonList("x"));
  expected.add("b", Collections.singletonList("y"));
  expected.add("c", Collections.singletonList("z"));
  expected.add("d", Collections.singletonList("v"));
  expected.add("noval1", Collections.singletonList(""));
  expected.add("noval2", Collections.singletonList(""));
  assertEquals(expected, actual);
  assertEquals(ArrayList.class, actual.get("a").getClass());
}
 
Example #12
Source File: GenericXmlTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
/**
 * The purpose of this test is to parse the given XML into a {@link GenericXml} Object that has no
 * fixed structure.
 */
@SuppressWarnings("unchecked")
@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<String, String> 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<GenericXml> foo = (Collection<GenericXml>) xml.get("entry");
  assertEquals(2, foo.size());
  ArrayMap<String, String> singleElementOne = ArrayMap.of("text()", "One");
  List<ArrayMap<String, String>> testOne = new ArrayList<ArrayMap<String, String>>();
  testOne.add(singleElementOne);
  assertEquals("abc", foo.toArray(new ArrayMap[] {})[0].get("@gd:etag"));
  assertEquals(testOne, foo.toArray(new ArrayMap[] {})[0].get("title"));
  ArrayMap<String, String> singleElementTwoAttrib =
      ArrayMap.of("@attribute", "someattribute", "text()", "Two");
  // ArrayMap<String, String> singleElementTwoValue =ArrayMap.of();
  List<ArrayMap<String, String>> testTwo = new ArrayList<ArrayMap<String, String>>();
  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"));
}
 
Example #13
Source File: YouTubeComment.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
public YouTubeComment(com.google.api.services.youtube.model.Comment comment) {
	if (comment.getSnippet() != null) {
		this.author = comment.getSnippet().getAuthorDisplayName();
		ArrayMap<String, String> channelIdMap = (ArrayMap<String, String>)comment.getSnippet().getAuthorChannelId();
		if(channelIdMap != null)
			this.authorChannelId = channelIdMap.get("value");
		this.comment = comment.getSnippet().getTextDisplay();
		this.datePublished = new PrettyTimeEx().format(comment.getSnippet().getPublishedAt());
		this.likeCount = comment.getSnippet().getLikeCount();
		this.thumbnailUrl = comment.getSnippet().getAuthorProfileImageUrl();
	}
}
 
Example #14
Source File: DataflowMetrics.java    From beam with Apache License 2.0 5 votes vote down vote up
private DistributionResult getDistributionValue(MetricUpdate metricUpdate) {
  if (metricUpdate.getDistribution() == null) {
    return DistributionResult.IDENTITY_ELEMENT;
  }
  ArrayMap distributionMap = (ArrayMap) metricUpdate.getDistribution();
  long count = ((Number) distributionMap.get("count")).longValue();
  long min = ((Number) distributionMap.get("min")).longValue();
  long max = ((Number) distributionMap.get("max")).longValue();
  long sum = ((Number) distributionMap.get("sum")).longValue();
  return DistributionResult.create(sum, count, min, max);
}
 
Example #15
Source File: YouTubeObject.java    From youtube-comment-suite with MIT License 5 votes vote down vote up
/**
 * For some reason this value returns as an ArrayMap? Cast and return correct value from it.
 *
 * @return channelId
 */
static String getChannelIdFromObject(Object authorChannelId) {
    if (authorChannelId instanceof ArrayMap) {
        ArrayMap<String, String> value = (ArrayMap) authorChannelId;

        return value.get("value");
    }
    return authorChannelId.toString();
}
 
Example #16
Source File: FirebaseTokenVerifierImpl.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
private boolean containsLegacyUidField(IdToken.Payload payload) {
  Object dataField = payload.get("d");
  if (dataField instanceof ArrayMap) {
    return ((ArrayMap) dataField).get("uid") != null;
  }
  return false;
}
 
Example #17
Source File: GenericXmlListTest.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
/** 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<String, String>) (rep[0].values().toArray(new ArrayList[] {})[0].get(0)))
          .getKey(0));
  assertEquals(
      "content1",
      ((ArrayMap<String, String>) (rep[0].values().toArray(new ArrayList[] {})[0].get(0)))
          .getValue(0));
  assertEquals(
      "text()",
      ((ArrayMap<String, String>) (rep[1].values().toArray(new ArrayList[] {})[0].get(0)))
          .getKey(0));
  assertEquals(
      "content2",
      ((ArrayMap<String, String>) (rep[1].values().toArray(new ArrayList[] {})[0].get(0)))
          .getValue(0));
  assertEquals(
      "text()",
      ((ArrayMap<String, String>) (rep[2].values().toArray(new ArrayList[] {})[0].get(0)))
          .getKey(0));
  assertEquals(
      "content3",
      ((ArrayMap<String, String>) (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());
}
 
Example #18
Source File: GenericXmlListTest.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
/** 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<String, String>) (rep[0].values().toArray(new ArrayList[] {})[0].get(0)))
          .getKey(0));
  assertEquals(
      "content1",
      ((ArrayMap<String, String>) (rep[0].values().toArray(new ArrayList[] {})[0].get(0)))
          .getValue(0));
  assertEquals(
      "text()",
      ((ArrayMap<String, String>) (rep[1].values().toArray(new ArrayList[] {})[0].get(0)))
          .getKey(0));
  assertEquals(
      "content2",
      ((ArrayMap<String, String>) (rep[1].values().toArray(new ArrayList[] {})[0].get(0)))
          .getValue(0));
  assertEquals(
      "text()",
      ((ArrayMap<String, String>) (rep[2].values().toArray(new ArrayList[] {})[0].get(0)))
          .getKey(0));
  assertEquals(
      "content3",
      ((ArrayMap<String, String>) (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());
}
 
Example #19
Source File: XmlTest.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
/**
 * 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());
}
 
Example #20
Source File: GenericXmlTest.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
/** 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<GenericXml> repList = (Collection<GenericXml>) xml.elem.get("rep");
  assertEquals(2, repList.size());
  Collection<GenericXml> repValue = (Collection<GenericXml>) 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());
}
 
Example #21
Source File: UrlEncodedParserTest.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
public void testParse_null() {
  ArrayMap<String, Object> actual = new ArrayMap<String, Object>();
  UrlEncodedParser.parse((String) null, actual);
  assertTrue(actual.isEmpty());
}