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 shouldParseGenerateStandardApiEnabled() {
192 generateStandardApi: true
194 final var config
= parser
.parseConfig(yaml
);
195 assertTrue(config
.generateStandardApi().isPresent());
196 assertTrue(config
.generateStandardApi().get());
200 void shouldParseGenerateStandardApiDisabled() {
202 generateStandardApi: false
204 final var config
= parser
.parseConfig(yaml
);
205 assertTrue(config
.generateStandardApi().isPresent());
206 assertFalse(config
.generateStandardApi().get());
210 void shouldParseGenerateBatchApiEnabled() {
212 generateBatchApi: true
214 final var config
= parser
.parseConfig(yaml
);
215 assertTrue(config
.generateBatchApi().isPresent());
216 assertTrue(config
.generateBatchApi().get());
220 void shouldParseGenerateBatchApiDisabled() {
222 generateBatchApi: false
224 final var config
= parser
.parseConfig(yaml
);
225 assertTrue(config
.generateBatchApi().isPresent());
226 assertFalse(config
.generateBatchApi().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 shouldParseInjectConvertersEnabled() {
252 injectConverters: true
254 final var config
= parser
.parseConfig(yaml
);
255 assertTrue(config
.injectConverters().isPresent());
256 assertTrue(config
.injectConverters().get());
260 void shouldParseInjectConvertersDisabled() {
262 injectConverters: false
264 final var config
= parser
.parseConfig(yaml
);
265 assertTrue(config
.injectConverters().isPresent());
266 assertFalse(config
.injectConverters().get());
270 void shouldParseStandardPrefix() {
272 standardPrefix: prefix
274 final var config
= parser
.parseConfig(yaml
);
275 assertTrue(config
.standardPrefix().isPresent());
276 assertEquals("prefix", config
.standardPrefix().get());
280 void shouldParseStandardSuffix() {
282 standardSuffix: suffix
284 final var config
= parser
.parseConfig(yaml
);
285 assertTrue(config
.standardSuffix().isPresent());
286 assertEquals("suffix", config
.standardSuffix().get());
290 void shouldParseBatchPrefix() {
294 final var config
= parser
.parseConfig(yaml
);
295 assertTrue(config
.batchPrefix().isPresent());
296 assertEquals("prefix", config
.batchPrefix().get());
300 void shouldParseBatchSuffix() {
304 final var config
= parser
.parseConfig(yaml
);
305 assertTrue(config
.batchSuffix().isPresent());
306 assertEquals("suffix", config
.batchSuffix().get());
310 void shouldParseParameter() {
314 type: java.lang.String
316 final var config
= parser
.parseConfig(yaml
);
317 assertEquals(1, config
.parameters().size());
319 () -> assertEquals("name", config
.parameters().get(0).name().get()),
320 () -> assertEquals("java.lang.String", config
.parameters().get(0).type().get()));
324 void shouldParseParameters() {
328 type: java.lang.String
334 final var config
= parser
.parseConfig(yaml
);
335 assertEquals(3, config
.parameters().size());
337 () -> assertEquals("string", config
.parameters().get(0).name().get()),
338 () -> assertEquals("java.lang.String", config
.parameters().get(0).type().get()),
339 () -> assertEquals("bool", config
.parameters().get(1).name().get()),
340 () -> assertEquals("boolean", config
.parameters().get(1).type().get()),
341 () -> assertEquals("number", config
.parameters().get(2).name().get()),
342 () -> assertEquals("int", config
.parameters().get(2).type().get()));
346 void shouldParseResultRowConverterAlias() {
349 alias: converterAlias
351 final var config
= parser
.parseConfig(yaml
);
352 assertTrue(config
.resultRowConverter().isPresent());
354 () -> assertEquals("converterAlias", config
.resultRowConverter().get().alias().get()),
355 () -> assertTrue(config
.resultRowConverter().get().methodName().isEmpty()),
356 () -> assertTrue(config
.resultRowConverter().get().converterType().isEmpty()),
357 () -> assertTrue(config
.resultRowConverter().get().resultType().isEmpty()));
361 void shouldParseResultRowConverterMethodName() {
364 methodName: someMethod
366 final var config
= parser
.parseConfig(yaml
);
367 assertTrue(config
.resultRowConverter().isPresent());
369 () -> assertTrue(config
.resultRowConverter().get().alias().isEmpty()),
370 () -> assertEquals("someMethod", config
.resultRowConverter().get().methodName().get()),
371 () -> assertTrue(config
.resultRowConverter().get().converterType().isEmpty()),
372 () -> assertTrue(config
.resultRowConverter().get().resultType().isEmpty()));
376 void shouldParseResultRowConverterConverterType() {
379 converterType: com.example.MyConverter
381 final var config
= parser
.parseConfig(yaml
);
382 assertTrue(config
.resultRowConverter().isPresent());
384 () -> assertTrue(config
.resultRowConverter().get().alias().isEmpty()),
385 () -> assertTrue(config
.resultRowConverter().get().methodName().isEmpty()),
386 () -> assertEquals("com.example.MyConverter", config
.resultRowConverter().get().converterType().get()),
387 () -> assertTrue(config
.resultRowConverter().get().resultType().isEmpty()));
391 void shouldParseResultRowConverterResultType() {
394 resultType: com.example.MyResult
396 final var config
= parser
.parseConfig(yaml
);
397 assertTrue(config
.resultRowConverter().isPresent());
399 () -> assertTrue(config
.resultRowConverter().get().alias().isEmpty()),
400 () -> assertTrue(config
.resultRowConverter().get().methodName().isEmpty()),
401 () -> assertTrue(config
.resultRowConverter().get().converterType().isEmpty()),
402 () -> assertEquals("com.example.MyResult", config
.resultRowConverter().get().resultType().get()));
406 void shouldParseResultRowConverter() {
409 alias: converterAlias
410 methodName: someMethod
411 converterType: com.example.MyConverter
412 resultType: com.example.MyResult
414 final var config
= parser
.parseConfig(yaml
);
415 assertTrue(config
.resultRowConverter().isPresent());
417 () -> assertEquals("converterAlias", config
.resultRowConverter().get().alias().get()),
418 () -> assertEquals("someMethod", config
.resultRowConverter().get().methodName().get()),
419 () -> assertEquals("com.example.MyConverter", config
.resultRowConverter().get().converterType().get()),
420 () -> assertEquals("com.example.MyResult", config
.resultRowConverter().get().resultType().get()));
424 void shouldParseAnnotation() {
427 - type: com.example.MyAnnotation
431 type: java.lang.String
433 final var config
= parser
.parseConfig(yaml
);
434 assertFalse(config
.annotations().isEmpty());
435 assertAll("annotation",
436 () -> assertEquals("com.example.MyAnnotation", config
.annotations().get(0).type()),
437 () -> assertAll("members",
438 () -> assertFalse(config
.annotations().get(0).members().isEmpty()),
439 () -> assertEquals("some", config
.annotations().get(0).members().get(0).key()),
440 () -> assertEquals("here", config
.annotations().get(0).members().get(0).value()),
441 () -> assertEquals("java.lang.String", config
.annotations().get(0).members().get(0).type())));
445 void shouldParseAnnotations() {
448 - type: com.example.MyAnnotation
452 type: java.lang.String
453 - type: com.example.OtherAnnotation
459 final var config
= parser
.parseConfig(yaml
);
460 assertFalse(config
.annotations().isEmpty());
461 assertAll("annotation",
462 () -> assertEquals("com.example.MyAnnotation", config
.annotations().get(0).type()),
463 () -> assertEquals("com.example.OtherAnnotation", config
.annotations().get(1).type()),
464 () -> assertAll("members",
465 () -> assertFalse(config
.annotations().get(0).members().isEmpty()),
466 () -> assertEquals("some", config
.annotations().get(0).members().get(0).key()),
467 () -> assertEquals("here", config
.annotations().get(0).members().get(0).value()),
468 () -> assertEquals("java.lang.String", config
.annotations().get(0).members().get(0).type()),
469 () -> assertEquals("another", config
.annotations().get(1).members().get(0).key()),
470 () -> assertEquals("12345", config
.annotations().get(1).members().get(0).value()),
471 () -> assertEquals("int", config
.annotations().get(1).members().get(0).type())));
475 void shouldParseAnnotationMembers() {
478 - type: com.example.MyAnnotation
482 type: java.lang.String
487 final var config
= parser
.parseConfig(yaml
);
488 assertFalse(config
.annotations().isEmpty());
489 assertAll("annotation",
490 () -> assertEquals("com.example.MyAnnotation", config
.annotations().get(0).type()),
491 () -> assertAll("members",
492 () -> assertFalse(config
.annotations().get(0).members().isEmpty()),
493 () -> assertEquals("some", config
.annotations().get(0).members().get(0).key()),
494 () -> assertEquals("here", config
.annotations().get(0).members().get(0).value()),
495 () -> assertEquals("java.lang.String", config
.annotations().get(0).members().get(0).type()),
496 () -> assertEquals("another", config
.annotations().get(0).members().get(1).key()),
497 () -> assertEquals("12345", config
.annotations().get(0).members().get(1).value()),
498 () -> assertEquals("int", config
.annotations().get(0).members().get(1).type())));