### Question:
ViewTransformation implements TableTransformation { @Override public Table transform(Table table) { if (!MetaStoreUtils.isView(table)) { return table; } LOG.info("Translating HQL of view {}.{}", table.getDbName(), table.getTableName()); String tableQualifiedName = Warehouse.getQualifiedName(table); String hql = hqlTranslator.translate(tableQualifiedName, table.getViewOriginalText()); String expandedHql = hqlTranslator.translate(tableQualifiedName, table.getViewExpandedText()); Table transformedView = new Table(table); transformedView.setViewOriginalText(hql); transformedView.setViewExpandedText(expandedHql); if (!replicaHiveConf.getBoolean(SKIP_TABLE_EXIST_CHECKS, false)) { LOG .info("Validating that tables used by the view {}.{} exist in the replica catalog", table.getDbName(), table.getTableName()); validateReferencedTables(transformedView); } return transformedView; } @Autowired  ViewTransformation(
      HiveConf replicaHiveConf,
      HqlTranslator hqlTranslator,
      Supplier<CloseableMetaStoreClient> replicaMetaStoreClientSupplier); @Override Table transform(Table table);  }### Answer:
@Test public void skipTables() { when(table.getTableType()).thenReturn(TableType.EXTERNAL_TABLE.name()); Table transformedTable = transformation.transform(table); assertThat(transformedTable, is(table)); }
@Test public void transform() { Table transformedTable = transformation.transform(table); assertThat(transformedTable, is(not(table))); verify(translator).translate(QUALIFIED_NAME, ORIGINAL_HQL); verify(translator).translate(QUALIFIED_NAME, EXPANDED_HQL); assertThat(transformedTable.getViewOriginalText(), is(ORIGINAL_TRANSLATED_HQL)); assertThat(transformedTable.getViewExpandedText(), is(EXPANDED_TRANSLATED_HQL)); }
@Test(expected = CircusTrainException.class) public void underlyingTableIsMissing() throws Exception { hiveConf.setBoolean(ViewTransformation.SKIP_TABLE_EXIST_CHECKS, false); when(metaStoreClient.getTable("replica", "tt")).thenThrow(new NoSuchObjectException()); transformation.transform(table); }
@Test public void underlyingTablesExist() { hiveConf.setBoolean(ViewTransformation.SKIP_TABLE_EXIST_CHECKS, false); when(table.getTableType()).thenReturn(TableType.VIRTUAL_VIEW.name()); Table transformedTable = transformation.transform(table); assertThat(transformedTable, is(not(table))); verify(translator).translate(QUALIFIED_NAME, ORIGINAL_HQL); verify(translator).translate(QUALIFIED_NAME, EXPANDED_HQL); assertThat(transformedTable.getViewOriginalText(), is(ORIGINAL_TRANSLATED_HQL)); assertThat(transformedTable.getViewExpandedText(), is(EXPANDED_TRANSLATED_HQL)); }