1
+ package com .flit .protoc .gen .server .undertow ;
2
+
3
+ import com .flit .protoc .Plugin ;
4
+ import com .google .protobuf .compiler .PluginProtos ;
5
+ import org .junit .Test ;
6
+
7
+ import java .util .Map ;
8
+ import java .util .function .Function ;
9
+ import java .util .stream .Collectors ;
10
+
11
+ import static org .junit .Assert .assertEquals ;
12
+ import static org .junit .Assert .assertNotNull ;
13
+ import static org .junit .Assert .assertTrue ;
14
+
15
+ /**
16
+ * Tests the generation of a service that has core definition imported from another file
17
+ */
18
+ public class ContextGeneratorTest extends BaseGeneratorTest {
19
+
20
+ @ Test
21
+ public void test_GenerateWithMissingRoot () throws Exception {
22
+ test_Route ("context.missing.undertow.bin" , "/twirp/com.example.context.NullService" );
23
+ }
24
+
25
+ @ Test
26
+ public void test_GenerateWithEmptyRoot () throws Exception {
27
+ test_Route ("context.empty.undertow.bin" , "/twirp/com.example.context.NullService" );
28
+ }
29
+
30
+ @ Test
31
+ public void test_GenerateWithSlashOnlyRoot () throws Exception {
32
+ test_Route ("context.slash.undertow.bin" , "/com.example.context.NullService" );
33
+ }
34
+
35
+ @ Test
36
+ public void test_GenerateWithSlashRoot () throws Exception {
37
+ test_Route ("context.root.undertow.bin" , "/root/com.example.context.NullService" );
38
+ }
39
+
40
+ @ Test
41
+ public void test_GenerateWithNameRoot () throws Exception {
42
+ test_Route ("context.name.undertow.bin" , "/fibble/com.example.context.NullService" );
43
+ }
44
+
45
+ private void test_Route (String file , String route ) throws Exception {
46
+ PluginProtos .CodeGeneratorRequest request = load (file );
47
+
48
+ Plugin plugin = new Plugin (request );
49
+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
50
+
51
+ assertNotNull (response );
52
+ assertEquals (2 , response .getFileCount ());
53
+
54
+ Map <String , PluginProtos .CodeGeneratorResponse .File > files = response .getFileList ().stream ().collect (Collectors .toMap (
55
+ PluginProtos .CodeGeneratorResponse .File ::getName ,
56
+ Function .identity ()
57
+ ));
58
+
59
+ assertTrue (files .containsKey ("com/example/context/rpc/RpcNullServiceService.java" ));
60
+ assertTrue (files .containsKey ("com/example/context/rpc/RpcNullServiceHandler.java" ));
61
+
62
+ assertTrue (files .get ("com/example/context/rpc/RpcNullServiceHandler.java" ).getContent ().contains (
63
+ String .format ("public static final String ROUTE = \" %s\" ;" , route )
64
+ ));
65
+ }
66
+
67
+ }
0 commit comments