Search in sources :

Example 51 with PropertiesProvider

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

the class BatchDownloadRunnerTest method test_elasticsearch_status_exception__should_be_sent.

@Test(expected = ElasticsearchStatusException.class)
public void test_elasticsearch_status_exception__should_be_sent() throws Exception {
    mockSearch.willThrow(new ElasticsearchStatusException("error", RestStatus.BAD_REQUEST, new RuntimeException()));
    new BatchDownloadRunner(indexer, new PropertiesProvider(), new BatchDownload(project("test-datashare"), User.local(), "query"), updater).call();
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BatchDownload(org.icij.datashare.batch.BatchDownload) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) Test(org.junit.Test)

Example 52 with PropertiesProvider

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

the class BatchDownloadRunnerTest method test_max_zip_size.

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

        {
            put(BATCH_DOWNLOAD_MAX_SIZE, valueOf("hello world 1".getBytes(StandardCharsets.UTF_8).length * 3));
            put(SCROLL_SIZE, "3");
        }
    }), new BatchDownload(project("test-datashare"), User.local(), "query"), updater).call();
    assertThat(new ZipFile(zip).size()).isEqualTo(4);
}
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 53 with PropertiesProvider

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

the class RootResourcePluginTest method setUp.

@Before
public void setUp() {
    propertiesProvider = new PropertiesProvider(new HashMap<String, String>() {

        {
            put("pluginsDir", folder.getRoot().toString());
        }
    });
    server.configure(routes -> routes.add(new RootResource(propertiesProvider)).bind("/plugins", folder.getRoot()).filter(new LocalUserFilter(new PropertiesProvider())));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) LocalUserFilter(org.icij.datashare.session.LocalUserFilter) HashMap(java.util.HashMap)

Example 54 with PropertiesProvider

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

the class SettingsResourceTest method test_patch_configuration.

@Test
public void test_patch_configuration() throws IOException {
    File settings = folder.newFile("file.settings");
    Files.write(settings.toPath(), asList("foo=doe", "bar=baz"));
    configure(routes -> routes.add(new SettingsResource(new PropertiesProvider(settings.getAbsolutePath()))).filter(new BasicAuthFilter("/", "icij", singleUser(local()))));
    patch("/api/settings", "{\"data\": {\"foo\": \"qux\", \"xyzzy\":\"fred\"}}").withPreemptiveAuthentication("local", "pass").should().respond(200);
    Properties properties = new PropertiesProvider(settings.getAbsolutePath()).getProperties();
    assertThat(properties).includes(entry("foo", "qux"), entry("bar", "baz"), entry("xyzzy", "fred"));
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) BasicAuthFilter(net.codestory.http.filters.basic.BasicAuthFilter) Properties(java.util.Properties) File(java.io.File) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 55 with PropertiesProvider

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

the class TaskResourceTest method test_index_and_scan_directory_with_options.

@Test
public void test_index_and_scan_directory_with_options() {
    String path = getClass().getResource("/docs/").getPath();
    RestAssert response = post("/api/task/batchUpdate/index/" + path.substring(1), "{\"options\":{\"foo\":\"baz\",\"key\":\"val\"}}");
    response.should().haveType("application/json");
    HashMap<String, String> defaultProperties = getDefaultProperties();
    defaultProperties.put("foo", "baz");
    defaultProperties.put("key", "val");
    verify(taskFactory).createIndexTask(local(), "extract:queue", new PropertiesProvider(defaultProperties).getProperties());
    verify(taskFactory).createScanTask(local(), "extract:queue", Paths.get(path), new PropertiesProvider(defaultProperties).getProperties());
}
Also used : PropertiesProvider(org.icij.datashare.PropertiesProvider) 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