SourceExtractor { public InputStream getSource(final Document document) throws FileNotFoundException { return getSource(document.getProject(), document); }  InputStream getSource(final Document document); InputStream getSource(final Project project, final Document document);  }
@Test public void test_get_source_for_root_doc() throws IOException { Document document = new Document(project("project"), get(getClass().getResource("/docs/embedded_doc.eml").getPath()), "it has been parsed", Language.FRENCH, Charset.defaultCharset(), "message/rfc822", new HashMap<>(), Document.Status.INDEXED, 45L); InputStream source = new SourceExtractor().getSource(document); assertThat(source).isNotNull(); assertThat(getBytes(source)).hasSize(70574); }
@Test public void test_get_source_for_embedded_doc() throws Exception { DocumentFactory tikaFactory = new DocumentFactory().configure(Options.from(new HashMap<String, String>() {{ put("idDigestMethod", Document.HASHER.toString()); }})); Path path = get(getClass().getResource("/docs/embedded_doc.eml").getPath()); Extractor extractor = new Extractor(tikaFactory); extractor.setDigester(new UpdatableDigester(TEST_INDEX, Document.HASHER.toString())); final TikaDocument document = extractor.extract(path); ElasticsearchSpewer spewer = new ElasticsearchSpewer(es.client, l -> Language.ENGLISH, new FieldNames(), Mockito.mock(Publisher.class), new PropertiesProvider()).withRefresh(IMMEDIATE).withIndex(TEST_INDEX); spewer.write(document); Document attachedPdf = new ElasticsearchIndexer(es.client, new PropertiesProvider()). get(TEST_INDEX, "1bf2b6aa27dd8b45c7db58875004b8cb27a78ced5200b4976b63e351ebbae5ececb86076d90e156a7cdea06cde9573ca", "f4078910c3e73a192e3a82d205f3c0bdb749c4e7b23c1d05a622db0f07d7f0ededb335abdb62aef41ace5d3cdb9298bc"); assertThat(attachedPdf).isNotNull(); assertThat(attachedPdf.getContentType()).isEqualTo("application/pdf"); InputStream source = new SourceExtractor().getSource(project(TEST_INDEX), attachedPdf); assertThat(source).isNotNull(); assertThat(getBytes(source)).hasSize(49779); }