Search in sources :

Example 1 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class IndexTests method testIndexMovieFindByIndexDesignDoc.

@Test
public void testIndexMovieFindByIndexDesignDoc() {
    QueryResult<Movie> movies = db.query(new QueryBuilder(and(gt("Movie_year", 1960), eq("Person_name", "Alec Guinness"))).sort(Sort.desc("Movie_year")).fields("Movie_name", "Movie_year").limit(1).skip(1).useIndex("Movie_year").build(), Movie.class);
    assertNotNull(movies);
    assert (movies.getDocs().size() == 1);
    for (Movie m : movies.getDocs()) {
        assertNotNull(m.getMovie_name());
        assertNotNull(m.getMovie_year());
    }
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class IndexTests method useIndexNotSpecified.

/**
 * Test that use_index is not specified if no index is provided
 *
 * @throws Exception
 */
@Test
public void useIndexNotSpecified() throws Exception {
    JsonElement useIndex = getUseIndexFromRequest(new QueryBuilder(empty()));
    assertNull(useIndex, "The use_index property should be null (i.e. was not specified)");
}
Also used : JsonElement(com.google.gson.JsonElement) QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class IndexTests method useIndexDesignDocAndIndexNameJsonTypeIsArray.

/**
 * Test that a design document and index name is passed as an array.
 *
 * @throws Exception
 */
@Test
public void useIndexDesignDocAndIndexNameJsonTypeIsArray() throws Exception {
    JsonElement useIndex = getUseIndexFromRequest(new QueryBuilder(empty()).useIndex("Movie_year", "Person_name"));
    assertNotNull(useIndex, "The use_index property should not be null");
    assertTrue(useIndex.isJsonArray(), "The use_index property should be a JsonArray");
    JsonArray useIndexArray = useIndex.getAsJsonArray();
    assertEquals(2, useIndexArray.size(), "The use_index array should have two elements");
    assertEquals("Movie_year", useIndexArray.get(0).getAsString(), "The use_index design " + "document should be Movie_year");
    assertEquals("Person_name", useIndexArray.get(1).getAsString(), "The use_index index name" + " should be Person_name");
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class IndexTests method useIndexDesignDocJsonTypeIsString.

/**
 * Test that a design document name is passed as a string.
 *
 * @throws Exception
 */
@Test
public void useIndexDesignDocJsonTypeIsString() throws Exception {
    JsonElement useIndex = getUseIndexFromRequest(new QueryBuilder(empty()).useIndex("Movie_year"));
    assertUseIndexString(useIndex);
}
Also used : JsonElement(com.google.gson.JsonElement) QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with QueryBuilder

use of com.cloudant.client.api.query.QueryBuilder in project java-cloudant by cloudant.

the class IndexTests method useIndexReplaced.

/**
 * Test that use_index is replaced if called multiple times
 *
 * @throws Exception
 */
@Test
public void useIndexReplaced() throws Exception {
    QueryBuilder builder = new QueryBuilder(empty()).useIndex("Movie_year", "Person_name").useIndex("Movie_year");
    assertUseIndexString(getUseIndexFromRequest(builder));
}
Also used : QueryBuilder(com.cloudant.client.api.query.QueryBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

QueryBuilder (com.cloudant.client.api.query.QueryBuilder)33 Test (org.junit.jupiter.api.Test)33 JsonElement (com.google.gson.JsonElement)3 JsonArray (com.google.gson.JsonArray)1