99import java .io .IOException ;
1010import java .util .List ;
1111import java .util .Map ;
12+ import java .util .stream .Collectors ;
1213
1314public class ZDLJavaSignatureUtilsTest {
1415
@@ -46,11 +47,26 @@ void methodParameterType() throws IOException {
4647 void methodParametersSignature () throws IOException {
4748 var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl" );
4849 var method = JSONPath .get (model , "$.services.AttachmentService.methods.downloadAttachmentFile" , Map .of ());
49- var inputDTOSuffix = "InputDTO" ;
5050 var signature = ZDLJavaSignatureUtils .methodParametersSignature ("String" , method , model );
5151 Assertions .assertEquals ("String businessUnit, String orderId, String documentManagerId" , signature );
5252 }
5353
54+ @ Test
55+ void methodParametersSignatureWithId () throws IOException {
56+ var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/customer-address.zdl" );
57+ var method = JSONPath .get (model , "$.services.CustomerService.methods.updateCustomer" , Map .of ());
58+ var signature = ZDLJavaSignatureUtils .methodParametersSignature ("String" , method , model );
59+ Assertions .assertEquals ("String id, CustomerInput input" , signature );
60+ }
61+
62+ @ Test
63+ void methodParametersSignaturePageable () throws IOException {
64+ var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/customer-address.zdl" );
65+ var method = JSONPath .get (model , "$.services.CustomerService.methods.searchCustomers" , Map .of ());
66+ var signature = ZDLJavaSignatureUtils .methodParametersSignature ("String" , method , model );
67+ Assertions .assertEquals ("CustomerSearchCriteria input, Pageable pageable" , signature );
68+ }
69+
5470 @ Test
5571 void methodParametersSignatureWithNaturalIds () throws IOException {
5672 var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/natural-ids.zdl" );
@@ -120,15 +136,21 @@ void mapperInputCallSignatureInline() throws IOException {
120136 @ Test
121137 void mapperInputSignature () throws IOException {
122138 var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl" );
123- var inputDTOSuffix = "InputDTO" ;
124139 var signature = ZDLJavaSignatureUtils .mapperInputSignature ("AttachmentFileId" , model );
125140 Assertions .assertEquals ("String businessUnit, String orderId, String documentManagerId" , signature );
126141 }
127142
143+ @ Test
144+ void mapperInputAnnotations () throws IOException {
145+ var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl" );
146+ var annotations = ZDLJavaSignatureUtils .mapperInputAnnotations ("AttachmentFileId" , model );
147+ var str = annotations .stream ().map (a -> a .get ("source" ) + " = " + a .get ("target" )).collect (Collectors .joining (", " ));
148+ Assertions .assertEquals ("businessUnit = businessUnit, orderId = orderId, documentManagerId = documentManagerId" , str );
149+ }
150+
128151 @ Test
129152 void inputFieldInitializer () throws IOException {
130153 var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl" );
131- var inputDTOSuffix = "InputDTO" ;
132154 var signature = ZDLJavaSignatureUtils .inputFieldInitializer ("AttachmentFileId" , model );
133155 Assertions .assertEquals ("""
134156 String businessUnit = null;
@@ -141,7 +163,6 @@ void inputFieldInitializer() throws IOException {
141163 void methodInputCall () throws IOException {
142164 var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/order-faults-attachments-model.zdl" );
143165 var method = JSONPath .get (model , "$.services.AttachmentService.methods.downloadAttachmentFile" , Map .of ());
144- var inputDTOSuffix = "InputDTO" ;
145166 var signature = ZDLJavaSignatureUtils .methodInputCall (method , model );
146167 Assertions .assertEquals (List .of ("businessUnit" , "orderId" , "documentManagerId" ), signature );
147168 }
@@ -251,4 +272,101 @@ void relationshipFieldTypeInitializer() throws IOException {
251272 Assertions .assertEquals ("= new HashSet<>()" , fieldTypeInitializer );
252273 }
253274
275+ @ Test
276+ void naturalIdsKotlinRepoMethodSignature () throws IOException {
277+ var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/natural-ids.zdl" );
278+ var entity = JSONPath .get (model , "$.entities.Customer" , Map .of ());
279+ var signature = ZDLJavaSignatureUtils .naturalIdsKotlinRepoMethodSignature (entity );
280+ Assertions .assertEquals ("fun findByCustomerIdAndAnotherId(customerId: Long, anotherId: String): Customer?" , signature );
281+ }
282+
283+ @ Test
284+ void findServiceMethodMainParameter_withInlineComplexType () throws IOException {
285+ var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/customer-address.zdl" );
286+ var method = JSONPath .get (model , "$.services.CustomerService.methods.addCustomerAddress" , Map .<String , Object >of ());
287+ var result = ZDLJavaSignatureUtils .findServiceMethodMainParameter (method , model );
288+ Assertions .assertEquals ("Address" , result );
289+ }
290+
291+ @ Test
292+ void findServiceMethodMainParameter_withNullMethod () {
293+ var result = ZDLJavaSignatureUtils .findServiceMethodMainParameter (null , Map .of ());
294+ Assertions .assertNull (result );
295+ }
296+
297+ @ Test
298+ void findServiceMethodMainParameter_withNonExistentParameter () throws IOException {
299+ var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/natural-ids.zdl" );
300+ var method = Map .<String , Object >of ("parameter" , "NonExistentType" );
301+ var result = ZDLJavaSignatureUtils .findServiceMethodMainParameter (method , model );
302+ Assertions .assertNull (result );
303+ }
304+
305+ @ Test
306+ void fieldsParamsSignature_withNullFields () {
307+ var signature = ZDLJavaSignatureUtils .fieldsParamsSignature (null );
308+ Assertions .assertEquals ("" , signature );
309+ }
310+
311+ @ Test
312+ void fieldsParamsCallSignature_withNullFields () {
313+ var signature = ZDLJavaSignatureUtils .fieldsParamsCallSignature (null );
314+ Assertions .assertEquals ("" , signature );
315+ }
316+
317+ @ Test
318+ void toKotlinMethodSignature_withNullSignature () {
319+ var result = ZDLJavaSignatureUtils .toKotlinMethodSignature (null );
320+ Assertions .assertEquals ("" , result );
321+ }
322+
323+ @ Test
324+ void toKotlinMethodSignature_withEmptySignature () {
325+ var result = ZDLJavaSignatureUtils .toKotlinMethodSignature ("" );
326+ Assertions .assertEquals ("" , result );
327+ }
328+
329+ @ Test
330+ void javaType_withBlobTypes () {
331+ var blobField = Map .of ("type" , "Blob" );
332+ Assertions .assertEquals ("byte[]" , ZDLJavaSignatureUtils .javaType (blobField ));
333+
334+ var anyBlobField = Map .of ("type" , "AnyBlob" );
335+ Assertions .assertEquals ("byte[]" , ZDLJavaSignatureUtils .javaType (anyBlobField ));
336+
337+ var imageBlobField = Map .of ("type" , "ImageBlob" );
338+ Assertions .assertEquals ("byte[]" , ZDLJavaSignatureUtils .javaType (imageBlobField ));
339+
340+ var textBlobField = Map .of ("type" , "TextBlob" );
341+ Assertions .assertEquals ("String" , ZDLJavaSignatureUtils .javaType (textBlobField ));
342+ }
343+
344+ @ Test
345+ void methodParameterType_withPatchOption () throws IOException {
346+ var model = loadZDL ("classpath:io/zenwave360/sdk/resources/zdl/natural-ids.zdl" );
347+ var method = Map .of ("options" , Map .of ("patch" , true ), "parameter" , "Customer" );
348+ var result = ZDLJavaSignatureUtils .methodParameterType (method , model );
349+ Assertions .assertEquals ("java.util.Map" , result );
350+ }
351+
352+ @ Test
353+ void fieldType_withByteArray () {
354+ var field = Map .of ("type" , "byte" , "isArray" , true );
355+ var result = ZDLJavaSignatureUtils .fieldType (field , "" , "" );
356+ Assertions .assertEquals ("byte[]" , result );
357+ }
358+
359+ @ Test
360+ void fieldType_withMapType () {
361+ var field = Map .of ("type" , "Map" );
362+ var result = ZDLJavaSignatureUtils .fieldType (field , "" , "" );
363+ Assertions .assertEquals ("Map<String,Object>" , result );
364+ }
365+
366+ @ Test
367+ void fieldType_withPrefixAndSuffix () {
368+ var field = Map .of ("type" , "String" );
369+ var result = ZDLJavaSignatureUtils .fieldType (field , "Pre" , "Suf" );
370+ Assertions .assertEquals ("PreStringSuf" , result );
371+ }
254372}
0 commit comments