Search in sources :

Example 41 with RepositoryConnection

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");
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) RepositoryException(org.openrdf.repository.RepositoryException) Test(org.junit.Test)

Example 42 with RepositoryConnection

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();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) HashMap(java.util.HashMap) URI(org.openrdf.model.URI)

Example 43 with RepositoryConnection

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;
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Statement(org.openrdf.model.Statement) Resource(org.openrdf.model.Resource) URI(org.openrdf.model.URI)

Example 44 with RepositoryConnection

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());
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Literal(org.openrdf.model.Literal) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 45 with RepositoryConnection

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);
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Literal(org.openrdf.model.Literal) TupleQuery(org.openrdf.query.TupleQuery) URI(org.openrdf.model.URI)

Aggregations

RepositoryConnection (org.openrdf.repository.RepositoryConnection)71 TupleQuery (org.openrdf.query.TupleQuery)27 URI (org.openrdf.model.URI)24 RepositoryException (org.openrdf.repository.RepositoryException)20 Test (org.junit.Test)15 Statement (org.openrdf.model.Statement)11 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)10 Literal (org.openrdf.model.Literal)9 RdfRepresentation (org.apache.stanbol.entityhub.model.sesame.RdfRepresentation)6 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)6 StatementImpl (org.openrdf.model.impl.StatementImpl)6 Update (org.openrdf.query.Update)6 InputStream (java.io.InputStream)5 Value (org.openrdf.model.Value)5 Repository (org.openrdf.repository.Repository)5 SailRepository (org.openrdf.repository.sail.SailRepository)5 RyaSailRepository (org.apache.rya.rdftriplestore.RyaSailRepository)4 Resource (org.openrdf.model.Resource)4 InputStreamReader (java.io.InputStreamReader)3 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)3