19
19
20
20
import static org .junit .jupiter .api .Assertions .assertNotNull ;
21
21
22
- import javax .annotation .PostConstruct ;
23
-
24
22
import org .junit .jupiter .api .Test ;
25
23
import org .springframework .beans .factory .annotation .Autowired ;
26
24
import org .springframework .beans .factory .annotation .Qualifier ;
33
31
import io .grpc .stub .AbstractStub ;
34
32
import lombok .extern .slf4j .Slf4j ;
35
33
import net .devh .boot .grpc .client .inject .GrpcClient ;
34
+ import net .devh .boot .grpc .client .inject .GrpcClientBean ;
35
+ import net .devh .boot .grpc .client .inject .GrpcClientBeans ;
36
36
import net .devh .boot .grpc .client .stubfactory .StandardJavaGrpcStubFactory ;
37
37
import net .devh .boot .grpc .client .stubfactory .StubFactory ;
38
38
import net .devh .boot .grpc .test .config .BaseAutoConfiguration ;
47
47
@ SpringBootTest
48
48
@ SpringJUnitConfig (
49
49
classes = {
50
- GrpcClientAutoWiringFieldAndMethodInjectionTest .TestConfig .class ,
51
- GrpcClientAutoWiringFieldAndMethodInjectionTest .TestConfig2 .class ,
50
+ GrpcClientBeanInjectionTest .TestConfig .class ,
52
51
InProcessConfiguration .class ,
53
52
ServiceConfiguration .class ,
54
53
BaseAutoConfiguration .class
55
54
})
56
55
@ DirtiesContext
57
- public class GrpcClientAutoWiringFieldAndMethodInjectionTest {
56
+ public class GrpcClientBeanInjectionTest {
57
+
58
+ @ Autowired
59
+ TestServiceGrpc .TestServiceBlockingStub blockingStub ;
60
+
61
+ @ Autowired
62
+ TestServiceGrpc .TestServiceFutureStub futureStubForClientTest ;
63
+
64
+ @ Autowired
65
+ TestServiceGrpc .TestServiceBlockingStub anotherBlockingStub ;
66
+
67
+ @ Autowired
68
+ TestServiceGrpc .TestServiceBlockingStub unnamedTestServiceBlockingStub ;
58
69
59
70
@ Autowired
60
- @ Qualifier ("testServiceBlockingStub" )
61
- TestServiceGrpc .TestServiceBlockingStub testServiceBlockingStub ; // created in TestConfig with @GrpcClient
71
+ CustomGrpc .FactoryMethodAccessibleStub anotherServiceClientBean ;
62
72
63
73
@ Autowired
64
- String aboutBlockingStubBean ; // created in TestConfig2 with method injection
74
+ String aboutMethodInjectedBlockingStubBean ;
75
+
76
+ @ Test
77
+ void singleContextInjectionTest () {
78
+ assertNotNull (blockingStub , "blockingStub" );
79
+ }
80
+
81
+ @ Test
82
+ void anotherSubTypeAndSameClientDefinitionTest () {
83
+ assertNotNull (futureStubForClientTest , "futureStubForClientTest" );
84
+ }
85
+
86
+ @ Test
87
+ void twoDifferentClientDefinitionsTest () {
88
+ assertNotNull (anotherBlockingStub , "blockingStub" );
89
+ }
65
90
66
91
@ Test
67
- void fieldInjectionAutoWiringTest () {
68
- assertNotNull (testServiceBlockingStub , "testServiceBlockingStub " );
92
+ void unnamedBeanContextInjectionTest () {
93
+ assertNotNull (unnamedTestServiceBlockingStub , "unnamedTestServiceBlockingStub " );
69
94
}
70
95
71
96
@ Test
72
- void methodInjectionAutoWiringTest () {
73
- assertNotNull (aboutBlockingStubBean , "aboutBlockingStubBean" );
97
+ void autoWiringQualifierMethodInjectionFromContextTest () {
98
+ assertNotNull (aboutMethodInjectedBlockingStubBean , "aboutBlockingStubBean" );
99
+ }
100
+
101
+ @ Test
102
+ void anotherGrpcServiceAndSameGrpcClientDefinitionTest () {
103
+ assertNotNull (anotherServiceClientBean , "anotherServiceClientBean" );
74
104
}
75
105
76
106
@ TestConfiguration
107
+ @ GrpcClientBeans (value = {
108
+ @ GrpcClientBean (
109
+ clazz = TestServiceGrpc .TestServiceBlockingStub .class ,
110
+ beanName = "blockingStub" ,
111
+ client = @ GrpcClient ("test" )),
112
+ @ GrpcClientBean (
113
+ clazz = TestServiceGrpc .TestServiceFutureStub .class ,
114
+ beanName = "futureStubForClientTest" ,
115
+ client = @ GrpcClient ("test" )),
116
+ @ GrpcClientBean (
117
+ clazz = TestServiceGrpc .TestServiceBlockingStub .class ,
118
+ beanName = "anotherBlockingStub" ,
119
+ client = @ GrpcClient ("anotherTest" )),
120
+ @ GrpcClientBean (
121
+ clazz = TestServiceGrpc .TestServiceBlockingStub .class ,
122
+ client = @ GrpcClient ("unnamed" )),
123
+ @ GrpcClientBean (
124
+ clazz = CustomGrpc .FactoryMethodAccessibleStub .class ,
125
+ beanName = "anotherServiceClientBean" ,
126
+ client = @ GrpcClient ("test" ))
127
+ })
77
128
public static class TestConfig {
78
129
79
- @ GrpcClient ("test" )
80
- TestServiceGrpc .TestServiceBlockingStub blockingStub ;
130
+ @ Bean
131
+ public String aboutMethodInjectedBlockingStubBean (
132
+ @ Autowired
133
+ @ Qualifier ("anotherBlockingStub" ) TestServiceGrpc .TestServiceBlockingStub blockingStub ) {
134
+ return blockingStub .toString ();
135
+ }
81
136
82
137
@ Bean
83
138
StubFactory customStubFactory () {
@@ -95,21 +150,5 @@ protected String getFactoryMethodName() {
95
150
96
151
};
97
152
}
98
-
99
- @ PostConstruct
100
- public void init () {
101
- assertNotNull (this .blockingStub , "blockingStub" );
102
- }
103
153
}
104
-
105
- @ TestConfiguration
106
- public static class TestConfig2 {
107
-
108
- @ Bean
109
- public String aboutBlockingStubBean (
110
- @ Autowired @ Qualifier ("testServiceBlockingStub" ) TestServiceGrpc .TestServiceBlockingStub blockingStub ) {
111
- return blockingStub .toString ();
112
- }
113
- }
114
-
115
154
}
0 commit comments