incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject [2/3] AMBARI-2254 - Reduce number of requests when querying for subtasks
Date Thu, 14 Nov 2013 10:39:19 GMT
http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/fc427d9f/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
index ee9b51b..8e02394 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/query/QueryImplTest.java
@@ -1,5 +1,3 @@
-package org.apache.ambari.server.api.query;
-
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,627 +16,364 @@ package org.apache.ambari.server.api.query;
  * limitations under the License.
  */
 
+
+package org.apache.ambari.server.api.query;
+
+
 import org.apache.ambari.server.api.resources.ResourceDefinition;
-import org.apache.ambari.server.api.util.TreeNode;
-import org.apache.ambari.server.api.util.TreeNodeImpl;
-import org.apache.ambari.server.controller.predicate.AndPredicate;
-import org.apache.ambari.server.controller.spi.*;
-import org.apache.ambari.server.controller.utilities.PredicateBuilder;
 import org.apache.ambari.server.api.resources.ResourceInstance;
+import org.apache.ambari.server.api.resources.SubResourceDefinition;
 import org.apache.ambari.server.api.services.Result;
-import org.apache.ambari.server.controller.utilities.PropertyHelper;
-import org.junit.After;
+import org.apache.ambari.server.api.util.TreeNode;
+import org.apache.ambari.server.controller.internal.ClusterControllerImpl;
+import org.apache.ambari.server.controller.internal.ClusterControllerImplTest;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.junit.Assert;
 import org.junit.Test;
 
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 
 import static org.easymock.EasyMock.*;
