From a7fdfe67aa9d481f3d8641fac30a761d4d7f9091 Mon Sep 17 00:00:00 2001 From: JazzyJosh Date: Thu, 14 Jul 2016 22:29:30 -0400 Subject: [PATCH] Create test reproducing bound array parameter issue --- .../array_binding/ArrayBindingTest.java | 64 +++++++++++++++++++ .../submitted/array_binding/CreateDB.sql | 24 +++++++ .../submitted/array_binding/Mapper.java | 22 +++++++ .../ibatis/submitted/array_binding/Mapper.xml | 30 +++++++++ .../ibatis/submitted/array_binding/User.java | 38 +++++++++++ .../array_binding/mybatis-config.xml | 42 ++++++++++++ 6 files changed, 220 insertions(+) create mode 100644 src/test/java/org/apache/ibatis/submitted/array_binding/ArrayBindingTest.java create mode 100644 src/test/java/org/apache/ibatis/submitted/array_binding/CreateDB.sql create mode 100644 src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.java create mode 100644 src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.xml create mode 100644 src/test/java/org/apache/ibatis/submitted/array_binding/User.java create mode 100644 src/test/java/org/apache/ibatis/submitted/array_binding/mybatis-config.xml diff --git a/src/test/java/org/apache/ibatis/submitted/array_binding/ArrayBindingTest.java b/src/test/java/org/apache/ibatis/submitted/array_binding/ArrayBindingTest.java new file mode 100644 index 00000000000..e461c90b5cc --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/array_binding/ArrayBindingTest.java @@ -0,0 +1,64 @@ +/** + * Copyright 2009-2016 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. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.submitted.array_binding; + +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.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.Reader; +import java.sql.Connection; + +public class ArrayBindingTest { + + private static SqlSessionFactory sqlSessionFactory; + + @BeforeClass + public static void setUp() throws Exception { + // create an SqlSessionFactory + Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_binding/mybatis-config.xml"); + sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); + reader.close(); + + // populate in-memory database + SqlSession session = sqlSessionFactory.openSession(); + Connection conn = session.getConnection(); + reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_binding/CreateDB.sql"); + ScriptRunner runner = new ScriptRunner(conn); + runner.setLogWriter(null); + runner.runScript(reader); + reader.close(); + session.close(); + } + + @Test + public void shouldGetAUserByArrayIndex() { + SqlSession sqlSession = sqlSessionFactory.openSession(); + try { + Mapper mapper = sqlSession.getMapper(Mapper.class); + User user = mapper.getUserFromBoundArray(); + Assert.assertEquals("User1", user.getName()); + } finally { + sqlSession.close(); + } + } + +} diff --git a/src/test/java/org/apache/ibatis/submitted/array_binding/CreateDB.sql b/src/test/java/org/apache/ibatis/submitted/array_binding/CreateDB.sql new file mode 100644 index 00000000000..2354824ab88 --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/array_binding/CreateDB.sql @@ -0,0 +1,24 @@ +-- +-- Copyright 2009-2016 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. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- + +drop table users if exists; + +create table users ( + id int, + name varchar(20) +); + +insert into users (id, name) values(1, 'User1'); diff --git a/src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.java b/src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.java new file mode 100644 index 00000000000..dfd42bf8d7a --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.java @@ -0,0 +1,22 @@ +/** + * Copyright 2009-2016 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. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.submitted.array_binding; + +public interface Mapper { + + User getUserFromBoundArray(); + +} diff --git a/src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.xml b/src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.xml new file mode 100644 index 00000000000..8bf46cd194b --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/array_binding/Mapper.xml @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/src/test/java/org/apache/ibatis/submitted/array_binding/User.java b/src/test/java/org/apache/ibatis/submitted/array_binding/User.java new file mode 100644 index 00000000000..0f0a203c282 --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/array_binding/User.java @@ -0,0 +1,38 @@ +/** + * Copyright 2009-2016 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. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.ibatis.submitted.array_binding; + +public class User { + + private Integer id; + private String name; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/test/java/org/apache/ibatis/submitted/array_binding/mybatis-config.xml b/src/test/java/org/apache/ibatis/submitted/array_binding/mybatis-config.xml new file mode 100644 index 00000000000..82d34eb781a --- /dev/null +++ b/src/test/java/org/apache/ibatis/submitted/array_binding/mybatis-config.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + +