List of usage examples for org.apache.http.client.fluent Request Get
public static Request Get(final String uri)
From source file:org.wildfly.swarm.test.HelloServletIT.java
@Test public void test() throws IOException { String response = Request.Get("http://localhost:8080/servlet").execute().returnContent().asString(); assertEquals("Hello from servlet\n", response); }
From source file:com.triage.radium.testweb.it.ITTestWeb.java
@Test public void testRuntimeExecListsDirectory() throws Exception { Response resp = Request.Get(WEBAPP_BASE_URL + "/runtimeExec").execute(); String resultText = resp.returnContent().toString(); assertTrue(resultText.contains("SUCCESS")); }
From source file:org.mule.module.oauth2.internal.authorizationcode.functional.AuthorizationCodeMinimalConfigTestCase.java
@Ignore("MULE-6926: flaky test") @Test/* w w w . j a va2 s . c o m*/ public void hitRedirectUrlAndGetToken() throws Exception { configureWireMockToExpectTokenPathRequestForAuthorizationCodeGrantType(); Request.Get(redirectUrl.getValue() + "?" + OAuthConstants.CODE_PARAMETER + "=" + AUTHENTICATION_CODE) .connectTimeout(REQUEST_TIMEOUT).socketTimeout(REQUEST_TIMEOUT).execute(); verifyRequestDoneToTokenUrlForAuthorizationCode(); OAuthContextFunctionAsserter.createFrom(muleContext.getExpressionLanguage(), "tokenManagerConfig") .assertAccessTokenIs(ACCESS_TOKEN).assertRefreshTokenIs(REFRESH_TOKEN); }
From source file:es.uvigo.esei.dai.hybridserver.utils.TestUtils.java
/** * Realiza una peticin por GET y devuelve el contenido de la respuesta. * /*from ww w. j a v a2 s. c o m*/ * La peticin se hace en UTF-8 y solicitando el cierre de la conexin. * * Este mtodo comprueba que el cdigo de respuesta HTTP sea 200 OK. * * @param url URL de la pgina solicitada. * @return contenido de la respuesta HTTP. * @throws IOException en el caso de que se produzca un error de conexin. */ public static String getContent(String url) throws IOException { final HttpResponse response = Request.Get(url).addHeader("Connection", "close") .addHeader("Content-encoding", "UTF-8").execute().returnResponse(); assertEquals(200, response.getStatusLine().getStatusCode()); return EntityUtils.toString(response.getEntity()); }
From source file:com.blade.BladeTestCase.java
@SuppressWarnings("resource") @Test/*w w w. ja va 2s . c om*/ public void testStartStopServer() throws Exception { Blade blade = Blade.me(); blade.listen(10241).start(); try { HttpResponse response = Request.Get("http://localhost:10241/").execute().returnResponse(); Assert.assertEquals(response.getStatusLine().getStatusCode(), 404); } finally { blade.stop(); try { new Socket("localhost", 10241); Assert.fail("Server is still running"); } catch (ConnectException e) { } } }
From source file:org.mule.module.oauth2.internal.authorizationcode.functional.AuthorizationCodeNoTokenManagerConfigTestCase.java
@Test public void hitRedirectUrlAndGetToken() throws Exception { configureWireMockToExpectTokenPathRequestForAuthorizationCodeGrantType(); Request.Get(redirectUrl.getValue() + "?" + OAuthConstants.CODE_PARAMETER + "=" + AUTHENTICATION_CODE) .connectTimeout(REQUEST_TIMEOUT).socketTimeout(REQUEST_TIMEOUT).execute(); verifyRequestDoneToTokenUrlForAuthorizationCode(); TokenManagerConfig tokenManagerConfig = muleContext.getRegistry().lookupObject(TokenManagerConfig.class); final ResourceOwnerOAuthContext oauthContext = tokenManagerConfig.getConfigOAuthContext() .getContextForResourceOwner(ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID); assertThat(oauthContext.getAccessToken(), Is.is(ACCESS_TOKEN)); assertThat(oauthContext.getRefreshToken(), Is.is(REFRESH_TOKEN)); }
From source file:org.mule.module.http.functional.listener.HttpAllInterfacesTestCase.java
@Test public void testAllInterfaces() throws IOException { final String url = String.format("http://localhost:%s/%s", listenPort.getNumber(), PATH); final Response response = Request.Get(url).connectTimeout(1000).execute(); assertThat(response.returnContent().asString(), is(PATH)); }
From source file:org.wildfly.swarm.scriptengine.test.ScriptEngineTest.java
@Test @RunAsClient//from ww w. ja v a 2s .c om public void testScriptEngineAvailable() throws Exception { assertEquals("2", Request.Get("http://localhost:8080/engine").execute().returnContent().asString()); }
From source file:org.mule.module.http.functional.listener.HttpListenerHostNameTestCase.java
@Test public void routeToTheRightListener() throws Exception { final String url = String.format("http://localhost:%s/", listenPort.getNumber()); final Response response = Request.Get(url).connectTimeout(RECEIVE_TIMEOUT).execute(); assertThat(response.returnContent().asString(), is("ok")); }
From source file:org.elasticsearch.packaging.util.ServerUtils.java
public static void waitForElasticsearch(String status, String index) throws IOException { Objects.requireNonNull(status); // we loop here rather than letting httpclient handle retries so we can measure the entire waiting time final long startTime = System.currentTimeMillis(); long timeElapsed = 0; boolean started = false; while (started == false && timeElapsed < waitTime) { try {// ww w.ja va 2 s .co m final HttpResponse response = Request.Get("http://localhost:9200/_cluster/health") .connectTimeout((int) timeoutLength).socketTimeout((int) timeoutLength).execute() .returnResponse(); if (response.getStatusLine().getStatusCode() >= 300) { final String statusLine = response.getStatusLine().toString(); final String body = EntityUtils.toString(response.getEntity()); throw new RuntimeException( "Connecting to elasticsearch cluster health API failed:\n" + statusLine + "\n" + body); } started = true; } catch (HttpHostConnectException e) { // we want to retry if the connection is refused LOG.debug("Got connection refused when waiting for cluster health", e); } timeElapsed = System.currentTimeMillis() - startTime; } if (started == false) { throw new RuntimeException("Elasticsearch did not start"); } final String url; if (index == null) { url = "http://localhost:9200/_cluster/health?wait_for_status=" + status + "&timeout=60s&pretty"; } else { url = "http://localhost:9200/_cluster/health/" + index + "?wait_for_status=" + status + "&timeout=60s&pretty"; } final String body = makeRequest(Request.Get(url)); assertThat("cluster health response must contain desired status", body, containsString(status)); }