@Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { if (request.getPath().startsWith("/notifications/v2")) { String notifications = request.getRequestUrl().queryParameter("notifications"); return new MockResponse().setResponseCode(200).setBody(mockLongPollBody(notifications)); } else if (request.getPath().startsWith("/configs")) { List<String> pathSegments = request.getRequestUrl().pathSegments(); // appId and cluster might be used in the future String appId = pathSegments.get(1); String cluster = pathSegments.get(2); String namespace = pathSegments.get(3); return new MockResponse().setResponseCode(200).setBody(loadConfigFor(namespace)); } return new MockResponse().setResponseCode(404); } };
String code = requestUrl.queryParameter("code"); String stateString = requestUrl.queryParameter("state"); ByteString state = stateString != null ? ByteString.decodeBase64(stateString) : null;
@Test public void download_compressed_and_add_uncompressed_to_cache_if_missing() throws Exception { FileAndMd5 jar = new FileAndMd5(); enqueueCompressedDownload(jar, true); InstalledPlugin plugin = newInstalledPlugin("foo", jar.md5); File result = underTest.get(plugin).get(); verifySameContentAfterCompression(jar.file, result); RecordedRequest recordedRequest = server.takeRequest(); assertThat(recordedRequest.getRequestUrl().queryParameter("acceptCompressions")).isEqualTo("pack200"); // get from cache on second call result = underTest.get(plugin).get(); verifySameContentAfterCompression(jar.file, result); assertThat(server.getRequestCount()).isEqualTo(1); }
private static AttributeSet extractQueryParameters(HttpUrl url) { AttributeSet attributes = new AttributeSet(); String labelSelector = url.queryParameter("labelSelector"); if (labelSelector != null) { for (String requirement : labelSelector.split(",")) { Matcher m = LABEL_REQUIREMENT_EQUALITY.matcher(requirement); if (m.matches()) { attributes = attributes.add(new Attribute(LABEL_KEY_PREFIX + m.group(KEY), m.group(VALUE))); } else { LOGGER.warn("Ignoring unsupported label requirement: {}", requirement); } } } return attributes; }
static String queryParam(String url, String name) { HttpUrl httpUrl = HttpUrl.parse(url); if (httpUrl == null) { return null; } return httpUrl.queryParameter(name); } }
static String queryParam(String url, String name) { HttpUrl httpUrl = HttpUrl.parse(url); if (httpUrl == null) { return null; } return httpUrl.queryParameter(name); } }
@Override protected String getText(Request request) { return request.url().queryParameter(param); }
@Nullable private String parseLinkHeader(@NotNull String header) { int start = header.indexOf("<") + 1; int end = header.lastIndexOf(">"); if (start <= 0 || end < 0 || end >= header.length() || start >= end) { return null; } HttpUrl url = HttpUrl.parse(FAKE_URL + header.substring(start, end)); if (url == null) { return null; } return url.queryParameter(KEY_LAST); }
private boolean matchesParameter(HttpUrl url, Description mismatchDescription) { String value = url.queryParameter(paramKey); if (value != null && !value.equals(paramValue) || value == null && paramValue != null) { mismatchDescription.appendText("value was ").appendValue(value); return false; } return true; }
@Test public void geocodingTypes_getsAddedToUrlCorrectly() throws Exception { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .geocodingTypes(GeocodingCriteria.TYPE_COUNTRY, GeocodingCriteria.TYPE_DISTRICT) .query("1600 pennsylvania ave nw") .build(); assertEquals("country,district", mapboxGeocoding.cloneCall().request().url().queryParameter("types")); }
@Test public void language_getsConvertedToUrlCorrectly() throws Exception { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .languages(Locale.ENGLISH, Locale.FRANCE) .query("1600 pennsylvania ave nw") .build(); assertEquals("en,fr", mapboxGeocoding.cloneCall().request().url().queryParameter("language")); }
@Test public void proximity_doesGetAddedToUrlCorrectly() throws Exception { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .query("1600 pennsylvania ave nw") .proximity(Point.fromLngLat(-77.03655, 38.89770)) .build(); assertEquals("-77.03655,38.8977", mapboxGeocoding.cloneCall().request().url().queryParameter("proximity")); }
@Test public void country_localeCountryHandlesMultipleCountriesCorrectly() throws Exception { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .country(Locale.US) .country(Locale.CANADA) .query(Point.fromLngLat(-77.03655, 38.89770)) .build(); assertEquals("US,CA", mapboxGeocoding.cloneCall().request().url().queryParameter("country")); }
@Test public void bbox_getsFormattedCorrectlyForUrl() throws Exception { MapboxGeocoding mapboxGeocoding = MapboxGeocoding.builder() .accessToken(ACCESS_TOKEN) .baseUrl(mockUrl.toString()) .bbox( Point.fromLngLat(-77.083056, 38.908611), Point.fromLngLat(-76.997778, 38.959167) ) .query("1600 pennsylvania ave nw") .build(); assertEquals("-77.083056,38.908611,-76.997778,38.959167", mapboxGeocoding.cloneCall().request().url().queryParameter("bbox")); }
@Test public void radiuses_doesGetFormattedInUrlCorrectly() throws Exception { MapboxDirections directions = MapboxDirections.builder() .destination(Point.fromLngLat(13.4930, 9.958)) .origin(Point.fromLngLat(1.234, 2.345)) .radiuses(23, 30) .accessToken(ACCESS_TOKEN) .build(); assertEquals("23;30", directions.cloneCall().request().url().queryParameter("radiuses")); }
@Test public void addBearing_doesGetFormattedInUrlCorrectly() throws Exception { MapboxDirections directions = MapboxDirections.builder() .destination(Point.fromLngLat(13.4930, 9.958)) .origin(Point.fromLngLat(1.234, 2.345)) .addBearing(45d, 90d) .addBearing(2d, 90d) .accessToken(ACCESS_TOKEN) .build(); assertEquals("45,90;2,90", directions.cloneCall().request().url().queryParameter("bearings")); }
@Test public void annotations_doesGetFormattedInUrlCorrectly() throws Exception { MapboxDirections directions = MapboxDirections.builder() .destination(Point.fromLngLat(13.4930, 9.958)) .origin(Point.fromLngLat(1.234, 2.345)) .annotations(DirectionsCriteria.ANNOTATION_CONGESTION, DirectionsCriteria.ANNOTATION_DURATION) .overview(DirectionsCriteria.OVERVIEW_FULL) .accessToken(ACCESS_TOKEN) .build(); assertEquals("congestion,duration", directions.cloneCall().request().url().queryParameter("annotations")); }
@Test public void radiuses_doesShowInUrlCorrectly() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.1234, 3.3456)) .coordinate(Point.fromLngLat(90.10293, 7.10293)) .coordinate(Point.fromLngLat(100.10203, 84.039)) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .radiuses(1d, 2d, 3d) .build(); assertEquals("1.0;2.0;3.0", mapMatching.cloneCall().request().url().queryParameter("radiuses")); }
@Test public void timestamps_doesShowInUrlCorrectly() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder() .coordinate(Point.fromLngLat(2.1234, 3.3456)) .coordinate(Point.fromLngLat(90.10293, 7.10293)) .coordinate(Point.fromLngLat(100.10203, 84.039)) .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .timestamps("1", "2", "3") .build(); assertEquals("1;2;3", mapMatching.cloneCall().request().url().queryParameter("timestamps")); }
@Test public void sanityWaypointNamesInstructions() throws Exception { MapboxDirections mapboxDirections = MapboxDirections.builder() .origin(Point.fromLngLat(1.0, 1.0)) .addWaypoint(Point.fromLngLat(2.0, 2.0)) .destination(Point.fromLngLat(4.0, 4.0)) .addWaypointNames("Home", "Store", "Work") .baseUrl("https://foobar.com") .accessToken(ACCESS_TOKEN) .build(); assertNotNull(mapboxDirections); assertEquals("Home;Store;Work", mapboxDirections.cloneCall().request().url().queryParameter("waypoint_names")); }