1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.any23.cli;
18
19 import java.io.File;
20 import java.io.IOException;
21 import java.nio.charset.StandardCharsets;
22 import java.util.Locale;
23
24 import org.apache.commons.io.FileUtils;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31
32
33
34
35 public class YAMLRoverTest extends ToolTestBase {
36
37 private static final String file1 = "/org/apache/any23/extractor/yaml/simple-load.yml";
38
39 private static final String baseUri = "urn:test";
40
41 private final Logger log = LoggerFactory.getLogger(getClass());
42
43 public YAMLRoverTest() {
44 super(Rover.class);
45 }
46
47 @Test
48 public void simpleTest() throws Exception {
49 File outputFile = File.createTempFile("rover-test", ".ttl", tempDirectory);
50 File logfile = File.createTempFile("test-log", ".txt", tempDirectory);
51
52 int 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()));
55
56 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));
59
60 Assert.assertEquals("Unexpected exit code.", 0, exitCode);
61 assertFileContainsString(outputFile, baseUri);
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public void 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 }
82
83 }