@Test
public void testGetResources() throws Exception{

  AmbariManagementController managementController = EasyMock.createMock(AmbariManagementController.class);
  RepositoryResponse rr = new RepositoryResponse(VAL_BASE_URL, VAL_OS,
      VAL_REPO_ID, VAL_REPO_NAME, null, null, null);
  rr.setStackName(VAL_STACK_NAME);
  rr.setStackVersion(VAL_STACK_VERSION);
  Set<RepositoryResponse> allResponse = new HashSet<RepositoryResponse>();
  allResponse.add(rr);
  // set expectations
  expect(managementController.getRepositories(EasyMock.<Set<RepositoryRequest>>anyObject())).andReturn(allResponse).times(2);
  // replay
  replay(managementController);
  ResourceProvider provider = new RepositoryResourceProvider(managementController);
  Set<String> propertyIds = new HashSet<String>();
  propertyIds.add(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID);
  propertyIds.add(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID);
  propertyIds.add(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID);
  propertyIds.add(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID);
  propertyIds.add(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID);
  propertyIds.add(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID);
  propertyIds.add(RepositoryResourceProvider.REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID);
  Predicate predicate =
      new PredicateBuilder().property(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID).equals(VAL_STACK_NAME)
        .and().property(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID).equals(VAL_STACK_VERSION)
        .toPredicate();
  // create the request
  Request request = PropertyHelper.getReadRequest(propertyIds);
  // get all ... no predicate
  Set<Resource> resources = provider.getResources(request, predicate);
  Assert.assertEquals(allResponse.size(), resources.size());
  for (Resource resource : resources) {
    Object o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID);
    Assert.assertEquals(VAL_STACK_NAME, o);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID);
    Assert.assertEquals(VAL_STACK_VERSION, o);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID);
    Assert.assertEquals(o, VAL_REPO_NAME);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID);
    Assert.assertEquals(o, VAL_BASE_URL);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID);
    Assert.assertEquals(o, VAL_OS);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID);
    Assert.assertEquals(o, VAL_REPO_ID);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID);
    Assert.assertNull(o);
  }
  // !!! check that the stack version id is returned
  rr.setClusterVersionId(525L);
  resources = provider.getResources(request, predicate);
  Assert.assertEquals(allResponse.size(), resources.size());
  for (Resource resource : resources) {
    Object o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_NAME_PROPERTY_ID);
    Assert.assertEquals(VAL_STACK_NAME, o);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_STACK_VERSION_PROPERTY_ID);
    Assert.assertEquals(VAL_STACK_VERSION, o);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_NAME_PROPERTY_ID);
    Assert.assertEquals(o, VAL_REPO_NAME);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_BASE_URL_PROPERTY_ID);
    Assert.assertEquals(o, VAL_BASE_URL);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_OS_TYPE_PROPERTY_ID);
    Assert.assertEquals(o, VAL_OS);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_REPO_ID_PROPERTY_ID);
    Assert.assertEquals(o, VAL_REPO_ID);
    o = resource.getPropertyValue(RepositoryResourceProvider.REPOSITORY_CLUSTER_STACK_VERSION_PROPERTY_ID);
    Assert.assertEquals(525L, o);
  }
  // verify
  verify(managementController);
}