Search in sources :

Example 21 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method shouldSuccessfullyLoadMinimalXMLConfigFile.

@Test
public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
    String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
    Configuration config = builder.parse();
    assertNotNull(config);
    assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.PARTIAL));
    assertThat(config.getAutoMappingUnknownColumnBehavior(), is(AutoMappingUnknownColumnBehavior.NONE));
    assertThat(config.isCacheEnabled(), is(true));
    assertThat(config.getProxyFactory(), is(instanceOf(JavassistProxyFactory.class)));
    assertThat(config.isLazyLoadingEnabled(), is(false));
    assertThat(config.isAggressiveLazyLoading(), is(false));
    assertThat(config.isMultipleResultSetsEnabled(), is(true));
    assertThat(config.isUseColumnLabel(), is(true));
    assertThat(config.isUseGeneratedKeys(), is(false));
    assertThat(config.getDefaultExecutorType(), is(ExecutorType.SIMPLE));
    assertNull(config.getDefaultStatementTimeout());
    assertNull(config.getDefaultFetchSize());
    assertThat(config.isMapUnderscoreToCamelCase(), is(false));
    assertThat(config.isSafeRowBoundsEnabled(), is(false));
    assertThat(config.getLocalCacheScope(), is(LocalCacheScope.SESSION));
    assertThat(config.getJdbcTypeForNull(), is(JdbcType.OTHER));
    assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString"))));
    assertThat(config.isSafeResultHandlerEnabled(), is(true));
    assertThat(config.getDefaultScriptingLanguageInstance(), is(instanceOf(XMLLanguageDriver.class)));
    assertThat(config.isCallSettersOnNulls(), is(false));
    assertNull(config.getLogPrefix());
    assertNull(config.getLogImpl());
    assertNull(config.getConfigurationFactory());
}
Also used : HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) Configuration(org.apache.ibatis.session.Configuration) InputStream(java.io.InputStream) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) Test(org.junit.Test)

Example 22 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method shouldSuccessfullyLoadXMLConfigFileWithPropertiesUrl.

@Test
public void shouldSuccessfullyLoadXMLConfigFileWithPropertiesUrl() throws Exception {
    String resource = "org/apache/ibatis/builder/PropertiesUrlMapperConfig.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
    Configuration config = builder.parse();
    assertThat(config.getVariables().get("driver").toString(), is("org.apache.derby.jdbc.EmbeddedDriver"));
    assertThat(config.getVariables().get("prop1").toString(), is("bbbb"));
}
Also used : Configuration(org.apache.ibatis.session.Configuration) InputStream(java.io.InputStream) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) Test(org.junit.Test)

Example 23 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method shouldSuccessfullyLoadXMLConfigFile.

