KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > support > JdbcUtilsTests


1 /*
2  * Copyright 2002-2005 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
17 package org.springframework.jdbc.support;
18
19 import java.sql.Types JavaDoc;
20
21 import junit.framework.TestCase;
22
23 /**
24  * TODO this test case needs attention: I wrote it based on Isabelle's documentation
25  * and it appears that JdbcUtils doesn't work exactly as documented.
26  *
27  * @author Rod Johnson
28  * @author Juergen Hoeller
29  */

30 public class JdbcUtilsTests extends TestCase {
31
32     public void testCountParameterPlaceholders() {
33         assertTrue(JdbcUtils.countParameterPlaceholders(null, '?', '\'') == 0);
34
35         assertTrue(JdbcUtils.countParameterPlaceholders("", '?', '\'') == 0);
36
37         assertTrue(JdbcUtils.countParameterPlaceholders("?", '?', '\'') == 1);
38
39         assertTrue(JdbcUtils.countParameterPlaceholders("The big ? 'bad wolf'", '?', '\'') == 1);
40         
41         assertTrue(JdbcUtils.countParameterPlaceholders("The big ?? bad wolf", '?', '\'') == 2);
42         
43         assertTrue(JdbcUtils.countParameterPlaceholders("The big 'ba''ad?' ? wolf", '?', '\'') == 1);
44
45         assertTrue(JdbcUtils.countParameterPlaceholders(null, '?', "\"'") == 0);
46
47         assertTrue(JdbcUtils.countParameterPlaceholders("", '?', "\"'") == 0);
48
49         assertTrue(JdbcUtils.countParameterPlaceholders("?", '?', "\"'") == 1);
50
51         assertTrue(JdbcUtils.countParameterPlaceholders("The \"big\" ? 'bad wolf'", '?', "\"'") == 1);
52         
53         assertTrue(JdbcUtils.countParameterPlaceholders("The big ?? bad wolf", '?', "\"'") == 2);
54         
55         assertTrue(JdbcUtils.countParameterPlaceholders("The \"big?\" 'ba''ad?' ? wolf", '?', "\"'") == 1);
56 }
57
58     public void testIsNumeric() {
59         assertTrue(JdbcUtils.isNumeric(Types.BIGINT));
60         assertTrue(JdbcUtils.isNumeric(Types.NUMERIC));
61         assertTrue(JdbcUtils.isNumeric(Types.INTEGER));
62         assertTrue(JdbcUtils.isNumeric(Types.FLOAT));
63         assertTrue(!JdbcUtils.isNumeric(Types.VARCHAR));
64     }
65
66     public void testTranslateType() {
67         assertTrue(JdbcUtils.translateType(Types.VARCHAR) == Types.VARCHAR);
68         assertTrue(JdbcUtils.translateType(Types.CHAR) == Types.VARCHAR);
69     }
70
71 }
72
Popular Tags