Esempio n. 1
0
  /*
         This test-case replicates a bug that occurs when using RibbonRequest with a query string.

         The querystrings would not be URL-encoded, leading to invalid HTTP-requests if the query string contained
         invalid characters (ex. space).
  */
  @Test
  public void urlEncodeQueryStringParameters() throws IOException, InterruptedException {
    String queryStringValue = "some string with space";
    String expectedQueryStringValue = "some+string+with+space";
    String expectedRequestLine = String.format("GET /?a=%s HTTP/1.1", expectedQueryStringValue);

    server1.enqueue(new MockResponse().setBody("success!"));

    getConfigInstance().setProperty(serverListKey(), hostAndPort(server1.getUrl("")));

    TestInterface api =
        Feign.builder()
            .client(RibbonClient.create())
            .target(TestInterface.class, "http://" + client());

    api.getWithQueryParameters(queryStringValue);

    final String recordedRequestLine = server1.takeRequest().getRequestLine();

    assertEquals(recordedRequestLine, expectedRequestLine);
  }