1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.any23.extractor.yaml;
18
19 import java.io.BufferedInputStream;
20 import java.io.InputStream;
21 import org.apache.any23.mime.MIMEType;
22 import org.apache.any23.mime.TikaMIMETypeDetector;
23 import org.apache.any23.mime.purifier.WhiteSpacesPurifier;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31
32
33 public class YAMLTikaParserTest {
34
35 private final String file1 = "/org/apache/any23/extractor/yaml/simple-load.yml";
36
37 private final Logger log = LoggerFactory.getLogger(getClass());
38
39 private TikaMIMETypeDetector detector;
40
41 @Before
42 public void prepareDetector() throws Exception {
43 detector = new TikaMIMETypeDetector(new WhiteSpacesPurifier());
44 }
45
46
47
48
49
50
51
52 @Test
53 public void tikaStreamDetect() throws Exception {
54 InputStream is = new BufferedInputStream(this.getClass().getResourceAsStream(file1));
55 Assert.assertNotNull("Could not find test file: " + file1, is);
56 MIMEType type = detector.guessMIMEType(null, is, null);
57
58
59 Assert.assertEquals("application/octet-stream", type.toString());
60 }
61
62 @Test
63 public void tikaNameDetect() throws Exception {
64 String fileName = java.net.URI.create(file1).getPath();
65
66 log.debug("normatised file name: {}", fileName);
67 MIMEType type = detector.guessMIMEType(fileName, null, null);
68
69 Assert.assertEquals("text/x-yaml", type.toString());
70 }
71
72 }