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 */1718package org.apache.any23.cli;
1920import org.apache.any23.cli.flows.PeopleExtractor;
21import org.apache.any23.rdf.RDFUtils;
22import org.apache.commons.io.FileUtils;
23import org.eclipse.rdf4j.model.Model;
24import org.eclipse.rdf4j.model.impl.TreeModel;
25import org.eclipse.rdf4j.rio.Rio;
26import org.junit.Assert;
27import org.junit.Test;
28import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
3031import java.io.BufferedInputStream;
32import java.io.File;
33import java.io.FileInputStream;
34import java.lang.invoke.MethodHandles;
35import java.util.Arrays;
36import java.util.Locale;
37import java.util.stream.Stream;
3839/**40 * This is example for task ANY23-39641 *42 * @author Jacek Grzebyta (jgrzebyta@apache.org)43 * @author Hans Brende (hansbrende@apache.org)44 */45publicclassExtractorsFlowTestextendsToolTestBase {
4647privatestaticfinal String testingDatafile = "/org/apache/any23/extractor/csv/test-comma.csv";
48privatestaticfinal Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
4950publicExtractorsFlowTest() {
51super(Rover.class);
52 }
5354/**55 * Emulates action described in ANY23-396.56 * 57 * @throws Exception58 * if there is an error asserting the test data.59 */60 @Test
61publicvoid runTestFor396() throws Exception {
62 File outputFile = File.createTempFile("mockdata-", ".ttl", tempDirectory);
63 File logFile = File.createTempFile("log-exec-", ".txt", tempDirectory);
6465 runTool(String.format(Locale.ROOT, "-l %s -o %s -f people,turtle -e csv -d %s %s", logFile.getAbsolutePath(),
66 outputFile.getAbsolutePath(), PeopleExtractor.RAW_NS,
67 copyResourceToTempFile(testingDatafile).getAbsolutePath()));
6869// populate expected model70 Model expected = new TreeModel();
71 Stream.of("Davide Palmisano", "Michele Mostarda", "Giovanni Tummarello").map(PeopleExtractor::createPerson)
72 .forEach(expected::addAll);
7374if (log.isDebugEnabled()) {
75 log.debug("\n\nlog file content:\n{}", FileUtils.readFileToString(logFile, "utf-8"));
76 log.debug("\n\nData file: \n{}", FileUtils.readFileToString(outputFile, "utf-8"));
77 }
7879 Assert.assertTrue(assertCompareModels(expected, outputFile));
80 }
8182/**83 * Compare expected model and received from input File.84 * 85 * @throws Exception86 * if there is an error asserting the test data.87 */88privateboolean assertCompareModels(Model expected, File received) throws Exception {
89 Model receivedModel = new TreeModel();
90 receivedModel.addAll(Arrays.asList(
91 RDFUtils.parseRDF(Rio.getParserFormatForFileName(received.getName()).orElseThrow(AssertionError::new),
92new BufferedInputStream(new FileInputStream(received)), received.toURI().toString())));
9394return receivedModel.containsAll(expected);
95 }
96 }