N3ParserTest.java
/*******************************************************************************
* Copyright (c) 2020 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
package org.eclipse.rdf4j.rio.n3;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.StringReader;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.vocabulary.OWL;
import org.eclipse.rdf4j.rio.helpers.ParseErrorCollector;
import org.eclipse.rdf4j.rio.helpers.SimpleParseLocationListener;
import org.eclipse.rdf4j.rio.helpers.StatementCollector;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/**
* @author tanisha
*/
public class N3ParserTest {
private N3Parser parser;
private final ValueFactory vf = SimpleValueFactory.getInstance();
private final ParseErrorCollector errorCollector = new ParseErrorCollector();
private final StatementCollector statementCollector = new StatementCollector();
private final String prefixes = "@prefix ex: <http://example.org/ex/> . \n@prefix : <http://example.org/> . \n";
private final String baseURI = "http://example.org/";
private final SimpleParseLocationListener locationListener = new SimpleParseLocationListener();
@BeforeEach
public void setUp() {
parser = new N3Parser();
parser.setParseErrorListener(errorCollector);
parser.setRDFHandler(statementCollector);
parser.setParseLocationListener(locationListener);
}
@Test
public void testParseEquals() throws IOException {
String data = prefixes + " ex:foo = ex:bar. ";
parser.parse(new StringReader(data), baseURI);
assertTrue(errorCollector.getWarnings().isEmpty());
assertTrue(errorCollector.getErrors().isEmpty());
assertTrue(errorCollector.getFatalErrors().isEmpty());
assertThat(statementCollector.getStatements()).containsExactly(vf.createStatement(
vf.createIRI("http://example.org/ex/foo"), OWL.SAMEAS, vf.createIRI("http://example.org/ex/bar")));
}
}