Search in sources :

Example 1 with ShouldChain

use of net.codestory.rest.ShouldChain in project datashare by ICIJ.

the class TaskResourceTest method test_clean_tasks.

@Test
public void test_clean_tasks() {
    post("/api/task/batchUpdate/index/file/" + getClass().getResource("/docs/doc.txt").getPath().substring(1), "{}").response();
    List<String> taskNames = taskManager.waitTasksToBeDone(1, SECONDS).stream().map(t -> t.name).collect(toList());
    ShouldChain responseBody = post("/api/task/clean", "{}").should().haveType("application/json");
    responseBody.should().contain(taskNames.get(0));
    responseBody.should().contain(taskNames.get(1));
    assertThat(taskManager.get()).isEmpty();
}
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) ShouldChain(net.codestory.rest.ShouldChain) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Example 2 with ShouldChain

use of net.codestory.rest.ShouldChain in project datashare by ICIJ.

the class TaskResourceTest method test_index_directory.

@Test
public void test_index_directory() {
    RestAssert response = post("/api/task/batchUpdate/index/file/" + getClass().getResource("/docs/").getPath().substring(1), "{}");
    ShouldChain responseBody = response.should().haveType("application/json");
    List<String> taskNames = taskManager.waitTasksToBeDone(1, SECONDS).stream().map(t -> t.name).collect(toList());
    responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(0)));
    responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(1)));
}
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) ShouldChain(net.codestory.rest.ShouldChain) RestAssert(net.codestory.rest.RestAssert) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Example 3 with ShouldChain

use of net.codestory.rest.ShouldChain 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)

Example 4 with ShouldChain

use of net.codestory.rest.ShouldChain in project datashare by ICIJ.

the class TaskResourceTest method test_index_file_and_filter.

@Test
public void test_index_file_and_filter() {
    RestAssert response = post("/api/task/batchUpdate/index/" + getClass().getResource("/docs/doc.txt").getPath().substring(1), "{\"options\":{\"filter\": true}}");
    ShouldChain responseBody = response.should().haveType("application/json");
    List<String> taskNames = taskManager.waitTasksToBeDone(1, SECONDS).stream().map(t -> t.name).collect(toList());
    responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(0)));
    responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(1)));
    verify(taskFactory).createScanIndexTask(eq(local()), eq("extract:report"));
}
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) ShouldChain(net.codestory.rest.ShouldChain) RestAssert(net.codestory.rest.RestAssert) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Example 5 with ShouldChain

use of net.codestory.rest.ShouldChain in project datashare by ICIJ.

the class TaskResourceTest method test_index_file.

@Test
public void test_index_file() {
    RestAssert response = post("/api/task/batchUpdate/index/" + getClass().getResource("/docs/doc.txt").getPath().substring(1), "{}");
    ShouldChain responseBody = response.should().haveType("application/json");
    List<String> taskNames = taskManager.waitTasksToBeDone(1, SECONDS).stream().map(t -> t.name).collect(toList());
    responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(0)));
    responseBody.should().contain(format("{\"name\":\"%s\"", taskNames.get(1)));
}
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) ShouldChain(net.codestory.rest.ShouldChain) RestAssert(net.codestory.rest.RestAssert) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)

Aggregations

String.format (java.lang.String.format)5 Path (java.nio.file.Path)5 Paths (java.nio.file.Paths)5 Collections.singleton (java.util.Collections.singleton)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Properties (java.util.Properties)5 SECONDS (java.util.concurrent.TimeUnit.SECONDS)5 Collectors.toList (java.util.stream.Collectors.toList)5 Filter (net.codestory.http.filters.Filter)5 Routes (net.codestory.http.routes.Routes)5 RestAssert (net.codestory.rest.RestAssert)5 ShouldChain (net.codestory.rest.ShouldChain)5 Assertions.assertThat (org.fest.assertions.Assertions.assertThat)5 MapAssert.entry (org.fest.assertions.MapAssert.entry)5 PropertiesProvider (org.icij.datashare.PropertiesProvider)5 BatchDownload (org.icij.datashare.batch.BatchDownload)5 PipelineRegistry (org.icij.datashare.extension.PipelineRegistry)5 CommonMode (org.icij.datashare.mode.CommonMode)5 EmailPipeline (org.icij.datashare.nlp.EmailPipeline)5