@Test public void testListen() throws Exception { Blade blade = Blade.of(); blade.listen(9001).start().await(); try { int code = Unirest.get("http://127.0.0.1:9001").asString().getStatus(); assertEquals(404, code); } finally { blade.stop(); try { new Socket("127.0.0.1", 9001); Assert.fail("Server is still running"); } catch (ConnectException e) { } } }
private void auth(KevoreeRegistryClient client) throws MojoExecutionException, UnirestException, KevoreeRegistryException { HttpResponse<RAuth> authRes = client.auth(login, password); if (authRes.getStatus() == 401) { throw new MojoExecutionException("You are not logged in"); } else { throw new MojoExecutionException("Something went wrong while authenticating " + login + " (status: " + authRes.getStatusText()+")"); } } }
@Test public void testListenAddress() throws Exception { Blade blade = Blade.of(); blade.listen("localhost", 9002).start().await(); try { int code = Unirest.get("http://localhost:9002/").asString().getStatus(); assertEquals(404, code); } finally { blade.stop(); } }
protected String extractErrorString(@NotNull HttpResponse httpResponse) { return String.format("Status:%d; Body: %s", httpResponse.getStatus(), httpResponse.getBody()); } }
@Override public void completed(HttpResponse<JsonNode> response) { int code = response.getStatus(); JsonNode body = response.getBody(); System.out.println("Status Code: " + code); System.out.println(body.toString()); }
@Override public void completed(HttpResponse<String> response) { int code = response.getStatus(); // Map<String, String> headers = response.getHeaders(); String body = response.getBody(); // InputStream rawBody = response.getRawBody();. log.info("body:" + body); }
protected boolean isAlive(String testUrl) { try { return Unirest.get(url + testUrl).asString().getStatus() == 200; } catch (UnirestException e) { return false; } }
public int deleteAllImposters() { try { HttpResponse<JsonNode> response = Unirest.delete(baseUrl + "/imposters").asJson(); return response.getStatus(); } catch (UnirestException e) { return 500; } }
public boolean isMountebankRunning() { try { HttpResponse<JsonNode> response = Unirest.get(baseUrl).asJson(); return response.getStatus() == 200; } catch (UnirestException e) { return false; } }
public int createImposter(Imposter imposter) { try { HttpResponse<JsonNode> response = Unirest.post(baseUrl + "/imposters").body(imposter.toString()).asJson(); return response.getStatus(); } catch (UnirestException e) { return 500; } }
protected void request(String url) throws StorageException { HttpResponse<String> response; try { response = Unirest.get(url).basicAuth(username, password).asString(); } catch (UnirestException e) { throw new StorageException("Unable to execute request on url " + url, e); } if (response.getStatus() != 200) { throw new StorageException("Wrong status code " + response.getStatus() + " when requesting url " + url); } }
private Optional<JsonNode> loadProviderJson(String dateTime) throws UnirestException { HttpRequest getRequest = Unirest.get(url + "/provider.json"); if (StringUtils.isNoneEmpty(dateTime)) { getRequest = getRequest.queryString("validDate", dateTime); } HttpResponse<JsonNode> jsonNodeHttpResponse = getRequest.asJson(); if (jsonNodeHttpResponse.getStatus() == 200) { return Optional.of(jsonNodeHttpResponse.getBody()); } else { return Optional.empty(); } }
public static HtmlAnalysisResult analyze(Map<String, String> config, String url) { try { String userAgent = config.getOrDefault(CONFIG_USER_AGENT, DEFAULT_USER_AGENT); HttpResponse<String> response = Unirest.get(url) .header("User-Agent", userAgent) .asString(); return analyze(config, url, response.getBody(), response.getStatus(), response.getHeaders()); } catch (UnirestException e) { throw new RuntimeException(e); } }
private static int registerServiceHttpClient(String body) throws UnirestException { HttpResponse<JsonNode> jsonResponse = Unirest.put(consulURL().toString() + "/" + CONSUL_URL_REGISTER_SERVICE) .header("accept", "application/json") .body(body) .asJson(); return jsonResponse.getStatus(); }
@Test public void shouldVerifyMountebankIsRunning() throws UnirestException { when(Unirest.get(Client.DEFAULT_BASE_URL)).thenReturn(getRequest); when(getRequest.asJson()).thenReturn(httpResponse); when(httpResponse.getStatus()).thenReturn(Integer.valueOf(200)); assertThat(client.isMountebankRunning()).isEqualTo(true); }
private void whenTheCapacityIsRetrievedForExchange(String exchangeCode) throws UnirestException { String apiPath = GetCapacityForExchangeEndpoint.API_PATH.replace("{exchangeCode}", exchangeCode); String apiUrl = "http://localhost:8080" + apiPath; log("API Url", apiUrl); HttpResponse<String> httpResponse = Unirest.get(apiUrl).asString(); responseStatus = httpResponse.getStatus(); log("Response Status", responseStatus); responseContent = httpResponse.getBody(); log("Response Content", formatJson(responseContent)); }
private void whenTheApiToGetTheDeviceDetailsIsCalledForThatDevice() throws UnirestException { String apiPath = GetBroadbandAccessDeviceEndpoint.API_PATH.replace("{hostname}", HOSTNAME); String apiUrl = "http://localhost:8080" + apiPath; log("API Url", apiUrl); HttpResponse<String> httpResponse = Unirest.get(apiUrl).asString(); responseStatus = httpResponse.getStatus(); log("Response Status", responseStatus); responseContent = httpResponse.getBody(); log("Response Content", formatJson(responseContent)); }
@Test public void shouldStartAndServeFile() throws UnknownHostException, UnirestException, InterruptedException { final SimpleFileServer simpleFileServer = new SimpleFileServer(TEST_FILE); simpleFileServer.run(); InetSocketAddress address = simpleFileServer.getAddress(); String serverAddress = NetworkUtils.addressToString(address, true); HttpResponse<String> response = Unirest.get(serverAddress + "/get").asString(); assertEquals(200, response.getStatus()); assertTrue(response.getBody().contains("This is a test file")); }