Search in sources :

Example 1 with TimbuctooActions

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)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonBuilder.jsnO(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnO) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UrlGenerator(nl.knaw.huygens.timbuctoo.crud.UrlGenerator) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Lists(com.google.common.collect.Lists) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) BDDMockito.given(org.mockito.BDDMockito.given) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) JsonBuilder.jsnA(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsnA) Is.is(org.hamcrest.core.Is.is) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) Matchers.anyInt(org.mockito.Matchers.anyInt) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JsonBuilder.jsn(nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) MockitoHamcrest.intThat(org.mockito.hamcrest.MockitoHamcrest.intThat) Test(org.junit.Test) UUID(java.util.UUID) Mockito.verify(org.mockito.Mockito.verify) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) CollectionStubs.collWithCollectionName(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionStubs.collWithCollectionName) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Optional(java.util.Optional) SameJSONAs.sameJSONAs(uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs) CollectionStubs.keywordCollWithCollectionName(nl.knaw.huygens.timbuctoo.core.dto.dataset.CollectionStubs.keywordCollWithCollectionName) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UUID(java.util.UUID) UrlGenerator(nl.knaw.huygens.timbuctoo.crud.UrlGenerator) Test(org.junit.Test)

Example 2 with TimbuctooActions

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)));
}
Also used : QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with TimbuctooActions

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());
}
Also used : TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) InvalidCollectionException(nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException) Test(org.junit.Test)

Example 4 with TimbuctooActions

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");
}
Also used : Mockito.doThrow(org.mockito.Mockito.doThrow) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) ImmutableEntityLookup(nl.knaw.huygens.timbuctoo.core.dto.ImmutableEntityLookup) Test(org.junit.Test) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) URI(java.net.URI) UUID(java.util.UUID) DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Mockito.verify(org.mockito.Mockito.verify) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) URI(java.net.URI) Before(org.junit.Before)

Example 5 with TimbuctooActions

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)));
}
Also used : QuickSearchResult(nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

TimbuctooActions (nl.knaw.huygens.timbuctoo.core.TimbuctooActions)6 UUID (java.util.UUID)4 Test (org.junit.Test)4 URI (java.net.URI)3 QuickSearch (nl.knaw.huygens.timbuctoo.core.dto.QuickSearch)3 QuickSearchResult (nl.knaw.huygens.timbuctoo.core.dto.QuickSearchResult)3 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 InvalidCollectionException (nl.knaw.huygens.timbuctoo.crud.InvalidCollectionException)2 UrlGenerator (nl.knaw.huygens.timbuctoo.crud.UrlGenerator)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2 JmxAttributeGauge (com.codahale.metrics.JmxAttributeGauge)1 MetricRegistry.name (com.codahale.metrics.MetricRegistry.name)1 HealthCheck (com.codahale.metrics.health.HealthCheck)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 Lists (com.google.common.collect.Lists)1 ActiveMQBundle (com.kjetland.dropwizard.activemq.ActiveMQBundle)1 Application (io.dropwizard.Application)1