fix #123 allow to specify extra annotations on repositories/methods
[yosql.git] / yosql-codegen / src / test / java / wtf / metio / yosql / codegen / files / DefaultMethodNameValidatorTest.java
blob92a89a23969a6842aec53067844fc13e1923ae2e
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.logging.LoggingObjectMother;
14 import wtf.metio.yosql.codegen.orchestration.ExecutionErrors;
15 import wtf.metio.yosql.codegen.orchestration.OrchestrationObjectMother;
16 import wtf.metio.yosql.models.configuration.SqlStatementType;
17 import wtf.metio.yosql.models.immutables.SqlConfiguration;
18 import wtf.metio.yosql.testing.configs.RepositoriesConfigurations;
20 import java.nio.file.Paths;
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
25 @DisplayName("DefaultMethodNameValidator")
26 class DefaultMethodNameValidatorTest {
28 private DefaultMethodNameValidator validator;
29 private ExecutionErrors errors;
31 @BeforeEach
32 void setUp() {
33 errors = OrchestrationObjectMother.executionErrors();
34 validator = new DefaultMethodNameValidator(RepositoriesConfigurations.validatingMethodNames(), errors, LoggingObjectMother.messages());
37 @Test
38 void detectInvalidReadPrefix() {
39 final var configuration = SqlConfiguration.usingDefaults()
40 .setType(SqlStatementType.READING)
41 .setName("updateSomeData")
42 .build();
43 final var source = Paths.get("some.sql");
44 validator.validateNames(configuration, source);
45 assertTrue(errors.hasErrors());
48 @Test
49 void detectInvalidWritePrefix() {
50 final var configuration = SqlConfiguration.usingDefaults()
51 .setType(SqlStatementType.WRITING)
52 .setName("findSomeData")
53 .build();
54 final var source = Paths.get("some.sql");
55 validator.validateNames(configuration, source);
56 assertTrue(errors.hasErrors());
59 @Test
60 void detectInvalidCallPrefix() {
61 final var configuration = SqlConfiguration.usingDefaults()
62 .setType(SqlStatementType.CALLING)
63 .setName("findSomeData")
64 .build();
65 final var source = Paths.get("some.sql");
66 validator.validateNames(configuration, source);
67 assertTrue(errors.hasErrors());
70 @Test
71 void acceptValidReadPrefix() {
72 final var configuration = SqlConfiguration.usingDefaults()
73 .setType(SqlStatementType.READING)
74 .setName("findSomeData")
75 .build();
76 final var source = Paths.get("some.sql");
77 validator.validateNames(configuration, source);
78 assertFalse(errors.hasErrors());
81 @Test
82 void acceptValidWritePrefix() {
83 final var configuration = SqlConfiguration.usingDefaults()
84 .setType(SqlStatementType.WRITING)
85 .setName("writeSomeData")
86 .build();
87 final var source = Paths.get("some.sql");
88 validator.validateNames(configuration, source);
89 assertFalse(errors.hasErrors());
92 @Test
93 void acceptValidCallPrefix() {
94 final var configuration = SqlConfiguration.usingDefaults()
95 .setType(SqlStatementType.CALLING)
96 .setName("callSomeProcedure")
97 .build();
98 final var source = Paths.get("some.sql");
99 validator.validateNames(configuration, source);
100 assertFalse(errors.hasErrors());