Search in sources :

Example 6 with XMLConfigBuilder

use of org.apache.ibatis.builder.xml.XMLConfigBuilder in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method parseIsTwice.

@Test
public void parseIsTwice() throws Exception {
    String resource = "org/apache/ibatis/builder/MinimalMapperConfig.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
    builder.parse();
    expectedException.expect(BuilderException.class);
    expectedException.expectMessage("Each XMLConfigBuilder can only be used once.");
    builder.parse();
}
Also used : InputStream(java.io.InputStream) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) Test(org.junit.Test)

Example 7 with XMLConfigBuilder

use of org.apache.ibatis.builder.xml.XMLConfigBuilder in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method unknownJavaTypeOnTypeHandler.

@Test
public void unknownJavaTypeOnTypeHandler() {
    final String MAPPER_CONFIG = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<!DOCTYPE configuration PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">\n" + "<configuration>\n" + "  <typeAliases>\n" + "    <typeAlias type=\"a.b.c.Foo\"/>\n" + "  </typeAliases>\n" + "</configuration>\n";
    expectedException.expect(BuilderException.class);
    expectedException.expectMessage("Error registering typeAlias for 'null'. Cause: ");
    XMLConfigBuilder builder = new XMLConfigBuilder(new StringReader(MAPPER_CONFIG));
    builder.parse();
}
Also used : StringReader(java.io.StringReader) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) Test(org.junit.Test)

Example 8 with XMLConfigBuilder

use of org.apache.ibatis.builder.xml.XMLConfigBuilder in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method propertiesSpecifyResourceAndUrlAtSameTime.

@Test
public void propertiesSpecifyResourceAndUrlAtSameTime() {
    final String MAPPER_CONFIG = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<!DOCTYPE configuration PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">\n" + "<configuration>\n" + "  <properties resource=\"a/b/c/foo.properties\" url=\"file:./a/b/c/jdbc.properties\"/>\n" + "</configuration>\n";
    expectedException.expect(BuilderException.class);
    expectedException.expectMessage("The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
    XMLConfigBuilder builder = new XMLConfigBuilder(new StringReader(MAPPER_CONFIG));
    builder.parse();
}
Also used : StringReader(java.io.StringReader) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) Test(org.junit.Test)

Example 9 with XMLConfigBuilder

use of org.apache.ibatis.builder.xml.XMLConfigBuilder in project mybatis-3 by mybatis.

the class XmlConfigBuilderTest method registerJavaTypeInitializingTypeHandler.

@Test
public void registerJavaTypeInitializingTypeHandler() {
    final String MAPPER_CONFIG = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<!DOCTYPE configuration PUBLIC \"-//mybatis.org//DTD Config 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-config.dtd\">\n" + "<configuration>\n" + "  <typeHandlers>\n" + "    <typeHandler javaType=\"org.apache.ibatis.builder.XmlConfigBuilderTest$MyEnum\"\n" + "      handler=\"org.apache.ibatis.builder.XmlConfigBuilderTest$EnumOrderTypeHandler\"/>\n" + "  </typeHandlers>\n" + "</configuration>\n";
    XMLConfigBuilder builder = new XMLConfigBuilder(new StringReader(MAPPER_CONFIG));
    builder.parse();
    TypeHandlerRegistry typeHandlerRegistry = builder.getConfiguration().getTypeHandlerRegistry();
    TypeHandler<MyEnum> typeHandler = typeHandlerRegistry.getTypeHandler(MyEnum.class);
    assertTrue(typeHandler instanceof EnumOrderTypeHandler);
    assertArrayEquals(MyEnum.values(), ((EnumOrderTypeHandler) typeHandler).constants);
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) StringReader(java.io.StringReader) XMLConfigBuilder(org.apache.ibatis.builder.xml.XMLConfigBuilder) Test(org.junit.Test)

Aggregations

XMLConfigBuilder (org.apache.ibatis.builder.xml.XMLConfigBuilder)9 Test (org.junit.Test)8 InputStream (java.io.InputStream)4 StringReader (java.io.StringReader)4 Configuration (org.apache.ibatis.session.Configuration)4 ResultSet (java.sql.ResultSet)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Properties (java.util.Properties)1 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)1 CustomMapper (org.apache.ibatis.builder.mapper.CustomMapper)1 Author (org.apache.ibatis.domain.blog.Author)1 Blog (org.apache.ibatis.domain.blog.Blog)1 BlogMapper (org.apache.ibatis.domain.blog.mappers.BlogMapper)1 NestedBlogMapper (org.apache.ibatis.domain.blog.mappers.NestedBlogMapper)1 Cart (org.apache.ibatis.domain.jpetstore.Cart)1 Environment (org.apache.ibatis.mapping.Environment)1 TypeHandlerRegistry (org.apache.ibatis.type.TypeHandlerRegistry)1