|
| 1 | +/* |
| 2 | + * Copyright © 2023 Cask Data, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * 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, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.cdap.plugin.util; |
| 18 | + |
| 19 | +import org.junit.Assert; |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +/** |
| 23 | + * Test class for FQNGenerator. |
| 24 | + */ |
| 25 | +public class FQNGeneratorTest { |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testMySQLFQN() { |
| 29 | + // Testcases consist of Connection URL, Table Name, Expected FQN String |
| 30 | + String[][] testCases = {{"jdbc:mysql://localhost:1111/db", "table1", "mysql://localhost:1111/db.table1"}, |
| 31 | + {"jdbc:mysql://34.35.36.37/db?useSSL=false", "table2", |
| 32 | + "mysql://34.35.36.37:3306/db.table2"}}; |
| 33 | + for (int i = 0; i < testCases.length; i++) { |
| 34 | + String fqn = FQNGenerator.constructFQN(testCases[i][0], testCases[i][1]); |
| 35 | + Assert.assertEquals(testCases[i][2], fqn); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testSQLServerFQN() { |
| 41 | + // Testcases consist of Connection URL, Table Name, Expected FQN String |
| 42 | + String[][] testCases = {{"jdbc:sqlserver://;serverName=127.0.0.1;databaseName=DB", |
| 43 | + "table1", "sqlserver://127.0.0.1:1433/DB.table1"}, |
| 44 | + {"jdbc:sqlserver://localhost:1111;databaseName=DB;encrypt=true;user=user;password=pwd;", |
| 45 | + "table2", "sqlserver://localhost:1111/DB.table2"}}; |
| 46 | + for (int i = 0; i < testCases.length; i++) { |
| 47 | + String fqn = FQNGenerator.constructFQN(testCases[i][0], testCases[i][1]); |
| 48 | + Assert.assertEquals(testCases[i][2], fqn); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testOracleFQN() { |
| 54 | + // Testcases consist of Connection URL, Table Name, Expected FQN String |
| 55 | + String[][] testCases = {{"jdbc:oracle:thin:@localhost:db", "table1", "oracle://localhost:1521/db.table1"}, |
| 56 | + {"jdbc:oracle:thin:@test.server:1111/db", |
| 57 | + "table2", "oracle://test.server:1111/db.table2"}}; |
| 58 | + for (int i = 0; i < testCases.length; i++) { |
| 59 | + String fqn = FQNGenerator.constructFQN(testCases[i][0], testCases[i][1]); |
| 60 | + Assert.assertEquals(testCases[i][2], fqn); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testPostgresqlFQN() { |
| 66 | + // Testcases consist of Connection URL, Table Name, Expected FQN String |
| 67 | + String[][] testCases = {{"jdbc:postgresql://34.35.36.37/test?user=user&password=secret&ssl=true", |
| 68 | + "table1", "postgresql://34.35.36.37:5432/test.public.table1"}, |
| 69 | + {"jdbc:postgresql://localhost/test?connectionSchema=schema", |
| 70 | + "table2", "postgresql://localhost:5432/test.schema.table2"}, |
| 71 | + {"jdbc:postgresql://localhost/test?searchpath=schema", |
| 72 | + "table3", "postgresql://localhost:5432/test.schema.table3"}}; |
| 73 | + for (int i = 0; i < testCases.length; i++) { |
| 74 | + String fqn = FQNGenerator.constructFQN(testCases[i][0], testCases[i][1]); |
| 75 | + Assert.assertEquals(testCases[i][2], fqn); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
0 commit comments