FederatedStoreCache extends Cache<Pair<GraphSerialisable, FederatedAccess>> { public void addGraphToCache(final Graph graph, final FederatedAccess access, final boolean overwrite) throws CacheOperationException { String graphId = graph.getGraphId(); Pair<GraphSerialisable, FederatedAccess> pair = new Pair<>(new GraphSerialisable.Builder().graph(graph).build(), access); try { addToCache(graphId, pair, overwrite); } catch (final CacheOperationException e) { throw new CacheOperationException(String.format(ERROR_ADDING_GRAPH_TO_CACHE_GRAPH_ID_S, graphId), e.getCause()); } } FederatedStoreCache(); Set<String> getAllGraphIds(); void addGraphToCache(final Graph graph, final FederatedAccess access, final boolean overwrite); Graph getGraphFromCache(final String graphId); GraphSerialisable getGraphSerialisableFromCache(final String graphId); FederatedAccess getAccessFromCache(final String graphId); static final String ERROR_ADDING_GRAPH_TO_CACHE_GRAPH_ID_S; }
@Test public void shouldThrowExceptionIfGraphAlreadyExistsInCache() throws CacheOperationException { federatedStoreCache.addGraphToCache(testGraph, null, false); try { federatedStoreCache.addGraphToCache(testGraph, null, false); fail("Exception expected"); } catch (OverwritingException e) { assertTrue(e.getMessage().contains("Cache entry already exists")); } }