-
-import static org.easymock.EasyMock.eq;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 
-//todo: add assertions for temporal info
+/**
+ * QueryImpl unit tests.
+ */
 public class QueryImplTest {
 
-  ClusterController m_controller = createNiceMock(ClusterController.class);
-
   @Test
-  public void testExecute__Component_instance_noSpecifiedProps() throws Exception {
-    Result result = createNiceMock(Result.class);
-    ResourceInstance componentResourceInstance = createNiceMock(ResourceInstance.class);
-    ResourceDefinition componentResourceDefinition = createNiceMock(ResourceDefinition.class);
-    ResourceInstance hostResourceInstance = createNiceMock(ResourceInstance.class);
-    ResourceDefinition hostResourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema componentSchema = createNiceMock(Schema.class);
-    Resource componentResource = createNiceMock(Resource.class);
-    String componentPropertyId = "componentId";
-    QueryImpl hostComponentQuery = createStrictMock(QueryImpl.class);
-
-    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
-    Set<Resource> listResources = Collections.singleton(componentResource);
-
-    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
-    mapResourceIds.put(Resource.Type.Cluster, "clusterName");
-    mapResourceIds.put(Resource.Type.Service, "serviceName");
-    mapResourceIds.put(Resource.Type.Component, "componentName");
-
-    Map<String, ResourceInstance> mapChildren = new HashMap<String, ResourceInstance>();
-    mapChildren.put("host_components", hostResourceInstance);
+  public void testIsCollection__True() {
+    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
 
-    PredicateBuilder pb = new PredicateBuilder();
-    Predicate predicate = pb.property("clusterId").equals("clusterName").and().
-        property("serviceId").equals("serviceName").and().
-        property("componentId").equals("componentName").toPredicate();
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+    mapIds.put(Resource.Type.Cluster, "cluster");
+    mapIds.put(Resource.Type.Service, null);
 
     // expectations
-    expect(componentResourceInstance.getResourceDefinition()).andReturn(componentResourceDefinition).anyTimes();
-    expect(componentResourceInstance.getSubResources()).andReturn(mapChildren).anyTimes();
-    expect(componentResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
-
-    expect(hostResourceInstance.createCopy()).andReturn(hostResourceInstance).anyTimes();
-
-    expect(componentResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();
-
-    expect(componentResource.getType()).andReturn(Resource.Type.Component).anyTimes();
-    expect(componentResource.getPropertyValue(componentPropertyId)).andReturn("keyVal");
-
-    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes();
-
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("clusterId");
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceId");
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(componentPropertyId).atLeastOnce();
-
-    expect(m_controller.getRawResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(Collections.<String>emptySet())),
-        eq(predicate))).andReturn(listResources);
-
-    expect(m_controller.getResources(eq(Resource.Type.Component), eq(listResources), eq(predicate))).andReturn(
-        listResources);
-
-    expect(result.getResultTree()).andReturn(tree).anyTimes();
-
-    Map<Resource.Type, String> mapResourceIdsSet = new HashMap<Resource.Type, String>(mapResourceIds);
-    mapResourceIdsSet.put(Resource.Type.Component, "keyVal");
-    hostResourceInstance.setIds(mapResourceIdsSet);
-    expect(hostResourceInstance.getResourceDefinition()).andReturn(hostResourceDefinition).anyTimes();
-    expect(hostResourceInstance.getQuery()).andReturn(hostComponentQuery).anyTimes();
-
-    expect(hostResourceDefinition.getType()).andReturn(Resource.Type.Host);
-
-//    expect(hostComponentQuery.getResourceInstance()).andReturn(hostResourceInstance);
-    expect(hostComponentQuery.getResourceType()).andReturn(Resource.Type.Host);
-    expect(hostComponentQuery.getPredicate()).andReturn(predicate);
-    expect(hostComponentQuery.createRequest()).andReturn(PropertyHelper.getReadRequest(Collections.<String>emptySet()));
-    expect(hostComponentQuery.getProviderResources()).andReturn(Collections.<Resource>emptySet());
-    expect(hostComponentQuery.getSubQueries()).andReturn(Collections.<QueryImpl, Resource>emptyMap());
-    expect(hostComponentQuery.getResourceIterable()).andReturn(Collections.<Resource>emptySet());
-    expect(hostComponentQuery.getResultName()).andReturn("host_components");
-
-
-    replay(m_controller, result, componentResourceInstance, componentResourceDefinition, hostResourceInstance, componentSchema, componentResource,
-        hostComponentQuery);
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(Collections.<SubResourceDefinition>emptySet()).anyTimes();
 
-    QueryImpl query = new TestQuery(componentResourceInstance, result);
-    query.execute();
+    replay(resourceDefinition);
 
-    verify(m_controller, result, componentResourceInstance, componentResourceDefinition, hostResourceInstance, componentSchema, componentResource,
-        hostComponentQuery);
+    //test
+    ResourceInstance instance = new TestQuery(mapIds, resourceDefinition);
+    assertTrue(instance.isCollectionResource());
 
-    assertEquals(1, tree.getChildren().size());
-    TreeNode<Resource> componentNode = tree.getChild("Component:1");
-    assertEquals("Component:1", componentNode.getName());
-    assertEquals(componentResource, componentNode.getObject());
-    assertEquals(1, componentNode.getChildren().size());
-    assertEquals("false", componentNode.getChild("host_components").getProperty("isCollection"));
+    verify(resourceDefinition);
   }
 
   @Test
-  public void testExecute__Component_collection_noSpecifiedProps() throws Exception {
-    Result result = createNiceMock(Result.class);
-    ResourceInstance componentResourceInstance = createNiceMock(ResourceInstance.class);
-    ResourceDefinition componentResourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema componentSchema = createNiceMock(Schema.class);
-    Resource componentResource = createNiceMock(Resource.class);
-    String componentPropertyId = "componentId";
-    String servicePropertyId = "serviceId";
-    String clusterPropertyId = "clusterId";
-
-    Set<String> setPropertyIds = new HashSet<String>();
-    setPropertyIds.add(clusterPropertyId);
-    setPropertyIds.add(servicePropertyId);
-    setPropertyIds.add(componentPropertyId);
-
-    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
-    Set<Resource> resourceSet = Collections.singleton(componentResource);
-
-    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
-    mapResourceIds.put(Resource.Type.Cluster, "clusterName");
-    mapResourceIds.put(Resource.Type.Service, "serviceName");
-    mapResourceIds.put(Resource.Type.Component, null);
+  public void testIsCollection__False() {
+    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
 
-    PredicateBuilder pb = new PredicateBuilder();
-    Predicate predicate = pb.property("clusterId").equals("clusterName").and().
-        property("serviceId").equals("serviceName").toPredicate();
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+    mapIds.put(Resource.Type.Cluster, "cluster");
+    mapIds.put(Resource.Type.Service, "service");
 
     // expectations
-    expect(componentResource.getType()).andReturn(Resource.Type.Component).anyTimes();
-
-    expect(componentResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
-    expect(componentResourceInstance.getResourceDefinition()).andReturn(componentResourceDefinition).anyTimes();
-
-    expect(componentResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();
-
-    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes();
-
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(componentPropertyId).anyTimes();
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("clusterId").anyTimes();
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceId").anyTimes();
-
-    expect(result.getResultTree()).andReturn(tree).anyTimes();
-
-
-    expect(m_controller.getRawResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(setPropertyIds)),
-        eq(predicate))).andReturn(resourceSet);
-
-    expect(m_controller.getResources(eq(Resource.Type.Component), eq(resourceSet), eq(predicate))).andReturn(
-        resourceSet);
-
-    expect(componentResourceInstance.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
-
-    replay(m_controller, result,componentResourceInstance, componentResourceDefinition, componentSchema, componentResource);
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(Collections.<SubResourceDefinition>emptySet()).anyTimes();
 
-    QueryImpl query = new TestQuery(componentResourceInstance, result);
-    query.execute();
+    replay(resourceDefinition);
 
-    verify(m_controller, result, componentResourceInstance, componentResourceDefinition, componentSchema, componentResource);
+    //test
+    ResourceInstance instance = new TestQuery(mapIds, resourceDefinition);
+    assertFalse(instance.isCollectionResource());
 
-    assertEquals("true", tree.getProperty("isCollection"));
-    assertEquals(1, tree.getChildren().size());
-    TreeNode<Resource> componentNode = tree.getChild("Component:1");
-    assertSame(componentResource, componentNode.getObject());
-    assertEquals(0, componentNode.getChildren().size());
+    verify(resourceDefinition);
   }
 
   @Test
-  public void testExecute__collection_nullInternalPredicate_nullUserPredicate() throws Exception {
-    Result result = createNiceMock(Result.class);
-    ResourceInstance clusterResourceInstance = createNiceMock(ResourceInstance.class);
-    ResourceDefinition clusterResourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema clusterSchema = createNiceMock(Schema.class);
-    Resource clusterResource = createNiceMock(Resource.class);
-    String clusterPropertyId = "clusterId";
-
-    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
-    Set<Resource> resourceSet = Collections.singleton(clusterResource);
+  public void testExecute__Cluster_instance_noSpecifiedProps() throws Exception {
+    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
 
-    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+    mapIds.put(Resource.Type.Cluster, "cluster");
 
     // expectations
-    expect(clusterResource.getType()).andReturn(Resource.Type.Cluster).anyTimes();
-
-    expect(clusterResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
-    expect(clusterResourceInstance.getResourceDefinition()).andReturn(clusterResourceDefinition).anyTimes();
-
-    expect(clusterResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();
-
-    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(clusterSchema).atLeastOnce();
-
-    expect(clusterSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(clusterPropertyId).atLeastOnce();
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Cluster).anyTimes();
+    Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>();
+    setChildren.add(new SubResourceDefinition(Resource.Type.Host));
 
-    expect(result.getResultTree()).andReturn(tree).atLeastOnce();
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes();
 
-    expect(m_controller.getRawResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(Collections.singleton(clusterPropertyId))),
-        isNull(Predicate.class))).andReturn(resourceSet);
+    replay(resourceDefinition);
 
-    expect(m_controller.getResources(eq(Resource.Type.Component), eq(resourceSet), isNull(Predicate.class))).andReturn(
-        resourceSet);
+    //test
+    QueryImpl instance = new TestQuery(mapIds, resourceDefinition);
 
+    Result result = instance.execute();
 
-    expect(clusterResourceInstance.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    verify(resourceDefinition);
 
-    replay(m_controller, result, clusterResourceInstance, clusterResourceDefinition, clusterSchema, clusterResource);
+    TreeNode<Resource> tree = result.getResultTree();
 
-    QueryImpl query = new TestQuery(clusterResourceInstance, result);
-    query.execute();
-
-    verify(m_controller, result, clusterResourceInstance, clusterResourceDefinition, clusterSchema, clusterResource);
-
-    assertEquals("true", tree.getProperty("isCollection"));
-    assertEquals(1, tree.getChildren().size());
+    Assert.assertEquals(1, tree.getChildren().size());
     TreeNode<Resource> clusterNode = tree.getChild("Cluster:1");
-    assertSame(clusterResource, clusterNode.getObject());
-    assertEquals(0, clusterNode.getChildren().size());
-
+    Assert.assertEquals("Cluster:1", clusterNode.getName());
+    Assert.assertEquals(Resource.Type.Cluster, clusterNode.getObject().getType());
+    Assert.assertEquals(1, clusterNode.getChildren().size());
+    TreeNode<Resource> hostNode = clusterNode.getChild("hosts");
+    Assert.assertEquals(4, hostNode.getChildren().size());
   }
 
   @Test
-  public void testExecute__collection_nullInternalPredicate_nonNullUserPredicate() throws Exception {
-    Result result = createNiceMock(Result.class);
-    ResourceInstance clusterResourceInstance = createNiceMock(ResourceInstance.class);
-    ResourceDefinition clusterResourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema clusterSchema = createNiceMock(Schema.class);
-    Resource clusterResource = createNiceMock(Resource.class);
-    String clusterPropertyId = "clusterId";
-    Predicate userPredicate = createNiceMock(Predicate.class);
-
-    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
-    Set<Resource> resourceSet = Collections.singleton(clusterResource);
+  public void testExecute__Host_collection_noSpecifiedProps() throws Exception {
+    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
 
-    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
 
     // expectations
-    expect(clusterResource.getType()).andReturn(Resource.Type.Cluster).anyTimes();
-
-    expect(clusterResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
-    expect(clusterResourceInstance.getResourceDefinition()).andReturn(clusterResourceDefinition).anyTimes();
-
-    expect(clusterResourceDefinition.getType()).andReturn(Resource.Type.Component).atLeastOnce();
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Host).anyTimes();
+    Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>();
 
-    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(clusterSchema).anyTimes();
-    expect(clusterSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(clusterPropertyId).anyTimes();
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes();
 
-    expect(result.getResultTree()).andReturn(tree).anyTimes();
+    replay(resourceDefinition);
 
-//    expect(m_controller.getResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(Collections.singleton(clusterPropertyId))),
-//        eq(userPredicate))).andReturn(resourceSet);
+    //test
+    QueryImpl instance = new TestQuery(mapIds, resourceDefinition);
 
-    expect(m_controller.getRawResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(Collections.singleton(clusterPropertyId))),
-        eq(userPredicate))).andReturn(resourceSet);
+    Result result = instance.execute();
 
-    expect(m_controller.getResources(eq(Resource.Type.Component), eq(resourceSet), eq(userPredicate))).andReturn(
-        resourceSet);
+    verify(resourceDefinition);
 
-    expect(clusterResourceInstance.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    TreeNode<Resource> tree = result.getResultTree();
 
-    replay(m_controller, result,clusterResourceInstance, clusterResourceDefinition, clusterSchema, clusterResource, userPredicate);
+    Assert.assertEquals(4, tree.getChildren().size());
+    TreeNode<Resource> hostNode = tree.getChild("Host:1");
+    Assert.assertEquals("Host:1", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
 
-    QueryImpl query = new TestQuery(clusterResourceInstance, result);
-    query.setUserPredicate(userPredicate);
-    query.execute();
+    hostNode = tree.getChild("Host:2");
+    Assert.assertEquals("Host:2", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
 
-    verify(m_controller, result, clusterResourceInstance, clusterResourceDefinition, clusterSchema, clusterResource, userPredicate);
+    hostNode = tree.getChild("Host:3");
+    Assert.assertEquals("Host:3", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
 
-    assertEquals("true", tree.getProperty("isCollection"));
-    assertEquals(1, tree.getChildren().size());
-    TreeNode<Resource> clusterNode = tree.getChild("Cluster:1");
-    assertSame(clusterResource, clusterNode.getObject());
-    assertEquals(0, clusterNode.getChildren().size());
+    hostNode = tree.getChild("Host:4");
+    Assert.assertEquals("Host:4", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
   }
 
   @Test
-  public void testExecute__collection_nonNullInternalPredicate_nonNullUserPredicate() throws Exception {
-    Result result = createNiceMock(Result.class);
-    ResourceInstance componentResourceInstance = createNiceMock(ResourceInstance.class);
-    ResourceDefinition componentResourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema componentSchema = createNiceMock(Schema.class);
-    Resource componentResource = createNiceMock(Resource.class);
-    String componentPropertyId = "componentId";
-    String servicePropertyId = "serviceId";
-    String clusterPropertyId = "clusterId";
-
-    Set<String> setPropertyIds = new HashSet<String>();
-    setPropertyIds.add(clusterPropertyId);
-    setPropertyIds.add(servicePropertyId);
-    setPropertyIds.add(componentPropertyId);
-
-    TreeNode<Resource> tree = new TreeNodeImpl<Resource>(null, null, null);
-    Set<Resource> resourceSet = Collections.singleton(componentResource);
-
-    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
-    mapResourceIds.put(Resource.Type.Cluster, "clusterName");
-    mapResourceIds.put(Resource.Type.Service, "serviceName");
-    mapResourceIds.put(Resource.Type.Component, null);
-
-    PredicateBuilder pb = new PredicateBuilder();
-    Predicate internalPredicate = pb.property("clusterId").equals("clusterName").and().
-        property("serviceId").equals("serviceName").toPredicate();
+  public void testExecute__collection_nullInternalPredicate_nullUserPredicate() throws Exception {
+    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
 
-    pb = new PredicateBuilder();
-    Predicate userPredicate = pb.property("foo").equals("bar").toPredicate();
-    // combine internal predicate and user predicate
-    //todo: for now, need to cast to BasePredicate
-    Predicate predicate = new AndPredicate(internalPredicate, userPredicate);
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
 
     // expectations
-    expect(componentResource.getType()).andReturn(Resource.Type.Component).anyTimes();
-
-    expect(componentResourceInstance.getIds()).andReturn(mapResourceIds).anyTimes();
-    expect(componentResourceInstance.getResourceDefinition()).andReturn(componentResourceDefinition).anyTimes();
-
-    expect(componentResourceDefinition.getType()).andReturn(Resource.Type.Component).anyTimes();
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Cluster).anyTimes();
+    Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>();
+    setChildren.add(new SubResourceDefinition(Resource.Type.Host));
 
-    expect(m_controller.getSchema(Resource.Type.Component)).andReturn(componentSchema).anyTimes();
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Component)).andReturn(componentPropertyId).atLeastOnce();
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Cluster)).andReturn("clusterId").anyTimes();
-    expect(componentSchema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceId").anyTimes();
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes();
 
-    expect(result.getResultTree()).andReturn(tree).anyTimes();
+    replay(resourceDefinition);
 
-//    expect(m_controller.getResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(setPropertyIds)),
-//        eq(predicate))).andReturn(resourceSet);
+    //test
+    QueryImpl instance = new TestQuery(mapIds, resourceDefinition);
 
-    expect(m_controller.getRawResources(eq(Resource.Type.Component), eq(PropertyHelper.getReadRequest(setPropertyIds)),
-        eq(predicate))).andReturn(resourceSet);
+    Result result = instance.execute();
 
-    expect(m_controller.getResources(eq(Resource.Type.Component), eq(resourceSet), eq(predicate))).andReturn(
-        resourceSet);
+    verify(resourceDefinition);
 
-    expect(componentResourceInstance.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    TreeNode<Resource> tree = result.getResultTree();
 
-    replay(m_controller, result, componentResourceInstance, componentResourceDefinition, componentSchema, componentResource);
-
-    QueryImpl query = new TestQuery(componentResourceInstance, result);
-    query.setUserPredicate(userPredicate);
-    query.execute();
-
-    verify(m_controller, result, componentResourceInstance, componentResourceDefinition, componentSchema, componentResource);
-
-    assertEquals("true", tree.getProperty("isCollection"));
-    assertEquals(1, tree.getChildren().size());
-    TreeNode<Resource> componentNode = tree.getChild("Component:1");
-    assertSame(componentResource, componentNode.getObject());
-    assertEquals(0, componentNode.getChildren().size());
+    Assert.assertEquals(1, tree.getChildren().size());
+    TreeNode<Resource> clusterNode = tree.getChild("Cluster:1");
+    Assert.assertEquals("Cluster:1", clusterNode.getName());
+    Assert.assertEquals(Resource.Type.Cluster, clusterNode.getObject().getType());
+    Assert.assertEquals(0, clusterNode.getChildren().size());
   }
 
   @Test
-  public void testAddProperty__localProperty() throws Exception {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
+  public void testExecute__collection_nullInternalPredicate_nonNullUserPredicate() throws Exception {
     ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema schema = createNiceMock(Schema.class);
-
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
-    expect(resource.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
-
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
 
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
+    mapIds.put(Resource.Type.Cluster, "cluster");
 
-    replay(m_controller, resource, resourceDefinition, schema);
-
-    Query query = new TestQuery(resource, null);
-    query.addProperty("category", "property", null);
-
-    assertEquals(1, query.getProperties().size());
-    assertTrue(query.getProperties().contains("category/property"));
-
-    query.addProperty(null, "property2", null);
-
-    assertEquals(2, query.getProperties().size());
-    assertTrue(query.getProperties().contains("property2"));
+    // expectations
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Host).anyTimes();
+    Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>();
 
-    verify(m_controller, resource, resourceDefinition, schema);
-  }
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes();
 
-  @Test
-  public void testAddProperty__allProperties() throws Exception {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
-    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema schema = createNiceMock(Schema.class);
+    replay(resourceDefinition);
 
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
-    expect(resource.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    //test
+    QueryImpl instance = new TestQuery(mapIds, resourceDefinition);
 
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
+    PredicateBuilder pb = new PredicateBuilder();
+    Predicate predicate = pb.property("Hosts/host_name").equals("host:2").toPredicate();
 
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
+    instance.setUserPredicate(predicate);
 
-    replay(m_controller, resource, resourceDefinition, schema);
+    Result result = instance.execute();
 
-    Query query = new TestQuery(resource, null);
-    query.addProperty(null, "*", null);
+    verify(resourceDefinition);
 
-    assertEquals(0, query.getProperties().size());
+    TreeNode<Resource> tree = result.getResultTree();
 
-    verify(m_controller, resource, resourceDefinition, schema);
+    Assert.assertEquals(1, tree.getChildren().size());
+    TreeNode<Resource> hostNode = tree.getChild("Host:1");
+    Assert.assertEquals("Host:1", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertEquals("host:2", hostNode.getObject().getPropertyValue("Hosts/host_name"));
   }
 
   @Test
-  public void testAddProperty__allCategoryProperties() throws Exception {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
+  public void testExecute__collection_nonNullInternalPredicate_nonNullUserPredicate() throws Exception {
     ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema schema = createNiceMock(Schema.class);
-
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
-    expect(resource.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
-
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
-
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
 
-    replay(m_controller, resource, resourceDefinition, schema);
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
 
-    Query query = new TestQuery(resource, null);
-    query.addProperty("category", "*", null);
-
-    assertEquals(1, query.getProperties().size());
-    assertTrue(query.getProperties().contains("category"));
+    // expectations
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Host).anyTimes();
+    Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>();
 
-    verify(m_controller, resource, resourceDefinition, schema);
-  }
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes();
 
-  // this is the case where service can't differentiate category and property name
-  // the category name is give as the property name
-  @Test
-  public void testAddProperty__localCategory_asPropertyName() throws Exception  {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
-    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema schema = createNiceMock(Schema.class);
+    replay(resourceDefinition);
 
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
+    //test
+    QueryImpl instance = new TestQuery(mapIds, resourceDefinition);
 
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
+    PredicateBuilder pb = new PredicateBuilder();
+    Predicate predicate = pb.property("Hosts/host_name").equals("host:2").toPredicate();
 
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
-    expect(resource.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    instance.setUserPredicate(predicate);
 
-    replay(m_controller, resource, resourceDefinition, schema);
+    Result result = instance.execute();
 
-    Query query = new TestQuery(resource, null);
-    query.addProperty(null, "category", null);
+    verify(resourceDefinition);
 
-    Set<String> setProperties = query.getProperties();
-    assertEquals(1, setProperties.size());
-    assertTrue(setProperties.contains("category"));
+    TreeNode<Resource> tree = result.getResultTree();
 
-    verify(m_controller, resource, resourceDefinition, schema);
+    Assert.assertEquals(1, tree.getChildren().size());
+    TreeNode<Resource> hostNode = tree.getChild("Host:1");
+    Assert.assertEquals("Host:1", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertEquals("host:2", hostNode.getObject().getPropertyValue("Hosts/host_name"));
   }
 
-  // This is the case where the service can determine that only a category was provided because it contained
-  // a trailing '/'
   @Test
-  public void testAddProperty__localCategory_categoryNameOnly() throws Exception {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
+  public void testAddProperty__localProperty() throws Exception {
     ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema schema = createNiceMock(Schema.class);
 
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
 
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
+    // expectations
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Host).anyTimes();
+    Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>();
 
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
-    expect(resource.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes();
 
-    replay(m_controller, resource, resourceDefinition, schema);
+    replay(resourceDefinition);
 
-    Query query = new TestQuery(resource, null);
-    query.addProperty("category/", "", null);
+    //test
+    QueryImpl instance = new TestQuery(mapIds, resourceDefinition);
 
-    Set<String> setProperties = query.getProperties();
-    assertEquals(1, setProperties.size());
-    assertTrue(setProperties.contains("category"));
+    instance.addLocalProperty("c1/p1");
 
-    verify(m_controller, resource, resourceDefinition, schema);
-  }
-
-  @Test
-  public void testAddProperty__localSubCategory() throws Exception {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
-    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema schema = createNiceMock(Schema.class);
-
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
-
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
+    Result result = instance.execute();
 
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
+    verify(resourceDefinition);
 
-    expect(resource.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    TreeNode<Resource> tree = result.getResultTree();
 
-    replay(m_controller, resource, resourceDefinition, schema);
+    Assert.assertEquals(4, tree.getChildren().size());
+    TreeNode<Resource> hostNode = tree.getChild("Host:1");
+    Assert.assertEquals("Host:1", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
 
-    Query query = new TestQuery(resource, null);
-    query.addProperty("category", "nestedCategory", null);
+    hostNode = tree.getChild("Host:2");
+    Assert.assertEquals("Host:2", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
 
-    Set<String> setProperties = query.getProperties();
-    assertEquals(1, setProperties.size());
-    assertTrue(setProperties.contains("category/nestedCategory"));
+    hostNode = tree.getChild("Host:3");
+    Assert.assertEquals("Host:3", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
 
-    verify(m_controller, resource, resourceDefinition, schema);
+    hostNode = tree.getChild("Host:4");
+    Assert.assertEquals("Host:4", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
   }
 
   @Test
-  public void testAddProperty__localCategorySubPropsOnly() throws Exception {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
+  public void testAddProperty__allCategoryProperties() throws Exception {
     ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    Schema schema = createNiceMock(Schema.class);
-
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
-
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
 
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
-    expect(resource.getSubResources()).andReturn(Collections.<String, ResourceInstance>emptyMap()).anyTimes();
+    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
 
-    replay(m_controller, resource, resourceDefinition, schema);
-
-    Query query = new TestQuery(resource, null);
-    query.addProperty(null, "category", null);
-
-    Set<String> setProperties = query.getProperties();
-    assertEquals(1, setProperties.size());
-    assertTrue(setProperties.contains("category"));
-
-    verify(m_controller, resource, resourceDefinition, schema);
-  }
-
-  @Test
-  public void testAddProperty__subProperty() throws Exception {
-    ResourceInstance resource = createNiceMock(ResourceInstance.class);
-    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-    ResourceInstance subResource = createNiceMock(ResourceInstance.class);
-    Schema schema = createNiceMock(Schema.class);
+    // expectations
+    expect(resourceDefinition.getType()).andReturn(Resource.Type.Host).anyTimes();
+    Set<SubResourceDefinition> setChildren = new HashSet<SubResourceDefinition>();
 
-    Map<Resource.Type, String> mapResourceIds = new HashMap<Resource.Type, String>();
-    mapResourceIds.put(Resource.Type.Service, "serviceName");
-    mapResourceIds.put(Resource.Type.Component, "componentName");
+    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(setChildren).anyTimes();
 
-    //expectations
-    expect(resource.getResourceDefinition()).andReturn(resourceDefinition).anyTimes();
+    replay(resourceDefinition);
 
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
+    //test
+    QueryImpl instance = new TestQuery(mapIds, resourceDefinition);
 
-    expect(m_controller.getSchema(Resource.Type.Service)).andReturn(schema).anyTimes();
+    instance.addLocalProperty("c1");
 
-    expect(schema.getKeyPropertyId(Resource.Type.Service)).andReturn("serviceName").anyTimes();
-    expect(schema.getKeyPropertyId(Resource.Type.Component)).andReturn("componentName").anyTimes();
+    Result result = instance.execute();
 
-    expect(resource.getSubResources()).andReturn(Collections.singletonMap("components", subResource)).anyTimes();
-    expect(resource.getIds()).andReturn(mapResourceIds).anyTimes();
+    verify(resourceDefinition);
 
-    //todo: ensure that sub-resource was added.
+    TreeNode<Resource> tree = result.getResultTree();
 
-    replay(m_controller, resource, resourceDefinition, subResource, schema);
+    Assert.assertEquals(4, tree.getChildren().size());
+    TreeNode<Resource> hostNode = tree.getChild("Host:1");
+    Assert.assertEquals("Host:1", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p2"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p3"));
 
-    Query query = new TestQuery(resource, null);
-    query.addProperty(null, "components", null);
+    hostNode = tree.getChild("Host:2");
+    Assert.assertEquals("Host:2", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p2"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p3"));
 
-    // verify that only the key properties of the parent resource have been added to the query
-    Set<String> properties = query.getProperties();
-    assertEquals(2, properties.size());
-    assertTrue(properties.contains("serviceName"));
-    assertTrue(properties.contains("componentName"));
+    hostNode = tree.getChild("Host:3");
+    Assert.assertEquals("Host:3", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p2"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p3"));
 
-    verify(m_controller, resource, resourceDefinition, subResource, schema);
+    hostNode = tree.getChild("Host:4");
+    Assert.assertEquals("Host:4", hostNode.getName());
+    Assert.assertEquals(Resource.Type.Host, hostNode.getObject().getType());
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p1"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p2"));
+    Assert.assertNotNull(hostNode.getObject().getPropertyValue("c1/p3"));
   }
 
-  //todo: sub-resource with property and with sub-path
-
-//  @Test
-//  public void testAddProperty__invalidProperty() {
-//
-//  }
-
   private class TestQuery extends QueryImpl {
-
-    private Result m_result;
-
-    public TestQuery(ResourceInstance ResourceInstance, Result result) {
-      super(ResourceInstance);
-      m_result = result;
-    }
-
-    @Override
-    ClusterController getClusterController() {
-      return m_controller;
-    }
-
-    @Override
-    Result createResult() {
-      return m_result;
+    public TestQuery(Map<Resource.Type, String> mapIds, ResourceDefinition resourceDefinition) {
+      super(mapIds, resourceDefinition, new ClusterControllerImpl(new ClusterControllerImplTest.TestProviderModule()));
     }
   }
-
-  @After
-  public void resetGlobalMocks() {
-    reset(m_controller);
-  }
 }
+

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/fc427d9f/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ResourceInstanceImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ResourceInstanceImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ResourceInstanceImplTest.java
deleted file mode 100644
index 4f729b2..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/resources/ResourceInstanceImplTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.ambari.server.api.resources;
-
-
-import org.apache.ambari.server.controller.spi.Resource;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static org.easymock.EasyMock.*;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-
-/**
- * ResourceInstanceImpl unit tests.
- */
-public class ResourceInstanceImplTest {
-  @Test
-  public void testIsCollection__True() {
-    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-
-    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
-    mapIds.put(Resource.Type.Cluster, "cluster");
-    mapIds.put(Resource.Type.Service, null);
-
-    // expectations
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
-    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(Collections.<SubResourceDefinition>emptySet()).anyTimes();
-
-    replay(resourceDefinition);
-
-    //test
-    ResourceInstance instance = new ResourceInstanceImpl(mapIds, resourceDefinition, null);
-    assertTrue(instance.isCollectionResource());
-
-    verify(resourceDefinition);
-  }
-
-  @Test
-  public void testIsCollection__False() {
-    ResourceDefinition resourceDefinition = createNiceMock(ResourceDefinition.class);
-
-    Map<Resource.Type, String> mapIds = new HashMap<Resource.Type, String>();
-    mapIds.put(Resource.Type.Cluster, "cluster");
-    mapIds.put(Resource.Type.Service, "service");
-
-    // expectations
-    expect(resourceDefinition.getType()).andReturn(Resource.Type.Service).anyTimes();
-    expect(resourceDefinition.getSubResourceDefinitions()).andReturn(Collections.<SubResourceDefinition>emptySet()).anyTimes();
-
-    replay(resourceDefinition);
-
-    //test
-    ResourceInstance instance = new ResourceInstanceImpl(mapIds, resourceDefinition, null);
-    assertFalse(instance.isCollectionResource());
-
-    verify(resourceDefinition);
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/fc427d9f/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
index 467cb8b..5fd608f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
@@ -544,8 +544,8 @@ public class GangliaPropertyProviderTest {
     Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
 
     String expected = (configuration.isGangliaSSL() ? "https" : "http") +
-        "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&e=now&pt=true";
-    Assert.assertEquals(expected, streamProvider.getLastSpec());
+        "://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=ip-10-39-113-33.ec2.internal&m=";
+    Assert.assertTrue(streamProvider.getLastSpec().startsWith(expected));
 
     Assert.assertEquals(33, PropertyHelper.getProperties(resource).size());
     Assert.assertNotNull(resource.getPropertyValue(FLUME_CHANNEL_CAPACITY_PROPERTY));

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/fc427d9f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
index a90c940..c765dd7 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
@@ -99,6 +99,10 @@ public class ClusterControllerImplTest {
     resourceProviderProperties.add(PropertyHelper.getPropertyId("c1", "p2"));
     resourceProviderProperties.add(PropertyHelper.getPropertyId("c1", "p3"));
     resourceProviderProperties.add(PropertyHelper.getPropertyId("c2", "p4"));
+    // add the categories
+    resourceProviderProperties.add("Hosts");
+    resourceProviderProperties.add("c1");
+    resourceProviderProperties.add("c2");
   }
 
   @Test
@@ -112,7 +116,7 @@ public class ClusterControllerImplTest {
 
     Request request = PropertyHelper.getReadRequest(propertyIds);
 
-    Iterable<Resource> iterable = controller.getResources(Resource.Type.Host, request, null);
+    Iterable<Resource> iterable = controller.getResourceIterable(Resource.Type.Host, request, null);
 
     int cnt = 0;
     for (Resource resource : iterable) {
@@ -141,9 +145,9 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(2, list.size());
-    Assert.assertEquals("host:1", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:0", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:2", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:1", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
 
     // get the first three
@@ -157,11 +161,11 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(3, list.size());
-    Assert.assertEquals("host:1", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:0", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:2", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:1", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
-    Assert.assertEquals("host:3", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:2", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(2).getType());
   }
 
@@ -178,8 +182,8 @@ public class ClusterControllerImplTest {
     PageResponse pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest);
 
     Assert.assertEquals(1, pageResponse.getOffset());
-    Assert.assertEquals("host:1", pageResponse.getPreviousResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
-    Assert.assertEquals("host:4", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:0", pageResponse.getPreviousResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:3", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
 
     Iterable<Resource> iterable = pageResponse.getIterable();
     List<Resource> list = new LinkedList<Resource>();
@@ -188,9 +192,9 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(2, list.size());
-    Assert.assertEquals("host:2", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:1", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:3", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:2", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
 
     // get the last three (0 - 2)
@@ -199,7 +203,7 @@ public class ClusterControllerImplTest {
 
     Assert.assertEquals(0, pageResponse.getOffset());
     Assert.assertNull(pageResponse.getPreviousResource());
-    Assert.assertEquals("host:4", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:3", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
 
     iterable = pageResponse.getIterable();
     list = new LinkedList<Resource>();
@@ -208,11 +212,11 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(3, list.size());
-    Assert.assertEquals("host:1", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:0", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:2", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:1", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
-    Assert.assertEquals("host:3", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:2", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(2).getType());
   }
 
@@ -235,9 +239,9 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(2, list.size());
-    Assert.assertEquals("host:3", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:2", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:4", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:3", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
 
     // get the last three
@@ -251,11 +255,11 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(3, list.size());
-    Assert.assertEquals("host:2", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:1", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:3", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:2", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
-    Assert.assertEquals("host:4", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:3", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(2).getType());
   }
 
@@ -272,8 +276,8 @@ public class ClusterControllerImplTest {
     PageResponse pageResponse = controller.getResources(Resource.Type.Host, request, null, pageRequest);
 
     Assert.assertEquals(1, pageResponse.getOffset());
-    Assert.assertEquals("host:1", pageResponse.getPreviousResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
-    Assert.assertEquals("host:4", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:0", pageResponse.getPreviousResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:3", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
 
     Iterable<Resource> iterable = pageResponse.getIterable();
     List<Resource> list = new LinkedList<Resource>();
@@ -282,9 +286,9 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(2, list.size());
-    Assert.assertEquals("host:2", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:1", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:3", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:2", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
 
     // get the last three (0 - 2)
@@ -293,7 +297,7 @@ public class ClusterControllerImplTest {
 
     Assert.assertEquals(0, pageResponse.getOffset());
     Assert.assertNull(pageResponse.getPreviousResource());
-    Assert.assertEquals("host:4", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:3", pageResponse.getNextResource().getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
 
     iterable = pageResponse.getIterable();
     list = new LinkedList<Resource>();
@@ -302,11 +306,11 @@ public class ClusterControllerImplTest {
       list.add(resource);
     }
     Assert.assertEquals(3, list.size());
-    Assert.assertEquals("host:1", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:0", (String) list.get(0).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(0).getType());
-    Assert.assertEquals("host:2", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:1", (String) list.get(1).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(1).getType());
-    Assert.assertEquals("host:3", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
+    Assert.assertEquals("host:2", (String) list.get(2).getPropertyValue(PropertyHelper.getPropertyId("Hosts", "host_name")));
     Assert.assertEquals(Resource.Type.Host, list.get(2).getType());
   }
 
@@ -318,7 +322,7 @@ public class ClusterControllerImplTest {
 
     Request request = PropertyHelper.getReadRequest(propertyIds);
 
-    Iterable<Resource> iterable = controller.getResources(Resource.Type.Host, request, null);
+    Iterable<Resource> iterable = controller.getResourceIterable(Resource.Type.Host, request, null);
 
     int cnt = 0;
     for (Resource resource : iterable) {
@@ -336,7 +340,7 @@ public class ClusterControllerImplTest {
 
     Request request = PropertyHelper.getReadRequest(propertyIds);
 
-    Iterable<Resource> iterable = controller.getResources(Resource.Type.Host, request, null);
+    Iterable<Resource> iterable = controller.getResourceIterable(Resource.Type.Host, request, null);
 
     String lastHostName = null;
     int cnt = 0;
@@ -369,7 +373,7 @@ public class ClusterControllerImplTest {
 
     Predicate predicate = new PredicateBuilder().property("c1/p2").equals(1).toPredicate();
 
-    Iterable<Resource> iterable = controller.getResources(Resource.Type.Host, request, predicate);
+    Iterable<Resource> iterable = controller.getResourceIterable(Resource.Type.Host, request, predicate);
 
     int cnt = 0;
     for (Resource resource : iterable) {
@@ -395,7 +399,7 @@ public class ClusterControllerImplTest {
     Predicate predicate = new PredicateBuilder().property(UNSUPPORTED_PROPERTY).equals(1).toPredicate();
 
     try {
-      controller.getResources(Resource.Type.Host, request, predicate);
+      controller.getResourceIterable(Resource.Type.Host, request, predicate);
       Assert.fail("Expected an UnsupportedPropertyException for the unsupported properties.");
     } catch (UnsupportedPropertyException e) {
       // Expected
@@ -418,7 +422,7 @@ public class ClusterControllerImplTest {
     Predicate predicate = new PredicateBuilder().property("c1/p2").equals(1).toPredicate();
 
     try {
-      controller.getResources(Resource.Type.Host, request, predicate);
+      controller.getResourceIterable(Resource.Type.Host, request, predicate);
       Assert.fail("Expected an UnsupportedPropertyException for the unsupported properties.");
     } catch (UnsupportedPropertyException e) {
       // Expected
@@ -428,7 +432,7 @@ public class ClusterControllerImplTest {
   @Test
   public void testCreateResources() throws Exception{
     TestProviderModule providerModule = new TestProviderModule();
-    TestResourceProvider resourceProvider = (TestResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
+    TestHostResourceProvider resourceProvider = (TestHostResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
     ClusterController controller = new ClusterControllerImpl(providerModule);
 
     Set<Map<String, Object>> properties = new HashSet<Map<String, Object>>();
@@ -443,7 +447,7 @@ public class ClusterControllerImplTest {
 
     controller.createResources(Resource.Type.Host, request);
 
-    Assert.assertEquals(TestResourceProvider.Action.Create, resourceProvider.getLastAction());
+    Assert.assertEquals(TestHostResourceProvider.Action.Create, resourceProvider.getLastAction());
     Assert.assertSame(request, resourceProvider.getLastRequest());
     Assert.assertNull(resourceProvider.getLastPredicate());
   }
@@ -474,7 +478,7 @@ public class ClusterControllerImplTest {
   @Test
   public void testUpdateResources() throws Exception{
     TestProviderModule providerModule = new TestProviderModule();
-    TestResourceProvider resourceProvider = (TestResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
+    TestHostResourceProvider resourceProvider = (TestHostResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
     ClusterController controller = new ClusterControllerImpl(providerModule);
 
     Map<String, Object> propertyMap = new HashMap<String, Object>();
@@ -488,7 +492,7 @@ public class ClusterControllerImplTest {
 
     controller.updateResources(Resource.Type.Host, request, predicate);
 
-    Assert.assertEquals(TestResourceProvider.Action.Update, resourceProvider.getLastAction());
+    Assert.assertEquals(TestHostResourceProvider.Action.Update, resourceProvider.getLastAction());
     Assert.assertSame(request, resourceProvider.getLastRequest());
     Assert.assertSame(predicate, resourceProvider.getLastPredicate());
   }
@@ -540,7 +544,7 @@ public class ClusterControllerImplTest {
   @Test
   public void testUpdateResourcesResolvePredicate() throws Exception{
     TestProviderModule providerModule = new TestProviderModule();
-    TestResourceProvider resourceProvider = (TestResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
+    TestHostResourceProvider resourceProvider = (TestHostResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
     ClusterController controller = new ClusterControllerImpl(providerModule);
 
     Map<String, Object> propertyMap = new HashMap<String, Object>();
@@ -554,7 +558,7 @@ public class ClusterControllerImplTest {
 
     controller.updateResources(Resource.Type.Host, request, predicate);
 
-    Assert.assertEquals(TestResourceProvider.Action.Update, resourceProvider.getLastAction());
+    Assert.assertEquals(TestHostResourceProvider.Action.Update, resourceProvider.getLastAction());
     Assert.assertSame(request, resourceProvider.getLastRequest());
     Predicate lastPredicate = resourceProvider.getLastPredicate();
     Assert.assertFalse(predicate.equals(lastPredicate));
@@ -567,14 +571,14 @@ public class ClusterControllerImplTest {
   @Test
   public void testDeleteResources() throws Exception{
     TestProviderModule providerModule = new TestProviderModule();
-    TestResourceProvider resourceProvider = (TestResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
+    TestHostResourceProvider resourceProvider = (TestHostResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
     ClusterController controller = new ClusterControllerImpl(providerModule);
 
     Predicate predicate = new PredicateBuilder().property("c1/p2").equals(1).toPredicate();
 
     controller.deleteResources(Resource.Type.Host, predicate);
 
-    Assert.assertEquals(TestResourceProvider.Action.Delete, resourceProvider.getLastAction());
+    Assert.assertEquals(TestHostResourceProvider.Action.Delete, resourceProvider.getLastAction());
     Assert.assertNull(resourceProvider.getLastRequest());
     Assert.assertSame(predicate, resourceProvider.getLastPredicate());
   }
@@ -597,14 +601,14 @@ public class ClusterControllerImplTest {
   @Test
   public void testDeleteResourcesResolvePredicate() throws Exception{
     TestProviderModule providerModule = new TestProviderModule();
-    TestResourceProvider resourceProvider = (TestResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
+    TestHostResourceProvider resourceProvider = (TestHostResourceProvider) providerModule.getResourceProvider(Resource.Type.Host);
     ClusterController controller = new ClusterControllerImpl(providerModule);
 
     Predicate predicate = new PredicateBuilder().property("c3/p6").equals(1).toPredicate();
 
     controller.deleteResources(Resource.Type.Host, predicate);
 
-    Assert.assertEquals(TestResourceProvider.Action.Delete, resourceProvider.getLastAction());
+    Assert.assertEquals(TestHostResourceProvider.Action.Delete, resourceProvider.getLastAction());
     Assert.assertNull(resourceProvider.getLastRequest());
     Predicate lastPredicate = resourceProvider.getLastPredicate();
     Assert.assertFalse(predicate.equals(lastPredicate));
@@ -659,12 +663,16 @@ public class ClusterControllerImplTest {
     Assert.assertFalse(comparator.compare(resource2, resource1) == 0);
   }
 
-  private static class TestProviderModule implements ProviderModule {
+  public static class TestProviderModule implements ProviderModule {
     private Map<Resource.Type, ResourceProvider> providers = new HashMap<Resource.Type, ResourceProvider>();
 
-    private TestProviderModule() {
-      providers.put(Resource.Type.Cluster, new TestResourceProvider());
-      providers.put(Resource.Type.Host, new TestResourceProvider());
+    public TestProviderModule() {
+
+      for (Resource.Type type : Resource.Type.values()) {
+        providers.put(type, new TestResourceProvider(type));
+      }
+      providers.put(Resource.Type.Cluster, new TestClusterResourceProvider());
+      providers.put(Resource.Type.Host, new TestHostResourceProvider());
     }
 
     @Override
@@ -679,10 +687,69 @@ public class ClusterControllerImplTest {
   }
 
   private static class TestResourceProvider implements ResourceProvider {
+
+    private Resource.Type type;
+
+    private TestResourceProvider(Resource.Type type) {
+      this.type = type;
+    }
+
+    @Override
+    public RequestStatus createResources(Request request) throws SystemException, UnsupportedPropertyException, ResourceAlreadyExistsException, NoSuchParentResourceException {
+      throw new UnsupportedOperationException(); // not needed for testing
+    }
+
+    @Override
+    public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+      return Collections.emptySet();
+    }
+
+    @Override
+    public RequestStatus updateResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+      throw new UnsupportedOperationException(); // not needed for testing
+    }
+
+    @Override
+    public RequestStatus deleteResources(Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+      throw new UnsupportedOperationException(); // not needed for testing
+    }
+
+    @Override
+    public Map<Resource.Type, String> getKeyPropertyIds() {
+      return PropertyHelper.getKeyPropertyIds(type);
+    }
+
+    @Override
+    public Set<String> checkPropertyIds(Set<String> propertyIds) {
+      return Collections.emptySet();
+    }
+  }
+
+
+  private static class TestClusterResourceProvider extends TestResourceProvider {
+    private TestClusterResourceProvider() {
+      super(Resource.Type.Cluster);
+    }
+
+    @Override
+    public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
+      ResourceImpl resource = new ResourceImpl(Resource.Type.Cluster);
+
+      resource.setProperty(PropertyHelper.getPropertyId("Clusters", "cluster_name"), "cluster");
+
+      return Collections.<Resource>singleton(resource);
+    }
+  }
+
+  private static class TestHostResourceProvider extends TestResourceProvider {
     private Action lastAction = null;
     private Request lastRequest = null;
     private Predicate lastPredicate = null;
 
+    private TestHostResourceProvider() {
+      super(Resource.Type.Host);
+    }
+
     @Override
     public Set<Resource> getResources(Request request, Predicate predicate) throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
 
@@ -694,6 +761,9 @@ public class ClusterControllerImplTest {
         resource.setProperty(PropertyHelper.getPropertyId("Hosts", "cluster_name"), "cluster");
         resource.setProperty(PropertyHelper.getPropertyId("Hosts", "host_name"), "host:" + (4 - cnt));
 
+        resource.setProperty(PropertyHelper.getPropertyId("Hosts", "cluster_name"), "cluster");
+        resource.setProperty(PropertyHelper.getPropertyId("Hosts", "host_name"), "host:" + cnt);
+
         resource.setProperty(PropertyHelper.getPropertyId("c1", "p1"), cnt);
         resource.setProperty(PropertyHelper.getPropertyId("c1", "p2"), cnt % 2);
         resource.setProperty(PropertyHelper.getPropertyId("c1", "p3"), "foo");


Mime
View raw message