Search in sources :

Example 56 with PropertiesProvider

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

the class TaskResourceTest method setUp.

@Before
public void setUp() {
    PipelineRegistry pipelineRegistry = new PipelineRegistry(new PropertiesProvider());
    pipelineRegistry.register(EmailPipeline.class);
    configure(new CommonMode(new Properties()) {

        @Override
        protected void configure() {
            bind(TaskFactory.class).toInstance(taskFactory);
            bind(Indexer.class).toInstance(mock(Indexer.class));
            bind(TaskManager.class).toInstance(taskManager);
            bind(PipelineRegistry.class).toInstance(pipelineRegistry);
            bind(Filter.class).to(LocalUserFilter.class).asEagerSingleton();
            bind(PropertiesProvider.class).toInstance(new PropertiesProvider(getDefaultProperties()));
        }

        @Override
        protected Routes addModeConfiguration(Routes routes) {
            return routes.add(TaskResource.class).filter(LocalUserFilter.class);
        }
    }.createWebConfiguration());
    init(taskFactory);
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) LocalUserFilter(org.icij.datashare.session.LocalUserFilter) Indexer(org.icij.datashare.text.indexing.Indexer) CommonMode(org.icij.datashare.mode.CommonMode) Routes(net.codestory.http.routes.Routes) Properties(java.util.Properties) PipelineRegistry(org.icij.datashare.extension.PipelineRegistry)

Example 57 with PropertiesProvider

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

the class TaskResourceTest method test_findNames_should_create_resume.

@Test
public void test_findNames_should_create_resume() {
    RestAssert response = post("/api/task/findNames/EMAIL", "{\"options\":{\"waitForNlpApp\": false}}");
    response.should().haveType("application/json");
    List<String> taskNames = taskManager.waitTasksToBeDone(1, SECONDS).stream().map(t -> t.name).collect(toList());
    assertThat(taskNames.size()).isEqualTo(2);
    verify(taskFactory).createResumeNlpTask(local(), singleton(Pipeline.Type.EMAIL));
    ArgumentCaptor<Pipeline> pipelineArgumentCaptor = ArgumentCaptor.forClass(Pipeline.class);
    HashMap<String, String> properties = getDefaultProperties();
    properties.put("waitForNlpApp", "false");
    verify(taskFactory).createNlpTask(eq(local()), pipelineArgumentCaptor.capture(), eq(new PropertiesProvider(properties).getProperties()), any());
    assertThat(pipelineArgumentCaptor.getValue().getType()).isEqualTo(Pipeline.Type.EMAIL);
}
Also used : Routes(net.codestory.http.routes.Routes) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) CommonMode(org.icij.datashare.mode.CommonMode) NlpApp(org.icij.datashare.nlp.NlpApp) HashMap(java.util.HashMap) AbstractModels(org.icij.datashare.text.nlp.AbstractModels) RestAssert(net.codestory.rest.RestAssert) ArgumentCaptor(org.mockito.ArgumentCaptor) Collections.singleton(java.util.Collections.singleton) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) EmailPipeline(org.icij.datashare.nlp.EmailPipeline) Matchers.eq(org.mockito.Matchers.eq) Filter(net.codestory.http.filters.Filter) User(org.icij.datashare.user.User) Project.project(org.icij.datashare.text.Project.project) BatchDownload(org.icij.datashare.batch.BatchDownload) DatashareTimeRule(org.icij.datashare.test.DatashareTimeRule) Path(java.nio.file.Path) Pipeline(org.icij.datashare.text.nlp.Pipeline) org.icij.datashare.tasks(org.icij.datashare.tasks) Properties(java.util.Properties) PropertiesProvider(org.icij.datashare.PropertiesProvider) Indexer(org.icij.datashare.text.indexing.Indexer) String.format(java.lang.String.format) PipelineRegistry(org.icij.datashare.extension.PipelineRegistry) ShouldChain(net.codestory.rest.ShouldChain) Mockito(org.mockito.Mockito) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) LocalUserFilter(org.icij.datashare.session.LocalUserFilter) DatashareUser.local(org.icij.datashare.session.DatashareUser.local) org.junit(org.junit) NotNull(org.jetbrains.annotations.NotNull) MapAssert.entry(org.fest.assertions.MapAssert.entry) SECONDS(java.util.concurrent.TimeUnit.SECONDS) PropertiesProvider(org.icij.datashare.PropertiesProvider) RestAssert(net.codestory.rest.RestAssert) EmailPipeline(org.icij.datashare.nlp.EmailPipeline) Pipeline(org.icij.datashare.text.nlp.Pipeline) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Example 58 with PropertiesProvider

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

