Skip to content

Instantly share code, notes, and snippets.

@garystafford
Created February 17, 2016 14:46
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 garystafford/2a3f0f557636d4e3ed36 to your computer and use it in GitHub Desktop.
Save garystafford/2a3f0f557636d4e3ed36 to your computer and use it in GitHub Desktop.
/**
* Test of HTTP GET to read a single vehicle.
*/
@Test
public void testVehicleRead() {
String responseBody = "";
String output;
Boolean result = true;
Boolean expResult = true;
try {
URL url = new URL(getBaseUrlAndPort() + "/vehicles/" + getVehicleObjectId());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "Bearer " + getJwt());
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
// if not 200 response code then fail test
result = false;
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
while ((output = br.readLine()) != null) {
responseBody = output;
}
if (responseBody.length() < 1) {
// if response body is empty then fail test
result = false;
}
conn.disconnect();
} catch (IOException e) {
// if MalformedURLException, ConnectException, etc. then fail test
result = false;
}
assertEquals(expResult, result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment