use of net.codestory.rest.RestAssert 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));
}
use of net.codestory.rest.RestAssert 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));
}
use of net.codestory.rest.RestAssert in project datashare by ICIJ.
the class CommonModeTest method test_one_extension.
RestAssert test_one_extension(String method, String prefix) throws Throwable {
String prefixString = prefix == null ? "\n" : "@Prefix(\"" + prefix + "\")\n";
String source = format("package org.icij.datashare.mode;\n" + "\n" + "import net.codestory.http.annotations.%s;\n" + "import net.codestory.http.annotations.Prefix;\n" + "\n" + prefixString + "public class FooResource {\n" + " @%s(\"url\")\n" + " public String url() {\n" + " return \"hello from foo extension with %s\";\n" + " }\n" + "}", method, method, method);
createJar(pluginFolder.getRoot().toPath(), "extension", source);
configure(routes -> mode.addExtensionConfiguration(routes));
Method restAssertMethod = FluentRestTest.class.getMethod(method.toLowerCase(), String.class);
return (RestAssert) restAssertMethod.invoke(this, ofNullable(prefix).orElse("") + "/url");
}
use of net.codestory.rest.RestAssert 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"));
}
use of net.codestory.rest.RestAssert 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());
}
Aggregations