use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.
the class TestHttpClient method testPostNoCompression.
@Test
void testPostNoCompression() throws Exception {
ExampleBean inputBean = new ExampleBean("x", 1, NOW);
HttpHandler handler = h -> {
Assertions.assertEquals("POST", 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).post(inputBean);
}
}
use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.
the class TestHttpClient method testGetMultipleQueryParam.
@Test
void testGetMultipleQueryParam() throws Exception {
ExampleBean inputBean = new ExampleBean("x", 1, NOW);
HttpHandler handler = h -> {
String[] queryParams = h.getRequestURI().getQuery().split("&");
Assertions.assertEquals(2, queryParams.length);
Set<String> queryParamSet = new HashSet<>(Arrays.asList(queryParams));
Assertions.assertTrue(queryParamSet.contains("x=y"));
Assertions.assertTrue(queryParamSet.contains("a=b"));
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").queryParam("a", "b").get().readEntity(ExampleBean.class);
Assertions.assertEquals(inputBean, bean);
}
}
use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.
the class TestHttpClient method testPost.
@Test
void testPost() throws Exception {
ExampleBean inputBean = new ExampleBean("x", 1, NOW);
HttpHandler handler = h -> {
Assertions.assertEquals("POST", h.getRequestMethod());
assertThat(h.getRequestHeaders()).containsEntry("Content-Encoding", Collections.singletonList("gzip"));
try (InputStream in = new GZIPInputStream(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()).post(inputBean);
}
}
use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.
the class TestNessieHttpClient method testTracing.
@Test
void testTracing() throws Exception {
AtomicReference<String> traceId = new AtomicReference<>();
try (TestServer server = new TestServer(handlerForHeaderTest("Uber-trace-id", traceId))) {
NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri()).withTracing(true).build(NessieApiV1.class);
try (Scope ignore = GlobalTracer.get().activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) {
api.getConfig();
}
}
// Cannot really assert on the value of the Uber-trace-id header, because the APIs don't
// give us access to that. Verifying that the Uber-trace-id header is being sent should
// be good enough though.
assertNotNull(traceId.get());
}
use of org.projectnessie.client.util.TestServer in project nessie by projectnessie.
the class TestNessieHttpClient method testNotFoundOnBaseUri.
@Test
void testNotFoundOnBaseUri() throws IOException {
try (TestServer server = errorServer(404)) {
NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri().resolve("/unknownPath")).build(NessieApiV1.class);
assertThatThrownBy(api::getConfig).isInstanceOf(RuntimeException.class).hasMessageContaining("Not Found");
}
}
Aggregations