Bump dawidd6/action-send-mail from 3 to 4
[yosql.git] / yosql-codegen / src / test / java / wtf / metio / yosql / codegen / files / DefaultSqlConfigurationParserTest.java
bloba310a0b9385d1ab1212c772be90300daf4f3829c
1 /*
2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.yosql.codegen.files;
10 import org.junit.jupiter.api.BeforeEach;
11 import org.junit.jupiter.api.DisplayName;
12 import org.junit.jupiter.api.Test;
13 import wtf.metio.yosql.codegen.orchestration.OrchestrationObjectMother;
14 import wtf.metio.yosql.models.configuration.ReturningMode;
15 import wtf.metio.yosql.models.configuration.SqlStatementType;
17 import static org.junit.jupiter.api.Assertions.*;
19 @DisplayName("DefaultSqlConfigurationParser")
20 class DefaultSqlConfigurationParserTest {
22 private DefaultSqlConfigurationParser parser;
24 @BeforeEach
25 void setUp() {
26 parser = new DefaultSqlConfigurationParser(OrchestrationObjectMother.executionErrors());
29 @Test
30 void shouldParseRepository() {
31 final var yaml = """
32 repository: com.example.MyRepository
33 """;
34 final var config = parser.parseConfig(yaml);
35 assertTrue(config.repository().isPresent());
36 assertEquals("com.example.MyRepository", config.repository().get());
39 @Test
40 void shouldParseName() {
41 final var yaml = """
42 name: findItemByName
43 """;
44 final var config = parser.parseConfig(yaml);
45 assertTrue(config.name().isPresent());
46 assertEquals("findItemByName", config.name().get());
49 @Test
50 void shouldParseDescription() {
51 final var yaml = """
52 description: some descriptive message about this statement
53 """;
54 final var config = parser.parseConfig(yaml);
55 assertTrue(config.description().isPresent());
56 assertEquals("some descriptive message about this statement", config.description().get());
59 @Test
60 void shouldParseVendor() {
61 final var yaml = """
62 vendor: Postgres
63 """;
64 final var config = parser.parseConfig(yaml);
65 assertTrue(config.vendor().isPresent());
66 assertEquals("Postgres", config.vendor().get());
69 @Test
70 void shouldParseTypeReading() {
71 final var yaml = """
72 type: READING
73 """;
74 final var config = parser.parseConfig(yaml);
75 assertTrue(config.type().isPresent());
76 assertEquals(SqlStatementType.READING, config.type().get());
79 @Test
80 void shouldParseTypeWriting() {
81 final var yaml = """
82 type: WRITING
83 """;
84 final var config = parser.parseConfig(yaml);
85 assertTrue(config.type().isPresent());
86 assertEquals(SqlStatementType.WRITING, config.type().get());
89 @Test
90 void shouldParseTypeCalling() {
91 final var yaml = """
92 type: CALLING
93 """;
94 final var config = parser.parseConfig(yaml);
95 assertTrue(config.type().isPresent());
96 assertEquals(SqlStatementType.CALLING, config.type().get());
99 @Test
100 void shouldParseTypeReadingCaseInsensitive() {
101 final var yaml = """
102 type: reading
103 """;
104 final var config = parser.parseConfig(yaml);
105 assertTrue(config.type().isPresent());
106 assertEquals(SqlStatementType.READING, config.type().get());
109 @Test
110 void shouldParseTypeWritingCaseInsensitive() {
111 final var yaml = """
112 type: writing
113 """;
114 final var config = parser.parseConfig(yaml);
115 assertTrue(config.type().isPresent());
116 assertEquals(SqlStatementType.WRITING, config.type().get());
119 @Test
120 void shouldParseTypeCallingCaseInsensitive() {
121 final var yaml = """
122 type: calling
123 """;
124 final var config = parser.parseConfig(yaml);
125 assertTrue(config.type().isPresent());
126 assertEquals(SqlStatementType.CALLING, config.type().get());
129 @Test
130 void shouldParseReturningModeNone() {
131 final var yaml = """
132 returning: NONE
133 """;
134 final var config = parser.parseConfig(yaml);
135 assertTrue(config.returningMode().isPresent());
136 assertEquals(ReturningMode.NONE, config.returningMode().get());
139 @Test
140 void shouldParseReturningModeFirst() {
141 final var yaml = """
142 returning: SINGLE
143 """;
144 final var config = parser.parseConfig(yaml);
145 assertTrue(config.returningMode().isPresent());
146 assertEquals(ReturningMode.SINGLE, config.returningMode().get());
149 @Test
150 void shouldParseReturningModeList() {
151 final var yaml = """
152 returning: MULTIPLE
153 """;
154 final var config = parser.parseConfig(yaml);
155 assertTrue(config.returningMode().isPresent());
156 assertEquals(ReturningMode.MULTIPLE, config.returningMode().get());
159 @Test
160 void shouldParseReturningModeNoneCaseInsensitive() {
161 final var yaml = """
162 returning: none
163 """;
164 final var config = parser.parseConfig(yaml);
165 assertTrue(config.returningMode().isPresent());
166 assertEquals(ReturningMode.NONE, config.returningMode().get());
169 @Test
170 void shouldParseReturningModeFirstCaseInsensitive() {
171 final var yaml = """
172 returning: single
173 """;
174 final var config = parser.parseConfig(yaml);
175 assertTrue(config.returningMode().isPresent());
176 assertEquals(ReturningMode.SINGLE, config.returningMode().get());
179 @Test
180 void shouldParseReturningModeListCaseInsensitive() {
181 final var yaml = """
182 returning: multiple
183 """;
184 final var config = parser.parseConfig(yaml);
185 assertTrue(config.returningMode().isPresent());
186 assertEquals(ReturningMode.MULTIPLE, config.returningMode().get());
189 @Test
190 void shouldParseExecuteOnceEnabled() {
191 final var yaml = """
192 executeOnce: true
193 """;
194 final var config = parser.parseConfig(yaml);
195 assertTrue(config.executeOnce().isPresent());
196 assertTrue(config.executeOnce().get());
199 @Test
200 void shouldParseExecuteOnceDisabled() {
201 final var yaml = """
202 executeOnce: false
203 """;
204 final var config = parser.parseConfig(yaml);
205 assertTrue(config.executeOnce().isPresent());
206 assertFalse(config.executeOnce().get());
209 @Test
210 void shouldParseExecuteBatchEnabled() {
211 final var yaml = """
212 executeBatch: true
213 """;
214 final var config = parser.parseConfig(yaml);
215 assertTrue(config.executeBatch().isPresent());
216 assertTrue(config.executeBatch().get());
219 @Test
220 void shouldParseExecuteBatchDisabled() {
221 final var yaml = """
222 executeBatch: false
223 """;
224 final var config = parser.parseConfig(yaml);
225 assertTrue(config.executeBatch().isPresent());
226 assertFalse(config.executeBatch().get());
229 @Test
230 void shouldParseCatchAndRethrowEnabled() {
231 final var yaml = """
232 catchAndRethrow: true
233 """;
234 final var config = parser.parseConfig(yaml);
235 assertTrue(config.catchAndRethrow().isPresent());
236 assertTrue(config.catchAndRethrow().get());
239 @Test
240 void shouldParseCatchAndRethrowDisabled() {
241 final var yaml = """
242 catchAndRethrow: false
243 """;
244 final var config = parser.parseConfig(yaml);
245 assertTrue(config.catchAndRethrow().isPresent());
246 assertFalse(config.catchAndRethrow().get());
249 @Test
250 void shouldParseThrowOnMultipleResultEnabled() {
251 final var yaml = """
252 throwOnMultipleResults: true
253 """;
254 final var config = parser.parseConfig(yaml);
255 assertTrue(config.throwOnMultipleResults().isPresent());
256 assertTrue(config.throwOnMultipleResults().get());
259 @Test
260 void shouldParseThrowOnMultipleResultsDisabled() {
261 final var yaml = """
262 throwOnMultipleResults: false
263 """;
264 final var config = parser.parseConfig(yaml);
265 assertTrue(config.throwOnMultipleResults().isPresent());
266 assertFalse(config.throwOnMultipleResults().get());
269 @Test
270 void shouldParseWritesReturnUpdateCountEnabled() {
271 final var yaml = """
272 writesReturnUpdateCount: true
273 """;
274 final var config = parser.parseConfig(yaml);
275 assertTrue(config.writesReturnUpdateCount().isPresent());
276 assertTrue(config.writesReturnUpdateCount().get());
279 @Test
280 void shouldParseWritesReturnUpdateCountDisabled() {
281 final var yaml = """
282 writesReturnUpdateCount: false
283 """;
284 final var config = parser.parseConfig(yaml);
285 assertTrue(config.writesReturnUpdateCount().isPresent());
286 assertFalse(config.writesReturnUpdateCount().get());
289 @Test
290 void shouldParseCreateConnectionEnabled() {
291 final var yaml = """
292 createConnection: true
293 """;
294 final var config = parser.parseConfig(yaml);
295 assertTrue(config.createConnection().isPresent());
296 assertTrue(config.createConnection().get());
299 @Test
300 void shouldParseCreateConnectionDisabled() {
301 final var yaml = """
302 createConnection: false
303 """;
304 final var config = parser.parseConfig(yaml);
305 assertTrue(config.createConnection().isPresent());
306 assertFalse(config.createConnection().get());
309 @Test
310 void shouldParseUsePreparedStatementEnabled() {
311 final var yaml = """
312 usePreparedStatement: true
313 """;
314 final var config = parser.parseConfig(yaml);
315 assertTrue(config.usePreparedStatement().isPresent());
316 assertTrue(config.usePreparedStatement().get());
319 @Test
320 void shouldParseUsePreparedStatementDisabled() {
321 final var yaml = """
322 usePreparedStatement: false
323 """;
324 final var config = parser.parseConfig(yaml);
325 assertTrue(config.usePreparedStatement().isPresent());
326 assertFalse(config.usePreparedStatement().get());
329 @Test
330 void shouldParseExecuteOncePrefix() {
331 final var yaml = """
332 executeOncePrefix: prefix
333 """;
334 final var config = parser.parseConfig(yaml);
335 assertTrue(config.executeOncePrefix().isPresent());
336 assertEquals("prefix", config.executeOncePrefix().get());
339 @Test
340 void shouldParseExecuteOnceSuffix() {
341 final var yaml = """
342 executeOnceSuffix: suffix
343 """;
344 final var config = parser.parseConfig(yaml);
345 assertTrue(config.executeOnceSuffix().isPresent());
346 assertEquals("suffix", config.executeOnceSuffix().get());
349 @Test
350 void shouldParseExecuteBatchPrefix() {
351 final var yaml = """
352 executeBatchPrefix: prefix
353 """;
354 final var config = parser.parseConfig(yaml);
355 assertTrue(config.executeBatchPrefix().isPresent());
356 assertEquals("prefix", config.executeBatchPrefix().get());
359 @Test
360 void shouldParseExecuteBatchSuffix() {
361 final var yaml = """
362 executeBatchSuffix: suffix
363 """;
364 final var config = parser.parseConfig(yaml);
365 assertTrue(config.executeBatchSuffix().isPresent());
366 assertEquals("suffix", config.executeBatchSuffix().get());
369 @Test
370 void shouldParseParameter() {
371 final var yaml = """
372 parameters:
373 - name: name
374 type: java.lang.String
375 """;
376 final var config = parser.parseConfig(yaml);
377 assertEquals(1, config.parameters().size());
378 assertAll(
379 () -> assertEquals("name", config.parameters().get(0).name().get()),
380 () -> assertEquals("java.lang.String", config.parameters().get(0).type().get()));
383 @Test
384 void shouldParseParameters() {
385 final var yaml = """
386 parameters:
387 - name: string
388 type: java.lang.String
389 - name: bool
390 type: boolean
391 - name: number
392 type: int
393 """;
394 final var config = parser.parseConfig(yaml);
395 assertEquals(3, config.parameters().size());
396 assertAll(
397 () -> assertEquals("string", config.parameters().get(0).name().get()),
398 () -> assertEquals("java.lang.String", config.parameters().get(0).type().get()),
399 () -> assertEquals("bool", config.parameters().get(1).name().get()),
400 () -> assertEquals("boolean", config.parameters().get(1).type().get()),
401 () -> assertEquals("number", config.parameters().get(2).name().get()),
402 () -> assertEquals("int", config.parameters().get(2).type().get()));
405 @Test
406 void shouldParseResultRowConverterAlias() {
407 final var yaml = """
408 resultRowConverter:
409 alias: converterAlias
410 """;
411 final var config = parser.parseConfig(yaml);
412 assertTrue(config.resultRowConverter().isPresent());
413 assertAll(
414 () -> assertEquals("converterAlias", config.resultRowConverter().get().alias().get()),
415 () -> assertTrue(config.resultRowConverter().get().methodName().isEmpty()),
416 () -> assertTrue(config.resultRowConverter().get().converterType().isEmpty()),
417 () -> assertTrue(config.resultRowConverter().get().resultType().isEmpty()));
420 @Test
421 void shouldParseResultRowConverterMethodName() {
422 final var yaml = """
423 resultRowConverter:
424 methodName: someMethod
425 """;
426 final var config = parser.parseConfig(yaml);
427 assertTrue(config.resultRowConverter().isPresent());
428 assertAll(
429 () -> assertTrue(config.resultRowConverter().get().alias().isEmpty()),
430 () -> assertEquals("someMethod", config.resultRowConverter().get().methodName().get()),
431 () -> assertTrue(config.resultRowConverter().get().converterType().isEmpty()),
432 () -> assertTrue(config.resultRowConverter().get().resultType().isEmpty()));
435 @Test
436 void shouldParseResultRowConverterConverterType() {
437 final var yaml = """
438 resultRowConverter:
439 converterType: com.example.MyConverter
440 """;
441 final var config = parser.parseConfig(yaml);
442 assertTrue(config.resultRowConverter().isPresent());
443 assertAll(
444 () -> assertTrue(config.resultRowConverter().get().alias().isEmpty()),
445 () -> assertTrue(config.resultRowConverter().get().methodName().isEmpty()),
446 () -> assertEquals("com.example.MyConverter", config.resultRowConverter().get().converterType().get()),
447 () -> assertTrue(config.resultRowConverter().get().resultType().isEmpty()));
450 @Test
451 void shouldParseResultRowConverterResultType() {
452 final var yaml = """
453 resultRowConverter:
454 resultType: com.example.MyResult
455 """;
456 final var config = parser.parseConfig(yaml);
457 assertTrue(config.resultRowConverter().isPresent());
458 assertAll(
459 () -> assertTrue(config.resultRowConverter().get().alias().isEmpty()),
460 () -> assertTrue(config.resultRowConverter().get().methodName().isEmpty()),
461 () -> assertTrue(config.resultRowConverter().get().converterType().isEmpty()),
462 () -> assertEquals("com.example.MyResult", config.resultRowConverter().get().resultType().get()));
465 @Test
466 void shouldParseResultRowConverter() {
467 final var yaml = """
468 resultRowConverter:
469 alias: converterAlias
470 methodName: someMethod
471 converterType: com.example.MyConverter
472 resultType: com.example.MyResult
473 """;
474 final var config = parser.parseConfig(yaml);
475 assertTrue(config.resultRowConverter().isPresent());
476 assertAll(
477 () -> assertEquals("converterAlias", config.resultRowConverter().get().alias().get()),
478 () -> assertEquals("someMethod", config.resultRowConverter().get().methodName().get()),
479 () -> assertEquals("com.example.MyConverter", config.resultRowConverter().get().converterType().get()),
480 () -> assertEquals("com.example.MyResult", config.resultRowConverter().get().resultType().get()));
483 @Test
484 void shouldParseAnnotation() {
485 final var yaml = """
486 annotations:
487 - type: com.example.MyAnnotation
488 members:
489 - key: some
490 value: here
491 type: java.lang.String
492 """;
493 final var config = parser.parseConfig(yaml);
494 assertFalse(config.annotations().isEmpty());
495 assertAll("annotation",
496 () -> assertEquals("com.example.MyAnnotation", config.annotations().get(0).type()),
497 () -> assertAll("members",
498 () -> assertFalse(config.annotations().get(0).members().isEmpty()),
499 () -> assertEquals("some", config.annotations().get(0).members().get(0).key()),
500 () -> assertEquals("here", config.annotations().get(0).members().get(0).value()),
501 () -> assertEquals("java.lang.String", config.annotations().get(0).members().get(0).type())));
504 @Test
505 void shouldParseAnnotations() {
506 final var yaml = """
507 annotations:
508 - type: com.example.MyAnnotation
509 members:
510 - key: some
511 value: here
512 type: java.lang.String
513 - type: com.example.OtherAnnotation
514 members:
515 - key: another
516 value: 12345
517 type: int
518 """;
519 final var config = parser.parseConfig(yaml);
520 assertFalse(config.annotations().isEmpty());
521 assertAll("annotation",
522 () -> assertEquals("com.example.MyAnnotation", config.annotations().get(0).type()),
523 () -> assertEquals("com.example.OtherAnnotation", config.annotations().get(1).type()),
524 () -> assertAll("members",
525 () -> assertFalse(config.annotations().get(0).members().isEmpty()),
526 () -> assertEquals("some", config.annotations().get(0).members().get(0).key()),
527 () -> assertEquals("here", config.annotations().get(0).members().get(0).value()),
528 () -> assertEquals("java.lang.String", config.annotations().get(0).members().get(0).type()),
529 () -> assertEquals("another", config.annotations().get(1).members().get(0).key()),
530 () -> assertEquals("12345", config.annotations().get(1).members().get(0).value()),
531 () -> assertEquals("int", config.annotations().get(1).members().get(0).type())));
534 @Test
535 void shouldParseAnnotationMembers() {
536 final var yaml = """
537 annotations:
538 - type: com.example.MyAnnotation
539 members:
540 - key: some
541 value: here
542 type: java.lang.String
543 - key: another
544 value: 12345
545 type: int
546 """;
547 final var config = parser.parseConfig(yaml);
548 assertFalse(config.annotations().isEmpty());
549 assertAll("annotation",
550 () -> assertEquals("com.example.MyAnnotation", config.annotations().get(0).type()),
551 () -> assertAll("members",
552 () -> assertFalse(config.annotations().get(0).members().isEmpty()),
553 () -> assertEquals("some", config.annotations().get(0).members().get(0).key()),
554 () -> assertEquals("here", config.annotations().get(0).members().get(0).value()),
555 () -> assertEquals("java.lang.String", config.annotations().get(0).members().get(0).type()),
556 () -> assertEquals("another", config.annotations().get(0).members().get(1).key()),
557 () -> assertEquals("12345", config.annotations().get(0).members().get(1).value()),
558 () -> assertEquals("int", config.annotations().get(0).members().get(1).type())));