Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Added additional test for impl.sparql
  • Loading branch information
retog committed Jan 26, 2017
1 parent 3da2f8b commit d5f31ce0b5a23fab7123e211f676d466dd540d1f
Showing 4 changed files with 111 additions and 40 deletions.
@@ -0,0 +1,94 @@
/*
* Copyright 2015 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.clerezza.commons.rdf.impl.sparql;

import com.hp.hpl.jena.query.DatasetAccessor;
import com.hp.hpl.jena.query.DatasetAccessorFactory;
import java.io.IOException;
import java.net.ServerSocket;
import org.apache.jena.fuseki.EmbeddedFusekiServer;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.clerezza.commons.rdf.Graph;
import org.apache.clerezza.commons.rdf.IRI;
import org.apache.clerezza.commons.rdf.Language;
import org.apache.clerezza.commons.rdf.Literal;
import org.apache.clerezza.commons.rdf.RDFTerm;
import org.apache.clerezza.commons.rdf.Triple;
import org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl;
import org.apache.clerezza.rdf.core.serializedform.Serializer;
import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

/**
*
* @author reto
*/
public class Dadmin2Test {

final static int serverPort = findFreePort();
static EmbeddedFusekiServer server;

@BeforeClass
public static void prepare() throws IOException {
final String serviceURI = "http://localhost:" + serverPort + "/ds/data";
final DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(serviceURI);
final InputStream in = Dadmin2Test.class.getResourceAsStream("dadmin2.ttl");
final Model m = ModelFactory.createDefaultModel();
String base = "http://example.org/";
m.read(in, base, "TURTLE");
server = EmbeddedFusekiServer.memTDB(serverPort, "/ds");//dataSet.getAbsolutePath());
server.start();
System.out.println("Started fuseki on port " + serverPort);
accessor.putModel(m);
}

@AfterClass
public static void cleanup() {
server.stop();
}

@Test
public void graphSize() {
final Graph graph = new SparqlGraph("http://localhost:" + serverPort + "/ds/query");
Assert.assertEquals("Graph not of the exepected size", 12, graph.size());
}

@Test
public void dump() {
final Graph graph = new SparqlGraph("http://localhost:" + serverPort + "/ds/query");
Serializer serializer = Serializer.getInstance();
serializer.serialize(System.out, graph, SupportedFormat.TURTLE);
}

public static int findFreePort() {
int port = 0;
try (ServerSocket server = new ServerSocket(0);) {
port = server.getLocalPort();
} catch (Exception e) {
throw new RuntimeException("unable to find a free port");
}
return port;
}

}
@@ -23,15 +23,10 @@
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.clerezza.commons.rdf.BlankNode;
import org.apache.clerezza.commons.rdf.BlankNodeOrIRI;
import org.apache.clerezza.commons.rdf.Graph;
import org.apache.clerezza.commons.rdf.IRI;
import org.apache.clerezza.commons.rdf.RDFTerm;
import org.apache.clerezza.commons.rdf.Triple;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -0,0 +1,17 @@
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ns1: <http://data.admin.ch/> .
@prefix ns2: <http://schema.org/> .
ns1:apps rdf:type ns2:WebPage ;
ns2:hasPart _:b10511 .
@prefix ns3: <http://schema.zazuko.com/site/> .
ns1:apps ns3:hasIntro _:b10510 ;
ns3:hasMenu _:b10509 .
_:b10509 rdf:type ns3:Menu ;
ns2:articleBody "\n <li><a href=\"http://data.admin.ch/datasets\" title=\"Available Data\">Data</a></li>\n <li><a href=\"http://data.admin.ch/apps\" title=\"Applications\">Applications</a></li>\n <li><a href=\"http://data.admin.ch/sparql\" title=\"SPARQL Endpoint\">SPARQL</a></li>\n <li><a title=\"About the Portal\" href=\"http://data.admin.ch/about\">About the Portal</a></li>\n <li><a title=\"Contact Us\" href=\"http://data.admin.ch/contact\">Contact</a></li>\n" .
_:b10510 rdf:type ns3:Intro ;
ns2:articleBody "\n<p><a href=\"http://data.admin.ch/map/\">Sample application</a> based on STATTAB-SDMX-01-2A01+2011 data. This visualization was made within the prototype phase in colaboration with <a href=\"http://www.ti.bfh.ch/\">Berner Fachhochschule</a>. There are currently no other STATPOP datasets available as RDF.</p>\n" ;
ns3:title "Choropleth" .
_:b10511 rdf:type ns3:Footer ;
ns2:articleBody "<p>Do you have questions about the Linked Data pilot portal? Contact us via our\n<a title=\"github\" href=\"https://github.com/zazuko/fso-lod\">Github page</a>.</p>" .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
_:b10511 ns2:dateCreated "2015-11-15+01:00"^^xsd:date .

This file was deleted.

0 comments on commit d5f31ce

Please sign in to comment.