Search in sources :

Example 36 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class BatchSearchRunnerTest method test_run_batch_search_failure.

@Test(expected = RuntimeException.class)
public void test_run_batch_search_failure() throws Exception {
    Document[] documents = { createDoc("doc").build() };
    mockSearch.willReturn(1, documents);
    BatchSearch batchSearch = new BatchSearch("uuid1", project("test-datashare"), "name1", "desc1", asSet("query1", "query2"), new Date(), BatchSearch.State.QUEUED, local());
    when(resultConsumer.apply(anyString(), any(), anyList())).thenThrow(new RuntimeException());
    new BatchSearchRunner(indexer, new PropertiesProvider(), batchSearch, resultConsumer).call();
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchSearch(org.icij.datashare.batch.BatchSearch) Document(org.icij.datashare.text.Document) Date(java.util.Date) Test(org.junit.Test)

Example 37 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class BatchSearchRunnerTest method test_run_batch_search_truncate_to_60k_max_results.

@Test
public void test_run_batch_search_truncate_to_60k_max_results() throws Exception {
    Document[] documents = IntStream.range(0, MAX_SCROLL_SIZE).mapToObj(i -> createDoc("doc" + i).build()).toArray(Document[]::new);
    mockSearch.willReturn(MAX_BATCH_RESULT_SIZE / MAX_SCROLL_SIZE + 1, documents);
    BatchSearch batchSearch = new BatchSearch("uuid1", project("test-datashare"), "name", "desc", asSet("query"), new Date(), BatchSearch.State.QUEUED, local());
    assertThat(new BatchSearchRunner(indexer, new PropertiesProvider(), batchSearch, resultConsumer).call()).isLessThan(60000);
}
Also used : IntStream(java.util.stream.IntStream) MAX_SCROLL_SIZE(org.icij.datashare.tasks.BatchSearchRunner.MAX_SCROLL_SIZE) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Mock(org.mockito.Mock) Date(java.util.Date) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Arrays.asList(java.util.Arrays.asList) SearchException(org.icij.datashare.batch.SearchException) User(org.icij.datashare.user.User) Project.project(org.icij.datashare.text.Project.project) DatashareTimeRule(org.icij.datashare.test.DatashareTimeRule) BATCH_SEARCH_MAX_TIME(org.icij.datashare.cli.DatashareCliOptions.BATCH_SEARCH_MAX_TIME) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) BATCH_THROTTLE(org.icij.datashare.cli.DatashareCliOptions.BATCH_THROTTLE) PropertiesProvider(org.icij.datashare.PropertiesProvider) DocumentBuilder.createDoc(org.icij.datashare.text.DocumentBuilder.createDoc) Indexer(org.icij.datashare.text.indexing.Indexer) CollectionUtils.asSet(org.icij.datashare.CollectionUtils.asSet) Test(org.junit.Test) MAX_BATCH_RESULT_SIZE(org.icij.datashare.tasks.BatchSearchRunner.MAX_BATCH_RESULT_SIZE) Document(org.icij.datashare.text.Document) Executors(java.util.concurrent.Executors) User.local(org.icij.datashare.user.User.local) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) List(java.util.List) Rule(org.junit.Rule) BatchSearch(org.icij.datashare.batch.BatchSearch) TerFunction(org.icij.datashare.function.TerFunction) PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchSearch(org.icij.datashare.batch.BatchSearch) Document(org.icij.datashare.text.Document) Date(java.util.Date) Test(org.junit.Test)

Example 38 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class LocalUserFilterTest method test_adds_custom_user_to_context.

@Test
public void test_adds_custom_user_to_context() throws Exception {
    LocalUserFilter localUserFilter = new LocalUserFilter(new PropertiesProvider(new HashMap<String, String>() {

        {
            put("defaultUserName", "foo");
        }
    }));
    Payload payload = localUserFilter.apply("url", context, nextFilter);
    assertThat(payload).isSameAs(next);
    verify(context).setCurrentUser(user.capture());
    assertThat(user.getValue().login()).isEqualTo("foo");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) HashMap(java.util.HashMap) Payload(net.codestory.http.payload.Payload) Test(org.junit.Test)

Example 39 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class LocalUserFilterTest method test_adds_local_user_to_context.

@Test
public void test_adds_local_user_to_context() throws Exception {
    LocalUserFilter localUserFilter = new LocalUserFilter(new PropertiesProvider());
    Payload payload = localUserFilter.apply("url", context, nextFilter);
    assertThat(payload).isSameAs(next);
    verify(context).setCurrentUser(user.capture());
    assertThat(user.getValue().login()).isEqualTo("local");
    assertThat(user.getValue().isInRole("local")).isTrue();
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Payload(net.codestory.http.payload.Payload) Test(org.junit.Test)

Example 40 with PropertiesProvider

use of org.icij.datashare.PropertiesProvider in project datashare by ICIJ.

the class YesCookieAuthFilterTest method test_adds_new_user_to_context.

@Test
public void test_adds_new_user_to_context() throws Exception {
    YesCookieAuthFilter filter = new YesCookieAuthFilter(new PropertiesProvider(new HashMap<String, String>() {

        {
            put("defaultProject", "demo");
            put("messageBusAddress", "redis://redis:6379");
        }
    }));
    Payload payload = filter.apply("url", context, nextFilter);
    assertThat(payload).isSameAs(next);
    verify(context).setCurrentUser(user.capture());
    assertThat(user.getValue().login()).isNotEmpty();
    assertThat(((DatashareUser) user.getValue()).getProjects()).containsExactly("demo");
    assertThat(user.getValue().isInRole("local")).isFalse();
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) HashMap(java.util.HashMap) Payload(net.codestory.http.payload.Payload) Test(org.junit.Test)

Aggregations

PropertiesProvider (org.icij.datashare.PropertiesProvider)73 Test (org.junit.Test)44 HashMap (java.util.HashMap)27 Document (org.icij.datashare.text.Document)18 BatchSearch (org.icij.datashare.batch.BatchSearch)17 LocalUserFilter (org.icij.datashare.session.LocalUserFilter)15 AbstractProdWebServerTest (org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)15 Path (java.nio.file.Path)11 Before (org.junit.Before)10 BatchDownload (org.icij.datashare.batch.BatchDownload)9 Publisher (org.icij.datashare.com.Publisher)8 Indexer (org.icij.datashare.text.indexing.Indexer)7 User (org.icij.datashare.user.User)7 Date (java.util.Date)6 Properties (java.util.Properties)6 RestAssert (net.codestory.rest.RestAssert)5 PipelineRegistry (org.icij.datashare.extension.PipelineRegistry)5 DocumentFactory (org.icij.extract.document.DocumentFactory)5 TikaDocument (org.icij.extract.document.TikaDocument)5 FieldNames (org.icij.spewer.FieldNames)5