@Test
  public void testAlterTableChangingDatabase() throws Exception {
    Table originalTable = testTables[2];
    String originalTableName = originalTable.getTableName();
    String originalDatabase = originalTable.getDbName();

    Table newTable = originalTable.deepCopy();
    newTable.setDbName(OTHER_DATABASE);
    client.alter_table(originalDatabase, originalTableName, newTable);
    List<String> tableNames = client.getTables(originalDatabase, originalTableName);
    Assert.assertEquals("Original table should be removed", 0, tableNames.size());
    Assert.assertFalse("Original table directory should be removed",
        metaStore.isPathExists(new Path(originalTable.getSd().getLocation())));
    Table alteredTable = client.getTable(newTable.getDbName(), newTable.getTableName());
    Assert.assertTrue("New table directory should exist",
        metaStore.isPathExists(new Path(alteredTable.getSd().getLocation())));
    Assert.assertEquals("New directory should be set", new Path(metaStore.getWarehouseRoot()
        + "/" + alteredTable.getDbName() + ".db/" + alteredTable.getTableName()),
        new Path(alteredTable.getSd().getLocation()));
    Path dataFile = new Path(alteredTable.getSd().getLocation() + "/dataFile");
    Assert.assertTrue("New directory should contain data", metaStore.isPathExists(dataFile));

    // The following data should be changed, other data should be the same
    newTable.getSd().setLocation(alteredTable.getSd().getLocation());
    Assert.assertEquals("The table data should be the same", newTable, alteredTable);
  }
This test creates and queries a table and then drops it. Good for testing the happy path
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/TestTablesCreateDropAlterTruncate.java