예제 #1
0
  @Test
  public void testRemoveAndClear() throws Exception {
    // Add some data to the repository
    con.begin();
    con.addStatement(painter, RDF.TYPE, RDFS.CLASS);
    con.addStatement(painting, RDF.TYPE, RDFS.CLASS);
    con.addStatement(picasso, RDF.TYPE, painter, context1);
    con.addStatement(guernica, RDF.TYPE, painting, context1);
    con.addStatement(picasso, paints, guernica, context1);
    con.commit();

    // Test removal of statements
    con.begin();
    con.removeStatements(painting, RDF.TYPE, RDFS.CLASS);
    con.commit();

    assertEquals("Repository should contain 4 statements in total", 4, countAllElements());

    assertEquals("Named context should contain 3 statements", 3, countContext1Elements());

    assertEquals(
        "Statement (Painting, type, Class) should no longer be in the repository",
        0,
        countQueryResults("select 1 from {ex:Painting} rdf:type {rdfs:Class}"));

    con.begin();
    con.removeStatements(null, null, null, context1);
    con.commit();

    assertEquals("Repository should contain 1 statement in total", 1, countAllElements());

    assertEquals("Named context should be empty", 0, countContext1Elements());

    con.begin();
    con.clear();
    con.commit();

    assertEquals("Repository should no longer contain any statements", 0, countAllElements());
  }
예제 #2
0
  @Test
  public void testTimeZoneRoundTrip() throws Exception {
    URI subj = new URIImpl(EXAMPLE_NS + PICASSO);
    URI pred = new URIImpl(EXAMPLE_NS + PAINTS);
    Literal obj = new LiteralImpl("2006-08-23+00:00", XMLSchema.DATE);
    testValueRoundTrip(subj, pred, obj);

    con.begin();
    con.removeStatements(null, null, null);
    con.commit();

    obj = new LiteralImpl("2006-08-23", XMLSchema.DATE);
    testValueRoundTrip(subj, pred, obj);
  }
예제 #3
0
 @Test
 public void testBNodeReuse() throws Exception {
   con.begin();
   con.addStatement(RDF.VALUE, RDF.VALUE, RDF.VALUE);
   assertEquals(1, con.size());
   BNode b1 = vf.createBNode();
   con.addStatement(b1, RDF.VALUE, b1);
   con.removeStatements(b1, RDF.VALUE, b1);
   assertEquals(1, con.size());
   BNode b2 = vf.createBNode();
   con.addStatement(b2, RDF.VALUE, b2);
   con.addStatement(b1, RDF.VALUE, b1);
   assertEquals(3, con.size());
   con.commit();
 }
예제 #4
0
  @Test
  public void testGetContextIDs() throws Exception {
    assertEquals(0, countElements(con.getContextIDs()));

    // load data
    con.begin();
    con.addStatement(picasso, paints, guernica, context1);
    assertEquals(1, countElements(con.getContextIDs()));
    assertEquals(context1, first(con.getContextIDs()));

    con.removeStatements(picasso, paints, guernica, context1);
    assertEquals(0, countElements(con.getContextIDs()));
    con.commit();

    assertEquals(0, countElements(con.getContextIDs()));

    con.begin();
    con.addStatement(picasso, paints, guernica, context2);
    assertEquals(1, countElements(con.getContextIDs()));
    assertEquals(context2, first(con.getContextIDs()));
    con.commit();
  }
예제 #5
0
  @Test
  public void testContexts() throws Exception {
    con.begin();
    // Add schema data to the repository, no context
    con.addStatement(painter, RDF.TYPE, RDFS.CLASS);
    con.addStatement(painting, RDF.TYPE, RDFS.CLASS);

    // Add stuff about picasso to context1
    con.addStatement(picasso, RDF.TYPE, painter, context1);
    con.addStatement(guernica, RDF.TYPE, painting, context1);
    con.addStatement(picasso, paints, guernica, context1);

    // Add stuff about rembrandt to context2
    con.addStatement(rembrandt, RDF.TYPE, painter, context2);
    con.addStatement(nightwatch, RDF.TYPE, painting, context2);
    con.addStatement(rembrandt, paints, nightwatch, context2);

    con.commit();

    assertEquals("context1 should contain 3 statements", 3, countContext1Elements());
    assertEquals(
        "context2 should contain 3 statements",
        3,
        countElements(con.getStatements(null, null, null, false, context2)));
    assertEquals("Repository should contain 8 statements", 8, countAllElements());
    assertEquals(
        "statements without context should equal 2",
        2,
        countElements(con.getStatements(null, null, null, false, (Resource) null)));

    assertEquals(
        "Statements without context and statements in context 1 together should total 5",
        5,
        countElements(con.getStatements(null, null, null, false, null, context1)));

    assertEquals(
        "Statements without context and statements in context 2 together should total 5",
        5,
        countElements(con.getStatements(null, null, null, false, null, context2)));

    assertEquals(
        "Statements in context 1 and in context 2 together should total 6",
        6,
        countElements(con.getStatements(null, null, null, false, context1, context2)));

    // remove two statements from context1.
    con.begin();
    con.removeStatements(picasso, null, null, context1);
    con.commit();

    assertEquals("context1 should contain 1 statements", 1, countContext1Elements());

    assertEquals("Repository should contain 6 statements", 6, countAllElements());

    assertEquals(
        "Statements without context and statements in context 1 together should total 3",
        3,
        countElements(con.getStatements(null, null, null, false, null, context1)));

    assertEquals(
        "Statements without context and statements in context 2 together should total 5",
        5,
        countElements(con.getStatements(null, null, null, false, context2, null)));

    assertEquals(
        "Statements in context 1 and in context 2 together should total 4",
        4,
        countElements(con.getStatements(null, null, null, false, context1, context2)));
  }