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());
}
}
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)");
}
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");
}
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);
}
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));
}
Aggregations