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
.Test
;
12 import wtf
.metio
.yosql
.models
.configuration
.SqlStatementType
;
13 import wtf
.metio
.yosql
.models
.immutables
.RepositoriesConfiguration
;
14 import wtf
.metio
.yosql
.models
.immutables
.SqlConfiguration
;
15 import wtf
.metio
.yosql
.testing
.configs
.RepositoriesConfigurations
;
17 import static org
.junit
.jupiter
.api
.Assertions
.*;
19 class DefaultMethodApiConfigurerTest
{
21 private DefaultMethodApiConfigurer configurer
;
22 private RepositoriesConfiguration repositories
;
26 repositories
= RepositoriesConfigurations
.defaults();
27 configurer
= new DefaultMethodApiConfigurer(repositories
);
32 final var original
= SqlConfiguration
.usingDefaults()
33 .setGenerateBatchApi(false)
35 final var adapted
= configurer
.batch(original
);
36 assertEquals(original
.generateBatchApi(), adapted
.generateBatchApi());
40 void batchChangedToRepositoryDefault() {
41 final var original
= SqlConfiguration
.usingDefaults()
42 // .setGenerateBatchApi(true) // value is NOT set
44 final var adapted
= configurer
.batch(original
);
45 assertTrue(adapted
.generateBatchApi().isPresent());
46 assertEquals(repositories
.generateBatchApi(), adapted
.generateBatchApi().get());
50 void batchAllowsReads() {
51 final var original
= SqlConfiguration
.usingDefaults()
52 .setGenerateBatchApi(true)
53 .setType(SqlStatementType
.READING
)
55 final var adapted
= configurer
.batch(original
);
56 assertTrue(adapted
.generateBatchApi().isPresent());
57 assertTrue(adapted
.generateBatchApi().get());
62 final var original
= SqlConfiguration
.usingDefaults()
63 .setGenerateStandardApi(false)
65 final var adapted
= configurer
.standard(original
);
66 assertEquals(original
.generateStandardApi(), adapted
.generateStandardApi());
70 void standardChangedToRepositoryDefault() {
71 final var original
= SqlConfiguration
.usingDefaults()
72 // .setGenerateStandardApi(true) // value is NOT set
74 final var adapted
= configurer
.standard(original
);
75 assertTrue(adapted
.generateStandardApi().isPresent());
76 assertEquals(repositories
.generateStandardApi(), adapted
.generateStandardApi().get());
81 final var original
= SqlConfiguration
.usingDefaults()
82 .setGenerateBatchApi(false)
83 .setGenerateStandardApi(false)
85 final var adapted
= configurer
.configureApis(original
);
87 () -> assertEquals(original
.generateBatchApi(), adapted
.generateBatchApi()),
88 () -> assertEquals(original
.generateStandardApi(), adapted
.generateStandardApi()));
93 final var original
= SqlConfiguration
.usingDefaults().build();
94 final var adapted
= configurer
.configureApis(original
);
96 () -> assertEquals(repositories
.generateBatchApi(), adapted
.generateBatchApi().get()),
97 () -> assertEquals(repositories
.generateStandardApi(), adapted
.generateStandardApi().get()));