Queries { public static Function<String, Multimap<String, String>> queryParser() { return parseQueryToDecodedMap; }  static Function<String, Multimap<String, String>> queryParser(); static String encodeQueryLine(Multimap<String, ?> queryParams); static String encodeQueryLine(Multimap<String, ?> queryParams, Iterable<Character> skips); static String buildQueryLine(Multimap<String, ?> queryParams);  }
@Test public void testParseQueryToMapSingleParam() { Multimap<String, String> parsedMap = queryParser().apply("v=1.3"); assert parsedMap.keySet().size() == 1 : "Expected 1 key, found: " + parsedMap.keySet().size(); assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys"; String valueForV = Iterables.getOnlyElement(parsedMap.get("v")); assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: " + valueForV; }
@Test public void testParseQueryToMapMultiParam() { Multimap<String, String> parsedMap = queryParser().apply("v=1.3&sig=123"); assert parsedMap.keySet().size() == 2 : "Expected 2 keys, found: " + parsedMap.keySet().size(); assert parsedMap.keySet().contains("v") : "Expected v to be a part of the keys"; assert parsedMap.keySet().contains("sig") : "Expected sig to be a part of the keys"; String valueForV = Iterables.getOnlyElement(parsedMap.get("v")); assert valueForV.equals("1.3") : "Expected the value for 'v' to be '1.3', found: " + valueForV; String valueForSig = Iterables.getOnlyElement(parsedMap.get("sig")); assert valueForSig.equals("123") : "Expected the value for 'v' to be '123', found: " + valueForSig; }
@Test public void testParseQueryEncodedWithDefaultJavaEncoder() { String key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCc903twxU2zcQnIJdXv61RwZNZW94uId9qz08fgsBJsCOnHNIC4+L9k" + "DOA2IHV9cUfEDBm1Be5TbpadWwSbS/05E+FARH2/MCO932UgcKUq5PGymS0249fLCBPci5zoLiG5vIym+1ij1hL/nHvkK99NIwe7io+Lmp" + "9OcF3PTsm3Rgh5T09cRHGX9horp0VoAVa9vKJx6C1/IEHVnG8p0YPPa1lmemvx5kNBEiyoNQNYa34EiFkcJfP6rqNgvY8h/j4nE9SXoUCC" + "/g6frhMFMOL0tzYqvz0Lczqm1Oh4RnSn3O9X4R934p28qqAobe337hmlLUdb6H5zuf+NwCh0HdZ"; Set<String> expected = ImmutableSet.of(key); Multimap<String, String> parsedMap = queryParser().apply("a=1&b=1+2&publickey=" + Strings2.urlEncode(key)); assertEquals(parsedMap.get("publickey"), expected); parsedMap = queryParser().apply("publickey=" + Strings2.urlEncode(key)); assertEquals(parsedMap.get("publickey"), expected); }
@Test public void testParseQueryWithKeysThatRequireDecoding() { Multimap<String, String> parsedMap = queryParser().apply("network%5B0%5D.id=23&network%5B0%5D.address=192.168.0.1"); assertEquals(parsedMap.get("network[0].id"), ImmutableSet.of("23")); assertEquals(parsedMap.get("network[0].address"), ImmutableSet.of("192.168.0.1")); }