You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2013/03/20 21:44:50 UTC

svn commit: r1459041 [12/18] - in /incubator/ambari/branches/branch-1.2: ./ ambari-agent/ ambari-agent/conf/unix/ ambari-agent/src/main/puppet/modules/hdp-ganglia/files/ ambari-agent/src/main/puppet/modules/hdp-ganglia/manifests/ ambari-agent/src/main/...

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/ganglia/GangliaPropertyProviderTest.java Wed Mar 20 20:44:43 2013
@@ -86,22 +86,32 @@ public class GangliaPropertyProviderTest
     //http://ec2-174-129-152-147.compute-1.amazonaws.com/cgi-bin/rrd.py?c=HDPSlaves&m=jvm.metrics.gcCount,mapred.shuffleOutput.shuffle_exceptions_caught,mapred.shuffleOutput.shuffle_failed_outputs,mapred.shuffleOutput.shuffle_output_bytes,mapred.shuffleOutput.shuffle_success_outputs&s=10&e=20&r=1&h=ip-10-85-111-149.ec2.internal
 
     Set<String> properties = new HashSet<String>();
-    properties.add(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_exceptions_caught"));
-    properties.add(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_failed_outputs"));
-    properties.add(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_output_bytes"));
-    properties.add(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_success_outputs"));
+    String shuffle_exceptions_caught = PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_exceptions_caught");
+    String shuffle_failed_outputs    = PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_failed_outputs");
+    String shuffle_output_bytes      = PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_output_bytes");
+    String shuffle_success_outputs   = PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_success_outputs");
+
+    properties.add(shuffle_exceptions_caught);
+    properties.add(shuffle_failed_outputs);
+    properties.add(shuffle_output_bytes);
+    properties.add(shuffle_success_outputs);
     request = PropertyHelper.getReadRequest(properties, temporalInfoMap);
 
+    temporalInfoMap.put(shuffle_exceptions_caught, new TemporalInfoImpl(10L, 20L, 1L));
+    temporalInfoMap.put(shuffle_failed_outputs, new TemporalInfoImpl(10L, 20L, 1L));
+    temporalInfoMap.put(shuffle_output_bytes, new TemporalInfoImpl(10L, 20L, 1L));
+    temporalInfoMap.put(shuffle_success_outputs, new TemporalInfoImpl(10L, 20L, 1L));
+
     Assert.assertEquals(1, propertyProvider.populateResources(Collections.singleton(resource), request, null).size());
 
-    Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=domU-12-31-39-0E-34-E1.compute-1.internal&m=mapred.shuffleOutput.shuffle_output_bytes,mapred.shuffleOutput.shuffle_success_outputs,mapred.shuffleOutput.shuffle_failed_outputs,mapred.shuffleOutput.shuffle_exceptions_caught&e=now&pt=true",
+    Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPSlaves&h=domU-12-31-39-0E-34-E1.compute-1.internal&m=mapred.shuffleOutput.shuffle_output_bytes,mapred.shuffleOutput.shuffle_success_outputs,mapred.shuffleOutput.shuffle_failed_outputs,mapred.shuffleOutput.shuffle_exceptions_caught&s=10&e=20&r=1",
         streamProvider.getLastSpec());
 
     Assert.assertEquals(6, PropertyHelper.getProperties(resource).size());
-    Assert.assertNotNull(resource.getPropertyValue(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_exceptions_caught")));
-    Assert.assertNotNull(resource.getPropertyValue(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_failed_outputs")));
-    Assert.assertNotNull(resource.getPropertyValue(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_output_bytes")));
-    Assert.assertNotNull(resource.getPropertyValue(PropertyHelper.getPropertyId("metrics/mapred/shuffleOutput", "shuffle_success_outputs")));
+    Assert.assertNotNull(resource.getPropertyValue(shuffle_exceptions_caught));
+    Assert.assertNotNull(resource.getPropertyValue(shuffle_failed_outputs));
+    Assert.assertNotNull(resource.getPropertyValue(shuffle_output_bytes));
+    Assert.assertNotNull(resource.getPropertyValue(shuffle_success_outputs));
   }
 
 
@@ -139,7 +149,6 @@ public class GangliaPropertyProviderTest
     Request  request = PropertyHelper.getReadRequest(Collections.singleton(PROPERTY_ID), temporalInfoMap);
 
     Assert.assertEquals(3, propertyProvider.populateResources(resources, request, null).size());
-
     Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPJobTracker,HDPHBaseMaster,HDPSlaves,HDPNameNode&h=domU-12-31-39-0E-34-E3.compute-1.internal,domU-12-31-39-0E-34-E1.compute-1.internal,domU-12-31-39-0E-34-E2.compute-1.internal&m=jvm.metrics.gcCount&s=10&e=20&r=1",
         streamProvider.getLastSpec());
 
@@ -149,6 +158,39 @@ public class GangliaPropertyProviderTest
     }
   }
 
+  @Test
+  public void testPopulateResources__LargeNumberOfHostResources() throws Exception {
+    TestStreamProvider streamProvider  = new TestStreamProvider();
+    TestGangliaHostProvider hostProvider = new TestGangliaHostProvider();
+
+    GangliaPropertyProvider propertyProvider = new GangliaHostPropertyProvider(
+        PropertyHelper.getGangliaPropertyIds(Resource.Type.Host),
+        streamProvider,
+        hostProvider,
+        CLUSTER_NAME_PROPERTY_ID,
+        HOST_NAME_PROPERTY_ID
+    );
+
+    Set<Resource> resources = new HashSet<Resource>();
+
+    for (int i = 0; i < 150; ++i) {
+      Resource resource = new ResourceImpl(Resource.Type.Host);
+      resource.setProperty(HOST_NAME_PROPERTY_ID, "host" + i);
+      resources.add(resource);
+    }
+
+    // only ask for one property
+    Map<String, TemporalInfo> temporalInfoMap = new HashMap<String, TemporalInfo>();
+    temporalInfoMap.put(PROPERTY_ID, new TemporalInfoImpl(10L, 20L, 1L));
+    Request  request = PropertyHelper.getReadRequest(Collections.singleton(PROPERTY_ID), temporalInfoMap);
+
+    Assert.assertEquals(150, propertyProvider.populateResources(resources, request, null).size());
+
+    Assert.assertEquals("http://domU-12-31-39-0E-34-E1.compute-1.internal/cgi-bin/rrd.py?c=HDPJobTracker,HDPHBaseMaster,HDPSlaves,HDPNameNode&m=jvm.metrics.gcCount&s=10&e=20&r=1",
+        streamProvider.getLastSpec());
+
+  }
+
   private static class TestGangliaHostProvider implements GangliaHostProvider {
 
     @Override

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProviderTest.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProviderTest.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostComponentProviderTest.java Wed Mar 20 20:44:43 2013
@@ -55,6 +55,58 @@ public class GSInstallerHostComponentPro
   }
 
   @Test
+  public void testGetResourcesCheckState() throws Exception {
+    TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
+    GSInstallerResourceProvider provider = new GSInstallerHostComponentProvider(clusterDefinition);
+    Predicate predicate = new PredicateBuilder().property(GSInstallerHostComponentProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("HBASE_REGIONSERVER").toPredicate();
+    Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(3, resources.size());
+
+    for (Resource resource : resources) {
+      Assert.assertEquals("STARTED", resource.getPropertyValue(GSInstallerHostComponentProvider.HOST_COMPONENT_STATE_PROPERTY_ID));
+    }
+
+    stateProvider.setHealthy(false);
+
+    // need to wait for old state value to expire
+    Thread.sleep(501);
+
+    resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(3, resources.size());
+
+    for (Resource resource : resources) {
+      Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerHostComponentProvider.HOST_COMPONENT_STATE_PROPERTY_ID));
+    }
+  }
+
+  @Test
+  public void testGetResourcesCheckStateFromCategory() throws Exception {
+    TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
+    GSInstallerResourceProvider provider = new GSInstallerHostComponentProvider(clusterDefinition);
+    Predicate predicate = new PredicateBuilder().property(GSInstallerHostComponentProvider.HOST_COMPONENT_COMPONENT_NAME_PROPERTY_ID).equals("HBASE_REGIONSERVER").toPredicate();
+    Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest("HostRoles"), predicate);
+    Assert.assertEquals(3, resources.size());
+
+    for (Resource resource : resources) {
+      Assert.assertEquals("STARTED", resource.getPropertyValue(GSInstallerHostComponentProvider.HOST_COMPONENT_STATE_PROPERTY_ID));
+    }
+
+    stateProvider.setHealthy(false);
+
+    // need to wait for old state value to expire
+    Thread.sleep(501);
+
+    resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(3, resources.size());
+
+    for (Resource resource : resources) {
+      Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerHostComponentProvider.HOST_COMPONENT_STATE_PROPERTY_ID));
+    }
+  }
+
+  @Test
   public void testCreateResources() throws Exception {
     ClusterDefinition clusterDefinition = new ClusterDefinition(new TestGSInstallerStateProvider());
     GSInstallerResourceProvider provider = new GSInstallerHostComponentProvider(clusterDefinition);

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProviderTest.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProviderTest.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerHostProviderTest.java Wed Mar 20 20:44:43 2013
@@ -62,7 +62,7 @@ public class GSInstallerHostProviderTest
   @Test
   public void testGetResourcesCheckState() throws Exception {
     TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
-    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider);
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
     GSInstallerResourceProvider provider = new GSInstallerHostProvider(clusterDefinition);
     Predicate predicate = new PredicateBuilder().property(GSInstallerHostProvider.HOST_NAME_PROPERTY_ID).equals("ip-10-190-97-104.ec2.internal").toPredicate();
     Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
@@ -75,7 +75,32 @@ public class GSInstallerHostProviderTest
     stateProvider.setHealthy(false);
 
     // need to wait for old state value to expire
-    Thread.sleep(15001);
+    Thread.sleep(501);
+
+    resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    resource = resources.iterator().next();
+    Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerHostProvider.HOST_STATE_PROPERTY_ID));
+  }
+
+  @Test
+  public void testGetResourcesCheckStateFromCategory() throws Exception {
+    TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
+    GSInstallerResourceProvider provider = new GSInstallerHostProvider(clusterDefinition);
+    Predicate predicate = new PredicateBuilder().property(GSInstallerHostProvider.HOST_NAME_PROPERTY_ID).equals("ip-10-190-97-104.ec2.internal").toPredicate();
+    Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest("Hosts"), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    Resource resource = resources.iterator().next();
+
+    Assert.assertEquals("HEALTHY", resource.getPropertyValue(GSInstallerHostProvider.HOST_STATE_PROPERTY_ID));
+
+    stateProvider.setHealthy(false);
+
+    // need to wait for old state value to expire
+    Thread.sleep(501);
 
     resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
     Assert.assertEquals(1, resources.size());

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProviderTest.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProviderTest.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerServiceProviderTest.java Wed Mar 20 20:44:43 2013
@@ -62,7 +62,7 @@ public class GSInstallerServiceProviderT
   @Test
   public void testGetResourcesCheckState() throws Exception {
     TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
-    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider);
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
     GSInstallerResourceProvider provider = new GSInstallerServiceProvider(clusterDefinition);
     Predicate predicate = new PredicateBuilder().property(GSInstallerServiceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("MAPREDUCE").toPredicate();
     Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
@@ -75,7 +75,32 @@ public class GSInstallerServiceProviderT
     stateProvider.setHealthy(false);
 
     // need to wait for old state value to expire
-    Thread.sleep(15001);
+    Thread.sleep(501);
+
+    resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    resource = resources.iterator().next();
+    Assert.assertEquals("INIT", resource.getPropertyValue(GSInstallerServiceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID));
+  }
+
+  @Test
+  public void testGetResourcesCheckStateFromCategory() throws Exception {
+    TestGSInstallerStateProvider stateProvider = new TestGSInstallerStateProvider();
+    ClusterDefinition clusterDefinition = new ClusterDefinition(stateProvider, 500);
+    GSInstallerResourceProvider provider = new GSInstallerServiceProvider(clusterDefinition);
+    Predicate predicate = new PredicateBuilder().property(GSInstallerServiceProvider.SERVICE_SERVICE_NAME_PROPERTY_ID).equals("MAPREDUCE").toPredicate();
+    Set<Resource> resources = provider.getResources(PropertyHelper.getReadRequest("ServiceInfo"), predicate);
+    Assert.assertEquals(1, resources.size());
+
+    Resource resource = resources.iterator().next();
+
+    Assert.assertEquals("STARTED", resource.getPropertyValue(GSInstallerServiceProvider.SERVICE_SERVICE_STATE_PROPERTY_ID));
+
+    stateProvider.setHealthy(false);
+
+    // need to wait for old state value to expire
+    Thread.sleep(501);
 
     resources = provider.getResources(PropertyHelper.getReadRequest(), predicate);
     Assert.assertEquals(1, resources.size());

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractPropertyProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractPropertyProviderTest.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractPropertyProviderTest.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractPropertyProviderTest.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,73 @@
+/**
+ * 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.controller.internal;
+
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.SystemException;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Abstract metric provider tests.
+ */
+public class AbstractPropertyProviderTest {
+
+
+  @Test
+  public void testGetComponentMetrics() {
+    Map<String, Map<String, PropertyInfo>> componentMetrics = PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent);
+    AbstractPropertyProvider provider = new TestPropertyProvider(componentMetrics);
+    Assert.assertEquals(componentMetrics, provider.getComponentMetrics());
+  }
+
+  @Test
+  public void testGetPropertyInfoMap() {
+    AbstractPropertyProvider provider = new TestPropertyProvider(PropertyHelper.getGangliaPropertyIds(Resource.Type.HostComponent));
+
+    // specific property
+    Map<String, PropertyInfo> propertyInfoMap = provider.getPropertyInfoMap("NAMENODE", "metrics/cpu/cpu_aidle");
+    Assert.assertEquals(1, propertyInfoMap.size());
+    Assert.assertTrue(propertyInfoMap.containsKey("metrics/cpu/cpu_aidle"));
+
+    // category
+    propertyInfoMap = provider.getPropertyInfoMap("NAMENODE", "metrics/disk");
+    Assert.assertEquals(3, propertyInfoMap.size());
+    Assert.assertTrue(propertyInfoMap.containsKey("metrics/disk/disk_free"));
+    Assert.assertTrue(propertyInfoMap.containsKey("metrics/disk/disk_total"));
+    Assert.assertTrue(propertyInfoMap.containsKey("metrics/disk/part_max_used"));
+  }
+
+  static class TestPropertyProvider extends AbstractPropertyProvider {
+
+    public TestPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics) {
+      super(componentMetrics);
+    }
+
+    @Override
+    public Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate) throws SystemException {
+      return null;
+    }
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AbstractResourceProviderTest.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,625 @@
+/**
+ * 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.controller.internal;
+
+import org.apache.ambari.server.controller.ActionRequest;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.ClusterRequest;
+import org.apache.ambari.server.controller.ConfigurationRequest;
+import org.apache.ambari.server.controller.HostRequest;
+import org.apache.ambari.server.controller.RequestStatusRequest;
+import org.apache.ambari.server.controller.ServiceComponentHostRequest;
+import org.apache.ambari.server.controller.ServiceComponentRequest;
+import org.apache.ambari.server.controller.ServiceRequest;
+import org.apache.ambari.server.controller.TaskStatusRequest;
+import org.apache.ambari.server.controller.UserRequest;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.easymock.EasyMock;
+import org.easymock.IArgumentMatcher;
+import org.junit.Assert;
+import org.junit.Test;
+
+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.createMock;
+
+/**
+ * Resource provider tests.
+ */
+public class AbstractResourceProviderTest {
+
+  @Test
+  public void testCheckPropertyIds() {
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("foo");
+    propertyIds.add("cat1/foo");
+    propertyIds.add("cat2/bar");
+    propertyIds.add("cat2/baz");
+    propertyIds.add("cat3/sub1/bam");
+    propertyIds.add("cat4/sub2/sub3/bat");
+    propertyIds.add("cat5/subcat5/map");
+
+    Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+
+    AbstractResourceProvider provider =
+        (AbstractResourceProvider) AbstractResourceProvider.getResourceProvider(
+            Resource.Type.Service,
+            propertyIds,
+            keyPropertyIds,
+            managementController);
+
+    Set<String> unsupported = provider.checkPropertyIds(Collections.singleton("foo"));
+    Assert.assertTrue(unsupported.isEmpty());
+
+    // note that key is not in the set of known property ids.  We allow it if its parent is a known property.
+    // this allows for Map type properties where we want to treat the entries as individual properties
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat5/subcat5/map/key")).isEmpty());
+
+    unsupported = provider.checkPropertyIds(Collections.singleton("bar"));
+    Assert.assertEquals(1, unsupported.size());
+    Assert.assertTrue(unsupported.contains("bar"));
+
+    unsupported = provider.checkPropertyIds(Collections.singleton("cat1/foo"));
+    Assert.assertTrue(unsupported.isEmpty());
+
+    unsupported = provider.checkPropertyIds(Collections.singleton("cat1"));
+    Assert.assertTrue(unsupported.isEmpty());
+  }
+
+  @Test
+  public void testGetPropertyIds() {
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("p1");
+    propertyIds.add("foo");
+    propertyIds.add("cat1/foo");
+    propertyIds.add("cat2/bar");
+    propertyIds.add("cat2/baz");
+    propertyIds.add("cat3/sub1/bam");
+    propertyIds.add("cat4/sub2/sub3/bat");
+
+    Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+
+    AbstractResourceProvider provider =
+        (AbstractResourceProvider) AbstractResourceProvider.getResourceProvider(
+            Resource.Type.Service,
+            propertyIds,
+            keyPropertyIds,
+            managementController);
+
+    Set<String> supportedPropertyIds = provider.getPropertyIds();
+    Assert.assertTrue(supportedPropertyIds.containsAll(propertyIds));
+  }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  /**
+   * Equals check that accounts for nulls.
+   *
+   * @param left   the left object
+   * @param right  the right object
+   *
+   * @return true if the left and right object are equal or both null
+   */
+  private static boolean eq(Object left, Object right) {
+    return  left == null ? right == null : right != null && left.equals(right);
+  }
+
+
+  // ----- inner classes -----------------------------------------------------
+
+  /**
+   * Utility class for getting various AmbariManagmentController request related matchers.
+   */
+  public static class Matcher
+  {
+    public static ClusterRequest getClusterRequest(
+        Long clusterId, String clusterName, String stackVersion, Set<String> hostNames)
+    {
+      EasyMock.reportMatcher(new ClusterRequestMatcher(clusterId, clusterName, stackVersion, hostNames));
+      return null;
+    }
+
+    public static ConfigurationRequest getConfigurationRequest(
+        String clusterName, String type, String tag, Map<String, String> configs)
+    {
+      EasyMock.reportMatcher(new ConfigurationRequestMatcher(clusterName, type, tag, configs));
+      return null;
+    }
+
+    public static RequestStatusRequest getRequestRequest(Long requestId)
+    {
+      EasyMock.reportMatcher(new RequestRequestMatcher(requestId));
+      return null;
+    }
+
+    public static Set<ActionRequest> getActionRequestSet(String clusterName, String serviceName, String actionName)
+    {
+      EasyMock.reportMatcher(new ActionRequestSetMatcher(clusterName, serviceName, actionName));
+      return null;
+    }
+
+    public static Set<ServiceComponentRequest> getComponentRequestSet(String clusterName, String serviceName,
+                                                                      String componentName,
+                                                                      Map<String, String> configVersions,
+                                                                      String desiredState)
+    {
+      EasyMock.reportMatcher(new ComponentRequestSetMatcher(clusterName, serviceName, componentName,
+          configVersions, desiredState));
+      return null;
+    }
+
+    public static Set<ConfigurationRequest> getConfigurationRequestSet(String clusterName, String type,
+                                                                       String tag, Map<String, String> configs)
+    {
+      EasyMock.reportMatcher(new ConfigurationRequestSetMatcher(clusterName, type, tag, configs));
+      return null;
+    }
+
+    public static Set<HostRequest> getHostRequestSet(String hostname, String clusterName,
+                                                     Map<String, String> hostAttributes)
+    {
+      EasyMock.reportMatcher(new HostRequestSetMatcher(hostname, clusterName, hostAttributes));
+      return null;
+    }
+
+    public static Set<ServiceComponentHostRequest> getHostComponentRequestSet(
+        String clusterName, String serviceName, String componentName, String hostName,
+        Map<String, String> configVersions, String desiredState)
+    {
+      EasyMock.reportMatcher(new HostComponentRequestSetMatcher(
+          clusterName, serviceName, componentName, hostName, configVersions, desiredState));
+      return null;
+    }
+
+    public static Set<ServiceRequest> getServiceRequestSet(String clusterName, String serviceName,
+                                                           Map<String, String> configVersions, String desiredState)
+    {
+      EasyMock.reportMatcher(new ServiceRequestSetMatcher(clusterName, serviceName, configVersions, desiredState));
+      return null;
+    }
+
+    public static Set<TaskStatusRequest> getTaskRequestSet(Long requestId, Long taskId)
+    {
+      EasyMock.reportMatcher(new TaskRequestSetMatcher(requestId, taskId));
+      return null;
+    }
+
+    public static Set<UserRequest> getUserRequestSet(String name)
+    {
+      EasyMock.reportMatcher(new UserRequestSetMatcher(name));
+      return null;
+    }
+  }
+
+  /**
+   * Matcher for a ClusterRequest.
+   */
+  public static class ClusterRequestMatcher extends ClusterRequest implements IArgumentMatcher {
+
+    public ClusterRequestMatcher(Long clusterId, String clusterName, String stackVersion, Set<String> hostNames) {
+      super(clusterId, clusterName, stackVersion, hostNames);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+      return o instanceof ClusterRequest &&
+          eq(((ClusterRequest) o).getClusterId(), getClusterId()) &&
+          eq(((ClusterRequest) o).getClusterName(), getClusterName()) &&
+          eq(((ClusterRequest) o).getStackVersion(), getStackVersion()) &&
+          eq(((ClusterRequest) o).getHostNames(), getHostNames());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("ClusterRequestMatcher(" + super.toString() + ")");
+    }
+  }
+
+  /**
+   * Matcher for a ConfigurationRequest.
+   */
+  public static class ConfigurationRequestMatcher extends ConfigurationRequest implements IArgumentMatcher {
+
+    public ConfigurationRequestMatcher(String clusterName, String type, String tag, Map<String, String> configs) {
+      super(clusterName, type, tag, configs);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+      return o instanceof ConfigurationRequest &&
+          eq(((ConfigurationRequest) o).getClusterName(), getClusterName()) &&
+          eq(((ConfigurationRequest) o).getType(), getType()) &&
+          eq(((ConfigurationRequest) o).getVersionTag(), getVersionTag()) &&
+          eq(((ConfigurationRequest) o).getConfigs(), getConfigs());
+
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("ConfigurationRequestMatcher(" + super.toString() + ")");
+    }
+  }
+
+  /**
+   * Matcher for a RequestStatusRequest.
+   */
+  public static class RequestRequestMatcher extends RequestStatusRequest implements IArgumentMatcher {
+
+    public RequestRequestMatcher(Long requestId) {
+      super(requestId, "");
+    }
+
+    @Override
+    public boolean matches(Object o) {
+
+      return o instanceof RequestStatusRequest &&
+          eq(((RequestStatusRequest) o).getRequestId(), getRequestId());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("RequestRequestMatcher(" + super.toString() + ")");
+    }
+  }
+
+  /**
+   * Matcher for a ActionRequest set containing a single request.
+   */
+  public static class ActionRequestSetMatcher extends HashSet<ActionRequest> implements IArgumentMatcher {
+
+    private final ActionRequest actionRequest;
+
+    public ActionRequestSetMatcher(String clusterName, String serviceName, String actionName) {
+      this.actionRequest = new ActionRequest(clusterName, serviceName, actionName, null);
+      add(this.actionRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof ActionRequest &&
+          eq(((ActionRequest) request).getClusterName(), actionRequest.getClusterName()) &&
+          eq(((ActionRequest) request).getServiceName(), actionRequest.getServiceName()) &&
+          eq(((ActionRequest) request).getActionName(), actionRequest.getActionName());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("ActionRequestSetMatcher(" + actionRequest + ")");
+    }
+  }
+
+  /**
+   * Matcher for a ServiceComponentRequest set containing a single request.
+   */
+  public static class ComponentRequestSetMatcher extends HashSet<ServiceComponentRequest> implements IArgumentMatcher {
+
+    private final ServiceComponentRequest serviceComponentRequest;
+
+    public ComponentRequestSetMatcher(String clusterName, String serviceName, String componentName,
+                                   Map<String, String> configVersions, String desiredState) {
+      this.serviceComponentRequest =
+          new ServiceComponentRequest(clusterName, serviceName, componentName, configVersions, desiredState);
+      add(this.serviceComponentRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof ServiceComponentRequest &&
+          eq(((ServiceComponentRequest) request).getClusterName(), serviceComponentRequest.getClusterName()) &&
+          eq(((ServiceComponentRequest) request).getServiceName(), serviceComponentRequest.getServiceName()) &&
+          eq(((ServiceComponentRequest) request).getComponentName(), serviceComponentRequest.getComponentName()) &&
+          eq(((ServiceComponentRequest) request).getConfigVersions(), serviceComponentRequest.getConfigVersions()) &&
+          eq(((ServiceComponentRequest) request).getDesiredState(), serviceComponentRequest.getDesiredState());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("ComponentRequestSetMatcher(" + serviceComponentRequest + ")");
+    }
+  }
+
+  /**
+   * Matcher for a ConfigurationRequest set containing a single request.
+   */
+  public static class ConfigurationRequestSetMatcher extends HashSet<ConfigurationRequest> implements IArgumentMatcher {
+
+    private final ConfigurationRequest configurationRequest;
+
+    public ConfigurationRequestSetMatcher(String clusterName, String type, String tag, Map<String, String> configs) {
+      this.configurationRequest = new ConfigurationRequest(clusterName, type, tag, configs);
+      add(this.configurationRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof ConfigurationRequest &&
+          eq(((ConfigurationRequest) request).getClusterName(), configurationRequest.getClusterName()) &&
+          eq(((ConfigurationRequest) request).getType(), configurationRequest.getType()) &&
+          eq(((ConfigurationRequest) request).getVersionTag(), configurationRequest.getVersionTag()) &&
+          eq(((ConfigurationRequest) request).getConfigs(), configurationRequest.getConfigs());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("ConfigurationRequestSetMatcher(" + configurationRequest + ")");
+    }
+  }
+
+  /**
+   * Matcher for a HostRequest set containing a single request.
+   */
+  public static class HostRequestSetMatcher extends HashSet<HostRequest> implements IArgumentMatcher {
+
+    private final HostRequest hostRequest;
+
+    public HostRequestSetMatcher(String hostname, String clusterName, Map<String, String> hostAttributes) {
+      this.hostRequest = new HostRequest(hostname, clusterName, hostAttributes);
+      add(this.hostRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof HostRequest &&
+          eq(((HostRequest) request).getClusterName(), hostRequest.getClusterName()) &&
+          eq(((HostRequest) request).getHostname(), hostRequest.getHostname()) &&
+          eq(((HostRequest) request).getHostAttributes(), hostRequest.getHostAttributes());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("HostRequestSetMatcher(" + hostRequest + ")");
+    }
+  }
+
+  /**
+   * Matcher for a ServiceComponentHostRequest set containing a single request.
+   */
+  public static class HostComponentRequestSetMatcher extends HashSet<ServiceComponentHostRequest>
+      implements IArgumentMatcher {
+
+    private final ServiceComponentHostRequest hostComponentRequest;
+
+    public HostComponentRequestSetMatcher(String clusterName, String serviceName, String componentName, String hostName,
+                                      Map<String, String> configVersions, String desiredState) {
+      this.hostComponentRequest =
+          new ServiceComponentHostRequest(clusterName, serviceName, componentName,
+              hostName, configVersions, desiredState);
+      add(this.hostComponentRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof ServiceComponentHostRequest &&
+          eq(((ServiceComponentHostRequest) request).getClusterName(), hostComponentRequest.getClusterName()) &&
+          eq(((ServiceComponentHostRequest) request).getServiceName(), hostComponentRequest.getServiceName()) &&
+          eq(((ServiceComponentHostRequest) request).getComponentName(), hostComponentRequest.getComponentName()) &&
+          eq(((ServiceComponentHostRequest) request).getHostname(), hostComponentRequest.getHostname()) &&
+          eq(((ServiceComponentHostRequest) request).getConfigVersions(), hostComponentRequest.getConfigVersions()) &&
+          eq(((ServiceComponentHostRequest) request).getDesiredState(), hostComponentRequest.getDesiredState());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("HostComponentRequestSetMatcher(" + hostComponentRequest + ")");
+    }
+  }
+
+  /**
+   * Matcher for a ServiceRequest set containing a single request.
+   */
+  public static class ServiceRequestSetMatcher extends HashSet<ServiceRequest> implements IArgumentMatcher {
+
+    private final ServiceRequest serviceRequest;
+
+    public ServiceRequestSetMatcher(
+        String clusterName, String serviceName, Map<String, String> configVersions, String desiredState) {
+      this.serviceRequest = new ServiceRequest(clusterName, serviceName, configVersions, desiredState);
+      add(this.serviceRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof ServiceRequest &&
+          eq(((ServiceRequest) request).getClusterName(), serviceRequest.getClusterName()) &&
+          eq(((ServiceRequest) request).getServiceName(), serviceRequest.getServiceName()) &&
+          eq(((ServiceRequest) request).getConfigVersions(), serviceRequest.getConfigVersions()) &&
+          eq(((ServiceRequest) request).getDesiredState(), serviceRequest.getDesiredState());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("ServiceRequestSetMatcher(" + serviceRequest + ")");
+    }
+  }
+
+  /**
+   * Matcher for a TaskStatusRequest set containing a single request.
+   */
+  public static class TaskRequestSetMatcher extends HashSet<TaskStatusRequest> implements IArgumentMatcher {
+
+    private final TaskStatusRequest taskStatusRequest;
+
+    public TaskRequestSetMatcher(Long requestId, Long taskId) {
+      this.taskStatusRequest = new TaskStatusRequest(requestId, taskId);
+      add(this.taskStatusRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof TaskStatusRequest &&
+          eq(((TaskStatusRequest) request).getRequestId(), taskStatusRequest.getRequestId());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("TaskRequestSetMatcher(" + taskStatusRequest + ")");
+    }
+  }
+
+  /**
+   * Matcher for a UserRequest set containing a single request.
+   */
+  public static class UserRequestSetMatcher extends HashSet<UserRequest> implements IArgumentMatcher {
+
+    private final UserRequest userRequest;
+
+    public UserRequestSetMatcher(String name) {
+      this.userRequest = new UserRequest(name);
+      add(this.userRequest);
+    }
+
+    @Override
+    public boolean matches(Object o) {
+
+      if (!(o instanceof Set)) {
+        return false;
+      }
+
+      Set set = (Set) o;
+
+      if (set.size() != 1) {
+        return false;
+      }
+
+      Object request = set.iterator().next();
+
+      return request instanceof UserRequest &&
+          eq(((UserRequest) request).getUsername(), userRequest.getUsername());
+    }
+
+    @Override
+    public void appendTo(StringBuffer stringBuffer) {
+      stringBuffer.append("UserRequestSetMatcher(" + userRequest + ")");
+    }
+  }
+
+  /**
+   * A test observer that records the last event.
+   */
+  public static class TestObserver implements ResourceProviderObserver {
+
+    ResourceProviderEvent lastEvent = null;
+
+    @Override
+    public void update(ResourceProviderEvent event) {
+      lastEvent = event;
+    }
+
+    public ResourceProviderEvent getLastEvent() {
+      return lastEvent;
+    }
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,237 @@
+/**
+ * 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.controller.internal;
+
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * ActionResourceProvider tests.
+ */
+public class ActionResourceProviderTest {
+  @Test
+  public void testCreateResources() throws Exception {
+    Resource.Type type = Resource.Type.Action;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+
+    expect(managementController.createActions(AbstractResourceProviderTest.Matcher.getActionRequestSet(
+        "Cluster100", "Service100", "Action100"))).andReturn(response);
+
+    // replay
+    replay(managementController, response);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    // add the property map to a set for the request.  add more maps for multiple creates
+    Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>();
+
+    // Service 1: create a map of properties for the request
+    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+
+    // add properties to the request map
+    properties.put(ActionResourceProvider.ACTION_CLUSTER_NAME_PROPERTY_ID, "Cluster100");
+    properties.put(ActionResourceProvider.ACTION_SERVICE_NAME_PROPERTY_ID, "Service100");
+    properties.put(ActionResourceProvider.ACTION_ACTION_NAME_PROPERTY_ID, "Action100");
+
+    propertySet.add(properties);
+
+    // create the request
+    Request request = PropertyHelper.getCreateRequest(propertySet);
+
+    provider.createResources(request);
+
+    // verify
+    verify(managementController, response);
+  }
+
+  @Test
+  public void testGetResources() throws Exception {
+    Resource.Type type = Resource.Type.Action;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+
+    // replay
+    replay(managementController);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Set<String> propertyIds = new HashSet<String>();
+
+    propertyIds.add(ActionResourceProvider.ACTION_CLUSTER_NAME_PROPERTY_ID);
+    propertyIds.add(ActionResourceProvider.ACTION_SERVICE_NAME_PROPERTY_ID);
+    propertyIds.add(ActionResourceProvider.ACTION_ACTION_NAME_PROPERTY_ID);
+
+    // create the request
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+
+    // get all ... no predicate
+    try {
+      provider.getResources(request, null);
+      Assert.fail("Expected an UnsupportedOperationException");
+    } catch (UnsupportedOperationException e) {
+      // expected
+    }
+
+    // verify
+    verify(managementController);
+  }
+
+
+  @Test
+  public void testUpdateResources() throws Exception {
+    Resource.Type type = Resource.Type.Action;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+
+    // replay
+    replay(managementController, response);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    // add the property map to a set for the request.
+    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+
+    // create the request
+    Request request = PropertyHelper.getUpdateRequest(properties);
+
+    Predicate predicate =
+        new PredicateBuilder().property(ActionResourceProvider.ACTION_CLUSTER_NAME_PROPERTY_ID).equals("Cluster100").
+        and().property(ActionResourceProvider.ACTION_SERVICE_NAME_PROPERTY_ID).equals("Service102").
+        and().property(ActionResourceProvider.ACTION_ACTION_NAME_PROPERTY_ID).equals("Action100").toPredicate();
+    try {
+      provider.updateResources(request, predicate);
+      Assert.fail("Expected an UnsupportedOperationException");
+    } catch (UnsupportedOperationException e) {
+      // expected
+    }
+
+    // verify
+    verify(managementController, response);
+  }
+
+  @Test
+  public void testDeleteResources() throws Exception {
+    Resource.Type type = Resource.Type.Action;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+
+    // replay
+    replay(managementController, response);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Predicate  predicate =
+        new PredicateBuilder().property(ActionResourceProvider.ACTION_ACTION_NAME_PROPERTY_ID).equals("Action100").
+            toPredicate();
+    try {
+      provider.deleteResources(predicate);
+      Assert.fail("Expected an UnsupportedOperationException");
+    } catch (UnsupportedOperationException e) {
+      // expected
+    }
+
+    // verify
+    verify(managementController, response);
+  }
+
+  @Test
+  public void testCheckPropertyIds() throws Exception {
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("foo");
+    propertyIds.add("cat1/foo");
+    propertyIds.add("cat2/bar");
+    propertyIds.add("cat2/baz");
+    propertyIds.add("cat3/sub1/bam");
+    propertyIds.add("cat4/sub2/sub3/bat");
+    propertyIds.add("cat5/subcat5/map");
+
+    Map<Resource.Type, String> keyPropertyIds = new HashMap<Resource.Type, String>();
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+
+    AbstractResourceProvider provider =
+        (AbstractResourceProvider) AbstractResourceProvider.getResourceProvider(
+            Resource.Type.Action,
+            propertyIds,
+            keyPropertyIds,
+            managementController);
+
+    Set<String> unsupported = provider.checkPropertyIds(Collections.singleton("foo"));
+    Assert.assertTrue(unsupported.isEmpty());
+
+    // note that key is not in the set of known property ids.  We allow it if its parent is a known property.
+    // this allows for Map type properties where we want to treat the entries as individual properties
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat5/subcat5/map/key")).isEmpty());
+
+    unsupported = provider.checkPropertyIds(Collections.singleton("bar"));
+    Assert.assertEquals(1, unsupported.size());
+    Assert.assertTrue(unsupported.contains("bar"));
+
+    unsupported = provider.checkPropertyIds(Collections.singleton("cat1/foo"));
+    Assert.assertTrue(unsupported.isEmpty());
+
+    unsupported = provider.checkPropertyIds(Collections.singleton("cat1"));
+    Assert.assertTrue(unsupported.isEmpty());
+
+    unsupported = provider.checkPropertyIds(Collections.singleton("parameters/unknown_property"));
+    Assert.assertTrue(unsupported.isEmpty());
+  }
+}

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseProviderTest.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseProviderTest.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BaseProviderTest.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,261 @@
+/**
+ * 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.controller.internal;
+
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Base provider tests.
+ */
+public class BaseProviderTest {
+  @Test
+  public void testGetProperties() {
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("foo");
+    propertyIds.add("bar");
+    propertyIds.add("cat1/prop1");
+    propertyIds.add("cat2/prop2");
+    propertyIds.add("cat3/subcat3/prop3");
+
+    BaseProvider provider = new TestProvider(propertyIds);
+
+    Set<String> supportedPropertyIds = provider.getPropertyIds();
+    Assert.assertTrue(supportedPropertyIds.containsAll(propertyIds));
+  }
+
+  @Test
+  public void testCheckPropertyIds() {
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("foo");
+    propertyIds.add("bar");
+    propertyIds.add("cat1/prop1");
+    propertyIds.add("cat2/prop2");
+    propertyIds.add("cat3/subcat3/prop3");
+    propertyIds.add("cat4/subcat4/map");
+
+    BaseProvider provider = new TestProvider(propertyIds);
+
+    Assert.assertTrue(provider.checkPropertyIds(propertyIds).isEmpty());
+
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat1")).isEmpty());
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat2")).isEmpty());
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat3")).isEmpty());
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat3/subcat3")).isEmpty());
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat4/subcat4/map")).isEmpty());
+
+    // note that key is not in the set of known property ids.  We allow it if its parent is a known property.
+    // this allows for Map type properties where we want to treat the entries as individual properties
+    Assert.assertTrue(provider.checkPropertyIds(Collections.singleton("cat4/subcat4/map/key")).isEmpty());
+
+    propertyIds.add("badprop");
+    propertyIds.add("badcat");
+
+    Set<String> unsupportedPropertyIds = provider.checkPropertyIds(propertyIds);
+    Assert.assertFalse(unsupportedPropertyIds.isEmpty());
+    Assert.assertEquals(2, unsupportedPropertyIds.size());
+    Assert.assertTrue(unsupportedPropertyIds.contains("badprop"));
+    Assert.assertTrue(unsupportedPropertyIds.contains("badcat"));
+  }
+
+  @Test
+  public void testGetRequestPropertyIds() {
+    Set<String> providerPropertyIds = new HashSet<String>();
+    providerPropertyIds.add("foo");
+    providerPropertyIds.add("bar");
+    providerPropertyIds.add("cat1/sub1");
+
+    BaseProvider provider = new TestProvider(providerPropertyIds);
+
+    Request request = PropertyHelper.getReadRequest("foo");
+
+    Set<String> requestedPropertyIds = provider.getRequestPropertyIds(request, null);
+
+    Assert.assertEquals(1, requestedPropertyIds.size());
+    Assert.assertTrue(requestedPropertyIds.contains("foo"));
+
+    request = PropertyHelper.getReadRequest("foo", "bar");
+
+    requestedPropertyIds = provider.getRequestPropertyIds(request, null);
+
+    Assert.assertEquals(2, requestedPropertyIds.size());
+    Assert.assertTrue(requestedPropertyIds.contains("foo"));
+    Assert.assertTrue(requestedPropertyIds.contains("bar"));
+
+    request = PropertyHelper.getReadRequest("foo", "baz", "bar", "cat", "cat1/prop1");
+
+    requestedPropertyIds = provider.getRequestPropertyIds(request, null);
+
+    Assert.assertEquals(2, requestedPropertyIds.size());
+    Assert.assertTrue(requestedPropertyIds.contains("foo"));
+    Assert.assertTrue(requestedPropertyIds.contains("bar"));
+
+    // ask for a property that isn't specified as supported, but its category is... the property
+    // should end up in the returned set for the case where the category is a Map property
+    request = PropertyHelper.getReadRequest("foo", "cat1/sub1/prop1");
+
+    requestedPropertyIds = provider.getRequestPropertyIds(request, null);
+
+    Assert.assertEquals(2, requestedPropertyIds.size());
+    Assert.assertTrue(requestedPropertyIds.contains("foo"));
+    Assert.assertTrue(requestedPropertyIds.contains("cat1/sub1/prop1"));
+  }
+
+  @Test
+  public void testSetResourceProperty() {
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("p1");
+    propertyIds.add("foo");
+    propertyIds.add("cat1/foo");
+    propertyIds.add("cat2/bar");
+    propertyIds.add("cat2/baz");
+    propertyIds.add("cat3/sub1/bam");
+    propertyIds.add("cat4/sub2/sub3/bat");
+    propertyIds.add("cat5/sub5");
+
+    Resource resource = new ResourceImpl(Resource.Type.Service);
+
+    Assert.assertNull(resource.getPropertyValue("foo"));
+
+    BaseProvider.setResourceProperty(resource, "foo", "value1", propertyIds);
+    Assert.assertEquals("value1", resource.getPropertyValue("foo"));
+
+    BaseProvider.setResourceProperty(resource, "cat2/bar", "value2", propertyIds);
+    Assert.assertEquals("value2", resource.getPropertyValue("cat2/bar"));
+
+    Assert.assertNull(resource.getPropertyValue("unsupported"));
+    BaseProvider.setResourceProperty(resource, "unsupported", "valueX", propertyIds);
+    Assert.assertNull(resource.getPropertyValue("unsupported"));
+
+    // we should allow anything under the category cat5/sub5
+    BaseProvider.setResourceProperty(resource, "cat5/sub5/prop5", "value5", propertyIds);
+    Assert.assertEquals("value5", resource.getPropertyValue("cat5/sub5/prop5"));
+    BaseProvider.setResourceProperty(resource, "cat5/sub5/sub5a/prop5a", "value5", propertyIds);
+    Assert.assertEquals("value5", resource.getPropertyValue("cat5/sub5/sub5a/prop5a"));
+    // we shouldn't allow anything under the category cat5/sub7
+    BaseProvider.setResourceProperty(resource, "cat5/sub7/unsupported", "valueX", propertyIds);
+    Assert.assertNull(resource.getPropertyValue("cat5/sub7/unsupported"));
+  }
+
+  @Test
+  public void testSetResourcePropertyWithMaps() {
+    Set<String> propertyIds = new HashSet<String>();
+    propertyIds.add("cat1/emptyMapProperty");
+    propertyIds.add("cat1/mapProperty");
+    propertyIds.add("cat2/mapMapProperty");
+    propertyIds.add("cat3/mapProperty3/key2");
+    propertyIds.add("cat4/mapMapProperty4/subMap1/key3");
+    propertyIds.add("cat4/mapMapProperty4/subMap2");
+
+    Resource resource = new ResourceImpl(Resource.Type.Service);
+
+    // Adding an empty Map as a property should add the actual Map as a property
+    Map<String, String> emptyMapProperty = new HashMap<String, String>();
+    BaseProvider.setResourceProperty(resource, "cat1/emptyMapProperty", emptyMapProperty, propertyIds);
+    Assert.assertTrue(resource.getPropertiesMap().containsKey("cat1/emptyMapProperty"));
+
+    Map<String, String> mapProperty = new HashMap<String, String>();
+    mapProperty.put("key1", "value1");
+    mapProperty.put("key2", "value2");
+    mapProperty.put("key3", "value3");
+
+    // Adding a property of type Map should add all of its keys as sub properties
+    // if the map property was requested
+    BaseProvider.setResourceProperty(resource, "cat1/mapProperty", mapProperty, propertyIds);
+    Assert.assertNull(resource.getPropertyValue("cat1/mapProperty"));
+    Assert.assertEquals("value1", resource.getPropertyValue("cat1/mapProperty/key1"));
+    Assert.assertEquals("value2", resource.getPropertyValue("cat1/mapProperty/key2"));
+    Assert.assertEquals("value3", resource.getPropertyValue("cat1/mapProperty/key3"));
+
+    Map<String, Map<String, String>> mapMapProperty = new HashMap<String, Map<String, String>>();
+    Map<String, String> mapSubProperty1 = new HashMap<String, String>();
+    mapSubProperty1.put("key1", "value11");
+    mapSubProperty1.put("key2", "value12");
+    mapSubProperty1.put("key3", "value13");
+    mapMapProperty.put("subMap1", mapSubProperty1);
+    Map<String, String> mapSubProperty2 = new HashMap<String, String>();
+    mapSubProperty2.put("key1", "value21");
+    mapSubProperty2.put("key2", "value22");
+    mapSubProperty2.put("key3", "value23");
+    mapMapProperty.put("subMap2", mapSubProperty2);
+    Map<String, String> mapSubProperty3 = new HashMap<String, String>();
+    mapMapProperty.put("subMap3", mapSubProperty3);
+
+    // Map of maps ... adding a property of type Map should add all of its keys as sub properties
+    // if the map property was requested
+    BaseProvider.setResourceProperty(resource, "cat2/mapMapProperty", mapMapProperty, propertyIds);
+    Assert.assertNull(resource.getPropertyValue("cat2/mapMapProperty"));
+    Assert.assertNull(resource.getPropertyValue("cat2/mapMapProperty/subMap1"));
+    Assert.assertNull(resource.getPropertyValue("cat2/mapMapProperty/subMap2"));
+    Assert.assertTrue(resource.getPropertiesMap().containsKey("cat2/mapMapProperty/subMap3"));
+    Assert.assertEquals("value11", resource.getPropertyValue("cat2/mapMapProperty/subMap1/key1"));
+    Assert.assertEquals("value12", resource.getPropertyValue("cat2/mapMapProperty/subMap1/key2"));
+    Assert.assertEquals("value13", resource.getPropertyValue("cat2/mapMapProperty/subMap1/key3"));
+    Assert.assertEquals("value21", resource.getPropertyValue("cat2/mapMapProperty/subMap2/key1"));
+    Assert.assertEquals("value22", resource.getPropertyValue("cat2/mapMapProperty/subMap2/key2"));
+    Assert.assertEquals("value23", resource.getPropertyValue("cat2/mapMapProperty/subMap2/key3"));
+
+    Map<String, String> mapProperty3 = new HashMap<String, String>();
+    mapProperty3.put("key1", "value1");
+    mapProperty3.put("key2", "value2");
+    mapProperty3.put("key3", "value3");
+
+    // Adding a property of type Map shouldn't add the map if it wasn't requested and
+    // should only add requested keys as sub properties ...
+    // only "cat3/mapProperty3/key2" was requested
+    BaseProvider.setResourceProperty(resource, "cat3/mapProperty3", mapProperty3, propertyIds);
+    Assert.assertNull(resource.getPropertyValue("cat3/mapProperty3"));
+    Assert.assertNull(resource.getPropertyValue("cat3/mapProperty3/key1"));
+    Assert.assertEquals("value2", resource.getPropertyValue("cat3/mapProperty3/key2"));
+    Assert.assertNull(resource.getPropertyValue("cat3/mapProperty3/key3"));
+
+    Map<String, Map<String, String>> mapMapProperty4 = new HashMap<String, Map<String, String>>();
+    mapMapProperty4.put("subMap1", mapSubProperty1);
+    mapMapProperty4.put("subMap2", mapSubProperty2);
+    // Map of maps ... adding a property of type Map shouldn't add the map if it wasn't requested and
+    // should only add requested keys as sub properties ...
+    // only "cat4/mapMapProperty4/subMap1/key3" and "cat4/mapMapProperty4/subMap2" are requested
+    BaseProvider.setResourceProperty(resource, "cat4/mapMapProperty4", mapMapProperty4, propertyIds);
+    Assert.assertNull(resource.getPropertyValue("cat4/mapMapProperty4"));
+    Assert.assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap1"));
+    Assert.assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap2"));
+    Assert.assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap1/key1"));
+    Assert.assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap1/key2"));
+    Assert.assertEquals("value13", resource.getPropertyValue("cat4/mapMapProperty4/subMap1/key3"));
+    Assert.assertEquals("value21", resource.getPropertyValue("cat4/mapMapProperty4/subMap2/key1"));
+    Assert.assertEquals("value22", resource.getPropertyValue("cat4/mapMapProperty4/subMap2/key2"));
+    Assert.assertEquals("value23", resource.getPropertyValue("cat4/mapMapProperty4/subMap2/key3"));
+  }
+
+  static class TestProvider extends BaseProvider {
+
+    public TestProvider(Set<String> propertyIds) {
+      super(propertyIds);
+    }
+  }
+}

Modified: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java?rev=1459041&r1=1459040&r2=1459041&view=diff
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java (original)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterControllerImplTest.java Wed Mar 20 20:44:43 2013
@@ -66,11 +66,6 @@ public class ClusterControllerImplTest {
     }
 
     @Override
-    public Set<String> getPropertyIds() {
-      return propertyProviderProperties;
-    }
-
-    @Override
     public Set<String> checkPropertyIds(Set<String> propertyIds) {
       if (!propertyProviderProperties.containsAll(propertyIds)) {
         Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);
@@ -402,39 +397,39 @@ public class ClusterControllerImplTest {
     Assert.assertTrue(keyPropertyIds.containsAll(predicatePropertyIds));
   }
 
-  @Test
-  public void testGetSchema() {
-    ProviderModule module = new TestProviderModule();
-
-    ClusterController controller = new ClusterControllerImpl(module);
-    Schema schema = controller.getSchema(Resource.Type.Host);
-
-    ResourceProvider resourceProvider = module.getResourceProvider(Resource.Type.Host);
-
-    Map<Resource.Type, String> keyPropertyIds = resourceProvider.getKeyPropertyIds();
-    for (Map.Entry<Resource.Type, String> entry : keyPropertyIds.entrySet()) {
-      Assert.assertEquals(entry.getValue(), schema.getKeyPropertyId(entry.getKey()));
-    }
-
-    Map<String, Set<String>> categories = schema.getCategoryProperties();
-    for (String propertyId : resourceProvider.getPropertyIdsForSchema()) {
-      String category = PropertyHelper.getPropertyCategory(propertyId);
-      Set<String> properties = categories.get(category);
-      Assert.assertNotNull(properties);
-      Assert.assertTrue(properties.contains(PropertyHelper.getPropertyName(propertyId)));
-    }
-
-    List<PropertyProvider> propertyProviders = module.getPropertyProviders(Resource.Type.Host);
-
-    for (PropertyProvider propertyProvider : propertyProviders) {
-      for (String propertyId : propertyProvider.getPropertyIds()) {
-        String category = PropertyHelper.getPropertyCategory(propertyId);
-        Set<String> properties = categories.get(category);
-        Assert.assertNotNull(properties);
-        Assert.assertTrue(properties.contains(PropertyHelper.getPropertyName(propertyId)));
-      }
-    }
-  }
+//  @Test
+//  public void testGetSchema() {
+//    ProviderModule module = new TestProviderModule();
+//
+//    ClusterController controller = new ClusterControllerImpl(module);
+//    Schema schema = controller.getSchema(Resource.Type.Host);
+//
+//    ResourceProvider resourceProvider = module.getResourceProvider(Resource.Type.Host);
+//
+//    Map<Resource.Type, String> keyPropertyIds = resourceProvider.getKeyPropertyIds();
+//    for (Map.Entry<Resource.Type, String> entry : keyPropertyIds.entrySet()) {
+//      Assert.assertEquals(entry.getValue(), schema.getKeyPropertyId(entry.getKey()));
+//    }
+//
+//    Map<String, Set<String>> categories = schema.getCategoryProperties();
+//    for (String propertyId : resourceProvider.getPropertyIdsForSchema()) {
+//      String category = PropertyHelper.getPropertyCategory(propertyId);
+//      Set<String> properties = categories.get(category);
+//      Assert.assertNotNull(properties);
+//      Assert.assertTrue(properties.contains(PropertyHelper.getPropertyName(propertyId)));
+//    }
+//
+//    List<PropertyProvider> propertyProviders = module.getPropertyProviders(Resource.Type.Host);
+//
+//    for (PropertyProvider propertyProvider : propertyProviders) {
+//      for (String propertyId : propertyProvider.getPropertyIds()) {
+//        String category = PropertyHelper.getPropertyCategory(propertyId);
+//        Set<String> properties = categories.get(category);
+//        Assert.assertNotNull(properties);
+//        Assert.assertTrue(properties.contains(PropertyHelper.getPropertyName(propertyId)));
+//      }
+//    }
+//  }
 
   private static class TestProviderModule implements ProviderModule {
     private Map<Resource.Type, ResourceProvider> providers = new HashMap<Resource.Type, ResourceProvider>();
@@ -506,11 +501,6 @@ public class ClusterControllerImplTest {
     }
 
     @Override
-    public Set<String> getPropertyIdsForSchema() {
-      return resourceProviderProperties;
-    }
-
-    @Override
     public Set<String> checkPropertyIds(Set<String> propertyIds) {
       if (!resourceProviderProperties.containsAll(propertyIds)) {
         Set<String> unsupportedPropertyIds = new HashSet<String>(propertyIds);

Added: incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java?rev=1459041&view=auto
==============================================================================
--- incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java (added)
+++ incubator/ambari/branches/branch-1.2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClusterResourceProviderTest.java Wed Mar 20 20:44:43 2013
@@ -0,0 +1,301 @@
+/**
+ * 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.controller.internal;
+
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.ClusterRequest;
+import org.apache.ambari.server.controller.ClusterResponse;
+import org.apache.ambari.server.controller.RequestStatusResponse;
+import org.apache.ambari.server.controller.spi.Predicate;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.apache.ambari.server.controller.spi.ResourceProvider;
+import org.apache.ambari.server.controller.utilities.PredicateBuilder;
+import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+/**
+ * ClusterResourceProvider tests.
+ */
+public class ClusterResourceProviderTest {
+  @Test
+  public void testCreateResources() throws Exception{
+    Resource.Type type = Resource.Type.Cluster;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+
+    managementController.createCluster(
+        AbstractResourceProviderTest.Matcher.getClusterRequest(null, "Cluster100", "HDP-0.1", null));
+    managementController.createCluster(
+        AbstractResourceProviderTest.Matcher.getClusterRequest(99L, null, "HDP-0.1", null));
+
+    // replay
+    replay(managementController, response);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+
+    ((ObservableResourceProvider)provider).addObserver(observer);
+
+    // add the property map to a set for the request.  add more maps for multiple creates
+    Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>();
+
+    // Cluster 1: create a map of properties for the request
+    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+
+    // add the cluster name to the properties map
+    properties.put(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID, "Cluster100");
+
+    // add the version to the properties map
+    properties.put(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, "HDP-0.1");
+
+    propertySet.add(properties);
+
+    // Cluster 2: create a map of properties for the request
+    properties = new LinkedHashMap<String, Object>();
+
+    // add the cluster id to the properties map
+    properties.put(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID, 99L);
+
+    // add the version to the properties map
+    properties.put(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, "HDP-0.1");
+
+    propertySet.add(properties);
+
+    // create the request
+    Request request = PropertyHelper.getCreateRequest(propertySet);
+
+    provider.createResources(request);
+
+    ResourceProviderEvent lastEvent = observer.getLastEvent();
+    Assert.assertNotNull(lastEvent);
+    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
+    Assert.assertEquals(ResourceProviderEvent.Type.Create, lastEvent.getType());
+    Assert.assertEquals(request, lastEvent.getRequest());
+    Assert.assertNull(lastEvent.getPredicate());
+
+    // verify
+    verify(managementController, response);
+  }
+
+  @Test
+  public void testGetResources() throws Exception{
+    Resource.Type type = Resource.Type.Cluster;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+
+    Set<ClusterResponse> allResponse = new HashSet<ClusterResponse>();
+    allResponse.add(new ClusterResponse(100L, "Cluster100", null, null));
+    allResponse.add(new ClusterResponse(101L, "Cluster101", null, null));
+    allResponse.add(new ClusterResponse(102L, "Cluster102", null, null));
+    allResponse.add(new ClusterResponse(103L, "Cluster103", null, null));
+    allResponse.add(new ClusterResponse(104L, "Cluster104", null, null));
+
+    Set<ClusterResponse> nameResponse = new HashSet<ClusterResponse>();
+    nameResponse.add(new ClusterResponse(102L, "Cluster102", null, null));
+
+    Set<ClusterResponse> idResponse = new HashSet<ClusterResponse>();
+    idResponse.add(new ClusterResponse(103L, "Cluster103", null, null));
+
+    // set expectations
+    expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(allResponse).once();
+    expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(nameResponse).once();
+    expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(idResponse).once();
+
+    // replay
+    replay(managementController);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    Set<String> propertyIds = new HashSet<String>();
+
+    propertyIds.add(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID);
+    propertyIds.add(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);
+
+    // create the request
+    Request request = PropertyHelper.getReadRequest(propertyIds);
+
+    // get all ... no predicate
+    Set<Resource> resources = provider.getResources(request, null);
+
+    Assert.assertEquals(5, resources.size());
+    for (Resource resource : resources) {
+      Long id = (Long) resource.getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID);
+      String name = (String) resource.getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID);
+      Assert.assertEquals(name, "Cluster" + id);
+    }
+
+    // get cluster named Cluster102
+    Predicate predicate =
+        new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").
+            toPredicate();
+    resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    Assert.assertEquals(102L, resources.iterator().next().
+        getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID));
+    Assert.assertEquals("Cluster102", resources.iterator().next().
+        getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));
+
+    // get cluster with id == 103
+    predicate =
+        new PredicateBuilder().property(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
+    resources = provider.getResources(request, predicate);
+
+    Assert.assertEquals(1, resources.size());
+    Assert.assertEquals(103L, resources.iterator().next().
+        getPropertyValue(ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID));
+    Assert.assertEquals("Cluster103", resources.iterator().next().
+        getPropertyValue(ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID));
+
+    // verify
+    verify(managementController);
+  }
+
+  @Test
+  public void testUpdateResources() throws Exception{
+    Resource.Type type = Resource.Type.Cluster;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+
+    Set<ClusterResponse> nameResponse = new HashSet<ClusterResponse>();
+    nameResponse.add(new ClusterResponse(102L, "Cluster102", null, null));
+
+    // set expectations
+    expect(managementController.getClusters(EasyMock.<Set<ClusterRequest>>anyObject())).andReturn(nameResponse).once();
+    expect(managementController.updateCluster(
+        AbstractResourceProviderTest.Matcher.getClusterRequest(102L, "Cluster102", "HDP-0.1", null))).
+        andReturn(response).once();
+    expect(managementController.updateCluster(
+        AbstractResourceProviderTest.Matcher.getClusterRequest(103L, null, "HDP-0.1", null))).
+        andReturn(response).once();
+
+    // replay
+    replay(managementController, response);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+
+    ((ObservableResourceProvider)provider).addObserver(observer);
+
+    Map<String, Object> properties = new LinkedHashMap<String, Object>();
+
+    properties.put(ClusterResourceProvider.CLUSTER_VERSION_PROPERTY_ID, "HDP-0.1");
+
+    // create the request
+    Request request = PropertyHelper.getUpdateRequest(properties);
+
+    // update the cluster named Cluster102
+    Predicate  predicate = new PredicateBuilder().property(
+        ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").toPredicate();
+    provider.updateResources(request, predicate);
+
+    // update the cluster where id == 103
+    predicate = new PredicateBuilder().property(
+        ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
+    provider.updateResources(request, predicate);
+
+    ResourceProviderEvent lastEvent = observer.getLastEvent();
+    Assert.assertNotNull(lastEvent);
+    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
+    Assert.assertEquals(ResourceProviderEvent.Type.Update, lastEvent.getType());
+    Assert.assertEquals(request, lastEvent.getRequest());
+    Assert.assertEquals(predicate, lastEvent.getPredicate());
+
+    // verify
+    verify(managementController, response);
+  }
+
+  @Test
+  public void testDeleteResources() throws Exception{
+    Resource.Type type = Resource.Type.Cluster;
+
+    AmbariManagementController managementController = createMock(AmbariManagementController.class);
+    RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
+
+    // set expectations
+    managementController.deleteCluster(
+        AbstractResourceProviderTest.Matcher.getClusterRequest(null, "Cluster102", null, null));
+    managementController.deleteCluster(
+        AbstractResourceProviderTest.Matcher.getClusterRequest(103L, null, null, null));
+
+    // replay
+    replay(managementController, response);
+
+    ResourceProvider provider = AbstractResourceProvider.getResourceProvider(
+        type,
+        PropertyHelper.getPropertyIds(type),
+        PropertyHelper.getKeyPropertyIds(type),
+        managementController);
+
+    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+
+    ((ObservableResourceProvider)provider).addObserver(observer);
+
+    // delete the cluster named Cluster102
+    Predicate  predicate = new PredicateBuilder().property(
+        ClusterResourceProvider.CLUSTER_NAME_PROPERTY_ID).equals("Cluster102").toPredicate();
+    provider.deleteResources(predicate);
+
+    // delete the cluster where id == 103
+    predicate = new PredicateBuilder().property(
+        ClusterResourceProvider.CLUSTER_ID_PROPERTY_ID).equals(103L).toPredicate();
+    provider.deleteResources(predicate);
+
+    ResourceProviderEvent lastEvent = observer.getLastEvent();
+    Assert.assertNotNull(lastEvent);
+    Assert.assertEquals(Resource.Type.Cluster, lastEvent.getResourceType());
+    Assert.assertEquals(ResourceProviderEvent.Type.Delete, lastEvent.getType());
+    Assert.assertEquals(predicate, lastEvent.getPredicate());
+    Assert.assertNull(lastEvent.getRequest());
+
+    // verify
+    verify(managementController, response);
+  }
+}