List of usage examples for org.springframework.boot.test.util TestPropertyValues of
public static TestPropertyValues of(Stream<String> pairs)
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testWithConfigLocation() { TestPropertyValues.of("mybatis.config-location:mybatis-config.xml").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisAutoConfiguration.class, MybatisMapperConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1); assertThat(this.context.getBeanNamesForType(CityMapperImpl.class)).hasSize(1); assertThat(this.context.getBean(SqlSessionTemplate.class).getExecutorType()).isEqualTo(ExecutorType.BATCH); assertThat(this.context.getBean(SqlSessionFactory.class).getConfiguration().isMapUnderscoreToCamelCase()) .isTrue();// w w w. j av a2s .c o m }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testWithCheckConfigLocationFileNotSpecify() { TestPropertyValues.of("mybatis.check-config-location=true").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1); }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testWithTypeHandlersPackage() { TestPropertyValues.of("mybatis.type-handlers-package:org.mybatis.spring.boot.autoconfigure.handler") .applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); TypeHandlerRegistry typeHandlerRegistry = this.context.getBean(SqlSessionFactory.class).getConfiguration() .getTypeHandlerRegistry();//from w ww. j a v a2 s . co m assertThat(typeHandlerRegistry.hasTypeHandler(BigInteger.class)).isTrue(); }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testMixedWithConfigurationFileAndInterceptor() { TestPropertyValues.of("mybatis.config-location:mybatis-config-settings-only.xml").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisInterceptorConfiguration.class); this.context.refresh(); org.apache.ibatis.session.Configuration configuration = this.context.getBean(SqlSessionFactory.class) .getConfiguration();/*from w ww . jav a 2 s. co m*/ assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1); assertThat(this.context.getBeanNamesForType(SqlSessionTemplate.class)).hasSize(1); assertThat(this.context.getBeanNamesForType(CityMapper.class)).hasSize(1); assertThat(configuration.getDefaultFetchSize()).isEqualTo(1000); assertThat(configuration.getInterceptors()).hasSize(1); assertThat(configuration.getInterceptors().get(0)).isInstanceOf(MyInterceptor.class); }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testMixedWithConfigurationFileAndDatabaseIdProvider() { TestPropertyValues.of("mybatis.config-location:mybatis-config-settings-only.xml").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisBootMapperScanAutoConfiguration.class, DatabaseProvidersConfiguration.class); this.context.refresh(); org.apache.ibatis.session.Configuration configuration = this.context.getBean(SqlSessionFactory.class) .getConfiguration();// w w w. j av a 2s.c o m assertThat(this.context.getBeanNamesForType(SqlSessionFactory.class)).hasSize(1); assertThat(this.context.getBeanNamesForType(SqlSessionTemplate.class)).hasSize(1); assertThat(this.context.getBeanNamesForType(CityMapper.class)).hasSize(1); assertThat(configuration.getDefaultFetchSize()).isEqualTo(1000); assertThat(configuration.getDatabaseId()).isEqualTo("h2"); }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testWithMyBatisConfiguration() { TestPropertyValues.of("mybatis.configuration.map-underscore-to-camel-case:true").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisAutoConfiguration.class); this.context.refresh(); assertThat(this.context.getBean(SqlSessionFactory.class).getConfiguration().isMapUnderscoreToCamelCase()) .isTrue();//from w w w . j a v a 2 s . c o m }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testWithMyBatisConfigurationCustomizeByJavaConfig() { TestPropertyValues.of("mybatis.configuration.default-fetch-size:100").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisAutoConfiguration.class, MybatisPropertiesConfigurationCustomizer.class); this.context.refresh(); SqlSessionFactory sqlSessionFactory = this.context.getBean(SqlSessionFactory.class); assertThat(sqlSessionFactory.getConfiguration().getDefaultFetchSize()).isEqualTo(100); assertThat(sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().getTypeHandler(BigInteger.class)) .isInstanceOf(DummyTypeHandler.class); }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testWithConfigurationVariablesOnly() { TestPropertyValues.of("mybatis.configuration.variables.key1:value1").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables(); assertThat(variables).hasSize(1);//from w w w . j a v a 2s . c o m assertThat(variables.getProperty("key1")).isEqualTo("value1"); }
From source file:org.mybatis.spring.boot.autoconfigure.MybatisAutoConfigurationTest.java
@Test public void testWithConfigurationPropertiesOnly() { TestPropertyValues.of("mybatis.configuration-properties.key2:value2").applyTo(this.context); this.context.register(EmbeddedDataSourceConfiguration.class, MybatisAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); this.context.refresh(); Properties variables = this.context.getBean(SqlSessionFactory.class).getConfiguration().getVariables(); assertThat(variables).hasSize(1);/*from w ww . j a v a 2s . c om*/ assertThat(variables.getProperty("key2")).isEqualTo("value2"); }
From source file:org.springframework.cloud.context.scope.refresh.RefreshScopeConfigurationScaleTests.java
@Test @Repeat(10)/* www. ja v a 2 s . c om*/ @DirtiesContext public void testConcurrentRefresh() throws Exception { scope.setEager(false); // overload the thread pool and try to force Spring to create too many instances int n = 80; TestPropertyValues.of("message=Foo").applyTo(environment); this.scope.refreshAll(); final CountDownLatch latch = new CountDownLatch(n); List<Future<String>> results = new ArrayList<>(); for (int i = 0; i < n; i++) { results.add(this.executor.submit(new Callable<String>() { @Override public String call() throws Exception { logger.debug("Background started."); try { return RefreshScopeConfigurationScaleTests.this.service.getMessage(); } finally { latch.countDown(); logger.debug("Background done."); } } })); this.executor.submit(new Runnable() { @Override public void run() { logger.debug("Refreshing."); RefreshScopeConfigurationScaleTests.this.scope.refreshAll(); } }); } assertTrue(latch.await(15000, TimeUnit.MILLISECONDS)); assertEquals("Foo", this.service.getMessage()); for (Future<String> result : results) { assertEquals("Foo", result.get()); } }