/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.openjena.riot.lang; import org.junit.Test ; import org.openjena.atlas.junit.BaseTest ; import org.openjena.atlas.lib.Sink ; import org.openjena.atlas.lib.StrUtils ; import org.openjena.riot.RiotLoader ; import org.openjena.riot.RiotReader ; import org.openjena.riot.ErrorHandlerTestLib.ErrorHandlerEx ; import org.openjena.riot.ErrorHandlerTestLib.ExWarning ; import org.openjena.riot.tokens.Tokenizer ; import org.openjena.riot.tokens.TokenizerFactory ; import com.hp.hpl.jena.graph.Triple ; import com.hp.hpl.jena.sparql.core.DatasetGraph ; import com.hp.hpl.jena.sparql.core.Quad ; import com.hp.hpl.jena.sparql.lib.DatasetLib ; import com.hp.hpl.jena.sparql.sse.SSE ; /** Test the behaviour of the RIOT reader for TriG. TriG includes checking of terms */ public class TestLangTrig extends BaseTest { @Test public void trig_01() { parse("{}") ; } @Test public void trig_02() { parse("{}.") ; } @Test public void trig_03() { parse(" {}") ; } @Test public void trig_04() { parse(" = {}") ; } @Test public void trig_05() { parse(" = {} .") ; } // Need to check we get resolved URIs. @Test public void trig_10() //{ parse("{

}") ; } { DatasetGraph dsg = parse("{

}") ; assertEquals(1, dsg.getDefaultGraph().size()) ; Triple t = dsg.getDefaultGraph().find(null,null,null).next(); Triple t2 = SSE.parseTriple("( )") ; assertEquals(t2, t) ; } @Test public void trig_11() { DatasetGraph dsg = parse("@prefix ex: .", "{ ex:s ex:p 123 }") ; assertEquals(1, dsg.getDefaultGraph().size()) ; Triple t = dsg.getDefaultGraph().find(null,null,null).next(); Triple t2 = SSE.parseTriple("( 123)") ; } @Test public void trig_12() { parse("@prefix xsd: .", "{

'1'^^xsd:byte }") ; } // Also need to check that the RiotExpection is called in normal use. // Bad terms. @Test (expected=ExWarning.class) public void trig_20() { parse("@prefix ex: .", "{ ex:s ex:p 123 }") ; } @Test (expected=ExWarning.class) public void trig_21() { parse("@prefix ex: .", "{ ex:s 123 }") ; } @Test (expected=ExWarning.class) public void trig_22() { parse("{

'number'^^ }") ; } @Test (expected=ExWarning.class) public void trig_23() { parse("@prefix xsd: .", "{

'number'^^xsd:byte }") ; } //Check reading into a dataset. private static DatasetGraph parse(String... strings) { String string = StrUtils.strjoin("\n", strings) ; DatasetGraph dsg = DatasetLib.createDatasetGraphMem() ; Sink sink = RiotLoader.datasetSink(dsg) ; Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(string) ; LangTriG parser = RiotReader.createParserTriG(tokenizer, "http://base/", sink) ; parser.getProfile().setHandler(new ErrorHandlerEx()) ; try { parser.parse(); } finally { sink.close() ; } return dsg ; } }