@Test
public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
    String resource = "org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    Properties props = new Properties();
    props.put("prop2", "cccc");
    XMLConfigBuilder builder = new XMLConfigBuilder(inputStream, null, props);
    Configuration config = builder.parse();
    assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.NONE));
    assertThat(config.getAutoMappingUnknownColumnBehavior(), is(AutoMappingUnknownColumnBehavior.WARNING));
    assertThat(config.isCacheEnabled(), is(false));
    assertThat(config.getProxyFactory(), is(instanceOf(CglibProxyFactory.class)));
    assertThat(config.isLazyLoadingEnabled(), is(true));
    assertThat(config.isAggressiveLazyLoading(), is(true));
    assertThat(config.isMultipleResultSetsEnabled(), is(false));
    assertThat(config.isUseColumnLabel(), is(false));
    assertThat(config.isUseGeneratedKeys(), is(true));
    assertThat(config.getDefaultExecutorType(), is(ExecutorType.BATCH));
    assertThat(config.getDefaultStatementTimeout(), is(10));
    assertThat(config.getDefaultFetchSize(), is(100));
    assertThat(config.isMapUnderscoreToCamelCase(), is(true));
    assertThat(config.isSafeRowBoundsEnabled(), is(true));
    assertThat(config.getLocalCacheScope(), is(LocalCacheScope.STATEMENT));
    assertThat(config.getJdbcTypeForNull(), is(JdbcType.NULL));
    assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx"))));
    assertThat(config.isSafeResultHandlerEnabled(), is(false));
    assertThat(config.getDefaultScriptingLanguageInstance(), is(instanceOf(RawLanguageDriver.class)));
    assertThat(config.isCallSettersOnNulls(), is(true));
    assertThat(config.getLogPrefix(), is("mybatis_"));
    assertThat(config.getLogImpl().getName(), is(Slf4jImpl.class.getName()));
    assertThat(config.getVfsImpl().getName(), is(JBoss6VFS.class.getName()));
    assertThat(config.getConfigurationFactory().getName(), is(String.class.getName()));
    assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("blogauthor").equals(Author.class));
    assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("blog").equals(Blog.class));
    assertTrue(config.getTypeAliasRegistry().getTypeAliases().get("cart").equals(Cart.class));
    assertThat(config.getTypeHandlerRegistry().getTypeHandler(Integer.class), is(instanceOf(CustomIntegerTypeHandler.class)));
    assertThat(config.getTypeHandlerRegistry().getTypeHandler(Long.class), is(instanceOf(CustomLongTypeHandler.class)));
    assertThat(config.getTypeHandlerRegistry().getTypeHandler(String.class), is(instanceOf(CustomStringTypeHandler.class)));
    assertThat(config.getTypeHandlerRegistry().getTypeHandler(String.class, JdbcType.VARCHAR), is(instanceOf(CustomStringTypeHandler.class)));
    ExampleObjectFactory objectFactory = (ExampleObjectFactory) config.getObjectFactory();
    assertThat(objectFactory.getProperties().size(), is(1));
    assertThat(objectFactory.getProperties().getProperty("objectFactoryProperty"), is("100"));
    assertThat(config.getObjectWrapperFactory(), is(instanceOf(CustomObjectWrapperFactory.class)));
    assertThat(config.getReflectorFactory(), is(instanceOf(CustomReflectorFactory.class)));
    ExamplePlugin plugin = (ExamplePlugin) config.getInterceptors().get(0);
    assertThat(plugin.getProperties().size(), is(1));
    assertThat(plugin.getProperties().getProperty("pluginProperty"), is("100"));
    Environment environment = config.getEnvironment();
    assertThat(environment.getId(), is("development"));
    assertThat(environment.getDataSource(), is(instanceOf(UnpooledDataSource.class)));
    assertThat(environment.getTransactionFactory(), is(instanceOf(JdbcTransactionFactory.class)));
    assertThat(config.getDatabaseId(), is("derby"));
    assertThat(config.getMapperRegistry().getMappers().size(), is(4));
    assertThat(config.getMapperRegistry().hasMapper(CachedAuthorMapper.class), is(true));
    assertThat(config.getMapperRegistry().hasMapper(CustomMapper.class), is(true));
    assertThat(config.getMapperRegistry().hasMapper(BlogMapper.class), is(true));
    assertThat(config.getMapperRegistry().hasMapper(NestedBlogMapper.class), is(true));
}
Also used : NestedBlogMapper(org.apache.ibatis.domain.blog.mappers.NestedBlogMapper) BlogMapper(org.apache.ibatis.domain.blog.mappers.BlogMapper) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Set(java.util.Set) Configuration(org.apache.ibatis.session.Configuration) InputStream(java.io.InputStream) NestedBlogMapper(org.apache.ibatis.domain.blog.mappers.NestedBlogMapper) Properties(java.util.Properties) CustomMapper(org.apache.ibatis.builder.mapper.CustomMapper) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) Author(org.apache.ibatis.domain.blog.Author) Environment(org.apache.ibatis.mapping.Environment) Blog(org.apache.ibatis.domain.blog.Blog) Cart(org.apache.ibatis.domain.jpetstore.Cart) Test(org.junit.Test)

Example 24 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class XmlMapperBuilderTest method resolveResultSetTypeWithUndefinedValue.

@Test
public void resolveResultSetTypeWithUndefinedValue() {
    BaseBuilder builder = new BaseBuilder(new Configuration()) {

        {
        }
    };
    expectedException.expect(BuilderException.class);
    expectedException.expectMessage(startsWith("Error resolving ResultSetType. Cause: java.lang.IllegalArgumentException: No enum"));
    expectedException.expectMessage(endsWith("org.apache.ibatis.mapping.ResultSetType.bbb"));
    builder.resolveResultSetType("bbb");
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Test(org.junit.Test)

Example 25 with Configuration

use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.

the class XmlMapperBuilderTest method useCacheRefNamespaceIsUndefined.

@Test
public void useCacheRefNamespaceIsUndefined() {
    MapperBuilderAssistant builder = new MapperBuilderAssistant(new Configuration(), "resource");
    expectedException.expect(IncompleteElementException.class);
    expectedException.expectMessage(is("No cache for namespace 'eee' could be found."));
    builder.useCacheRef("eee");
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Test(org.junit.Test)

Aggregations

Configuration (org.apache.ibatis.session.Configuration)118 Test (org.junit.Test)85 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)30 Environment (org.apache.ibatis.mapping.Environment)19 Reader (java.io.Reader)18 BaseDataTest (org.apache.ibatis.BaseDataTest)17 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)17 BoundSql (org.apache.ibatis.mapping.BoundSql)16 TextSqlNode (org.apache.ibatis.scripting.xmltags.TextSqlNode)16 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)16 Connection (java.sql.Connection)15 MappedStatement (org.apache.ibatis.mapping.MappedStatement)15 DefaultObjectFactory (org.apache.ibatis.reflection.factory.DefaultObjectFactory)13 SqlSession (org.apache.ibatis.session.SqlSession)13 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)13 Properties (java.util.Properties)12 IfSqlNode (org.apache.ibatis.scripting.xmltags.IfSqlNode)12 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)10 WhereSqlNode (org.apache.ibatis.scripting.xmltags.WhereSqlNode)10 Statement (java.sql.Statement)9