package eu.dnetlib.ariadneplus.virtuoso;

import java.io.IOException;
import java.io.InputStream;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.RDFFormat;
import org.apache.jena.riot.RIOT;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.springframework.core.io.ClassPathResource;

/**
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.
 */
@RunWith(JUnit4.class)
public class ExampleIO_01 {

	@Test
		public void test() throws IOException {
			InputStream in = getResourceAsStream("eu/dnetlib/ariadneplus/virtuoso/data.ttl");

			RIOT.init() ;

			Model model = ModelFactory.createDefaultModel(); // creates an in-memory Jena Model
			model.read(in, null, "TURTLE"); // parses an InputStream assuming RDF in Turtle format

			// Write the Jena Model in Turtle, RDF/XML and N-Triples format
			System.out.println("\n---- Turtle ----");
			model.write(System.out, "TURTLE");
			System.out.println("\n---- RDF/XML ----");
			model.write(System.out, "RDF/XML");
			System.out.println("\n---- RDF/XML Abbreviated ----");
			model.write(System.out, "RDF/XML-ABBREV");
			System.out.println("\n---- N-Triples ----");
			model.write(System.out, "N-TRIPLES");
			System.out.println("\n---- RDF/JSON ----");
			model.write(System.out, "RDF/JSON");
			RDFDataMgr.write(System.out, model.getGraph(), RDFFormat.RDFXML_PLAIN);
			System.out.println("\n----RDFDataMgr with model and RDFFormat.RDFXML_PLAIN ----");
			RDFDataMgr.write(System.out, model, RDFFormat.RDFXML_PLAIN);


		}

		@Test
		public void testPropertyNamespace(){
			Property p = ResourceFactory.createProperty("dnet:", "transformedInDate");
			System.out.println(p.toString());
		}

	@Test
	public void testPropertyNamespaceUrl(){
		String ns = "http://www.d-net.research-infrastructures.eu/provenance/";
		Property p = ResourceFactory.createProperty(ns, "transformedInDate");
		System.out.println(p.toString());
	}

	private InputStream getResourceAsStream(final String classpath) throws IOException {
		final ClassPathResource resource = new ClassPathResource(classpath);
		return resource.getInputStream();
	}

}
