Skip to content

Commit

Permalink
TEIID-5088 TEIID-5089 Fix when add @Cache annotation, was missing enc…
Browse files Browse the repository at this point in the history
…losing paren (#1025)

* Fix when add @Cache annotation, was missing enclosing paren

* added testcase to the fix for adding @Cache
  • Loading branch information
vhalbert authored and shawkins committed Oct 11, 2017
1 parent 09e6f05 commit bdf0890
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Expand Up @@ -86,7 +86,7 @@ private void visit(Table table, String defaultCacheName) {
buffer.append("/* @Indexed");
String cacheName = ProtobufMetadataProcessor.getCacheName(table);
if (cacheName != null && !cacheName.equals(defaultCacheName)) {
buffer.append("@Cache(name=").append(cacheName);
buffer.append("@Cache(name=").append(cacheName).append(")");
}
buffer.append(" */").append(NL);
}
Expand Down
Expand Up @@ -37,6 +37,7 @@ public class TestSchemaToProtobufProcessor {
@Test
public void testConverstion() throws Exception {
SchemaToProtobufProcessor tool = new SchemaToProtobufProcessor();
//tool.setIndexMessages(true);
MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables.proto");
InfinispanConnection conn = Mockito.mock(InfinispanConnection.class);
BasicCache cache = Mockito.mock(BasicCache.class);
Expand Down Expand Up @@ -196,4 +197,33 @@ public void testSimpleNoMetadataConversion() throws Exception {
assertEquals(expected, resource.getContents());

}

@SuppressWarnings("rawtypes")
@Test
public void testConverstionUsingCacheAnnotation() throws Exception {
SchemaToProtobufProcessor tool = new SchemaToProtobufProcessor();
tool.setIndexMessages(true);
MetadataFactory mf = TestProtobufMetadataProcessor.protoMatadata("tables_bad.proto");
InfinispanConnection conn = Mockito.mock(InfinispanConnection.class);
BasicCache cache = Mockito.mock(BasicCache.class);
Mockito.stub(cache.getName()).toReturn("foo");
Mockito.stub(conn.getCache()).toReturn(cache);
ProtobufResource resource = tool.process(mf, conn);

String expected = "package model;\n" +
"\n" +
"/* @Indexed @Cache(name=foo) */\n" +
"message G1 {\n" +
" /* @Id @IndexedField(index=true, store=false) */\n" +
" required int32 e1 = 1;\n" +
" /* @IndexedField */\n" +
" required string e2 = 2;\n" +
" optional float e3 = 3;\n" +
" /* @IndexedField(index=true, store=false) */\n" +
" repeated string e4 = 4;\n" +
" repeated string e5 = 5;\n" +
"}\n\n";
assertEquals(expected, resource.getContents());
}

}
@@ -0,0 +1,13 @@
package pm1;

/* @Indexed @Cache(name=foo) */
message G1 {
/* @Id @IndexedField(index=true, store=false) */
required int32 e1 = 1;
/* @IndexedField */
required string e2 = 2;
optional float e3 = 3;
/* @IndexedField(index=true, store=false) */
repeated string e4 = 4;
repeated string e5 = 5;
}

0 comments on commit bdf0890

Please sign in to comment.