Search in sources :

Example 1 with SearchQuery

use of com.hortonworks.registries.storage.search.SearchQuery in project registry by hortonworks.

the class SearchApiTest method testSearchAPIJsons.

@Test
public void testSearchAPIJsons() throws Exception {
    LOG.info("simpleQuery = [{}]", simpleQuery);
    LOG.info("complexQuery = [{}]", complexQuery);
    SearchQuery[] queries = { simpleQuery, complexQuery };
    for (SearchQuery query : queries) {
        ObjectMapper objectMapper = new ObjectMapper();
        String queryAsJson = objectMapper.writeValueAsString(query);
        LOG.info("queryAsJson = [{}]", queryAsJson);
        SearchQuery returnedQuery = objectMapper.readValue(queryAsJson, SearchQuery.class);
        LOG.info("returnedQuery [{}] ", returnedQuery);
        Assert.assertEquals(query, returnedQuery);
    }
}
Also used : SearchQuery(com.hortonworks.registries.storage.search.SearchQuery) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with SearchQuery

use of com.hortonworks.registries.storage.search.SearchQuery in project registry by hortonworks.

the class JdbcStorageManagerIntegrationTest method testSearchQueryApi.

@Test
public void testSearchQueryApi() {
    for (StorableTest storableTest : storableTests) {
        storableTest.addAllToStorage();
        String nameSpace = storableTest.getNameSpace();
        SearchQuery searchQuery = SearchQuery.searchFrom(nameSpace).where(WhereClause.begin().contains("name", "info").and().gt("id", 1L).combine()).orderBy(OrderBy.asc("name"));
        Collection<Storable> storablesWithIdGt1 = getStorageManager().search(searchQuery);
        System.out.println("storablesWithIdGt1 = " + storablesWithIdGt1);
        for (Storable storable : storablesWithIdGt1) {
            Assert.assertTrue(storable.getId() > 1L);
        }
        Collection<Storable> allStorables = getStorageManager().list(searchQuery.getNameSpace());
        System.out.println("list = " + allStorables);
        Assert.assertEquals(allStorables.size() - 1, storablesWithIdGt1.size());
    }
}
Also used : SearchQuery(com.hortonworks.registries.storage.search.SearchQuery) StorableTest(com.hortonworks.registries.storage.StorableTest) Storable(com.hortonworks.registries.storage.Storable) AbstractStoreManagerTest(com.hortonworks.registries.storage.AbstractStoreManagerTest) StorableTest(com.hortonworks.registries.storage.StorableTest) Test(org.junit.Test) IntegrationTest(com.hortonworks.registries.common.test.IntegrationTest)

Aggregations

SearchQuery (com.hortonworks.registries.storage.search.SearchQuery)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IntegrationTest (com.hortonworks.registries.common.test.IntegrationTest)1 AbstractStoreManagerTest (com.hortonworks.registries.storage.AbstractStoreManagerTest)1 Storable (com.hortonworks.registries.storage.Storable)1 StorableTest (com.hortonworks.registries.storage.StorableTest)1