Search in sources :

Example 86 with Test

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();
    }
}
Also used : Response(com.cloudant.client.api.model.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.cloudant.client.api.model.Document) Test(org.junit.jupiter.api.Test)

Example 87 with Test

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));
}
Also used : Response(com.cloudant.client.api.model.Response) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test)

Example 88 with Test

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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) CloudantClient(com.cloudant.client.api.CloudantClient) Database(com.cloudant.client.api.Database) Test(org.junit.jupiter.api.Test)

Example 89 with Test

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();
}
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 90 with Test

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

Aggregations

Test (org.junit.jupiter.api.Test)67450 lombok.val (lombok.val)3880 File (java.io.File)2228 HashMap (java.util.HashMap)2180 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2164 ArrayList (java.util.ArrayList)2137 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2027 SqlSession (org.apache.ibatis.session.SqlSession)1845 List (java.util.List)1799 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1484 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1184 Map (java.util.Map)1143 IOException (java.io.IOException)1048 Path (java.nio.file.Path)1006 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)935 Date (java.util.Date)914 Method (java.lang.reflect.Method)862 TestBean (org.springframework.beans.testfixture.beans.TestBean)822 Transaction (org.neo4j.graphdb.Transaction)752 BaseDataTest (org.apache.ibatis.BaseDataTest)740