Search in sources :

Example 1 with TestFile

use of org.apache.rya.helper.TestFile in project incubator-rya by apache.

the class AccumuloRyaSailFactoryLoadFilesIT method testFileLoading.

@Test
public void testFileLoading() throws Exception {
    log.info("Starting file loading test...");
    final String query = "SELECT * WHERE { ?s ?p ?o . FILTER(?p != <" + RdfCloudTripleStoreConstants.RTS_VERSION_PREDICATE + ">) }";
    final String deleteQuery = "DELETE WHERE { ?s ?p ?o . }";
    for (final TestFile testFile : TestFileUtils.TEST_FILES) {
        final String testFilePath = testFile.getPath();
        final RDFFormat rdfFormat = RdfFormatUtils.forFileName(testFilePath, null);
        log.info("Loading file \"" + testFilePath + "\" with RDFFormat: " + rdfFormat.getName());
        try (final InputStream rdfContent = getClass().getResourceAsStream(testFilePath)) {
            addTriples(ryaRepository, rdfContent, rdfFormat);
        }
        SailRepositoryConnection queryConn = null;
        try {
            log.info("Querying for triples in the repository from the " + rdfFormat.getName() + " file.");
            queryConn = ryaRepository.getConnection();
            final int count = performTupleQuery(query, queryConn);
            assertEquals("Expected number of triples not found in: " + testFilePath, testFile.getExpectedCount(), count);
        } finally {
            closeQuietly(queryConn);
        }
        SailRepositoryConnection deleteConn = null;
        try {
            log.info("Deleting triples in the repository from the " + rdfFormat.getName() + " file.");
            deleteConn = ryaRepository.getConnection();
            final Update update = deleteConn.prepareUpdate(QueryLanguage.SPARQL, deleteQuery);
            update.execute();
        } finally {
            closeQuietly(deleteConn);
        }
    }
    log.info("File loading test finished.");
}
Also used : InputStream(java.io.InputStream) TestFile(org.apache.rya.helper.TestFile) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) Update(org.eclipse.rdf4j.query.Update) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) Test(org.junit.Test)

Example 2 with TestFile

use of org.apache.rya.helper.TestFile in project incubator-rya by apache.

the class MongoDbRyaSailFactoryLoadFilesIT method testFileLoading.

@Test
public void testFileLoading() throws Exception {
    log.info("Starting file loading test...");
    final String query = "SELECT * WHERE { ?s ?p ?o . }";
    final String deleteQuery = "DELETE WHERE { ?s ?p ?o . }";
    for (final TestFile testFile : TestFileUtils.TEST_FILES) {
        final String testFilePath = testFile.getPath();
        final RDFFormat rdfFormat = RdfFormatUtils.forFileName(testFilePath, null);
        log.info("Loading file \"" + testFilePath + "\" with RDFFormat: " + rdfFormat.getName());
        try (final InputStream rdfContent = getClass().getResourceAsStream(testFilePath)) {
            addTriples(ryaRepository, rdfContent, rdfFormat);
        }
        SailRepositoryConnection queryConn = null;
        try {
            log.info("Querying for triples in the repository from the " + rdfFormat.getName() + " file.");
            queryConn = ryaRepository.getConnection();
            final int count = performTupleQuery(query, queryConn);
            assertEquals("Expected number of triples not found in: " + testFilePath, testFile.getExpectedCount(), count);
        } finally {
            closeQuietly(queryConn);
        }
        SailRepositoryConnection deleteConn = null;
        try {
            log.info("Deleting triples in the repository from the " + rdfFormat.getName() + " file.");
            deleteConn = ryaRepository.getConnection();
            final Update update = deleteConn.prepareUpdate(QueryLanguage.SPARQL, deleteQuery);
            update.execute();
        } finally {
            closeQuietly(deleteConn);
        }
    }
    log.info("File loading test finished.");
}
Also used : InputStream(java.io.InputStream) TestFile(org.apache.rya.helper.TestFile) SailRepositoryConnection(org.eclipse.rdf4j.repository.sail.SailRepositoryConnection) Update(org.eclipse.rdf4j.query.Update) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) Test(org.junit.Test)

Aggregations

InputStream (java.io.InputStream)2 TestFile (org.apache.rya.helper.TestFile)2 Update (org.eclipse.rdf4j.query.Update)2 SailRepositoryConnection (org.eclipse.rdf4j.repository.sail.SailRepositoryConnection)2 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)2 Test (org.junit.Test)2