@SuppressWarnings("rawtypes") @Test public void testConverstion() throws Exception { SchemaToProtobufProcessor tool = new SchemaToProtobufProcessor(); MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto"); InfinispanConnection conn = Mockito.mock(InfinispanConnection.class); BasicCache cache = Mockito.mock(BasicCache.class); Mockito.stub(cache.getName()).toReturn("default"); Mockito.stub(conn.getCache()).toReturn(cache); ProtobufResource resource = tool.process(mf, conn); String expected = "package model;\n" + "\n" + "\n" + "message G1 {\n" + " \n" + " required int32 e1 = 1;\n" + " \n" + " required string e2 = 2;\n" + " optional float e3 = 3;\n" + " \n" + " repeated string e4 = 4;\n" + " repeated string e5 = 5;\n" + "}\n" + "\n" + "\n" + "message G2 {\n" + " \n" + " required int32 e1 = 1;\n" + " required string e2 = 2;\n" + " optional G3 g3 = 5;\n" + " \n" + " optional bytes e5 = 7;\n" + " \n" + " optional fixed64 e6 = 8;\n" + " repeated G4 g4 = 6;\n" + "}\n" + "\n" + "\n" + "message G4 {\n" + " required int32 e1 = 1;\n" + " required string e2 = 2;\n" + " optional int32 e1 = 3;\n" + "}\n" + "\n" + "\n" + "message G5 {\n" + " \n"+ " required int32 e1 = 1;\n" + " required string e2 = 2;\n" + " optional double e3 = 3;\n" + " optional float e4 = 4;\n" + " \n" + " optional int32 e5 = 5;\n" + " \n" + " optional int32 e6 = 6;\n" + " \n" + " optional string e7 = 7;\n" + " optional int64 e8 = 8;\n" + " \n" + " optional string e9 = 9;\n" + " \n" + " optional string e10 = 10;\n" + " \n" + " optional int64 e11 = 11;\n" + " \n" + " optional int64 e12 = 12;\n" + " \n" + " optional int64 e13 = 13;\n" + " \n" + " optional bytes e14 = 14;\n" + " \n" + " optional bytes e15 = 15;\n" + " \n" + " optional bytes e16 = 16;\n" + " \n" + " optional bytes e17 = 17;\n" + " \n" + " optional bytes e18 = 18;\n" + "}\n" + "\n"+ "message pm1.G3 {\n" + " required int32 e1 = 1;\n" + " required string e2 = 2;\n" + "}"; assertEquals(expected, resource.getContents()); }
public ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection) throws TranslatorException { String defaultCacheName = null; if (connection != null) { defaultCacheName = connection.getCache().getName(); } this.schema = metadataFactory.getSchema(); buffer.append("package ").append(schema.getName()).append(";"); buffer.append(NL); buffer.append(NL); for (Table table : schema.getTables().values()) { visit(table, defaultCacheName); buffer.append(NL); buffer.append(NL); } for (String name : this.processLater.keySet()) { visitTable(name, this.processLater.get(name)); } return new ProtobufResource(schema.getName() + ".proto", buffer.toString()); }
SchemaToProtobufProcessor { public ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection) throws TranslatorException { String defaultCacheName = null; if (connection != null) { defaultCacheName = connection.getCache().getName(); } this.schema = metadataFactory.getSchema(); buffer.append("package ").append(schema.getName()).append(";"); buffer.append(NL); buffer.append(NL); for (Table table : schema.getTables().values()) { visit(table, defaultCacheName); buffer.append(NL); buffer.append(NL); } for (String name : this.processLater.keySet()) { visitTable(name, this.processLater.get(name)); } return new ProtobufResource(schema.getName() + ".proto", buffer.toString()); } }
SchemaToProtobufProcessor { public ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection) throws TranslatorException { String defaultCacheName = null; if (connection != null) { defaultCacheName = connection.getCache().getName(); } this.schema = metadataFactory.getSchema(); buffer.append("package ").append(schema.getName()).append(";"); buffer.append(NL); buffer.append(NL); for (Table table : schema.getTables().values()) { visit(table, defaultCacheName); buffer.append(NL); buffer.append(NL); } for (String name : this.processLater.keySet()) { visitTable(name, this.processLater.get(name)); } return new ProtobufResource(schema.getName() + ".proto", buffer.toString()); }  }
SchemaToProtobufProcessor { public ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection) throws TranslatorException { String defaultCacheName = null; if (connection != null) { defaultCacheName = connection.getCache().getName(); } this.schema = metadataFactory.getSchema(); buffer.append("package ").append(schema.getName()).append(";"); buffer.append(NL); buffer.append(NL); for (Table table : schema.getTables().values()) { visit(table, defaultCacheName); buffer.append(NL); buffer.append(NL); } for (String name : this.processLater.keySet()) { visitTable(name, this.processLater.get(name)); } return new ProtobufResource(schema.getName() + ".proto", buffer.toString()); }  ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection); boolean isPartOfPrimaryKey(Column column); boolean isPartOfUniqueKey(Column column); boolean hasIndex(Column column); }
SchemaToProtobufProcessor { public ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection) throws TranslatorException { String defaultCacheName = null; if (connection != null) { defaultCacheName = connection.getCache().getName(); } this.schema = metadataFactory.getSchema(); buffer.append("package ").append(schema.getName()).append(";"); buffer.append(NL); buffer.append(NL); for (Table table : schema.getTables().values()) { visit(table, defaultCacheName); buffer.append(NL); buffer.append(NL); } for (String name : this.processLater.keySet()) { visitTable(name, this.processLater.get(name)); } return new ProtobufResource(schema.getName() + ".proto", buffer.toString()); }  ProtobufResource process(MetadataFactory metadataFactory, InfinispanConnection connection); boolean isPartOfPrimaryKey(Column column); boolean isPartOfUniqueKey(Column column); boolean hasIndex(Column column);  }