Graph { public List<Class<? extends GraphHook>> getGraphHooks() { if (config.getHooks().isEmpty()) { return Collections.emptyList(); } return (List) config.getHooks().stream().map(GraphHook::getClass).collect(Collectors.toList()); } private  Graph(final GraphConfig config, final Store store); void execute(final Operation operation, final User user); void execute(final Operation operation, final Context context); O execute(final Output<O> operation, final User user); O execute(final Output<O> operation, final Context context); GraphResult<O> execute(final GraphRequest<O> request); JobDetail executeJob(final Operation operation, final User user); JobDetail executeJob(final Operation operation, final Context context); GraphResult<JobDetail> executeJob(final GraphRequest<?> request); JobDetail executeJob(final Job job, final User user); JobDetail executeJob(final Job job, final Context context); boolean isSupported(final Class<? extends Operation> operationClass); Set<Class<? extends Operation>> getSupportedOperations(); Set<Class<? extends Operation>> getNextOperations(final Class<? extends Operation> operation); View getView(); Schema getSchema(); String getDescription(); boolean hasTrait(final StoreTrait storeTrait); Set<StoreTrait> getStoreTraits(); String getGraphId(); StoreProperties getStoreProperties(); List<Class<? extends GraphHook>> getGraphHooks(); GraphLibrary getGraphLibrary();  }
@Test public void shouldAddHooksVarArgsAndGetGraphHooks() throws Exception { final StoreProperties storeProperties = new StoreProperties(); storeProperties.setStoreClass(TestStoreImpl.class.getName()); final GraphHook graphHook1 = mock(GraphHook.class); final Log4jLogger graphHook2 = mock(Log4jLogger.class); final Graph graph = new Graph.Builder() .config(new GraphConfig.Builder() .graphId("graphId") .addHooks(graphHook1, graphHook2) .build()) .storeProperties(storeProperties) .addSchemas(StreamUtil.schemas(getClass())) .build(); assertEquals(Arrays.asList(NamedViewResolver.class, graphHook1.getClass(), graphHook2.getClass(), FunctionAuthoriser.class), graph.getGraphHooks()); }
@Test public void shouldAddHooksFromPathAndGetGraphHooks() throws Exception { final StoreProperties storeProperties = new StoreProperties(); storeProperties.setStoreClass(TestStoreImpl.class.getName()); final File graphHooks = tempDir.resolve("graphHooks.json").toFile(); FileUtils.writeLines(graphHooks, IOUtils.readLines(StreamUtil.openStream(getClass(), "graphHooks.json"))); final Graph graph = new Graph.Builder() .config(new GraphConfig.Builder() .graphId("graphId") .addHooks(Paths.get(graphHooks.getPath())) .build()) .storeProperties(storeProperties) .addSchemas(StreamUtil.schemas(getClass())) .build(); assertEquals( Arrays.asList(NamedViewResolver.class, OperationChainLimiter.class, AddOperationsToChain.class, OperationAuthoriser.class, FunctionAuthoriser.class), graph.getGraphHooks() ); }
@Test public void shouldAddHookFromPathAndGetGraphHooks() throws Exception { final StoreProperties storeProperties = new StoreProperties(); storeProperties.setStoreClass(TestStoreImpl.class.getName()); final File graphHook1File = tempDir.resolve("opChainLimiter.json").toFile(); FileUtils.writeLines(graphHook1File, IOUtils.readLines(StreamUtil.openStream(getClass(), "opChainLimiter.json"))); final File graphHook2File = tempDir.resolve("opAuthoriser.json").toFile(); FileUtils.writeLines(graphHook2File, IOUtils.readLines(StreamUtil.openStream(getClass(), "opAuthoriser.json"))); final Graph graph = new Graph.Builder() .config(new GraphConfig.Builder() .graphId("graphId") .addHook(Paths.get(graphHook1File.getPath())) .addHook(Paths.get(graphHook2File.getPath())) .build()) .storeProperties(storeProperties) .addSchemas(StreamUtil.schemas(getClass())) .build(); assertEquals(Arrays.asList(NamedViewResolver.class, OperationChainLimiter.class, OperationAuthoriser.class, FunctionAuthoriser.class), graph.getGraphHooks()); }