25
25
import org .springframework .boot .test .context .SpringBootTest ;
26
26
import org .springframework .boot .test .context .TestConfiguration ;
27
27
import org .springframework .context .annotation .Bean ;
28
+ import org .springframework .context .annotation .Configuration ;
28
29
import org .springframework .test .annotation .DirtiesContext ;
29
30
import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
30
31
48
49
@ SpringJUnitConfig (
49
50
classes = {
50
51
GrpcClientBeanInjectionTest .TestConfig .class ,
52
+ GrpcClientBeanInjectionTest .CustomConfig .class ,
51
53
InProcessConfiguration .class ,
52
54
ServiceConfiguration .class ,
53
55
BaseAutoConfiguration .class
@@ -73,36 +75,67 @@ public class GrpcClientBeanInjectionTest {
73
75
@ Autowired
74
76
String aboutMethodInjectedBlockingStubBean ;
75
77
78
+ @ Autowired
79
+ TestServiceGrpc .TestServiceBlockingStub stubFromSpringConfiguration ;
80
+
81
+ /**
82
+ * Test should cover bean simple single bean creation with {@link GrpcClientBean} annotation with
83
+ * {@link TestConfiguration}
84
+ */
76
85
@ Test
77
- void singleContextInjectionTest () {
86
+ void singleContextInjectionFromTestConfigurationTest () {
78
87
assertNotNull (blockingStub , "blockingStub" );
79
88
}
80
89
90
+ /**
91
+ * Test should cover bean simple single bean creation with {@link GrpcClientBean} annotation with
92
+ * {@link Configuration}
93
+ */
94
+ @ Test
95
+ void singleContextInjectionFromConfigurationTest () {
96
+ assertNotNull (stubFromSpringConfiguration , "stubFromSpringConfiguration" );
97
+ }
98
+
99
+ /**
100
+ * Test should cover creation of another bean with different stub class and same grpc client definition
101
+ */
81
102
@ Test
82
103
void anotherSubTypeAndSameClientDefinitionTest () {
83
104
assertNotNull (futureStubForClientTest , "futureStubForClientTest" );
84
105
}
85
106
107
+ /**
108
+ * Test should cover creation of another bean same different stub class, but different grpc client definition
109
+ */
86
110
@ Test
87
111
void twoDifferentClientDefinitionsTest () {
88
112
assertNotNull (anotherBlockingStub , "blockingStub" );
89
113
}
90
114
115
+ /**
116
+ * Test should cover creation of another bean with different service and stub class with same grpc client definition
117
+ */
118
+ @ Test
119
+ void anotherGrpcServiceAndSameGrpcClientDefinitionTest () {
120
+ assertNotNull (anotherServiceClientBean , "anotherServiceClientBean" );
121
+ }
122
+
123
+ /**
124
+ * Test should cover creation of bean without defined bean name
125
+ */
91
126
@ Test
92
127
void unnamedBeanContextInjectionTest () {
93
128
assertNotNull (unnamedTestServiceBlockingStub , "unnamedTestServiceBlockingStub" );
94
129
}
95
130
131
+ /**
132
+ * Test should cover bean method injection via {@link Autowired} and {@link Qualifier} from context
133
+ */
96
134
@ Test
97
135
void autoWiringQualifierMethodInjectionFromContextTest () {
98
136
assertNotNull (aboutMethodInjectedBlockingStubBean , "aboutBlockingStubBean" );
99
137
}
100
138
101
- @ Test
102
- void anotherGrpcServiceAndSameGrpcClientDefinitionTest () {
103
- assertNotNull (anotherServiceClientBean , "anotherServiceClientBean" );
104
- }
105
-
106
139
@ TestConfiguration
107
140
@ GrpcClientBeans (value = {
108
141
@ GrpcClientBean (
@@ -151,4 +184,12 @@ protected String getFactoryMethodName() {
151
184
};
152
185
}
153
186
}
187
+
188
+ @ Configuration
189
+ @ GrpcClientBean (
190
+ clazz = TestServiceGrpc .TestServiceBlockingStub .class ,
191
+ beanName = "stubFromSpringConfiguration" ,
192
+ client = @ GrpcClient ("test2" ))
193
+ public static class CustomConfig {
194
+ }
154
195
}
0 commit comments