Repository: any23 Updated Branches: refs/heads/master 62e040b9a -> 5a486b29f
Ref ANY23-310 - created unit test Signed-off-by: Jacek Grzebyta <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/any23/repo Commit: http://git-wip-us.apache.org/repos/asf/any23/commit/1b68735f Tree: http://git-wip-us.apache.org/repos/asf/any23/tree/1b68735f Diff: http://git-wip-us.apache.org/repos/asf/any23/diff/1b68735f Branch: refs/heads/master Commit: 1b68735f918361182aa5e30f08fd5f221ef0dda9 Parents: b0baa94 Author: Jacek Grzebyta <[email protected]> Authored: Thu Jul 13 19:08:56 2017 +0100 Committer: Jacek Grzebyta <[email protected]> Committed: Thu Jul 13 19:25:18 2017 +0100 ---------------------------------------------------------------------- .../org/apache/any23/cli/SimpleRoverTest.java | 97 ++++++++++++++++++++ cli/src/test/resources/log4j.properties | 1 + 2 files changed, 98 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/any23/blob/1b68735f/cli/src/test/java/org/apache/any23/cli/SimpleRoverTest.java ---------------------------------------------------------------------- diff --git a/cli/src/test/java/org/apache/any23/cli/SimpleRoverTest.java b/cli/src/test/java/org/apache/any23/cli/SimpleRoverTest.java new file mode 100644 index 0000000..76cd5cf --- /dev/null +++ b/cli/src/test/java/org/apache/any23/cli/SimpleRoverTest.java @@ -0,0 +1,97 @@ +/* + * Copyright 2017 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.any23.cli; + +import com.google.common.io.Files; +import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import org.apache.any23.util.FileUtils; +import org.apache.pdfbox.util.Charsets; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Unit test for issue ANY23-310 + * + * @author Jacek Grzebyta (grzebyta.dev [at] gmail.com) + */ +@RunWith(Parameterized.class) +public class SimpleRoverTest extends ToolTestBase { + + private static final String baseUri = "urn:test"; + private static final Logger log = LoggerFactory.getLogger(SimpleRoverTest.class); + + private String filePath; + + @Parameterized.Parameters + public static Collection<String[]> litsFiles() throws Exception { + return Arrays.asList(new String[][] { + {"/org/apache/any23/extractor/yaml/simple-load.yml"}, + {"/org/apache/any23/extractor/csv/test-comma.csv"} + }); + } + + + public SimpleRoverTest(String filePath) { + super(Rover.class); + this.filePath = filePath; + } + + /** + * Ref {@link https://issues.apache.org/jira/browse/ANY23-310} unit test. + * @throws Exception + */ + @Test + public void ref310Test() + throws Exception { + File outputFile = File.createTempFile("rover-test", ".ttl", tempDirectory); + File logfile = File.createTempFile("test-log", ".txt", tempDirectory); + + int exitCode = runTool(String.format("-l %s -o %s -f turtle -e yaml,csv -d %s %s", + logfile.getAbsolutePath(), + outputFile.getAbsolutePath(), + baseUri, + copyResourceToTempFile(filePath).getAbsolutePath())); + + Assert.assertTrue(logfile.exists()); + Assert.assertTrue(outputFile.exists()); + // check if output file is longer than 10 chracters + String outputFileContent = FileUtils.readFileContent(outputFile); + Assert.assertTrue(outputFileContent.length() > 10); + + String[] logFileContent = FileUtils.readFileLines(logfile); + Assert.assertTrue(logFileContent.length == 2); + //Assert.assertTrue(logFileContent[1].split("\\W*")[1] == ); + int contentSize = Integer.valueOf(logFileContent[1].split("\\t")[1]); + log.info("Content: '{}'", contentSize); + String extractors = logFileContent[1].split("\\t")[4].replaceAll("[\\[\\]\\s:\\d]", ""); + log.info("Extractors: '{}'", extractors); + + + log.debug("Log file location: {}", logfile.getAbsolutePath()); + log.trace("Log file content: \n{}\n", Files.toString(logfile, Charsets.UTF_8)); + + Assert.assertTrue("Content size should be greated than 0", contentSize > 0); + Assert.assertFalse(extractors.isEmpty()); + Assert.assertEquals("Unexpected exit code.", 0, exitCode); + } + +} http://git-wip-us.apache.org/repos/asf/any23/blob/1b68735f/cli/src/test/resources/log4j.properties ---------------------------------------------------------------------- diff --git a/cli/src/test/resources/log4j.properties b/cli/src/test/resources/log4j.properties index f286f6a..b6af94e 100644 --- a/cli/src/test/resources/log4j.properties +++ b/cli/src/test/resources/log4j.properties @@ -13,6 +13,7 @@ # limitations under the License. log4j.logger.org.apache.any23.cli.YAMLRoverTest=trace +log4j.logger.org.apache.any23.cli.SimpleRoverTest=debug log4j.rootLogger=INFO, A1
