FederatedGetSchemaHandler implements OutputOperationHandler<GetSchema, Schema> { @Override public Schema doOperation(final GetSchema operation, final Context context, final Store store) throws OperationException { if (null == operation) { throw new OperationException("Operation cannot be null"); } return ((FederatedStore) store).getSchema(operation, context); }  @Override Schema doOperation(final GetSchema operation, final Context context, final Store store);  }
@Test public void shouldReturnSchema() throws OperationException { library.addProperties(ACC_PROP_ID, PROPERTIES); fStore.setGraphLibrary(library); final Schema edgeSchema = new Schema.Builder() .edge("edge", new SchemaEdgeDefinition.Builder() .source("string") .destination("string") .directed(DIRECTED_EITHER) .property("prop1", "string") .build()) .vertexSerialiser(new StringSerialiser()) .type(DIRECTED_EITHER, Boolean.class) .merge(STRING_SCHEMA) .build(); library.addSchema(EDGE_SCHEMA_ID, edgeSchema); fStore.execute(Operation.asOperationChain( new AddGraph.Builder() .graphId("schema") .parentPropertiesId(ACC_PROP_ID) .parentSchemaIds(Lists.newArrayList(EDGE_SCHEMA_ID)) .build()), context); final GetSchema operation = new GetSchema.Builder() .compact(true) .build(); final Schema result = handler.doOperation(operation, context, fStore); assertNotNull(result); JsonAssert.assertEquals(edgeSchema.toJson(true), result.toJson(true)); }
@Test public void shouldReturnSchemaOnlyForEnabledGraphs() throws OperationException { library.addProperties(ACC_PROP_ID, PROPERTIES); fStore.setGraphLibrary(library); final Schema edgeSchema1 = new Schema.Builder() .edge("edge", new SchemaEdgeDefinition.Builder() .source("string") .destination("string") .property("prop1", "string") .directed(DIRECTED_EITHER) .build()) .vertexSerialiser(new StringSerialiser()) .type(DIRECTED_EITHER, Boolean.class) .merge(STRING_SCHEMA) .build(); library.addSchema("edgeSchema1", edgeSchema1); final Schema edgeSchema2 = new Schema.Builder() .edge("edge", new SchemaEdgeDefinition.Builder() .source("string") .destination("string") .property("prop2", "string") .directed(DIRECTED_EITHER) .build()) .vertexSerialiser(new StringSerialiser()) .type(DIRECTED_EITHER, Boolean.class) .merge(STRING_SCHEMA) .build(); library.addSchema("edgeSchema2", edgeSchema2); fStore.execute(Operation.asOperationChain( new AddGraph.Builder() .graphId("schemaEnabled") .parentPropertiesId(ACC_PROP_ID) .parentSchemaIds(Lists.newArrayList("edgeSchema1")) .disabledByDefault(false) .build()), context); fStore.execute(Operation.asOperationChain( new AddGraph.Builder() .graphId("schemaDisabled") .parentPropertiesId(ACC_PROP_ID) .parentSchemaIds(Lists.newArrayList("edgeSchema2")) .disabledByDefault(true) .build()), context); final GetSchema operation = new GetSchema.Builder() .compact(true) .build(); final Schema result = handler.doOperation(operation, context, fStore); assertNotNull(result); JsonAssert.assertEquals(edgeSchema1.toJson(true), result.toJson(true)); }
@Test public void shouldThrowExceptionForANullOperation() throws OperationException { library.addProperties(ACC_PROP_ID, PROPERTIES); fStore.setGraphLibrary(library); final GetSchema operation = null; try { handler.doOperation(operation, context, fStore); } catch (final OperationException e) { assertTrue(e.getMessage().contains("Operation cannot be null")); } }