Skip to content

Commit 0fb0402

Browse files
committed
Add onDuplicateKeyException case to UpsertAssemblerContextTest
1 parent caca6d7 commit 0fb0402

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

doma-core/src/test/java/org/seasar/doma/jdbc/query/UpsertAssemblerContextTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,46 @@
2424

2525
class UpsertAssemblerContextTest {
2626
private final MockConfig config = new MockConfig();
27-
2827
private final PreparedSqlBuilder buf =
2928
new PreparedSqlBuilder(config, SqlKind.BATCH_INSERT, SqlLogType.RAW);
3029
private final Dept_ metaDept = new Dept_();
3130
private final List<EntityPropertyType<?, ?>> propertyTypes =
3231
metaDept.allPropertyMetamodels().stream().map(PropertyMetamodel::asType).collect(toList());
3332

33+
@Test
34+
void onDuplicateKeyException() {
35+
List<EntityPropertyType<?, ?>> keys =
36+
propertyTypes.stream().filter(EntityPropertyType::isId).collect(toList());
37+
List<Tuple2<EntityPropertyType<?, ?>, InParameter<?>>> insertValues =
38+
propertyTypes.stream()
39+
.filter(c -> !c.isId())
40+
.map(c -> new Tuple2<EntityPropertyType<?, ?>, InParameter<?>>(c, mockInParameter()))
41+
.collect(toList());
42+
List<Tuple2<EntityPropertyType<?, ?>, UpsertSetValue>> setValues =
43+
propertyTypes.stream()
44+
.filter(c -> !c.isId())
45+
.map(
46+
c ->
47+
new Tuple2<EntityPropertyType<?, ?>, UpsertSetValue>(
48+
c, new UpsertSetValue.Prop(c)))
49+
.collect(toList());
50+
DomaIllegalArgumentException ex =
51+
assertThrows(
52+
DomaIllegalArgumentException.class,
53+
() -> {
54+
new UpsertAssemblerContext(
55+
buf,
56+
metaDept.asType(),
57+
DuplicateKeyType.EXCEPTION,
58+
Naming.NONE,
59+
config.getDialect(),
60+
keys,
61+
insertValues,
62+
setValues);
63+
});
64+
System.out.println(ex.getMessage());
65+
}
66+
3467
@Test
3568
void onDuplicateKeyUpdate() {
3669
List<EntityPropertyType<?, ?>> keys =

0 commit comments

Comments
 (0)