Search in sources :

Example 1 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadRunnerEncryptedIntTest method test_zip_with_password_should_encrypt_file_and_send_mail.

@Test
public void test_zip_with_password_should_encrypt_file_and_send_mail() throws Exception {
    new IndexerHelper(es.client).indexFile("mydoc.txt", "content", fs);
    BatchDownload batchDownload = createBatchDownload("*");
    MailSender mailSender = mock(MailSender.class);
    new BatchDownloadRunner(indexer, createProvider(), batchDownload, updateCallback, (uri) -> mailSender).call();
    assertThat(new net.lingala.zip4j.ZipFile(batchDownload.filename.toFile()).isEncrypted()).isTrue();
    ArgumentCaptor<Mail> mailCaptor = ArgumentCaptor.forClass(Mail.class);
    verify(mailSender).send(mailCaptor.capture());
    assertThat(mailCaptor.getValue().from).isEqualTo("engineering@icij.org");
    assertThat(mailCaptor.getValue().toRecipientList).containsExactly("foo@bar.com");
    assertThat(mailCaptor.getValue().subject).isEqualTo("[datashare] " + batchDownload.filename.getFileName());
}
Also used : ElasticsearchRule(org.icij.datashare.test.ElasticsearchRule) MockitoAnnotations.initMocks(org.mockito.MockitoAnnotations.initMocks) PropertiesProvider(org.icij.datashare.PropertiesProvider) ElasticsearchIndexer(org.icij.datashare.text.indexing.elasticsearch.ElasticsearchIndexer) Mock(org.mockito.Mock) IOException(java.io.IOException) HashMap(java.util.HashMap) TEST_INDEX(org.icij.datashare.test.ElasticsearchRule.TEST_INDEX) Function(java.util.function.Function) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) MailSender(org.icij.datashare.com.mail.MailSender) User(org.icij.datashare.user.User) Project.project(org.icij.datashare.text.Project.project) org.junit(org.junit) IMMEDIATE(org.elasticsearch.action.support.WriteRequest.RefreshPolicy.IMMEDIATE) BatchDownload(org.icij.datashare.batch.BatchDownload) NotNull(org.jetbrains.annotations.NotNull) Mail(org.icij.datashare.com.mail.Mail) TemporaryFolder(org.junit.rules.TemporaryFolder) Mockito.mock(org.mockito.Mockito.mock) BatchDownload(org.icij.datashare.batch.BatchDownload) Mail(org.icij.datashare.com.mail.Mail) MailSender(org.icij.datashare.com.mail.MailSender)

Example 2 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadRunnerIntTest method test_embedded_doc_with_not_found_embedded_should_not_interrupt_zip_creation.

@Test
public void test_embedded_doc_with_not_found_embedded_should_not_interrupt_zip_creation() throws Exception {
    new IndexerHelper(es.client).indexEmbeddedFile("bad_project_name", "/docs/embedded_doc.eml");
    BatchDownload batchDownload = createBatchDownload("*");
    new BatchDownloadRunner(indexer, createProvider(), batchDownload, updateCallback).call();
    assertThat(new ZipFile(batchDownload.filename.toFile()).size()).isEqualTo(1);
}
Also used : BatchDownload(org.icij.datashare.batch.BatchDownload) ZipFile(java.util.zip.ZipFile)

Example 3 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadRunnerIntTest method test_one_result.

@Test
public void test_one_result() throws Exception {
    String content = "The quick brown fox jumps over the lazy dog";
    File file = new IndexerHelper(es.client).indexFile("mydoc.txt", content, fs);
    BatchDownload bd = createBatchDownload("fox");
    new BatchDownloadRunner(indexer, createProvider(), bd, updateCallback).call();
    assertThat(bd.filename.toFile()).isFile();
    assertThat(new ZipFile(bd.filename.toFile()).size()).isEqualTo(1);
    assertThat(new ZipFile(bd.filename.toFile()).getEntry(file.toString().substring(1))).isNotNull();
    assertThat(new ZipFile(bd.filename.toFile()).getEntry(file.toString().substring(1)).getSize()).isEqualTo(content.length());
    verify(updateCallback).apply(any());
}
Also used : BatchDownload(org.icij.datashare.batch.BatchDownload) ZipFile(java.util.zip.ZipFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 4 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadRunnerIntTest method test_empty_response.

@Test
public void test_empty_response() throws Exception {
    BatchDownload bd = createBatchDownload("query");
    new BatchDownloadRunner(indexer, createProvider(), bd, updateCallback).call();
    assertThat(bd.filename.toFile()).doesNotExist();
    verify(updateCallback, never()).apply(any());
}
Also used : BatchDownload(org.icij.datashare.batch.BatchDownload)

Example 5 with BatchDownload

use of org.icij.datashare.batch.BatchDownload in project datashare by ICIJ.

the class BatchDownloadRunnerIntTest method test_two_results.

@Test
public void test_two_results() throws Exception {
    new IndexerHelper(es.client).indexFile("doc1.txt", "The quick brown fox jumps over the lazy dog", fs);
    new IndexerHelper(es.client).indexFile("doc2.txt", "Portez ce vieux whisky au juge blond qui fume", fs);
    BatchDownload bd = createBatchDownload("*");
    new BatchDownloadRunner(indexer, createProvider(), bd, updateCallback).call();
    assertThat(bd.filename.toFile()).isFile();
    assertThat(new ZipFile(bd.filename.toFile()).size()).isEqualTo(2);
    verify(updateCallback, times(2)).apply(any());
}
Also used : BatchDownload(org.icij.datashare.batch.BatchDownload) ZipFile(java.util.zip.ZipFile)

Aggregations

BatchDownload (org.icij.datashare.batch.BatchDownload)21 ZipFile (java.util.zip.ZipFile)9 PropertiesProvider (org.icij.datashare.PropertiesProvider)8 File (java.io.File)7 Test (org.junit.Test)7 Path (java.nio.file.Path)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)4 Function (java.util.function.Function)3 Assertions.assertThat (org.fest.assertions.Assertions.assertThat)3 Project.project (org.icij.datashare.text.Project.project)3 Indexer (org.icij.datashare.text.indexing.Indexer)3 User (org.icij.datashare.user.User)3 TemporaryFolder (org.junit.rules.TemporaryFolder)3 Mock (org.mockito.Mock)3 MockitoAnnotations.initMocks (org.mockito.MockitoAnnotations.initMocks)3 String.valueOf (java.lang.String.valueOf)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2