fix #123 allow to specify extra annotations on repositories/methods
[yosql.git] / yosql-codegen / src / test / java / wtf / metio / yosql / codegen / files / DefaultMethodApiConfigurerTest.java
blob2e10a3b53cfeac631d8d373c1de91cded0789dee
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.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;
24 @BeforeEach
25 void setUp() {
26 repositories = RepositoriesConfigurations.defaults();
27 configurer = new DefaultMethodApiConfigurer(repositories);
30 @Test
31 void batchKeep() {
32 final var original = SqlConfiguration.usingDefaults()
33 .setGenerateBatchApi(false)
34 .build();
35 final var adapted = configurer.batch(original);
36 assertEquals(original.generateBatchApi(), adapted.generateBatchApi());
39 @Test
40 void batchChangedToRepositoryDefault() {
41 final var original = SqlConfiguration.usingDefaults()
42 // .setGenerateBatchApi(true) // value is NOT set
43 .build();
44 final var adapted = configurer.batch(original);
45 assertTrue(adapted.generateBatchApi().isPresent());
46 assertEquals(repositories.generateBatchApi(), adapted.generateBatchApi().get());
49 @Test
50 void batchAllowsReads() {
51 final var original = SqlConfiguration.usingDefaults()
52 .setGenerateBatchApi(true)
53 .setType(SqlStatementType.READING)
54 .build();
55 final var adapted = configurer.batch(original);
56 assertTrue(adapted.generateBatchApi().isPresent());
57 assertTrue(adapted.generateBatchApi().get());
60 @Test
61 void standardKeep() {
62 final var original = SqlConfiguration.usingDefaults()
63 .setGenerateStandardApi(false)
64 .build();
65 final var adapted = configurer.standard(original);
66 assertEquals(original.generateStandardApi(), adapted.generateStandardApi());
69 @Test
70 void standardChangedToRepositoryDefault() {
71 final var original = SqlConfiguration.usingDefaults()
72 // .setGenerateStandardApi(true) // value is NOT set
73 .build();
74 final var adapted = configurer.standard(original);
75 assertTrue(adapted.generateStandardApi().isPresent());
76 assertEquals(repositories.generateStandardApi(), adapted.generateStandardApi().get());
79 @Test
80 void keepApis() {
81 final var original = SqlConfiguration.usingDefaults()
82 .setGenerateBatchApi(false)
83 .setGenerateStandardApi(false)
84 .build();
85 final var adapted = configurer.configureApis(original);
86 assertAll(
87 () -> assertEquals(original.generateBatchApi(), adapted.generateBatchApi()),
88 () -> assertEquals(original.generateStandardApi(), adapted.generateStandardApi()));
91 @Test
92 void changeApis() {
93 final var original = SqlConfiguration.usingDefaults().build();
94 final var adapted = configurer.configureApis(original);
95 assertAll(
96 () -> assertEquals(repositories.generateBatchApi(), adapted.generateBatchApi().get()),
97 () -> assertEquals(repositories.generateStandardApi(), adapted.generateStandardApi().get()));