@Test
  public void testTransformerManagedTable() throws Exception {
    try {
      resetHMSClient();

      final String dbName = "db1";
      String basetblName = "oldstylemgdtable";
      Map<String, Object> tProps = new HashMap<>();

      String tblName = basetblName;
      tProps.put("DBNAME", dbName);
      tProps.put("TBLNAME", tblName);
      tProps.put("TBLTYPE", TableType.MANAGED_TABLE);
      // create unbucketed managed table with no capabilities
      Table tbl = createTableWithCapabilities(tProps);

      // retrieve the table
      Table tbl2 = client.getTable(dbName, tblName);
      LOG.info("Table=" + tblName + ",Access=" + tbl2.getAccessType());
      assertEquals("Created and retrieved tables do not match:" + tbl2.getTableName() + ":" + tblName,
          tbl2.getTableName(), tblName);
      assertEquals("TableType mismatch", TableType.EXTERNAL_TABLE.name(), tbl2.getTableType()); // transformed
      assertEquals(-1, tbl2.getSd().getNumBuckets());
      assertEquals("Table access type does not match expected value:" + tblName,
          0, tbl2.getAccessType()); // no translation to be done, so accessType not set
      assertNull("Required read capabilities not null", tbl2.getRequiredReadCapabilities());
      assertNull("Required write capabilities not null", tbl2.getRequiredWriteCapabilities());

      // managed table with no capabilities
      tblName = "test_mgd_insert_woc";
      StringBuilder properties = new StringBuilder();
      tProps.put("TBLNAME", tblName);
      properties.append("transactional=true");
      properties.append(";");
      properties.append("transactional_properties=insert_only");
      tProps.put("PROPERTIES", properties.toString());

      setHMSClient("createTable", new String[] {"HIVEMANAGEDINSERTWRITE", "HIVEFULLACIDWRITE"});
      tbl = createTableWithCapabilities(tProps);
      resetHMSClient();

      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          0, tbl2.getAccessType()); // no transformation

      setHMSClient("testMGDwithConnectorRead", new String[] {"CONNECTORREAD"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READONLY, tbl2.getAccessType());
      assertNotNull("Required write capabilities are null", tbl2.getRequiredWriteCapabilities());
      assertTrue("Required write capabilities does not contain CONNECTORWRITE",
              tbl2.getRequiredWriteCapabilities().contains("CONNECTORWRITE"));
      resetHMSClient();

      setHMSClient("testMGDwithInsertRead", new String[] {"HIVEMANAGEDINSERTREAD"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READONLY, tbl2.getAccessType());
      assertNotNull("Required write capabilities are null", tbl2.getRequiredWriteCapabilities());
      assertTrue("Required write capabilities does not contain CONNECTORWRITE",
              tbl2.getRequiredWriteCapabilities().contains("CONNECTORWRITE"));
      resetHMSClient();

      setHMSClient("testMGDwithInsertWrite", new String[] {"HIVEMANAGEDINSERTWRITE"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      assertNull("Required read capabilities are not null", tbl2.getRequiredReadCapabilities());
      assertNull("Required write capabilities are not null", tbl2.getRequiredWriteCapabilities());
      resetHMSClient();

      setHMSClient("testMGDwithConnectorWrite", new String[] {"CONNECTORWRITE"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      assertNull("Required read capabilities are not null", tbl2.getRequiredReadCapabilities());
      resetHMSClient();

      // bucketed table with no capabilities
      tblName = "test_mgd_insert_wc";
      properties = new StringBuilder();
      properties.append("transactional=true");
      properties.append(";");
      properties.append(CAPABILITIES_KEY).append("=").append("HIVEMANAGEDINSERTREAD,HIVEMANAGEDINSERTWRITE,HIVECACHEINVALIDATE,")
                .append("HIVEMANAGEDSTATS,CONNECTORREAD,CONNECTORWRITE");
      properties.append(";");
      properties.append("transactional_properties=insert_only");
      tProps.put("TBLNAME", tblName);
      tProps.put("PROPERTIES", properties.toString());
      setHMSClient("createTable", new String[] {"HIVEMANAGEDINSERTWRITE" ,"HIVEFULLACIDWRITE"});
      tbl = createTableWithCapabilities(tProps);
      resetHMSClient();

      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          0, tbl2.getAccessType());

      setHMSClient("testMGDwithAllWrites", new String[] { "HIVEMANAGEDINSERTWRITE", "HIVECACHEINVALIDATE",
          "HIVEMANAGEDSTATS" , "CONNECTORWRITE" });
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      assertNull("Required read capabilities are not null", tbl2.getRequiredReadCapabilities());
      assertNull("Required write capabilities are not null", tbl2.getRequiredWriteCapabilities());
      resetHMSClient();

      setHMSClient("testMGDwith1MissingWrite", new String[] {"HIVEMANAGEDINSERTREAD", "HIVEMANAGEDINSERTWRITE",
          "HIVECACHEINVALIDATE" });
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READONLY, tbl2.getAccessType());
      assertNull("Required read capabilities are not null", tbl2.getRequiredReadCapabilities());
      assertNotNull("Required write capabilities are null", tbl2.getRequiredWriteCapabilities());
      assertTrue("Required write capabilities contains HIVEMANAGEDSTATS",
              tbl2.getRequiredWriteCapabilities().contains("HIVEMANAGEDSTATS"));
      resetHMSClient();

      setHMSClient("testMGDwith1Write", new String[] {"CONNECTORWRITE"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDwithConnectorRead", new String[] {"CONNECTORREAD"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READONLY, tbl2.getAccessType());
      resetHMSClient();

      // managed tables with no capabilities
      tblName = "test_mgd_full_woc";
      properties = new StringBuilder();
      properties.append("transactional=true");
      properties.append(";");
      tProps.put("TBLNAME", tblName);
      tProps.put("TBLTYPE", TableType.MANAGED_TABLE);
      tProps.put("PROPERTIES", properties.toString());
      setHMSClient("createTable", new String[] {"HIVEMANAGEDINSERTWRITE", "HIVEFULLACIDWRITE"});
      tbl = createTableWithCapabilities(tProps);
      resetHMSClient();

      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          0, tbl2.getAccessType()); // translation skipped due to no capabilities

      setHMSClient("testMGDwithRAWMETADATA", new String[] {"MANAGERAWMETADATA"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          0, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDwithConnectorRead", new String[] {"CONNECTORREAD"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READONLY, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDwithFullACIDRead", new String[] {"HIVEFULLACIDREAD"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READONLY, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDwith1Write", new String[] {"HIVEFULLACIDWRITE"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDwithConnectorWrite", new String[] {"CONNECTORWRITE"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      resetHMSClient();

      // bucketed table with no capabilities
      tblName = "test_mgd_full_wc";
      properties = new StringBuilder();
      properties.append("transactional=true");
      properties.append(";");
      properties.append(CAPABILITIES_KEY).append("=").append("HIVEFULLACIDREAD,HIVEFULLACIDWRITE,HIVECACHEINVALIDATE,")
                .append("HIVEMANAGEDSTATS,CONNECTORREAD,CONNECTORWRITE");
      tProps.put("TBLNAME", tblName);
      tProps.put("TBLTYPE", TableType.MANAGED_TABLE);
      tProps.put("PROPERTIES", properties.toString());
      setHMSClient("createTable", new String[] {"HIVEMANAGEDINSERTWRITE", "HIVEFULLACIDWRITE"});
      tbl = createTableWithCapabilities(tProps);
      resetHMSClient();

      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          0, tbl2.getAccessType());

      setHMSClient("testMGDwithRAWMETADATA", new String[] {"MANAGERAWMETADATA"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          0, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDFULLwithAllWrites", new String[] { "HIVEFULLACIDWRITE", "HIVECACHEINVALIDATE",
          "HIVEMANAGEDSTATS", "CONNECTORWRITE" });
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDFULLwith1MissingWrite", new String[] { "HIVECACHEINVALIDATE",
          "HIVEMANAGEDSTATS", "CONNECTORWRITE" });
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDFULLwith1Write", new String[] { "CONNECTORWRITE" });
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDwith1MissingWrite", new String[] {"HIVEFULLACIDREAD", "HIVEFULLACIDWRITE",
          "HIVECACHEINVALIDATE" });
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READWRITE, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testMGDwithConnectorRead", new String[] {"CONNECTORREAD"});
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match expected value:" + tblName,
          ACCESSTYPE_READONLY, tbl2.getAccessType());
      resetHMSClient();

      setHMSClient("testTranformerExternalTable", (new String[] { "HIVEBUCKET2", "EXTREAD", "EXTWRITE"}));
      tbl2 = client.getTable(dbName, tblName);
      assertEquals("Table access type does not match the expected value:" + tblName,
          ACCESSTYPE_NONE, tbl2.getAccessType());

      resetHMSClient();

      LOG.info("Test execution complete:testTransformerManagedTable");
    } catch (Exception e) {
      e.printStackTrace();
      fail("testTransformerManagedTable failed with " + e.getMessage());
    } finally {
      resetHMSClient();
    }
  }
EXTERNAL_TABLE
  1) Old table (name in upper case) with no capabilities
  2) Old table with no capabilities
  3a) New table with capabilities with no client requirements
  3b) New table with capabilities with no matching client requirements
  3c) New table with capabilities with partial match requirements
  3d) New table with capabilities with full match requirements
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetastoreTransformer.java