Search in sources :

Example 96 with Test

use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.

the class CouchDbUtilTest method mockQueryResultWithNullDocValue.

/**
 * Assert that if doc's value in JSON object
 * is null, the result from jsonToObject
 * will be null and no exception occurs.
 */
@Test
public void mockQueryResultWithNullDocValue() {
    String queryResult = "{\"doc\":null}";
    Gson gson = new Gson();
    JsonObject jsonFromSearchQuery = new JsonParser().parse(queryResult).getAsJsonObject();
    JsonObject mockResult = jsonToObject(gson, jsonFromSearchQuery, "doc", JsonObject.class);
    assertEquals(null, mockResult);
}
Also used : Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser) Test(org.junit.jupiter.api.Test)

Example 97 with Test

use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.

the class DBServerTest method dbInfo.

@Test
public void dbInfo() {
    DbInfo dbInfo = db.info();
    assertNotNull(dbInfo);
}
Also used : DbInfo(com.cloudant.client.api.model.DbInfo) Test(org.junit.jupiter.api.Test)

Example 98 with Test

use of org.junit.jupiter.api.Test in project java-cloudant by cloudant.

the class DatabaseTest method permissionsParsing.

@Test
public void permissionsParsing() throws Exception {
    CloudantClient client = CloudantClientHelper.newMockWebServerClientBuilder(mockWebServer).build();
    Database db = client.database("notarealdb", false);
    // Mock up a request of all permissions
    // for GET _security
    mockWebServer.enqueue(MockWebServerResources.PERMISSIONS);
    // for PUT _security
    mockWebServer.enqueue(MockWebServerResources.JSON_OK);
    db.setPermissions("testUsername", EnumSet.allOf(Permissions.class));
    // Mock up a failing request
    String testError = "test error";
    String testReason = "test reason";
    // for GET _security
    mockWebServer.enqueue(MockWebServerResources.PERMISSIONS);
    mockWebServer.enqueue(new MockResponse().setResponseCode(400).setBody("{\"reason\":\"" + testReason + "\", \"error\":\"" + testError + "\"}"));
    try {
        db.setPermissions("testUsername", EnumSet.allOf(Permissions.class));
    } catch (CouchDbException e) {
        assertEquals(testError, e.getError());
        assertEquals(testReason, e.getReason());
    }
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) CouchDbException(com.cloudant.client.org.lightcouch.CouchDbException) CloudantClient(com.cloudant.client.api.CloudantClient) Database(com.cloudant.client.api.Database) Permissions(com.cloudant.client.api.model.Permissions) Test(org.junit.jupiter.api.Test)

Example 99 with Test

use of org.junit.jupiter.api.Test 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 100 with Test

use of org.junit.jupiter.api.Test 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

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