27
27
import org .elasticsearch .index .mapper .ParseContext ;
28
28
import org .elasticsearch .index .mapper .attachment .AttachmentMapper ;
29
29
import org .elasticsearch .index .mapper .attachment .test .MapperTestUtils ;
30
+ import org .junit .BeforeClass ;
30
31
import org .junit .Test ;
31
32
32
33
import java .io .IOException ;
35
36
import static org .elasticsearch .common .io .Streams .copyToBytesFromClasspath ;
36
37
import static org .elasticsearch .common .io .Streams .copyToStringFromClasspath ;
37
38
import static org .elasticsearch .common .xcontent .XContentFactory .jsonBuilder ;
39
+ import static org .elasticsearch .index .mapper .attachment .AttachmentMapper .FieldNames .*;
38
40
import static org .elasticsearch .plugin .mapper .attachments .tika .TikaInstance .tika ;
39
41
import static org .hamcrest .Matchers .isEmptyOrNullString ;
40
42
import static org .hamcrest .Matchers .not ;
44
46
*/
45
47
public class VariousDocTest extends AttachmentUnitTestCase {
46
48
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
+
47
60
/**
48
61
* Test for https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/104
49
62
*/
@@ -91,6 +104,16 @@ public void testTxtDocument() throws Exception {
91
104
testMapper ("text-in-english.txt" , false );
92
105
}
93
106
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
+
94
117
protected void testTika (String filename , boolean errorExpected ) {
95
118
Tika tika = tika ();
96
119
assumeTrue ("Tika has been disabled. Ignoring test..." , tika != null );
@@ -107,11 +130,6 @@ protected void testTika(String filename, boolean errorExpected) {
107
130
}
108
131
109
132
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 );
115
133
byte [] html = copyToBytesFromClasspath ("/org/elasticsearch/index/mapper/attachment/test/sample-files/" + filename );
116
134
117
135
BytesReference json = jsonBuilder ()
@@ -126,7 +144,20 @@ protected void testMapper(String filename, boolean errorExpected) throws IOExcep
126
144
ParseContext .Document doc = docMapper .parse (json ).rootDoc ();
127
145
if (!errorExpected ) {
128
146
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 );
130
157
}
131
158
}
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
+ }
132
163
}
0 commit comments