use of org.openrdf.repository.RepositoryConnection in project gocd by gocd.
the class SesameGraphTest method checkWhenAddStatementWithStringObjectExplodesItThrowsAShineRuntimeException.
@Test(expected = ShineRuntimeException.class)
public void checkWhenAddStatementWithStringObjectExplodesItThrowsAShineRuntimeException() throws RepositoryException {
RDFProperty property = new RDFProperty("http://www.example.com/ontology#foo");
RepositoryConnection badConnection = mock(RepositoryConnection.class);
doThrow(new RepositoryException("")).when(badConnection).add((org.openrdf.model.Resource) any(), (org.openrdf.model.URI) any(), (org.openrdf.model.Literal) any());
org.openrdf.model.ValueFactory stubValueFactory = mock(org.openrdf.model.ValueFactory.class);
when(badConnection.getValueFactory()).thenReturn(stubValueFactory);
SesameURIReference stubSubject = mock(SesameURIReference.class);
when(stubSubject.getSesameNativeResource()).thenReturn(null);
URIReference stubPredicate = mock(URIReference.class);
when(stubPredicate.getURIText()).thenReturn("");
SesameGraph badGraph = new SesameGraph(badConnection, null);
badGraph.addStatement(stubSubject, property, "foo");
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class CbSailTest method testSimpleQueryAuth.
public void testSimpleQueryAuth() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI cpu = vf.createURI(litdupsNS, "cpu");
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
URI uri1 = vf.createURI(litdupsNS, "uri1");
URI uri2 = vf.createURI(litdupsNS, "uri2");
URI auth1 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "auth1");
conn.add(cpu, loadPerc, uri1, auth1);
conn.add(cpu, loadPerc, uri2);
conn.commit();
conn.close();
resultEndpoint.expectedMessageCount(1);
// query through camel
String query = "select * where {" + "<" + cpu.toString() + "> ?p ?o1." + "}";
template.sendBodyAndHeader(null, CbSailComponent.SPARQL_QUERY_PROP, query);
assertMockEndpointsSatisfied();
resultEndpoint.expectedMessageCount(2);
query = "select * where {" + "<" + cpu.toString() + "> ?p ?o1." + "}";
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(CbSailComponent.SPARQL_QUERY_PROP, query);
headers.put(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, "auth1");
template.sendBodyAndHeaders(null, headers);
assertMockEndpointsSatisfied();
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class GetStatementsRyaCommand method doRyaExecute.
@Override
protected Object doRyaExecute() throws Exception {
if (subject == null && predicate == null && object == null && context == null) {
System.out.println("Please specify subject|predicate|object|context");
return null;
}
System.out.println(subject);
System.out.println(predicate);
System.out.println(object);
System.out.println(context);
RepositoryConnection connection = null;
try {
connection = repository.getConnection();
RepositoryResult<Statement> statements = connection.getStatements((subject != null) ? (Resource) createValue(subject) : null, (predicate != null) ? (URI) createValue(predicate) : null, (object != null) ? createValue(object) : null, false, (context != null) ? new Resource[] { (Resource) createValue(context) } : new Resource[0]);
while (statements.hasNext()) {
System.out.println(statements.next());
}
statements.close();
} finally {
if (connection != null) {
connection.close();
}
}
return null;
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfControllerTest method updateQuery.
@Test
public void updateQuery() throws Exception {
this.mockMvc.perform(get("/queryrdf").param("query", "INSERT \n DATA\n {\n <http://mynamespace/ProductType1> <http://mynamespace#pred1> \"test\" }")).andExpect(status().isOk());
ValueFactory vf = repository.getValueFactory();
RepositoryConnection con = repository.getConnection();
URI s = vf.createURI("http://mynamespace/ProductType1");
URI p = vf.createURI("http://mynamespace#pred1");
Literal o = vf.createLiteral("test");
assertTrue(con.getStatements(s, p, o, false).hasNext());
}
use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testSPOSubjRange.
public void testSPOSubjRange() throws Exception {
RepositoryConnection conn = repository.getConnection();
URI cpu2 = vf.createURI(litdupsNS, "cpu2");
URI cpu3 = vf.createURI(litdupsNS, "cpu3");
URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
Literal six = vf.createLiteral("6");
Literal sev = vf.createLiteral("7");
Literal ten = vf.createLiteral("10");
conn.add(cpu, loadPerc, six);
conn.add(cpu2, loadPerc, sev);
conn.add(cpu3, loadPerc, ten);
conn.commit();
String query = "PREFIX org.apache: <" + NAMESPACE + ">\n" + "select * where {" + "?s ?p ?o.\n" + "FILTER(org.apache:range(?s, <" + cpu.stringValue() + ">, <" + cpu2.stringValue() + ">))." + "}";
TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
CountTupleHandler cth = new CountTupleHandler();
tupleQuery.evaluate(cth);
conn.close();
assertEquals(cth.getCount(), 2);
}
Aggregations