@Test public void searchConvertsTheReadEntityToJson() throws Exception { UUID id = UUID.randomUUID(); String collectionName = "wwpersons"; QuickSearchResult entity = QuickSearchResult.create("[TEMP] An author", id, 2); TimbuctooActions timbuctooActions = mock(TimbuctooActions.class); given(timbuctooActions.getCollectionMetadata(anyString())).willReturn(collWithCollectionName(collectionName)); given(timbuctooActions.doQuickSearch(any(), any(), isNull(), anyInt())).willReturn(Lists.newArrayList(entity)); AutocompleteService instance = new AutocompleteService( (collection, id1, rev) -> URI.create("http: timbuctooActions ); String query = "*author*"; JsonNode result = instance.search(collectionName, Optional.of(query), Optional.empty()); assertThat(result.toString(), sameJSONAs(jsnA( jsnO("value", jsn("[TEMP] An author"), "key", jsn("http: ).toString())); verify(timbuctooActions).doQuickSearch( argThat(hasProperty("collectionName", equalTo(collectionName))), any(QuickSearch.class), isNull(), intThat(is(50)) ); }
public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType); }
AutocompleteService { public JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType) throws InvalidCollectionException { final Collection collection = timbuctooActions.getCollectionMetadata(collectionName); int limit = query.isPresent() ? 50 : 1000; String queryString = query.orElse(null); QuickSearch quickSearch = QuickSearch.fromQueryString(queryString); List<QuickSearchResult> results = timbuctooActions.doQuickSearch( collection, quickSearch, keywordType.orElse(null), limit ); return jsnA(results.stream().map(entity -> jsnO( "value", jsn(entity.getIndexedValue()), "key", jsn(autoCompleteUrlFor.apply(collectionName, entity.getId(), entity.getRev()).toString()) ))); } AutocompleteService(UrlGenerator autoCompleteUrlFor, TimbuctooActions timbuctooActions); JsonNode search(String collectionName, Optional<String> query, Optional<String> keywordType);  }