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
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
;
26 parser
= new DefaultSqlConfigurationParser(OrchestrationObjectMother
.executionErrors());
30 void shouldParseRepository() {
32 repository: com.example.MyRepository
34 final var config
= parser
.parseConfig(yaml
);
35 assertTrue(config
.repository().isPresent());
36 assertEquals("com.example.MyRepository", config
.repository().get());
40 void shouldParseName() {
44 final var config
= parser
.parseConfig(yaml
);
45 assertTrue(config
.name().isPresent());
46 assertEquals("findItemByName", config
.name().get());
50 void shouldParseDescription() {
52 description: some descriptive message about this statement
54 final var config
= parser
.parseConfig(yaml
);
55 assertTrue(config
.description().isPresent());
56 assertEquals("some descriptive message about this statement", config
.description().get());
60 void shouldParseVendor() {
64 final var config
= parser
.parseConfig(yaml
);
65 assertTrue(config
.vendor().isPresent());
66 assertEquals("Postgres", config
.vendor().get());
70 void shouldParseTypeReading() {
74 final var config
= parser
.parseConfig(yaml
);
75 assertTrue(config
.type().isPresent());
76 assertEquals(SqlStatementType
.READING
, config
.type().get());
80 void shouldParseTypeWriting() {
84 final var config
= parser
.parseConfig(yaml
);
85 assertTrue(config
.type().isPresent());
86 assertEquals(SqlStatementType
.WRITING
, config
.type().get());
90 void shouldParseTypeCalling() {
94 final var config
= parser
.parseConfig(yaml
);
95 assertTrue(config
.type().isPresent());
96 assertEquals(SqlStatementType
.CALLING
, config
.type().get());
100 void shouldParseTypeReadingCaseInsensitive() {
104 final var config
= parser
.parseConfig(yaml
);
105 assertTrue(config
.type().isPresent());
106 assertEquals(SqlStatementType
.READING
, config
.type().get());
110 void shouldParseTypeWritingCaseInsensitive() {
114 final var config
= parser
.parseConfig(yaml
);
115 assertTrue(config
.type().isPresent());
116 assertEquals(SqlStatementType
.WRITING
, config
.type().get());
120 void shouldParseTypeCallingCaseInsensitive() {
124 final var config
= parser
.parseConfig(yaml
);
125 assertTrue(config
.type().isPresent());
126 assertEquals(SqlStatementType
.CALLING
, config
.type().get());
130 void shouldParseReturningModeNone() {
134 final var config
= parser
.parseConfig(yaml
);
135 assertTrue(config
.returningMode().isPresent());
136 assertEquals(ReturningMode
.NONE
, config
.returningMode().get());
140 void shouldParseReturningModeFirst() {
144 final var config
= parser
.parseConfig(yaml
);
145 assertTrue(config
.returningMode().isPresent());
146 assertEquals(ReturningMode
.SINGLE
, config
.returningMode().get());
150 void shouldParseReturningModeList() {
154 final var config
= parser
.parseConfig(yaml
);
155 assertTrue(config
.returningMode().isPresent());
156 assertEquals(ReturningMode
.MULTIPLE
, config
.returningMode().get());
160 void shouldParseReturningModeNoneCaseInsensitive() {
164 final var config
= parser
.parseConfig(yaml
);
165 assertTrue(config
.returningMode().isPresent());
166 assertEquals(ReturningMode
.NONE
, config
.returningMode().get());
170 void shouldParseReturningModeFirstCaseInsensitive() {
174 final var config
= parser
.parseConfig(yaml
);
175 assertTrue(config
.returningMode().isPresent());
176 assertEquals(ReturningMode
.SINGLE
, config
.returningMode().get());
180 void shouldParseReturningModeListCaseInsensitive() {
184 final var config
= parser
.parseConfig(yaml
);
185 assertTrue(config
.returningMode().isPresent());
186 assertEquals(ReturningMode
.MULTIPLE
, config
.returningMode().get());
190 void shouldParseExecuteOnceEnabled() {
194 final var config
= parser
.parseConfig(yaml
);
195 assertTrue(config
.executeOnce().isPresent());
196 assertTrue(config
.executeOnce().get());
200 void shouldParseExecuteOnceDisabled() {
204 final var config
= parser
.parseConfig(yaml
);
205 assertTrue(config
.executeOnce().isPresent());
206 assertFalse(config
.executeOnce().get());
210 void shouldParseExecuteBatchEnabled() {
214 final var config
= parser
.parseConfig(yaml
);
215 assertTrue(config
.executeBatch().isPresent());
216 assertTrue(config
.executeBatch().get());
220 void shouldParseExecuteBatchDisabled() {
224 final var config
= parser
.parseConfig(yaml
);
225 assertTrue(config
.executeBatch().isPresent());
226 assertFalse(config
.executeBatch().get());
230 void shouldParseCatchAndRethrowEnabled() {
232 catchAndRethrow: true
234 final var config
= parser
.parseConfig(yaml
);
235 assertTrue(config
.catchAndRethrow().isPresent());
236 assertTrue(config
.catchAndRethrow().get());
240 void shouldParseCatchAndRethrowDisabled() {
242 catchAndRethrow: false
244 final var config
= parser
.parseConfig(yaml
);
245 assertTrue(config
.catchAndRethrow().isPresent());
246 assertFalse(config
.catchAndRethrow().get());
250 void shouldParseThrowOnMultipleResultEnabled() {
252 throwOnMultipleResults: true
254 final var config
= parser
.parseConfig(yaml
);
255 assertTrue(config
.throwOnMultipleResults().isPresent());
256 assertTrue(config
.throwOnMultipleResults().get());
260 void shouldParseThrowOnMultipleResultsDisabled() {
262 throwOnMultipleResults: false
264 final var config
= parser
.parseConfig(yaml
);
265 assertTrue(config
.throwOnMultipleResults().isPresent());
266 assertFalse(config
.throwOnMultipleResults().get());
270 void shouldParseWritesReturnUpdateCountEnabled() {
272 writesReturnUpdateCount: true
274 final var config
= parser
.parseConfig(yaml
);
275 assertTrue(config
.writesReturnUpdateCount().isPresent());
276 assertTrue(config
.writesReturnUpdateCount().get());
280 void shouldParseWritesReturnUpdateCountDisabled() {
282 writesReturnUpdateCount: false
284 final var config
= parser
.parseConfig(yaml
);
285 assertTrue(config
.writesReturnUpdateCount().isPresent());
286 assertFalse(config
.writesReturnUpdateCount().get());
290 void shouldParseCreateConnectionEnabled() {
292 createConnection: true
294 final var config
= parser
.parseConfig(yaml
);
295 assertTrue(config
.createConnection().isPresent());
296 assertTrue(config
.createConnection().get());
300 void shouldParseCreateConnectionDisabled() {
302 createConnection: false
304 final var config
= parser
.parseConfig(yaml
);
305 assertTrue(config
.createConnection().isPresent());
306 assertFalse(config
.createConnection().get());
310 void shouldParseUsePreparedStatementEnabled() {
312 usePreparedStatement: true
314 final var config
= parser
.parseConfig(yaml
);
315 assertTrue(config
.usePreparedStatement().isPresent());
316 assertTrue(config
.usePreparedStatement().get());
320 void shouldParseUsePreparedStatementDisabled() {
322 usePreparedStatement: false
324 final var config
= parser
.parseConfig(yaml
);
325 assertTrue(config
.usePreparedStatement().isPresent());
326 assertFalse(config
.usePreparedStatement().get());
330 void shouldParseExecuteOncePrefix() {
332 executeOncePrefix: prefix
334 final var config
= parser
.parseConfig(yaml
);
335 assertTrue(config
.executeOncePrefix().isPresent());
336 assertEquals("prefix", config
.executeOncePrefix().get());
340 void shouldParseExecuteOnceSuffix() {
342 executeOnceSuffix: suffix
344 final var config
= parser
.parseConfig(yaml
);
345 assertTrue(config
.executeOnceSuffix().isPresent());
346 assertEquals("suffix", config
.executeOnceSuffix().get());
350 void shouldParseExecuteBatchPrefix() {
352 executeBatchPrefix: prefix
354 final var config
= parser
.parseConfig(yaml
);
355 assertTrue(config
.executeBatchPrefix().isPresent());
356 assertEquals("prefix", config
.executeBatchPrefix().get());
360 void shouldParseExecuteBatchSuffix() {
362 executeBatchSuffix: suffix
364 final var config
= parser
.parseConfig(yaml
);
365 assertTrue(config
.executeBatchSuffix().isPresent());
366 assertEquals("suffix", config
.executeBatchSuffix().get());
370 void shouldParseParameter() {
374 type: java.lang.String
376 final var config
= parser
.parseConfig(yaml
);
377 assertEquals(1, config
.parameters().size());
379 () -> assertEquals("name", config
.parameters().get(0).name().get()),
380 () -> assertEquals("java.lang.String", config
.parameters().get(0).type().get()));
384 void shouldParseParameters() {
388 type: java.lang.String
394 final var config
= parser
.parseConfig(yaml
);
395 assertEquals(3, config
.parameters().size());
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()));
406 void shouldParseResultRowConverterAlias() {
409 alias: converterAlias
411 final var config
= parser
.parseConfig(yaml
);
412 assertTrue(config
.resultRowConverter().isPresent());
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()));
421 void shouldParseResultRowConverterMethodName() {
424 methodName: someMethod
426 final var config
= parser
.parseConfig(yaml
);
427 assertTrue(config
.resultRowConverter().isPresent());
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()));
436 void shouldParseResultRowConverterConverterType() {
439 converterType: com.example.MyConverter
441 final var config
= parser
.parseConfig(yaml
);
442 assertTrue(config
.resultRowConverter().isPresent());
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()));
451 void shouldParseResultRowConverterResultType() {
454 resultType: com.example.MyResult
456 final var config
= parser
.parseConfig(yaml
);
457 assertTrue(config
.resultRowConverter().isPresent());
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()));
466 void shouldParseResultRowConverter() {
469 alias: converterAlias
470 methodName: someMethod
471 converterType: com.example.MyConverter
472 resultType: com.example.MyResult
474 final var config
= parser
.parseConfig(yaml
);
475 assertTrue(config
.resultRowConverter().isPresent());
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()));
484 void shouldParseAnnotation() {
487 - type: com.example.MyAnnotation
491 type: java.lang.String
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())));
505 void shouldParseAnnotations() {
508 - type: com.example.MyAnnotation
512 type: java.lang.String
513 - type: com.example.OtherAnnotation
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())));
535 void shouldParseAnnotationMembers() {
538 - type: com.example.MyAnnotation
542 type: java.lang.String
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())));