use of org.junit.jupiter.api.TestTemplate in project java-cloudant by cloudant.
the class HttpTest method testHttpConnectionRetries.
/**
* Test the global number of retries
*
* @throws Exception
*/
@TestTemplate
public void testHttpConnectionRetries() throws Exception {
// Just return 200 OK
mockWebServer.setDispatcher(new MockWebServerResources.ConstantResponseDispatcher(200));
CloudantClient c = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer).interceptors(new HttpConnectionResponseInterceptor() {
@Override
public HttpConnectionInterceptorContext interceptResponse(HttpConnectionInterceptorContext context) {
// At least do something with the connection, otherwise we risk breaking it
try {
context.connection.getConnection().getResponseCode();
} catch (IOException e) {
fail("IOException getting response code");
}
// Set to always replay
context.replayRequest = true;
return context;
}
}).build();
String response = c.executeRequest(Http.GET(c.getBaseUri()).setNumberOfRetries(5)).responseAsString();
assertTrue(response.isEmpty(), "There should be no response body on the mock response");
assertEquals(5, mockWebServer.getRequestCount(), "There should be 5 request attempts");
}
use of org.junit.jupiter.api.TestTemplate 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 org.junit.jupiter.api.TestTemplate 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 org.junit.jupiter.api.TestTemplate in project java-cloudant by cloudant.
the class DatabaseURIHelperTest method buildDocumentUri_slashInDocumentId.
@TestTemplate
public void buildDocumentUri_slashInDocumentId(String path) throws Exception {
URI expected = new URI(uriBase + "/test/path1%2Fpath2");
URI actual = helper(path + "/test").documentUri("path1/path2");
Assertions.assertEquals(expected, actual);
}
use of org.junit.jupiter.api.TestTemplate in project java-cloudant by cloudant.
the class DatabaseURIHelperTest method buildVeryEscapedUri.
// this test shows that non-ascii characters will be represented correctly
// in the url but that we don't escape characters like / in the root url, but that they are
// correctly escaped in the document part of the url
@TestTemplate
public void buildVeryEscapedUri(String path) throws Exception {
URI expected = new URI(uriBase + "/SDF@%23%25$%23)KLDfdffdg%C3%A9/%2FSF@%23%25$%23)" + "DFGKLDfdffdg%C3%A9%2Fpath2?detail=/SDF@%23%25$%23)%C3%A9&revs=%5B1-2%5D");
Map<String, Object> options = new TreeMap<String, Object>();
options.put("revs", "[1-2]");
options.put("detail", "/SDF@#%$#)\u00E9");
URI actual = helper(path + "/SDF@#%$#)KLDfdffdg\u00E9").documentId("/SF@#%$#)" + "DFGKLDfdffdg\u00E9/path2").query(options).build();
Assertions.assertEquals(expected.toASCIIString(), actual.toASCIIString());
}
Aggregations