|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
25 | 25 |
|
26 | 26 | import javax.sql.DataSource;
|
27 | 27 |
|
| 28 | +import org.assertj.core.api.InstanceOfAssertFactories; |
28 | 29 | import org.junit.jupiter.api.BeforeEach;
|
29 | 30 | import org.junit.jupiter.api.Test;
|
30 | 31 |
|
31 | 32 | import org.springframework.dao.InvalidDataAccessApiUsageException;
|
32 | 33 | import org.springframework.jdbc.BadSqlGrammarException;
|
| 34 | +import org.springframework.jdbc.core.RowMapper; |
33 | 35 | import org.springframework.jdbc.core.SqlOutParameter;
|
34 | 36 | import org.springframework.jdbc.core.SqlParameter;
|
35 | 37 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
36 | 38 |
|
37 | 39 | import static org.assertj.core.api.Assertions.assertThat;
|
38 | 40 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
| 41 | +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
39 | 42 | import static org.mockito.BDDMockito.given;
|
40 | 43 | import static org.mockito.Mockito.atLeastOnce;
|
41 | 44 | import static org.mockito.Mockito.mock;
|
@@ -360,4 +363,37 @@ void correctSybaseFunctionStatementNamed() throws Exception {
|
360 | 363 | verifyStatement(adder, "{call ADD_INVOICE(@AMOUNT = ?, @CUSTID = ?)}");
|
361 | 364 | }
|
362 | 365 |
|
| 366 | + @Test |
| 367 | + void declareParametersCannotBeInvokedWhenCompiled() { |
| 368 | + SimpleJdbcCall call = new SimpleJdbcCall(dataSource) |
| 369 | + .withProcedureName("procedure_name") |
| 370 | + .declareParameters(new SqlParameter("PARAM", Types.VARCHAR)); |
| 371 | + call.compile(); |
| 372 | + assertThatIllegalStateException() |
| 373 | + .isThrownBy(() -> call.declareParameters(new SqlParameter("Ignored Param", Types.VARCHAR))) |
| 374 | + .withMessage("SqlCall for procedure is already compiled"); |
| 375 | + } |
| 376 | + |
| 377 | + @Test |
| 378 | + void addDeclaredRowMapperCanBeConfigured() { |
| 379 | + SimpleJdbcCall call = new SimpleJdbcCall(dataSource) |
| 380 | + .withProcedureName("procedure_name") |
| 381 | + .returningResultSet("result_set", (rs, i) -> new Object()); |
| 382 | + |
| 383 | + assertThat(call).extracting("declaredRowMappers") |
| 384 | + .asInstanceOf(InstanceOfAssertFactories.map(String.class, RowMapper.class)) |
| 385 | + .containsOnlyKeys("result_set"); |
| 386 | + } |
| 387 | + |
| 388 | + @Test |
| 389 | + void addDeclaredRowMapperWhenCompiled() { |
| 390 | + SimpleJdbcCall call = new SimpleJdbcCall(dataSource) |
| 391 | + .withProcedureName("procedure_name") |
| 392 | + .returningResultSet("result_set", (rs, i) -> new Object()); |
| 393 | + call.compile(); |
| 394 | + assertThatIllegalStateException() |
| 395 | + .isThrownBy(() -> call.returningResultSet("not added", (rs, i) -> new Object())) |
| 396 | + .withMessage("SqlCall for procedure is already compiled"); |
| 397 | + } |
| 398 | + |
363 | 399 | }
|
0 commit comments