Schema extends ElementDefinitions<SchemaEntityDefinition, SchemaEdgeDefinition> implements Cloneable { public TypeDefinition getType(final String typeName) { TypeDefinition typeDef = types.get(typeName); if (null == typeDef) { typeDef = unknownType; } return typeDef; } Schema(); protected  Schema(final Map<String, TypeDefinition> types); static Schema fromJson(final InputStream... inputStreams); static Schema fromJson(final Path... filePaths); static Schema fromJson(final byte[]... jsonBytes); @Deprecated String getId(); @Deprecated void setId(final String id); @SuppressWarnings("CloneDoesntCallSuperClone") @SuppressFBWarnings(value = "CN_IDIOM_NO_SUPER_CALL", justification = "Uses toJson instead.") @Override Schema clone(); @JsonIgnore boolean isAggregationEnabled(); @JsonIgnore List<String> getAggregatedGroups(); ValidationResult validate(); boolean hasValidation(); Map<String, TypeDefinition> getTypes(); TypeDefinition getType(final String typeName); @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "class") Serialiser getVertexSerialiser(); @Deprecated @JsonIgnore String getVertexSerialiserClass(); @Override SchemaElementDefinition getElement(final String group); String getVisibilityProperty(); @Deprecated String getTimestampProperty(); Map<String, String> getConfig(); String getConfig(final String key); void addConfig(final String key, final String value); @Override String toString(); byte[] toCompactJson();  }
@Test public void testLoadingSchemaFromJson() { SchemaElementDefinition edgeDefinition = schema.getEdge(TestGroups.EDGE); assertNotNull(edgeDefinition); assertEquals(EDGE_DESCRIPTION, edgeDefinition.getDescription()); final Map<String, String> propertyMap = edgeDefinition.getPropertyMap(); assertEquals(3, propertyMap.size()); assertEquals("prop.string", propertyMap.get(TestPropertyNames.PROP_2)); assertEquals("prop.date", propertyMap.get(TestPropertyNames.DATE)); assertEquals("timestamp", propertyMap.get(TestPropertyNames.TIMESTAMP)); assertEquals(Sets.newLinkedHashSet(Collections.singletonList(TestPropertyNames.DATE)), edgeDefinition.getGroupBy()); ElementFilter validator = edgeDefinition.getValidator(); List<TupleAdaptedPredicate<String, ?>> valContexts = validator.getComponents(); int index = 0; TupleAdaptedPredicate<String, ?> tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(IdentifierType.SOURCE.name(), tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(IdentifierType.DESTINATION.name(), tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(IdentifierType.DIRECTED.name(), tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof ExampleFilterFunction); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(IdentifierType.DIRECTED.name(), tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(TestPropertyNames.PROP_2, tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof ExampleFilterFunction); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(TestPropertyNames.PROP_2, tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(TestPropertyNames.DATE, tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(TestPropertyNames.TIMESTAMP, tuplePredicate.getSelection()[0]); assertEquals(index, valContexts.size()); TypeDefinition type = edgeDefinition.getPropertyTypeDef(TestPropertyNames.DATE); assertEquals(Date.class, type.getClazz()); assertEquals(DATE_TYPE_DESCRIPTION, type.getDescription()); assertNull(type.getSerialiser()); assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction); SchemaElementDefinition entityDefinition = schema.getEntity(TestGroups.ENTITY); assertNotNull(entityDefinition); assertEquals(ENTITY_DESCRIPTION, entityDefinition.getDescription()); assertTrue(entityDefinition.containsProperty(TestPropertyNames.PROP_1)); type = entityDefinition.getPropertyTypeDef(TestPropertyNames.PROP_1); assertEquals(0, entityDefinition.getGroupBy().size()); assertEquals(STRING_TYPE_DESCRIPTION, type.getDescription()); assertEquals(String.class, type.getClazz()); assertNull(type.getSerialiser()); assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction); validator = entityDefinition.getValidator(); valContexts = validator.getComponents(); index = 0; tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsXMoreThanY); assertEquals(2, tuplePredicate.getSelection().length); assertEquals(TestPropertyNames.PROP_1, tuplePredicate.getSelection()[0]); assertEquals(TestPropertyNames.VISIBILITY, tuplePredicate.getSelection()[1]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(IdentifierType.VERTEX.name(), tuplePredicate.getSelection()[0]); tuplePredicate = valContexts.get(index++); assertTrue(tuplePredicate.getPredicate() instanceof IsA); assertEquals(1, tuplePredicate.getSelection().length); assertEquals(TestPropertyNames.PROP_1, tuplePredicate.getSelection()[0]); final ElementAggregator aggregator = edgeDefinition.getFullAggregator(); final List<TupleAdaptedBinaryOperator<String, ?>> aggContexts = aggregator.getComponents(); assertEquals(3, aggContexts.size()); TupleAdaptedBinaryOperator<String, ?> aggContext = aggContexts.get(0); assertTrue(aggContext.getBinaryOperator() instanceof ExampleAggregateFunction); assertEquals(1, aggContext.getSelection().length); assertEquals(TestPropertyNames.PROP_2, aggContext.getSelection()[0]); aggContext = aggContexts.get(1); assertTrue(aggContext.getBinaryOperator() instanceof ExampleAggregateFunction); assertEquals(1, aggContext.getSelection().length); assertEquals(TestPropertyNames.DATE, aggContext.getSelection()[0]); TypeDefinition mapTypeDef = schema.getType(TestTypes.PROP_MAP); assertEquals(LinkedHashMap.class, mapTypeDef.getClazz()); assertEquals(MAP_TYPE_DESCRIPTION, mapTypeDef.getDescription()); Serialiser serialiser = mapTypeDef.getSerialiser(); assertEquals(MapSerialiser.class, serialiser.getClass()); MapSerialiser mapSerialiser = (MapSerialiser) serialiser; assertEquals(StringSerialiser.class, mapSerialiser.getKeySerialiser().getClass()); assertEquals(RawLongSerialiser.class, mapSerialiser.getValueSerialiser().getClass()); assertNull(mapSerialiser.getMapClass()); }