Search in sources :

Example 21 with PropertiesProvider

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

the class RootResourcePluginTest method test_invalid_folder_should_throw_error.

@Test
public void test_invalid_folder_should_throw_error() {
    server.configure(routes -> routes.add(new RootResource(new PropertiesProvider(new HashMap<String, String>() {

        {
            put("pluginsDir", "unknown");
        }
    }))));
    get("/").should().respond(500);
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) HashMap(java.util.HashMap) FluentRestTest(net.codestory.rest.FluentRestTest)

Example 22 with PropertiesProvider

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

the class SettingsResourceTest method test_patch_configuration_should_answer_403_in_server_mode.

@Test
public void test_patch_configuration_should_answer_403_in_server_mode() {
    PropertiesProvider properties = new PropertiesProvider(new HashMap<String, String>() {

        {
            put("mode", "SERVER");
        }
    });
    configure(routes -> routes.add(new SettingsResource(properties)).filter(new BasicAuthFilter("/", "icij", singleUser(local()))));
    patch("/api/settings", "{\"data\": {\"foo\": \"qux\", \"xyzzy\":\"fred\"}}").withPreemptiveAuthentication("local", "pass").should().respond(403);
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 23 with PropertiesProvider

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

the class TaskResourceTest method test_index_and_scan_default_directory.

@Test
public void test_index_and_scan_default_directory() {
    RestAssert response = post("/api/task/batchUpdate/index/file", "{}");
    HashMap<String, String> properties = getDefaultProperties();
    properties.put("foo", "bar");
    response.should().respond(200).haveType("application/json");
    verify(taskFactory).createScanTask(local(), "extract:queue", Paths.get("/default/data/dir"), new PropertiesProvider(properties).getProperties());
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) RestAssert(net.codestory.rest.RestAssert) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Example 24 with PropertiesProvider

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

the class TaskResourceTest method test_index_queue_with_options.

@Test
public void test_index_queue_with_options() {
    RestAssert response = post("/api/task/batchUpdate/index", "{\"options\":{\"key1\":\"val1\",\"key2\":\"val2\"}}");
    response.should().haveType("application/json");
    verify(taskFactory).createIndexTask(local(), "extract:queue", new PropertiesProvider(new HashMap<String, String>() {

        {
            put("key1", "val1");
            put("key2", "val2");
        }
    }).getProperties());
    verify(taskFactory, never()).createScanTask(eq(local()), eq("extract:queue"), any(Path.class), any(Properties.class));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) Path(java.nio.file.Path) Properties(java.util.Properties) RestAssert(net.codestory.rest.RestAssert) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Example 25 with PropertiesProvider

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

the class TaskResourceTest method test_scan_with_options.

@Test
public void test_scan_with_options() {
    String path = getClass().getResource("/docs/").getPath();
    RestAssert response = post("/api/task/batchUpdate/scan/" + path.substring(1), "{\"options\":{\"key\":\"val\",\"foo\":\"qux\"}}");
    ShouldChain responseBody = response.should().haveType("application/json");
    List<String> taskNames = taskManager.waitTasksToBeDone(1, SECONDS).stream().map(t -> t.name).collect(toList());
    assertThat(taskNames.size()).isEqualTo(1);
    responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(0)));
    HashMap<String, String> defaultProperties = getDefaultProperties();
    defaultProperties.put("key", "val");
    defaultProperties.put("foo", "qux");
    verify(taskFactory).createScanTask(local(), "extract:queue", Paths.get(path), new PropertiesProvider(defaultProperties).getProperties());
    verify(taskFactory, never()).createIndexTask(any(User.class), anyString(), any(Properties.class));
}
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) User(org.icij.datashare.user.User) ShouldChain(net.codestory.rest.ShouldChain) Properties(java.util.Properties) RestAssert(net.codestory.rest.RestAssert) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

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