FederatedGraphStorage { public void put(final Collection<GraphSerialisable> graphs, final FederatedAccess access) throws StorageException { for (final GraphSerialisable graph : graphs) { put(graph, access); } }  void put(final Collection<GraphSerialisable> graphs, final FederatedAccess access); void put(final GraphSerialisable graph, final FederatedAccess access); Collection<String> getAllIds(final User user); Collection<String> getAllIds(final User user, final String adminAuth); Collection<Graph> getAll(final User user); boolean remove(final String graphId, final User user); Collection<Graph> get(final User user, final List<String> graphIds); Schema getSchema(final GetSchema operation, final Context context); Schema getSchema(final Map<String, String> config, final Context context); Schema getSchema(final Map<String, String> config, final User user); Set<StoreTrait> getTraits(final GetTraits op, final Context context); Set<StoreTrait> getTraits(final Map<String, String> config, final User user); void setGraphLibrary(final GraphLibrary graphLibrary); boolean changeGraphAccess(final String graphId, final FederatedAccess newFederatedAccess, final User requestingUser); boolean changeGraphAccess(final String graphId, final FederatedAccess newFederatedAccess, final User requestingUser, final String adminAuth); @Deprecated boolean changeGraphAccessAsAdmin(final String graphId, final FederatedAccess newFederatedAccess); boolean changeGraphId(final String graphId, final String newGraphId, final User requestingUser); boolean changeGraphId(final String graphId, final String newGraphId, final User requestingUser, final String adminAuth); @Deprecated boolean changeGraphIdAsAdmin(final String graphId, final String newGraphId); static final boolean DEFAULT_DISABLED_BY_DEFAULT; static final String ERROR_ADDING_GRAPH_TO_CACHE; static final String USER_IS_ATTEMPTING_TO_OVERWRITE; static final String ACCESS_IS_NULL; static final String GRAPH_IDS_NOT_VISIBLE; static final String UNABLE_TO_MERGE_THE_SCHEMAS_FOR_ALL_OF_YOUR_FEDERATED_GRAPHS; }
@Test public void shouldThrowExceptionWhenAddingNullSchema() { GraphSerialisable nullGraph = null; try { graphStorage.put(nullGraph, access); } catch (StorageException e) { assertEquals("Graph cannot be null", e.getMessage()); } }
@Test public void checkSchemaNotLeakedWhenAlreadyExistsUnderDifferentAccess() throws Exception { Schema schemaNotToBeExposed = new Schema.Builder() .type(UNUSUAL_TYPE, String.class) .type(DIRECTED_EITHER, Boolean.class) .entity(GROUP_ENT, new SchemaEntityDefinition.Builder() .vertex(UNUSUAL_TYPE) .build()) .edge(GROUP_EDGE, new SchemaEdgeDefinition.Builder() .source(UNUSUAL_TYPE) .destination(UNUSUAL_TYPE) .directed(DIRECTED_EITHER) .build()) .build(); final GraphSerialisable graph1 = new GraphSerialisable.Builder() .config(new GraphConfig.Builder().graphId(GRAPH_ID_A).build()) .properties(PROPERTIES) .schema(schemaNotToBeExposed) .build(); graphStorage.put(graph1, access); try { graphStorage.put(graph1, altAccess); } catch (StorageException e) { assertEquals("Error adding graph " + GRAPH_ID_A + " to storage due to: " + String.format(FederatedGraphStorage.USER_IS_ATTEMPTING_TO_OVERWRITE, GRAPH_ID_A), e.getMessage()); testNotLeakingContents(e, UNUSUAL_TYPE, GROUP_EDGE, GROUP_ENT); } }
@Test public void checkSchemaNotLeakedWhenAlreadyExistsUnderDifferentAccessWithOtherGraphs() throws Exception { final String unusualType = "unusualType"; final String groupEnt = "ent"; final String groupEdge = "edg"; Schema schemaNotToBeExposed = new Schema.Builder() .type(unusualType, String.class) .type(DIRECTED_EITHER, Boolean.class) .entity(groupEnt, new SchemaEntityDefinition.Builder() .vertex(unusualType) .build()) .edge(groupEdge, new SchemaEdgeDefinition.Builder() .source(unusualType) .destination(unusualType) .directed(DIRECTED_EITHER) .build()) .build(); final GraphSerialisable graph1 = new GraphSerialisable.Builder() .config(new GraphConfig.Builder().graphId(GRAPH_ID_A).build()) .properties(PROPERTIES) .schema(schemaNotToBeExposed) .build(); graphStorage.put(graph1, access); final GraphSerialisable graph2 = new GraphSerialisable.Builder() .config(new GraphConfig.Builder().graphId(GRAPH_ID_B).build()) .schema(new Schema.Builder() .merge(schemaNotToBeExposed) .entity("e2", e2) .type("string2", String.class) .build()) .properties(PROPERTIES) .build(); graphStorage.put(graph2, altAccess); try { graphStorage.put(graph2, access); } catch (StorageException e) { assertEquals("Error adding graph " + GRAPH_ID_B + " to storage due to: " + String.format(FederatedGraphStorage.USER_IS_ATTEMPTING_TO_OVERWRITE, GRAPH_ID_B), e.getMessage()); testNotLeakingContents(e, unusualType, groupEdge, groupEnt); } }