|
| 1 | +/** |
| 2 | + * Copyright 2009-2015 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.apache.ibatis.mapping; |
| 17 | + |
| 18 | +import static org.junit.Assert.*; |
| 19 | + |
| 20 | +import java.util.Collections; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +import org.apache.ibatis.session.Configuration; |
| 26 | +import org.junit.Test; |
| 27 | + |
| 28 | +public class BoundSqlTest { |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testHasAdditionalParameter() throws Exception { |
| 32 | + List<ParameterMapping> params = Collections.emptyList(); |
| 33 | + BoundSql boundSql = new BoundSql(new Configuration(), "some sql", params, new Object()); |
| 34 | + |
| 35 | + Map<String, String> map = new HashMap<String, String>(); |
| 36 | + map.put("key1", "value1"); |
| 37 | + boundSql.setAdditionalParameter("map", map); |
| 38 | + |
| 39 | + Person bean = new Person(); |
| 40 | + bean.id = 1; |
| 41 | + boundSql.setAdditionalParameter("person", bean); |
| 42 | + |
| 43 | + assertFalse(boundSql.hasAdditionalParameter("pet")); |
| 44 | + assertFalse(boundSql.hasAdditionalParameter("pet.name")); |
| 45 | + |
| 46 | + assertTrue(boundSql.hasAdditionalParameter("map")); |
| 47 | + assertTrue(boundSql.hasAdditionalParameter("map.key1")); |
| 48 | + assertTrue("should return true even if the child property does not exists.", boundSql.hasAdditionalParameter("map.key2")); |
| 49 | + |
| 50 | + assertTrue(boundSql.hasAdditionalParameter("person")); |
| 51 | + assertTrue(boundSql.hasAdditionalParameter("person.id")); |
| 52 | + assertTrue("should return true even if the child property does not exists.", boundSql.hasAdditionalParameter("person.name")); |
| 53 | + } |
| 54 | + |
| 55 | + public static class Person { |
| 56 | + public Integer id; |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments