View Javadoc
1   /*
2    *    Copyright 2016-2026 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 org.mybatis.dynamic.sql.insert.render;
17  
18  import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
19  
20  import org.junit.jupiter.api.Test;
21  import org.mybatis.dynamic.sql.SqlColumn;
22  import org.mybatis.dynamic.sql.SqlTable;
23  import org.mybatis.dynamic.sql.exception.InvalidSqlException;
24  import org.mybatis.dynamic.sql.render.RenderingStrategies;
25  import org.mybatis.dynamic.sql.util.MappedColumnMapping;
26  import org.mybatis.dynamic.sql.util.Messages;
27  
28  class InsertVisitorsTest {
29      @Test
30      void testThatMultiRowInsertVisitorErrorsForMappedColumnWhenPropertyIsMissing() {
31          TestTable table = new TestTable();
32          MultiRowValuePhraseVisitor tv = new MultiRowValuePhraseVisitor(RenderingStrategies.MYBATIS3, "prefix");
33          MappedColumnMapping mapping = MappedColumnMapping.of(table.id);
34  
35          assertThatExceptionOfType(InvalidSqlException.class).isThrownBy(() -> tv.visit(mapping))
36                  .withMessage(Messages.getString("ERROR.50", table.id.name()));
37      }
38  
39      @Test
40      void testThatValuePhraseVisitorErrorsForMappedColumnWhenPropertyIsMissing() {
41          TestTable table = new TestTable();
42          ValuePhraseVisitor tv = new ValuePhraseVisitor(RenderingStrategies.MYBATIS3);
43          MappedColumnMapping mapping = MappedColumnMapping.of(table.id);
44  
45          assertThatExceptionOfType(InvalidSqlException.class).isThrownBy(() -> tv.visit(mapping))
46                  .withMessage(Messages.getString("ERROR.50", table.id.name()));
47      }
48  
49      private static class TestTable extends SqlTable {
50          public final SqlColumn<Integer> id;
51          public final SqlColumn<String> description;
52  
53          public TestTable() {
54              super("Test");
55  
56              id = column("id");
57              description = column("description");
58          }
59      }
60  }