use of com.cloudant.client.api.CloudantClient in project java-cloudant by cloudant.
the class SslAuthenticationTest method localSSLAuthenticationDisabledWithCookieAuth.
/**
* Repeat the localSSLAuthenticationDisabled, but with the cookie auth enabled.
* This test validates that the SSL settings also get applied to the cookie interceptor.
*/
@TestTemplate
public void localSSLAuthenticationDisabledWithCookieAuth() throws Exception {
// Mock up an OK cookie response then an OK response for the getAllDbs()
server.enqueue(MockWebServerResources.OK_COOKIE);
// OK 200
server.enqueue(new MockResponse());
// Use a username and password to enable the cookie auth interceptor
CloudantClient dbClient = CloudantClientHelper.newMockWebServerClientBuilder(server).username("user").password("password").disableSSLAuthentication().build();
dbClient.getAllDbs();
}
use of com.cloudant.client.api.CloudantClient in project java-cloudant by cloudant.
the class SslAuthenticationTest method localSSLAuthenticationEnabledWithCookieAuth.
/**
* Repeat the localSSLAuthenticationEnabled, but with the cookie auth enabled.
* This test validates that the SSL settings also get applied to the cookie interceptor.
*/
@TestTemplate
public void localSSLAuthenticationEnabledWithCookieAuth() throws Exception {
// Mock up an OK cookie response then an OK response for the getAllDbs()
server.enqueue(MockWebServerResources.OK_COOKIE);
// OK 200
server.enqueue(new MockResponse());
// Use a username and password to enable the cookie auth interceptor
CloudantClient dbClient = CloudantClientHelper.newMockWebServerClientBuilder(server).username("user").password("password").build();
try {
dbClient.getAllDbs();
fail("The SSL authentication failure should result in a CouchDbException");
} catch (CouchDbException e) {
validateClientAuthenticationException(e);
}
}
use of com.cloudant.client.api.CloudantClient in project java-cloudant by cloudant.
the class URIBaseTest method buildAccountUri_noTrailingPathSeparator.
@Test
public void buildAccountUri_noTrailingPathSeparator() throws Exception {
CloudantClient client = ClientBuilder.url(clientResource.get().getBaseUri().toURL()).build();
Assertions.assertFalse(client.getBaseUri().toString().endsWith("/"));
URI clientUri = new URIBase(client.getBaseUri()).build();
Assertions.assertFalse(clientUri.toString().endsWith("/"));
// Check that path is not missing / separators
clientUri = new URIBase(client.getBaseUri()).path("").path("api").path("couch").build();
URI expectedAccountUri = new URI(clientResource.get().getBaseUri().toString() + "/api/couch");
Assertions.assertEquals(expectedAccountUri, clientUri);
}
use of com.cloudant.client.api.CloudantClient in project java-cloudant by cloudant.
the class ChangeNotificationsTest method changesCustomParameter.
/**
* Test that a custom parameter can be added to a changes request.
*/
@Test
public void changesCustomParameter() throws Exception {
CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer).build();
Database db = client.database("notreal", false);
// Mock up an empty set of changes
mockWebServer.enqueue(new MockResponse().setBody("{\"results\": []}"));
db.changes().filter("myFilter").parameter("myParam", "paramValue").getChanges();
RecordedRequest request = mockWebServer.takeRequest(1, TimeUnit.SECONDS);
assertNotNull(request, "There should be a changes request");
assertTrue(request.getPath().contains("filter=myFilter"), "There should be a filter parameter on the request");
assertTrue(request.getPath().contains("myParam=paramValue"), "There should be a custom parameter on the " + "request");
}
use of com.cloudant.client.api.CloudantClient in project java-cloudant by cloudant.
the class CloudantClientTests method testBasicAuth.
/**
* Test that adding the Basic Authentication interceptor to CloudantClient works.
*/
@Test
@RequiresCloudant
public void testBasicAuth() throws IOException {
BasicAuthInterceptor interceptor = new BasicAuthInterceptor(CloudantClientHelper.COUCH_USERNAME + ":" + CloudantClientHelper.COUCH_PASSWORD);
CloudantClient client = ClientBuilder.account(CloudantClientHelper.COUCH_USERNAME).interceptors(interceptor).build();
// Test passes if there are no exceptions
client.getAllDbs();
}
Aggregations