package io.dropwizard.http2;

import io.dropwizard.Configuration;
import io.dropwizard.logging.BootstrapLogging;
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit.DropwizardAppRule;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http2.api.Session;
import org.eclipse.jetty.http2.api.server.ServerSessionListener;
import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.frames.HeadersFrame;
import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.Promise;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;

public class Http2CIntegrationTest {

    static {
        BootstrapLogging.bootstrap();
    }

    @Rule
    public DropwizardAppRule<Configuration> appRule = new DropwizardAppRule<>(
            FakeApplication.class, ResourceHelpers.resourceFilePath("test-http2c.yml"));

    private final HTTP2Client client = new HTTP2Client();

    @Before
    public void setUp() throws Exception {
        client.start();
    }

    @After
    public void tearDown() throws Exception {
        client.stop();
    }

    @Test
    public void testHttp2c() throws Exception {
        final String hostname = "127.0.0.1";
        final int port = appRule.getLocalPort();

        final FuturePromise<Session> sessionPromise = new FuturePromise<>();
        client.connect(new InetSocketAddress(hostname, port), new ServerSessionListener.Adapter(), sessionPromise);
        final Session session = sessionPromise.get(5, TimeUnit.SECONDS);

        final MetaData.Request request = new MetaData.Request("GET",
                new HttpURI("http://" + hostname + ":" + port + "/api/test"),
                HttpVersion.HTTP_2, new HttpFields());
        final ResponseListener listener = new ResponseListener();
        session.newStream(new HeadersFrame(request, null, true), new Promise.Adapter<>(), listener);
        assertThat(listener.getResponse()).isEqualTo(FakeApplication.HELLO_WORLD);
    }
}

@@ -23,16 +23,58 @@
 http2;%0A%0A
+import com.google.common.net.HttpHeaders;%0A
 import i
@@ -97,24 +97,24 @@
 figuration;%0A
-
 import io.dr
@@ -700,32 +700,137 @@
 y.util.Promise;%0A
+import org.glassfish.jersey.client.JerseyClient;%0Aimport org.glassfish.jersey.client.JerseyClientBuilder;%0A
 import org.junit
@@ -905,24 +905,93 @@
 unit.Test;%0A%0A
+import javax.ws.rs.core.MediaType;%0Aimport javax.ws.rs.core.Response;%0A
 import java.
@@ -1580,32 +1580,32 @@
 ows Exception %7B%0A
-
         client.s
@@ -1614,24 +1614,631 @@
 p();%0A    %7D%0A%0A
+    @Test%0A    public void testHttp11() %7B%0A        final String hostname = %22127.0.0.1%22;%0A        final int port = appRule.getLocalPort();%0A        final JerseyClient http11Client = new JerseyClientBuilder().build();%0A        final Response response = http11Client.target(%22http://%22 + hostname + %22:%22 + port + %22/api/test%22)%0A                .request()%0A                .get();%0A        assertThat(response.getHeaderString(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.APPLICATION_JSON);%0A        assertThat(response.readEntity(String.class)).isEqualTo(FakeApplication.HELLO_WORLD);%0A        http11Client.close();%0A    %7D%0A%0A
     @Test%0A  

Add a test for plain HTTP 1.1 connection