Package org.apache.clerezza.rdf.core

Examples of org.apache.clerezza.rdf.core.MGraph


    Assert.assertEquals(bNode, result.next().getSubject());
  }

  @Test
  public void testContainsIfContained() throws Exception {
    MGraph graph = getEmptyMGraph();
    final Triple triple= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/alice");
    Assert.assertTrue(graph.add(triple));
    Assert.assertTrue(graph.contains(triple));
  }
View Full Code Here


  }


  @Test
  public void testContainsIfEmpty() throws Exception {
    MGraph graph = getEmptyMGraph();
    final Triple triple= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/alice");
    Assert.assertFalse(graph.contains(triple));
  }
View Full Code Here

  }


  @Test
  public void testContainsIfNotContained() throws Exception {
    MGraph graph = getEmptyMGraph();
    final Triple tripleAdd= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/alice");
    final Triple tripleTest= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/bob");
    Assert.assertTrue(graph.add(tripleAdd));
    Assert.assertFalse(graph.contains(tripleTest));
  }
View Full Code Here

  }


  @Test
  public void testFilterEmptyGraph() throws Exception {
    MGraph graph = getEmptyMGraph();
    Iterator<Triple> i = graph.filter(null, null, null);
    Assert.assertFalse(i.hasNext());
  }
View Full Code Here

  }


  @Test
  public void testFilterSingleEntry() throws Exception {
    MGraph graph = getEmptyMGraph();
    final Triple triple= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/alice");
    Assert.assertTrue(graph.add(triple));

    Iterator<Triple> i = graph.filter(null, null, null);
    Collection<Triple> resultSet= toCollection(i);
    Assert.assertEquals(1, resultSet.size());
    Assert.assertTrue(resultSet.contains(triple));
  }
View Full Code Here

  }


  @Test
  public void testFilterByObject() throws Exception {
    MGraph graph = getEmptyMGraph();
    final Triple tripleAlice= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/alice");
    final Triple tripleBob= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/bob");
    Assert.assertTrue(graph.add(tripleAlice));
    Assert.assertTrue(graph.add(tripleBob));

    Iterator<Triple> iterator;
    Collection<Triple> resultSet;

    // Find bob
    iterator = graph.filter(null, null,
        new UriRef("http://example.org/people/bob"));
    resultSet= toCollection(iterator);
    Assert.assertEquals(1, resultSet.size());
    Assert.assertTrue(resultSet.contains(tripleBob));

    // Find alice
    iterator = graph.filter(null, null,
        new UriRef("http://example.org/people/alice"));
    resultSet= toCollection(iterator);
    Assert.assertEquals(1, resultSet.size());
    Assert.assertTrue(resultSet.contains(tripleAlice));

    // Find both
    iterator = graph.filter(null, null, null);
    resultSet= toCollection(iterator);
    Assert.assertEquals(2, resultSet.size());
    Assert.assertTrue(resultSet.contains(tripleAlice));
    Assert.assertTrue(resultSet.contains(tripleBob));
  }
View Full Code Here

    Assert.assertTrue(resultSet.contains(tripleBob));
  }

  @Test
  public void graphEventTestAddRemove() {
    MGraph mGraph = getEmptyMGraph();
    TestGraphListener listener = new TestGraphListener();
    mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
    mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
    mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));   
    mGraph.add(trpl1);
    Assert.assertNull(listener.getEvents());   
    mGraph.add(trpl2);
    Assert.assertEquals(1, listener.getEvents().size());
    Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
    Assert.assertTrue(listener.getEvents().get(0) instanceof  AddEvent);
    listener.resetEvents();
    mGraph.remove(trpl2);
    Assert.assertEquals(1, listener.getEvents().size());
    Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
    Assert.assertTrue(listener.getEvents().get(0) instanceof RemoveEvent);
    listener.resetEvents();   
    mGraph.add(trpl3);
    Assert.assertEquals(1, listener.getEvents().size());
    Assert.assertEquals(trpl3, listener.getEvents().get(0).getTriple());
    Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
    listener.resetEvents();   
    mGraph.remove(trpl4);
    Assert.assertNull(listener.getEvents());
  }
View Full Code Here

    Assert.assertNull(listener.getEvents());
  }
 
  @Test
  public void graphEventTestAddAllRemoveAll() {
    MGraph mGraph = getEmptyMGraph();
    TestGraphListener listener = new TestGraphListener();
    mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
    mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
    mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
    MGraph triples = new SimpleMGraph();
    triples.add(trpl1);
    triples.add(trpl2);
    triples.add(trpl3);
    triples.add(trpl4);
    mGraph.addAll(triples);
    List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
    Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
    Assert.assertEquals(3, cumulatedEvents.size());
    Assert.assertTrue(cumulatedEvents.get(0) instanceof AddEvent);
View Full Code Here

    Assert.assertTrue(cumulatedTriples.contains(trpl4));
  }

  @Test
  public void graphEventTestFilterRemove() {
    MGraph mGraph = getEmptyMGraph();
    TestGraphListener listener = new TestGraphListener();
    mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
    mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
    mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
    mGraph.add(trpl1);
    mGraph.add(trpl2);
    mGraph.add(trpl3);
    mGraph.add(trpl4);
    listener.resetCumulatedEvents();
    Iterator<Triple> result = mGraph.filter(null, uriRef2, null);
    while (result.hasNext()) {
      result.next();
      result.remove();
    }
    List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
View Full Code Here

    Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
  }

  @Test
  public void graphEventTestIteratorRemove() {
    MGraph mGraph = getEmptyMGraph();
    TestGraphListener listener = new TestGraphListener();
    mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
    mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
    mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
    mGraph.add(trpl1);
    mGraph.add(trpl2);
    mGraph.add(trpl3);
    mGraph.add(trpl4);
    listener.resetCumulatedEvents();
    Iterator<Triple> result = mGraph.iterator();
    while (result.hasNext()) {
      result.next();
      result.remove();
    }
    List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.MGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.