|
34 | 34 | import java.io.InputStreamReader;
|
35 | 35 | import java.sql.Connection;
|
36 | 36 | import java.sql.DriverManager;
|
37 |
| -import java.sql.SQLSyntaxErrorException; |
38 | 37 | import java.util.Collection;
|
39 | 38 | import java.util.Collections;
|
40 | 39 | import java.util.List;
|
41 | 40 | import java.util.Map;
|
42 | 41 |
|
43 | 42 | import org.apache.ibatis.datasource.unpooled.UnpooledDataSource;
|
44 |
| -import org.apache.ibatis.exceptions.PersistenceException; |
45 | 43 | import org.apache.ibatis.jdbc.ScriptRunner;
|
46 | 44 | import org.apache.ibatis.mapping.Environment;
|
47 | 45 | import org.apache.ibatis.session.Configuration;
|
|
51 | 49 | import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
52 | 50 | import org.junit.jupiter.api.BeforeEach;
|
53 | 51 | import org.junit.jupiter.api.Test;
|
| 52 | +import org.mybatis.dynamic.sql.exception.InvalidSqlException; |
54 | 53 | import org.mybatis.dynamic.sql.render.RenderingStrategies;
|
55 | 54 | import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
|
| 55 | +import org.mybatis.dynamic.sql.util.Messages; |
56 | 56 | import org.mybatis.dynamic.sql.util.mybatis3.CommonSelectMapper;
|
57 | 57 |
|
58 | 58 | class VariousListConditionsTest {
|
@@ -136,26 +136,15 @@ void testInWhenPresentWithNull() {
|
136 | 136 |
|
137 | 137 | @Test
|
138 | 138 | void testInWithEmptyList() {
|
139 |
| - try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
140 |
| - CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); |
141 |
| - |
142 |
| - SelectStatementProvider selectStatement = select(id, animalName) |
143 |
| - .from(animalData) |
144 |
| - .where(id, isIn(Collections.emptyList())) |
145 |
| - .orderBy(id) |
146 |
| - .build() |
147 |
| - .render(RenderingStrategies.MYBATIS3); |
148 |
| - |
149 |
| - assertThat(selectStatement.getSelectStatement()).isEqualTo( |
150 |
| - "select id, animal_name from AnimalData " + |
151 |
| - "where id in () " + |
152 |
| - "order by id" |
153 |
| - ); |
154 |
| - |
155 |
| - assertThatExceptionOfType(PersistenceException.class).isThrownBy(() -> |
156 |
| - mapper.selectManyMappedRows(selectStatement) |
157 |
| - ).withCauseInstanceOf(SQLSyntaxErrorException.class); |
158 |
| - } |
| 139 | + var selectModel = select(id, animalName) |
| 140 | + .from(animalData) |
| 141 | + .where(id, isIn(Collections.emptyList())) |
| 142 | + .orderBy(id) |
| 143 | + .build(); |
| 144 | + |
| 145 | + assertThatExceptionOfType(InvalidSqlException.class) |
| 146 | + .isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3)) |
| 147 | + .withMessage(Messages.getString("ERROR.44", "IsIn")); |
159 | 148 | }
|
160 | 149 |
|
161 | 150 | @Test
|
@@ -319,121 +308,66 @@ void testNotInCaseInsensitiveWhenPresentMap() {
|
319 | 308 |
|
320 | 309 | @Test
|
321 | 310 | void testInEventuallyEmpty() {
|
322 |
| - try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
323 |
| - CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); |
324 |
| - |
325 |
| - SelectStatementProvider selectStatement = select(id, animalName) |
326 |
| - .from(animalData) |
327 |
| - .where(id, isIn(1, 2).filter(s -> false)) |
328 |
| - .orderBy(id) |
329 |
| - .build() |
330 |
| - .render(RenderingStrategies.MYBATIS3); |
331 |
| - |
332 |
| - assertThat(selectStatement.getSelectStatement()).isEqualTo( |
333 |
| - "select id, animal_name from AnimalData " + |
334 |
| - "where id in () " + |
335 |
| - "order by id" |
336 |
| - ); |
337 |
| - |
338 |
| - assertThatExceptionOfType(PersistenceException.class).isThrownBy( |
339 |
| - () -> mapper.selectManyMappedRows(selectStatement)) |
340 |
| - .withCauseInstanceOf(SQLSyntaxErrorException.class); |
341 |
| - } |
| 311 | + var selectModel = select(id, animalName) |
| 312 | + .from(animalData) |
| 313 | + .where(id, isIn(1, 2).filter(s -> false)) |
| 314 | + .orderBy(id) |
| 315 | + .build(); |
| 316 | + |
| 317 | + assertThatExceptionOfType(InvalidSqlException.class) |
| 318 | + .isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3)) |
| 319 | + .withMessage(Messages.getString("ERROR.44", "IsIn")); |
342 | 320 | }
|
343 | 321 |
|
344 | 322 | @Test
|
345 | 323 | void testInCaseInsensitiveEventuallyEmpty() {
|
346 |
| - try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
347 |
| - CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); |
348 |
| - |
349 |
| - SelectStatementProvider selectStatement = select(id, animalName) |
350 |
| - .from(animalData) |
351 |
| - .where(animalName, isInCaseInsensitive("Fred", "Betty").filter(s -> false)) |
352 |
| - .orderBy(id) |
353 |
| - .build() |
354 |
| - .render(RenderingStrategies.MYBATIS3); |
355 |
| - |
356 |
| - assertThat(selectStatement.getSelectStatement()).isEqualTo( |
357 |
| - "select id, animal_name from AnimalData " + |
358 |
| - "where upper(animal_name) in () " + |
359 |
| - "order by id" |
360 |
| - ); |
361 |
| - |
362 |
| - assertThatExceptionOfType(PersistenceException.class).isThrownBy( |
363 |
| - () -> mapper.selectManyMappedRows(selectStatement)) |
364 |
| - .withCauseInstanceOf(SQLSyntaxErrorException.class); |
365 |
| - } |
| 324 | + var selectModel = select(id, animalName) |
| 325 | + .from(animalData) |
| 326 | + .where(animalName, isInCaseInsensitive("Fred", "Betty").filter(s -> false)) |
| 327 | + .orderBy(id) |
| 328 | + .build(); |
| 329 | + |
| 330 | + assertThatExceptionOfType(InvalidSqlException.class) |
| 331 | + .isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3)) |
| 332 | + .withMessage(Messages.getString("ERROR.44", "IsInCaseInsensitive")); |
366 | 333 | }
|
367 | 334 |
|
368 | 335 | @Test
|
369 | 336 | void testNotInEventuallyEmpty() {
|
370 |
| - try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
371 |
| - CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); |
372 |
| - |
373 |
| - SelectStatementProvider selectStatement = select(id, animalName) |
374 |
| - .from(animalData) |
375 |
| - .where(id, isNotIn(1, 2).filter(s -> false)) |
376 |
| - .orderBy(id) |
377 |
| - .build() |
378 |
| - .render(RenderingStrategies.MYBATIS3); |
379 |
| - |
380 |
| - assertThat(selectStatement.getSelectStatement()).isEqualTo( |
381 |
| - "select id, animal_name from AnimalData " + |
382 |
| - "where id not in () " + |
383 |
| - "order by id" |
384 |
| - ); |
385 |
| - |
386 |
| - assertThatExceptionOfType(PersistenceException.class).isThrownBy( |
387 |
| - () -> mapper.selectManyMappedRows(selectStatement)) |
388 |
| - .withCauseInstanceOf(SQLSyntaxErrorException.class); |
389 |
| - } |
| 337 | + var selectModel = select(id, animalName) |
| 338 | + .from(animalData) |
| 339 | + .where(id, isNotIn(1, 2).filter(s -> false)) |
| 340 | + .orderBy(id) |
| 341 | + .build(); |
| 342 | + |
| 343 | + assertThatExceptionOfType(InvalidSqlException.class) |
| 344 | + .isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3)) |
| 345 | + .withMessage(Messages.getString("ERROR.44", "IsNotIn")); |
390 | 346 | }
|
391 | 347 |
|
392 | 348 | @Test
|
393 | 349 | void testNotInCaseInsensitiveEventuallyEmpty() {
|
394 |
| - try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
395 |
| - CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); |
396 |
| - |
397 |
| - SelectStatementProvider selectStatement = select(id, animalName) |
398 |
| - .from(animalData) |
399 |
| - .where(animalName, isNotInCaseInsensitive("Fred", "Betty").filter(s -> false)) |
400 |
| - .orderBy(id) |
401 |
| - .build() |
402 |
| - .render(RenderingStrategies.MYBATIS3); |
403 |
| - |
404 |
| - assertThat(selectStatement.getSelectStatement()).isEqualTo( |
405 |
| - "select id, animal_name from AnimalData " + |
406 |
| - "where upper(animal_name) not in () " + |
407 |
| - "order by id" |
408 |
| - ); |
409 |
| - |
410 |
| - assertThatExceptionOfType(PersistenceException.class).isThrownBy( |
411 |
| - () -> mapper.selectManyMappedRows(selectStatement)) |
412 |
| - .withCauseInstanceOf(SQLSyntaxErrorException.class); |
413 |
| - } |
| 350 | + var selectModel = select(id, animalName) |
| 351 | + .from(animalData) |
| 352 | + .where(animalName, isNotInCaseInsensitive("Fred", "Betty").filter(s -> false)) |
| 353 | + .orderBy(id) |
| 354 | + .build(); |
| 355 | + |
| 356 | + assertThatExceptionOfType(InvalidSqlException.class) |
| 357 | + .isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3)) |
| 358 | + .withMessage(Messages.getString("ERROR.44", "IsNotInCaseInsensitive")); |
414 | 359 | }
|
415 | 360 |
|
416 | 361 | @Test
|
417 | 362 | void testInEventuallyEmptyDoubleFilter() {
|
418 |
| - try (SqlSession sqlSession = sqlSessionFactory.openSession()) { |
419 |
| - CommonSelectMapper mapper = sqlSession.getMapper(CommonSelectMapper.class); |
420 |
| - |
421 |
| - SelectStatementProvider selectStatement = select(id, animalName) |
422 |
| - .from(animalData) |
423 |
| - .where(id, isIn(1, 2).filter(s -> false).filter(s -> false)) |
424 |
| - .orderBy(id) |
425 |
| - .build() |
426 |
| - .render(RenderingStrategies.MYBATIS3); |
427 |
| - |
428 |
| - assertThat(selectStatement.getSelectStatement()).isEqualTo( |
429 |
| - "select id, animal_name from AnimalData " + |
430 |
| - "where id in () " + |
431 |
| - "order by id" |
432 |
| - ); |
433 |
| - |
434 |
| - assertThatExceptionOfType(PersistenceException.class).isThrownBy( |
435 |
| - () -> mapper.selectManyMappedRows(selectStatement)) |
436 |
| - .withCauseInstanceOf(SQLSyntaxErrorException.class); |
437 |
| - } |
| 363 | + var selectModel = select(id, animalName) |
| 364 | + .from(animalData) |
| 365 | + .where(id, isIn(1, 2).filter(s -> false).filter(s -> false)) |
| 366 | + .orderBy(id) |
| 367 | + .build(); |
| 368 | + |
| 369 | + assertThatExceptionOfType(InvalidSqlException.class) |
| 370 | + .isThrownBy(() -> selectModel.render(RenderingStrategies.MYBATIS3)) |
| 371 | + .withMessage(Messages.getString("ERROR.44", "IsIn")); |
438 | 372 | }
|
439 | 373 | }
|
0 commit comments