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())));
}
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");
}
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);
}
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);
}
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");
}
Aggregations