Search in sources :

Example 26 with PropertiesProvider

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

the class UserTaskResourceTest method setupAppWith.

private void setupAppWith(String... userLogins) {
    final PropertiesProvider propertiesProvider = new PropertiesProvider();
    taskManager = new TaskManagerMemory(propertiesProvider);
    configure(new CommonMode(new Properties()) {

        @Override
        protected void configure() {
            bind(PropertiesProvider.class).toInstance(propertiesProvider);
            bind(PipelineRegistry.class).toInstance(mock(PipelineRegistry.class));
            bind(SessionIdStore.class).toInstance(SessionIdStore.inMemory());
            bind(TaskManager.class).toInstance(taskManager);
            bind(Filter.class).toInstance(new BasicAuthFilter("/", "ds", DatashareUser.users(userLogins)));
            bind(TaskFactory.class).toInstance(mock(TaskFactory.class));
            bind(Indexer.class).toInstance(mock(Indexer.class));
        }

        @Override
        protected Routes addModeConfiguration(Routes routes) {
            return routes.add(TaskResource.class).filter(Filter.class);
        }
    }.createWebConfiguration());
}
Also used : BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) CommonMode(org.icij.datashare.mode.CommonMode) Routes(net.codestory.http.routes.Routes) Properties(java.util.Properties) PipelineRegistry(org.icij.datashare.extension.PipelineRegistry) PropertiesProvider(org.icij.datashare.PropertiesProvider) SessionIdStore(net.codestory.http.security.SessionIdStore) Indexer(org.icij.datashare.text.indexing.Indexer) Filter(net.codestory.http.filters.Filter) BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter)

Example 27 with PropertiesProvider

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

the class ElasticsearchConfigurationTest method test_create_client_with_user_pass.

@Test
public void test_create_client_with_user_pass() throws Exception {
    RestHighLevelClient esClient = ElasticsearchConfiguration.createESClient(new PropertiesProvider(new HashMap<String, String>() {

        {
            put("elasticsearchAddress", "http://user:pass@elasticsearch:9200");
        }
    }));
    Response response = esClient.getLowLevelClient().performRequest(new Request("GET", TEST_INDEX));
    assertThat(EntityUtils.toString(response.getEntity())).contains("settings");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Response(org.elasticsearch.client.Response) HashMap(java.util.HashMap) Request(org.elasticsearch.client.Request) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) Test(org.junit.Test)

Example 28 with PropertiesProvider

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

the class ElasticsearchConfigurationTest method test_create_client_creates_mapping.

@Test
public void test_create_client_creates_mapping() throws Exception {
    ElasticsearchConfiguration.createESClient(new PropertiesProvider());
    Response response = es.client.getLowLevelClient().performRequest(new Request("GET", TEST_INDEX));
    assertThat(EntityUtils.toString(response.getEntity())).contains("mapping");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Response(org.elasticsearch.client.Response) Request(org.elasticsearch.client.Request) Test(org.junit.Test)

Example 29 with PropertiesProvider

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

the class ElasticsearchSpewerTest method test_truncated_content.

@Test
public void test_truncated_content() throws Exception {
    ElasticsearchSpewer limitedContentSpewer = new ElasticsearchSpewer(es.client, text -> Language.ENGLISH, new FieldNames(), publisher, new PropertiesProvider(new HashMap<String, String>() {

        {
            put("maxContentLength", "20");
        }
    })).withRefresh(IMMEDIATE).withIndex("test-datashare");
    final TikaDocument document = new DocumentFactory().withIdentifier(new PathIdentifier()).create(get("fake-file.txt"));
    final ParsingReader reader = new ParsingReader(new ByteArrayInputStream("this content should be truncated".getBytes()));
    document.setReader(reader);
    limitedContentSpewer.write(document);
    GetResponse documentFields = es.client.get(new GetRequest(TEST_INDEX, document.getId()), RequestOptions.DEFAULT);
    assertThat(documentFields.getSourceAsMap()).includes(entry("content", "this content should"));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) DocumentFactory(org.icij.extract.document.DocumentFactory) FieldNames(org.icij.spewer.FieldNames) HashMap(java.util.HashMap) ParsingReader(org.apache.tika.parser.ParsingReader) ByteArrayInputStream(java.io.ByteArrayInputStream) GetRequest(org.elasticsearch.action.get.GetRequest) PathIdentifier(org.icij.extract.document.PathIdentifier) TikaDocument(org.icij.extract.document.TikaDocument) GetResponse(org.elasticsearch.action.get.GetResponse) Test(org.junit.Test)

Example 30 with PropertiesProvider

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

the class StatusResourceTest method test_get_status_with_open_metrics_format_with_platform_name.

@Test
public void test_get_status_with_open_metrics_format_with_platform_name() {
    configure(routes -> routes.add(new StatusResource(new PropertiesProvider(new HashMap<String, String>() {

        {
            put("platform", "platform");
        }
    }), repository, indexer, dataBus, documentCollectionFactory)));
    when(dataBus.getHealth()).thenReturn(true);
    get("/api/status?format=openmetrics").should().respond(200).haveType("text/plain;version=0.0.4").contain("" + "# HELP datashare The datashare resources status\n" + "# TYPE datashare gauge\n" + "datashare{environment=\"platform\",status=\"KO\",resource=\"database\"} 0 1593531060000\n" + "datashare{environment=\"platform\",status=\"KO\",resource=\"index\"} 0 1593531060000\n" + "datashare{environment=\"platform\",status=\"OK\",resource=\"databus\"} 1 1593531060000\n" + "datashare{environment=\"platform\",status=\"OK\",resource=\"document_queue_status\"} 1 1593531060000\n" + "datashare{environment=\"platform\",resource=\"document_queue_size\"} 0 1593531060000");
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) HashMap(java.util.HashMap) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) 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