Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #836 from Jiri-Kremser/itests-http-response-msgs
Browse files Browse the repository at this point in the history
more informative itests failures
  • Loading branch information
pilhuhn committed Feb 10, 2016
2 parents 4d7b15a + 6f2bc41 commit 5991b70
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected static Request.Builder newAuthRequest() {
protected void postNew(String path, Object payload) throws Throwable {
String json = mapper.writeValueAsString(payload);
Response response = post(path, json);
Assert.assertEquals(201, response.code());
Assert.assertEquals("Response msg: " + response.body().string(), 201, response.code());
}

protected Response post(String path, String payload) throws Throwable {
Expand All @@ -104,9 +104,10 @@ protected String getWithRetries(String path, int attemptCount, long attemptDelay
try {
Request request = newAuthRequest().url(url).build();
Response response = client.newCall(request).execute();
Assert.assertEquals(200, response.code());
String responseBody = response.body().string();
Assert.assertEquals("Response msg: " + responseBody, 200, response.code());
System.out.println("Got after " + (i + 1) + " retries: " + url);
return response.body().string();
return responseBody;
} catch (Throwable t) {
/* some initial attempts may fail */
e = t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class Scenario1ITest extends AbstractTestBase {
public void testScenario() throws Throwable {
Persona persona = getWithRetries("/hawkular/accounts/personas/current", HawkularUser.class, 10, 2000);
String tenantId = persona.getIdAsUUID().toString();
Assert.assertTrue("Cannot get the current tenant id.", tenantId != null && !tenantId.trim().isEmpty());

/* assert the test environment exists */
/* There is a race condition when WildFly agent is enabled:
Expand All @@ -64,21 +65,23 @@ public void testScenario() throws Throwable {
*/
String path = "/hawkular/inventory/environments/" + environmentId;
Environment env = getWithRetries(path, Environment.class, 10, 2000);
Assert.assertEquals(environmentId, env.getId());
Assert.assertEquals("Unable to get the '" + environmentId + "' environment.", environmentId, env.getId());

/* assert the URL resource type exists */
path = "/hawkular/inventory/resourceTypes/" + urlTypeId;
ResourceType resourceType = getWithRetries(path, ResourceType.class, 10, 2000);
Assert.assertEquals(urlTypeId, resourceType.getId());
Assert.assertEquals("Unable to get the '" + urlTypeId + "' resource type.", urlTypeId, resourceType.getId());

/* assert the metric types exist */
path = "/hawkular/inventory/metricTypes/" + statusCodeTypeId;
MetricType statusCodeType = getWithRetries(path, MetricType.class, 10, 2000);
Assert.assertEquals(statusCodeTypeId, statusCodeType.getId());
Assert.assertEquals("Unable to get the '" + statusCodeTypeId + "' metric type.", statusCodeTypeId,
statusCodeType.getId());

path = "/hawkular/inventory/metricTypes/" + durationTypeId;
MetricType durationType = getWithRetries(path, MetricType.class, 10, 2000);
Assert.assertEquals(durationTypeId, durationType.getId());
Assert.assertEquals("Unable to get the '" + durationTypeId + "' metric type.", durationTypeId, durationType
.getId());

/* create a URL */
String resourceId = UUID.randomUUID().toString();
Expand All @@ -104,7 +107,7 @@ public void testScenario() throws Throwable {
Response response = post("/hawkular/inventory/" + environmentId + "/resources/" + resourceId + "/metrics",
"[\"/e;" + environmentId + "/m;" + statusCodeId + "\", \"/e;" + environmentId + "/m;" + durationId
+ "\"]");
Assert.assertEquals(204, response.code());
Assert.assertEquals("Response msg: " + response.body().string(), 204, response.code());

/* Pinger should start pinging now but we do not want to wait */

Expand Down Expand Up @@ -137,14 +140,14 @@ public void testScenario() throws Throwable {
}

for (int i = -30; i < -3; i++) {
postMetricValue(tenantId, resourceId, statusCodeId, 100 + i, i);
postMetricValue(tenantId, resourceId, durationId, 200, i);
postMetricValue(resourceId, statusCodeId, 100 + i, i);
postMetricValue(resourceId, durationId, 200, i);
}

postMetricValue(tenantId, resourceId, statusCodeId, 500, -2);
postMetricValue(tenantId, resourceId, statusCodeId, 404, -1);
postMetricValue(tenantId, resourceId, statusCodeId, 200, 0);
postMetricValue(tenantId, resourceId, statusCodeId, 42, 0);
postMetricValue(resourceId, statusCodeId, 500, -2);
postMetricValue(resourceId, statusCodeId, 404, -1);
postMetricValue(resourceId, statusCodeId, 200, 0);
postMetricValue(resourceId, statusCodeId, 42, 0);

/* Get values for a chart - last 4h data */
long end = System.currentTimeMillis();
Expand Down Expand Up @@ -180,14 +183,14 @@ static void cleanUp() throws IOException {
for (int i = pathsToDelete.size() - 1; i >= 0; i--) {
String path = pathsToDelete.get(i);
Response response = client.newCall(newAuthRequest().url(baseURI + path).delete().build()).execute();
Assert.assertEquals(204, response.code());
Assert.assertEquals("Response msg: " + response.body().string(), 204, response.code());

response = client.newCall(newAuthRequest().url(baseURI + path).build()).execute();
Assert.assertEquals(404, response.code());
Assert.assertEquals("Response msg: " + response.body().string(), 404, response.code());
}
}

private void postMetricValue(String tenantId, String resourceId, String metricName, int value, int timeSkewMinutes)
private void postMetricValue(String resourceId, String metricName, int value, int timeSkewMinutes)
throws IOException {
long now = System.currentTimeMillis();
String tmp = resourceId + "." + metricName;
Expand All @@ -199,6 +202,6 @@ private void postMetricValue(String tenantId, String resourceId, String metricNa
Request request = newAuthRequest().url(baseURI + path)
.post(RequestBody.create(MEDIA_TYPE_JSON, json)).build();
Response response = client.newCall(request).execute();
Assert.assertEquals(200, response.code());
Assert.assertEquals("Response msg: " + response.body().string(), 200, response.code());
}
}

0 comments on commit 5991b70

Please sign in to comment.