16
16
17
17
package org .springframework .cloud .function .context .catalog ;
18
18
19
+ import java .io .ByteArrayOutputStream ;
20
+ import java .io .IOException ;
19
21
import java .lang .reflect .Field ;
20
22
import java .lang .reflect .Type ;
21
23
import java .util .ArrayList ;
37
39
38
40
import com .fasterxml .jackson .databind .ObjectMapper ;
39
41
import com .google .gson .Gson ;
42
+ import com .google .protobuf .StringValue ;
40
43
import org .junit .jupiter .api .Assertions ;
41
44
import org .junit .jupiter .api .BeforeEach ;
42
45
import org .junit .jupiter .api .Disabled ;
43
46
import org .junit .jupiter .api .Test ;
44
47
import org .junit .jupiter .params .ParameterizedTest ;
45
48
import org .junit .jupiter .params .provider .ValueSource ;
46
49
import org .reactivestreams .Publisher ;
50
+ import org .springframework .messaging .converter .ProtobufMessageConverter ;
47
51
import reactor .core .publisher .Flux ;
48
52
import reactor .core .publisher .Mono ;
49
53
78
82
import org .springframework .util .ReflectionUtils ;
79
83
80
84
import static org .assertj .core .api .Assertions .assertThat ;
85
+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
81
86
82
87
/**
83
88
* @author Oleg Zhurakousky
@@ -97,6 +102,7 @@ public void before() {
97
102
messageConverters .add (new JsonMessageConverter (jsonMapper ));
98
103
messageConverters .add (new ByteArrayMessageConverter ());
99
104
messageConverters .add (new StringMessageConverter ());
105
+ messageConverters .add (new ProtobufMessageConverter ());
100
106
this .messageConverter = new SmartCompositeMessageConverter (messageConverters );
101
107
102
108
this .conversionService = new DefaultConversionService ();
@@ -207,6 +213,34 @@ void textContentTypeWithValueWrappedBracketsIsOk(String inputMessagePayloadValue
207
213
assertThat (functionResult ).isEqualTo (inputMessagePayloadValue );
208
214
}
209
215
216
+ @ ParameterizedTest
217
+ @ ValueSource (strings = {
218
+ "aaaaaaaaaa" , // no problem
219
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa]" // protobuf encoder prepends '[' for length (91 bytes)
220
+ })
221
+ public void testSCF1094 (String stringValue ) throws IOException {
222
+
223
+ Function <StringValue , String > getValue = msg -> msg != null ? msg .getValue () : null ;
224
+ Type functionType = ResolvableType .forClassWithGenerics (Function .class , ResolvableType .forClass (StringValue .class ), ResolvableType .forClass (String .class )).getType ();
225
+
226
+ var catalog = new SimpleFunctionRegistry (this .conversionService , this .messageConverter , new JacksonMapper (new ObjectMapper ()));
227
+ catalog .register (new FunctionRegistration <>(getValue , "getValue" ).type (functionType ));
228
+ FunctionInvocationWrapper lookedUpFunction = catalog .lookup ("getValue" );
229
+
230
+ ByteArrayOutputStream payload = new ByteArrayOutputStream ();
231
+ StringValue .newBuilder ()
232
+ .setValue (stringValue )
233
+ .build ()
234
+ .writeTo (payload );
235
+
236
+ var inputMessage = MessageBuilder .withPayload (payload .toByteArray ())
237
+ .setHeader ("contentType" , "application/x-protobuf" )
238
+ .build ();
239
+
240
+ Object result = assertDoesNotThrow (() -> lookedUpFunction .apply (inputMessage ));
241
+ assertThat (result ).isEqualTo (stringValue );
242
+ }
243
+
210
244
@ SuppressWarnings ("unchecked" )
211
245
@ Test
212
246
public void testSCF762 () {
0 commit comments