Search in sources :

Example 6 with Response

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();
}
Also used : Response(net.codestory.rest.Response) BatchSearch(org.icij.datashare.batch.BatchSearch) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 7 with Response

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)));
}
Also used : Response(net.codestory.rest.Response) Annotations(org.icij.datashare.text.nlp.Annotations) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Document(org.icij.datashare.text.Document) HashMap(java.util.HashMap) Map(java.util.Map) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Aggregations

Response (net.codestory.rest.Response)7 AbstractProdWebServerTest (org.icij.datashare.web.testhelpers.AbstractProdWebServerTest)6 Test (org.junit.Test)6 BatchSearch (org.icij.datashare.batch.BatchSearch)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 List (java.util.List)1 Document (org.icij.datashare.text.Document)1 Annotations (org.icij.datashare.text.nlp.Annotations)1