Skip to content

Commit 2d16ba2

Browse files
committed
tests: improve coverage
1 parent 75bc742 commit 2d16ba2

File tree

3 files changed

+341
-0
lines changed

3 files changed

+341
-0
lines changed

zenwave-sdk-cli/src/test/java/io/zenwave360/sdk/zdl/utils/ZDLHttpUtilsTest.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,33 @@ void testFindMethodParams() throws IOException {
3838
Assertions.assertEquals("CustomerInputDTO", parameters.get(1).getKey());
3939
}
4040

41+
@Test
42+
void testFindMethodParamsMultipart() throws IOException {
43+
var model = loadOpenAPI("classpath:io/zenwave360/sdk/resources/openapi/documents-openapi.yml");
44+
var operation = (Map) JSONPath.get(model, "$.paths./documents/upload.post");
45+
46+
var parameters = ZDLHttpUtils.methodParameters(operation, "", "DTO");
47+
Assertions.assertNotNull(parameters);
48+
Assertions.assertEquals(9, parameters.size());
49+
Assertions.assertEquals("org.springframework.web.multipart.MultipartFile", parameters.get(0).getKey());
50+
Assertions.assertEquals("file", parameters.get(0).getValue());
51+
Assertions.assertEquals("Long", parameters.get(1).getKey());
52+
Assertions.assertEquals("id", parameters.get(1).getValue());
53+
}
54+
55+
@Test
56+
void testFindMethodParamsPatch() throws IOException {
57+
var model = loadOpenAPI("classpath:io/zenwave360/sdk/resources/openapi/openapi-petstore.yml");
58+
var operation = (Map) JSONPath.get(model, "$.paths./pet.patch");
59+
60+
var parameters = ZDLHttpUtils.methodParameters(operation, "", "DTO");
61+
Assertions.assertNotNull(parameters);
62+
Assertions.assertEquals(1, parameters.size());
63+
Assertions.assertEquals("Map", parameters.get(0).getKey());
64+
Assertions.assertEquals("input", parameters.get(0).getValue());
65+
}
66+
67+
4168
@Test
4269
void testFindPathParams() throws IOException {
4370
var model = loadZDL("classpath:io/zenwave360/sdk/resources/zdl/customer-address.zdl");
@@ -98,4 +125,48 @@ void getRequestBodyTypeInline() throws IOException {
98125
Assertions.assertEquals("Address", pathParam);
99126
}
100127

128+
@Test
129+
void testGetJavaType() {
130+
// Test binary format
131+
Map binaryParam = Map.of("schema", Map.of("type", "string", "format", "binary"));
132+
Assertions.assertEquals("org.springframework.web.multipart.MultipartFile",
133+
ZDLHttpUtils.getJavaType(binaryParam, "", ""));
134+
135+
// Test date format
136+
Map dateParam = Map.of("schema", Map.of("type", "string", "format", "date"));
137+
Assertions.assertEquals("LocalDate", ZDLHttpUtils.getJavaType(dateParam, "", ""));
138+
139+
// Test date-time format
140+
Map dateTimeParam = Map.of("schema", Map.of("type", "string", "format", "date-time"));
141+
Assertions.assertEquals("Instant", ZDLHttpUtils.getJavaType(dateTimeParam, "", ""));
142+
143+
// Test integer with int64 format
144+
Map longParam = Map.of("schema", Map.of("type", "integer", "format", "int64"));
145+
Assertions.assertEquals("Long", ZDLHttpUtils.getJavaType(longParam, "", ""));
146+
147+
// Test integer without format
148+
Map intParam = Map.of("schema", Map.of("type", "integer"));
149+
Assertions.assertEquals("Integer", ZDLHttpUtils.getJavaType(intParam, "", ""));
150+
151+
// Test number type
152+
Map numberParam = Map.of("schema", Map.of("type", "number"));
153+
Assertions.assertEquals("BigDecimal", ZDLHttpUtils.getJavaType(numberParam, "", ""));
154+
155+
// Test boolean type
156+
Map booleanParam = Map.of("schema", Map.of("type", "boolean"));
157+
Assertions.assertEquals("Boolean", ZDLHttpUtils.getJavaType(booleanParam, "", ""));
158+
159+
// Test array type
160+
Map arrayParam = Map.of("schema", Map.of("type", "array", "items", Map.of("type", "string")));
161+
Assertions.assertEquals("List<String>", ZDLHttpUtils.getJavaType(arrayParam, "", ""));
162+
163+
// Test schema name with prefixes/suffixes
164+
Map schemaParam = Map.of("schema", Map.of("x--schema-name", "Customer"));
165+
Assertions.assertEquals("CustomerDTO", ZDLHttpUtils.getJavaType(schemaParam, "", "DTO"));
166+
167+
// Test default string type
168+
Map stringParam = Map.of("schema", Map.of("type", "string"));
169+
Assertions.assertEquals("String", ZDLHttpUtils.getJavaType(stringParam, "", ""));
170+
}
171+
101172
}
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
openapi: 3.0.1
2+
info:
3+
title: "Documents API"
4+
version: 0.0.1
5+
description: "Documents API"
6+
contact:
7+
email: email@domain.com
8+
servers:
9+
- description: localhost
10+
url: http://localhost:8080/api
11+
- description: custom
12+
url: "{protocol}://{server}/{path}"
13+
variables:
14+
protocol:
15+
enum: ['http', 'https']
16+
default: 'http'
17+
server:
18+
default: 'localhost:8080'
19+
path:
20+
default: 'api'
21+
tags:
22+
- name: "Default"
23+
- name: "Document"
24+
25+
26+
paths:
27+
/documents/:
28+
get:
29+
operationId: listDocumentInfo
30+
description: "listDocumentInfo"
31+
tags: [Document]
32+
parameters:
33+
- name: "documentIds"
34+
in: query
35+
schema:
36+
type: integer
37+
format: int64
38+
responses:
39+
"200":
40+
description: "OK"
41+
content:
42+
application/json:
43+
schema:
44+
$ref: "#/components/schemas/DocumentInfoList"
45+
/documents/{id}:
46+
get:
47+
operationId: downloadDocument
48+
description: "downloadDocument"
49+
tags: [Document]
50+
parameters:
51+
- name: "id"
52+
in: path
53+
required: true
54+
schema:
55+
type: integer
56+
format: int64
57+
- name: "preview"
58+
in: query
59+
schema:
60+
type: boolean
61+
responses:
62+
"200":
63+
description: "OK"
64+
headers:
65+
Content-Disposition:
66+
description: "Controls file download behavior. Values: 'inline' (display in browser) or 'attachment; filename=example.pdf' (download file)"
67+
schema:
68+
type: string
69+
content:
70+
'*/*':
71+
schema:
72+
type: string
73+
format: binary
74+
delete:
75+
operationId: deleteDocumentInfo
76+
description: "deleteDocumentInfo"
77+
tags: [Document]
78+
parameters:
79+
- name: "id"
80+
in: path
81+
required: true
82+
schema:
83+
type: integer
84+
format: int64
85+
responses:
86+
"204":
87+
description: "OK"
88+
/documents/upload:
89+
post:
90+
operationId: uploadDocument
91+
description: "uploadDocument"
92+
tags: [Document]
93+
requestBody:
94+
required: true
95+
content:
96+
multipart/form-data:
97+
schema:
98+
allOf:
99+
- type: object
100+
properties:
101+
file:
102+
type: string
103+
format: binary
104+
- $ref: "#/components/schemas/DocumentInfo"
105+
106+
responses:
107+
"201":
108+
description: "OK"
109+
content:
110+
application/json:
111+
schema:
112+
$ref: "#/components/schemas/DocumentInfo"
113+
114+
components:
115+
schemas:
116+
DocumentInfo:
117+
type: "object"
118+
x-business-entity: "DocumentInfo"
119+
required:
120+
- "fileName"
121+
- "documentType"
122+
- "contentType"
123+
properties:
124+
id:
125+
type: "integer"
126+
format: "int64"
127+
readOnly: true
128+
version:
129+
type: "integer"
130+
default: "null"
131+
description: "Version of the document (required in PUT for concurrency control,\
132+
\ should be null in POSTs)."
133+
uuid:
134+
type: "string"
135+
fileName:
136+
type: "string"
137+
documentType:
138+
type: "string"
139+
contentType:
140+
type: "string"
141+
tags:
142+
type: "array"
143+
items:
144+
type: "string"
145+
documentData:
146+
$ref: "#/components/schemas/DocumentData"
147+
DocumentInfoList:
148+
type: "array"
149+
items:
150+
$ref: "#/components/schemas/DocumentInfo"
151+
DocumentData:
152+
type: "object"
153+
x-business-entity: "DocumentData"
154+
required:
155+
- "data"
156+
properties:
157+
id:
158+
type: "integer"
159+
format: "int64"
160+
readOnly: true
161+
version:
162+
type: "integer"
163+
default: "null"
164+
description: "Version of the document (required in PUT for concurrency control,\
165+
\ should be null in POSTs)."
166+
data:
167+
type: "string"
168+
format: "binary"
169+
170+
Page:
171+
type: object
172+
required:
173+
- "content"
174+
- "totalElements"
175+
- "totalPages"
176+
- "size"
177+
- "number"
178+
properties:
179+
number:
180+
type: integer
181+
minimum: 0
182+
numberOfElements:
183+
type: integer
184+
minimum: 0
185+
size:
186+
type: integer
187+
minimum: 0
188+
maximum: 200
189+
multipleOf: 25
190+
totalElements:
191+
type: integer
192+
totalPages:
193+
type: integer
194+
195+
parameters:
196+
page:
197+
name: page
198+
in: query
199+
description: The number of results page
200+
schema:
201+
type: integer
202+
format: int32
203+
default: 0
204+
limit:
205+
name: limit
206+
in: query
207+
description: The number of results in a single page
208+
schema:
209+
type: integer
210+
format: int32
211+
default: 20
212+
sort:
213+
name: sort
214+
in: query
215+
description: The number of results page
216+
schema:
217+
type: array
218+
items:
219+
type: string
220+
221+
securitySchemes:
222+
basicAuth: # <-- arbitrary name for the security scheme
223+
type: http
224+
scheme: basic
225+
bearerAuth: # <-- arbitrary name for the security scheme
226+
type: http
227+
scheme: bearer
228+
bearerFormat: JWT # optional, arbitrary value for documentation purposes
229+
security:
230+
- basicAuth: [] # <-- use the same name here
231+
- bearerAuth: [] # <-- use the same name here

