Search in sources :

Example 6 with Response

use of org.apache.http.client.fluent.Response in project moco by dreamhead.

the class MocoConnectionTest method should_not_keep_alive_for_close_request.

@Test
public void should_not_keep_alive_for_close_request() throws Exception {
    server.response("foo");
    running(server, new Runnable() {

        @Override
        public void run() throws Exception {
            Response response = Request.Get(root()).addHeader("Connection", "close").execute();
            assertThat(response.returnResponse().getFirstHeader("Connection"), nullValue());
        }
    });
}
Also used : Response(org.apache.http.client.fluent.Response) Runnable(com.github.dreamhead.moco.Runnable) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 7 with Response

use of org.apache.http.client.fluent.Response in project moco by dreamhead.

the class MocoConnectionTest method should_not_have_keep_alive_header_for_1_1_keep_alive_request.

@Test
public void should_not_have_keep_alive_header_for_1_1_keep_alive_request() throws Exception {
    server.response("foo");
    running(server, new com.github.dreamhead.moco.Runnable() {

        @Override
        public void run() throws Exception {
            Response response = Request.Get(root()).version(HttpVersion.HTTP_1_1).addHeader("Connection", "keep-alive").execute();
            assertThat(response.returnResponse().getFirstHeader("Connection"), nullValue());
        }
    });
}
Also used : Response(org.apache.http.client.fluent.Response) Runnable(com.github.dreamhead.moco.Runnable) AbstractMocoHttpTest(com.github.dreamhead.moco.AbstractMocoHttpTest) Test(org.junit.Test)

Example 8 with Response

use of org.apache.http.client.fluent.Response in project sling by apache.

the class SimpleHttpDistributionTransportTest method testDeliverPackage.

@Test
public void testDeliverPackage() throws Exception {
    DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
    Map<String, String> credentialsMap = new HashMap<String, String>();
    credentialsMap.put("username", "foo");
    credentialsMap.put("password", "foo");
    when(secret.asCredentialsMap()).thenReturn(credentialsMap);
    DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
    when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
    Executor executor = mock(Executor.class);
    Response response = mock(Response.class);
    when(executor.execute(any(Request.class))).thenReturn(response);
    DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
    DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
    SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    DistributionPackage distributionPackage = mock(DistributionPackage.class);
    when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
    InputStream stream = mock(InputStream.class);
    when(distributionPackage.createInputStream()).thenReturn(stream);
    DistributionTransportContext distributionContext = mock(DistributionTransportContext.class);
    when(distributionContext.get(any(String.class), same(Executor.class))).thenReturn(executor);
    when(distributionContext.containsKey(any(String.class))).thenReturn(true);
    simpleHttpDistributionTransport.deliverPackage(resourceResolver, distributionPackage, distributionContext);
}
Also used : DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Request(org.apache.http.client.fluent.Request) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) DistributionTransportSecretProvider(org.apache.sling.distribution.transport.DistributionTransportSecretProvider) DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) URI(java.net.URI) HttpResponse(org.apache.http.HttpResponse) Response(org.apache.http.client.fluent.Response) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionTransportSecret(org.apache.sling.distribution.transport.DistributionTransportSecret) Executor(org.apache.http.client.fluent.Executor) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Aggregations

Response (org.apache.http.client.fluent.Response)8 Test (org.junit.Test)6 URI (java.net.URI)4 HttpResponse (org.apache.http.HttpResponse)4 Executor (org.apache.http.client.fluent.Executor)4 Request (org.apache.http.client.fluent.Request)4 DistributionRequest (org.apache.sling.distribution.DistributionRequest)4 AbstractMocoHttpTest (com.github.dreamhead.moco.AbstractMocoHttpTest)3 Runnable (com.github.dreamhead.moco.Runnable)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)3 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)3 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)3 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)3 DistributionTransportSecret (org.apache.sling.distribution.transport.DistributionTransportSecret)3 DistributionTransportSecretProvider (org.apache.sling.distribution.transport.DistributionTransportSecretProvider)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StatusLine (org.apache.http.StatusLine)2