use of com.cloudant.test.main.RequiresCloudant in project java-cloudant by cloudant.
the class HttpTest method testCookieAuthWithoutRetry.
// NOTE: This test doesn't work with specified couch servers,
// the URL will always include the creds specified for the test
//
// A couchdb server needs to be set and running with the correct
// security settings, the database *must* not be public, it *must*
// be named cookie_test
//
@TestTemplate
@RequiresCloudant
public void testCookieAuthWithoutRetry() throws IOException {
CookieInterceptor interceptor = new CookieInterceptor(CloudantClientHelper.COUCH_USERNAME, CloudantClientHelper.COUCH_PASSWORD, clientResource.get().getBaseUri().toString());
HttpConnection conn = new HttpConnection("POST", dbResource.get().getDBUri().toURL(), "application/json");
conn.responseInterceptors.add(interceptor);
conn.requestInterceptors.add(interceptor);
ByteArrayInputStream bis = new ByteArrayInputStream(data.getBytes());
// nothing read from stream
assertEquals(data.getBytes().length, bis.available());
conn.setRequestBody(bis);
HttpConnection responseConn = conn.execute();
// stream was read to end
assertEquals(0, bis.available());
assertEquals(2, responseConn.getConnection().getResponseCode() / 100);
// check the json
Gson gson = new Gson();
InputStream is = responseConn.responseAsInputStream();
try {
JsonObject response = gson.fromJson(new InputStreamReader(is), JsonObject.class);
assertTrue(response.has("ok"));
assertTrue(response.get("ok").getAsBoolean());
assertTrue(response.has("id"));
assertTrue(response.has("rev"));
} finally {
is.close();
}
}
use of com.cloudant.test.main.RequiresCloudant 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();
}
use of com.cloudant.test.main.RequiresCloudant in project java-cloudant by cloudant.
the class CloudantClientTests method cookieTest.
@Test
@RequiresCloudant
public void cookieTest() {
Membership membership = account.getMembership();
assertNotNull(membership);
}
use of com.cloudant.test.main.RequiresCloudant in project java-cloudant by cloudant.
the class DatabaseTest method shards.
@Test
@RequiresCloudant
public void shards() {
List<Shard> shards = db.getShards();
assert (shards.size() > 0);
for (Shard s : shards) {
assertNotNull(s.getRange());
assertNotNull(s.getNodes());
assertNotNull(s.getNodes().hasNext());
}
}
use of com.cloudant.test.main.RequiresCloudant in project java-cloudant by cloudant.
the class DatabaseTest method shard.
@Test
@RequiresCloudant
public void shard() {
Shard s = db.getShard("snipe");
assertNotNull(s);
assertNotNull(s.getRange());
assertNotNull(s.getNodes());
assert (s.getNodes().hasNext());
}
Aggregations