|
20 | 20 | import static org.junit.Assert.assertEquals; |
21 | 21 | import static org.junit.Assert.assertFalse; |
22 | 22 | import static org.junit.Assert.assertTrue; |
| 23 | +import static org.junit.Assert.assertNull; |
23 | 24 |
|
24 | 25 | import java.math.BigInteger; |
25 | 26 | import java.util.Map; |
@@ -407,6 +408,77 @@ public void testConfigFileAndConfigurationWithTogether() { |
407 | 408 | this.context.refresh(); |
408 | 409 | } |
409 | 410 |
|
| 411 | + @Test |
| 412 | + public void testWithoutConfigurationVariablesAndProperties() { |
| 413 | + EnvironmentTestUtils.addEnvironment(this.context); |
| 414 | + this.context.register(EmbeddedDataSourceConfiguration.class, |
| 415 | + MybatisAutoConfiguration.class, |
| 416 | + PropertyPlaceholderAutoConfiguration.class); |
| 417 | + this.context.refresh(); |
| 418 | + |
| 419 | + Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables(); |
| 420 | + assertNull(variables); |
| 421 | + } |
| 422 | + |
| 423 | + @Test |
| 424 | + public void testWithConfigurationVariablesOnly() { |
| 425 | + EnvironmentTestUtils.addEnvironment(this.context, |
| 426 | + "mybatis.configuration.variables.key1:value1"); |
| 427 | + this.context.register(EmbeddedDataSourceConfiguration.class, |
| 428 | + MybatisAutoConfiguration.class, |
| 429 | + PropertyPlaceholderAutoConfiguration.class); |
| 430 | + this.context.refresh(); |
| 431 | + |
| 432 | + Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables(); |
| 433 | + assertEquals(1, variables.size()); |
| 434 | + assertEquals("value1", variables.get("key1")); |
| 435 | + } |
| 436 | + |
| 437 | + @Test |
| 438 | + public void testWithConfigurationPropertiesOnly() { |
| 439 | + EnvironmentTestUtils.addEnvironment(this.context, |
| 440 | + "mybatis.configuration-properties.key2:value2"); |
| 441 | + this.context.register(EmbeddedDataSourceConfiguration.class, |
| 442 | + MybatisAutoConfiguration.class, |
| 443 | + PropertyPlaceholderAutoConfiguration.class); |
| 444 | + this.context.refresh(); |
| 445 | + |
| 446 | + Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables(); |
| 447 | + assertEquals(1, variables.size()); |
| 448 | + assertEquals("value2", variables.get("key2")); |
| 449 | + } |
| 450 | + |
| 451 | + @Test |
| 452 | + public void testWithConfigurationVariablesAndPropertiesOtherKey() { |
| 453 | + EnvironmentTestUtils.addEnvironment(this.context, |
| 454 | + "mybatis.configuration.variables.key1:value1", |
| 455 | + "mybatis.configuration-properties.key2:value2"); |
| 456 | + this.context.register(EmbeddedDataSourceConfiguration.class, |
| 457 | + MybatisAutoConfiguration.class, |
| 458 | + PropertyPlaceholderAutoConfiguration.class); |
| 459 | + this.context.refresh(); |
| 460 | + |
| 461 | + Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables(); |
| 462 | + assertEquals(2, variables.size()); |
| 463 | + assertEquals("value1", variables.get("key1")); |
| 464 | + assertEquals("value2", variables.get("key2")); |
| 465 | + } |
| 466 | + |
| 467 | + @Test |
| 468 | + public void testWithConfigurationVariablesAndPropertiesSameKey() { |
| 469 | + EnvironmentTestUtils.addEnvironment(this.context, |
| 470 | + "mybatis.configuration.variables.key:value1", |
| 471 | + "mybatis.configuration-properties.key:value2"); |
| 472 | + this.context.register(EmbeddedDataSourceConfiguration.class, |
| 473 | + MybatisAutoConfiguration.class, |
| 474 | + PropertyPlaceholderAutoConfiguration.class); |
| 475 | + this.context.refresh(); |
| 476 | + |
| 477 | + Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables(); |
| 478 | + assertEquals(1, variables.size()); |
| 479 | + assertEquals("value2", variables.get("key")); |
| 480 | + } |
| 481 | + |
410 | 482 | @Configuration |
411 | 483 | @EnableAutoConfiguration |
412 | 484 | @MapperScan("org.mybatis.spring.boot.autoconfigure.mapper") |
|
0 commit comments