From 162189a2076ab58b2f490a8b54ee4d0117f5d9c5 Mon Sep 17 00:00:00 2001 From: Alessia Date: Fri, 9 Aug 2024 15:14:09 +0200 Subject: [PATCH] Added test to clear a graph --- .../GraphDbReaderAndESIndexTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java b/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java index 93ec228..bcc8c25 100644 --- a/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java +++ b/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/GraphDbReaderAndESIndexTest.java @@ -4,16 +4,25 @@ package eu.dnetlib.ariadneplus; import eu.dnetlib.ariadneplus.elasticsearch.BulkUpload; +import eu.dnetlib.ariadneplus.publisher.AriadnePlusPublisherException; import eu.dnetlib.ariadneplus.reader.ResourceManager; import eu.dnetlib.ariadneplus.reader.RunSPARQLQueryService; import eu.dnetlib.ariadneplus.reader.json.ParseRDFJSON; import org.apache.commons.compress.utils.Lists; import org.apache.commons.io.IOUtils; +import org.eclipse.rdf4j.RDF4JException; +import org.eclipse.rdf4j.model.IRI; import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.query.GraphQuery; +import org.eclipse.rdf4j.query.GraphQueryResult; +import org.eclipse.rdf4j.query.QueryLanguage; +import org.eclipse.rdf4j.query.QueryResults; import org.eclipse.rdf4j.repository.Repository; import org.eclipse.rdf4j.repository.RepositoryConnection; import org.eclipse.rdf4j.repository.RepositoryResult; import org.eclipse.rdf4j.repository.manager.RemoteRepositoryManager; +import org.eclipse.rdf4j.repository.util.Repositories; import org.junit.Ignore; import org.junit.Test; import org.springframework.core.io.ClassPathResource; @@ -802,4 +811,23 @@ public class GraphDbReaderAndESIndexTest { repository.shutDown(); manager.shutDown(); } + + @Test + public void clearGraphTest() throws Exception { + RemoteRepositoryManager manager = new RemoteRepositoryManager("http://graphdb-test.ariadne.d4science.org:7200"); + //RemoteRepositoryManager manager = new RemoteRepositoryManager("https://graphdb-test.ariadne.d4science.org"); + manager.init(); + manager.setUsernameAndPassword("XXX", "XXX"); + Repository repository = manager.getRepository("XXX"); + ValueFactory factory = repository.getValueFactory(); + IRI defaultGraph = factory.createIRI("http://www.ontotext.com/", "explicit"); + try (RepositoryConnection connection = repository.getConnection()) { + Repositories.consume(repository, conn -> conn.clear(defaultGraph)); + } + catch (RDF4JException e) { + throw new AriadnePlusPublisherException(e); + } + repository.shutDown(); + manager.shutDown(); + } }