|
16 | 16 | */ |
17 | 17 | package com.google.edwmigration.dumper.application.dumper.connector.snowflake; |
18 | 18 |
|
| 19 | +import com.google.common.collect.ImmutableMap; |
| 20 | +import com.google.common.io.Resources; |
| 21 | +import com.google.edwmigration.dumper.application.dumper.ConnectorArguments; |
19 | 22 | import com.google.edwmigration.dumper.application.dumper.MetadataDumperUsageException; |
20 | 23 | import com.google.edwmigration.dumper.application.dumper.connector.MetadataConnector; |
| 24 | +import com.google.edwmigration.dumper.application.dumper.task.JdbcSelectTask; |
| 25 | +import com.google.edwmigration.dumper.application.dumper.task.Task; |
| 26 | +import com.google.edwmigration.dumper.plugin.lib.dumper.spi.CoreMetadataDumpFormat; |
21 | 27 | import com.google.edwmigration.dumper.plugin.lib.dumper.spi.SnowflakeMetadataDumpFormat; |
22 | 28 | import com.google.edwmigration.dumper.test.TestUtils; |
23 | 29 | import java.io.File; |
| 30 | +import java.io.IOException; |
| 31 | +import java.nio.charset.StandardCharsets; |
| 32 | +import java.util.ArrayList; |
| 33 | +import java.util.HashMap; |
| 34 | +import java.util.List; |
| 35 | +import java.util.Map; |
24 | 36 | import javax.annotation.Nonnull; |
25 | 37 | import org.junit.Assert; |
26 | 38 | import org.junit.Assume; |
@@ -124,4 +136,33 @@ public void testDatabaseNameFailure() { |
124 | 136 |
|
125 | 137 | Assert.assertTrue(exception.getMessage().startsWith("Database name not found")); |
126 | 138 | } |
| 139 | + |
| 140 | + @Test |
| 141 | + public void connector_generatesExpectedSql() throws IOException { |
| 142 | + Map<String, String> actualSqls = collectSqlStatements(); |
| 143 | + TaskSqlMap expectedSqls = |
| 144 | + CoreMetadataDumpFormat.MAPPER.readValue( |
| 145 | + Resources.toString( |
| 146 | + Resources.getResource("connector/snowflake/jdbc-tasks-sql.yaml"), |
| 147 | + StandardCharsets.UTF_8), |
| 148 | + TaskSqlMap.class); |
| 149 | + |
| 150 | + Assert.assertEquals(expectedSqls.size(), actualSqls.size()); |
| 151 | + Assert.assertEquals(expectedSqls.keySet(), actualSqls.keySet()); |
| 152 | + for (String name : expectedSqls.keySet()) { |
| 153 | + Assert.assertEquals(expectedSqls.get(name), actualSqls.get(name)); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + private static Map<String, String> collectSqlStatements() throws IOException { |
| 158 | + List<Task<?>> tasks = new ArrayList<>(); |
| 159 | + SnowflakeMetadataConnector connector = new SnowflakeMetadataConnector(); |
| 160 | + connector.addTasksTo(tasks, new ConnectorArguments("--connector", connector.getName())); |
| 161 | + return tasks.stream() |
| 162 | + .filter(t -> t instanceof JdbcSelectTask) |
| 163 | + .map(t -> (JdbcSelectTask) t) |
| 164 | + .collect(ImmutableMap.toImmutableMap(Task::getName, JdbcSelectTask::getSql)); |
| 165 | + } |
| 166 | + |
| 167 | + static class TaskSqlMap extends HashMap<String, String> {} |
127 | 168 | } |
0 commit comments