use of com.cloudant.client.api.ClientBuilder in project java-cloudant by cloudant.
the class HttpProxyTest method proxiedRequest.
/**
* This test validates that a request can successfully traverse a proxy to our mock server.
*/
@TestTemplate
public void proxiedRequest(final boolean okUsable, final boolean useSecureProxy, final boolean useHttpsServer, final boolean useProxyAuth) throws Exception {
// mock a 200 OK
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
return new MockResponse();
}
});
InetSocketAddress address = proxy.getListenAddress();
URL proxyUrl = new URL((useSecureProxy) ? "https" : "http", address.getHostName(), address.getPort(), "/");
ClientBuilder builder = CloudantClientHelper.newMockWebServerClientBuilder(server).proxyURL(proxyUrl);
if (useProxyAuth) {
builder.proxyUser(mockProxyUser).proxyPassword(mockProxyPass);
}
// We don't use SSL authentication for this test
CloudantClient client = builder.disableSSLAuthentication().build();
String response = client.executeRequest(Http.GET(client.getBaseUri())).responseAsString();
assertTrue(response.isEmpty(), "There should be no response body on the mock response");
// if it wasn't a 20x then an exception should have been thrown by now
RecordedRequest request = server.takeRequest(10, TimeUnit.SECONDS);
assertNotNull(request);
}
use of com.cloudant.client.api.ClientBuilder in project java-cloudant by cloudant.
the class CloudantClientTests method urlCheck.
private void urlCheck(String encodedUser, String encodedPassword) throws Exception {
ClientBuilder b = ClientBuilder.url(server.url("").newBuilder().encodedUsername(encodedUser).encodedPassword(encodedPassword).build().url());
credentialsCheck(b, encodedUser, encodedPassword);
}
Aggregations