@Test
  public void testEmptyBinding() throws Exception {

    when(mockQueryResult.getColumnNames()).thenReturn(new String[] {});
    final Binding binding = testObj.nextBinding();
    assertTrue(binding.isEmpty());
  }
 private static boolean isNotNeeded(List<Binding> bindingList) {
   for (Binding binding : bindingList) {
     if (!binding.isEmpty()) {
       return false;
     }
   }
   return true;
 }
  @Test
  public void testNextBinding() throws Exception {
    when(mockValue.getString()).thenReturn("x");
    final Binding binding = testObj.nextBinding();

    assertTrue(binding.contains(Var.alloc("a")));
    final Node a = binding.get(Var.alloc("a"));
    assertEquals("x", a.getLiteralLexicalForm());
  }
  @Test
  public void testBindingVars() throws Exception {
    final Binding binding = testObj.nextBinding();
    final List<String> vars =
        ImmutableList.copyOf(
            Iterators.transform(
                binding.vars(),
                new Function<Var, String>() {
                  @Override
                  public String apply(final Var var) {
                    return var.getVarName();
                  }
                }));

    assertArrayEquals(columnNames, vars.toArray());
    assertFalse(binding.isEmpty());
  }
 @Override
 public Iterator<String> varNames() {
   List<String> x = new ArrayList<String>();
   for (Iterator<Var> iter = binding.vars(); iter.hasNext(); ) {
     Var v = iter.next();
     x.add(v.getVarName());
   }
   return x.iterator();
 }
Beispiel #6
0
  private ResultSetRewindable convertToStrings(ResultSetRewindable resultsActual) {
    List<Binding> bindings = new ArrayList<Binding>();
    while (resultsActual.hasNext()) {
      Binding b = resultsActual.nextBinding();
      BindingMap b2 = BindingFactory.create();

      for (String vn : resultsActual.getResultVars()) {
        Var v = Var.alloc(vn);
        Node n = b.get(v);
        String s;
        if (n == null) s = "";
        else if (n.isBlank()) s = "_:" + n.getBlankNodeLabel();
        else s = NodeFunctions.str(n);
        b2.add(v, NodeFactory.createLiteral(s));
      }
      bindings.add(b2);
    }
    ResultSet rs =
        new ResultSetStream(
            resultsActual.getResultVars(), null, new QueryIterPlainWrapper(bindings.iterator()));
    return ResultSetFactory.makeRewindable(rs);
  }
 @Test
 public void testBindingEmpty() throws Exception {
   final Binding binding = testObj.nextBinding();
   assertFalse(binding.isEmpty());
 }
 @Test
 public void testBindingSize() throws Exception {
   final Binding binding = testObj.nextBinding();
   assertEquals(2, binding.size());
 }
 private static boolean isNotNeeded(Binding b) {
   return b.isEmpty();
 }
 @Override
 public String toString() {
   if (binding == null) return "<no binding>";
   return binding.toString();
 }
 @Override
 protected boolean _contains(String varName) {
   return binding.contains(Var.alloc(varName));
 }
 @Override
 protected RDFNode _get(String varName) {
   Node n = binding.get(Var.alloc(varName));
   if (n == null) return null;
   return ModelUtils.convertGraphNodeToRDFNode(n, model);
 }