use of org.openrdf.repository.RepositoryException in project gocd by gocd.
the class SesameGraphTest method checkWhenAddStatementWithIntObjectExplodesItThrowsAShineRuntimeException.
@Test(expected = ShineRuntimeException.class)
public void checkWhenAddStatementWithIntObjectExplodesItThrowsAShineRuntimeException() throws RepositoryException {
RDFProperty property = new RDFProperty("http://www.example.com/ontology#foo");
RepositoryConnection badConnection = mock(RepositoryConnection.class);
doThrow(new RepositoryException("")).when(badConnection).add((org.openrdf.model.Resource) any(), (org.openrdf.model.URI) any(), (org.openrdf.model.Literal) any());
org.openrdf.model.ValueFactory stubValueFactory = mock(org.openrdf.model.ValueFactory.class);
when(badConnection.getValueFactory()).thenReturn(stubValueFactory);
SesameURIReference stubSubject = mock(SesameURIReference.class);
when(stubSubject.getSesameNativeResource()).thenReturn(null);
URIReference stubPredicate = mock(URIReference.class);
when(stubPredicate.getURIText()).thenReturn("");
SesameGraph badGraph = new SesameGraph(badConnection, null);
badGraph.addStatement(stubSubject, property, 3);
}
use of org.openrdf.repository.RepositoryException in project gocd by gocd.
the class SesameGraphTest method checkWhenAddTriplesFromGraphExplodesItThrowsShineRuntimeException.
@Test(expected = ShineRuntimeException.class)
public void checkWhenAddTriplesFromGraphExplodesItThrowsShineRuntimeException() throws RepositoryException {
RepositoryConnection badConnection = mock(RepositoryConnection.class);
doThrow(new RepositoryException("")).when(badConnection).getStatements((org.openrdf.model.Resource) any(), (org.openrdf.model.URI) any(), (org.openrdf.model.Value) any(), anyBoolean());
SesameGraph otherGraph = new SesameGraph(badConnection, null);
SesameGraph badGraph = new SesameGraph(badConnection, null);
badGraph.addTriplesFromGraph(otherGraph);
}
use of org.openrdf.repository.RepositoryException in project stanbol by apache.
the class RdfIndexingSource method loadRepositoryConfig.
/**
* @param repoConfigFile
* @return
*/
private RepositoryConfig loadRepositoryConfig(File repoConfigFile) {
Repository configRepo = new SailRepository(new MemoryStore());
RepositoryConnection con = null;
try {
configRepo.initialize();
con = configRepo.getConnection();
//We need to load the configuration into a context
org.openrdf.model.URI configContext = con.getValueFactory().createURI("urn:stanbol.entityhub:indexing.source.sesame:config.context");
RDFFormat format = Rio.getParserFormatForFileName(repoConfigFile.getName());
try {
con.add(new InputStreamReader(new FileInputStream(repoConfigFile), Charset.forName("UTF-8")), baseUri, format, configContext);
} catch (RDFParseException e) {
throw new IllegalArgumentException("Unable to parsed '" + repoConfigFile + "' using RDF format '" + format + "'!", e);
} catch (IOException e) {
throw new IllegalArgumentException("Unable to access '" + repoConfigFile + "'!", e);
}
con.commit();
} catch (RepositoryException e) {
throw new IllegalStateException("Unable to load '" + repoConfigFile + "' to inmemory Sail!", e);
} finally {
if (con != null) {
try {
con.close();
} catch (RepositoryException e) {
/* ignore */
}
}
}
Set<String> repoNames;
RepositoryConfig repoConfig;
try {
repoNames = RepositoryConfigUtil.getRepositoryIDs(configRepo);
if (repoNames.size() == 1) {
repoConfig = RepositoryConfigUtil.getRepositoryConfig(configRepo, repoNames.iterator().next());
repoConfig.validate();
} else if (repoNames.size() > 1) {
throw new IllegalArgumentException("Repository configuration file '" + repoConfigFile + "' MUST only contain a single repository configuration!");
} else {
throw new IllegalArgumentException("Repository configuration file '" + repoConfigFile + "' DOES NOT contain a repository configuration!");
}
} catch (RepositoryException e) {
throw new IllegalStateException("Unable to read RepositoryConfiguration form the " + "in-memory Sail!", e);
} catch (RepositoryConfigException e) {
throw new IllegalArgumentException("Repository Configuration in '" + repoConfigFile + "is not valid!", e);
} finally {
try {
configRepo.shutDown();
} catch (RepositoryException e) {
/* ignore */
}
}
if (repoConfig.getRepositoryImplConfig() == null) {
throw new IllegalArgumentException("Missing RepositoryImpl config for " + "config " + repoConfig.getID() + " of file " + repoConfigFile + "!");
}
return repoConfig;
}
use of org.openrdf.repository.RepositoryException in project stanbol by apache.
the class RdfIndexingSource method close.
@Override
public void close() {
//first close still active RdfEntityDataIterator instances
for (EntityDataIterator edi : entityDataIterators) {
edi.close();
}
//close connections used for LDPath and EntityDataProvider
ungetLdPathConnection();
ungetEntityDataProviderConnection();
//finally shutdown the repository
if (shutdownRepository) {
try {
repository.shutDown();
} catch (RepositoryException e) {
log.warn("Error while closing Sesame Connection", e);
}
}
}
use of org.openrdf.repository.RepositoryException in project stanbol by apache.
the class RdfResourceImporter method importResource.
@Override
public ResourceState importResource(InputStream is, String resourceName) throws IOException {
log.info("> importing {}:", resourceName);
RDFFormat rdfFormat = Rio.getParserFormatForFileName(resourceName);
if (rdfFormat == null) {
log.info(" ... unable to detect RDF format for {}", resourceName);
log.info(" ... resource '{}' will not be imported", resourceName);
return ResourceState.IGNORED;
} else {
RepositoryConnection con = null;
try {
con = repository.getConnection();
con.begin();
con.add(new InputStreamReader(is, UTF8), baseUri, rdfFormat, contexts);
con.commit();
return ResourceState.LOADED;
} catch (RDFParseException e) {
log.error(" ... unable to parser RDF file " + resourceName + " (format: " + rdfFormat + ")", e);
return ResourceState.ERROR;
} catch (RepositoryException e) {
throw new IllegalArgumentException("Repository Exception while " + resourceName + "!", e);
} finally {
if (con != null) {
try {
con.close();
} catch (RepositoryException e1) {
/* ignore */
}
}
}
}
}
Aggregations