This project has retired. For details please refer to its
Attic page.
SimpleRoverTest xref
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.lang.invoke.MethodHandles;
21 import java.nio.charset.StandardCharsets;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.Locale;
25
26 import org.apache.commons.io.FileUtils;
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.junit.runners.Parameterized;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34
35
36
37
38
39 @RunWith(Parameterized.class)
40 public class SimpleRoverTest extends ToolTestBase {
41
42 private static final String baseUri = "urn:test";
43 private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
44
45 private String filePath;
46
47 @Parameterized.Parameters
48 public static Collection<String[]> litsFiles() throws Exception {
49 return Arrays.asList(new String[][] { { "/org/apache/any23/extractor/yaml/simple-load.yml" },
50 { "/org/apache/any23/extractor/csv/test-comma.csv" } });
51 }
52
53 public SimpleRoverTest(String filePath) {
54 super(Rover.class);
55 this.filePath = filePath;
56 }
57
58
59
60
61
62
63
64 @Test
65 public void ref310Test() throws Exception {
66 File outputFile = File.createTempFile("rover-test", ".ttl", tempDirectory);
67 File logfile = File.createTempFile("test-log", ".txt", tempDirectory);
68
69 int exitCode = runTool(
70 String.format(Locale.ROOT, "-l %s -o %s -f turtle -e yaml,csv -d %s %s", logfile.getAbsolutePath(),
71 outputFile.getAbsolutePath(), baseUri, copyResourceToTempFile(filePath).getAbsolutePath()));
72
73 Assert.assertTrue(logfile.exists());
74 Assert.assertTrue(outputFile.exists());
75
76 String outputFileContent = FileUtils.readFileToString(outputFile, StandardCharsets.UTF_8);
77 Assert.assertTrue(outputFileContent.length() > 10);
78
79 String[] logFileContent = FileUtils.readLines(logfile, StandardCharsets.UTF_8).toArray(new String[0]);
80 Assert.assertEquals(2, logFileContent.length);
81
82 int contentSize = Integer.valueOf(logFileContent[1].split("\\t")[1]);
83 String extractors = logFileContent[1].split("\\t")[4].replaceAll("[\\[\\]\\s:\\d]", "");
84
85 if (log.isDebugEnabled()) {
86 log.debug("Content: '{}'", contentSize);
87 log.debug("Extractors: '{}'", extractors);
88 log.debug("Log file location: {}", logfile.getAbsolutePath());
89 }
90 if (log.isTraceEnabled()) {
91 log.trace("Log file content: \n{}\n", FileUtils.readFileToString(logfile, StandardCharsets.UTF_8));
92 }
93
94 Assert.assertTrue("Content size should be greated than 0", contentSize > 0);
95 Assert.assertFalse(extractors.isEmpty());
96 Assert.assertEquals("Unexpected exit code.", 0, exitCode);
97 }
98
99
100
101
102
103
104
105
106
107
108
109 @Test
110 public void ref310ExtendedTest() throws Exception {
111 File outputFile = File.createTempFile("rover-test", ".ttl", tempDirectory);
112
113 int exitCode = runTool(String.format(Locale.ROOT, "-o %s -f turtle -e yaml,csv -d %s %s",
114 outputFile.getAbsolutePath(), baseUri, copyResourceToTempFile(filePath).getAbsolutePath()));
115
116 Assert.assertTrue(outputFile.exists());
117
118 String outputFileContent = FileUtils.readFileToString(outputFile, StandardCharsets.UTF_8);
119 Assert.assertTrue(outputFileContent.length() > 10);
120
121 Assert.assertEquals("Unexpected exit code.", 0, exitCode);
122 }
123
124 }