use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class AttachmentsTest method getAttachmentStandaloneWithRev.
@Test
public void getAttachmentStandaloneWithRev() throws IOException, URISyntaxException {
byte[] bytesToDB = "binary data".getBytes();
ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesToDB);
Response response = db.saveAttachment(bytesIn, "foo.txt", "text/plain");
Document doc = db.find(Document.class, response.getId());
assertTrue(doc.getAttachments().containsKey("foo.txt"));
InputStream in = db.getAttachment(response.getId(), "foo.txt", response.getRev());
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
IOUtils.copy(in, bytesOut);
byte[] bytesFromDB = bytesOut.toByteArray();
assertArrayEquals(bytesToDB, bytesFromDB);
} finally {
in.close();
}
}
use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class BulkDocumentTest method bulkModifyDocs.
@Test
public void bulkModifyDocs() {
List<Object> newDocs = new ArrayList<Object>();
newDocs.add(new Foo());
newDocs.add(new JsonObject());
List<Response> responses = db.bulk(newDocs);
assertThat(responses.size(), is(2));
}
use of org.junit.jupiter.api.Test 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 org.junit.jupiter.api.Test 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 org.junit.jupiter.api.Test in project java-cloudant by cloudant.
the class CloudantClientTests method apiKey.
@Test
@RequiresCloudantService
public void apiKey() {
ApiKey key = account.generateApiKey();
assertNotNull(key);
assertNotNull(key.getKey());
assertNotNull(key.getPassword());
}
Aggregations