use of net.codestory.rest.Response in project datashare by ICIJ.
the class BatchSearchResourceTest method test_upload_batch_search_csv_with_all_parameters.
@Test
public void test_upload_batch_search_csv_with_all_parameters() {
when(batchSearchRepository.save(any())).thenReturn(true);
Response response = postRaw("/api/batch/search/prj", "multipart/form-data;boundary=AaB03x", new MultipartContentBuilder("AaB03x").addField("name", "my batch search").addField("description", "search description").addFile(new FileUpload("csvFile").withFilename("search.csv").withContentType("text/csv").withContent("query one\n" + "query two\r\n" + "query three\r\n")).addField("published", String.valueOf(true)).addField("fileTypes", "application/pdf").addField("fileTypes", "image/jpeg").addField("paths", "/path/to/document").addField("paths", "/other/path/").addField("fuzziness", String.valueOf(4)).addField("phrase_matches", String.valueOf(true)).build()).response();
assertThat(response.code()).isEqualTo(200);
ArgumentCaptor<BatchSearch> argument = ArgumentCaptor.forClass(BatchSearch.class);
verify(batchSearchRepository).save(argument.capture());
assertThat(argument.getValue().published).isTrue();
assertThat(argument.getValue().fileTypes).containsExactly("application/pdf", "image/jpeg");
assertThat(argument.getValue().paths).containsExactly("/path/to/document", "/other/path/");
assertThat(argument.getValue().fuzziness).isEqualTo(4);
assertThat(argument.getValue().phraseMatches).isTrue();
assertThat(argument.getValue().user).isEqualTo(User.local());
assertThat(argument.getValue().description).isEqualTo("search description");
Iterator<String> iterator = argument.getValue().queries.keySet().iterator();
assertThat(iterator.next()).isEqualTo("query one");
assertThat(iterator.next()).isEqualTo("query two");
assertThat(iterator.next()).isEqualTo("query three");
assertThat(iterator.hasNext()).isFalse();
}
use of net.codestory.rest.Response in project datashare by ICIJ.
the class NerResourceTest method test_post_text_returns_NamedEntity_list.
@Test
public void test_post_text_returns_NamedEntity_list() throws Exception {
Document doc = DocumentBuilder.createDoc("inline").with("This the 'foù' file content.").with(ENGLISH).build();
final Annotations annotations = new Annotations("inline", CORENLP, ENGLISH);
annotations.add(NlpStage.NER, 10, 13, NamedEntity.Category.PERSON);
doReturn(asList(NamedEntity.create(NamedEntity.Category.PERSON, "foù", asList(10L), doc.getId(), "root", CORENLP, ENGLISH))).when(pipeline).process(eq(doc));
Response response = post("/api/ner/findNames/CORENLP", doc.getContent()).response();
List actualNerList = TypeConvert.fromJson(response.content(), List.class);
assertThat(actualNerList).hasSize(1);
assertThat(actualNerList.get(0)).isInstanceOf(HashMap.class);
assertThat((Map) actualNerList.get(0)).includes(entry("mention", "foù"), entry("extractor", "CORENLP"), entry("mentionNorm", "fou"), entry("offsets", asList(10)));
}
Aggregations