zenwave-sdk-test-resources/src/main/resources/io/zenwave360/sdk/resources/openapi/openapi-petstore.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,45 @@ paths:
114114
- petstore_auth:
115115
- write:pets
116116
- read:pets
117+
patch:
118+
tags:
119+
- pet
120+
summary: Partial Update an existing pet
121+
description: Partial Update an existing pet by Id
122+
operationId: patchPet
123+
requestBody:
124+
description: Update an existent pet in the store
125+
content:
126+
application/json:
127+
schema:
128+
"$ref": "#/components/schemas/Pet"
129+
application/xml:
130+
schema:
131+
"$ref": "#/components/schemas/Pet"
132+
application/x-www-form-urlencoded:
133+
schema:
134+
"$ref": "#/components/schemas/Pet"
135+
required: true
136+
responses:
137+
200:
138+
description: Successful operation
139+
content:
140+
application/xml:
141+
schema:
142+
"$ref": "#/components/schemas/Pet"
143+
application/json:
144+
schema:
145+
"$ref": "#/components/schemas/Pet"
146+
'400':
147+
description: Invalid ID supplied
148+
'404':
149+
description: Pet not found
150+
'405':
151+
description: Validation exception
152+
security:
153+
- petstore_auth:
154+
- write:pets
155+
- read:pets
117156
"/pet/findByStatus":
118157
get:
119158
tags:

0 commit comments

Comments
 (0)