Search in sources :

Example 1 with TestServer

use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.

the class TestHttpClient method testGetNullQueryParam.

@Test
void testGetNullQueryParam() throws Exception {
    ExampleBean inputBean = new ExampleBean("x", 1, NOW);
    HttpHandler handler = h -> {
        String queryParams = h.getRequestURI().getQuery();
        Assertions.assertNull(queryParams);
        Assertions.assertEquals("GET", h.getRequestMethod());
        String response = MAPPER.writeValueAsString(inputBean);
        h.sendResponseHeaders(200, response.getBytes().length);
        OutputStream os = h.getResponseBody();
        os.write(response.getBytes());
        os.close();
    };
    try (TestServer server = new TestServer(handler)) {
        ExampleBean bean = get(server.getAddress()).queryParam("x", null).get().readEntity(ExampleBean.class);
        Assertions.assertEquals(inputBean, bean);
    }
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) TestServer(org.projectnessie.client.util.TestServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) URI(java.net.URI) CommitMeta(org.projectnessie.model.CommitMeta) OutputStream(java.io.OutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) IOError(java.io.IOError) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpHandler(com.sun.net.httpserver.HttpHandler) Assertions(org.junit.jupiter.api.Assertions) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) InputStream(java.io.InputStream) HttpHandler(com.sun.net.httpserver.HttpHandler) OutputStream(java.io.OutputStream) TestServer(org.projectnessie.client.util.TestServer) Test(org.junit.jupiter.api.Test)

Example 2 with TestServer

use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.

the class TestHttpClient method testGetQueryParam.

@Test
void testGetQueryParam() throws Exception {
    ExampleBean inputBean = new ExampleBean("x", 1, NOW);
    HttpHandler handler = h -> {
        Assertions.assertEquals("x=y", h.getRequestURI().getQuery());
        Assertions.assertEquals("GET", h.getRequestMethod());
        String response = MAPPER.writeValueAsString(inputBean);
        h.sendResponseHeaders(200, response.getBytes().length);
        OutputStream os = h.getResponseBody();
        os.write(response.getBytes());
        os.close();
    };
    try (TestServer server = new TestServer(handler)) {
        ExampleBean bean = get(server.getAddress()).queryParam("x", "y").get().readEntity(ExampleBean.class);
        Assertions.assertEquals(inputBean, bean);
    }
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) TestServer(org.projectnessie.client.util.TestServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) URI(java.net.URI) CommitMeta(org.projectnessie.model.CommitMeta) OutputStream(java.io.OutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) IOError(java.io.IOError) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpHandler(com.sun.net.httpserver.HttpHandler) Assertions(org.junit.jupiter.api.Assertions) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) InputStream(java.io.InputStream) HttpHandler(com.sun.net.httpserver.HttpHandler) OutputStream(java.io.OutputStream) TestServer(org.projectnessie.client.util.TestServer) Test(org.junit.jupiter.api.Test)

Example 3 with TestServer

use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.

the class TestHttpClient method testGet.

@Test
void testGet() throws Exception {
    ExampleBean inputBean = new ExampleBean("x", 1, NOW);
    HttpHandler handler = h -> {
        Assertions.assertEquals("GET", h.getRequestMethod());
        String response = MAPPER.writeValueAsString(inputBean);
        h.sendResponseHeaders(200, response.getBytes().length);
        OutputStream os = h.getResponseBody();
        os.write(response.getBytes());
        os.close();
    };
    try (TestServer server = new TestServer(handler)) {
        ExampleBean bean = get(server.getAddress()).get().readEntity(ExampleBean.class);
        Assertions.assertEquals(inputBean, bean);
    }
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) TestServer(org.projectnessie.client.util.TestServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) URI(java.net.URI) CommitMeta(org.projectnessie.model.CommitMeta) OutputStream(java.io.OutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) IOError(java.io.IOError) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpHandler(com.sun.net.httpserver.HttpHandler) Assertions(org.junit.jupiter.api.Assertions) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) InputStream(java.io.InputStream) HttpHandler(com.sun.net.httpserver.HttpHandler) OutputStream(java.io.OutputStream) TestServer(org.projectnessie.client.util.TestServer) Test(org.junit.jupiter.api.Test)

