コード例 #1
0
ファイル: Client.java プロジェクト: bdecoste/ce-testsuite
  public String get(String key, Map<String, String> headers) {
    try {
      String url = basicUrl;
      if (key != null) {
        url = basicUrl + "/" + key;
        if (basicUrl.endsWith("/")) url = basicUrl + key;
      }

      HttpRequest request = HttpClientBuilder.doGET(url);

      if (headers != null) {
        for (Map.Entry<String, String> header : headers.entrySet())
          request.setHeader(header.getKey(), header.getValue());
      }

      HttpResponse response = client.execute(request);

      int statusCode = response.getResponseCode();
      log.warning("Response Code : " + statusCode);

      return response.getResponseBodyAsString();
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
コード例 #2
0
  private JSONObject getPerson(int id) throws Exception {
    HttpClient client = HttpClientBuilder.untrustedConnectionClient();
    HttpRequest request = HttpClientBuilder.doGET(getUrl() + "/rest/members/" + id);
    HttpResponse response = client.execute(request, execOptions);

    JSONParser jsonParser = new JSONParser();
    return (JSONObject) jsonParser.parse(response.getResponseBodyAsString());
  }
コード例 #3
0
  @Test
  @RunAsClient
  @InSequence(1)
  public void testInitialState() throws Exception {
    log.info("Trying URL " + getUrl());
    HttpClient client = HttpClientBuilder.untrustedConnectionClient();
    HttpRequest request = HttpClientBuilder.doGET(getUrl() + "/rest/members");
    HttpResponse response = client.execute(request, execOptions);

    JSONParser jsonParser = new JSONParser();
    JSONArray array = (JSONArray) jsonParser.parse(response.getResponseBodyAsString());
    assertEquals(array.size(), 1);

    JSONObject remotePerson = getPerson(0);
    Person localPerson = new Person(0, "John Smith", "*****@*****.**", "2125551212");
    assertPeopleAreSame(remotePerson, localPerson);
  }