001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.servicemix.components.jdbc;
018:
019: import java.sql.ResultSetMetaData;
020: import java.sql.SQLException;
021:
022: import junit.framework.TestCase;
023:
024: public class JdbcComponentUniqueNamesTest extends TestCase {
025:
026: public void testNames() throws Exception {
027:
028: JdbcComponent comp = new JdbcComponent();
029:
030: String[] names = new String[] { "name", "name", "name", "id",
031: "test_1", "test_1", "test_1" };
032:
033: ResultSetMetaData metaData = new MetaMock(names);
034: String[] uniqueColumnNames = comp
035: .getUniqueColumnNames(metaData);
036:
037: String[] expected = new String[] { "name", "name_1", "name_2",
038: "id", "test_1", "test_1_1", "test_1_2" };
039:
040: for (int i = 0; i < uniqueColumnNames.length; i++) {
041: assertEquals(expected[i], uniqueColumnNames[i]);
042: }
043: }
044:
045: private static class MetaMock implements ResultSetMetaData {
046:
047: private final String[] names;
048:
049: MetaMock(String[] names) {
050: this .names = names;
051: }
052:
053: public int getColumnCount() throws SQLException {
054: return names.length;
055: }
056:
057: public String getColumnName(int column) throws SQLException {
058: return names[column - 1];
059: }
060:
061: public String getCatalogName(int column) throws SQLException {
062: throw new RuntimeException("not implemented");
063: }
064:
065: public String getColumnClassName(int column)
066: throws SQLException {
067: throw new RuntimeException("not implemented");
068: }
069:
070: public int getColumnDisplaySize(int column) throws SQLException {
071: throw new RuntimeException("not implemented");
072: }
073:
074: public String getColumnLabel(int column) throws SQLException {
075: throw new RuntimeException("not implemented");
076: }
077:
078: public int getColumnType(int column) throws SQLException {
079: throw new RuntimeException("not implemented");
080: }
081:
082: public String getColumnTypeName(int column) throws SQLException {
083: throw new RuntimeException("not implemented");
084: }
085:
086: public int getPrecision(int column) throws SQLException {
087: throw new RuntimeException("not implemented");
088: }
089:
090: public int getScale(int column) throws SQLException {
091: throw new RuntimeException("not implemented");
092: }
093:
094: public String getSchemaName(int column) throws SQLException {
095: throw new RuntimeException("not implemented");
096: }
097:
098: public String getTableName(int column) throws SQLException {
099: throw new RuntimeException("not implemented");
100: }
101:
102: public boolean isAutoIncrement(int column) throws SQLException {
103: throw new RuntimeException("not implemented");
104: }
105:
106: public boolean isCaseSensitive(int column) throws SQLException {
107: throw new RuntimeException("not implemented");
108: }
109:
110: public boolean isCurrency(int column) throws SQLException {
111: throw new RuntimeException("not implemented");
112: }
113:
114: public boolean isDefinitelyWritable(int column)
115: throws SQLException {
116: throw new RuntimeException("not implemented");
117: }
118:
119: public int isNullable(int column) throws SQLException {
120: throw new RuntimeException("not implemented");
121: }
122:
123: public boolean isReadOnly(int column) throws SQLException {
124: throw new RuntimeException("not implemented");
125: }
126:
127: public boolean isSearchable(int column) throws SQLException {
128: throw new RuntimeException("not implemented");
129: }
130:
131: public boolean isSigned(int column) throws SQLException {
132: throw new RuntimeException("not implemented");
133: }
134:
135: public boolean isWritable(int column) throws SQLException {
136: throw new RuntimeException("not implemented");
137: }
138:
139: public boolean isWrapperFor(Class arg0) throws SQLException {
140: throw new RuntimeException("not implemented");
141: }
142:
143: public Object unwrap(Class arg0) throws SQLException {
144: throw new RuntimeException("not implemented");
145: }
146:
147: }
148:
149: }
|