@Test
  public void testCredentialStoreFields() throws Exception {
    /*
     * <credential-store> supported and enabled.
     */
    String serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>RANGER</name>\n" +
        "      <credential-store>\n" +
        "          <supported>true</supported>\n" +
        "          <enabled>true</enabled>\n" +
        "          <required>true</required>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";
    Map<String, ServiceInfo> serviceInfoMap = getServiceInfo(serviceInfoXml);
    ServiceInfo service = serviceInfoMap.get("RANGER");
    assertTrue(service.isCredentialStoreSupported());
    assertTrue(service.isCredentialStoreEnabled());
    assertTrue(service.isCredentialStoreRequired());

    /*
     * <credential-store> supported but not enabled.
     */
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>HIVE</name>\n" +
        "      <credential-store>\n" +
        "          <supported>true</supported>\n" +
        "          <enabled>false</enabled>\n" +
        "          <required>false</required>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";
    serviceInfoMap = getServiceInfo(serviceInfoXml);
    service = serviceInfoMap.get("HIVE");
    assertTrue(service.isCredentialStoreSupported());
    assertFalse(service.isCredentialStoreEnabled());
    assertFalse(service.isCredentialStoreRequired());

    /*
     * <credential-store> is missing
     */
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>AMBARI_METRICS</name>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";
    serviceInfoMap = getServiceInfo(serviceInfoXml);
    service = serviceInfoMap.get("AMBARI_METRICS");
    assertFalse(service.isCredentialStoreSupported());
    assertFalse(service.isCredentialStoreEnabled());

    /*
     * <credential-store><enabled> is missing. Invalid
     * scenario. So both values should be false.
     */
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>HBASE</name>\n" +
        "      <credential-store>\n" +
        "          <supported>true</supported>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";
    serviceInfoMap = getServiceInfo(serviceInfoXml);
    service = serviceInfoMap.get("HBASE");
    assertTrue(service.isCredentialStoreSupported());
    assertFalse(service.isCredentialStoreEnabled());
  }
Tests the presence and absence of the credential-store block.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/ServiceInfoTest.java