Search in sources :

Example 71 with Test

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

the class SearchTests method multipleDrillDownTest.

@Test
public /**
 * Request a search with two drilldown queries against the views101
 * design document. The design document only contains one animal
 * that satisfies the drilldown requirements.
 * Assert that the result is one animal in the class bird, and
 * that the only existing min_length value of this animal is small.
 */
void multipleDrillDownTest() {
    Search srch = db.search("views101/animals");
    SearchResult<Animal> rslt = srch.includeDocs(true).counts(new String[] { "class", "diet" }).ranges("{ \"min_length\": {\"small\": \"[0 TO 1.0]\"," + "\"medium\": \"[1.1 TO 3.0]\", \"large\": \"[3.1 TO 9999999]\"} }").drillDown("class", "bird").drillDown("diet", "omnivore").querySearchResult("class:bird", Animal.class);
    assertNotNull(rslt);
    assertNotNull(rslt.getRanges());
    assertEquals(1, rslt.getRanges().entrySet().size());
    assertEquals(3, rslt.getRanges().get("min_length").entrySet().size());
    assertEquals(new Long(1), rslt.getRanges().get("min_length").get("small"));
    assertEquals(new Long(0), rslt.getRanges().get("min_length").get("medium"));
    assertEquals(new Long(0), rslt.getRanges().get("min_length").get("large"));
}
Also used : Search(com.cloudant.client.api.Search) Test(org.junit.jupiter.api.Test)

Example 72 with Test

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

the class SearchTests method drillDownTest.

@Test
public void drillDownTest() {
    // do a faceted search for drilldown
    Search srch = db.search("views101/animals");
    SearchResult<Animal> rslt = srch.includeDocs(true).counts(new String[] { "class", "diet" }).ranges("{ \"min_length\": {\"small\": \"[0 TO 1.0]\"," + "\"medium\": \"[1.1 TO 3.0]\", \"large\": \"[3.1 TO 9999999]\"} }").drillDown("class", "mammals").querySearchResult("class:mammal", Animal.class);
    assertNotNull(rslt);
    assertNotNull(rslt.getRanges());
    assertEquals(1, rslt.getRanges().entrySet().size());
    assertEquals(3, rslt.getRanges().get("min_length").entrySet().size());
    assertEquals(new Long(0), rslt.getRanges().get("min_length").get("small"));
    assertEquals(new Long(0), rslt.getRanges().get("min_length").get("medium"));
    assertEquals(new Long(0), rslt.getRanges().get("min_length").get("large"));
}
Also used : Search(com.cloudant.client.api.Search) Test(org.junit.jupiter.api.Test)

Example 73 with Test

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

the class SearchTests method multiValueDrillDownTest.

@Test
public void multiValueDrillDownTest() {
    // do a faceted search for multi-value drilldown
    Search srch = db.search("views101/animals");
    SearchResult<Animal> rslt = srch.includeDocs(true).drillDown("diet", "carnivore", "omnivore").querySearchResult("class:mammal", Animal.class);
    assertNotNull(rslt);
    assertEquals(4, rslt.getTotalRows());
    List<String> ids = new ArrayList<String>();
    for (SearchResultRow row : rslt.getRows()) {
        ids.add(row.getId());
    }
    List<String> expectedIds = Arrays.asList("panda", "aardvark", "badger", "lemur");
    assertTrue(ids.containsAll(expectedIds));
}
Also used : Search(com.cloudant.client.api.Search) ArrayList(java.util.ArrayList) SearchResultRow(com.cloudant.client.api.model.SearchResult.SearchResultRow) Test(org.junit.jupiter.api.Test)

Example 74 with Test

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

the class SearchTests method groupSortTest.

@Test
public void groupSortTest() {
    Search srch = db.search("views101/animals");
    Map<String, List<Animal>> groups = srch.includeDocs(true).groupField("diet", false).groupSort("[\"-diet<string>\"]").queryGroups("l*", Animal.class);
    assertNotNull(groups);
    assertEquals(2, groups.size());
    Iterator<String> it = groups.keySet().iterator();
    // diet in reverse order
    assertEquals("omnivore", it.next());
    assertEquals("herbivore", it.next());
}
Also used : Search(com.cloudant.client.api.Search) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 75 with Test

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

the class URIBaseTest method buildAccountUri_noTrailingPathSeparator.

@Test
public void buildAccountUri_noTrailingPathSeparator() throws Exception {
    CloudantClient client = ClientBuilder.url(clientResource.get().getBaseUri().toURL()).build();
    Assertions.assertFalse(client.getBaseUri().toString().endsWith("/"));
    URI clientUri = new URIBase(client.getBaseUri()).build();
    Assertions.assertFalse(clientUri.toString().endsWith("/"));
    // Check that path is not missing / separators
    clientUri = new URIBase(client.getBaseUri()).path("").path("api").path("couch").build();
    URI expectedAccountUri = new URI(clientResource.get().getBaseUri().toString() + "/api/couch");
    Assertions.assertEquals(expectedAccountUri, clientUri);
}
Also used : CloudantClient(com.cloudant.client.api.CloudantClient) URI(java.net.URI) URIBase(com.cloudant.client.internal.URIBase) Test(org.junit.jupiter.api.Test)

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