// base data
InputStream baseData = this.getClass().getResourceAsStream("version-base.rdf");
assumeThat("Could not load test-data: version-base.rdf", baseData, notNullValue(InputStream.class));
RepositoryConnection connectionBase = repository.getConnection();
try {
connectionBase.add(baseData, "http://marmotta.apache.org/testing/ns1/", RDFFormat.RDFXML);
connectionBase.commit();
} finally {
connectionBase.close();
}
Thread.sleep(1000);
Date date2 = new Date();
Thread.sleep(1000);
// update 1
InputStream update1Data = this.getClass().getResourceAsStream("version-update1.rdf");
assumeThat("Could not load test-data: version-update1.rdf", update1Data, notNullValue(InputStream.class));
RepositoryConnection connectionUpdate1 = repository.getConnection();
try {
connectionUpdate1.add(update1Data, "http://marmotta.apache.org/testing/ns1/", RDFFormat.RDFXML);
connectionUpdate1.commit();
} finally {
connectionUpdate1.close();
}
Thread.sleep(1000);
Date date3 = new Date();
Thread.sleep(1000);
// update 2
InputStream update2Data = this.getClass().getResourceAsStream("version-update2.rdf");
assumeThat("Could not load test-data: version-update2.rdf", update2Data, notNullValue(InputStream.class));
RepositoryConnection connectionUpdate2 = repository.getConnection();
try {
connectionUpdate2.add(update2Data, "http://marmotta.apache.org/testing/ns1/", RDFFormat.RDFXML);
connectionUpdate2.commit();
} finally {
connectionUpdate2.close();
}
// test snapshot connection for date2 (i.e. after base import and before updates)
RepositoryConnection snapshot1 = repository.getSnapshot(date2);
// query all triples for http://marmotta.apache.org/testing/ns1/R1, should be exactly 3
List<Statement> s1_r1_triples = asList(snapshot1.getStatements(repository.getValueFactory().createURI("http://marmotta.apache.org/testing/ns1/R1"), null, null, true));
Assert.assertEquals(3, s1_r1_triples.size());
// query all triples for http://marmotta.apache.org/testing/ns1/R2, should be zero
List<Statement> s1_r2_triples = asList(snapshot1.getStatements(repository.getValueFactory().createURI("http://marmotta.apache.org/testing/ns1/R2"), null, null, true));
Assert.assertEquals(0, s1_r2_triples.size());
snapshot1.commit();
snapshot1.close();
// test snapshot connection for date3 (i.e. after first update)
RepositoryConnection snapshot2 = repository.getSnapshot(date3);
// query all triples for http://marmotta.apache.org/testing/ns1/R1, should be exactly 4
List<Statement> s2_r1_triples = asList(snapshot2.getStatements(repository.getValueFactory().createURI("http://marmotta.apache.org/testing/ns1/R1"), null, null, true));
Assert.assertEquals(3, s2_r1_triples.size());
// query all triples for http://marmotta.apache.org/testing/ns1/R2, should be 3
List<Statement> s2_r2_triples = asList(snapshot2.getStatements(repository.getValueFactory().createURI("http://marmotta.apache.org/testing/ns1/R2"), null, null, true));
Assert.assertEquals(3, s2_r2_triples.size());
snapshot2.commit();
snapshot2.close();
// test snapshot connection for now (i.e. after both updates)
RepositoryConnection snapshot3 = repository.getSnapshot(new Date());
// query all triples for http://marmotta.apache.org/testing/ns1/R1, should be exactly 4
List<Statement> s3_r1_triples = asList(snapshot3.getStatements(repository.getValueFactory().createURI("http://marmotta.apache.org/testing/ns1/R1"), null, null, true));
Assert.assertEquals(4, s3_r1_triples.size());
// query all triples for http://marmotta.apache.org/testing/ns1/R2, should be 3
List<Statement> s3_r2_triples = asList(snapshot3.getStatements(repository.getValueFactory().createURI("http://marmotta.apache.org/testing/ns1/R2"), null, null, true));
Assert.assertEquals(3, s3_r2_triples.size());
snapshot3.commit();
snapshot3.close();
}