|
28 | 28 | import org.elasticsearch.index.mapper.ParseContext;
|
29 | 29 | import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
|
30 | 30 | import org.elasticsearch.index.mapper.attachment.test.MapperTestUtils;
|
31 |
| -import org.junit.Test; |
32 | 31 |
|
33 | 32 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
34 | 33 | import static org.elasticsearch.test.StreamsUtils.copyToBytesFromClasspath;
|
|
40 | 39 | */
|
41 | 40 | public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase {
|
42 | 41 |
|
43 |
| - @Test |
44 | 42 | public void testSimpleMappings() throws Exception {
|
45 | 43 | DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(createTempDir());
|
46 | 44 | mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
@@ -83,4 +81,36 @@ public void testContentBackcompat() throws Exception {
|
83 | 81 | ParseContext.Document doc = docMapper.parse("person", "person", "1", json).rootDoc();
|
84 | 82 | assertThat(doc.get("file"), containsString("This document tests the ability of Apache Tika to extract content"));
|
85 | 83 | }
|
| 84 | + |
| 85 | + /** |
| 86 | + * test for https://github.com/elastic/elasticsearch-mapper-attachments/issues/179 |
| 87 | + * @throws Exception |
| 88 | + */ |
| 89 | + public void testSimpleMappingsWithAllFields() throws Exception { |
| 90 | + DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(createTempDir()); |
| 91 | + mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser()); |
| 92 | + String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/simple/test-mapping-all-fields.json"); |
| 93 | + DocumentMapper docMapper = mapperParser.parse(mapping); |
| 94 | + byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/attachment/test/sample-files/testXHTML.html"); |
| 95 | + |
| 96 | + BytesReference json = jsonBuilder().startObject().field("file", html).endObject().bytes(); |
| 97 | + ParseContext.Document doc = docMapper.parse("person", "person", "1", json).rootDoc(); |
| 98 | + |
| 99 | + assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").fieldType().names().indexName()), startsWith("application/xhtml+xml")); |
| 100 | + assertThat(doc.get(docMapper.mappers().getMapper("file.title").fieldType().names().indexName()), equalTo("XHTML test document")); |
| 101 | + assertThat(doc.get(docMapper.mappers().getMapper("file.content").fieldType().names().indexName()), containsString("This document tests the ability of Apache Tika to extract content")); |
| 102 | + |
| 103 | + // re-parse it |
| 104 | + String builtMapping = docMapper.mappingSource().string(); |
| 105 | + docMapper = mapperParser.parse(builtMapping); |
| 106 | + |
| 107 | + json = jsonBuilder().startObject().field("file", html).endObject().bytes(); |
| 108 | + |
| 109 | + doc = docMapper.parse("person", "person", "1", json).rootDoc(); |
| 110 | + |
| 111 | + assertThat(doc.get(docMapper.mappers().getMapper("file.content_type").fieldType().names().indexName()), startsWith("application/xhtml+xml")); |
| 112 | + assertThat(doc.get(docMapper.mappers().getMapper("file.title").fieldType().names().indexName()), equalTo("XHTML test document")); |
| 113 | + assertThat(doc.get(docMapper.mappers().getMapper("file.content").fieldType().names().indexName()), containsString("This document tests the ability of Apache Tika to extract content")); |
| 114 | + } |
| 115 | + |
86 | 116 | }
|
0 commit comments