From afc0f7701bb65388d165127b4d1d11c3f5b79316 Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Thu, 3 May 2018 18:04:28 +0900 Subject: [PATCH] Change to calling BaseDataTest#runScript on setup test data --- .../autoconstructor/AutoConstructorTest.java | 14 ++----- .../ancestor_ref/AncestorRefTest.java | 14 ++----- .../ArrayResultTypeTest.java | 14 ++----- .../associationtest/AssociationTest.java | 14 ++----- .../associationtype/AssociationTypeTest.java | 14 ++----- .../automapping/AutomappingTest.java | 14 ++----- .../submitted/awful_table/AwfulTableTest.java | 22 +++-------- .../ibatis/submitted/basetest/BaseTest.java | 14 ++----- .../submitted/batch_keys/BatchKeysTest.java | 33 ++++------------ .../submitted/batch_test/BatchTest.java | 16 ++------ .../ibatis/submitted/blobtest/BlobTest.java | 34 ++++------------- .../blocking_cache/BlockingCacheTest.java | 14 ++----- .../ibatis/submitted/cache/CacheTest.java | 14 ++----- .../submitted/cacheorder/CacheOrderTest.java | 17 ++------- .../CallSettersOnNullsTest.java | 15 ++------ .../DoNotCallSettersOnNullsTest.java | 14 ++----- .../camelcase/CamelCaseMappingTest.java | 30 +++------------ .../cglib_lazy_error/CglibNPELazyTest.java | 38 +++++-------------- .../cglib_lazy_error/CglibNPETest.java | 31 ++++----------- .../CollectionParametersTest.java | 14 ++----- .../ColumnForwardingTest.java | 14 ++----- .../column_prefix/ColumnPrefixTest.java | 30 +++------------ .../complex_column/ComplexColumnTest.java | 34 ++++------------- .../complex_property/ComponentTest.java | 31 ++++----------- .../complex_type/ComplexTypeTest.java | 14 ++----- .../ibatis/submitted/count/CountTest.java | 32 +++------------- .../submitted/criterion/CriterionTest.java | 32 +++------------- .../cursor_nested/CursorNestedTest.java | 14 ++----- .../cursor_simple/CursorSimpleTest.java | 14 ++----- .../CustomCollectionHandlingTest.java | 26 +++---------- .../CommonPropertyDeferLoadError.java | 37 +++++------------- .../DmlMapperReturnTypesTest.java | 17 ++------- .../DuplicateStatementsTest.java | 14 ++----- .../ibatis/submitted/dynsql/DynSqlTest.java | 29 ++++---------- .../ibatis/submitted/dynsql2/DynSqlTest.java | 34 ++++------------- .../ReturnInstanceForEmptyRowTest.java | 15 ++------ .../submitted/encoding/EncodingTest.java | 33 +++------------- .../EnumInterfaceTypeHandlerTest.java | 15 ++------ .../EnumTypeHandlerUsingAnnotationTest.java | 35 ++++------------- .../EnumTypeHandlerTest.java | 34 ++++------------- .../ibatis/submitted/extend/ExtendTest.java | 31 +++------------ .../extendresultmap/ExtendResultMapTest.java | 14 ++----- .../NpeExtendsTest.java | 33 ++++------------ .../FlushStatementNpeTest.java | 32 +++------------- .../ForceFlushOnSelectTest.java | 29 +++----------- .../ibatis/submitted/foreach/ForEachTest.java | 14 ++----- .../submitted/foreach_map/ForEachMapTest.java | 16 ++------ .../GenericTypeResolutionTest.java | 14 ++----- .../generictypes/GenericTypesTest.java | 32 +++------------- .../submitted/global_variables/BaseTest.java | 14 ++----- .../HashMapTypeHandlerTest.java | 14 ++----- .../ImmutablePOJOTest.java | 32 +++------------- .../include_property/IncludePropertyTest.java | 14 ++----- .../submitted/includes/IncludeTest.java | 14 ++----- .../inheritance/InheritanceTest.java | 14 ++----- .../AuthorDAOTest.java | 16 ++------ .../InlineCollectionWithDotTest.java | 18 ++------- .../submitted/javassist/JavassistTest.java | 14 ++----- .../keygen/Jdbc3KeyGeneratorTest.java | 14 ++----- .../submitted/language/LanguageTest.java | 34 ++++------------- .../lazy_deserialize/LazyDeserializeTest.java | 38 ++++--------------- .../lazy_immutable/ImmutablePOJOTest.java | 28 +++----------- .../lazy_properties/LazyPropertiesTest.java | 15 ++------ .../CommonPropertyLazyLoadError.java | 32 +++------------- .../AbstractLazyTest.java | 16 ++------ .../mapper_extend/MapperExtendTest.java | 14 ++----- .../MapperTypeParameterTest.java | 14 ++----- .../maptypehandler/MapTypeHandlerTest.java | 16 ++------ .../MissingIdPropertyTest.java | 14 ++----- .../ibatis/submitted/multidb/MultiDbTest.java | 31 +++------------ .../MultipleDiscriminatorTest.java | 34 ++++------------- .../MultipleIteratesTest.java | 14 ++----- .../InvalidNamedConstructorArgsTest.java | 18 ++------- .../NamedConstructorArgsTest.java | 14 ++----- ...NamedConstructorArgsUseActualNameTest.java | 15 ++------ .../submitted/nested/NestedForEachTest.java | 34 ++++------------- .../NestedResultHandlerTest.java | 14 ++----- .../NestedResultHandlerAssociationTest.java | 14 ++----- ...dResultHandlerMultipleAssociationTest.java | 18 +++------ .../no_param_type/NoParamTypeTest.java | 14 ++----- .../NonExistentVariablesTest.java | 32 +++------------- .../not_null_column/NotNullColumnTest.java | 32 +++------------- .../null_associations/FooMapperTest.java | 26 +++++-------- .../submitted/ognl_enum/EnumWithOgnlTest.java | 34 ++++------------- .../submitted/ognlstatic/OgnlStaticTest.java | 14 ++----- .../OrderPrefixRemoved.java | 31 +++------------ .../overwritingproperties/FooMapperTest.java | 26 +++++-------- .../ParametrizedListTest.java | 32 +++------------- .../parent_childs/ParentChildTest.java | 14 ++----- .../parent_reference_3level/BlogTest.java | 30 +++------------ .../permissions/PermissionsTest.java | 15 ++------ .../primitive_array/PrimitiveArrayTest.java | 14 ++----- .../primitive_result_type/IbatisConfig.java | 8 +++- .../PrimitiveResultTypeTest.java | 19 ++-------- .../submitted/primitives/PrimitivesTest.java | 14 ++----- .../PropertiesInMappersTest.java | 14 ++----- .../QuotedColumnNamesTest.java | 30 +++------------ .../raw_sql_source/RawSqlSourceTest.java | 14 ++----- .../result_handler/ResulthandlerTest.java | 14 ++----- .../DefaultResultHandlerTypeTest.java | 27 ++----------- .../ResultMapWithAssociationsTest.java | 14 ++----- .../submitted/results_id/ResultsIdTest.java | 14 ++----- .../rounding/RoundingHandlersTest.java | 14 ++----- .../submitted/selectkey/SelectKeyTest.java | 36 ++++-------------- .../SerializeCircularTest.java | 27 ++----------- .../SimpleListParameterTest.java | 14 ++----- .../ibatis/submitted/sptests/SPTest.java | 36 +++++------------- .../sqlprovider/SqlProviderTest.java | 15 ++------ .../submitted/stringlist/StringListTest.java | 14 ++----- .../SubstitutionInAnnotsTest.java | 23 ++--------- .../typehandler/TypeHandlerTest.java | 14 ++----- .../TypeHandlerInjectionTest.java | 14 ++----- .../default_method/DefaultMethodTest.java | 15 ++------ .../usesjava8/keycolumn/InsertTest.java | 16 ++------ .../MultipleResultTest.java | 16 ++------ .../OptionalOnMapperMethodTest.java | 14 ++----- .../PostgresGeneratedKeysTest.java | 15 ++------ .../usesjava8/refcursor/RefCursorTest.java | 16 ++------ .../UseActualParamNameTest.java | 15 ++------ .../ibatis/submitted/uuid_test/UUIDTest.java | 14 ++----- .../submitted/valueinmap/ValueInMapTest.java | 14 ++----- .../MultipleCrossIncludeTest.java | 36 +++++------------- .../xml_external_ref/MultipleIncludeTest.java | 32 +++++----------- .../MultipleReverseIncludeTest.java | 37 +++++------------- .../NonFullyQualifiedNamespaceTest.java | 35 ++++------------- .../ParameterMapReferenceTest.java | 38 ++++++------------- .../ResultMapExtendsTest.java | 37 +++++------------- .../ResultMapReferenceTest.java | 37 +++++------------- .../xml_external_ref/ReverseIncludeTest.java | 37 +++++------------- .../xml_external_ref/SameIdTest.java | 37 +++++------------- .../xml_external_ref/XmlExternalRefTest.java | 37 +++++------------- .../type/BlobInputStreamTypeHandlerTest.java | 4 +- .../type/ClobReaderTypeHandlerTest.java | 4 +- .../ibatis/type/SqlxmlTypeHandlerTest.java | 14 ++----- 134 files changed, 651 insertions(+), 2258 deletions(-) diff --git a/src/test/java/org/apache/ibatis/autoconstructor/AutoConstructorTest.java b/src/test/java/org/apache/ibatis/autoconstructor/AutoConstructorTest.java index 1f33a729da2..1dd5158503f 100644 --- a/src/test/java/org/apache/ibatis/autoconstructor/AutoConstructorTest.java +++ b/src/test/java/org/apache/ibatis/autoconstructor/AutoConstructorTest.java @@ -15,9 +15,9 @@ */ package org.apache.ibatis.autoconstructor; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -27,7 +27,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; import java.util.List; public class AutoConstructorTest { @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - final SqlSession session = sqlSessionFactory.openSession(); - final Connection conn = session.getConnection(); - final Reader dbReader = Resources.getResourceAsReader("org/apache/ibatis/autoconstructor/CreateDB.sql"); - final ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(dbReader); - conn.close(); - dbReader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/autoconstructor/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/ancestor_ref/AncestorRefTest.java b/src/test/java/org/apache/ibatis/submitted/ancestor_ref/AncestorRefTest.java index ce1bb5fc5a5..32ea57b0084 100644 --- a/src/test/java/org/apache/ibatis/submitted/ancestor_ref/AncestorRefTest.java +++ b/src/test/java/org/apache/ibatis/submitted/ancestor_ref/AncestorRefTest.java @@ -18,10 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -39,15 +38,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/ancestor_ref/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/array_result_type/ArrayResultTypeTest.java b/src/test/java/org/apache/ibatis/submitted/array_result_type/ArrayResultTypeTest.java index 9e97f5e8cc2..31bd17c8ef3 100644 --- a/src/test/java/org/apache/ibatis/submitted/array_result_type/ArrayResultTypeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/array_result_type/ArrayResultTypeTest.java @@ -18,10 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/array_result_type/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/associationtest/AssociationTest.java b/src/test/java/org/apache/ibatis/submitted/associationtest/AssociationTest.java index 612cac54f42..7439ee6583c 100644 --- a/src/test/java/org/apache/ibatis/submitted/associationtest/AssociationTest.java +++ b/src/test/java/org/apache/ibatis/submitted/associationtest/AssociationTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.associationtest; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/associationtest/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/associationtest/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/associationtype/AssociationTypeTest.java b/src/test/java/org/apache/ibatis/submitted/associationtype/AssociationTypeTest.java index 95da647d6ab..5e3bae5a379 100644 --- a/src/test/java/org/apache/ibatis/submitted/associationtype/AssociationTypeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/associationtype/AssociationTypeTest.java @@ -16,14 +16,13 @@ package org.apache.ibatis.submitted.associationtype; import java.io.Reader; -import java.sql.Connection; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.junit.Assert; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -42,15 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/associationtype/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/associationtype/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/automapping/AutomappingTest.java b/src/test/java/org/apache/ibatis/submitted/automapping/AutomappingTest.java index 6b520781a5e..62b8730cc28 100644 --- a/src/test/java/org/apache/ibatis/submitted/automapping/AutomappingTest.java +++ b/src/test/java/org/apache/ibatis/submitted/automapping/AutomappingTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.automapping; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.AutoMappingBehavior; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/automapping/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/automapping/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/awful_table/AwfulTableTest.java b/src/test/java/org/apache/ibatis/submitted/awful_table/AwfulTableTest.java index 2653da2a8f1..6934bd21496 100644 --- a/src/test/java/org/apache/ibatis/submitted/awful_table/AwfulTableTest.java +++ b/src/test/java/org/apache/ibatis/submitted/awful_table/AwfulTableTest.java @@ -18,11 +18,9 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -34,22 +32,12 @@ public class AwfulTableTest { @Before public void setUp() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:attest", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - conn.close(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/MapperConfig.xml"); + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/MapperConfig.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/awful_table/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/basetest/BaseTest.java b/src/test/java/org/apache/ibatis/submitted/basetest/BaseTest.java index 426ed1e57b6..75d50a9dbd9 100644 --- a/src/test/java/org/apache/ibatis/submitted/basetest/BaseTest.java +++ b/src/test/java/org/apache/ibatis/submitted/basetest/BaseTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.basetest; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -39,15 +38,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/basetest/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/basetest/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/batch_keys/BatchKeysTest.java b/src/test/java/org/apache/ibatis/submitted/batch_keys/BatchKeysTest.java index e2d982d23a8..c36bedaf4e2 100644 --- a/src/test/java/org/apache/ibatis/submitted/batch_keys/BatchKeysTest.java +++ b/src/test/java/org/apache/ibatis/submitted/batch_keys/BatchKeysTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +17,18 @@ import static org.junit.Assert.assertEquals; -import java.io.PrintWriter; import java.io.Reader; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.junit.Assert; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -44,29 +42,12 @@ public class BatchKeysTest { @Before public void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/batch_keys/Config.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:batch_keys", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/batch_keys/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(new PrintWriter(System.err)); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/batch_keys/Config.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/batch_keys/CreateDB.sql"); } public void testJdbc3Support() throws Exception { diff --git a/src/test/java/org/apache/ibatis/submitted/batch_test/BatchTest.java b/src/test/java/org/apache/ibatis/submitted/batch_test/BatchTest.java index c81ea4c1d97..1dda0cbc48a 100644 --- a/src/test/java/org/apache/ibatis/submitted/batch_test/BatchTest.java +++ b/src/test/java/org/apache/ibatis/submitted/batch_test/BatchTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.batch_test; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/batch_test/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/batch_test/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/blobtest/BlobTest.java b/src/test/java/org/apache/ibatis/submitted/blobtest/BlobTest.java index 90e84c4b850..0eb01a9a811 100644 --- a/src/test/java/org/apache/ibatis/submitted/blobtest/BlobTest.java +++ b/src/test/java/org/apache/ibatis/submitted/blobtest/BlobTest.java @@ -19,12 +19,10 @@ import static org.junit.Assert.assertTrue; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,30 +34,12 @@ public class BlobTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; - - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:blobtest", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/blobtest/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/blobtest/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/blobtest/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/blobtest/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/blocking_cache/BlockingCacheTest.java b/src/test/java/org/apache/ibatis/submitted/blocking_cache/BlockingCacheTest.java index b76997a2ffb..cdede3cc780 100644 --- a/src/test/java/org/apache/ibatis/submitted/blocking_cache/BlockingCacheTest.java +++ b/src/test/java/org/apache/ibatis/submitted/blocking_cache/BlockingCacheTest.java @@ -16,12 +16,11 @@ package org.apache.ibatis.submitted.blocking_cache; import java.io.Reader; -import java.sql.Connection; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -42,15 +41,8 @@ public void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/blocking_cache/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/blocking_cache/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/cache/CacheTest.java b/src/test/java/org/apache/ibatis/submitted/cache/CacheTest.java index fbfd2de772e..f03143e6ab3 100644 --- a/src/test/java/org/apache/ibatis/submitted/cache/CacheTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cache/CacheTest.java @@ -17,8 +17,8 @@ import java.io.Reader; import java.lang.reflect.Field; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.annotations.CacheNamespace; import org.apache.ibatis.annotations.Property; import org.apache.ibatis.cache.Cache; @@ -26,7 +26,6 @@ import org.apache.ibatis.annotations.CacheNamespaceRef; import org.apache.ibatis.builder.BuilderException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -50,15 +49,8 @@ public void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cache/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/cache/CreateDB.sql"); } /* diff --git a/src/test/java/org/apache/ibatis/submitted/cacheorder/CacheOrderTest.java b/src/test/java/org/apache/ibatis/submitted/cacheorder/CacheOrderTest.java index b3c123d5519..9fa42b23e5d 100644 --- a/src/test/java/org/apache/ibatis/submitted/cacheorder/CacheOrderTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cacheorder/CacheOrderTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,13 +18,11 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.cache.Cache; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.MappedStatement; -import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.BeforeClass; @@ -42,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cacheorder/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/cacheorder/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/CallSettersOnNullsTest.java b/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/CallSettersOnNullsTest.java index 3b84c63eea4..3d29486daa0 100644 --- a/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/CallSettersOnNullsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/CallSettersOnNullsTest.java @@ -15,8 +15,8 @@ */ package org.apache.ibatis.submitted.call_setters_on_nulls; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -25,7 +25,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; import java.util.List; import java.util.Map; @@ -42,16 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/call_setters_on_nulls/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/DoNotCallSettersOnNullsTest.java b/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/DoNotCallSettersOnNullsTest.java index 81deb4f8c21..0774d344d1e 100644 --- a/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/DoNotCallSettersOnNullsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/DoNotCallSettersOnNullsTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.call_setters_on_nulls; import java.io.Reader; -import java.sql.Connection; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/call_setters_on_nulls/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/call_setters_on_nulls/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/camelcase/CamelCaseMappingTest.java b/src/test/java/org/apache/ibatis/submitted/camelcase/CamelCaseMappingTest.java index 7e9b4a96c23..e52cc9c121f 100644 --- a/src/test/java/org/apache/ibatis/submitted/camelcase/CamelCaseMappingTest.java +++ b/src/test/java/org/apache/ibatis/submitted/camelcase/CamelCaseMappingTest.java @@ -16,13 +16,11 @@ package org.apache.ibatis.submitted.camelcase; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,28 +34,12 @@ public class CamelCaseMappingTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/camelcase/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:gname", "sa", ""); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/camelcase/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/camelcase/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/camelcase/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPELazyTest.java b/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPELazyTest.java index 1140a00ac06..3050890572e 100644 --- a/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPELazyTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPELazyTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2015 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,9 @@ package org.apache.ibatis.submitted.cglib_lazy_error; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -34,32 +32,14 @@ public class CglibNPELazyTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/ibatisConfigLazy.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + sqlSessionFactory.getConfiguration().setLazyLoadingEnabled(true); + sqlSessionFactory.getConfiguration().setAggressiveLazyLoading(false); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:cglib_lazy_error", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/ibatisConfigLazy.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - sqlSessionFactory.getConfiguration().setLazyLoadingEnabled(true); - sqlSessionFactory.getConfiguration().setAggressiveLazyLoading(false); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/cglib_lazy_error/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPETest.java b/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPETest.java index e7b90fd4106..df57761cb0c 100644 --- a/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPETest.java +++ b/src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/CglibNPETest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2015 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.sql.Connection; import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; @@ -34,30 +35,12 @@ public class CglibNPETest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:cglib_lazy_eager_no_error", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/cglib_lazy_error/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/collectionparameters/CollectionParametersTest.java b/src/test/java/org/apache/ibatis/submitted/collectionparameters/CollectionParametersTest.java index cbaf3861776..2af6436a9a6 100644 --- a/src/test/java/org/apache/ibatis/submitted/collectionparameters/CollectionParametersTest.java +++ b/src/test/java/org/apache/ibatis/submitted/collectionparameters/CollectionParametersTest.java @@ -16,14 +16,13 @@ package org.apache.ibatis.submitted.collectionparameters; import java.io.Reader; -import java.sql.Connection; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -43,15 +42,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/collectionparameters/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/collectionparameters/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/column_forwarding/ColumnForwardingTest.java b/src/test/java/org/apache/ibatis/submitted/column_forwarding/ColumnForwardingTest.java index e32858c7025..8075264a208 100644 --- a/src/test/java/org/apache/ibatis/submitted/column_forwarding/ColumnForwardingTest.java +++ b/src/test/java/org/apache/ibatis/submitted/column_forwarding/ColumnForwardingTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.column_forwarding; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -39,15 +38,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_forwarding/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/column_forwarding/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/column_prefix/ColumnPrefixTest.java b/src/test/java/org/apache/ibatis/submitted/column_prefix/ColumnPrefixTest.java index 5ce6a50f0e9..a6a2a47a037 100644 --- a/src/test/java/org/apache/ibatis/submitted/column_prefix/ColumnPrefixTest.java +++ b/src/test/java/org/apache/ibatis/submitted/column_prefix/ColumnPrefixTest.java @@ -18,12 +18,10 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,28 +34,12 @@ public class ColumnPrefixTest { @Before public void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader(getConfigPath()); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:clmpfx", "sa", ""); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_prefix/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader(getConfigPath()); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/column_prefix/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/complex_column/ComplexColumnTest.java b/src/test/java/org/apache/ibatis/submitted/complex_column/ComplexColumnTest.java index 8351c34e56e..a685540a95e 100644 --- a/src/test/java/org/apache/ibatis/submitted/complex_column/ComplexColumnTest.java +++ b/src/test/java/org/apache/ibatis/submitted/complex_column/ComplexColumnTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2016 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ package org.apache.ibatis.submitted.complex_column; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -25,8 +25,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; public class ComplexColumnTest { @@ -34,30 +32,12 @@ public class ComplexColumnTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_column/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:complex_column", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_column/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_column/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/complex_column/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/complex_property/ComponentTest.java b/src/test/java/org/apache/ibatis/submitted/complex_property/ComponentTest.java index 06800f7f2bd..6eabf10a551 100644 --- a/src/test/java/org/apache/ibatis/submitted/complex_property/ComponentTest.java +++ b/src/test/java/org/apache/ibatis/submitted/complex_property/ComponentTest.java @@ -16,18 +16,16 @@ package org.apache.ibatis.submitted.complex_property; import static org.junit.Assert.assertNotNull; + +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.BeforeClass; import org.junit.Test; -import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.SQLException; import java.util.Calendar; public class ComponentTest { @@ -35,8 +33,12 @@ public class ComponentTest { @BeforeClass public static void setup() throws Exception { - setupSqlSessionFactory(); - runDBScript(); + String resource = "org/apache/ibatis/submitted/complex_property/Configuration.xml"; + Reader reader = Resources.getResourceAsReader(resource); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/complex_property/db.sql"); } @@ -61,21 +63,4 @@ public void shouldInsertNestedPasswordFieldOfComplexType() throws Exception { } } - private static void runDBScript() throws SQLException, IOException { - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - String resource = "org/apache/ibatis/submitted/complex_property/db.sql"; - Reader reader = Resources.getResourceAsReader(resource); - runner.runScript(reader); - conn.close(); - } - - private static void setupSqlSessionFactory() throws IOException { - String resource = "org/apache/ibatis/submitted/complex_property/Configuration.xml"; - Reader reader = Resources.getResourceAsReader(resource); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - } - } diff --git a/src/test/java/org/apache/ibatis/submitted/complex_type/ComplexTypeTest.java b/src/test/java/org/apache/ibatis/submitted/complex_type/ComplexTypeTest.java index 581db694911..6987b2bfadb 100644 --- a/src/test/java/org/apache/ibatis/submitted/complex_type/ComplexTypeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/complex_type/ComplexTypeTest.java @@ -16,12 +16,11 @@ package org.apache.ibatis.submitted.complex_type; import java.io.Reader; -import java.sql.Connection; import java.util.ArrayList; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/complex_type/CreateDB.sql"); } // see https://issues.apache.org/jira/browse/IBATIS-653 diff --git a/src/test/java/org/apache/ibatis/submitted/count/CountTest.java b/src/test/java/org/apache/ibatis/submitted/count/CountTest.java index df1afdb89d1..cf425372cc8 100644 --- a/src/test/java/org/apache/ibatis/submitted/count/CountTest.java +++ b/src/test/java/org/apache/ibatis/submitted/count/CountTest.java @@ -18,11 +18,9 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -35,30 +33,12 @@ public class CountTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/count/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:gname", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/count/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/count/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/count/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/criterion/CriterionTest.java b/src/test/java/org/apache/ibatis/submitted/criterion/CriterionTest.java index ef1768bf533..1f9ca1955a5 100644 --- a/src/test/java/org/apache/ibatis/submitted/criterion/CriterionTest.java +++ b/src/test/java/org/apache/ibatis/submitted/criterion/CriterionTest.java @@ -18,13 +18,11 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -37,30 +35,12 @@ public class CriterionTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/criterion/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:aname", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/criterion/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/criterion/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/criterion/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_nested/CursorNestedTest.java b/src/test/java/org/apache/ibatis/submitted/cursor_nested/CursorNestedTest.java index 046f9fe7a84..d75642b7741 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_nested/CursorNestedTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cursor_nested/CursorNestedTest.java @@ -15,9 +15,9 @@ */ package org.apache.ibatis.submitted.cursor_nested; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.cursor.Cursor; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -27,7 +27,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; import java.util.Iterator; public class CursorNestedTest { @@ -42,15 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cursor_nested/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/cursor_nested/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java b/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java index 7f192387b74..f654ba97e96 100644 --- a/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java +++ b/src/test/java/org/apache/ibatis/submitted/cursor_simple/CursorSimpleTest.java @@ -15,9 +15,9 @@ */ package org.apache.ibatis.submitted.cursor_simple; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.cursor.Cursor; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -28,7 +28,6 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -46,15 +45,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cursor_simple/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/cursor_simple/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/custom_collection_handling/CustomCollectionHandlingTest.java b/src/test/java/org/apache/ibatis/submitted/custom_collection_handling/CustomCollectionHandlingTest.java index e0c490d34f2..c51435a108f 100644 --- a/src/test/java/org/apache/ibatis/submitted/custom_collection_handling/CustomCollectionHandlingTest.java +++ b/src/test/java/org/apache/ibatis/submitted/custom_collection_handling/CustomCollectionHandlingTest.java @@ -18,13 +18,12 @@ import static org.junit.Assert.*; import java.io.IOException; -import java.io.PrintWriter; import java.io.Reader; -import java.sql.Connection; import java.sql.SQLException; import java.util.List; + +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -76,26 +75,13 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig(String resource) throws SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/custom_collection_handling/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(new PrintWriter(System.err)); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/custom_collection_handling/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/deferload_common_property/CommonPropertyDeferLoadError.java b/src/test/java/org/apache/ibatis/submitted/deferload_common_property/CommonPropertyDeferLoadError.java index 8f950ebea0f..a6311470a03 100644 --- a/src/test/java/org/apache/ibatis/submitted/deferload_common_property/CommonPropertyDeferLoadError.java +++ b/src/test/java/org/apache/ibatis/submitted/deferload_common_property/CommonPropertyDeferLoadError.java @@ -18,13 +18,11 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.ArrayList; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.SqlSession; @@ -40,32 +38,15 @@ public class CommonPropertyDeferLoadError { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/deferload_common_property/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/deferload_common_property/lazyLoadIbatisConfig.xml"); + lazyLoadSqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:deferload_common_property", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/deferload_common_property/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/deferload_common_property/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/deferload_common_property/lazyLoadIbatisConfig.xml"); - lazyLoadSqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/deferload_common_property/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/dml_return_types/DmlMapperReturnTypesTest.java b/src/test/java/org/apache/ibatis/submitted/dml_return_types/DmlMapperReturnTypesTest.java index fa3d83932ab..915e931a972 100644 --- a/src/test/java/org/apache/ibatis/submitted/dml_return_types/DmlMapperReturnTypesTest.java +++ b/src/test/java/org/apache/ibatis/submitted/dml_return_types/DmlMapperReturnTypesTest.java @@ -15,8 +15,8 @@ */ package org.apache.ibatis.submitted.dml_return_types; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -26,7 +26,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; import static org.junit.Assert.assertEquals; @@ -51,18 +50,8 @@ public static void setUp() throws Exception { } // populate in-memory database - try (SqlSession session = sqlSessionFactory.openSession()) { - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader(SQL); - try { - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - } finally { - reader.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), SQL); + } @Before diff --git a/src/test/java/org/apache/ibatis/submitted/duplicate_statements/DuplicateStatementsTest.java b/src/test/java/org/apache/ibatis/submitted/duplicate_statements/DuplicateStatementsTest.java index 15581f9f54c..a248b271ddd 100644 --- a/src/test/java/org/apache/ibatis/submitted/duplicate_statements/DuplicateStatementsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/duplicate_statements/DuplicateStatementsTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.duplicate_statements; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -42,15 +41,8 @@ public void setupDb() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/duplicate_statements/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/duplicate_statements/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/dynsql/DynSqlTest.java b/src/test/java/org/apache/ibatis/submitted/dynsql/DynSqlTest.java index ae03046d035..20edded14bf 100644 --- a/src/test/java/org/apache/ibatis/submitted/dynsql/DynSqlTest.java +++ b/src/test/java/org/apache/ibatis/submitted/dynsql/DynSqlTest.java @@ -18,8 +18,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -29,7 +29,6 @@ import java.io.Reader; import java.math.BigDecimal; import java.math.BigInteger; -import java.sql.Connection; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -40,26 +39,12 @@ public class DynSqlTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; - try { - Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/dynsql/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); - configReader.close(); - conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/dynsql/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - - } finally { - if (conn != null) { - conn.close(); - } - } + Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/dynsql/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); + configReader.close(); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/dynsql/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/dynsql2/DynSqlTest.java b/src/test/java/org/apache/ibatis/submitted/dynsql2/DynSqlTest.java index 4f9660c474a..7f912666a1b 100644 --- a/src/test/java/org/apache/ibatis/submitted/dynsql2/DynSqlTest.java +++ b/src/test/java/org/apache/ibatis/submitted/dynsql2/DynSqlTest.java @@ -19,14 +19,12 @@ import static org.junit.Assert.assertTrue; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,30 +38,12 @@ public class DynSqlTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; - - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:bname", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/dynsql2/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/dynsql2/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/dynsql2/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/dynsql2/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/empty_row/ReturnInstanceForEmptyRowTest.java b/src/test/java/org/apache/ibatis/submitted/empty_row/ReturnInstanceForEmptyRowTest.java index db1a844a98c..c775a8adace 100644 --- a/src/test/java/org/apache/ibatis/submitted/empty_row/ReturnInstanceForEmptyRowTest.java +++ b/src/test/java/org/apache/ibatis/submitted/empty_row/ReturnInstanceForEmptyRowTest.java @@ -18,11 +18,10 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -43,16 +42,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/empty_row/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/empty_row/CreateDB.sql"); } @Before diff --git a/src/test/java/org/apache/ibatis/submitted/encoding/EncodingTest.java b/src/test/java/org/apache/ibatis/submitted/encoding/EncodingTest.java index bb2ea2e3976..97f7c1ca6dc 100644 --- a/src/test/java/org/apache/ibatis/submitted/encoding/EncodingTest.java +++ b/src/test/java/org/apache/ibatis/submitted/encoding/EncodingTest.java @@ -19,11 +19,9 @@ import java.io.Reader; import java.nio.charset.Charset; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,37 +34,18 @@ public class EncodingTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/encoding/EncodingConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - // save charset Charset charset = Resources.getCharset(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:encoding", "sa", ""); - // make sure that the SQL file has been saved in UTF-8! Resources.setCharset(Charset.forName("utf-8")); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/encoding/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/encoding/EncodingConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/encoding/CreateDB.sql"); } finally { - // restore charset Resources.setCharset(charset); - - if (conn != null) { - conn.close(); - } } } diff --git a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java index e19152f8478..281215e8a64 100644 --- a/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/enum_interface_type_handler/EnumInterfaceTypeHandlerTest.java @@ -18,10 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -41,16 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/enum_interface_type_handler/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/enum_interface_type_handler/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_annotation/EnumTypeHandlerUsingAnnotationTest.java b/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_annotation/EnumTypeHandlerUsingAnnotationTest.java index 444d06d15a3..9c5865613d6 100644 --- a/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_annotation/EnumTypeHandlerUsingAnnotationTest.java +++ b/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_annotation/EnumTypeHandlerUsingAnnotationTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2016 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,8 @@ */ package org.apache.ibatis.submitted.enumtypehandler_on_annotation; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -26,8 +26,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import static org.assertj.core.api.Assertions.assertThat; @@ -49,30 +47,13 @@ public class EnumTypeHandlerUsingAnnotationTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/enumtypehandler_on_annotation/mybatis-config.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + sqlSessionFactory.getConfiguration().getMapperRegistry().addMapper(PersonMapper.class); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:enumtypehandler_on_annotation", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/enumtypehandler_on_annotation/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/enumtypehandler_on_annotation/mybatis-config.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - sqlSessionFactory.getConfiguration().getMapperRegistry().addMapper(PersonMapper.class); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/enumtypehandler_on_annotation/CreateDB.sql"); } @Before diff --git a/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_map/EnumTypeHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_map/EnumTypeHandlerTest.java index 9f119a0f70a..fa76ae78a9c 100644 --- a/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_map/EnumTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/enumtypehandler_on_map/EnumTypeHandlerTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2015 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,10 @@ package org.apache.ibatis.submitted.enumtypehandler_on_map; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -37,30 +35,12 @@ public class EnumTypeHandlerTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/enumtypehandler_on_map/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:enumtypehandler_on_map", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/enumtypehandler_on_map/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/enumtypehandler_on_map/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/enumtypehandler_on_map/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/extend/ExtendTest.java b/src/test/java/org/apache/ibatis/submitted/extend/ExtendTest.java index 7db3d585fff..76e1c009001 100644 --- a/src/test/java/org/apache/ibatis/submitted/extend/ExtendTest.java +++ b/src/test/java/org/apache/ibatis/submitted/extend/ExtendTest.java @@ -18,11 +18,9 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -35,29 +33,12 @@ public class ExtendTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/extend/ExtendConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:extend", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/extend/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/extend/ExtendConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/extend/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/extendresultmap/ExtendResultMapTest.java b/src/test/java/org/apache/ibatis/submitted/extendresultmap/ExtendResultMapTest.java index f2f560c4daa..b179874c6e7 100644 --- a/src/test/java/org/apache/ibatis/submitted/extendresultmap/ExtendResultMapTest.java +++ b/src/test/java/org/apache/ibatis/submitted/extendresultmap/ExtendResultMapTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.extendresultmap; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -38,15 +37,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/extendresultmap/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/extendresultmap/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/extends_with_constructor/NpeExtendsTest.java b/src/test/java/org/apache/ibatis/submitted/extends_with_constructor/NpeExtendsTest.java index 27da8b2f01e..186024766ac 100644 --- a/src/test/java/org/apache/ibatis/submitted/extends_with_constructor/NpeExtendsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/extends_with_constructor/NpeExtendsTest.java @@ -17,14 +17,10 @@ import static org.junit.Assert.*; -import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.Properties; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.AutoMappingBehavior; import org.apache.ibatis.session.Configuration; @@ -41,28 +37,15 @@ * @author poitrac */ public class NpeExtendsTest { - @BeforeClass - public static void initDatabase() throws Exception { - Connection conn = null; - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:extends_with_constructor", "sa", - ""); + private static SqlSessionFactory sqlSessionFactory; - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/extends_with_constructor/CreateDB.sql"); + @BeforeClass + public static void initDatabase() throws Exception { + sqlSessionFactory = getSqlSessionFactoryWithConstructor(); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/extends_with_constructor/CreateDB.sql"); } @Test @@ -80,7 +63,7 @@ public void testWithConstructorConfiguration() { configuration.getMappedStatementNames(); } - private SqlSessionFactory getSqlSessionFactoryWithConstructor() { + private static SqlSessionFactory getSqlSessionFactoryWithConstructor() { UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory(); Properties properties = new Properties(); properties.setProperty("driver", "org.hsqldb.jdbcDriver"); diff --git a/src/test/java/org/apache/ibatis/submitted/flush_statement_npe/FlushStatementNpeTest.java b/src/test/java/org/apache/ibatis/submitted/flush_statement_npe/FlushStatementNpeTest.java index 5d3704085ca..88585c1cdfa 100644 --- a/src/test/java/org/apache/ibatis/submitted/flush_statement_npe/FlushStatementNpeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/flush_statement_npe/FlushStatementNpeTest.java @@ -16,11 +16,9 @@ package org.apache.ibatis.submitted.flush_statement_npe; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -34,30 +32,12 @@ public class FlushStatementNpeTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/flush_statement_npe/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:flush_statement_npe", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/flush_statement_npe/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/flush_statement_npe/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/flush_statement_npe/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/force_flush_on_select/ForceFlushOnSelectTest.java b/src/test/java/org/apache/ibatis/submitted/force_flush_on_select/ForceFlushOnSelectTest.java index e185d2bc215..fb5313981c4 100644 --- a/src/test/java/org/apache/ibatis/submitted/force_flush_on_select/ForceFlushOnSelectTest.java +++ b/src/test/java/org/apache/ibatis/submitted/force_flush_on_select/ForceFlushOnSelectTest.java @@ -19,13 +19,12 @@ import java.io.Reader; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.LocalCacheScope; import org.apache.ibatis.session.SqlSession; @@ -40,28 +39,12 @@ public class ForceFlushOnSelectTest { @Before public void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/force_flush_on_select/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:force_flush_on_select", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/force_flush_on_select/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/force_flush_on_select/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/force_flush_on_select/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/foreach/ForEachTest.java b/src/test/java/org/apache/ibatis/submitted/foreach/ForEachTest.java index c21347d8c4d..d922a3f1f4d 100644 --- a/src/test/java/org/apache/ibatis/submitted/foreach/ForEachTest.java +++ b/src/test/java/org/apache/ibatis/submitted/foreach/ForEachTest.java @@ -16,14 +16,13 @@ package org.apache.ibatis.submitted.foreach; import java.io.Reader; -import java.sql.Connection; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -46,15 +45,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/foreach/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/foreach_map/ForEachMapTest.java b/src/test/java/org/apache/ibatis/submitted/foreach_map/ForEachMapTest.java index 8ae495701be..a724bdee431 100644 --- a/src/test/java/org/apache/ibatis/submitted/foreach_map/ForEachMapTest.java +++ b/src/test/java/org/apache/ibatis/submitted/foreach_map/ForEachMapTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.foreach_map; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -42,15 +41,8 @@ public static void setUpClass() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach_map/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/foreach_map/CreateDB.sql"); } @Before diff --git a/src/test/java/org/apache/ibatis/submitted/generictyperesolution/GenericTypeResolutionTest.java b/src/test/java/org/apache/ibatis/submitted/generictyperesolution/GenericTypeResolutionTest.java index 814e089c361..0f09c47ca14 100644 --- a/src/test/java/org/apache/ibatis/submitted/generictyperesolution/GenericTypeResolutionTest.java +++ b/src/test/java/org/apache/ibatis/submitted/generictyperesolution/GenericTypeResolutionTest.java @@ -18,10 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/generictyperesolution/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/generictyperesolution/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/generictypes/GenericTypesTest.java b/src/test/java/org/apache/ibatis/submitted/generictypes/GenericTypesTest.java index 93f9c70dfdc..6d8ed9365db 100644 --- a/src/test/java/org/apache/ibatis/submitted/generictypes/GenericTypesTest.java +++ b/src/test/java/org/apache/ibatis/submitted/generictypes/GenericTypesTest.java @@ -15,15 +15,12 @@ */ package org.apache.ibatis.submitted.generictypes; -import java.io.PrintWriter; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.junit.Assert; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,29 +33,12 @@ public class GenericTypesTest { @Before public void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/generictypes/Config.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:generictypes", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/generictypes/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(new PrintWriter(System.err)); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/generictypes/Config.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/generictypes/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/global_variables/BaseTest.java b/src/test/java/org/apache/ibatis/submitted/global_variables/BaseTest.java index ad4639361f5..92bd48bffb3 100644 --- a/src/test/java/org/apache/ibatis/submitted/global_variables/BaseTest.java +++ b/src/test/java/org/apache/ibatis/submitted/global_variables/BaseTest.java @@ -17,11 +17,10 @@ import java.io.Reader; import java.lang.reflect.Field; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.cache.Cache; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/global_variables/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/hashmaptypehandler/HashMapTypeHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/hashmaptypehandler/HashMapTypeHandlerTest.java index 641acd28a36..30398bbca7f 100644 --- a/src/test/java/org/apache/ibatis/submitted/hashmaptypehandler/HashMapTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/hashmaptypehandler/HashMapTypeHandlerTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.hashmaptypehandler; import java.io.Reader; -import java.sql.Connection; import java.util.HashMap; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/hashmaptypehandler/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/hashmaptypehandler/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/immutable_constructor/ImmutablePOJOTest.java b/src/test/java/org/apache/ibatis/submitted/immutable_constructor/ImmutablePOJOTest.java index de697c9c673..20e8a576dec 100644 --- a/src/test/java/org/apache/ibatis/submitted/immutable_constructor/ImmutablePOJOTest.java +++ b/src/test/java/org/apache/ibatis/submitted/immutable_constructor/ImmutablePOJOTest.java @@ -15,14 +15,11 @@ */ package org.apache.ibatis.submitted.immutable_constructor; -import java.io.PrintWriter; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -41,29 +38,12 @@ public final class ImmutablePOJOTest { @BeforeClass public static void setupClass() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/immutable_constructor/ibatisConfig.xml"); + factory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:immutable_constructor", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/immutable_constructor/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(new PrintWriter(System.err)); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/immutable_constructor/ibatisConfig.xml"); - factory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(factory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/immutable_constructor/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/include_property/IncludePropertyTest.java b/src/test/java/org/apache/ibatis/submitted/include_property/IncludePropertyTest.java index a80d1acf871..815c461f678 100644 --- a/src/test/java/org/apache/ibatis/submitted/include_property/IncludePropertyTest.java +++ b/src/test/java/org/apache/ibatis/submitted/include_property/IncludePropertyTest.java @@ -18,13 +18,12 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -43,15 +42,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/include_property/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/include_property/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/includes/IncludeTest.java b/src/test/java/org/apache/ibatis/submitted/includes/IncludeTest.java index 1c8e4e2191f..5cc219e530e 100755 --- a/src/test/java/org/apache/ibatis/submitted/includes/IncludeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/includes/IncludeTest.java @@ -15,15 +15,14 @@ */ package org.apache.ibatis.submitted.includes; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.BeforeClass; import org.junit.Test; import java.io.Reader; -import java.sql.Connection; import java.util.Map; import org.apache.ibatis.session.SqlSession; @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/includes/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/includes/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/inheritance/InheritanceTest.java b/src/test/java/org/apache/ibatis/submitted/inheritance/InheritanceTest.java index d30805a906a..c6b3eb723e4 100644 --- a/src/test/java/org/apache/ibatis/submitted/inheritance/InheritanceTest.java +++ b/src/test/java/org/apache/ibatis/submitted/inheritance/InheritanceTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.inheritance; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/inheritance/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/inheritance/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/initialized_collection_property/AuthorDAOTest.java b/src/test/java/org/apache/ibatis/submitted/initialized_collection_property/AuthorDAOTest.java index 514db697c2c..1a48d8010c3 100755 --- a/src/test/java/org/apache/ibatis/submitted/initialized_collection_property/AuthorDAOTest.java +++ b/src/test/java/org/apache/ibatis/submitted/initialized_collection_property/AuthorDAOTest.java @@ -15,8 +15,8 @@ */ package org.apache.ibatis.submitted.initialized_collection_property; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -27,7 +27,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; import java.util.List; public class AuthorDAOTest { @@ -39,17 +38,10 @@ public static void testGetMessageForEmptyDatabase() throws Exception { final String resource = "org/apache/ibatis/submitted/initialized_collection_property/mybatis-config.xml"; Reader reader = Resources.getResourceAsReader(resource); factory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - SqlSession session = factory.openSession(); - - Connection conn = session.getConnection(); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/initialized_collection_property/create.sql"); - runner.runScript(reader); - conn.close(); - session.close(); + BaseDataTest.runScript(factory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/initialized_collection_property/create.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/inline_association_with_dot/InlineCollectionWithDotTest.java b/src/test/java/org/apache/ibatis/submitted/inline_association_with_dot/InlineCollectionWithDotTest.java index 21705751f88..1c89983ce6c 100644 --- a/src/test/java/org/apache/ibatis/submitted/inline_association_with_dot/InlineCollectionWithDotTest.java +++ b/src/test/java/org/apache/ibatis/submitted/inline_association_with_dot/InlineCollectionWithDotTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,9 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -47,17 +46,8 @@ public void openSession(String aConfig) throws Exception { batisConfigReader.close(); - SqlSession session = sqlSessionFactory.openSession(); - - Connection conn = session.getConnection(); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - Reader createScriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/inline_association_with_dot/create.sql"); - runner.runScript(createScriptReader); - createScriptReader.close(); - conn.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/inline_association_with_dot/create.sql"); sqlSession = sqlSessionFactory.openSession(); } diff --git a/src/test/java/org/apache/ibatis/submitted/javassist/JavassistTest.java b/src/test/java/org/apache/ibatis/submitted/javassist/JavassistTest.java index 3572859602b..d56e63c5f1a 100644 --- a/src/test/java/org/apache/ibatis/submitted/javassist/JavassistTest.java +++ b/src/test/java/org/apache/ibatis/submitted/javassist/JavassistTest.java @@ -18,12 +18,11 @@ import static org.junit.Assert.assertTrue; import java.io.Reader; -import java.sql.Connection; import javassist.util.proxy.Proxy; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -43,15 +42,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/javassist/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/javassist/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java b/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java index ddbb439d18d..a2dc683cbf9 100644 --- a/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java +++ b/src/test/java/org/apache/ibatis/submitted/keygen/Jdbc3KeyGeneratorTest.java @@ -18,13 +18,12 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.ArrayList; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -49,15 +48,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keygen/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/keygen/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/language/LanguageTest.java b/src/test/java/org/apache/ibatis/submitted/language/LanguageTest.java index e929e375bb0..f449aba21e8 100644 --- a/src/test/java/org/apache/ibatis/submitted/language/LanguageTest.java +++ b/src/test/java/org/apache/ibatis/submitted/language/LanguageTest.java @@ -16,13 +16,12 @@ package org.apache.ibatis.submitted.language; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.HashMap; import java.util.List; import java.util.Map; + +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,29 +39,12 @@ public class LanguageTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; - - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:language", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/language/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/language/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/language/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/language/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/lazy_deserialize/LazyDeserializeTest.java b/src/test/java/org/apache/ibatis/submitted/lazy_deserialize/LazyDeserializeTest.java index 669de047334..5f68669c9aa 100644 --- a/src/test/java/org/apache/ibatis/submitted/lazy_deserialize/LazyDeserializeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/lazy_deserialize/LazyDeserializeTest.java @@ -21,19 +21,15 @@ import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.PrintWriter; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.executor.ExecutorException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -54,31 +50,13 @@ public static Configuration getConfiguration() { @Before public void setupClass() throws Exception { - Connection conn = null; - - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:lazy_deserialize", "sa", ""); - - Reader reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/lazy_deserialize/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(new PrintWriter(System.err)); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/lazy_deserialize/ibatisConfig.xml"); - factory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + Reader reader = Resources + .getResourceAsReader("org/apache/ibatis/submitted/lazy_deserialize/ibatisConfig.xml"); + factory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + + BaseDataTest.runScript(factory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/lazy_deserialize/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/lazy_immutable/ImmutablePOJOTest.java b/src/test/java/org/apache/ibatis/submitted/lazy_immutable/ImmutablePOJOTest.java index 57fdc395be9..7e8668831a6 100644 --- a/src/test/java/org/apache/ibatis/submitted/lazy_immutable/ImmutablePOJOTest.java +++ b/src/test/java/org/apache/ibatis/submitted/lazy_immutable/ImmutablePOJOTest.java @@ -15,6 +15,7 @@ */ package org.apache.ibatis.submitted.lazy_immutable; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.ScriptRunner; @@ -38,29 +39,12 @@ public final class ImmutablePOJOTest { @BeforeClass public static void setupClass() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazy_immutable/ibatisConfig.xml"); + factory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:lazy_immutable", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazy_immutable/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(new PrintWriter(System.err)); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazy_immutable/ibatisConfig.xml"); - factory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(factory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/lazy_immutable/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/lazy_properties/LazyPropertiesTest.java b/src/test/java/org/apache/ibatis/submitted/lazy_properties/LazyPropertiesTest.java index c94c48546ab..7214dcfb3b6 100644 --- a/src/test/java/org/apache/ibatis/submitted/lazy_properties/LazyPropertiesTest.java +++ b/src/test/java/org/apache/ibatis/submitted/lazy_properties/LazyPropertiesTest.java @@ -18,15 +18,14 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.Collections; import java.util.HashSet; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.executor.loader.ProxyFactory; import org.apache.ibatis.executor.loader.cglib.CglibProxyFactory; import org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -47,16 +46,8 @@ public void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/lazy_properties/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/lazy_properties/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/lazyload_common_property/CommonPropertyLazyLoadError.java b/src/test/java/org/apache/ibatis/submitted/lazyload_common_property/CommonPropertyLazyLoadError.java index 29c89a50481..67ff6db7e11 100644 --- a/src/test/java/org/apache/ibatis/submitted/lazyload_common_property/CommonPropertyLazyLoadError.java +++ b/src/test/java/org/apache/ibatis/submitted/lazyload_common_property/CommonPropertyLazyLoadError.java @@ -16,11 +16,9 @@ package org.apache.ibatis.submitted.lazyload_common_property; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -33,30 +31,12 @@ public class CommonPropertyLazyLoadError { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_common_property/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:lazyload_common_property", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_common_property/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_common_property/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/lazyload_common_property/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/AbstractLazyTest.java b/src/test/java/org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/AbstractLazyTest.java index 0b99d01a7eb..4ccfb849ee4 100644 --- a/src/test/java/org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/AbstractLazyTest.java +++ b/src/test/java/org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/AbstractLazyTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.lazyload_proxyfactory_comparison; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -44,15 +43,8 @@ public void before() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/lazyload_proxyfactory_comparison/CreateDB.sql"); sqlSession = sqlSessionFactory.openSession(); mapper = sqlSession.getMapper(Mapper.class); diff --git a/src/test/java/org/apache/ibatis/submitted/mapper_extend/MapperExtendTest.java b/src/test/java/org/apache/ibatis/submitted/mapper_extend/MapperExtendTest.java index f265bddfa64..f988448ff2c 100644 --- a/src/test/java/org/apache/ibatis/submitted/mapper_extend/MapperExtendTest.java +++ b/src/test/java/org/apache/ibatis/submitted/mapper_extend/MapperExtendTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.mapper_extend; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.binding.BindingException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -43,15 +42,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/mapper_extend/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/mapper_extend/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/MapperTypeParameterTest.java b/src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/MapperTypeParameterTest.java index 189d0a71366..0db35c263cc 100644 --- a/src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/MapperTypeParameterTest.java +++ b/src/test/java/org/apache/ibatis/submitted/mapper_type_parameter/MapperTypeParameterTest.java @@ -18,13 +18,12 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.Arrays; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -42,15 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/mapper_type_parameter/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/mapper_type_parameter/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/maptypehandler/MapTypeHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/maptypehandler/MapTypeHandlerTest.java index 8a94ab9f3f3..228db9c7761 100644 --- a/src/test/java/org/apache/ibatis/submitted/maptypehandler/MapTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/maptypehandler/MapTypeHandlerTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,12 @@ package org.apache.ibatis.submitted.maptypehandler; import java.io.Reader; -import java.sql.Connection; import java.util.HashMap; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -46,15 +45,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/maptypehandler/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/maptypehandler/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/missing_id_property/MissingIdPropertyTest.java b/src/test/java/org/apache/ibatis/submitted/missing_id_property/MissingIdPropertyTest.java index d13916aa7fa..f4072ffbaa8 100644 --- a/src/test/java/org/apache/ibatis/submitted/missing_id_property/MissingIdPropertyTest.java +++ b/src/test/java/org/apache/ibatis/submitted/missing_id_property/MissingIdPropertyTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.missing_id_property; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -39,15 +38,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/missing_id_property/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/missing_id_property/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/multidb/MultiDbTest.java b/src/test/java/org/apache/ibatis/submitted/multidb/MultiDbTest.java index 08ae2ee2b77..bd2ef998505 100644 --- a/src/test/java/org/apache/ibatis/submitted/multidb/MultiDbTest.java +++ b/src/test/java/org/apache/ibatis/submitted/multidb/MultiDbTest.java @@ -18,11 +18,9 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,29 +34,12 @@ public class MultiDbTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/MultiDbConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:multidb", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/MultiDbConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/multidb/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/multiple_discriminator/MultipleDiscriminatorTest.java b/src/test/java/org/apache/ibatis/submitted/multiple_discriminator/MultipleDiscriminatorTest.java index a5830f9e84b..419cfd00bda 100755 --- a/src/test/java/org/apache/ibatis/submitted/multiple_discriminator/MultipleDiscriminatorTest.java +++ b/src/test/java/org/apache/ibatis/submitted/multiple_discriminator/MultipleDiscriminatorTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2015 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,9 @@ package org.apache.ibatis.submitted.multiple_discriminator; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -34,30 +32,12 @@ public class MultipleDiscriminatorTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multiple_discriminator/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:multiple_discriminator", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multiple_discriminator/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multiple_discriminator/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/multiple_discriminator/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/multipleiterates/MultipleIteratesTest.java b/src/test/java/org/apache/ibatis/submitted/multipleiterates/MultipleIteratesTest.java index 8a4c45db227..f8c12897416 100644 --- a/src/test/java/org/apache/ibatis/submitted/multipleiterates/MultipleIteratesTest.java +++ b/src/test/java/org/apache/ibatis/submitted/multipleiterates/MultipleIteratesTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.multipleiterates; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -38,15 +37,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multipleiterates/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/multipleiterates/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/named_constructor_args/InvalidNamedConstructorArgsTest.java b/src/test/java/org/apache/ibatis/submitted/named_constructor_args/InvalidNamedConstructorArgsTest.java index 521301862e0..aeaea81dd1d 100644 --- a/src/test/java/org/apache/ibatis/submitted/named_constructor_args/InvalidNamedConstructorArgsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/named_constructor_args/InvalidNamedConstructorArgsTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,14 @@ package org.apache.ibatis.submitted.named_constructor_args; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.annotations.Arg; import org.apache.ibatis.annotations.ConstructorArgs; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.builder.BuilderException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.Configuration; -import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.BeforeClass; @@ -47,16 +45,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql"); } interface NoMatchingConstructorMapper { diff --git a/src/test/java/org/apache/ibatis/submitted/named_constructor_args/NamedConstructorArgsTest.java b/src/test/java/org/apache/ibatis/submitted/named_constructor_args/NamedConstructorArgsTest.java index a5bc77359b6..7a3a366efdd 100644 --- a/src/test/java/org/apache/ibatis/submitted/named_constructor_args/NamedConstructorArgsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/named_constructor_args/NamedConstructorArgsTest.java @@ -18,10 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -45,15 +44,8 @@ public static void setUp() throws Exception { configuration.addMapper(Mapper.class); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/named_constructor_args/usesjava8/NamedConstructorArgsUseActualNameTest.java b/src/test/java/org/apache/ibatis/submitted/named_constructor_args/usesjava8/NamedConstructorArgsUseActualNameTest.java index a2ce9db4b36..bbb70b13558 100644 --- a/src/test/java/org/apache/ibatis/submitted/named_constructor_args/usesjava8/NamedConstructorArgsUseActualNameTest.java +++ b/src/test/java/org/apache/ibatis/submitted/named_constructor_args/usesjava8/NamedConstructorArgsUseActualNameTest.java @@ -18,14 +18,12 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; -import org.apache.ibatis.submitted.named_constructor_args.usesjava8.Mapper; import org.apache.ibatis.submitted.named_constructor_args.User; import org.junit.BeforeClass; import org.junit.Test; @@ -44,15 +42,8 @@ public static void setUp() throws Exception { sqlSessionFactory.getConfiguration().addMapper(Mapper.class); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/nested/NestedForEachTest.java b/src/test/java/org/apache/ibatis/submitted/nested/NestedForEachTest.java index dd7e2873eb2..a89120585b6 100644 --- a/src/test/java/org/apache/ibatis/submitted/nested/NestedForEachTest.java +++ b/src/test/java/org/apache/ibatis/submitted/nested/NestedForEachTest.java @@ -18,14 +18,12 @@ import static org.junit.Assert.assertEquals; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -38,30 +36,12 @@ public class NestedForEachTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; - - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:nested", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nested/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nested/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nested/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/nested/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java index 6512a942c13..6c48e4e3d32 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler/NestedResultHandlerTest.java @@ -16,12 +16,11 @@ package org.apache.ibatis.submitted.nestedresulthandler; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.SqlSession; @@ -42,15 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/nestedresulthandler/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_association/NestedResultHandlerAssociationTest.java b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_association/NestedResultHandlerAssociationTest.java index c390197d8f8..58abf027371 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_association/NestedResultHandlerAssociationTest.java +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_association/NestedResultHandlerAssociationTest.java @@ -18,14 +18,13 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; @@ -47,15 +46,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_association/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/nestedresulthandler_association/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_multiple_association/NestedResultHandlerMultipleAssociationTest.java b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_multiple_association/NestedResultHandlerMultipleAssociationTest.java index 5d84e51e899..fdfca5fbf51 100644 --- a/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_multiple_association/NestedResultHandlerMultipleAssociationTest.java +++ b/src/test/java/org/apache/ibatis/submitted/nestedresulthandler_multiple_association/NestedResultHandlerMultipleAssociationTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,11 @@ package org.apache.ibatis.submitted.nestedresulthandler_multiple_association; import java.io.Reader; -import java.sql.Connection; + import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -41,16 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_multiple_association/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/nestedresulthandler_multiple_association/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/no_param_type/NoParamTypeTest.java b/src/test/java/org/apache/ibatis/submitted/no_param_type/NoParamTypeTest.java index e92e6e000c8..9531a3a99b9 100644 --- a/src/test/java/org/apache/ibatis/submitted/no_param_type/NoParamTypeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/no_param_type/NoParamTypeTest.java @@ -18,12 +18,11 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.executor.BatchResult; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -43,15 +42,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/no_param_type/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/no_param_type/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/nonexistentvariables/NonExistentVariablesTest.java b/src/test/java/org/apache/ibatis/submitted/nonexistentvariables/NonExistentVariablesTest.java index 3ecfa6ce686..ba5d68382a5 100644 --- a/src/test/java/org/apache/ibatis/submitted/nonexistentvariables/NonExistentVariablesTest.java +++ b/src/test/java/org/apache/ibatis/submitted/nonexistentvariables/NonExistentVariablesTest.java @@ -18,12 +18,10 @@ import static org.junit.Assert.fail; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,30 +34,12 @@ public class NonExistentVariablesTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nonexistentvariables/mybatis-config.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:nonexistentvariables", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nonexistentvariables/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nonexistentvariables/mybatis-config.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/nonexistentvariables/CreateDB.sql"); } @Test(expected = PersistenceException.class) diff --git a/src/test/java/org/apache/ibatis/submitted/not_null_column/NotNullColumnTest.java b/src/test/java/org/apache/ibatis/submitted/not_null_column/NotNullColumnTest.java index 6235f60820a..427df602738 100644 --- a/src/test/java/org/apache/ibatis/submitted/not_null_column/NotNullColumnTest.java +++ b/src/test/java/org/apache/ibatis/submitted/not_null_column/NotNullColumnTest.java @@ -18,11 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -35,30 +33,12 @@ public class NotNullColumnTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/not_null_column/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:not_null_column", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/not_null_column/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/not_null_column/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/not_null_column/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/null_associations/FooMapperTest.java b/src/test/java/org/apache/ibatis/submitted/null_associations/FooMapperTest.java index c721d2955e9..6b3fe86a66e 100644 --- a/src/test/java/org/apache/ibatis/submitted/null_associations/FooMapperTest.java +++ b/src/test/java/org/apache/ibatis/submitted/null_associations/FooMapperTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,13 @@ */ package org.apache.ibatis.submitted.null_associations; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.*; -import java.io.Reader; import java.sql.Connection; import java.sql.SQLException; @@ -33,20 +32,13 @@ public class FooMapperTest { private static Connection conn; @BeforeClass - public static void setUpBeforeClass() { - try { - final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(SQL_MAP_CONFIG)); - session = factory.openSession(); - conn = session.getConnection(); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/null_associations/create-schema-mysql.sql"); - runner.runScript(reader); - reader.close(); - } catch (Exception ex) { - Assert.fail(ex.getMessage()); - } + public static void setUpBeforeClass() throws Exception { + final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(SQL_MAP_CONFIG)); + session = factory.openSession(); + conn = session.getConnection(); + + BaseDataTest.runScript(factory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/null_associations/create-schema-mysql.sql"); } @Before diff --git a/src/test/java/org/apache/ibatis/submitted/ognl_enum/EnumWithOgnlTest.java b/src/test/java/org/apache/ibatis/submitted/ognl_enum/EnumWithOgnlTest.java index 1830abee507..dbbbf0c7e9e 100644 --- a/src/test/java/org/apache/ibatis/submitted/ognl_enum/EnumWithOgnlTest.java +++ b/src/test/java/org/apache/ibatis/submitted/ognl_enum/EnumWithOgnlTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2015 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,10 @@ package org.apache.ibatis.submitted.ognl_enum; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -37,30 +35,12 @@ public class EnumWithOgnlTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ognl_enum/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:ognl_enum", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ognl_enum/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ognl_enum/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/ognl_enum/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/ognlstatic/OgnlStaticTest.java b/src/test/java/org/apache/ibatis/submitted/ognlstatic/OgnlStaticTest.java index 4775b70a1f5..93a5a7c60b0 100644 --- a/src/test/java/org/apache/ibatis/submitted/ognlstatic/OgnlStaticTest.java +++ b/src/test/java/org/apache/ibatis/submitted/ognlstatic/OgnlStaticTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.ognlstatic; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -39,15 +38,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ognlstatic/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/ognlstatic/CreateDB.sql"); } /** diff --git a/src/test/java/org/apache/ibatis/submitted/order_prefix_removed/OrderPrefixRemoved.java b/src/test/java/org/apache/ibatis/submitted/order_prefix_removed/OrderPrefixRemoved.java index a95fc87756c..5e2f62eeb46 100644 --- a/src/test/java/org/apache/ibatis/submitted/order_prefix_removed/OrderPrefixRemoved.java +++ b/src/test/java/org/apache/ibatis/submitted/order_prefix_removed/OrderPrefixRemoved.java @@ -18,11 +18,9 @@ import static org.junit.Assert.assertNotNull; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -36,29 +34,12 @@ public class OrderPrefixRemoved { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/order_prefix_removed/ibatisConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:order_prefix_removed", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/order_prefix_removed/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/order_prefix_removed/ibatisConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/order_prefix_removed/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/overwritingproperties/FooMapperTest.java b/src/test/java/org/apache/ibatis/submitted/overwritingproperties/FooMapperTest.java index d8ed266672c..de806d03f76 100644 --- a/src/test/java/org/apache/ibatis/submitted/overwritingproperties/FooMapperTest.java +++ b/src/test/java/org/apache/ibatis/submitted/overwritingproperties/FooMapperTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,11 @@ */ package org.apache.ibatis.submitted.overwritingproperties; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.*; import org.junit.*; -import java.io.Reader; import java.sql.Connection; import java.sql.SQLException; @@ -34,20 +33,13 @@ public class FooMapperTest { private static Connection conn; @BeforeClass - public static void setUpBeforeClass() { - try { - final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(SQL_MAP_CONFIG)); - session = factory.openSession(); - conn = session.getConnection(); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/overwritingproperties/create-schema-mysql.sql"); - runner.runScript(reader); - reader.close(); - } catch (Exception ex) { - Assert.fail(ex.getMessage()); - } + public static void setUpBeforeClass() throws Exception { + final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(SQL_MAP_CONFIG)); + session = factory.openSession(); + conn = session.getConnection(); + + BaseDataTest.runScript(factory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/overwritingproperties/create-schema-mysql.sql"); } @Before diff --git a/src/test/java/org/apache/ibatis/submitted/parametrizedlist/ParametrizedListTest.java b/src/test/java/org/apache/ibatis/submitted/parametrizedlist/ParametrizedListTest.java index c596ef8c3a3..b86f0ec848d 100644 --- a/src/test/java/org/apache/ibatis/submitted/parametrizedlist/ParametrizedListTest.java +++ b/src/test/java/org/apache/ibatis/submitted/parametrizedlist/ParametrizedListTest.java @@ -15,17 +15,14 @@ */ package org.apache.ibatis.submitted.parametrizedlist; -import java.io.PrintWriter; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.junit.Assert; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -38,29 +35,12 @@ public class ParametrizedListTest { @Before public void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/parametrizedlist/Config.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:parametrizedlist", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/parametrizedlist/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(new PrintWriter(System.err)); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/parametrizedlist/Config.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/parametrizedlist/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/parent_childs/ParentChildTest.java b/src/test/java/org/apache/ibatis/submitted/parent_childs/ParentChildTest.java index 3ba9d2b7bdc..78bcbeaa6f5 100644 --- a/src/test/java/org/apache/ibatis/submitted/parent_childs/ParentChildTest.java +++ b/src/test/java/org/apache/ibatis/submitted/parent_childs/ParentChildTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.parent_childs; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/parent_childs/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/parent_childs/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/parent_reference_3level/BlogTest.java b/src/test/java/org/apache/ibatis/submitted/parent_reference_3level/BlogTest.java index 579c6e878a1..bef7fdf1d2d 100644 --- a/src/test/java/org/apache/ibatis/submitted/parent_reference_3level/BlogTest.java +++ b/src/test/java/org/apache/ibatis/submitted/parent_reference_3level/BlogTest.java @@ -18,11 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,28 +38,12 @@ protected String getConfigPath() { @Before public void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader(getConfigPath()); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:parent_reference_3level", "sa", ""); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/parent_reference_3level/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader(getConfigPath()); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/parent_reference_3level/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/permissions/PermissionsTest.java b/src/test/java/org/apache/ibatis/submitted/permissions/PermissionsTest.java index 4123b0ffdf7..ad83cf918f9 100644 --- a/src/test/java/org/apache/ibatis/submitted/permissions/PermissionsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/permissions/PermissionsTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.permissions; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,16 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/permissions/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - conn.close(); - reader.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/permissions/CreateDB.sql"); } @Test // see issue #168 diff --git a/src/test/java/org/apache/ibatis/submitted/primitive_array/PrimitiveArrayTest.java b/src/test/java/org/apache/ibatis/submitted/primitive_array/PrimitiveArrayTest.java index f0b5d857837..f4ed8b35cbc 100644 --- a/src/test/java/org/apache/ibatis/submitted/primitive_array/PrimitiveArrayTest.java +++ b/src/test/java/org/apache/ibatis/submitted/primitive_array/PrimitiveArrayTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.primitive_array; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -39,15 +38,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/primitive_array/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/primitive_array/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/primitive_result_type/IbatisConfig.java b/src/test/java/org/apache/ibatis/submitted/primitive_result_type/IbatisConfig.java index 070de1666d8..12d7bbdf652 100644 --- a/src/test/java/org/apache/ibatis/submitted/primitive_result_type/IbatisConfig.java +++ b/src/test/java/org/apache/ibatis/submitted/primitive_result_type/IbatisConfig.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2015 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,4 +46,10 @@ public static SqlSession getSession() { } return sqlSessionFactory.openSession(); } + + public static SqlSessionFactory getSqlSessionFactory() { + init(); + return sqlSessionFactory; + } + } \ No newline at end of file diff --git a/src/test/java/org/apache/ibatis/submitted/primitive_result_type/PrimitiveResultTypeTest.java b/src/test/java/org/apache/ibatis/submitted/primitive_result_type/PrimitiveResultTypeTest.java index 242ac1e31b8..cf0410b80dd 100755 --- a/src/test/java/org/apache/ibatis/submitted/primitive_result_type/PrimitiveResultTypeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/primitive_result_type/PrimitiveResultTypeTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,31 +15,20 @@ */ package org.apache.ibatis.submitted.primitive_result_type; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; -import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.BaseDataTest; import static org.junit.Assert.assertTrue; import org.junit.BeforeClass; import org.junit.Test; -import java.io.Reader; import java.math.BigDecimal; -import java.sql.Connection; import java.util.List; public class PrimitiveResultTypeTest { @BeforeClass public static void setup() throws Exception { - SqlSession session = IbatisConfig.getSession(); - Connection conn = session.getConnection(); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/primitive_result_type/create.sql"); - runner.runScript(reader); - conn.close(); - reader.close(); + BaseDataTest.runScript(IbatisConfig.getSqlSessionFactory().getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/primitive_result_type/create.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/primitives/PrimitivesTest.java b/src/test/java/org/apache/ibatis/submitted/primitives/PrimitivesTest.java index fd64a390a5b..90d68e76885 100644 --- a/src/test/java/org/apache/ibatis/submitted/primitives/PrimitivesTest.java +++ b/src/test/java/org/apache/ibatis/submitted/primitives/PrimitivesTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.primitives; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/primitives/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/primitives/CreateDB.sql"); } @Test // issue #69 diff --git a/src/test/java/org/apache/ibatis/submitted/propertiesinmapperfiles/PropertiesInMappersTest.java b/src/test/java/org/apache/ibatis/submitted/propertiesinmapperfiles/PropertiesInMappersTest.java index 09e90ad8b2b..5ea989cc420 100644 --- a/src/test/java/org/apache/ibatis/submitted/propertiesinmapperfiles/PropertiesInMappersTest.java +++ b/src/test/java/org/apache/ibatis/submitted/propertiesinmapperfiles/PropertiesInMappersTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.propertiesinmapperfiles; import java.io.Reader; -import java.sql.Connection; import java.util.Properties; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -45,15 +44,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/propertiesinmapperfiles/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/propertiesinmapperfiles/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/quotedcolumnnames/QuotedColumnNamesTest.java b/src/test/java/org/apache/ibatis/submitted/quotedcolumnnames/QuotedColumnNamesTest.java index 98938e74a99..dfd6dbfb4fc 100644 --- a/src/test/java/org/apache/ibatis/submitted/quotedcolumnnames/QuotedColumnNamesTest.java +++ b/src/test/java/org/apache/ibatis/submitted/quotedcolumnnames/QuotedColumnNamesTest.java @@ -16,13 +16,11 @@ package org.apache.ibatis.submitted.quotedcolumnnames; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -36,28 +34,12 @@ public class QuotedColumnNamesTest { @BeforeClass public static void setUp() throws Exception { - Connection conn = null; + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:gname", "sa", ""); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - - } finally { - if (conn != null) { - conn.close(); - } - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/quotedcolumnnames/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/raw_sql_source/RawSqlSourceTest.java b/src/test/java/org/apache/ibatis/submitted/raw_sql_source/RawSqlSourceTest.java index 7b2bcd32b36..bb1d5c81ea7 100644 --- a/src/test/java/org/apache/ibatis/submitted/raw_sql_source/RawSqlSourceTest.java +++ b/src/test/java/org/apache/ibatis/submitted/raw_sql_source/RawSqlSourceTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.raw_sql_source; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.SqlSource; import org.apache.ibatis.scripting.defaults.RawSqlSource; import org.apache.ibatis.scripting.xmltags.DynamicSqlSource; @@ -42,15 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/raw_sql_source/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/raw_sql_source/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/result_handler/ResulthandlerTest.java b/src/test/java/org/apache/ibatis/submitted/result_handler/ResulthandlerTest.java index ad792153803..fc5a34adbd7 100644 --- a/src/test/java/org/apache/ibatis/submitted/result_handler/ResulthandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/result_handler/ResulthandlerTest.java @@ -16,10 +16,9 @@ package org.apache.ibatis.submitted.result_handler; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { sqlSessionFactory.getConfiguration().addMapper(Mapper.class); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/result_handler/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/result_handler/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/result_handler_type/DefaultResultHandlerTypeTest.java b/src/test/java/org/apache/ibatis/submitted/result_handler_type/DefaultResultHandlerTypeTest.java index cf314f09b16..96aef390d24 100644 --- a/src/test/java/org/apache/ibatis/submitted/result_handler_type/DefaultResultHandlerTypeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/result_handler_type/DefaultResultHandlerTypeTest.java @@ -17,15 +17,12 @@ import static org.junit.Assert.*; -import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.SQLException; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -74,28 +71,10 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig(String resource) throws SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/result_handler_type/CreateDB.sql"); return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/result_handler_type/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } - } - } diff --git a/src/test/java/org/apache/ibatis/submitted/resultmapwithassociationstest/ResultMapWithAssociationsTest.java b/src/test/java/org/apache/ibatis/submitted/resultmapwithassociationstest/ResultMapWithAssociationsTest.java index 780d67fb06e..9eb0a1e2103 100644 --- a/src/test/java/org/apache/ibatis/submitted/resultmapwithassociationstest/ResultMapWithAssociationsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/resultmapwithassociationstest/ResultMapWithAssociationsTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.resultmapwithassociationstest; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/resultmapwithassociationstest/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/resultmapwithassociationstest/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/results_id/ResultsIdTest.java b/src/test/java/org/apache/ibatis/submitted/results_id/ResultsIdTest.java index 60e2d72b7f4..bb8e46c5b72 100644 --- a/src/test/java/org/apache/ibatis/submitted/results_id/ResultsIdTest.java +++ b/src/test/java/org/apache/ibatis/submitted/results_id/ResultsIdTest.java @@ -18,11 +18,10 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/results_id/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/results_id/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/rounding/RoundingHandlersTest.java b/src/test/java/org/apache/ibatis/submitted/rounding/RoundingHandlersTest.java index 67b53116841..3adb3a50141 100644 --- a/src/test/java/org/apache/ibatis/submitted/rounding/RoundingHandlersTest.java +++ b/src/test/java/org/apache/ibatis/submitted/rounding/RoundingHandlersTest.java @@ -18,10 +18,9 @@ import java.io.Reader; import java.math.BigDecimal; import java.math.RoundingMode; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -42,15 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/rounding/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/rounding/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/selectkey/SelectKeyTest.java b/src/test/java/org/apache/ibatis/submitted/selectkey/SelectKeyTest.java index 58006e1df83..d9bf38e0cee 100644 --- a/src/test/java/org/apache/ibatis/submitted/selectkey/SelectKeyTest.java +++ b/src/test/java/org/apache/ibatis/submitted/selectkey/SelectKeyTest.java @@ -15,9 +15,9 @@ */ package org.apache.ibatis.submitted.selectkey; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -29,8 +29,6 @@ import org.junit.Test; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.HashMap; import java.util.Map; @@ -40,31 +38,13 @@ public class SelectKeyTest { @Before public void setUp() throws Exception { - Connection conn = null; - - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:lname", "sa", - ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/selectkey/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/selectkey/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - sqlSessionFactory.getConfiguration().addMapper(AnnotatedMapper.class); - } finally { - if (conn != null) { - conn.close(); - } - } + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/selectkey/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + sqlSessionFactory.getConfiguration().addMapper(AnnotatedMapper.class); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/selectkey/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/serializecircular/SerializeCircularTest.java b/src/test/java/org/apache/ibatis/submitted/serializecircular/SerializeCircularTest.java index 2197f33b8e1..6795d784a3b 100644 --- a/src/test/java/org/apache/ibatis/submitted/serializecircular/SerializeCircularTest.java +++ b/src/test/java/org/apache/ibatis/submitted/serializecircular/SerializeCircularTest.java @@ -15,13 +15,10 @@ */ package org.apache.ibatis.submitted.serializecircular; -import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -112,28 +109,10 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig(String resource) throws SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/serializecircular/CreateDB.sql"); return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/serializecircular/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } - } - } diff --git a/src/test/java/org/apache/ibatis/submitted/simplelistparameter/SimpleListParameterTest.java b/src/test/java/org/apache/ibatis/submitted/simplelistparameter/SimpleListParameterTest.java index 17f5d2a1180..60e6ef86a17 100644 --- a/src/test/java/org/apache/ibatis/submitted/simplelistparameter/SimpleListParameterTest.java +++ b/src/test/java/org/apache/ibatis/submitted/simplelistparameter/SimpleListParameterTest.java @@ -16,12 +16,11 @@ package org.apache.ibatis.submitted.simplelistparameter; import java.io.Reader; -import java.sql.Connection; import java.util.Arrays; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/simplelistparameter/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/simplelistparameter/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java b/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java index 80f69c33315..c18a98c49c8 100644 --- a/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java +++ b/src/test/java/org/apache/ibatis/submitted/sptests/SPTest.java @@ -21,14 +21,13 @@ import java.io.Reader; import java.sql.Array; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; @@ -42,30 +41,15 @@ public class SPTest { @BeforeClass public static void initDatabase() throws Exception { - Connection conn = null; - - try { - Class.forName("org.hsqldb.jdbcDriver"); - conn = DriverManager.getConnection("jdbc:hsqldb:mem:sptest", "sa", ""); - - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/sptests/CreateDB.sql"); - - ScriptRunner runner = new ScriptRunner(conn); - runner.setDelimiter("go"); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - conn.commit(); - reader.close(); - - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/sptests/MapperConfig.xml"); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); - reader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/sptests/MapperConfig.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + + ScriptRunner runner = new ScriptRunner(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection()); + runner.setDelimiter("go"); + runner.setLogWriter(null); + runner.setErrorLogWriter(null); + BaseDataTest.runScript(runner, "org/apache/ibatis/submitted/sptests/CreateDB.sql"); } /* diff --git a/src/test/java/org/apache/ibatis/submitted/sqlprovider/SqlProviderTest.java b/src/test/java/org/apache/ibatis/submitted/sqlprovider/SqlProviderTest.java index 1149de25334..ea5309bc7ee 100644 --- a/src/test/java/org/apache/ibatis/submitted/sqlprovider/SqlProviderTest.java +++ b/src/test/java/org/apache/ibatis/submitted/sqlprovider/SqlProviderTest.java @@ -23,19 +23,18 @@ import java.io.Reader; import java.lang.reflect.Method; -import java.sql.Connection; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.SelectProvider; import org.apache.ibatis.builder.BuilderException; import org.apache.ibatis.builder.annotation.ProviderContext; import org.apache.ibatis.builder.annotation.ProviderSqlSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -57,16 +56,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/sqlprovider/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/sqlprovider/CreateDB.sql"); } // Test for list diff --git a/src/test/java/org/apache/ibatis/submitted/stringlist/StringListTest.java b/src/test/java/org/apache/ibatis/submitted/stringlist/StringListTest.java index dd41b9a7e08..600562c8a8d 100644 --- a/src/test/java/org/apache/ibatis/submitted/stringlist/StringListTest.java +++ b/src/test/java/org/apache/ibatis/submitted/stringlist/StringListTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.stringlist; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -40,15 +39,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/stringlist/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/stringlist/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/substitution_in_annots/SubstitutionInAnnotsTest.java b/src/test/java/org/apache/ibatis/submitted/substitution_in_annots/SubstitutionInAnnotsTest.java index 8517278d288..b6131d04292 100644 --- a/src/test/java/org/apache/ibatis/submitted/substitution_in_annots/SubstitutionInAnnotsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/substitution_in_annots/SubstitutionInAnnotsTest.java @@ -17,13 +17,8 @@ import static org.junit.Assert.assertEquals; -import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; - +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -40,24 +35,14 @@ public class SubstitutionInAnnotsTest { @BeforeClass public static void setUp() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:annots", "sa", ""); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(c); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(reader); - c.commit(); - reader.close(); - Configuration configuration = new Configuration(); Environment environment = new Environment("test", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:annots", null)); configuration.setEnvironment(environment); - configuration.addMapper(SubstitutionInAnnotsMapper.class); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); - c.close(); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/substitution_in_annots/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/typehandler/TypeHandlerTest.java b/src/test/java/org/apache/ibatis/submitted/typehandler/TypeHandlerTest.java index 189ac72c4bb..f1d50fcd05a 100644 --- a/src/test/java/org/apache/ibatis/submitted/typehandler/TypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/submitted/typehandler/TypeHandlerTest.java @@ -18,11 +18,10 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.builder.BuilderException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -46,15 +45,8 @@ public void setUp() throws Exception { sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(StringTrimmingTypeHandler.class); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/typehandler/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/typehandler/CreateDB.sql"); } // Some tests need to register additional type handler diff --git a/src/test/java/org/apache/ibatis/submitted/typehandlerinjection/TypeHandlerInjectionTest.java b/src/test/java/org/apache/ibatis/submitted/typehandlerinjection/TypeHandlerInjectionTest.java index 1b97b4fcd93..50bc97d4a43 100644 --- a/src/test/java/org/apache/ibatis/submitted/typehandlerinjection/TypeHandlerInjectionTest.java +++ b/src/test/java/org/apache/ibatis/submitted/typehandlerinjection/TypeHandlerInjectionTest.java @@ -16,11 +16,10 @@ package org.apache.ibatis.submitted.typehandlerinjection; import java.io.Reader; -import java.sql.Connection; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -45,15 +44,8 @@ public static void setUp() throws Exception { sqlSessionFactory.getConfiguration().addMapper(Mapper.class); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/typehandlerinjection/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/typehandlerinjection/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/usesjava8/default_method/DefaultMethodTest.java b/src/test/java/org/apache/ibatis/submitted/usesjava8/default_method/DefaultMethodTest.java index 00543a73235..d7875491aa1 100644 --- a/src/test/java/org/apache/ibatis/submitted/usesjava8/default_method/DefaultMethodTest.java +++ b/src/test/java/org/apache/ibatis/submitted/usesjava8/default_method/DefaultMethodTest.java @@ -18,10 +18,9 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -42,16 +41,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader( - "org/apache/ibatis/submitted/usesjava8/default_method/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/usesjava8/default_method/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/usesjava8/keycolumn/InsertTest.java b/src/test/java/org/apache/ibatis/submitted/usesjava8/keycolumn/InsertTest.java index 031129c63ea..b78acd5e244 100644 --- a/src/test/java/org/apache/ibatis/submitted/usesjava8/keycolumn/InsertTest.java +++ b/src/test/java/org/apache/ibatis/submitted/usesjava8/keycolumn/InsertTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,16 +18,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.io.Reader; import java.nio.file.Paths; -import java.sql.Connection; import java.util.Collections; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.executor.BatchResult; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ExecutorType; @@ -66,13 +63,8 @@ public static void setUp() throws Exception { configuration.addMapper(InsertMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); - try (SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/usesjava8/keycolumn/CreateDB.sql")) { - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/usesjava8/keycolumn/CreateDB.sql"); } @AfterClass diff --git a/src/test/java/org/apache/ibatis/submitted/usesjava8/multiple_resultsets/MultipleResultTest.java b/src/test/java/org/apache/ibatis/submitted/usesjava8/multiple_resultsets/MultipleResultTest.java index 91047b9bfa8..d4008fac04e 100644 --- a/src/test/java/org/apache/ibatis/submitted/usesjava8/multiple_resultsets/MultipleResultTest.java +++ b/src/test/java/org/apache/ibatis/submitted/usesjava8/multiple_resultsets/MultipleResultTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,12 @@ package org.apache.ibatis.submitted.usesjava8.multiple_resultsets; import java.io.IOException; -import java.io.Reader; import java.nio.file.Paths; -import java.sql.Connection; import java.util.Collections; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -65,13 +62,8 @@ public static void setUp() throws Exception { configuration.addMapper(Mapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); - try (SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/usesjava8/multiple_resultsets/CreateDB.sql")) { - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/usesjava8/multiple_resultsets/CreateDB.sql"); } @AfterClass diff --git a/src/test/java/org/apache/ibatis/submitted/usesjava8/optional_on_mapper_method/OptionalOnMapperMethodTest.java b/src/test/java/org/apache/ibatis/submitted/usesjava8/optional_on_mapper_method/OptionalOnMapperMethodTest.java index 9047f7f40d4..a0baaad7ddc 100644 --- a/src/test/java/org/apache/ibatis/submitted/usesjava8/optional_on_mapper_method/OptionalOnMapperMethodTest.java +++ b/src/test/java/org/apache/ibatis/submitted/usesjava8/optional_on_mapper_method/OptionalOnMapperMethodTest.java @@ -15,8 +15,8 @@ */ package org.apache.ibatis.submitted.usesjava8.optional_on_mapper_method; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -25,7 +25,6 @@ import org.mockito.Mockito; import java.io.Reader; -import java.sql.Connection; import java.util.Optional; import static org.hamcrest.core.Is.is; @@ -54,15 +53,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader( - "org/apache/ibatis/submitted/usesjava8/optional_on_mapper_method/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/usesjava8/optional_on_mapper_method/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/usesjava8/postgres_genkeys/PostgresGeneratedKeysTest.java b/src/test/java/org/apache/ibatis/submitted/usesjava8/postgres_genkeys/PostgresGeneratedKeysTest.java index b9e8093b133..420114761a5 100644 --- a/src/test/java/org/apache/ibatis/submitted/usesjava8/postgres_genkeys/PostgresGeneratedKeysTest.java +++ b/src/test/java/org/apache/ibatis/submitted/usesjava8/postgres_genkeys/PostgresGeneratedKeysTest.java @@ -17,20 +17,16 @@ import static org.junit.Assert.*; -import java.io.Reader; import java.nio.file.Paths; -import java.sql.Connection; import java.util.Collections; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; -import org.apache.ibatis.submitted.usesjava8.keycolumn.InsertMapper; import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -58,13 +54,8 @@ public static void setUp() throws Exception { configuration.addMapper(Mapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); - try (SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/usesjava8/postgres_genkeys/CreateDB.sql")) { - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/usesjava8/postgres_genkeys/CreateDB.sql"); } @AfterClass diff --git a/src/test/java/org/apache/ibatis/submitted/usesjava8/refcursor/RefCursorTest.java b/src/test/java/org/apache/ibatis/submitted/usesjava8/refcursor/RefCursorTest.java index c250ea4ffdb..bed319b0c28 100644 --- a/src/test/java/org/apache/ibatis/submitted/usesjava8/refcursor/RefCursorTest.java +++ b/src/test/java/org/apache/ibatis/submitted/usesjava8/refcursor/RefCursorTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,18 +18,15 @@ import static org.junit.Assert.*; import java.io.IOException; -import java.io.Reader; import java.nio.file.Paths; -import java.sql.Connection; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.ResultContext; @@ -69,13 +66,8 @@ public static void setUp() throws Exception { configuration.addMapper(OrdersMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); - try (SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/usesjava8/refcursor/CreateDB.sql")) { - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/usesjava8/refcursor/CreateDB.sql"); } @AfterClass diff --git a/src/test/java/org/apache/ibatis/submitted/usesjava8/use_actual_param_name/UseActualParamNameTest.java b/src/test/java/org/apache/ibatis/submitted/usesjava8/use_actual_param_name/UseActualParamNameTest.java index c99a8238895..f95f9177717 100644 --- a/src/test/java/org/apache/ibatis/submitted/usesjava8/use_actual_param_name/UseActualParamNameTest.java +++ b/src/test/java/org/apache/ibatis/submitted/usesjava8/use_actual_param_name/UseActualParamNameTest.java @@ -18,12 +18,11 @@ import static org.junit.Assert.*; import java.io.Reader; -import java.sql.Connection; import java.util.Arrays; import java.util.List; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -43,16 +42,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader( - "org/apache/ibatis/submitted/usesjava8/use_actual_param_name/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/usesjava8/use_actual_param_name/CreateDB.sql"); } @Test diff --git a/src/test/java/org/apache/ibatis/submitted/uuid_test/UUIDTest.java b/src/test/java/org/apache/ibatis/submitted/uuid_test/UUIDTest.java index fd9f76320b6..b0a8f884b5f 100644 --- a/src/test/java/org/apache/ibatis/submitted/uuid_test/UUIDTest.java +++ b/src/test/java/org/apache/ibatis/submitted/uuid_test/UUIDTest.java @@ -16,12 +16,11 @@ package org.apache.ibatis.submitted.uuid_test; import java.io.Reader; -import java.sql.Connection; import java.util.UUID; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -41,15 +40,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/uuid_test/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/uuid_test/CreateDB.sql"); } @Test(expected=PersistenceException.class) diff --git a/src/test/java/org/apache/ibatis/submitted/valueinmap/ValueInMapTest.java b/src/test/java/org/apache/ibatis/submitted/valueinmap/ValueInMapTest.java index e5c90e4fbbb..da131c4655c 100644 --- a/src/test/java/org/apache/ibatis/submitted/valueinmap/ValueInMapTest.java +++ b/src/test/java/org/apache/ibatis/submitted/valueinmap/ValueInMapTest.java @@ -16,15 +16,14 @@ package org.apache.ibatis.submitted.valueinmap; import java.io.Reader; -import java.sql.Connection; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.exceptions.PersistenceException; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; @@ -44,15 +43,8 @@ public static void setUp() throws Exception { reader.close(); // populate in-memory database - SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/valueinmap/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - conn.close(); - reader.close(); - session.close(); + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/valueinmap/CreateDB.sql"); } @Test // issue #165 diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleCrossIncludeTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleCrossIncludeTest.java index dfffae32f2a..1246f6cb313 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleCrossIncludeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleCrossIncludeTest.java @@ -19,14 +19,12 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.cache.Cache; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.session.Configuration; @@ -89,44 +87,28 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(MultipleCrossIncludePersonMapper.class); configuration.addMapper(MultipleCrossIncludePetMapper.class); - c.close(); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); - return new SqlSessionFactoryBuilder().build(configuration); + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleIncludeTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleIncludeTest.java index 79992d6d68b..837cc2ad45c 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleIncludeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleIncludeTest.java @@ -20,12 +20,11 @@ import java.io.IOException; import java.io.Reader; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -62,42 +61,29 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { configReader.close(); Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); + initDb(sqlSessionFactory); conn.close(); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(MultipleIncludePersonMapper.class); - c.close(); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); - return new SqlSessionFactoryBuilder().build(configuration); + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleReverseIncludeTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleReverseIncludeTest.java index 19ce2dbc10f..a614a45573a 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleReverseIncludeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/MultipleReverseIncludeTest.java @@ -19,13 +19,11 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -61,43 +59,28 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(MultipleReverseIncludePersonMapper.class); - c.close(); - return new SqlSessionFactoryBuilder().build(configuration); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); + + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespaceTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespaceTest.java index dfe1edbf3da..f8455015f7e 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespaceTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespaceTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,10 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -46,11 +45,9 @@ public void testCrossReferenceXmlConfig() throws Exception { "org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespacePersonMapper.xml", selectPerson.getResource()); - Connection conn = configuration.getEnvironment().getDataSource().getConnection(); - initDb(conn); + initDb(sqlSessionFactory); - SqlSession sqlSession = sqlSessionFactory.openSession(); - try { + try (SqlSession sqlSession = sqlSessionFactory.openSession()) { Person person = (Person) sqlSession.selectOne("person namespace.select", 1); assertEquals((Integer)1, person.getId()); assertEquals(2, person.getPets().size()); @@ -63,27 +60,11 @@ public void testCrossReferenceXmlConfig() throws Exception { assertEquals((Integer)3, pet2.getId()); assertEquals((Integer)2, pet2.getOwner().getId()); } - finally { - conn.close(); - sqlSession.close(); - } } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } - finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } + } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ParameterMapReferenceTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ParameterMapReferenceTest.java index 928dce3a97c..a07113ce18e 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ParameterMapReferenceTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ParameterMapReferenceTest.java @@ -19,13 +19,11 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -62,44 +60,30 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(ParameterMapReferencePersonMapper.class); configuration.addMapper(ParameterMapReferencePetMapper.class); - c.close(); - return new SqlSessionFactoryBuilder().build(configuration); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); + + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapExtendsTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapExtendsTest.java index 3dd6fb9b446..1208214d490 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapExtendsTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapExtendsTest.java @@ -19,13 +19,11 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -61,44 +59,29 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(ResultMapReferencePersonMapper.class); configuration.addMapper(ResultMapReferencePetMapper.class); - c.close(); - return new SqlSessionFactoryBuilder().build(configuration); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); + + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapReferenceTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapReferenceTest.java index d1bdf44edce..fbe0e5bb3cf 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapReferenceTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ResultMapReferenceTest.java @@ -19,13 +19,11 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -61,44 +59,29 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(ResultMapReferencePersonMapper.class); configuration.addMapper(ResultMapReferencePetMapper.class); - c.close(); - return new SqlSessionFactoryBuilder().build(configuration); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); + + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ReverseIncludeTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ReverseIncludeTest.java index d0d875ca91d..8e385f5ea5a 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ReverseIncludeTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/ReverseIncludeTest.java @@ -19,13 +19,11 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -61,43 +59,28 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(ReverseIncludePersonMapper.class); - c.close(); - return new SqlSessionFactoryBuilder().build(configuration); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); + + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/SameIdTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/SameIdTest.java index 16badb62586..e91548715c3 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/SameIdTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/SameIdTest.java @@ -19,13 +19,11 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -70,44 +68,29 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(SameIdPersonMapper.class); configuration.addMapper(SameIdPetMapper.class); - c.close(); - return new SqlSessionFactoryBuilder().build(configuration); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); + + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/XmlExternalRefTest.java b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/XmlExternalRefTest.java index 6cee6421795..86bc4f8a187 100644 --- a/src/test/java/org/apache/ibatis/submitted/xml_external_ref/XmlExternalRefTest.java +++ b/src/test/java/org/apache/ibatis/submitted/xml_external_ref/XmlExternalRefTest.java @@ -19,15 +19,13 @@ import java.io.IOException; import java.io.Reader; -import java.sql.Connection; -import java.sql.DriverManager; import java.sql.SQLException; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.builder.BuilderException; import org.apache.ibatis.cache.Cache; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.session.Configuration; @@ -113,44 +111,29 @@ private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception { SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader); configReader.close(); - Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection(); - initDb(conn); - conn.close(); + initDb(sqlSessionFactory); return sqlSessionFactory; } private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception { - Class.forName("org.hsqldb.jdbcDriver"); - Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", ""); - initDb(c); - Configuration configuration = new Configuration(); Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource( "org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null)); configuration.setEnvironment(environment); - configuration.addMapper(PersonMapper.class); configuration.addMapper(PetMapper.class); - c.close(); - return new SqlSessionFactoryBuilder().build(configuration); + SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + initDb(sqlSessionFactory); + + return sqlSessionFactory; } - private static void initDb(Connection conn) throws IOException, SQLException { - try { - Reader scriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.setErrorLogWriter(null); - runner.runScript(scriptReader); - conn.commit(); - scriptReader.close(); - } finally { - if (conn != null) { - conn.close(); - } - } + private static void initDb(SqlSessionFactory sqlSessionFactory) throws IOException, SQLException { + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/submitted/xml_external_ref/CreateDB.sql"); } } diff --git a/src/test/java/org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.java b/src/test/java/org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.java index 367e5799b08..a3bdf1c834c 100644 --- a/src/test/java/org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.java @@ -55,12 +55,14 @@ public class BlobInputStreamTypeHandlerTest extends BaseTypeHandlerTest { @BeforeClass public static void setupSqlSessionFactory() throws Exception { DataSource dataSource = BaseDataTest.createUnpooledDataSource("org/apache/ibatis/type/jdbc.properties"); - BaseDataTest.runScript(dataSource, "org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.sql"); TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("Production", transactionFactory, dataSource); Configuration configuration = new Configuration(environment); configuration.addMapper(Mapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/type/BlobInputStreamTypeHandlerTest.sql"); } @Override diff --git a/src/test/java/org/apache/ibatis/type/ClobReaderTypeHandlerTest.java b/src/test/java/org/apache/ibatis/type/ClobReaderTypeHandlerTest.java index d99baa4ae05..561c0169e93 100644 --- a/src/test/java/org/apache/ibatis/type/ClobReaderTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/type/ClobReaderTypeHandlerTest.java @@ -57,12 +57,14 @@ public class ClobReaderTypeHandlerTest extends BaseTypeHandlerTest { @BeforeClass public static void setupSqlSessionFactory() throws Exception { DataSource dataSource = BaseDataTest.createUnpooledDataSource("org/apache/ibatis/type/jdbc.properties"); - BaseDataTest.runScript(dataSource, "org/apache/ibatis/type/ClobReaderTypeHandlerTest.sql"); TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("Production", transactionFactory, dataSource); Configuration configuration = new Configuration(environment); configuration.addMapper(Mapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); + + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/type/ClobReaderTypeHandlerTest.sql"); } @Override diff --git a/src/test/java/org/apache/ibatis/type/SqlxmlTypeHandlerTest.java b/src/test/java/org/apache/ibatis/type/SqlxmlTypeHandlerTest.java index 68e29b55738..de2afac4321 100644 --- a/src/test/java/org/apache/ibatis/type/SqlxmlTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/type/SqlxmlTypeHandlerTest.java @@ -20,17 +20,15 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import java.io.Reader; import java.nio.file.Paths; import java.sql.Connection; import java.sql.SQLXML; import java.util.Collections; +import org.apache.ibatis.BaseDataTest; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.datasource.unpooled.UnpooledDataSource; -import org.apache.ibatis.io.Resources; -import org.apache.ibatis.jdbc.ScriptRunner; import org.apache.ibatis.mapping.Environment; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSession; @@ -74,14 +72,8 @@ public static void setUp() throws Exception { configuration.addMapper(Mapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); - try (SqlSession session = sqlSessionFactory.openSession(); - Connection conn = session.getConnection(); - Reader reader = Resources - .getResourceAsReader("org/apache/ibatis/type/SqlxmlTypeHandlerTest.sql")) { - ScriptRunner runner = new ScriptRunner(conn); - runner.setLogWriter(null); - runner.runScript(reader); - } + BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), + "org/apache/ibatis/type/SqlxmlTypeHandlerTest.sql"); } @AfterClass