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);
}
}
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);
}
}
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);
}
}
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);
}
}
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));
}
}
Aggregations