3535class AsyncAnnotationUtilTest {
3636 StringValueResolver stringValueResolver = mock (StringValueResolver .class );
3737
38+ {
39+ when (stringValueResolver .resolveStringValue (any ()))
40+ .thenAnswer (invocation -> invocation .getArgument (0 ).toString () + "Resolved" );
41+ }
42+
3843 @ ParameterizedTest
3944 @ ValueSource (classes = {ClassWithOperationBindingProcessor .class , ClassWithAbstractOperationBindingProcessor .class })
4045 void getAsyncHeaders (Class <?> classWithOperationBindingProcessor ) throws Exception {
4146 // given
4247 Method m = classWithOperationBindingProcessor .getDeclaredMethod ("methodWithAnnotation" , String .class );
4348 AsyncOperation operation = m .getAnnotation (AsyncListener .class ).operation ();
4449
45- when (stringValueResolver .resolveStringValue (any ()))
46- .thenAnswer (invocation -> invocation .getArgument (0 ).toString () + "Resolved" );
47-
4850 // when
4951 SchemaObject headers = AsyncAnnotationUtil .getAsyncHeaders (operation , stringValueResolver );
5052
@@ -58,6 +60,7 @@ void getAsyncHeaders(Class<?> classWithOperationBindingProcessor) throws Excepti
5860 assertThat (headerResolved .getType ()).containsExactly ("string" );
5961 assertThat (headerResolved .getExamples ().get (0 )).isEqualTo ("valueResolved" );
6062 assertThat (headerResolved .getDescription ()).isEqualTo ("descriptionResolved" );
63+ assertThat (headerResolved .getFormat ()).isEqualTo ("int32Resolved" );
6164
6265 assertThat (headers .getProperties ().containsKey ("headerWithoutValueResolved" ))
6366 .as (headers .getProperties () + " does not contain key 'headerWithoutValueResolved'" )
@@ -68,6 +71,7 @@ void getAsyncHeaders(Class<?> classWithOperationBindingProcessor) throws Excepti
6871 assertThat (headerWithoutValueResolved .getExamples ()).isNull ();
6972 assertThat (headerWithoutValueResolved .getEnumValues ()).isNull ();
7073 assertThat (headerWithoutValueResolved .getDescription ()).isEqualTo ("descriptionResolved" );
74+ assertThat (headerWithoutValueResolved .getFormat ()).isNull ();
7175 }
7276
7377 @ Test
@@ -76,10 +80,6 @@ void getAsyncHeadersWithEmptyHeaders() throws Exception {
7680 Method m = ClassWithHeaders .class .getDeclaredMethod ("emptyHeaders" , String .class );
7781 AsyncOperation operation = m .getAnnotation (AsyncListener .class ).operation ();
7882
79- StringValueResolver stringValueResolver = mock (StringValueResolver .class );
80- when (stringValueResolver .resolveStringValue (any ()))
81- .thenAnswer (invocation -> invocation .getArgument (0 ).toString () + "Resolved" );
82-
8383 // when
8484 SchemaObject headers = AsyncAnnotationUtil .getAsyncHeaders (operation , stringValueResolver );
8585
@@ -93,24 +93,21 @@ void getAsyncHeadersWithoutSchemaName() throws Exception {
9393 Method m = ClassWithHeaders .class .getDeclaredMethod ("withoutSchemaName" , String .class );
9494 AsyncOperation operation = m .getAnnotation (AsyncListener .class ).operation ();
9595
96- StringValueResolver stringValueResolver = mock (StringValueResolver .class );
97- when (stringValueResolver .resolveStringValue (any ()))
98- .thenAnswer (invocation -> invocation .getArgument (0 ).toString () + "Resolved" );
99-
10096 // when
10197 SchemaObject headers = AsyncAnnotationUtil .getAsyncHeaders (operation , stringValueResolver );
10298
10399 // then
104100 assertThat (headers )
105101 .isEqualTo (SchemaObject .builder ()
106102 .type (SchemaType .OBJECT )
107- .title ("Headers-501004016 " )
103+ .title ("Headers-1585401221 " )
108104 .properties (Map .of (
109105 "headerResolved" ,
110106 SchemaObject .builder ()
111107 .type (SchemaType .STRING )
112108 .title ("headerResolved" )
113109 .description ("descriptionResolved" )
110+ .format (null )
114111 .enumValues (List .of ("valueResolved" ))
115112 .examples (List .of ("valueResolved" ))
116113 .build ()))
@@ -123,9 +120,32 @@ void getAsyncHeadersWithoutValue() throws Exception {
123120 Method m = ClassWithHeaders .class .getDeclaredMethod ("withoutValue" , String .class );
124121 AsyncOperation operation = m .getAnnotation (AsyncListener .class ).operation ();
125122
126- StringValueResolver stringValueResolver = mock (StringValueResolver .class );
127- when (stringValueResolver .resolveStringValue (any ()))
128- .thenAnswer (invocation -> invocation .getArgument (0 ).toString () + "Resolved" );
123+ // when
124+ SchemaObject headers = AsyncAnnotationUtil .getAsyncHeaders (operation , stringValueResolver );
125+
126+ // then
127+ assertThat (headers )
128+ .isEqualTo (SchemaObject .builder ()
129+ .type (SchemaType .OBJECT )
130+ .title ("Headers-1612438838" )
131+ .properties (Map .of (
132+ "headerResolved" ,
133+ SchemaObject .builder ()
134+ .type (SchemaType .STRING )
135+ .title ("headerResolved" )
136+ .description ("descriptionResolved" )
137+ .format (null )
138+ .enumValues (null )
139+ .examples (null )
140+ .build ()))
141+ .build ());
142+ }
143+
144+ @ Test
145+ void getAsyncHeadersWithFormat () throws Exception {
146+ // given
147+ Method m = ClassWithHeaders .class .getDeclaredMethod ("withFormat" , String .class );
148+ AsyncOperation operation = m .getAnnotation (AsyncListener .class ).operation ();
129149
130150 // when
131151 SchemaObject headers = AsyncAnnotationUtil .getAsyncHeaders (operation , stringValueResolver );
@@ -134,11 +154,12 @@ void getAsyncHeadersWithoutValue() throws Exception {
134154 assertThat (headers )
135155 .isEqualTo (SchemaObject .builder ()
136156 .type (SchemaType .OBJECT )
137- .title ("Headers-472917891 " )
157+ .title ("Headers-1701213112 " )
138158 .properties (Map .of (
139159 "headerResolved" ,
140160 SchemaObject .builder ()
141161 .type (SchemaType .STRING )
162+ .format ("int32Resolved" )
142163 .title ("headerResolved" )
143164 .description ("descriptionResolved" )
144165 .enumValues (null )
@@ -147,6 +168,20 @@ void getAsyncHeadersWithoutValue() throws Exception {
147168 .build ());
148169 }
149170
171+ @ Test
172+ void getAsyncHeadersWithEmptyFormat () throws Exception {
173+ // given
174+ Method m = ClassWithHeaders .class .getDeclaredMethod ("withoutFormat" , String .class );
175+ AsyncOperation operation = m .getAnnotation (AsyncListener .class ).operation ();
176+
177+ // when
178+ SchemaObject headers = AsyncAnnotationUtil .getAsyncHeaders (operation , stringValueResolver );
179+
180+ // then
181+ SchemaObject headerProperty = (SchemaObject ) headers .getProperties ().get ("headerResolved" );
182+ assertThat (headerProperty .getFormat ()).isNull ();
183+ }
184+
150185 @ Test
151186 void generatedHeaderSchemaNameShouldBeUnique () throws Exception {
152187 // given
@@ -156,10 +191,6 @@ void generatedHeaderSchemaNameShouldBeUnique() throws Exception {
156191 Method m2 = ClassWithHeaders .class .getDeclaredMethod ("differentHeadersWithoutSchemaName" , String .class );
157192 AsyncOperation operation2 = m2 .getAnnotation (AsyncListener .class ).operation ();
158193
159- StringValueResolver stringValueResolver = mock (StringValueResolver .class );
160- when (stringValueResolver .resolveStringValue (any ()))
161- .thenAnswer (invocation -> invocation .getArgument (0 ).toString () + "Resolved" );
162-
163194 // when
164195 SchemaObject headers1 = AsyncAnnotationUtil .getAsyncHeaders (operation1 , stringValueResolver );
165196 SchemaObject headers2 = AsyncAnnotationUtil .getAsyncHeaders (operation2 , stringValueResolver );
@@ -286,8 +317,6 @@ void getServers() throws Exception {
286317 Method m = ClassWithOperationBindingProcessor .class .getDeclaredMethod ("methodWithAnnotation" , String .class );
287318 AsyncOperation operation = m .getAnnotation (AsyncListener .class ).operation ();
288319
289- StringValueResolver stringValueResolver = mock (StringValueResolver .class );
290-
291320 // when
292321 when (stringValueResolver .resolveStringValue ("${test.property.server1}" )).thenReturn ("server1" );
293322
@@ -351,7 +380,8 @@ private static class ClassWithOperationBindingProcessor {
351380 @ AsyncOperation .Headers .Header (
352381 name = "header" ,
353382 value = "value" ,
354- description = "description" ),
383+ description = "description" ,
384+ format = "int32" ),
355385 @ AsyncOperation .Headers .Header (
356386 name = "headerWithoutValue" ,
357387 description = "description" )
@@ -398,7 +428,8 @@ private static class ClassWithAbstractOperationBindingProcessor {
398428 @ AsyncOperation .Headers .Header (
399429 name = "header" ,
400430 value = "value" ,
401- description = "description" ),
431+ description = "description" ,
432+ format = "int32" ),
402433 @ AsyncOperation .Headers .Header (
403434 name = "headerWithoutValue" ,
404435 description = "description" )
@@ -465,6 +496,35 @@ private void withoutSchemaName(String payload) {}
465496 @ TestOperationBindingProcessor .TestOperationBinding ()
466497 private void withoutValue (String payload ) {}
467498
499+ @ AsyncListener (
500+ operation =
501+ @ AsyncOperation (
502+ channelName = "${test.property.test-channel}" ,
503+ headers =
504+ @ AsyncOperation .Headers (
505+ values = {
506+ @ AsyncOperation .Headers .Header (
507+ name = "header" ,
508+ description = "description" ,
509+ format = "int32" )
510+ })))
511+ @ TestOperationBindingProcessor .TestOperationBinding ()
512+ private void withFormat (String payload ) {}
513+
514+ @ AsyncListener (
515+ operation =
516+ @ AsyncOperation (
517+ channelName = "${test.property.test-channel}" ,
518+ headers =
519+ @ AsyncOperation .Headers (
520+ values = {
521+ @ AsyncOperation .Headers .Header (
522+ name = "header" ,
523+ description = "description" )
524+ })))
525+ @ TestOperationBindingProcessor .TestOperationBinding ()
526+ private void withoutFormat (String payload ) {}
527+
468528 @ AsyncListener (
469529 operation =
470530 @ AsyncOperation (
0 commit comments