This is an automated email from the ASF dual-hosted git repository. benyoka pushed a commit to branch branch-feature-AMBARI-14714 in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/branch-feature-AMBARI-14714 by this push: new d341c7a AMBARI-22614 fix some unit tests (benyoka) (#461) d341c7a is described below commit d341c7a61761a2997027ae0441c2175562b76f63 Author: benyoka <beny...@users.noreply.github.com> AuthorDate: Sat Feb 24 21:00:04 2018 +0100 AMBARI-22614 fix some unit tests (benyoka) (#461) * AMBARI-22614 fix some unit tests (benyoka) * AMBARI-22614 fix some unit tests / remove unused import (benyoka) --- .../server/state/configgroup/ConfigGroupImpl.java | 3 ++- .../main/resources/Ambari-DDL-SQLServer-CREATE.sql | 1 - .../internal/ConfigGroupResourceProviderTest.java | 11 +++++++-- .../ambari/server/state/ConfigGroupTest.java | 28 +++++++++++++++++++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java index 2536d8b..b1cf381 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java @@ -101,7 +101,8 @@ public class ConfigGroupImpl implements ConfigGroup { @AssistedInject public ConfigGroupImpl(@Assisted("cluster") Cluster cluster, @Assisted("serviceGroupId") @Nullable Long serviceGroupId, - @Assisted("serviceId") @Nullable Long serviceId, @Assisted("name") String name, + @Assisted("serviceId") @Nullable Long serviceId, + @Assisted("name") String name, @Assisted("tag") String tag, @Assisted("description") String description, @Assisted("configs") Map<String, Config> configurations, @Assisted("hosts") Map<Long, Host> hosts, Clusters clusters, ConfigFactory configFactory, diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql index 036ebc8..94f00f0 100644 --- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql +++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql @@ -137,7 +137,6 @@ CREATE TABLE servicegroups ( id BIGINT NOT NULL, service_group_name VARCHAR(255) NOT NULL, cluster_id BIGINT NOT NULL, - stack_id BIGINT NOT NULL, CONSTRAINT PK_servicegroups PRIMARY KEY (id, cluster_id), CONSTRAINT FK_servicegroups_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id), CONSTRAINT FK_servicegroups_stack_id FOREIGN KEY (stack_id) REFERENCES stack (stack_id)); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java index 0485396..158ab7d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ConfigGroupResourceProviderTest.java @@ -64,6 +64,7 @@ import org.apache.ambari.server.state.Clusters; import org.apache.ambari.server.state.Config; import org.apache.ambari.server.state.ConfigHelper; import org.apache.ambari.server.state.Host; +import org.apache.ambari.server.state.Service; import org.apache.ambari.server.state.configgroup.ConfigGroup; import org.apache.ambari.server.state.configgroup.ConfigGroupFactory; import org.easymock.Capture; @@ -82,6 +83,8 @@ import com.google.inject.util.Modules; public class ConfigGroupResourceProviderTest { + public static final String SERVICE_GROUP_NAME = "default"; + public static final String SERVICE_NAME = "ZOOKEEPER"; private HostDAO hostDAO = null; @Before @@ -154,6 +157,7 @@ public class ConfigGroupResourceProviderTest { HostEntity hostEntity2 = createMock(HostEntity.class); ConfigGroupFactory configGroupFactory = createNiceMock(ConfigGroupFactory.class); ConfigGroup configGroup = createNiceMock(ConfigGroup.class); + Service service = createNiceMock(Service.class); expect(managementController.getClusters()).andReturn(clusters).anyTimes(); expect(clusters.getCluster("Cluster100")).andReturn(cluster).anyTimes(); @@ -161,6 +165,8 @@ public class ConfigGroupResourceProviderTest { expect(clusters.getHost("h2")).andReturn(h2); expect(cluster.getClusterName()).andReturn("Cluster100").anyTimes(); expect(cluster.isConfigTypeExists(anyString())).andReturn(true).anyTimes(); + expect(cluster.getService(SERVICE_GROUP_NAME, SERVICE_NAME)).andReturn(service); + expect(service.getServiceId()).andReturn(1L); expect(managementController.getConfigGroupFactory()).andReturn(configGroupFactory); expect(managementController.getAuthName()).andReturn("admin").anyTimes(); expect(hostDAO.findByName("h1")).andReturn(hostEntity1).atLeastOnce(); @@ -172,7 +178,6 @@ public class ConfigGroupResourceProviderTest { Capture<String> serviceName = newCapture(); Capture<Long> servcieId = newCapture(); Capture<Long> servcieGroupId = newCapture(); - Capture<String> captureName = newCapture(); Capture<String> captureDesc = newCapture(); Capture<String> captureTag = newCapture(); Capture<Map<String, Config>> captureConfigs = newCapture(); @@ -182,7 +187,7 @@ public class ConfigGroupResourceProviderTest { capture(captureTag), capture(captureDesc), capture(captureConfigs), capture(captureHosts))).andReturn(configGroup); - replay(managementController, clusters, cluster, configGroupFactory, + replay(managementController, clusters, cluster, service, configGroupFactory, configGroup, response, hostDAO, hostEntity1, hostEntity2); ResourceProvider provider = getConfigGroupResourceProvider @@ -218,6 +223,8 @@ public class ConfigGroupResourceProviderTest { hostSet); properties.put(ConfigGroupResourceProvider.CONFIGGROUP_CONFIGS_PROPERTY_ID, configSet); + properties.put(ConfigGroupResourceProvider.CONFIGGROUP_SERVICEGROUPNAME_PROPERTY_ID, SERVICE_GROUP_NAME); + properties.put(ConfigGroupResourceProvider.CONFIGGROUP_SERVICENAME_PROPERTY_ID, SERVICE_NAME); propertySet.add(properties); diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java index 1296be9..062389a 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/ConfigGroupTest.java @@ -27,11 +27,17 @@ import org.apache.ambari.server.H2DatabaseCleaner; import org.apache.ambari.server.orm.GuiceJpaInitializer; import org.apache.ambari.server.orm.InMemoryDefaultTestModule; import org.apache.ambari.server.orm.OrmTestHelper; +import org.apache.ambari.server.orm.dao.ClusterDAO; +import org.apache.ambari.server.orm.dao.ClusterServiceDAO; import org.apache.ambari.server.orm.dao.ConfigGroupDAO; import org.apache.ambari.server.orm.dao.ConfigGroupHostMappingDAO; +import org.apache.ambari.server.orm.dao.ServiceGroupDAO; +import org.apache.ambari.server.orm.entities.ClusterEntity; +import org.apache.ambari.server.orm.entities.ClusterServiceEntity; import org.apache.ambari.server.orm.entities.ConfigGroupConfigMappingEntity; import org.apache.ambari.server.orm.entities.ConfigGroupEntity; import org.apache.ambari.server.orm.entities.ConfigGroupHostMappingEntity; +import org.apache.ambari.server.orm.entities.ServiceGroupEntity; import org.apache.ambari.server.state.configgroup.ConfigGroup; import org.apache.ambari.server.state.configgroup.ConfigGroupFactory; import org.junit.After; @@ -54,6 +60,9 @@ public class ConfigGroupTest { private ConfigFactory configFactory; private ConfigGroupDAO configGroupDAO; private ConfigGroupHostMappingDAO configGroupHostMappingDAO; + private ClusterDAO clusterDAO; + private ClusterServiceDAO clusterServiceDAO; + private ServiceGroupDAO serviceGroupDAO; @Before public void setup() throws Exception { @@ -65,6 +74,9 @@ public class ConfigGroupTest { configGroupDAO = injector.getInstance(ConfigGroupDAO.class); configGroupHostMappingDAO = injector.getInstance (ConfigGroupHostMappingDAO.class); + clusterServiceDAO = injector.getInstance(ClusterServiceDAO.class); + clusterDAO = injector.getInstance(ClusterDAO.class); + serviceGroupDAO = injector.getInstance(ServiceGroupDAO.class); StackId stackId = new StackId("HDP-0.1"); OrmTestHelper helper = injector.getInstance(OrmTestHelper.class); @@ -105,7 +117,21 @@ public class ConfigGroupTest { configs.put(config.getType(), config); hosts.put(host.getHostId(), host); - ConfigGroup configGroup = configGroupFactory.createNew(cluster, 1L, 1L, "HDFS", "", "New HDFS configs for h1", configs, hosts); + ClusterEntity clusterEntity = clusterDAO.findByName("foo"); + + ServiceGroupEntity serviceGroupEntity = new ServiceGroupEntity(); + serviceGroupEntity.setClusterEntity(clusterEntity); + serviceGroupEntity.setServiceGroupName("default"); + serviceGroupDAO.create(serviceGroupEntity); + + ClusterServiceEntity clusterServiceEntity = new ClusterServiceEntity(); + clusterServiceEntity.setClusterEntity(clusterEntity); + clusterServiceEntity.setServiceGroupEntity(serviceGroupEntity); + clusterServiceEntity.setServiceName("HDFS"); + clusterServiceEntity.setServiceType("HDFS"); + clusterServiceDAO.create(clusterServiceEntity); + + ConfigGroup configGroup = configGroupFactory.createNew(cluster, 1L, clusterServiceEntity.getServiceId(), "cg-test", "HDFS", "New HDFS configs for h1", configs, hosts); cluster.addConfigGroup(configGroup); return configGroup; -- To stop receiving notification emails like this one, please contact beny...@apache.org.