RequestUrlBuilder { URL getDatasetsUrl(String projectId, String datasetName, boolean fetchResults, Map<String, ?> queryParams) throws KeenQueryClientException { try { StringBuilder url = createBaseDatasetsUrl(projectId); if (datasetName != null) { appendDatasetName(url, datasetName); if (fetchResults) { appendFetchResults(url); } } if (queryParams != null && !queryParams.isEmpty()) { appendQueryParams(url, queryParams); } return new URL(url.toString()); } catch (IOException ex) { Logger.getLogger(RequestUrlBuilder.class.getName()) .log(Level.SEVERE, "Failed to format dataset URL.", ex); throw new KeenQueryClientException("Failed to format dataset URL.", ex); } } RequestUrlBuilder(String apiVersion, String baseUrl);   }
@Test public void shouldCreateBasicDatasetUrl() { URL result = builder.getDatasetsUrl(PROJECT_ID, null, false, Collections.<String, Object>emptyMap()); assertThat(result.toString(), equalTo("https: }
@Test public void shouldCreateSpecificDatasetUrl() { URL result = builder.getDatasetsUrl(PROJECT_ID, DATASET, false, Collections.<String, Object>emptyMap()); assertThat(result.toString(), equalTo("https: }
@Test public void shouldCreateSpecificDatasetResultUrl() { URL result = builder.getDatasetsUrl(PROJECT_ID, DATASET, true, Collections.<String, Object>emptyMap()); assertThat(result.toString(), equalTo("https: }
@Test public void shouldAppendEncodedQueryParams() { Map<String, Object> queryParams = new HashMap<String, Object>() {{ put("key1", "value"); put("key2", "value?& <3"); put("key3", "¯\\_(ツ)_/¯"); }}; String encodedEntry1 = "key1=value"; String encodedEntry2 = "key2=value%3F%26+%3C3"; String encodedEntry3 = "key3=%C2%AF%5C_%28%E3%83%84%29_%2F%C2%AF"; URL result = builder.getDatasetsUrl(PROJECT_ID, DATASET, true, queryParams); assertThat(result.getQuery().length(), equalTo(encodedEntry1.length() + encodedEntry2.length() + encodedEntry3.length() + 2)); assertThat(result.getQuery(), containsString(encodedEntry1)); assertThat(result.getQuery(), containsString(encodedEntry2)); assertThat(result.getQuery(), containsString(encodedEntry3)); }