Skip to content

Instantly share code, notes, and snippets.

@hgoebl
Created January 16, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgoebl/af5b54f76bace9d50f43 to your computer and use it in GitHub Desktop.
Save hgoebl/af5b54f76bace9d50f43 to your computer and use it in GitHub Desktop.
Example using DavidWebb HTTP-Client for a stackoverflow question
package com.goebl.david;
public class TestWebb_LocalStackoverflow27980798 extends AbstractTestWebb {
public static final String BASE_URL = "https://domain.com";
public static final String API_VER = "/v1";
public void testDownload() throws Exception {
String token = "token12345";
Webb webb = Webb.create();
webb.setBaseUri(BASE_URL + API_VER);
Response<String> response = webb
.get("/resource")
.param("token", token)
.header("Accept-Charset", "UTF-8")
.asString();
assertEquals(200, response.getStatusCode());
assertNotNull(response.getBody());
assertTrue(response.getBody().contains("some text of the body"));
}
public void testDownloadShort() throws Exception {
String token = "token12345";
Webb webb = Webb.create();
webb.setBaseUri(BASE_URL + API_VER);
String xml = webb
.get("/resource")
.param("token", token)
.header("Accept-Charset", "UTF-8")
.asString()
.getBody();
assertTrue(xml.contains("some text of the body"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment