Esempio n. 1
0
  @Test
  public void testEmptyRepository() throws Exception {
    // repository should be empty
    assertEquals("Empty repository should not return any statements", 0, countAllElements());

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

    assertEquals(
        "Empty repository should not return any context identifiers",
        0,
        countElements(con.getContextIDs()));

    assertEquals(
        "Empty repository should not return any query results",
        0,
        countQueryResults("select * from {S} P {O}"));
  }
Esempio n. 2
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();
  }
Esempio n. 3
0
  @Test
  public void testAddData() 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();

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

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

    assertEquals(
        "Repository should have 1 context identifier", 1, countElements(con.getContextIDs()));

    assertEquals(
        "Repository should contain 5 statements in total",
        5,
        countQueryResults("select * from {S} P {O}"));

    // Check for presence of the added statements
    assertEquals(
        "Statement (Painter, type, Class) should be in the repository",
        1,
        countQueryResults("select 1 from {ex:Painter} rdf:type {rdfs:Class}"));

    assertEquals(
        "Statement (picasso, type, Painter) should be in the repository",
        1,
        countQueryResults("select 1 from {ex:picasso} rdf:type {ex:Painter}"));

    // Check for absense of non-added statements
    assertEquals(
        "Statement (Painter, paints, Painting) should not be in the repository",
        0,
        countQueryResults("select 1 from {ex:Painter} ex:paints {ex:Painting}"));

    assertEquals(
        "Statement (picasso, creates, guernica) should not be in the repository",
        0,
        countQueryResults("select 1 from {ex:picasso} ex:creates {ex:guernica}"));

    // Various other checks
    assertEquals(
        "Repository should contain 2 statements matching (picasso, _, _)",
        2,
        countQueryResults("select * from {ex:picasso} P {O}"));

    assertEquals(
        "Repository should contain 1 statement matching (picasso, paints, _)",
        1,
        countQueryResults("select * from {ex:picasso} ex:paints {O}"));

    assertEquals(
        "Repository should contain 4 statements matching (_, type, _)",
        4,
        countQueryResults("select * from {S} rdf:type {O}"));

    assertEquals(
        "Repository should contain 2 statements matching (_, _, Class)",
        2,
        countQueryResults("select * from {S} P {rdfs:Class}"));

    assertEquals(
        "Repository should contain 0 statements matching (_, _, type)",
        0,
        countQueryResults("select * from {S} P {rdf:type}"));
  }