Example 4 with TestServer

use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.

the class TestHttpClient method testPutNoCompression.

@Test
void testPutNoCompression() throws Exception {
    ExampleBean inputBean = new ExampleBean("x", 1, NOW);
    HttpHandler handler = h -> {
        Assertions.assertEquals("PUT", h.getRequestMethod());
        assertThat(h.getRequestHeaders()).doesNotContainKeys("Content-Encoding");
        try (InputStream in = h.getRequestBody()) {
            Object bean = MAPPER.readerFor(ExampleBean.class).readValue(in);
            Assertions.assertEquals(inputBean, bean);
        }
        h.sendResponseHeaders(200, 0);
    };
    try (TestServer server = new TestServer(handler)) {
        get(server.getAddress(), true).put(inputBean);
    }
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) TestServer(org.projectnessie.client.util.TestServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) URI(java.net.URI) CommitMeta(org.projectnessie.model.CommitMeta) OutputStream(java.io.OutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) IOError(java.io.IOError) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpHandler(com.sun.net.httpserver.HttpHandler) Assertions(org.junit.jupiter.api.Assertions) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) InputStream(java.io.InputStream) HttpHandler(com.sun.net.httpserver.HttpHandler) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) TestServer(org.projectnessie.client.util.TestServer) Test(org.junit.jupiter.api.Test)

Example 5 with TestServer

use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.

the class TestHttpClient method testGetTemplateThrows.

@Test
void testGetTemplateThrows() throws Exception {
    HttpHandler handler = h -> Assertions.fail();
    try (TestServer server = new TestServer("/a/b", handler)) {
        Assertions.assertThrows(HttpClientException.class, () -> get(server.getAddress()).path("a/{b}").get().readEntity(ExampleBean.class));
        Assertions.assertThrows(HttpClientException.class, () -> get(server.getAddress()).path("a/b").resolveTemplate("b", "b").get().readEntity(ExampleBean.class));
    }
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) TestServer(org.projectnessie.client.util.TestServer) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) JsonSerialize(com.fasterxml.jackson.databind.annotation.JsonSerialize) URI(java.net.URI) CommitMeta(org.projectnessie.model.CommitMeta) OutputStream(java.io.OutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Instant(java.time.Instant) InetSocketAddress(java.net.InetSocketAddress) IOError(java.io.IOError) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) HttpHandler(com.sun.net.httpserver.HttpHandler) Assertions(org.junit.jupiter.api.Assertions) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) InputStream(java.io.InputStream) HttpHandler(com.sun.net.httpserver.HttpHandler) TestServer(org.projectnessie.client.util.TestServer) Test(org.junit.jupiter.api.Test)

Aggregations

TestServer (org.projectnessie.client.util.TestServer)19 Test (org.junit.jupiter.api.Test)18 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 HttpHandler (com.sun.net.httpserver.HttpHandler)13 OutputStream (java.io.OutputStream)13 URI (java.net.URI)13 Assertions (org.junit.jupiter.api.Assertions)13 JsonDeserialize (com.fasterxml.jackson.databind.annotation.JsonDeserialize)12 JsonSerialize (com.fasterxml.jackson.databind.annotation.JsonSerialize)12 IOError (java.io.IOError)12 IOException (java.io.IOException)12 InputStream (java.io.InputStream)12 InetSocketAddress (java.net.InetSocketAddress)12 Instant (java.time.Instant)12 Arrays (java.util.Arrays)12 Collections (java.util.Collections)12 HashSet (java.util.HashSet)12 List (java.util.List)12 Objects (java.util.Objects)12