"OPTIONAL { ?x <http://example.org/ns#price> ?price . } " +
"}";
Variable title = new Variable("title");
Variable price = new Variable("price");
SimpleSelectQuery selectQuery = new SimpleSelectQuery();
selectQuery.addSelection(title);
selectQuery.addSelection(price);
Variable x = new Variable("x");
Set<TriplePattern> triplePatterns = new HashSet<TriplePattern>();
triplePatterns.add(new SimpleTriplePattern(x,
new UriRef("http://purl.org/dc/elements/1.1/title"), title));
SimpleBasicGraphPattern bgp = new SimpleBasicGraphPattern(triplePatterns);
Set<TriplePattern> triplePatternsOpt = new HashSet<TriplePattern>();
triplePatternsOpt.add(new SimpleTriplePattern(x,
new UriRef("http://example.org/ns#price"), price));
SimpleBasicGraphPattern bgpOpt =
new SimpleBasicGraphPattern(triplePatternsOpt);
SimpleGroupGraphPattern ggpOpt = new SimpleGroupGraphPattern();
ggpOpt.addGraphPattern(bgpOpt);
SimpleOptionalGraphPattern ogp = new SimpleOptionalGraphPattern(bgp, ggpOpt);
SimpleGroupGraphPattern queryPattern = new SimpleGroupGraphPattern();
queryPattern.addGraphPattern(ogp);
selectQuery.setQueryPattern(queryPattern);
Assert.assertTrue(selectQuery.toString()
.replaceAll("( |\n)+", " ").trim().equals(queryString));
}