the class BatchSearchResourceTest method test_get_search_results_csv_with_url_prefix_parameter.

@Test
public void test_get_search_results_csv_with_url_prefix_parameter() {
    server.configure(routes -> {
        PropertiesProvider propertiesProvider = new PropertiesProvider(new HashMap<String, String>() {

            {
                put("rootHost", "http://foo.com:12345");
            }
        });
        routes.add(new BatchSearchResource(batchSearchRepository, batchSearchQueue, propertiesProvider)).filter(new LocalUserFilter(propertiesProvider));
    });
    when(batchSearchRepository.get(User.local(), "batchSearchId")).thenReturn(new BatchSearch(project("prj"), "name", "desc", asSet("q"), User.local()));
    when(batchSearchRepository.getResults(User.local(), "batchSearchId", new BatchSearchRepository.WebQuery())).thenReturn(singletonList(new SearchResult("q", "docId", "rootId", Paths.get("/path/to/doc"), new Date(), "content/type", 123L, 1)));
    get("/api/batch/search/result/csv/batchSearchId").should().respond(200).haveType("text/csv").haveHeader("Content-Disposition", "attachment;filename=\"batchSearchId.csv\"").contain("\"http://foo.com:12345/#/d/prj/docId/rootId\",\"docId\",\"rootId\"");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) LocalUserFilter(org.icij.datashare.session.LocalUserFilter) BatchSearch(org.icij.datashare.batch.BatchSearch) JooqBatchSearchRepository(org.icij.datashare.db.JooqBatchSearchRepository) BatchSearchRepository(org.icij.datashare.batch.BatchSearchRepository) SearchResult(org.icij.datashare.batch.SearchResult) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 59 with PropertiesProvider

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

the class BatchDownloadRunnerTest method test_max_default_results.

@Test
public void test_max_default_results() throws Exception {
    Document[] documents = IntStream.range(0, 3).mapToObj(i -> createDoc("doc" + i).with(createFile(i)).build()).toArray(Document[]::new);
    mockSearch.willReturn(2, documents);
    File zip = new BatchDownloadRunner(indexer, new PropertiesProvider(new HashMap<String, String>() {

        {
            put(BATCH_DOWNLOAD_MAX_NB_FILES, "3");
            put(SCROLL_SIZE, "3");
        }
    }), new BatchDownload(project("test-datashare"), User.local(), "query"), updater).call();
    assertThat(new ZipFile(zip).size()).isEqualTo(3);
}
Also used : IntStream(java.util.stream.IntStream) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) Mock(org.mockito.Mock) HashMap(java.util.HashMap) Function(java.util.function.Function) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) DatashareCliOptions(org.icij.datashare.cli.DatashareCliOptions) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) User(org.icij.datashare.user.User) ZipFile(java.util.zip.ZipFile) Project.project(org.icij.datashare.text.Project.project) BatchDownload(org.icij.datashare.batch.BatchDownload) Path(java.nio.file.Path) Before(org.junit.Before) PropertiesProvider(org.icij.datashare.PropertiesProvider) Files(java.nio.file.Files) DocumentBuilder.createDoc(org.icij.datashare.text.DocumentBuilder.createDoc) Indexer(org.icij.datashare.text.indexing.Indexer) Test(org.junit.Test) IOException(java.io.IOException) Document(org.icij.datashare.text.Document) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Rule(org.junit.Rule) String.valueOf(java.lang.String.valueOf) RestStatus(org.elasticsearch.rest.RestStatus) TemporaryFolder(org.junit.rules.TemporaryFolder) PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchDownload(org.icij.datashare.batch.BatchDownload) ZipFile(java.util.zip.ZipFile) Document(org.icij.datashare.text.Document) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 60 with PropertiesProvider

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

the class BatchSearchRunnerIntTest method test_search_with_paths_ok.

@Test
public void test_search_with_paths_ok() throws Exception {
    Document mydoc = createDoc("mydoc").build();
    indexer.add(TEST_INDEX, mydoc);
    BatchSearch searchOk = new BatchSearch(project(TEST_INDEX), "name", "desc", asSet("mydoc"), User.local(), false, null, singletonList("/path/to"), 0);
    new BatchSearchRunner(indexer, new PropertiesProvider(), searchOk, resultConsumer).call();
    verify(resultConsumer).apply(searchOk.uuid, "mydoc", singletonList(mydoc));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchSearch(org.icij.datashare.batch.BatchSearch) Document(org.icij.datashare.text.Document)

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