ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jspei...@apache.org
Subject [04/13] ambari git commit: AMBARI-10750. Initial merge of advanced api provisioning work.
Date Mon, 27 Apr 2015 05:52:58 GMT
http://git-wip-us.apache.org/repos/asf/ambari/blob/c9f0dd0b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
index 1fa4a4d..118a7be 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/BlueprintResourceProviderTest.java
@@ -18,7 +18,7 @@
 
 package org.apache.ambari.server.controller.internal;
 
-import static org.easymock.EasyMock.capture;
+import static org.easymock.EasyMock.anyObject;
 import static org.easymock.EasyMock.createMock;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.createStrictMock;
@@ -31,7 +31,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -41,21 +40,12 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.StackConfigurationRequest;
-import org.apache.ambari.server.controller.StackConfigurationResponse;
-import org.apache.ambari.server.controller.StackLevelConfigurationRequest;
-import org.apache.ambari.server.controller.StackServiceComponentRequest;
-import org.apache.ambari.server.controller.StackServiceComponentResponse;
-import org.apache.ambari.server.controller.StackServiceRequest;
-import org.apache.ambari.server.controller.StackServiceResponse;
 import org.apache.ambari.server.controller.internal.BlueprintResourceProvider.BlueprintConfigPopulationStrategy;
 import org.apache.ambari.server.controller.internal.BlueprintResourceProvider.BlueprintConfigPopulationStrategyV1;
 import org.apache.ambari.server.controller.internal.BlueprintResourceProvider.BlueprintConfigPopulationStrategyV2;
@@ -65,7 +55,6 @@ import org.apache.ambari.server.controller.spi.NoSuchResourceException;
 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.ResourceAlreadyExistsException;
 import org.apache.ambari.server.controller.spi.ResourceProvider;
 import org.apache.ambari.server.controller.spi.SystemException;
 import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
@@ -79,13 +68,10 @@ import org.apache.ambari.server.orm.entities.HostGroupComponentEntity;
 import org.apache.ambari.server.orm.entities.HostGroupConfigEntity;
 import org.apache.ambari.server.orm.entities.HostGroupEntity;
 import org.apache.ambari.server.orm.entities.StackEntity;
-import org.apache.ambari.server.state.AutoDeployInfo;
-import org.apache.ambari.server.state.ComponentInfo;
-import org.apache.ambari.server.state.DependencyInfo;
-import org.apache.ambari.server.state.ServiceInfo;
 import org.apache.ambari.server.utils.StageUtils;
-import org.easymock.Capture;
-import org.easymock.EasyMock;
+import org.apache.ambari.server.topology.Blueprint;
+import org.apache.ambari.server.topology.BlueprintFactory;
+import org.apache.ambari.server.topology.InvalidTopologyException;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
@@ -105,75 +91,79 @@ public class BlueprintResourceProviderTest {
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private final static BlueprintResourceProvider provider = createProvider();
   private final static BlueprintDAO dao = createStrictMock(BlueprintDAO.class);
   private final static StackDAO stackDAO = createNiceMock(StackDAO.class);
-  private final static Gson gson = new Gson();
+  private final static BlueprintEntity entity = createStrictMock(BlueprintEntity.class);
+  private final static Blueprint blueprint = createMock(Blueprint.class);
   private final static AmbariMetaInfo metaInfo = createMock(AmbariMetaInfo.class);
+  private final static BlueprintFactory blueprintFactory = createMock(BlueprintFactory.class);
+  private final static BlueprintResourceProvider provider = createProvider();
+  private final static Gson gson = new Gson();
+
 
   @BeforeClass
   public static void initClass() {
-    BlueprintResourceProvider.init(dao, stackDAO, gson, metaInfo);
+    BlueprintResourceProvider.init(blueprintFactory, dao, gson);
 
     StackEntity stackEntity = new StackEntity();
     stackEntity.setStackName("test-stack-name");
     stackEntity.setStackVersion("test-stack-version");
 
     expect(
-        stackDAO.find(EasyMock.anyObject(String.class),
-            EasyMock.anyObject(String.class))).andReturn(stackEntity).anyTimes();
+        stackDAO.find(anyObject(String.class),
+            anyObject(String.class))).andReturn(stackEntity).anyTimes();
 
     replay(stackDAO);
+
   }
 
   @Before
   public void resetGlobalMocks() {
-    reset(dao, metaInfo);
+    reset(dao, metaInfo, blueprintFactory, blueprint, entity);
   }
 
   @Test
-  public void testCreateResources() throws AmbariException, ResourceAlreadyExistsException, SystemException,
-      UnsupportedPropertyException, NoSuchParentResourceException {
+  public void testCreateResources() throws Exception {
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
     Request request = createMock(Request.class);
-    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
+    //Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
 
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
+//    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
+//    ServiceInfo service = new ServiceInfo();
+//    service.setName("test-service");
+//    services.put("test-service", service);
 
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
+//    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
+//    ComponentInfo component1 = new ComponentInfo();
+//    component1.setName("component1");
+//    ComponentInfo component2 = new ComponentInfo();
+//    component2.setName("component2");
+//    serviceComponents.add(component1);
+//    serviceComponents.add(component2);
 
-    Set<Map<String, Object>> setProperties = getTestProperties();
-
-
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
+    Set<Map<String, Object>> setProperties = getBlueprintTestProperties();
 
     // set expectations
-    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(
-        Collections.<StackServiceResponse>emptySet());
+    expect(blueprintFactory.createBlueprint(setProperties.iterator().next())).andReturn(blueprint).once();
+    blueprint.validateRequiredProperties();
+    blueprint.validateTopology();
+    expect(blueprint.toEntity()).andReturn(entity);
+    expect(blueprint.getName()).andReturn(BLUEPRINT_NAME).atLeastOnce();
     expect(request.getProperties()).andReturn(setProperties);
     expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
     expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-    dao.create(capture(entityCapture));
-
-    replay(dao, metaInfo, request, managementController);
+//    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
+//    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
+//        andReturn(serviceComponents).anyTimes();
+//    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
+//        andReturn("test-service").anyTimes();
+//    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
+//        andReturn("test-service").anyTimes();
+//    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
+    dao.create(entity);
+
+    replay(dao, entity, metaInfo, blueprintFactory, blueprint, request, managementController);
     // end expectations
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
@@ -194,51 +184,31 @@ public class BlueprintResourceProviderTest {
     assertEquals(request, lastEvent.getRequest());
     assertNull(lastEvent.getPredicate());
 
-    validateEntity(entityCapture.getValue(), false);
+    //validateEntity(entityCapture.getValue(), false);
 
-    verify(dao, metaInfo, request, managementController);
+    verify(dao, entity, blueprintFactory, metaInfo, request, managementController);
   }
 
   @Test
-  public void testCreateResources_NoValidation() throws AmbariException, ResourceAlreadyExistsException, SystemException,
-      UnsupportedPropertyException, NoSuchParentResourceException {
+  public void testCreateResources_NoValidation() throws Exception {
 
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
     Request request = createMock(Request.class);
 
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
 
-    Set<Map<String, Object>> setProperties = getTestProperties();
-
-
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
+    Set<Map<String, Object>> setProperties = getBlueprintTestProperties();
 
     // set expectations
+    expect(blueprintFactory.createBlueprint(setProperties.iterator().next())).andReturn(blueprint).once();
+    blueprint.validateRequiredProperties();
+    expect(blueprint.toEntity()).andReturn(entity);
+    expect(blueprint.getName()).andReturn(BLUEPRINT_NAME).atLeastOnce();
     expect(request.getProperties()).andReturn(setProperties);
     expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>singletonMap("validate_topology", "false"));
     expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-    dao.create(capture(entityCapture));
-
-    replay(dao, metaInfo, request, managementController);
+    dao.create(entity);
+
+    replay(dao, entity, metaInfo, blueprintFactory, blueprint, request, managementController);
     // end expectations
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
@@ -259,53 +229,84 @@ public class BlueprintResourceProviderTest {
     assertEquals(request, lastEvent.getRequest());
     assertNull(lastEvent.getPredicate());
 
-    validateEntity(entityCapture.getValue(), false);
+    verify(dao, entity, blueprintFactory, metaInfo, request, managementController);
+  }
+
+  @Test
+  public void testCreateResources_TopologyValidationFails() throws Exception {
+
+    Request request = createMock(Request.class);
+    Set<Map<String, Object>> setProperties = getBlueprintTestProperties();
+
+    // set expectations
+    expect(blueprintFactory.createBlueprint(setProperties.iterator().next())).andReturn(blueprint).once();
+    blueprint.validateRequiredProperties();
+    expect(blueprint.getName()).andReturn(BLUEPRINT_NAME).atLeastOnce();
+    blueprint.validateTopology();
+    expectLastCall().andThrow(new InvalidTopologyException("test"));
+
+    expect(request.getProperties()).andReturn(setProperties);
+    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
+    expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
 
-    verify(dao, metaInfo, request, managementController);
+    replay(dao, entity, metaInfo, blueprintFactory, blueprint, request);
+    // end expectations
+
+    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
+        Resource.Type.Blueprint,
+        PropertyHelper.getPropertyIds(Resource.Type.Blueprint),
+        PropertyHelper.getKeyPropertyIds(Resource.Type.Blueprint),
+        createMock(AmbariManagementController.class));
+
+    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
+    ((ObservableResourceProvider)provider).addObserver(observer);
+
+    try {
+      provider.createResources(request);
+      fail("Expected exception due to topology validation error");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+
+    verify(dao, entity, blueprintFactory, metaInfo, request);
   }
 
+
   @Test
-  public void testCreateResources_withConfiguration() throws AmbariException, ResourceAlreadyExistsException, SystemException,
-      UnsupportedPropertyException, NoSuchParentResourceException {
+  public void testCreateResources_withConfiguration() throws Exception {
 
-    Set<Map<String, Object>> setProperties = getTestProperties();
+    Set<Map<String, Object>> setProperties = getBlueprintTestProperties();
     setConfigurationProperties(setProperties);
     AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
+//    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
     Request request = createMock(Request.class);
 
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
+//    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
+//    ServiceInfo service = new ServiceInfo();
+//    service.setName("test-service");
+//    services.put("test-service", service);
+//
+//    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
+//    ComponentInfo component1 = new ComponentInfo();
+//    component1.setName("component1");
+//    ComponentInfo component2 = new ComponentInfo();
+//    component2.setName("component2");
+//    serviceComponents.add(component1);
+//    serviceComponents.add(component2);
 
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
 
     // set expectations
-    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(
-        Collections.<StackServiceResponse>emptySet());
+    expect(blueprintFactory.createBlueprint(setProperties.iterator().next())).andReturn(blueprint).once();
+    blueprint.validateRequiredProperties();
+    blueprint.validateTopology();
+    expect(blueprint.toEntity()).andReturn(entity);
+    expect(blueprint.getName()).andReturn(BLUEPRINT_NAME).atLeastOnce();
     expect(request.getProperties()).andReturn(setProperties);
     expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
     expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-    dao.create(capture(entityCapture));
-
-    replay(dao, metaInfo, request, managementController);
+    dao.create(entity);
+
+    replay(dao, entity, metaInfo, blueprintFactory, blueprint, request, managementController);
     // end expectations
 
     ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
@@ -326,17 +327,42 @@ public class BlueprintResourceProviderTest {
     assertEquals(request, lastEvent.getRequest());
     assertNull(lastEvent.getPredicate());
 
-    validateEntity(entityCapture.getValue(), true);
+    verify(dao, entity, blueprintFactory, metaInfo, request, managementController);
+  }
 
-    verify(dao, metaInfo, request, managementController);
+  @Test
+  public void testCreateResource_BlueprintFactoryThrowsException() throws Exception
+  {
+    Request request = createMock(Request.class);
+
+    Set<Map<String, Object>> setProperties = getBlueprintTestProperties();
+    setProperties.iterator().next().remove(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID);
+
+    // set expectations
+    expect(blueprintFactory.createBlueprint(setProperties.iterator().next())).andThrow(
+        new IllegalArgumentException("Blueprint name must be provided"));
+    expect(request.getProperties()).andReturn(setProperties);
+    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
+
+    replay(dao, entity, metaInfo, blueprintFactory, blueprint, request);
+    // end expectations
+
+    try {
+      provider.createResources(request);
+      fail("Exception expected");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    verify(dao, entity, blueprintFactory, metaInfo, request);
   }
 
+
   @Test
   public void testGetResourcesNoPredicate() throws SystemException, UnsupportedPropertyException,
                                                    NoSuchParentResourceException, NoSuchResourceException {
     Request request = createNiceMock(Request.class);
 
-    BlueprintEntity entity = createEntity(getTestProperties().iterator().next());
+    BlueprintEntity entity = createEntity(getBlueprintTestProperties().iterator().next());
 
     List<BlueprintEntity> results = new ArrayList<BlueprintEntity>();
     results.add(entity);
@@ -357,7 +383,7 @@ public class BlueprintResourceProviderTest {
       NoSuchParentResourceException, NoSuchResourceException {
     Request request = createNiceMock(Request.class);
 
-    Set<Map<String, Object>> testProperties = getTestProperties();
+    Set<Map<String, Object>> testProperties = getBlueprintTestProperties();
     setConfigurationProperties(testProperties);
     BlueprintEntity entity = createEntity(testProperties.iterator().next());
 
@@ -380,7 +406,7 @@ public class BlueprintResourceProviderTest {
   public void testDeleteResources() throws SystemException, UnsupportedPropertyException,
                                            NoSuchParentResourceException, NoSuchResourceException {
 
-    BlueprintEntity blueprintEntity = createEntity(getTestProperties().iterator().next());
+    BlueprintEntity blueprintEntity = createEntity(getBlueprintTestProperties().iterator().next());
 
     // set expectations
     expect(dao.findByName(BLUEPRINT_NAME)).andReturn(blueprintEntity);
@@ -405,718 +431,7 @@ public class BlueprintResourceProviderTest {
     verify(dao);
   }
 
-  @Test
-  public void testCreateResource_Validate__NoHostGroups() throws AmbariException, ResourceAlreadyExistsException, SystemException,
-      UnsupportedPropertyException, NoSuchParentResourceException
-  {
-    Request request = createMock(Request.class);
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    setProperties.iterator().next().remove(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID);
-
-    // set expectations
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-
-    replay(dao, metaInfo, request);
-    // end expectations
-
-    try {
-      provider.createResources(request);
-      fail("Exception expected");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    verify(dao, metaInfo, request);
-  }
-
-  @Test
-  public void testCreateResource_Validate__NoHostGroupName() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException
-  {
-    Request request = createMock(Request.class);
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    ((HashSet<Map<String, String>>) setProperties.iterator().next().get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).
-        iterator().next().put("name", "");
-
-    // set expectations
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-
-    replay(dao, metaInfo, request);
-    // end expectations
-
-    try {
-      provider.createResources(request);
-      fail("Exception expected");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    verify(dao, metaInfo, request);
-  }
-
-  @Test
-  public void testCreateResource_Validate__NoHostGroupComponents() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException
-  {
-    Request request = createMock(Request.class);
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    ((HashSet<Map<String, String>>) setProperties.iterator().next().get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).
-        iterator().next().remove("components");
-
-    // set expectations
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-
-    replay(dao, metaInfo, request);
-    // end expectations
-
-    try {
-      provider.createResources(request);
-      fail("Exception expected");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    verify(dao, metaInfo, request);
-  }
-
-  @Test
-  public void testCreateResource_Validate__NoHostGroupComponentName() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException
-  {
-    Request request = createMock(Request.class);
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    ((HashSet<Map<String, String>>) ((HashSet<Map<String, Object>>) setProperties.iterator().next().get(
-        BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).iterator().next().get("components")).
-        iterator().next().put("name", "");
-
-    // set expectations
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-
-    replay(dao, metaInfo, request);
-    // end expectations
-
-    try {
-      provider.createResources(request);
-      fail("Exception expected");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    verify(dao, metaInfo, request);
-  }
-
-  @Test
-  public void testCreateResource_Validate__InvalidComponent() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException
-  {
-    Request request = createMock(Request.class);
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    // change component1->foo which results in a validation failure for bad component name
-    component1.setName("foo");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-
-    // set expectations
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-
-    replay(dao, metaInfo, request);
-    // end expectations
-
-    try {
-      provider.createResources(request);
-      fail("Exception expected");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-    verify(dao, metaInfo, request);
-  }
-
-  @Test
-  public void testCreateResource_Validate__Cardinality__ExternalComponent() throws AmbariException, ResourceAlreadyExistsException,
-    SystemException, UnsupportedPropertyException, NoSuchParentResourceException {
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    setConfigurationProperties(setProperties);
-    ((Set<Map<String, String>>) setProperties.iterator().next().get("configurations")).
-        add(Collections.singletonMap("global/hive_database", "Existing MySQL Database"));
-
-    Iterator iter = ((HashSet<Map<String, HashSet<Map<String, String>>>>) setProperties.iterator().next().
-        get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).
-        iterator().next().get("components").iterator();
-    iter.next();
-    iter.remove();
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
-    Capture<Set<StackServiceComponentRequest>> serviceComponentRequestCapture = new Capture<Set<StackServiceComponentRequest>>();
-    Capture<StackConfigurationRequest> stackConfigurationRequestCapture = new Capture<StackConfigurationRequest>();
-    Capture<StackLevelConfigurationRequest> stackLevelConfigurationRequestCapture = new Capture<StackLevelConfigurationRequest>();
-    Request request = createMock(Request.class);
-    StackServiceResponse stackServiceResponse = createMock(StackServiceResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse = createNiceMock(StackServiceComponentResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse2 = createNiceMock(StackServiceComponentResponse.class);
-    Set<StackServiceComponentResponse> setServiceComponents = new HashSet<StackServiceComponentResponse>();
-    setServiceComponents.add(stackServiceComponentResponse);
-    setServiceComponents.add(stackServiceComponentResponse2);
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("MYSQL_SERVER");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
-
-    // set expectations
-    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(
-        Collections.<StackServiceResponse>singleton(stackServiceResponse));
-    expect(stackServiceResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();
-    expect(stackServiceResponse.getExcludedConfigTypes()).andReturn(Collections.<String>emptySet());
-
-    expect(managementController.getStackComponents(capture(serviceComponentRequestCapture))).andReturn(setServiceComponents).anyTimes();
-    expect(stackServiceComponentResponse.getCardinality()).andReturn("2").anyTimes();
-    expect(stackServiceComponentResponse.getComponentName()).andReturn("component1").anyTimes();
-    expect(stackServiceComponentResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();
-    expect(stackServiceComponentResponse2.getCardinality()).andReturn("1").anyTimes();
-    expect(stackServiceComponentResponse2.getComponentName()).andReturn("MYSQL_SERVER").anyTimes();
-    expect(stackServiceComponentResponse2.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse2.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse2.getStackVersion()).andReturn("test-stack-version").anyTimes();
-
-    expect(managementController.getStackConfigurations(Collections.singleton(capture(stackConfigurationRequestCapture)))).
-        andReturn(Collections.<StackConfigurationResponse>emptySet());
-    expect(managementController.getStackLevelConfigurations(Collections.singleton(capture(stackLevelConfigurationRequestCapture)))).
-    andReturn(Collections.<StackConfigurationResponse>emptySet());
-
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "MYSQL_SERVER")).
-        andReturn(Collections.<DependencyInfo>emptyList()).anyTimes();
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "component1")).
-        andReturn(Collections.<DependencyInfo>emptyList()).anyTimes();
-
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-    dao.create(capture(entityCapture));
-
-    replay(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-    // end expectations
-
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        Resource.Type.Blueprint,
-        PropertyHelper.getPropertyIds(Resource.Type.Blueprint),
-        PropertyHelper.getKeyPropertyIds(Resource.Type.Blueprint),
-        managementController);
-
-    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
-    ((ObservableResourceProvider)provider).addObserver(observer);
-
-    provider.createResources(request);
-
-    ResourceProviderEvent lastEvent = observer.getLastEvent();
-    assertNotNull(lastEvent);
-    assertEquals(Resource.Type.Blueprint, lastEvent.getResourceType());
-    assertEquals(ResourceProviderEvent.Type.Create, lastEvent.getType());
-    assertEquals(request, lastEvent.getRequest());
-    assertNull(lastEvent.getPredicate());
-
-    verify(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-  }
-
-  @Test
-   public void testCreateResource_Validate__Cardinality__MultipleDependencyInstances() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException {
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    setConfigurationProperties(setProperties);
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
-    Capture<Set<StackServiceComponentRequest>> serviceComponentRequestCapture = new Capture<Set<StackServiceComponentRequest>>();
-    Capture<StackConfigurationRequest> stackConfigurationRequestCapture = new Capture<StackConfigurationRequest>();
-    Capture<StackLevelConfigurationRequest> stackLevelConfigurationRequestCapture = new Capture<StackLevelConfigurationRequest>();
-    Request request = createMock(Request.class);
-    StackServiceResponse stackServiceResponse = createMock(StackServiceResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse = createNiceMock(StackServiceComponentResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse2 = createNiceMock(StackServiceComponentResponse.class);
-    Set<StackServiceComponentResponse> setServiceComponents = new HashSet<StackServiceComponentResponse>();
-    setServiceComponents.add(stackServiceComponentResponse);
-    setServiceComponents.add(stackServiceComponentResponse2);
-
-    DependencyInfo dependencyInfo = new DependencyInfo();
-    AutoDeployInfo autoDeployInfo = new AutoDeployInfo();
-    autoDeployInfo.setEnabled(false);
-    dependencyInfo.setAutoDeploy(autoDeployInfo);
-    dependencyInfo.setScope("cluster");
-    dependencyInfo.setName("test-service/component1");
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
-
-    // set expectations
-    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(
-        Collections.<StackServiceResponse>singleton(stackServiceResponse));
-    expect(stackServiceResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();
-    expect(stackServiceResponse.getExcludedConfigTypes()).andReturn(Collections.<String>emptySet());
-
-    expect(managementController.getStackComponents(capture(serviceComponentRequestCapture))).andReturn(setServiceComponents).anyTimes();
-    expect(stackServiceComponentResponse.getCardinality()).andReturn("2").anyTimes();
-    expect(stackServiceComponentResponse.getComponentName()).andReturn("component1").anyTimes();
-    expect(stackServiceComponentResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();
-    expect(stackServiceComponentResponse2.getCardinality()).andReturn("1").anyTimes();
-    expect(stackServiceComponentResponse2.getComponentName()).andReturn("component2").anyTimes();
-    expect(stackServiceComponentResponse2.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse2.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse2.getStackVersion()).andReturn("test-stack-version").anyTimes();
-
-    expect(managementController.getStackConfigurations(Collections.singleton(capture(stackConfigurationRequestCapture)))).
-        andReturn(Collections.<StackConfigurationResponse>emptySet());
-    expect(managementController.getStackLevelConfigurations(Collections.singleton(capture(stackLevelConfigurationRequestCapture)))).
-        andReturn(Collections.<StackConfigurationResponse>emptySet());
-
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "component2")).
-        andReturn(Collections.<DependencyInfo>singletonList(dependencyInfo)).anyTimes();
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "component1")).
-        andReturn(Collections.<DependencyInfo>emptyList()).anyTimes();
-
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-    dao.create(capture(entityCapture));
-
-    replay(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-    // end expectations
-
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        Resource.Type.Blueprint,
-        PropertyHelper.getPropertyIds(Resource.Type.Blueprint),
-        PropertyHelper.getKeyPropertyIds(Resource.Type.Blueprint),
-        managementController);
-
-    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
-    ((ObservableResourceProvider)provider).addObserver(observer);
-
-    provider.createResources(request);
-
-    ResourceProviderEvent lastEvent = observer.getLastEvent();
-    assertNotNull(lastEvent);
-    assertEquals(Resource.Type.Blueprint, lastEvent.getResourceType());
-    assertEquals(ResourceProviderEvent.Type.Create, lastEvent.getType());
-    assertEquals(request, lastEvent.getRequest());
-    assertNull(lastEvent.getPredicate());
-
-    verify(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-  }
-
-  @Test
-  public void testCreateResource_Validate__Cardinality__AutoCommit() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException {
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    setConfigurationProperties(setProperties);
-
-    // remove component2 from BP
-    Iterator iter = ((HashSet<Map<String, HashSet<Map<String, String>>>>) setProperties.iterator().next().
-        get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).
-        iterator().next().get("components").iterator();
-    iter.next();
-    iter.remove();
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
-    Capture<Set<StackServiceComponentRequest>> serviceComponentRequestCapture = new Capture<Set<StackServiceComponentRequest>>();
-    Capture<StackConfigurationRequest> stackConfigurationRequestCapture = new Capture<StackConfigurationRequest>();
-    Capture<StackLevelConfigurationRequest> stackLevelConfigurationRequestCapture = new Capture<StackLevelConfigurationRequest>();
-    Request request = createMock(Request.class);
-    StackServiceResponse stackServiceResponse = createMock(StackServiceResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse = createNiceMock(StackServiceComponentResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse2 = createNiceMock(StackServiceComponentResponse.class);
-    Set<StackServiceComponentResponse> setServiceComponents = new HashSet<StackServiceComponentResponse>();
-    setServiceComponents.add(stackServiceComponentResponse);
-    setServiceComponents.add(stackServiceComponentResponse2);
-
-    DependencyInfo dependencyInfo = new DependencyInfo();
-    AutoDeployInfo autoDeployInfo = new AutoDeployInfo();
-    autoDeployInfo.setEnabled(true);
-    autoDeployInfo.setCoLocate("test-service/component1");
-    dependencyInfo.setAutoDeploy(autoDeployInfo);
-    dependencyInfo.setScope("cluster");
-    dependencyInfo.setName("test-service/component2");
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
-
-    // set expectations
-    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(
-        Collections.<StackServiceResponse>singleton(stackServiceResponse));
-    expect(stackServiceResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();;
-    expect(stackServiceResponse.getExcludedConfigTypes()).andReturn(Collections.<String>emptySet());
-
-    expect(managementController.getStackComponents(capture(serviceComponentRequestCapture))).andReturn(setServiceComponents).anyTimes();
-    expect(stackServiceComponentResponse.getCardinality()).andReturn("2").anyTimes();
-    expect(stackServiceComponentResponse.getComponentName()).andReturn("component1").anyTimes();
-    expect(stackServiceComponentResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();
-    expect(stackServiceComponentResponse2.getCardinality()).andReturn("1").anyTimes();
-    expect(stackServiceComponentResponse2.getComponentName()).andReturn("component2").anyTimes();
-    expect(stackServiceComponentResponse2.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse2.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse2.getStackVersion()).andReturn("test-stack-version").anyTimes();
-
-    expect(managementController.getStackConfigurations(Collections.singleton(capture(stackConfigurationRequestCapture)))).
-        andReturn(Collections.<StackConfigurationResponse>emptySet());
-    expect(managementController.getStackLevelConfigurations(Collections.singleton(capture(stackLevelConfigurationRequestCapture)))).
-        andReturn(Collections.<StackConfigurationResponse>emptySet());
-
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "component2")).
-        andReturn(Collections.<DependencyInfo>emptyList()).anyTimes();
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "component1")).
-        andReturn(Collections.<DependencyInfo>singletonList(dependencyInfo)).anyTimes();
-
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-    dao.create(capture(entityCapture));
-
-    replay(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-    // end expectations
-
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        Resource.Type.Blueprint,
-        PropertyHelper.getPropertyIds(Resource.Type.Blueprint),
-        PropertyHelper.getKeyPropertyIds(Resource.Type.Blueprint),
-        managementController);
-
-    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
-    ((ObservableResourceProvider)provider).addObserver(observer);
-
-    provider.createResources(request);
-
-    ResourceProviderEvent lastEvent = observer.getLastEvent();
-    assertNotNull(lastEvent);
-    assertEquals(Resource.Type.Blueprint, lastEvent.getResourceType());
-    assertEquals(ResourceProviderEvent.Type.Create, lastEvent.getType());
-    assertEquals(request, lastEvent.getRequest());
-    assertNull(lastEvent.getPredicate());
-
-    verify(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-  }
-
-  @Test
-  public void testCreateResource_Validate__Cardinality__Fail() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException {
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    setConfigurationProperties(setProperties);
-
-    Iterator iter = ((HashSet<Map<String, HashSet<Map<String, String>>>>) setProperties.iterator().next().
-        get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).
-        iterator().next().get("components").iterator();
-    iter.next();
-    iter.remove();
-
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
-    Capture<Set<StackServiceComponentRequest>> serviceComponentRequestCapture = new Capture<Set<StackServiceComponentRequest>>();
-    Capture<StackConfigurationRequest> stackConfigurationRequestCapture = new Capture<StackConfigurationRequest>();
-    Capture<StackLevelConfigurationRequest> stackLevelConfigurationRequestCapture = new Capture<StackLevelConfigurationRequest>();
-    Request request = createMock(Request.class);
-    StackServiceResponse stackServiceResponse = createMock(StackServiceResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse = createNiceMock(StackServiceComponentResponse.class);
-    StackServiceComponentResponse stackServiceComponentResponse2 = createNiceMock(StackServiceComponentResponse.class);
-    Set<StackServiceComponentResponse> setServiceComponents = new HashSet<StackServiceComponentResponse>();
-    setServiceComponents.add(stackServiceComponentResponse);
-    setServiceComponents.add(stackServiceComponentResponse2);
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("MYSQL_SERVER");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-    // set expectations
-    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(
-        Collections.<StackServiceResponse>singleton(stackServiceResponse));
-    expect(stackServiceResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();
-    expect(stackServiceResponse.getExcludedConfigTypes()).andReturn(Collections.<String>emptySet());
-
-    expect(managementController.getStackComponents(capture(serviceComponentRequestCapture))).andReturn(setServiceComponents).anyTimes();
-    expect(stackServiceComponentResponse.getCardinality()).andReturn("2").anyTimes();
-    expect(stackServiceComponentResponse.getComponentName()).andReturn("component1").anyTimes();
-    expect(stackServiceComponentResponse.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse.getStackVersion()).andReturn("test-stack-version").anyTimes();
-    expect(stackServiceComponentResponse2.getCardinality()).andReturn("1").anyTimes();
-    expect(stackServiceComponentResponse2.getComponentName()).andReturn("MYSQL_SERVER").anyTimes();
-    expect(stackServiceComponentResponse2.getServiceName()).andReturn("test-service").anyTimes();
-    expect(stackServiceComponentResponse2.getStackName()).andReturn("test-stack-name").anyTimes();
-    expect(stackServiceComponentResponse2.getStackVersion()).andReturn("test-stack-version").anyTimes();
-
-    expect(managementController.getStackConfigurations(Collections.singleton(capture(stackConfigurationRequestCapture)))).
-        andReturn(Collections.<StackConfigurationResponse>emptySet());
-    expect(managementController.getStackLevelConfigurations(Collections.singleton(capture(stackLevelConfigurationRequestCapture)))).
-        andReturn(Collections.<StackConfigurationResponse>emptySet());
-
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "MYSQL_SERVER")).
-        andReturn(Collections.<DependencyInfo>emptyList()).anyTimes();
-    expect(metaInfo.getComponentDependencies("test-stack-name", "test-stack-version", "test-service", "component1")).
-        andReturn(Collections.<DependencyInfo>emptyList()).anyTimes();
-
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component2")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-
-    replay(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-    // end expectations
-
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        Resource.Type.Blueprint,
-        PropertyHelper.getPropertyIds(Resource.Type.Blueprint),
-        PropertyHelper.getKeyPropertyIds(Resource.Type.Blueprint),
-        managementController);
-
-    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
-    ((ObservableResourceProvider)provider).addObserver(observer);
-
-    try {
-      provider.createResources(request);
-      fail("Expected validation failure for MYSQL_SERVER");
-    } catch (IllegalArgumentException e) {
-      // expected
-    }
-
-    verify(dao, metaInfo, request, managementController, stackServiceResponse,
-        stackServiceComponentResponse, stackServiceComponentResponse2);
-  }
-
-  @Test
-  public void testCreateResource_Validate__AmbariServerComponent() throws AmbariException, ResourceAlreadyExistsException,
-      SystemException, UnsupportedPropertyException, NoSuchParentResourceException
-  {
-    Request request = createMock(Request.class);
-    AmbariManagementController managementController = createMock(AmbariManagementController.class);
-    Capture<Set<StackServiceRequest>> stackServiceRequestCapture = new Capture<Set<StackServiceRequest>>();
-
-    Map<String, ServiceInfo> services = new HashMap<String, ServiceInfo>();
-    ServiceInfo service = new ServiceInfo();
-    service.setName("test-service");
-    services.put("test-service", service);
-
-    List<ComponentInfo> serviceComponents = new ArrayList<ComponentInfo>();
-    ComponentInfo component1 = new ComponentInfo();
-    component1.setName("component1");
-    ComponentInfo component2 = new ComponentInfo();
-    component2.setName("component2");
-    serviceComponents.add(component1);
-    serviceComponents.add(component2);
-
-
-    Set<Map<String, Object>> setProperties = getTestProperties();
-    ((HashSet<Map<String, String>>) ((HashSet<Map<String, Object>>) setProperties.iterator().next().get(
-        BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).iterator().next().get("components")).
-        iterator().next().put("name", "AMBARI_SERVER");
-
-    Capture<BlueprintEntity> entityCapture = new Capture<BlueprintEntity>();
-
-    // set expectations
-    expect(managementController.getStackServices(capture(stackServiceRequestCapture))).andReturn(
-        Collections.<StackServiceResponse>emptySet());
-    expect(request.getProperties()).andReturn(setProperties);
-    expect(request.getRequestInfoProperties()).andReturn(Collections.<String, String>emptyMap());
-    expect(dao.findByName(BLUEPRINT_NAME)).andReturn(null);
-    expect(metaInfo.getServices("test-stack-name", "test-stack-version")).andReturn(services).anyTimes();
-    expect(metaInfo.getComponentsByService("test-stack-name", "test-stack-version", "test-service")).
-        andReturn(serviceComponents).anyTimes();
-    expect(metaInfo.getComponentToService("test-stack-name", "test-stack-version", "component1")).
-        andReturn("test-service").anyTimes();
-    expect(metaInfo.getService("test-stack-name", "test-stack-version", "test-service")).andReturn(service).anyTimes();
-
-    dao.create(capture(entityCapture));
-
-    replay(dao, metaInfo, request, managementController);
-    // end expectations
-
-    ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
-        Resource.Type.Blueprint,
-        PropertyHelper.getPropertyIds(Resource.Type.Blueprint),
-        PropertyHelper.getKeyPropertyIds(Resource.Type.Blueprint),
-        managementController);
-
-    AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
-    ((ObservableResourceProvider)provider).addObserver(observer);
-
-    provider.createResources(request);
-
-    ResourceProviderEvent lastEvent = observer.getLastEvent();
-    assertNotNull(lastEvent);
-    assertEquals(Resource.Type.Blueprint, lastEvent.getResourceType());
-    assertEquals(ResourceProviderEvent.Type.Create, lastEvent.getType());
-    assertEquals(request, lastEvent.getRequest());
-    assertNull(lastEvent.getPredicate());
-
-    verify(dao, metaInfo, request, managementController);
-  }
-
-  private Set<Map<String, Object>> getTestProperties() {
+  public static Set<Map<String, Object>> getBlueprintTestProperties() {
     Map<String, String> mapHostGroupComponentProperties = new HashMap<String, String>();
     mapHostGroupComponentProperties.put(BlueprintResourceProvider.COMPONENT_NAME_PROPERTY_ID, "component1");
 
@@ -1153,7 +468,7 @@ public class BlueprintResourceProviderTest {
     return Collections.singleton(mapProperties);
   }
 
-  private void setConfigurationProperties(Set<Map<String, Object>> properties ) {
+  public static void setConfigurationProperties(Set<Map<String, Object>> properties ) {
     Map<String, String> clusterProperties = new HashMap<String, String>();
     clusterProperties.put("core-site/properties/fs.trash.interval", "480");
     clusterProperties.put("core-site/properties/ipc.client.idlethreshold", "8500");
@@ -1179,68 +494,6 @@ public class BlueprintResourceProviderTest {
     }
   }
 
-  private void validateEntity(BlueprintEntity entity, boolean containsConfig) {
-    assertEquals(BLUEPRINT_NAME, entity.getBlueprintName());
-
-    StackEntity stackEntity = entity.getStack();
-    assertEquals("test-stack-name", stackEntity.getStackName());
-    assertEquals("test-stack-version", stackEntity.getStackVersion());
-
-    Collection<HostGroupEntity> hostGroupEntities = entity.getHostGroups();
-
-    assertEquals(2, hostGroupEntities.size());
-    for (HostGroupEntity hostGroup : hostGroupEntities) {
-      assertEquals(BLUEPRINT_NAME, hostGroup.getBlueprintName());
-      assertNotNull(hostGroup.getBlueprintEntity());
-      Collection<HostGroupComponentEntity> componentEntities = hostGroup.getComponents();
-      if (hostGroup.getName().equals("group1")) {
-        assertEquals("1", hostGroup.getCardinality());
-        assertEquals(2, componentEntities.size());
-        Iterator<HostGroupComponentEntity> componentIterator = componentEntities.iterator();
-        String name = componentIterator.next().getName();
-        assertTrue(name.equals("component1") || name.equals("component2"));
-        String name2 = componentIterator.next().getName();
-        assertFalse(name.equals(name2));
-        assertTrue(name2.equals("component1") || name2.equals("component2"));
-      } else if (hostGroup.getName().equals("group2")) {
-        assertEquals("2", hostGroup.getCardinality());
-        assertEquals(1, componentEntities.size());
-        HostGroupComponentEntity componentEntity = componentEntities.iterator().next();
-        assertEquals("component1", componentEntity.getName());
-
-        if (containsConfig) {
-          Collection<HostGroupConfigEntity> configurations = hostGroup.getConfigurations();
-          assertEquals(1, configurations.size());
-          HostGroupConfigEntity hostGroupConfigEntity = configurations.iterator().next();
-          assertEquals(BLUEPRINT_NAME, hostGroupConfigEntity.getBlueprintName());
-          assertSame(hostGroup, hostGroupConfigEntity.getHostGroupEntity());
-          assertEquals("core-site", hostGroupConfigEntity.getType());
-          Map<String, String> properties = gson.<Map<String, String>>fromJson(
-              hostGroupConfigEntity.getConfigData(), Map.class);
-          assertEquals(1, properties.size());
-          assertEquals("anything", properties.get("my.custom.hg.property"));
-        }
-      } else {
-        fail("Unexpected host group name");
-      }
-    }
-    Collection<BlueprintConfigEntity> configurations = entity.getConfigurations();
-    if (containsConfig) {
-      assertEquals(1, configurations.size());
-      BlueprintConfigEntity blueprintConfigEntity = configurations.iterator().next();
-      assertEquals(BLUEPRINT_NAME, blueprintConfigEntity.getBlueprintName());
-      assertSame(entity, blueprintConfigEntity.getBlueprintEntity());
-      assertEquals("core-site", blueprintConfigEntity.getType());
-      Map<String, String> properties = gson.<Map<String, String>>fromJson(
-          blueprintConfigEntity.getConfigData(), Map.class);
-      assertEquals(2, properties.size());
-      assertEquals("480", properties.get("fs.trash.interval"));
-      assertEquals("8500", properties.get("ipc.client.idlethreshold"));
-    } else {
-      assertEquals(0, configurations.size());
-    }
-  }
-
   private void validateResource(Resource resource, boolean containsConfig) {
     assertEquals(BLUEPRINT_NAME, resource.getPropertyValue(BlueprintResourceProvider.BLUEPRINT_NAME_PROPERTY_ID));
     assertEquals("test-stack-name", resource.getPropertyValue(BlueprintResourceProvider.STACK_NAME_PROPERTY_ID));
@@ -1501,7 +754,7 @@ public class BlueprintResourceProviderTest {
     Map<String, String> configMap = new HashMap<String, String>();
     configMap.put("global/properties/lot/foo_contact", "foo@ffl.dsfds");
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage(provider.SCHEMA_IS_NOT_SUPPORTED_MESSAGE);
+    expectedException.expectMessage(BlueprintResourceProvider.SCHEMA_IS_NOT_SUPPORTED_MESSAGE);
 
     provider.decidePopulationStrategy(configMap);
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c9f0dd0b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
index e138196..9d78245 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ClientConfigResourceProviderTest.java
@@ -27,7 +27,6 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
 import org.apache.ambari.server.state.*;
 import org.apache.ambari.server.state.PropertyInfo;
 import org.apache.ambari.server.utils.StageUtils;
-import org.easymock.EasyMock;
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -39,10 +38,8 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.io.PrintWriter;
-import java.lang.reflect.Method;
 import java.util.*;
-import static org.apache.ambari.server.configuration.Configuration.AMBARI_PYTHON_WRAP_DEFAULT;
-import static org.apache.ambari.server.configuration.Configuration.SERVER_TMP_DIR_DEFAULT;
+
 import org.apache.ambari.server.stack.StackManager;
 
 import static org.easymock.EasyMock.*;
@@ -268,7 +265,7 @@ public class ClientConfigResourceProviderTest {
     Map<String, Host> stringHostMap = new HashMap<String, Host>();
     stringHostMap.put(hostName, host);
     clusterHostInfo.put("all_hosts",all_hosts);
-    expect(StageUtils.getClusterHostInfo(stringHostMap,cluster)).andReturn(clusterHostInfo);
+    expect(StageUtils.getClusterHostInfo(cluster)).andReturn(clusterHostInfo);
 
     expect(stackId.getStackName()).andReturn(stackName).anyTimes();
     expect(stackId.getStackVersion()).andReturn(stackVersion).anyTimes();
@@ -283,7 +280,6 @@ public class ClientConfigResourceProviderTest {
     expect(ambariMetaInfo.getStackRoot()).andReturn(stackRootFile);
     expect(cluster.getConfig("hive-site", null)).andReturn(clusterConfig);
     expect(cluster.getDesiredConfigs()).andReturn(desiredConfigMap);
-    expect(clusters.getHostsForCluster(clusterName)).andReturn(hosts);
     expect(clusters.getHost(hostName)).andReturn(host);
 
     HashMap<String, String> rcaParams = new HashMap<String, String>();
@@ -471,7 +467,7 @@ public class ClientConfigResourceProviderTest {
     Map<String, Host> stringHostMap = new HashMap<String, Host>();
     stringHostMap.put(hostName, host);
     clusterHostInfo.put("all_hosts",all_hosts);
-    expect(StageUtils.getClusterHostInfo(stringHostMap,cluster)).andReturn(clusterHostInfo);
+    expect(StageUtils.getClusterHostInfo(cluster)).andReturn(clusterHostInfo);
 
     expect(stackId.getStackName()).andReturn(stackName).anyTimes();
     expect(stackId.getStackVersion()).andReturn(stackVersion).anyTimes();
@@ -486,7 +482,6 @@ public class ClientConfigResourceProviderTest {
     expect(ambariMetaInfo.getStackRoot()).andReturn(stackRootFile);
     expect(cluster.getConfig("hive-site", null)).andReturn(clusterConfig);
     expect(cluster.getDesiredConfigs()).andReturn(desiredConfigMap);
-    expect(clusters.getHostsForCluster(clusterName)).andReturn(hosts);
     expect(clusters.getHost(hostName)).andReturn(host);
 
     HashMap<String, String> rcaParams = new HashMap<String, String>();


Mime
View raw message