### Question:
KerberosDescriptor extends AbstractKerberosDescriptorContainer { public Map<String, String> principals() throws AmbariException { Map<String, String> result = new HashMap<>(); for (AbstractKerberosDescriptorContainer each : nullToEmpty(getChildContainers())) { if ((each instanceof KerberosServiceDescriptor)) { collectFromComponents(each.getName(), nullToEmpty(((KerberosServiceDescriptor) each).getComponents()).values(), result); collectFromIdentities(each.getName(), "", nullToEmpty(each.getIdentities()), result); } } return result; } KerberosDescriptor();   KerberosDescriptor(Map<?, ?> data); @Override Collection<? extends AbstractKerberosDescriptorContainer> getChildContainers(); @Override AbstractKerberosDescriptorContainer getChildContainer(String name); void setServices(Map<String, KerberosServiceDescriptor> services); Map<String, KerberosServiceDescriptor> getServices(); KerberosServiceDescriptor getService(String name); void putService(KerberosServiceDescriptor service); void setProperties(Map<String, String> properties); Map<String, String> getProperties(); String getProperty(String name); void putProperty(String name, String value); void update(KerberosDescriptor updates); @Override Map<String, Object> toMap(); @Override void setParent(AbstractKerberosDescriptor parent); @Override int hashCode(); @Override boolean equals(Object object); Set<String> getAllAuthToLocalProperties(); Map<String, String> principals();  }### Answer:
@Test public void testCollectPrincipalNames() throws Exception { URL systemResourceURL = ClassLoader.getSystemResource("kerberos/test_get_referenced_identity_descriptor.json"); KerberosDescriptor descriptor = KERBEROS_DESCRIPTOR_FACTORY.createInstance(new File(systemResourceURL.getFile())); Map<String, String> principalsPerComponent = descriptor.principals(); Assert.assertEquals("service2_component1@${realm}", principalsPerComponent.get("SERVICE2/SERVICE2_COMPONENT1/service2_component1_identity")); Assert.assertEquals("service1@${realm}", principalsPerComponent.get("SERVICE1/service1_identity")); }