@Test
  public void testCredentialStoreInfoValidity() throws Exception {
    // Valid: Supported->True, Enabled->False
    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>false</enabled>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    Map<String, ServiceInfo> serviceInfoMap = getServiceInfo(serviceInfoXml);
    ServiceInfo serviceInfo = serviceInfoMap.get("RANGER");
    assertTrue(serviceInfo.isValid());

    // Valid: Supported->True, Enabled->True
    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" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    serviceInfoMap = getServiceInfo(serviceInfoXml);
    serviceInfo = serviceInfoMap.get("RANGER");
    assertTrue(serviceInfo.isValid());

    // Valid: Supported->False, Enabled->False
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>RANGER</name>\n" +
        "      <credential-store>\n" +
        "          <supported>false</supported>\n" +
        "          <enabled>false</enabled>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    serviceInfoMap = getServiceInfo(serviceInfoXml);
    serviceInfo = serviceInfoMap.get("RANGER");
    assertTrue(serviceInfo.isValid());

    // Valid: credential-store not specified
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>RANGER</name>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    serviceInfoMap = getServiceInfo(serviceInfoXml);
    serviceInfo = serviceInfoMap.get("RANGER");
    assertTrue(serviceInfo.isValid());

    // Specified but invalid
    // Invalid: Supported->False, Enabled->True
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>RANGER</name>\n" +
        "      <credential-store>\n" +
        "          <supported>false</supported>\n" +
        "          <enabled>true</enabled>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    serviceInfoMap = getServiceInfo(serviceInfoXml);
    serviceInfo = serviceInfoMap.get("RANGER");
    assertFalse("Credential store is enabled for a service that does not support it", serviceInfo.isValid());

    // Invalid: Supported->Unspecified, Enabled->Unspecified
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>RANGER</name>\n" +
        "      <credential-store>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    serviceInfoMap = getServiceInfo(serviceInfoXml);
    serviceInfo = serviceInfoMap.get("RANGER");
    assertFalse("Credential store details not specified", serviceInfo.isValid());

    // Invalid: Supported->Specified, Enabled->Unspecified
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>RANGER</name>\n" +
        "      <credential-store>\n" +
        "          <supported>true</supported>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    serviceInfoMap = getServiceInfo(serviceInfoXml);
    serviceInfo = serviceInfoMap.get("RANGER");
    assertFalse("Credential store enabled not specified", serviceInfo.isValid());

    // Invalid: Supported->Unspecified, Enabled->Specified
    serviceInfoXml = "<metainfo>\n" +
        "  <schemaVersion>2.0</schemaVersion>\n" +
        "  <services>\n" +
        "    <service>\n" +
        "      <name>RANGER</name>\n" +
        "      <credential-store>\n" +
        "          <enabled>true</enabled>\n" +
        "      </credential-store>\n" +
        "    </service>\n" +
        "  </services>\n" +
        "</metainfo>\n";

    serviceInfoMap = getServiceInfo(serviceInfoXml);
    serviceInfo = serviceInfoMap.get("RANGER");
    assertFalse("Credential store supported not specified", serviceInfo.isValid());
  }
Tests the presence and absence of the credential-store block.

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