use of nl.knaw.huygens.timbuctoo.core.TimbuctooActions in project timbuctoo by HuygensING.
the class AutocompleteServiceTest method searchFiltersKeywordsByType.
@Test
public void searchFiltersKeywordsByType() throws InvalidCollectionException {
String query = "*foo bar*";
String keywordType = "maritalStatus";
String collectionName = "wwkeywords";
UUID id = UUID.randomUUID();
QuickSearchResult readEntity = QuickSearchResult.create("a keyword", id, 2);
TimbuctooActions timbuctooActions = mock(TimbuctooActions.class);
given(timbuctooActions.getCollectionMetadata(anyString())).willReturn(keywordCollWithCollectionName(collectionName));
given(timbuctooActions.doQuickSearch(any(), any(), anyString(), anyInt())).willReturn(Lists.newArrayList(readEntity));
UrlGenerator urlGenerator = (coll, id1, rev) -> URI.create("http://example.com/" + coll + "/" + id1 + "?rev=" + rev);
AutocompleteService instance = new AutocompleteService(urlGenerator, timbuctooActions);
JsonNode result = instance.search(collectionName, Optional.of(query), Optional.of(keywordType));
assertThat(result.toString(), sameJSONAs(jsnA(jsnO("value", jsn("a keyword"), "key", jsn("http://example.com/wwkeywords/" + id.toString() + "?rev=2"))).toString()));
verify(timbuctooActions).doQuickSearch(argThat(hasProperty("collectionName", equalTo(collectionName))), any(QuickSearch.class), argThat(is(keywordType)), intThat(is(50)));
}
use of nl.knaw.huygens.timbuctoo.core.TimbuctooActions in project timbuctoo by HuygensING.
the class AutocompleteServiceTest method searchRequests1000ResultsWhenTheQueryIsEmpty.
@Test
public void searchRequests1000ResultsWhenTheQueryIsEmpty() 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(), anyString(), anyInt())).willReturn(Lists.newArrayList(entity));
AutocompleteService instance = new AutocompleteService((collection, id1, rev) -> URI.create("http://example.com/" + collection + "/" + id1 + "?rev=" + rev), timbuctooActions);
instance.search(collectionName, Optional.empty(), Optional.empty());
verify(timbuctooActions).doQuickSearch(any(Collection.class), any(QuickSearch.class), any(), intThat(is(1000)));
}
use of nl.knaw.huygens.timbuctoo.core.TimbuctooActions in project timbuctoo by HuygensING.
the class AutocompleteServiceTest method searchThrowsWhenTheCollectionNameDoesNotExist.
@Test(expected = InvalidCollectionException.class)
public void searchThrowsWhenTheCollectionNameDoesNotExist() throws InvalidCollectionException {
TimbuctooActions timbuctooActions = mock(TimbuctooActions.class);
given(timbuctooActions.getCollectionMetadata(anyString())).willThrow(new InvalidCollectionException(""));
AutocompleteService underTest = new AutocompleteService(null, timbuctooActions);
underTest.search("nonexistent", Optional.empty(), Optional.empty());
}
use of nl.knaw.huygens.timbuctoo.core.TimbuctooActions in project timbuctoo by HuygensING.
the class TimbuctooActionsAddPidTest method setup.
@Before
public void setup() throws Exception {
dataStoreOperations = mock(DataStoreOperations.class);
instance = new TimbuctooActions(null, null, null, (coll, id, rev) -> URI.create("http://example.org/persistent"), dataStoreOperations, null);
id = UUID.randomUUID();
pidUri = new URI("http://example.com/pid");
}
use of nl.knaw.huygens.timbuctoo.core.TimbuctooActions in project timbuctoo by HuygensING.
the class AutocompleteServiceTest method searchConvertsTheReadEntityToJson.
@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://example.com/" + collection + "/" + id1 + "?rev=" + rev), 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://example.com/wwpersons/" + id.toString() + "?rev=2"))).toString()));
verify(timbuctooActions).doQuickSearch(argThat(hasProperty("collectionName", equalTo(collectionName))), any(QuickSearch.class), isNull(), intThat(is(50)));
}
Aggregations