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.cli;
1819import java.io.File;
20import java.io.IOException;
21import java.nio.charset.StandardCharsets;
22import java.util.Locale;
2324import org.apache.commons.io.FileUtils;
25import org.junit.Assert;
26import org.junit.Test;
27import org.slf4j.Logger;
28import org.slf4j.LoggerFactory;
2930/**31 * Unit test for issue ANY23-30832 *33 * @author Jacek Grzebyta (grzebyta.dev [at] gmail.com)34 */35publicclassYAMLRoverTestextendsToolTestBase {
3637privatestaticfinal String file1 = "/org/apache/any23/extractor/yaml/simple-load.yml";
3839privatestaticfinal String baseUri = "urn:test";
4041privatefinal Logger log = LoggerFactory.getLogger(getClass());
4243publicYAMLRoverTest() {
44super(Rover.class);
45 }
4647 @Test
48publicvoid simpleTest() throws Exception {
49 File outputFile = File.createTempFile("rover-test", ".ttl", tempDirectory);
50 File logfile = File.createTempFile("test-log", ".txt", tempDirectory);
5152int exitCode = runTool(
53 String.format(Locale.ROOT, "-l %s -o %s -f turtle -e yaml,csv -d %s %s", logfile.getAbsolutePath(),
54 outputFile.getAbsolutePath(), baseUri, copyResourceToTempFile(file1).getAbsolutePath()));
5556 Assert.assertTrue(logfile.exists());
57 log.debug("Log file location: {}", logfile.getAbsolutePath());
58 log.debug("Log file content: \n{}\n", FileUtils.readFileToString(logfile, StandardCharsets.UTF_8));
5960 Assert.assertEquals("Unexpected exit code.", 0, exitCode);
61 assertFileContainsString(outputFile, baseUri);
62 }
6364/**65 * Asserts if file contains wanted string.66 * 67 * If logging level is <code>trace</code> than additionally displays file content.68 * 69 * @param f70 * input file71 * @param s72 * Expected string in the file73 * 74 * @throws IOException75 * if there is an error reading the input data.76 */77publicvoid assertFileContainsString(File f, String s) throws IOException {
78 String fileContent = FileUtils.readFileToString(f, StandardCharsets.UTF_8);
79 log.trace("File content: \n{}\n", fileContent);
80 Assert.assertTrue(fileContent.contains(s));
81 }
8283 }