|
| 1 | +/** |
| 2 | + * Licensed to JumpMind Inc under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed |
| 4 | + * with this work for additional information regarding |
| 5 | + * copyright ownership. JumpMind Inc licenses this file |
| 6 | + * to you under the GNU General Public License, version 3.0 (GPLv3) |
| 7 | + * (the "License"); you may not use this file except in compliance |
| 8 | + * with the License. |
| 9 | + * |
| 10 | + * You should have received a copy of the GNU General Public License, |
| 11 | + * version 3.0 (GPLv3) along with this library; if not, see |
| 12 | + * <http://www.gnu.org/licenses/>. |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, |
| 15 | + * software distributed under the License is distributed on an |
| 16 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | + * KIND, either express or implied. See the License for the |
| 18 | + * specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + */ |
| 21 | +package org.jumpmind.db.platform; |
| 22 | + |
| 23 | +import static org.junit.Assert.assertEquals; |
| 24 | +import static org.mockito.Mockito.mock; |
| 25 | + |
| 26 | +import java.sql.SQLException; |
| 27 | +import java.util.HashMap; |
| 28 | +import java.util.Map; |
| 29 | + |
| 30 | +import org.jumpmind.db.model.ForeignKey; |
| 31 | +import org.jumpmind.db.model.Reference; |
| 32 | +import org.junit.jupiter.api.Test; |
| 33 | +import org.mockito.Answers; |
| 34 | + |
| 35 | +public class AbstractJdbcDdlReaderTest { |
| 36 | + @Test |
| 37 | + public void testReadExportedKey() throws SQLException { |
| 38 | + AbstractJdbcDdlReader ddlReader = mock(AbstractJdbcDdlReader.class, Answers.CALLS_REAL_METHODS); |
| 39 | + Map<String, Object> metadataMap = new HashMap<String, Object>(); |
| 40 | + metadataMap.put("FK_NAME", "test_fk"); |
| 41 | + metadataMap.put("FKTABLE_NAME", "test_table"); |
| 42 | + metadataMap.put("fktable_cat", "test_catalog_lowercase"); |
| 43 | + metadataMap.put("fktable_schem", "test_schema_lowercase"); |
| 44 | + metadataMap.put("FKCOLUMN_NAME", "foreign_col"); |
| 45 | + metadataMap.put("PKCOLUMN_NAME", "local_col"); |
| 46 | + metadataMap.put("KEY_SEQ", (short) 123); |
| 47 | + Map<String, ForeignKey> fkMap = new HashMap<String, ForeignKey>(); |
| 48 | + ddlReader.readExportedKey(null, metadataMap, fkMap); |
| 49 | + assertEquals(1, fkMap.size()); |
| 50 | + ForeignKey fk = fkMap.get("test_fk"); |
| 51 | + assertEquals("test_fk", fk.getName()); |
| 52 | + assertEquals("test_table", fk.getForeignTableName()); |
| 53 | + assertEquals("test_catalog_lowercase", fk.getForeignTableCatalog()); |
| 54 | + assertEquals("test_schema_lowercase", fk.getForeignTableSchema()); |
| 55 | + assertEquals(1, fk.getReferenceCount()); |
| 56 | + Reference reference = fk.getFirstReference(); |
| 57 | + assertEquals("foreign_col", reference.getForeignColumnName()); |
| 58 | + assertEquals("local_col", reference.getLocalColumnName()); |
| 59 | + assertEquals(123, reference.getSequenceValue()); |
| 60 | + metadataMap.put("FKTABLE_CAT", "TEST_CATALOG_UPPERCASE"); |
| 61 | + metadataMap.put("FKTABLE_SCHEM", "TEST_SCHEMA_UPPERCASE"); |
| 62 | + fkMap.clear(); |
| 63 | + ddlReader.readExportedKey(null, metadataMap, fkMap); |
| 64 | + assertEquals(1, fkMap.size()); |
| 65 | + fk = fkMap.get("test_fk"); |
| 66 | + assertEquals("TEST_CATALOG_UPPERCASE", fk.getForeignTableCatalog()); |
| 67 | + assertEquals("TEST_SCHEMA_UPPERCASE", fk.getForeignTableSchema()); |
| 68 | + ddlReader.readExportedKey(null, metadataMap, fkMap); |
| 69 | + assertEquals(1, fkMap.size()); |
| 70 | + } |
| 71 | +} |
0 commit comments