Graph { public Schema getSchema() { return store.getOriginalSchema(); } 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 shouldConstructGraphFromSchemaFolderPath() throws IOException { final Schema expectedSchema = new Schema.Builder() .json(StreamUtil.elementsSchema(getClass()), StreamUtil.typesSchema(getClass())) .build(); Graph graph = null; File schemaDir = null; try { schemaDir = createSchemaDirectory(); graph = new Graph.Builder() .config(new GraphConfig.Builder() .graphId(GRAPH_ID) .build()) .storeProperties(StreamUtil.storeProps(getClass())) .addSchema(Paths.get(schemaDir.getPath())) .build(); } finally { if (null != schemaDir) { FileUtils.deleteDirectory(schemaDir); } } JsonAssert.assertEquals(expectedSchema.toJson(true), graph.getSchema().toJson(true)); }
@Test public void shouldConstructGraphFromSchemaURI() throws IOException, URISyntaxException { final URI typeInputUri = getResourceUri(StreamUtil.TYPES_SCHEMA); final URI schemaInputUri = getResourceUri(StreamUtil.ELEMENTS_SCHEMA); final URI storeInputUri = getResourceUri(StreamUtil.STORE_PROPERTIES); final Schema expectedSchema = new Schema.Builder() .json(StreamUtil.elementsSchema(getClass()), StreamUtil.typesSchema(getClass())) .build(); Graph graph = null; File schemaDir = null; try { schemaDir = createSchemaDirectory(); graph = new Graph.Builder() .config(new GraphConfig.Builder() .graphId(GRAPH_ID) .build()) .storeProperties(storeInputUri) .addSchemas(typeInputUri, schemaInputUri) .build(); } finally { if (schemaDir != null) { FileUtils.deleteDirectory(schemaDir); } } JsonAssert.assertEquals(expectedSchema.toJson(true), graph.getSchema().toJson(true)); }
@Test public void shouldGetSchemaFromStoreIfSchemaIsEmpty() throws OperationException { final Store store = mock(Store.class); final Schema schema = new Schema.Builder() .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .vertex("string") .build()) .type("string", String.class) .build(); given(store.getSchema()).willReturn(schema); given(store.getOriginalSchema()).willReturn(schema); given(store.getProperties()).willReturn(new StoreProperties()); final View view = mock(View.class); new Graph.Builder() .config(new GraphConfig.Builder() .graphId(GRAPH_ID) .view(view) .build()) .addSchema(new Schema()) .store(store) .build(); verify(store).setOriginalSchema(schema); }
@Test public void shouldBuildGraphUsingGraphIdAndLookupSchema() throws Exception { final StoreProperties storeProperties = new StoreProperties(); storeProperties.setStoreClass(TestStoreImpl.class.getName()); final Schema schemaModule1 = new Schema.Builder() .type(TestTypes.PROP_STRING, new TypeDefinition.Builder() .clazz(String.class) .build()) .type("vertex", new TypeDefinition.Builder() .clazz(String.class) .build()) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING) .aggregate(false) .source("vertex") .destination("vertex") .directed(DIRECTED_EITHER) .build()) .build(); final Schema schemaModule2 = new Schema.Builder() .type(TestTypes.PROP_INTEGER, new TypeDefinition.Builder() .clazz(Integer.class) .build()) .type("vertex2", new TypeDefinition.Builder() .clazz(String.class) .build()) .edge(TestGroups.EDGE_2, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_2, TestTypes.PROP_INTEGER) .aggregate(false) .source("vertex2") .destination("vertex2") .directed(DIRECTED_EITHER) .build()) .build(); final Schema schemaModule3 = new Schema.Builder() .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING) .aggregate(false) .vertex("vertex3") .build()) .type("vertex3", new TypeDefinition.Builder() .clazz(String.class) .build()) .build(); final Schema schemaModule4 = new Schema.Builder() .entity(TestGroups.ENTITY_2, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_2, TestTypes.PROP_INTEGER) .aggregate(false) .vertex("vertex4") .build()) .type("vertex4", new TypeDefinition.Builder() .clazz(String.class) .build()) .type(DIRECTED_EITHER, Boolean.class) .build(); final Graph graph = new Graph.Builder() .config(new GraphConfig.Builder() .graphId(GRAPH_ID) .library(new HashMapGraphLibrary()) .build()) .addSchema(schemaModule1) .addSchema(schemaModule2) .addSchema(schemaModule3) .addSchema(schemaModule4) .storeProperties(storeProperties) .build(); final Graph graph2 = new Graph.Builder() .config(new GraphConfig.Builder() .graphId(GRAPH_ID) .library(new HashMapGraphLibrary()) .build()) .storeProperties(storeProperties) .build(); JsonAssert.assertEquals(graph.getSchema().toJson(false), graph2.getSchema().toJson(false)); }