Search in sources :

Example 1 with RequiresCloudant

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();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HttpConnection(com.cloudant.http.HttpConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) CookieInterceptor(com.cloudant.http.internal.interceptors.CookieInterceptor) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) TestTemplate(org.junit.jupiter.api.TestTemplate) RequiresCloudant(com.cloudant.test.main.RequiresCloudant)

Example 2 with RequiresCloudant

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();
}
Also used : BasicAuthInterceptor(com.cloudant.http.interceptors.BasicAuthInterceptor) CloudantClient(com.cloudant.client.api.CloudantClient) Test(org.junit.jupiter.api.Test) RequiresCloudant(com.cloudant.test.main.RequiresCloudant)

Example 3 with RequiresCloudant

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);
}
Also used : Membership(com.cloudant.client.api.model.Membership) Test(org.junit.jupiter.api.Test) RequiresCloudant(com.cloudant.test.main.RequiresCloudant)

Example 4 with RequiresCloudant

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());
    }
}
Also used : Shard(com.cloudant.client.api.model.Shard) Test(org.junit.jupiter.api.Test) RequiresCloudant(com.cloudant.test.main.RequiresCloudant)

Example 5 with RequiresCloudant

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());
}
Also used : Shard(com.cloudant.client.api.model.Shard) Test(org.junit.jupiter.api.Test) RequiresCloudant(com.cloudant.test.main.RequiresCloudant)

Aggregations

RequiresCloudant (com.cloudant.test.main.RequiresCloudant)8 Test (org.junit.jupiter.api.Test)6 HttpConnection (com.cloudant.http.HttpConnection)3 CloudantClient (com.cloudant.client.api.CloudantClient)2 Membership (com.cloudant.client.api.model.Membership)2 Shard (com.cloudant.client.api.model.Shard)2 BasicAuthInterceptor (com.cloudant.http.interceptors.BasicAuthInterceptor)2 Gson (com.google.gson.Gson)2 JsonObject (com.google.gson.JsonObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 TestTemplate (org.junit.jupiter.api.TestTemplate)2 CouchDbException (com.cloudant.client.org.lightcouch.CouchDbException)1 HttpConnectionInterceptorContext (com.cloudant.http.HttpConnectionInterceptorContext)1 HttpConnectionRequestInterceptor (com.cloudant.http.HttpConnectionRequestInterceptor)1 CookieInterceptor (com.cloudant.http.internal.interceptors.CookieInterceptor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1