|
| 1 | +/* |
| 2 | + * Copyright 2016-2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package examples.simple; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | + |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | +import org.mybatis.dynamic.sql.ParameterTypeConverter; |
| 22 | +import org.mybatis.dynamic.sql.SqlTable; |
| 23 | +import org.mybatis.dynamic.sql.render.RenderingStrategies; |
| 24 | + |
| 25 | +class ExtendedColumnTest { |
| 26 | + |
| 27 | + private final SqlTable table = SqlTable.of("foo"); |
| 28 | + private final PrimaryKeyColumn<Integer> bar = new PrimaryKeyColumn.Builder<Integer>() |
| 29 | + .withName("first_name") |
| 30 | + .withTable(table) |
| 31 | + .isPrimaryKeyColumn(true) |
| 32 | + .build(); |
| 33 | + private final ParameterTypeConverter<Integer, String> ptc = Object::toString; |
| 34 | + |
| 35 | + @Test |
| 36 | + void testPropagatedDescending() { |
| 37 | + var baz = bar.descending(); |
| 38 | + |
| 39 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void testPropagatedAlias() { |
| 44 | + var baz = bar.as("fred"); |
| 45 | + |
| 46 | + assertThat(baz.alias()).hasValue("fred"); |
| 47 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void testPropagatedQualifiedWith() { |
| 52 | + var baz = bar.qualifiedWith("fred"); |
| 53 | + |
| 54 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + void testPropagatedAsCamelCase() { |
| 59 | + var baz = bar.asCamelCase(); |
| 60 | + |
| 61 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void testPropagatedWithTypeHandler() { |
| 66 | + var baz = bar.withTypeHandler("barney"); |
| 67 | + |
| 68 | + assertThat(baz.typeHandler()).hasValue("barney"); |
| 69 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + void testPropagatedRenderingStrategy() { |
| 74 | + var baz = bar.withRenderingStrategy(RenderingStrategies.MYBATIS3); |
| 75 | + |
| 76 | + assertThat(baz.renderingStrategy()).hasValue(RenderingStrategies.MYBATIS3); |
| 77 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + void testPropagatedParameterTypeConverter() { |
| 82 | + var baz = bar.withParameterTypeConverter(ptc); |
| 83 | + |
| 84 | + assertThat(baz.convertParameterType(11)).isEqualTo("11"); |
| 85 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 86 | + } |
| 87 | + |
| 88 | + @Test |
| 89 | + void testPropagatedJavaType() { |
| 90 | + var baz = bar.withJavaType(Integer.class); |
| 91 | + |
| 92 | + assertThat(baz.javaType()).hasValue(Integer.class); |
| 93 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + void testPropagatedJavaProperty() { |
| 98 | + var baz = bar.withJavaProperty("id"); |
| 99 | + |
| 100 | + assertThat(baz.javaProperty()).hasValue("id"); |
| 101 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + void testAll() { |
| 106 | + PrimaryKeyColumn<Integer> baz = bar.descending() |
| 107 | + .as("fred") |
| 108 | + .qualifiedWith("fred") |
| 109 | + .asCamelCase() |
| 110 | + .withTypeHandler("barney") |
| 111 | + .withRenderingStrategy(RenderingStrategies.MYBATIS3) |
| 112 | + .withParameterTypeConverter(ptc) |
| 113 | + .withJavaType(Integer.class) |
| 114 | + .withJavaProperty("id"); |
| 115 | + |
| 116 | + assertThat(baz.alias()).hasValue("\"firstName\""); |
| 117 | + assertThat(baz.typeHandler()).hasValue("barney"); |
| 118 | + assertThat(baz.renderingStrategy()).hasValue(RenderingStrategies.MYBATIS3); |
| 119 | + assertThat(baz.convertParameterType(11)).isEqualTo("11"); |
| 120 | + assertThat(baz.javaType()).hasValue(Integer.class); |
| 121 | + assertThat(baz.javaProperty()).hasValue("id"); |
| 122 | + assertThat(baz.isPrimaryKeyColumn()).isTrue(); |
| 123 | + } |
| 124 | +} |
0 commit comments