use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameBoundVariablesTest method checkGetAsStringCanConvertAllTypesToTheirStringForm.
@Test
public void checkGetAsStringCanConvertAllTypesToTheirStringForm() {
String turtle = "@prefix ex: <http://example.com/ontology#> . " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + "<http://example.com/1> ex:is _:foo . " + "<http://example.com/2> ex:is \"true\"^^xsd:boolean . " + "<http://example.com/3> ex:is \"3\"^^xsd:integer . " + "<http://example.com/4> ex:is \"ho hum\"^^xsd:string . " + "<http://example.com/5> ex:is <http://yadda/> . ";
graph.addTriplesFromTurtle(turtle);
String sparqlSelect = "PREFIX ex: <http://example.com/ontology#> " + "SELECT ?blankNode ?boolean ?int ?string ?uri ?unbound WHERE { " + "<http://example.com/1> ex:is ?blankNode . " + "<http://example.com/2> ex:is ?boolean . " + "<http://example.com/3> ex:is ?int . " + "<http://example.com/4> ex:is ?string . " + "<http://example.com/5> ex:is ?uri . " + "OPTIONAL { <http://example.com/6> ex:is ?unbound }" + "}";
BoundVariables bv = graph.selectFirst(sparqlSelect);
assertNotNull(bv.getAsString("blankNode"));
assertEquals("true", bv.getAsString("boolean"));
assertEquals("3", bv.getAsString("int"));
assertEquals("ho hum", bv.getAsString("string"));
assertEquals("http://yadda/", bv.getAsString("uri"));
assertNull(bv.getAsString("unbound"));
try {
bv.getAsString("baz");
fail("Illegal argument exception expected.");
} catch (IllegalArgumentException e) {
assertEquals("boundName 'baz' is not in the list of possible values ('blankNode', 'boolean', 'int', 'string', 'uri', 'unbound')", e.getMessage());
}
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameBoundVariablesTest method checkGetURIReference.
@Test
public void checkGetURIReference() {
String turtle = "@prefix ex: <http://example.com/ontology#> . " + "<http://example.com/1> ex:is <http://hello> . ";
graph.addTriplesFromTurtle(turtle);
String sparqlSelect = "PREFIX ex: <http://example.com/ontology#> " + "SELECT ?one ?two WHERE { " + "<http://example.com/1> ex:is ?one . " + "OPTIONAL { [] ex:nope ?two } " + "}";
BoundVariables bv = graph.selectFirst(sparqlSelect);
assertEquals("http://hello", bv.getURIReference("one").getURIText());
assertNull(bv.getURIReference("two"));
try {
bv.getURIReference("baz");
fail("Illegal argument exception expected.");
} catch (IllegalArgumentException e) {
assertEquals("boundName 'baz' is not in the list of possible values ('one', 'two')", e.getMessage());
}
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameBoundVariablesTest method checkGetString.
@Test
public void checkGetString() {
String turtle = "@prefix ex: <http://example.com/ontology#> . " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + "<http://example.com/1> ex:is \"won\"^^xsd:string . " + "<http://example.com/2> ex:is \"too\"^^xsd:string . ";
graph.addTriplesFromTurtle(turtle);
String sparqlSelect = "PREFIX ex: <http://example.com/ontology#> " + "SELECT ?one ?two ?three WHERE { " + "<http://example.com/1> ex:is ?one . " + "<http://example.com/2> ex:is ?two . " + "OPTIONAL { <http://example.com/3> ex:is ?three } " + "}";
BoundVariables bv = graph.selectFirst(sparqlSelect);
assertEquals("won", bv.getString("one"));
assertEquals("too", bv.getString("two"));
assertNull(bv.getString("three"));
try {
bv.getString("baz");
fail("Illegal argument exception expected.");
} catch (IllegalArgumentException e) {
assertEquals("boundName 'baz' is not in the list of possible values ('one', 'two', 'three')", e.getMessage());
}
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameBoundVariablesTest method checkGetInt.
@Test
public void checkGetInt() {
String turtle = "@prefix ex: <http://example.com/ontology#> . " + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + "<http://example.com/1> ex:is \"1\"^^xsd:integer . " + "<http://example.com/2> ex:is \"2\"^^xsd:integer . ";
graph.addTriplesFromTurtle(turtle);
String sparqlSelect = "PREFIX ex: <http://example.com/ontology#> " + "SELECT ?one ?two ?three WHERE { " + "<http://example.com/1> ex:is ?one . " + "<http://example.com/2> ex:is ?two . " + "OPTIONAL { <http://example.com/3> ex:is ?three } " + "}";
BoundVariables bv = graph.selectFirst(sparqlSelect);
assertEquals((Integer) 1, bv.getInt("one"));
assertEquals((Integer) 2, bv.getInt("two"));
assertNull(bv.getInt("three"));
try {
bv.getInt("baz");
fail("Illegal argument exception expected.");
} catch (IllegalArgumentException e) {
assertEquals("boundName 'baz' is not in the list of possible values ('one', 'two', 'three')", e.getMessage());
}
}
use of com.thoughtworks.studios.shine.semweb.BoundVariables in project gocd by gocd.
the class SesameBoundVariablesTest method shouldBeSerializable.
@Test
public void shouldBeSerializable() throws Exception {
String turtle = "<http://s1> <http://p1> <http://o1> . ";
graph.addTriplesFromTurtle(turtle);
String sparqlSelect = "SELECT ?s ?p ?o { ?s ?p ?o . }";
List<BoundVariables> bvs = graph.select(sparqlSelect);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ObjectOutputStream objectOS = new ObjectOutputStream(os);
objectOS.writeObject(bvs);
ObjectInputStream objectIS = new ObjectInputStream(new ByteArrayInputStream(os.toByteArray()));
List<BoundVariables> bvsFromInputStream = (List<BoundVariables>) objectIS.readObject();
assertEquals(1, bvsFromInputStream.size());
assertEquals("http://s1", bvsFromInputStream.get(0).getAsString("s"));
assertEquals("http://p1", bvsFromInputStream.get(0).getAsString("p"));
assertEquals("http://o1", bvsFromInputStream.get(0).getAsString("o"));
}
Aggregations