List of usage examples for com.squareup.okhttp Response code
int code
To view the source code for com.squareup.okhttp Response code.
Click Source Link
From source file:org.hawkular.agent.ws.test.AbstractCommandITest.java
License:Apache License
protected String getWithRetries(String url, int attemptCount, long attemptDelay) throws Throwable { Throwable e = null;/*w w w . j ava2 s. c om*/ for (int i = 0; i < attemptCount; i++) { try { Request request = newAuthRequest().url(url).build(); Response response = client.newCall(request).execute(); AssertJUnit.assertEquals(200, response.code()); System.out.println("Got after " + (i + 1) + " retries: " + url); return response.body().string(); } catch (Throwable t) { /* some initial attempts may fail */ e = t; } System.out.println("URL [" + url + "] not ready yet on " + (i + 1) + " of " + attemptCount + " attempts, about to retry after " + attemptDelay + " ms"); Thread.sleep(attemptDelay); } if (e != null) { throw e; } else { throw new AssertionError("Could not get [" + url + "]"); } }
From source file:org.hawkular.apm.tests.dist.AbstractITest.java
License:Apache License
protected Response post(Server server, String path, String tenant, Object payload) throws IOException { Request.Builder request = new Request.Builder() .post(RequestBody.create(MEDIA_TYPE_JSON, serialize(server, payload))).url(server.getURL() + path); if (tenant != null) { request.addHeader(HAWKULAR_TENANT_HEADER, tenant); }// w w w .java 2 s .c o m Response response = execute(request.build(), server); switch (server) { case Zipkin: { Assert.assertEquals(202, response.code()); } } return response; }
From source file:org.hawkular.cmdgw.ws.test.AbstractCommandITest.java
License:Apache License
protected String getWithRetries(String url) throws Throwable { Throwable e = null;/*from w w w. j av a 2 s . c o m*/ for (int i = 0; i < ATTEMPT_COUNT; i++) { try { Request request = newAuthRequest().url(url).build(); Response response = client.newCall(request).execute(); AssertJUnit.assertEquals(200, response.code()); System.out.println("Got after " + (i + 1) + " retries: " + url); return response.body().string(); } catch (Throwable t) { /* some initial attempts may fail */ e = t; } System.out.println("URL [" + url + "] not ready yet on " + (i + 1) + " of " + ATTEMPT_COUNT + " attempts, about to retry after " + ATTEMPT_DELAY + " ms"); /* sleep one second */ Thread.sleep(ATTEMPT_DELAY); } if (e != null) { throw e; } else { throw new AssertionError("Could not get [" + url + "]"); } }
From source file:org.hawkular.commons.rest.status.itest.StatusEndpointITest.java
License:Apache License
@Test(groups = { GROUP }) public void testStatusEndpoint() throws IOException, InterruptedException { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder().addHeader("Accept", "application/json").url(statusUrl).build(); Response response = client.newCall(request).execute(); if (response.isSuccessful()) { String foundBody = response.body().string(); /* see src/test/resources/rest-status/MANIFEST.MF */ String expected = "{\"Implementation-Version\":\"1.2.3.4\","// + "\"Built-From-Git-SHA1\":\"cofeebabe\","// + "\"testKey1\":\"testValue1\"}"; Assert.assertEquals(foundBody, expected); } else {/*from w w w . j av a 2 s. c o m*/ Assert.fail("Could not get [" + statusUrl + "]: " + response.code() + " " + response.message()); } }
From source file:org.hawkular.datamining.itest.AbstractITest.java
License:Apache License
protected Response postNewEntity(String path, String tenant, Object payload) throws Throwable { String json = mapper.writeValueAsString(payload); Response response = post(path, tenant, json); assertThat(response.code(), is(201)); return response; }
From source file:org.hawkular.datamining.itest.HawkularDataminingITest.java
License:Apache License
@Test public void testPing() throws IOException { Response response = get(""); assertThat(response.code(), is(200)); }
From source file:org.hawkular.datamining.itest.HawkularDataminingITest.java
License:Apache License
@Test public void testModelLearnAndPredict() throws Throwable { // create/*from www .j ava 2 s. c o m*/ Metric.RestBlueprint blueprint = new Metric.RestBlueprint(metricId, 100L); postNewEntity("metrics", tenant, blueprint); // get Response responseGet = get("metrics", tenant); assertThat(responseGet.code(), is(200)); // learn List<DataPoint> dataPoints = dataPoints(1L, 60); Response responseLearn = post("metrics/" + metricId + "/forecaster/learn", tenant, dataPoints); assertThat(responseLearn.code(), is(204)); // predict int ahead = 5; Response responsePredict = get("metrics/" + metricId + "/forecaster/forecast?ahead=" + ahead, tenant); assertThat(responsePredict.code(), is(200)); List<DataPoint> predicted = parseResponseBody(responsePredict, new TypeReference<List<DataPoint>>() { }); assertThat(predicted.size(), is(ahead)); }
From source file:org.hawkular.datamining.itest.HawkularDataminingITest.java
License:Apache License
@Test public void testForecasterConfigUpdate() throws Throwable { String metricId = "metricForUpdate"; // create/* w w w . j ava 2 s . com*/ Metric.RestBlueprint blueprint = new Metric.RestBlueprint(metricId, 100L); postNewEntity("metrics", tenant, blueprint); // get Response responseGet = get("metrics", tenant); assertThat(responseGet.code(), is(200)); // learn List<DataPoint> dataPoints = dataPoints(1L, 60); Response responseLearn = post("metrics/" + metricId + "/forecaster/learn", tenant, dataPoints); assertThat(responseLearn.code(), is(204)); //change Forecaster.Update update = new Forecaster.Update(55, Model.SimpleExponentialSmoothing, InformationCriterion.BIC, new AutomaticForecaster.ErrorChangeStrategy(19, AutomaticForecaster.ErrorChangeStrategy.Statistics.MSE), null); Response responsePut = put("metrics/" + metricId + "/forecaster", tenant, update); assertThat(responsePut.code(), is(204)); }
From source file:org.hawkular.integration.test.AbstractTestBase.java
License:Apache License
protected void postNew(String path, Object payload) throws Throwable { String json = mapper.writeValueAsString(payload); Response response = post(path, json); Assert.assertEquals("Response msg: " + response.body().string(), 201, response.code()); }
From source file:org.hawkular.integration.test.AbstractTestBase.java
License:Apache License
protected String getWithRetries(String path, int attemptCount, long attemptDelay) throws Throwable { Throwable e = null;/*from ww w . ja v a 2s . c o m*/ String url = baseURI + path; for (int i = 0; i < attemptCount; i++) { try { Request request = newAuthRequest().url(url).build(); Response response = client.newCall(request).execute(); String responseBody = response.body().string(); Assert.assertEquals("Response msg: " + responseBody, 200, response.code()); System.out.println("Got after " + (i + 1) + " retries: " + url); return responseBody; } catch (Throwable t) { /* some initial attempts may fail */ e = t; } System.out.println("URL [" + url + "] not ready yet on " + (i + 1) + " of " + attemptCount + " attempts, about to retry after " + attemptDelay + " ms"); Thread.sleep(attemptDelay); } if (e != null) { throw e; } else { throw new AssertionError("Could not get [" + url + "]"); } }