Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit e8ca6ca

Browse files
committed
Add test for asciidoc format
Related to #29. (cherry picked from commit cfd8344) (cherry picked from commit 06eb785)
1 parent d6d63f7 commit e8ca6ca

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

src/test/java/org/elasticsearch/index/mapper/attachment/test/unit/VariousDocTest.java

+37-6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.index.mapper.ParseContext;
2828
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
2929
import org.elasticsearch.index.mapper.attachment.test.MapperTestUtils;
30+
import org.junit.BeforeClass;
3031
import org.junit.Test;
3132

3233
import java.io.IOException;
@@ -35,6 +36,7 @@
3536
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
3637
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
3738
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
39+
import static org.elasticsearch.index.mapper.attachment.AttachmentMapper.FieldNames.*;
3840
import static org.elasticsearch.plugin.mapper.attachments.tika.TikaInstance.tika;
3941
import static org.hamcrest.Matchers.isEmptyOrNullString;
4042
import static org.hamcrest.Matchers.not;
@@ -44,6 +46,17 @@
4446
*/
4547
public class VariousDocTest extends AttachmentUnitTestCase {
4648

49+
protected static DocumentMapper docMapper;
50+
51+
@BeforeClass
52+
public static void createMapper() throws IOException {
53+
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder().build());
54+
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
55+
56+
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/various-doc/test-mapping.json");
57+
docMapper = mapperParser.parse(mapping);
58+
}
59+
4760
/**
4861
* Test for https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/104
4962
*/
@@ -91,6 +104,16 @@ public void testTxtDocument() throws Exception {
91104
testMapper("text-in-english.txt", false);
92105
}
93106

107+
/**
108+
* Test for ASCIIDOC
109+
* Not yet supported by Tika: https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/29
110+
*/
111+
@Test
112+
public void testAsciidocDocument() throws Exception {
113+
testTika("asciidoc.asciidoc", false);
114+
testMapper("asciidoc.asciidoc", false);
115+
}
116+
94117
protected void testTika(String filename, boolean errorExpected) {
95118
Tika tika = tika();
96119
assumeTrue("Tika has been disabled. Ignoring test...", tika != null);
@@ -107,11 +130,6 @@ protected void testTika(String filename, boolean errorExpected) {
107130
}
108131

109132
protected void testMapper(String filename, boolean errorExpected) throws IOException {
110-
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder().build());
111-
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
112-
113-
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/various-doc/test-mapping.json");
114-
DocumentMapper docMapper = mapperParser.parse(mapping);
115133
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/" + filename);
116134

117135
BytesReference json = jsonBuilder()
@@ -126,7 +144,20 @@ protected void testMapper(String filename, boolean errorExpected) throws IOExcep
126144
ParseContext.Document doc = docMapper.parse(json).rootDoc();
127145
if (!errorExpected) {
128146
assertThat(doc.get(docMapper.mappers().smartName("file").mapper().names().indexName()), not(isEmptyOrNullString()));
129-
logger.debug("extracted content: {}", doc.get(docMapper.mappers().smartName("file").mapper().names().indexName()));
147+
logger.debug("-> extracted content: {}", doc.get(docMapper.mappers().smartName("file").mapper().names().indexName()));
148+
logger.debug("-> extracted metadata:");
149+
printMetadataContent(doc, AUTHOR);
150+
printMetadataContent(doc, CONTENT_LENGTH);
151+
printMetadataContent(doc, CONTENT_TYPE);
152+
printMetadataContent(doc, DATE);
153+
printMetadataContent(doc, KEYWORDS);
154+
printMetadataContent(doc, LANGUAGE);
155+
printMetadataContent(doc, NAME);
156+
printMetadataContent(doc, TITLE);
130157
}
131158
}
159+
160+
private void printMetadataContent(ParseContext.Document doc, String field) {
161+
logger.debug("- [{}]: [{}]", field, doc.get(docMapper.mappers().smartName("file." + field).mapper().names().indexName()));
162+
}
132163
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[[tika-asciidoc]]
2+
= AsciiDoc test
3+
4+
Here is a test of the asciidoc format.
5+

0 commit comments

Comments
 (0)