|
21 | 21 | import com.google.edwmigration.dumper.application.dumper.ConnectorArguments; |
22 | 22 | import com.google.edwmigration.dumper.application.dumper.MetadataDumperUsageException; |
23 | 23 | import com.google.edwmigration.dumper.application.dumper.connector.MetadataConnector; |
| 24 | +import com.google.edwmigration.dumper.application.dumper.connector.snowflake.SnowflakeMetadataConnector.PropertyAction; |
24 | 25 | import com.google.edwmigration.dumper.application.dumper.task.JdbcSelectTask; |
25 | 26 | import com.google.edwmigration.dumper.application.dumper.task.Task; |
26 | 27 | import com.google.edwmigration.dumper.plugin.lib.dumper.spi.CoreMetadataDumpFormat; |
|
34 | 35 | import java.util.List; |
35 | 36 | import java.util.Map; |
36 | 37 | import javax.annotation.Nonnull; |
| 38 | +import org.apache.commons.lang3.ArrayUtils; |
37 | 39 | import org.junit.Assert; |
38 | 40 | import org.junit.Assume; |
39 | 41 | import org.junit.Test; |
@@ -154,10 +156,93 @@ public void connector_generatesExpectedSql() throws IOException { |
154 | 156 | } |
155 | 157 | } |
156 | 158 |
|
157 | | - private static Map<String, String> collectSqlStatements() throws IOException { |
| 159 | + @Test |
| 160 | + public void connector_assessment_generatesExpectedSql() throws IOException { |
| 161 | + Map<String, String> actualSqls = collectSqlStatements("--assessment"); |
| 162 | + TaskSqlMap expectedSqls = |
| 163 | + CoreMetadataDumpFormat.MAPPER.readValue( |
| 164 | + Resources.toString( |
| 165 | + Resources.getResource("connector/snowflake/assessment-jdbc-tasks-sql.yaml"), |
| 166 | + StandardCharsets.UTF_8), |
| 167 | + TaskSqlMap.class); |
| 168 | + |
| 169 | + Assert.assertEquals(expectedSqls.size(), actualSqls.size()); |
| 170 | + Assert.assertEquals(expectedSqls.keySet(), actualSqls.keySet()); |
| 171 | + for (String name : expectedSqls.keySet()) { |
| 172 | + Assert.assertEquals(expectedSqls.get(name), actualSqls.get(name)); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + public void connector_generatesExpectedSql_withQueryOverrides() throws IOException { |
| 178 | + for (PropertyAction propertyAction : PropertyAction.values()) { |
| 179 | + TaskSqlMap expectedSqls = |
| 180 | + CoreMetadataDumpFormat.MAPPER.readValue( |
| 181 | + Resources.toString( |
| 182 | + Resources.getResource( |
| 183 | + String.format( |
| 184 | + "connector/snowflake/jdbc-tasks-sql-override-%s.yaml", |
| 185 | + propertyAction.value)), |
| 186 | + StandardCharsets.UTF_8), |
| 187 | + TaskSqlMap.class); |
| 188 | + |
| 189 | + List<String> overrideArguments = new ArrayList<>(); |
| 190 | + for (MetadataView metadataView : MetadataView.values()) { |
| 191 | + overrideArguments.add( |
| 192 | + String.format( |
| 193 | + "-Dsnowflake.metadata.%1$s.%2$s=SQL_OVERRIDE(%1$s, %2$s)", |
| 194 | + metadataView.nameComponent, propertyAction.value)); |
| 195 | + } |
| 196 | + |
| 197 | + Map<String, String> actualSqls = |
| 198 | + collectSqlStatements(overrideArguments.toArray(new String[] {})); |
| 199 | + |
| 200 | + Assert.assertEquals(expectedSqls.size(), actualSqls.size()); |
| 201 | + Assert.assertEquals(expectedSqls.keySet(), actualSqls.keySet()); |
| 202 | + for (String name : expectedSqls.keySet()) { |
| 203 | + Assert.assertEquals(expectedSqls.get(name), actualSqls.get(name)); |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + @Test |
| 209 | + public void connector_assessment_generatesExpectedSql_withQueryOverrides() throws IOException { |
| 210 | + for (PropertyAction propertyAction : PropertyAction.values()) { |
| 211 | + TaskSqlMap expectedSqls = |
| 212 | + CoreMetadataDumpFormat.MAPPER.readValue( |
| 213 | + Resources.toString( |
| 214 | + Resources.getResource( |
| 215 | + String.format( |
| 216 | + "connector/snowflake/assessment-jdbc-tasks-sql-override-%s.yaml", |
| 217 | + propertyAction.value)), |
| 218 | + StandardCharsets.UTF_8), |
| 219 | + TaskSqlMap.class); |
| 220 | + |
| 221 | + List<String> overrideArguments = new ArrayList<>(); |
| 222 | + for (MetadataView metadataView : MetadataView.values()) { |
| 223 | + overrideArguments.add( |
| 224 | + String.format( |
| 225 | + "-Dsnowflake.metadata.%1$s.%2$s=SQL_OVERRIDE(%1$s, %2$s)", |
| 226 | + metadataView.nameComponent, propertyAction.value)); |
| 227 | + } |
| 228 | + |
| 229 | + overrideArguments.add("--assessment"); |
| 230 | + Map<String, String> actualSqls = |
| 231 | + collectSqlStatements(overrideArguments.toArray(new String[] {})); |
| 232 | + |
| 233 | + Assert.assertEquals(expectedSqls.size(), actualSqls.size()); |
| 234 | + Assert.assertEquals(expectedSqls.keySet(), actualSqls.keySet()); |
| 235 | + for (String name : expectedSqls.keySet()) { |
| 236 | + Assert.assertEquals(expectedSqls.get(name), actualSqls.get(name)); |
| 237 | + } |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + private static Map<String, String> collectSqlStatements(String... extraArgs) throws IOException { |
158 | 242 | List<Task<?>> tasks = new ArrayList<>(); |
159 | 243 | SnowflakeMetadataConnector connector = new SnowflakeMetadataConnector(); |
160 | | - connector.addTasksTo(tasks, new ConnectorArguments("--connector", connector.getName())); |
| 244 | + String[] args = ArrayUtils.addAll(new String[] {"--connector", connector.getName()}, extraArgs); |
| 245 | + connector.addTasksTo(tasks, new ConnectorArguments(args)); |
161 | 246 | return tasks.stream() |
162 | 247 | .filter(t -> t instanceof JdbcSelectTask) |
163 | 248 | .map(t -> (JdbcSelectTask) t) |
|
0 commit comments