@Test public void parsesObjectSchema() throws IOException { String objectSchema = "/* This is a comment\n" + " consisting of multiple lines */\n" + " TypeA {\n" + " int a1;\n" + " \tstring a2; //This is a comment\n" + " String a3;\n" + "}\n"; HollowObjectSchema schema = (HollowObjectSchema) HollowSchemaParser.parseSchema(objectSchema); Assert.assertEquals("TypeA", schema.getName()); Assert.assertEquals(3, schema.numFields()); Assert.assertEquals(FieldType.INT, schema.getFieldType(0)); Assert.assertEquals("a1", schema.getFieldName(0)); Assert.assertEquals(FieldType.STRING, schema.getFieldType(1)); Assert.assertEquals("a2", schema.getFieldName(1)); Assert.assertEquals(FieldType.REFERENCE, schema.getFieldType(2)); Assert.assertEquals("String", schema.getReferencedType(2)); Assert.assertEquals("a3", schema.getFieldName(2)); // HollowObjectSchame.toString is parsed properly Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void parsesObjectSchemaMultipleWithKey() throws IOException { String objectSchema = " TypeA @PrimaryKey(a1, a3.value) {\n" + " int a1;\n" + " string a2;\n" + " String a3;\n" + "}\n"; HollowObjectSchema schema = (HollowObjectSchema) HollowSchemaParser.parseSchema(objectSchema); Assert.assertEquals("TypeA", schema.getName()); Assert.assertEquals(3, schema.numFields()); Assert.assertEquals(FieldType.INT, schema.getFieldType(0)); Assert.assertEquals("a1", schema.getFieldName(0)); Assert.assertEquals(FieldType.STRING, schema.getFieldType(1)); Assert.assertEquals("a2", schema.getFieldName(1)); Assert.assertEquals(FieldType.REFERENCE, schema.getFieldType(2)); Assert.assertEquals("String", schema.getReferencedType(2)); Assert.assertEquals("a3", schema.getFieldName(2)); // Make sure primary key and HollowObjectSchame.toString is parsed properly Assert.assertEquals(new PrimaryKey("TypeA", "a1", "a3.value"), schema.getPrimaryKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }
@Test public void parsesObjectSchemaWithKey() throws IOException { String objectSchema = " TypeA @PrimaryKey(a1) {\n" + " int a1;\n" + " string a2;\n" + " String a3;\n" + "}\n"; HollowObjectSchema schema = (HollowObjectSchema) HollowSchemaParser.parseSchema(objectSchema); Assert.assertEquals("TypeA", schema.getName()); Assert.assertEquals(3, schema.numFields()); Assert.assertEquals(FieldType.INT, schema.getFieldType(0)); Assert.assertEquals("a1", schema.getFieldName(0)); Assert.assertEquals(FieldType.STRING, schema.getFieldType(1)); Assert.assertEquals("a2", schema.getFieldName(1)); Assert.assertEquals(FieldType.REFERENCE, schema.getFieldType(2)); Assert.assertEquals("String", schema.getReferencedType(2)); Assert.assertEquals("a3", schema.getFieldName(2)); // Make sure primary key and HollowObjectSchame.toString is parsed properly Assert.assertEquals(new PrimaryKey("TypeA", "a1"), schema.getPrimaryKey()); Assert.assertEquals(schema, HollowSchemaParser.parseSchema(schema.toString())); }