Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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