Search in sources :

Example 1 with Response

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

the class BatchSearchResourceTest method test_upload_batch_search_csv_less_that_2chars_queries_are_filtered.

@Test
public void test_upload_batch_search_csv_less_that_2chars_queries_are_filtered() {
    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("1\n" + "\n" + "query\r\n")).build()).response();
    assertThat(response.code()).isEqualTo(200);
    verify(batchSearchRepository).save(eq(new BatchSearch(response.content(), project("prj"), "my batch search", "search description", asSet("query"), new Date(), BatchSearch.State.RUNNING, User.local())));
}
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 2 with Response

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

the class BatchSearchResourceTest method testTripleQuote.

private void testTripleQuote(Boolean phraseMatch, String query, String tripleQuoteResult) {
    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").addFile(new FileUpload("csvFile").withFilename("search.csv").withContentType("text/csv").withContent(query + "\"query two\"\r\n" + "query three\r\n" + "query\" four\r\n")).addField("phrase_matches", String.valueOf(phraseMatch)).build()).response();
    assertThat(response.code()).isEqualTo(200);
    ArgumentCaptor<BatchSearch> argument = ArgumentCaptor.forClass(BatchSearch.class);
    verify(batchSearchRepository).save(argument.capture());
    assertThat(argument.getValue().queries.keySet()).containsOnly(tripleQuoteResult, "\"query two\"", "query three", "query\" four");
}
Also used : Response(net.codestory.rest.Response) BatchSearch(org.icij.datashare.batch.BatchSearch)

Example 3 with Response

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

the class BatchSearchResourceTest method test_upload_batch_search_csv_with_csvFile_with_60K_queries_should_send_request_too_large.

@Test
public void test_upload_batch_search_csv_with_csvFile_with_60K_queries_should_send_request_too_large() throws IOException {
    when(batchSearchRepository.save(any())).thenReturn(true);
    StringBuilder content = new StringBuilder();
    IntStream.range(0, 60000).boxed().collect(Collectors.toList()).forEach(i -> content.append("Test ").append(i).append("\r\n"));
    Response response = postRaw("/api/batch/search/prj", "multipart/form-data;boundary=AaB03x", new MultipartContentBuilder("AaB03x").addField("name", "nameValue").addFile(new FileUpload("csvFile").withContent(content.toString())).build()).response();
    assertThat(response.code()).isEqualTo(413);
}
Also used : Response(net.codestory.rest.Response) AbstractProdWebServerTest(org.icij.datashare.web.testhelpers.AbstractProdWebServerTest) Test(org.junit.Test)

Example 4 with Response

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

the class BatchSearchResourceTest method test_upload_batch_search_csv_with_name_and_csvfile_should_send_OK.

@Test
public void test_upload_batch_search_csv_with_name_and_csvfile_should_send_OK() throws InterruptedException {
    when(batchSearchRepository.save(any())).thenReturn(true);
    Response response = postRaw("/api/batch/search/prj", "multipart/form-data;boundary=AaB03x", new MultipartContentBuilder("AaB03x").addField("name", "nameValue").addFile(new FileUpload("csvFile").withContent("query\r\néèàç\r\n")).build()).response();
    assertThat(response.code()).isEqualTo(200);
    BatchSearch expected = new BatchSearch(response.content(), project("prj"), "nameValue", null, asSet("query", "éèàç"), new Date(), BatchSearch.State.QUEUED, User.local());
    verify(batchSearchRepository).save(eq(expected));
    assertThat(batchSearchQueue.take()).isEqualTo(expected.uuid);
}
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 5 with Response

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

the class WebLocalAcceptanceTest method test_get_version.

@Test
public void test_get_version() throws Exception {
    Response response = get("/version").response();
    assertThat(response.code()).isEqualTo(200);
    assertThat(response.contentType()).contains("application/json");
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> map = mapper.readValue(response.content(), new TypeReference<Map<String, Object>>() {
    });
    assertThat(map.keySet()).contains("git.commit.id", "git.commit.id.abbrev");
}
Also used : Response(net.codestory.rest.Response) Map(java.util.Map) HashMap(java.util.HashMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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