use of com.palantir.dialogue.Response in project conjure-java-runtime by palantir.
the class JaxRsClientDialogueEndpointTest method stubNoContentResponseChannel.
static Channel stubNoContentResponseChannel() {
Channel channel = mock(Channel.class);
Response response = mock(Response.class);
when(response.body()).thenReturn(new ByteArrayInputStream(new byte[0]));
when(response.code()).thenReturn(204);
when(response.headers()).thenReturn(ImmutableListMultimap.of());
when(channel.execute(any(Endpoint.class), any(Request.class))).thenReturn(Futures.immediateFuture(response));
return channel;
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class MyServiceIntegrationTest method testCustomResponse.
private void testCustomResponse(int code) {
undertowHandler = exchange -> {
exchange.assertMethod(HttpMethod.PUT);
exchange.assertPath("/custom/request1");
exchange.assertAccept().isEqualTo("*/*");
exchange.assertContentType().isNull();
exchange.assertNoBody();
exchange.exchange.setStatusCode(code);
exchange.exchange.getResponseHeaders().add(HttpString.tryFromString("My-Custom-Header"), "my-custom-header-value");
exchange.setContentType("text/csv");
exchange.writeStringBody("Custom Body");
};
try (Response response = myServiceDialogue.customResponse()) {
assertThat(response.code()).isEqualTo(code);
assertThat(CharStreams.toString(new InputStreamReader(response.body(), StandardCharsets.UTF_8))).isEqualTo("Custom Body");
assertThat(response.headers().get("My-Custom-Header")).containsExactly("my-custom-header-value");
} catch (IOException e) {
throw new SafeRuntimeException(e);
}
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class BlockingChannelAdapterTest method testFailure.
@Test
public void testFailure() {
Channel channel = BlockingChannelAdapter.of((_endpoint, _request) -> {
throw new SafeRuntimeException("expected");
}, executor);
ListenableFuture<Response> result = channel.execute(TestEndpoint.POST, Request.builder().build());
Awaitility.waitAtMost(Duration.ofSeconds(3)).until(result::isDone);
assertThatThrownBy(result::get).isInstanceOf(ExecutionException.class).hasCauseExactlyInstanceOf(SafeRuntimeException.class).hasRootCauseMessage("expected");
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class SocksProxyManualTest method testTls.
// @org.junit.jupiter.api.Test
void testTls() throws Exception {
// ssh -D 8081 -v -N localhost
SSLContext context = SslSocketFactories.createSslContext(TestConfigurations.SSL_CONFIG);
Undertow undertow = Undertow.builder().addHttpsListener(8080, null, context, new ResponseCodeHandler(204)).build();
undertow.start();
try {
ClientConfiguration configuration = withSocks("https://localhost:" + 8080, "127.0.0.1:8081");
Channel channel = ApacheHttpClientChannels.create(configuration, "test");
ListenableFuture<Response> future = channel.execute(TestEndpoint.GET, Request.builder().build());
try (Response response = future.get()) {
assertThat(response.code()).isEqualTo(204);
}
} finally {
undertow.stop();
}
}
use of com.palantir.dialogue.Response in project dialogue by palantir.
the class SocksProxyManualTest method testPlain.
// @org.junit.jupiter.api.Test
void testPlain() throws Exception {
// ssh -D 8081 -v -N localhost
Undertow undertow = Undertow.builder().addHttpListener(8080, null, new ResponseCodeHandler(204)).build();
undertow.start();
try {
ClientConfiguration configuration = withSocks("http://localhost:" + 8080, "127.0.0.1:8081");
Channel channel = ApacheHttpClientChannels.create(configuration, "test");
ListenableFuture<Response> future = channel.execute(TestEndpoint.GET, Request.builder().build());
try (Response response = future.get()) {
assertThat(response.code()).isEqualTo(204);
}
} finally {
undertow.stop();
}
}
Aggregations