### Question:
HiveUtil { public static Properties getHiveCredentials(Cluster cluster) { String metaStoreUrl = ClusterHelper.getRegistryEndPoint(cluster); if (StringUtils.isBlank(metaStoreUrl)) { throw new IllegalStateException( "Registry interface is not defined in cluster: " + cluster.getName()); } Properties hiveCredentials = new Properties(); hiveCredentials.put(METASTOREURIS, metaStoreUrl); hiveCredentials.put(METASTORE_UGI, "true"); hiveCredentials.put(NODE, metaStoreUrl.replace("thrift", "hcat")); hiveCredentials.put(METASTORE_URI, metaStoreUrl); if (SecurityUtil.isSecurityEnabled()) { String principal = ClusterHelper .getPropertyValue(cluster, SecurityUtil.HIVE_METASTORE_KERBEROS_PRINCIPAL); hiveCredentials.put(SecurityUtil.HIVE_METASTORE_KERBEROS_PRINCIPAL, principal); hiveCredentials.put(SecurityUtil.METASTORE_PRINCIPAL, principal); hiveCredentials.put(SecurityUtil.METASTORE_USE_THRIFT_SASL, "true"); } return hiveCredentials; } private  HiveUtil(); static Properties getHiveCredentials(Cluster cluster); static final String METASTOREURIS; static final String METASTORE_URI; static final String NODE; static final String METASTORE_UGI; }### Answer:
@Test public void testGetHiveCredentialsWithoutKerberos() { StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, PseudoAuthenticationHandler.TYPE); Cluster cluster = new Cluster(); String metaStoreUrl = "thrift: Interfaces interfaces = new Interfaces(); Interface registry = new Interface(); registry.setEndpoint(metaStoreUrl); registry.setType(Interfacetype.REGISTRY); registry.setVersion("0.1"); interfaces.getInterfaces().add(registry); cluster.setInterfaces(interfaces); Properties expected = new Properties(); expected.put(HiveUtil.METASTORE_UGI, "true"); expected.put(HiveUtil.NODE, metaStoreUrl.replace("thrift", "hcat")); expected.put(HiveUtil.METASTORE_URI, metaStoreUrl); expected.put(HiveUtil.METASTOREURIS, metaStoreUrl); Properties actual = HiveUtil.getHiveCredentials(cluster); Assert.assertTrue(actual.equals(expected)); }
@Test public void testGetHiveCredentialsWithKerberos() { StartupProperties.get().setProperty(SecurityUtil.AUTHENTICATION_TYPE, KerberosAuthenticationHandler.TYPE); Cluster cluster = new Cluster(); String metaStoreUrl = "thrift: String principal = "kerberosPrincipal"; Interfaces interfaces = new Interfaces(); Interface registry = new Interface(); registry.setEndpoint(metaStoreUrl); registry.setType(Interfacetype.REGISTRY); registry.setVersion("0.1"); interfaces.getInterfaces().add(registry); cluster.setInterfaces(interfaces); org.apache.falcon.entity.v0.cluster.Properties props = new org.apache.falcon.entity.v0.cluster.Properties(); Property principal2 = new Property(); principal2.setName(SecurityUtil.HIVE_METASTORE_KERBEROS_PRINCIPAL); principal2.setValue(principal); props.getProperties().add(principal2); cluster.setProperties(props); Properties expected = new Properties(); expected.put(SecurityUtil.METASTORE_USE_THRIFT_SASL, "true"); expected.put(SecurityUtil.HIVE_METASTORE_KERBEROS_PRINCIPAL, principal); expected.put(SecurityUtil.METASTORE_PRINCIPAL, principal); expected.put(HiveUtil.METASTORE_UGI, "true"); expected.put(HiveUtil.NODE, metaStoreUrl.replace("thrift", "hcat")); expected.put(HiveUtil.METASTORE_URI, metaStoreUrl); expected.put(HiveUtil.METASTOREURIS, metaStoreUrl); Properties actual = HiveUtil.getHiveCredentials(cluster); Assert.assertTrue(actual.equals(expected)); }