use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class CloudantClientTests method cookieTest.
@Test
@RequiresCloudant
public void cookieTest() {
Membership membership = account.getMembership();
assertNotNull(membership);
}
use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class CloudantClientTests method gatewayStyleURL.
@Test
public void gatewayStyleURL() throws Exception {
final String gatewayPath = "/gateway";
// Set a dispatcher that returns 200 if the requests have the correct path /gateway/_all_dbs
// Otherwise return 400.
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals(gatewayPath + "/_all_dbs")) {
return new MockResponse();
} else {
return new MockResponse().setResponseCode(400);
}
}
});
// Build a client with a URL that includes a path
CloudantClient c = ClientBuilder.url(new URL(server.url(gatewayPath).toString())).build();
// If the request path is wrong this call will return 400 and throw an exception failing the
// test.
c.getAllDbs();
// Build a client with a URL that includes a path with a trailing /
c = ClientBuilder.url(new URL(server.url(gatewayPath + "/").toString())).build();
// If the request path is wrong this call will return 400 and throw an exception failing the
// test.
c.getAllDbs();
}
use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class CloudantClientTests method testBasicAuthFromCredentials.
/**
* Test that configuring the Basic Authentication interceptor from credentials and adding to
* the CloudantClient works.
*/
@Test
public void testBasicAuthFromCredentials() throws Exception {
BasicAuthInterceptor interceptor = BasicAuthInterceptor.createFromCredentials("username", "password");
// send back a mock OK 200
server.enqueue(new MockResponse());
CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(server).interceptors(interceptor).build();
client.getAllDbs();
// expected 'username:password'
assertEquals("Basic dXNlcm5hbWU6cGFzc3dvcmQ=", server.takeRequest().getHeader("Authorization"));
}
use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class CloudantClientTests method testUserAgentHeaderStringFromFile.
@Test
public void testUserAgentHeaderStringFromFile() throws Exception {
// This doesn't read the a properties file, since the tests do not run from the published
// jars.
// Point to the built classes, it's a bit awkward but we need to load the class cleanly
File f = new File("../cloudant-http/build/classes/main/");
String userAgentHeader = new UserAgentInterceptor(new URLClassLoader(new URL[] { f.toURI().toURL() }) {
@Override
public InputStream getResourceAsStream(String name) {
if (name.equals("META-INF/com.cloudant.client.properties")) {
try {
return new ByteArrayInputStream(("user.agent.name=java-cloudant\nuser" + ".agent.version=1.6.1").getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
return super.getResourceAsStream(name);
}
}, "META-INF/com.cloudant.client.properties").getUserAgent();
assertTrue(userAgentHeader.matches(userAgentRegex), "The value of the User-Agent header: " + "" + userAgentHeader + " should match the " + "format: " + userAgentFormat);
}
use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class CloudantClientTests method testDefaultPorts.
@Test
public void testDefaultPorts() throws Exception {
CloudantClient c = null;
c = CloudantClientHelper.newTestAddressClient().build();
assertEquals(80, c.getBaseUri().getPort(), "The http port should be 80");
c = CloudantClientHelper.newHttpsTestAddressClient().build();
assertEquals(443, c.getBaseUri().getPort(), "The http port should be 443");
}
Aggregations