@Test
public void testGetResources_KerberosSpecificProperties_KDCInvalidCredentials() throws Exception{

  AmbariManagementController managementController = createMock(AmbariManagementController.class);
  Clusters clusters = createNiceMock(Clusters.class);
  Cluster cluster = createNiceMock(Cluster.class);
  Service service0 = createNiceMock(Service.class);
  ServiceResponse serviceResponse0 = createNiceMock(ServiceResponse.class);
  StackId stackId = createNiceMock(StackId.class);
  ServiceFactory serviceFactory = createNiceMock(ServiceFactory.class);
  AmbariMetaInfo ambariMetaInfo = createNiceMock(AmbariMetaInfo.class);
  KerberosHelper kerberosHeper = createStrictMock(KerberosHelper.class);
  Map<String, Service> allResponseMap = new HashMap<String, Service>();
  allResponseMap.put("KERBEROS", service0);
  // set expectations
  expect(managementController.getClusters()).andReturn(clusters).anyTimes();
  expect(managementController.getAmbariMetaInfo()).andReturn(ambariMetaInfo).anyTimes();
  expect(managementController.getHostComponents(EasyMock.<Set<ServiceComponentHostRequest>>anyObject())).
      andReturn(Collections.<ServiceComponentHostResponse>emptySet()).anyTimes();
  expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes();
  expect(cluster.getServices()).andReturn(allResponseMap).anyTimes();
  expect(cluster.getService("KERBEROS")).andReturn(service0);
  expect(service0.convertToResponse()).andReturn(serviceResponse0).anyTimes();
  expect(service0.getName()).andReturn("Service100").anyTimes();
  expect(serviceResponse0.getClusterName()).andReturn("Cluster100").anyTimes();
  expect(serviceResponse0.getServiceName()).andReturn("KERBEROS").anyTimes();
  kerberosHeper.validateKDCCredentials(cluster);
  expectLastCall().andThrow(new KerberosAdminAuthenticationException("Invalid KDC administrator credentials."));
  // replay
  replay(managementController, clusters, cluster, service0, serviceResponse0,
      ambariMetaInfo, stackId, serviceFactory, kerberosHeper);
  SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
  ResourceProvider provider = getServiceProvider(managementController);
  // set kerberos helper on provider
  Class<?> c = provider.getClass();
  Field f = c.getDeclaredField("kerberosHelper");
  f.setAccessible(true);
  f.set(provider, kerberosHeper);
  // create the request
  Predicate predicate = new PredicateBuilder().property(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").and().
      property(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("KERBEROS").toPredicate();
  Request request = PropertyHelper.getReadRequest("ServiceInfo", "Services");
  Set<Resource> resources = provider.getResources(request, predicate);
  Assert.assertEquals(1, resources.size());
  for (Resource resource : resources) {
    Assert.assertEquals("Cluster100", resource.getPropertyValue(ServiceResourceProvider.SERVICE_CLUSTER_NAME_PROPERTY_ID));
    Assert.assertEquals("KERBEROS", resource.getPropertyValue(ServiceResourceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID));
    Assert.assertEquals("INVALID_CREDENTIALS", resource.getPropertyValue("Services/attributes/kdc_validation_result"));
    Assert.assertEquals("Invalid KDC administrator credentials.", resource.getPropertyValue("Services/attributes/kdc_validation_failure_details"));
  }
  // verify
  verify(managementController, clusters, cluster, service0, serviceResponse0,
      ambariMetaInfo, stackId, serviceFactory, kerberosHeper);
}