1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }