1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17package org.apache.any23.extractor.yaml;
1819import java.io.BufferedInputStream;
20import java.io.InputStream;
21import org.apache.any23.mime.MIMEType;
22import org.apache.any23.mime.TikaMIMETypeDetector;
23import org.apache.any23.mime.purifier.WhiteSpacesPurifier;
24import org.junit.Assert;
25import org.junit.Before;
26import org.junit.Test;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
2930/**31 * @author jacek32 */33publicclassYAMLTikaParserTest {
3435privatefinal String file1 = "/org/apache/any23/extractor/yaml/simple-load.yml";
3637privatefinal Logger log = LoggerFactory.getLogger(getClass());
3839private TikaMIMETypeDetector detector;
4041 @Before
42publicvoid prepareDetector() throws Exception {
43 detector = new TikaMIMETypeDetector(new WhiteSpacesPurifier());
44 }
4546/**47 * Yaml type is detected by file name only so detector returns octet type.48 * 49 * @throws Exception50 * if there is an error asserting the test data.51 */52 @Test
53publicvoid 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);
5758// Not currently doing stream detection for YAML, so it returns the default, octet-stream59 Assert.assertEquals("application/octet-stream", type.toString());
60 }
6162 @Test
63publicvoid tikaNameDetect() throws Exception {
64 String fileName = java.net.URI.create(file1).getPath();
6566 log.debug("normatised file name: {}", fileName);
67 MIMEType type = detector.guessMIMEType(fileName, null, null);
6869 Assert.assertEquals("text/x-yaml", type.toString());
70 }
7172 }