http://git-wip-us.apache.org/repos/asf/ambari/blob/56362fd6/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
----------------------------------------------------------------------
diff --git
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
index dbfee41..5b4987e 100644
---
a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
+++
b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerImplTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -73,9 +73,7 @@ import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.internal.RequestStageContainer;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
-import org.apache.ambari.server.orm.entities.ClusterVersionEntity;
import org.apache.ambari.server.orm.entities.LdapSyncSpecEntity;
import org.apache.ambari.server.orm.entities.RepositoryVersionEntity;
import org.apache.ambari.server.security.authorization.Users;
@@ -94,7 +92,6 @@ import org.apache.ambari.server.state.Host;
import org.apache.ambari.server.state.MaintenanceState;
import org.apache.ambari.server.state.PropertyInfo;
import org.apache.ambari.server.state.RepositoryInfo;
-import org.apache.ambari.server.state.RepositoryVersionState;
import org.apache.ambari.server.state.SecurityType;
import org.apache.ambari.server.state.Service;
import org.apache.ambari.server.state.ServiceComponent;
@@ -114,6 +111,7 @@ import org.junit.Test;
import org.springframework.security.core.context.SecurityContextHolder;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.inject.Binder;
@@ -154,7 +152,7 @@ public class AmbariManagementControllerImplTest {
public void testgetAmbariServerURI() throws Exception {
// create mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
// set expectations
injector.injectMembers(capture(controllerCapture));
@@ -224,13 +222,13 @@ public class AmbariManagementControllerImplTest {
public void testGetClusters() throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
ClusterRequest request1 = new ClusterRequest(null, "cluster1", "1",
Collections.<String>emptySet());
Cluster cluster = createNiceMock(Cluster.class);
ClusterResponse response = createNiceMock(ClusterResponse.class);
- Set<ClusterRequest> setRequests = new HashSet<ClusterRequest>();
+ Set<ClusterRequest> setRequests = new HashSet<>();
setRequests.add(request1);
// expectations
@@ -290,7 +288,7 @@ public class AmbariManagementControllerImplTest {
Cluster cluster = createNiceMock(Cluster.class);
Service service = createNiceMock(Service.class);
ServiceComponent component = createNiceMock(ServiceComponent.class);
- Map<String, ServiceComponentHost> hostMap = new HashMap<String,
ServiceComponentHost>();
+ Map<String, ServiceComponentHost> hostMap = new HashMap<>();
expect(component.getServiceComponentHosts()).andReturn(hostMap);
replay(cluster, service, component, injector);
@@ -344,7 +342,7 @@ public class AmbariManagementControllerImplTest {
expect(service.getName()).andReturn("service");
expect(service.getServiceComponent("component")).andReturn(component);
- expect(service.getDesiredStackVersion()).andReturn(stackId);
+ expect(service.getDesiredStackId()).andReturn(stackId);
expect(stackId.getStackName()).andReturn("stack");
expect(stackId.getStackVersion()).andReturn("1.0");
@@ -378,14 +376,14 @@ public class AmbariManagementControllerImplTest {
expect(service.getName()).andReturn("service");
expect(service.getServiceComponent("component")).andThrow(
new ServiceComponentNotFoundException("cluster", "service",
"component"));
- expect(service.getDesiredStackVersion()).andReturn(stackId);
+ expect(service.getDesiredStackId()).andReturn(stackId);
expect(stackId.getStackName()).andReturn("stack");
expect(stackId.getStackVersion()).andReturn("1.0");
- Map<String, ServiceComponent> componentsMap = new HashMap<String,
ServiceComponent>();
+ Map<String, ServiceComponent> componentsMap = new HashMap<>();
componentsMap.put("component1", component1);
componentsMap.put("component2", component2);
expect(service.getServiceComponents()).andReturn(componentsMap);
-
expect(component1.getServiceComponentHosts()).andReturn(Collections.EMPTY_MAP);
+
expect(component1.getServiceComponentHosts()).andReturn(Collections.<String,
ServiceComponentHost>emptyMap());
expect(component2.getServiceComponentHosts()).andReturn(
Collections.<String, ServiceComponentHost>singletonMap("anyHost", null));
@@ -416,14 +414,14 @@ public class AmbariManagementControllerImplTest {
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
expect(service.getName()).andReturn("service");
- expect(service.getDesiredStackVersion()).andReturn(stackId);
+ expect(service.getDesiredStackId()).andReturn(stackId);
expect(stackId.getStackName()).andReturn("stack");
expect(stackId.getStackVersion()).andReturn("1.0");
- Map<String, ServiceComponent> componentsMap = new HashMap<String,
ServiceComponent>();
+ Map<String, ServiceComponent> componentsMap = new HashMap<>();
componentsMap.put("component1", component1);
componentsMap.put("component2", component2);
expect(service.getServiceComponents()).andReturn(componentsMap);
-
expect(component1.getServiceComponentHosts()).andReturn(Collections.EMPTY_MAP);
+
expect(component1.getServiceComponentHosts()).andReturn(Collections.<String,
ServiceComponentHost>emptyMap());
expect(component2.getServiceComponentHosts()).andReturn(
Collections.<String, ServiceComponentHost>singletonMap("anyHost", null));
@@ -449,12 +447,12 @@ public class AmbariManagementControllerImplTest {
public void testGetClusters___ClusterNotFoundException() throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
// requests
ClusterRequest request1 = new ClusterRequest(null, "cluster1", "1",
Collections.<String>emptySet());
- Set<ClusterRequest> setRequests = new HashSet<ClusterRequest>();
+ Set<ClusterRequest> setRequests = new HashSet<>();
setRequests.add(request1);
// expectations
@@ -492,7 +490,7 @@ public class AmbariManagementControllerImplTest {
public void testGetClusters___OR_Predicate_ClusterNotFoundException() throws
Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Cluster cluster = createNiceMock(Cluster.class);
Cluster cluster2 = createNiceMock(Cluster.class);
@@ -505,7 +503,7 @@ public class AmbariManagementControllerImplTest {
ClusterRequest request3 = new ClusterRequest(null, "cluster3", "1",
Collections.<String>emptySet());
ClusterRequest request4 = new ClusterRequest(null, "cluster4", "1",
Collections.<String>emptySet());
- Set<ClusterRequest> setRequests = new HashSet<ClusterRequest>();
+ Set<ClusterRequest> setRequests = new HashSet<>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
@@ -558,14 +556,19 @@ public class AmbariManagementControllerImplTest {
@Test
public void testUpdateClusters() throws Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createNiceMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
ClusterRequest clusterRequest = createNiceMock(ClusterRequest.class);
+ ConfigurationRequest configurationRequest =
createNiceMock(ConfigurationRequest.class);
// requests
- Set<ClusterRequest> setRequests = Collections.singleton(clusterRequest);
+ Set<ClusterRequest> setRequests = new HashSet<ClusterRequest>();
+ setRequests.add(clusterRequest);
+
+ List<ConfigurationRequest> configRequests = new ArrayList<>();
+ configRequests.add(configurationRequest);
KerberosHelper kerberosHelper = createStrictMock(KerberosHelper.class);
// expectations
@@ -575,17 +578,22 @@ public class AmbariManagementControllerImplTest {
expect(injector.getInstance(KerberosHelper.class)).andReturn(kerberosHelper);
expect(clusterRequest.getClusterName()).andReturn("clusterNew").times(3);
expect(clusterRequest.getClusterId()).andReturn(1L).times(6);
+ expect(clusterRequest.getDesiredConfig()).andReturn(configRequests);
+ expect(configurationRequest.getVersionTag()).andReturn(null).times(1);
expect(clusters.getClusterById(1L)).andReturn(cluster).times(2);
expect(cluster.getClusterName()).andReturn("clusterOld").times(1);
- cluster.addSessionAttributes(anyObject(Map.class));
+ cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
expectLastCall().once();
cluster.setClusterName("clusterNew");
expectLastCall();
+ configurationRequest.setVersionTag(EasyMock.anyObject(String.class));
+ expectLastCall();
+
// replay mocks
- replay(actionManager, cluster, clusters, injector, clusterRequest,
sessionManager);
+ replay(actionManager, cluster, clusters, injector, clusterRequest,
sessionManager, configurationRequest);
// test
AmbariManagementController controller = new
AmbariManagementControllerImpl(actionManager, clusters, injector);
@@ -593,7 +601,7 @@ public class AmbariManagementControllerImplTest {
// assert and verify
assertSame(controller, controllerCapture.getValue());
- verify(actionManager, cluster, clusters, injector, clusterRequest,
sessionManager);
+ verify(actionManager, cluster, clusters, injector, clusterRequest,
sessionManager, configurationRequest);
}
/**
@@ -607,7 +615,7 @@ public class AmbariManagementControllerImplTest {
@Ignore
public void testUpdateClustersWithNullConfigPropertyValues() throws
Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createNiceMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -641,7 +649,7 @@ public class AmbariManagementControllerImplTest {
expect(config.getPropertiesAttributes()).andReturn(new
HashMap<String,Map<String,String>>()).anyTimes();
expect(cluster.getDesiredConfigByType(anyObject(String.class))).andReturn(config).anyTimes();
- cluster.addSessionAttributes(anyObject(Map.class));
+ cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
expectLastCall().once();
cluster.setClusterName("clusterNew");
@@ -666,7 +674,7 @@ public class AmbariManagementControllerImplTest {
@Test
public void testUpdateClustersToggleKerberosNotInvoked() throws Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createNiceMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -685,7 +693,7 @@ public class AmbariManagementControllerImplTest {
expect(clusters.getClusterById(1L)).andReturn(cluster).times(2);
expect(cluster.getClusterName()).andReturn("cluster").times(1);
- cluster.addSessionAttributes(anyObject(Map.class));
+ cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
expectLastCall().once();
// replay mocks
@@ -708,7 +716,7 @@ public class AmbariManagementControllerImplTest {
@Test
public void testUpdateClustersToggleKerberosReenable() throws Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createNiceMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -729,13 +737,13 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getClusterName()).andReturn("cluster").times(1);
expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
- cluster.addSessionAttributes(anyObject(Map.class));
+ cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
expectLastCall().once();
expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.KERBEROS,
null))
.andReturn(false)
.once();
-
expect(kerberosHelper.getForceToggleKerberosDirective(anyObject(Map.class)))
+
expect(kerberosHelper.getForceToggleKerberosDirective(EasyMock.<Map<String,
String>>anyObject()))
.andReturn(false)
.once();
// Note: kerberosHelper.toggleKerberos is not called
@@ -758,7 +766,7 @@ public class AmbariManagementControllerImplTest {
@Test
public void testUpdateClustersToggleKerberosEnable() throws Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createNiceMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -779,7 +787,7 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getClusterName()).andReturn("cluster").times(1);
expect(cluster.getSecurityType()).andReturn(SecurityType.NONE).anyTimes();
- cluster.addSessionAttributes(anyObject(Map.class));
+ cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
expectLastCall().once();
expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.KERBEROS,
null))
@@ -840,7 +848,7 @@ public class AmbariManagementControllerImplTest {
*/
private void testUpdateClustersToggleKerberosDisable(Boolean
manageIdentities) throws Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createNiceMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -849,7 +857,7 @@ public class AmbariManagementControllerImplTest {
// requests
Set<ClusterRequest> setRequests = Collections.singleton(clusterRequest);
- Capture<Boolean> manageIdentitiesCapture = new Capture<Boolean>();
+ Capture<Boolean> manageIdentitiesCapture = EasyMock.newCapture();
KerberosHelper kerberosHelper = createStrictMock(KerberosHelper.class);
// expectations
@@ -863,16 +871,16 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getClusterName()).andReturn("cluster").times(1);
expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
- cluster.addSessionAttributes(anyObject(Map.class));
+ cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
expectLastCall().once();
expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.NONE,
null))
.andReturn(false)
.once();
-
expect(kerberosHelper.getForceToggleKerberosDirective(anyObject(Map.class)))
+
expect(kerberosHelper.getForceToggleKerberosDirective(EasyMock.<Map<String,
String>>anyObject()))
.andReturn(false)
.once();
- expect(kerberosHelper.getManageIdentitiesDirective(anyObject(Map.class)))
+ expect(kerberosHelper.getManageIdentitiesDirective(EasyMock.<Map<String,
String>>anyObject()))
.andReturn(manageIdentities)
.once();
expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class),
anyObject(SecurityType.class), anyObject(RequestStageContainer.class),
captureBoolean(manageIdentitiesCapture)))
@@ -899,7 +907,7 @@ public class AmbariManagementControllerImplTest {
@Test
public void testUpdateClustersToggleKerberos_Fail() throws Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -920,7 +928,6 @@ public class AmbariManagementControllerImplTest {
expect(cluster.getResourceId()).andReturn(1L).times(3);
expect(cluster.getClusterName()).andReturn("cluster").times(1);
expect(cluster.getSecurityType()).andReturn(SecurityType.KERBEROS).anyTimes();
- expect(cluster.getCurrentClusterVersion()).andReturn(null).anyTimes();
expect(cluster.getCurrentStackVersion()).andReturn(null).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(null).anyTimes();
@@ -930,16 +937,16 @@ public class AmbariManagementControllerImplTest {
cluster.setClusterName(anyObject(String.class));
expectLastCall().once();
- cluster.addSessionAttributes(anyObject(Map.class));
+ cluster.addSessionAttributes(EasyMock.<Map<String, Object>>anyObject());
expectLastCall().once();
expect(kerberosHelper.shouldExecuteCustomOperations(SecurityType.NONE,
null))
.andReturn(false)
.once();
-
expect(kerberosHelper.getForceToggleKerberosDirective(anyObject(Map.class)))
+
expect(kerberosHelper.getForceToggleKerberosDirective(EasyMock.<Map<String,
String>>anyObject()))
.andReturn(false)
.once();
- expect(kerberosHelper.getManageIdentitiesDirective(anyObject(Map.class)))
+ expect(kerberosHelper.getManageIdentitiesDirective(EasyMock.<Map<String,
String>>anyObject()))
.andReturn(null)
.once();
expect(kerberosHelper.toggleKerberos(anyObject(Cluster.class),
anyObject(SecurityType.class), anyObject(RequestStageContainer.class),
anyBoolean()))
@@ -971,7 +978,7 @@ public class AmbariManagementControllerImplTest {
@Test
public void testUpdateClusters__RollbackException() throws Exception {
// member state mocks
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
Cluster cluster = createNiceMock(Cluster.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
@@ -1012,7 +1019,7 @@ public class AmbariManagementControllerImplTest {
public void testGetHostComponents() throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1029,7 +1036,7 @@ public class AmbariManagementControllerImplTest {
ServiceComponentHostRequest request1 = new ServiceComponentHostRequest(
"cluster1", null, "component1", "host1", null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
// expectations
@@ -1048,13 +1055,10 @@ public class AmbariManagementControllerImplTest {
put("host1", host);
}}).anyTimes();
- expect(cluster.getDesiredStackVersion()).andReturn(stack);
- expect(stack.getStackName()).andReturn("stackName");
- expect(stack.getStackVersion()).andReturn("stackVersion");
-
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
+ expect(service.getName()).andReturn("service1");
expect(component.getName()).andReturn("component1");
expect(component.getServiceComponentHosts()).andReturn(
new HashMap<String, ServiceComponentHost>() {{
@@ -1086,7 +1090,7 @@ public class AmbariManagementControllerImplTest {
public void testGetHostComponents___ServiceComponentHostNotFoundException()
throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1100,7 +1104,7 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component1", "host1", null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
// expectations
@@ -1114,13 +1118,15 @@ public class AmbariManagementControllerImplTest {
expect(clusters.getCluster("cluster1")).andReturn(cluster);
expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster));
- expect(cluster.getDesiredStackVersion()).andReturn(stack);
- expect(stack.getStackName()).andReturn("stackName");
- expect(stack.getStackVersion()).andReturn("stackVersion");
-
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
+// expect(cluster.getDesiredStackVersion()).andReturn(stack);
+// expect(stack.getStackName()).andReturn("stackName");
+// expect(stack.getStackVersion()).andReturn("stackVersion");
+//
+// expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
+ expect(service.getName()).andReturn("service1");
expect(component.getName()).andReturn("component1").anyTimes();
expect(component.getServiceComponentHosts()).andReturn(null);
@@ -1148,7 +1154,7 @@ public class AmbariManagementControllerImplTest {
public void testGetHostComponents___ServiceComponentHostFilteredByState()
throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1165,7 +1171,7 @@ public class AmbariManagementControllerImplTest {
request1.setState("INSTALLED");
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
// expectations
@@ -1186,14 +1192,16 @@ public class AmbariManagementControllerImplTest {
put("host1", host);
}}).anyTimes();
- expect(cluster.getDesiredStackVersion()).andReturn(stack);
+// expect(cluster.getDesiredStackVersion()).andReturn(stack);
+// expect(stack.getStackName()).andReturn("stackName");
+// expect(stack.getStackVersion()).andReturn("stackVersion");
+//
+// expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getClusterName()).andReturn("cl1");
- expect(stack.getStackName()).andReturn("stackName");
- expect(stack.getStackVersion()).andReturn("stackVersion");
-
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
+ expect(service.getName()).andReturn("service1");
expect(component.getName()).andReturn("component1").anyTimes();
expect(component.getServiceComponentHosts()).andReturn(new HashMap<String,
ServiceComponentHost>() {{
put("host1", componentHost1);
@@ -1223,7 +1231,7 @@ public class AmbariManagementControllerImplTest {
public void
testGetHostComponents___ServiceComponentHostFilteredByMaintenanceState() throws
Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1240,7 +1248,7 @@ public class AmbariManagementControllerImplTest {
request1.setMaintenanceState("ON");
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
// expectations
@@ -1261,14 +1269,11 @@ public class AmbariManagementControllerImplTest {
put("host1", host);
}}).anyTimes();
- expect(cluster.getDesiredStackVersion()).andReturn(stack);
expect(cluster.getClusterName()).andReturn("cl1");
- expect(stack.getStackName()).andReturn("stackName");
- expect(stack.getStackVersion()).andReturn("stackVersion");
-
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
+ expect(service.getName()).andReturn("service1");
expect(component.getName()).andReturn("component1").anyTimes();
expect(component.getServiceComponentHosts()).andReturn(new HashMap<String,
ServiceComponentHost>() {{
put("host1", componentHost1);
@@ -1297,13 +1302,13 @@ public class AmbariManagementControllerImplTest {
public void
testGetHostComponents___OR_Predicate_ServiceComponentHostNotFoundException()
throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
final Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
- ServiceComponent component = createNiceMock(ServiceComponent.class);
+ ServiceComponent component1 = createNiceMock(ServiceComponent.class);
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
ServiceComponent component3 = createNiceMock(ServiceComponent.class);
@@ -1332,7 +1337,7 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component3", "host1", null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
@@ -1350,27 +1355,24 @@ public class AmbariManagementControllerImplTest {
expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
expect(cluster.getService("service1")).andReturn(service).times(3);
- expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
- expect(stack.getStackName()).andReturn("stackName").anyTimes();
- expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
-
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
- expect(service.getServiceComponent("component1")).andReturn(component);
- expect(component.getName()).andReturn("component1");
- expect(component.getServiceComponentHosts()).andReturn(
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+ expect(service.getServiceComponent("component1")).andReturn(component1);
+ expect(service.getName()).andReturn("service1").anyTimes();
+ expect(component1.getName()).andReturn("component1");
+ expect(component1.getServiceComponentHosts()).andReturn(
new HashMap<String, ServiceComponentHost>() {{
put("host1", componentHost1);
}});
expect(componentHost1.convertToResponse(null)).andReturn(response1);
expect(componentHost1.getHostName()).andReturn("host1");
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component2")).andReturn("service1");
+ expect(cluster.getServiceByComponentName("component2")).andReturn(service);
expect(service.getServiceComponent("component2")).andReturn(component2);
expect(component2.getName()).andReturn("component2");
expect(component2.getServiceComponentHosts()).andReturn(null);
expect(componentHost2.getHostName()).andReturn("host1");
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component3")).andReturn("service1");
+ expect(cluster.getServiceByComponentName("component3")).andReturn(service);
expect(service.getServiceComponent("component3")).andReturn(component3);
expect(component3.getName()).andReturn("component3");
expect(component3.getServiceComponentHosts()).andReturn(
@@ -1381,7 +1383,7 @@ public class AmbariManagementControllerImplTest {
// replay mocks
replay(stateHelper, injector, clusters, cluster, host, stack,
- ambariMetaInfo, service, component, component2, component3,
componentHost1,
+ ambariMetaInfo, service, component1, component2, component3,
componentHost1,
componentHost2, response1, response2);
//test
@@ -1396,7 +1398,7 @@ public class AmbariManagementControllerImplTest {
assertTrue(setResponses.contains(response1));
assertTrue(setResponses.contains(response2));
- verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service,
component, component2, component3,
+ verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service,
component1, component2, component3,
componentHost1, componentHost2, response1, response2);
}
@@ -1404,13 +1406,13 @@ public class AmbariManagementControllerImplTest {
public void testGetHostComponents___OR_Predicate_ServiceNotFoundException()
throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
final Host host = createNiceMock(Host.class);
Service service = createNiceMock(Service.class);
- ServiceComponent component = createNiceMock(ServiceComponent.class);
+ ServiceComponent component1 = createNiceMock(ServiceComponent.class);
ServiceComponent component2 = createNiceMock(ServiceComponent.class);
ServiceComponent component3 = createNiceMock(ServiceComponent.class);
@@ -1434,7 +1436,7 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component3", "host1", null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
@@ -1457,22 +1459,23 @@ public class AmbariManagementControllerImplTest {
put("host1", host);
}}).anyTimes();
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
+// expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
- expect(service.getServiceComponent("component1")).andReturn(component);
- expect(component.getName()).andReturn("component1");
- expect(component.getServiceComponentHosts()).andReturn(new
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+ expect(service.getName()).andReturn("service1").atLeastOnce();
+ expect(service.getServiceComponent("component1")).andReturn(component1);
+ expect(component1.getName()).andReturn("component1");
+ expect(component1.getServiceComponentHosts()).andReturn(new
HashMap<String,
ServiceComponentHost>() {{
put("host1",
componentHost1);
}});
expect(componentHost1.convertToResponse(null)).andReturn(response1);
expect(componentHost1.getHostName()).andReturn("host1");
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component2")).andReturn("service2");
- expect(cluster.getService("service2")).andThrow(new
ServiceNotFoundException("cluster1", "service2"));
+ expect(cluster.getServiceByComponentName("component2")).andThrow(new
ServiceNotFoundException("cluster1", "service2"));
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component3")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component3")).andReturn(service);
expect(service.getServiceComponent("component3")).andReturn(component3);
expect(component3.getName()).andReturn("component3");
expect(component3.getServiceComponentHosts()).andReturn(new
@@ -1484,7 +1487,7 @@ public class AmbariManagementControllerImplTest {
// replay mocks
replay(maintHelper, injector, clusters, cluster, host, stack,
ambariMetaInfo,
- service, component, component2, component3, componentHost1,
+ service, component1, component2, component3, componentHost1,
componentHost2, response1, response2);
//test
@@ -1499,7 +1502,7 @@ public class AmbariManagementControllerImplTest {
assertTrue(setResponses.contains(response1));
assertTrue(setResponses.contains(response2));
- verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service,
component, component2, component3,
+ verify(injector, clusters, cluster, host, stack, ambariMetaInfo, service,
component1, component2, component3,
componentHost1, componentHost2, response1, response2);
}
@@ -1507,7 +1510,7 @@ public class AmbariManagementControllerImplTest {
public void
testGetHostComponents___OR_Predicate_ServiceComponentNotFoundException() throws
Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1539,7 +1542,7 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component3", "host1", null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
@@ -1554,39 +1557,42 @@ public class AmbariManagementControllerImplTest {
// getHostComponent
expect(clusters.getCluster("cluster1")).andReturn(cluster).times(3);
expect(clusters.getClustersForHost("host1")).andReturn(Collections.singleton(cluster)).anyTimes();
- expect(clusters.getHostsForCluster((String) anyObject())).andReturn(
- new HashMap<String, Host>() {{
- put("host1", host);
- }}).anyTimes();
+ expect(clusters.getHostsForCluster((String)
anyObject())).andReturn(ImmutableMap.<String, Host>builder()
+ .put("host1", host)
+ .build()).anyTimes();
expect(cluster.getDesiredStackVersion()).andReturn(stack).anyTimes();
expect(stack.getStackName()).andReturn("stackName").anyTimes();
expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
+// expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
+ expect(service.getName()).andReturn("service1").anyTimes();
expect(component.getName()).andReturn("component1");
- expect(component.getServiceComponentHosts()).andReturn(
- new HashMap<String, ServiceComponentHost>() {{
- put("host1", componentHost1);
- }});
+
expect(component.getServiceComponentHosts()).andReturn(ImmutableMap.<String,
ServiceComponentHost>builder()
+ .put("host1", componentHost1)
+ .build());
expect(componentHost1.convertToResponse(null)).andReturn(response1);
expect(componentHost1.getHostName()).andReturn("host1");
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component2")).andReturn("service2");
+// expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component2")).andReturn("service2");
expect(cluster.getService("service2")).andReturn(service2);
+
expect(cluster.getServiceByComponentName("component2")).andReturn(service2);
+ expect(service2.getName()).andReturn("service2");
expect(service2.getServiceComponent("component2")).
andThrow(new ServiceComponentNotFoundException("cluster1", "service2",
"component2"));
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component3")).andReturn("service1");
+// expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component3")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component3")).andReturn(service);
expect(service.getServiceComponent("component3")).andReturn(component3);
+
expect(component3.getName()).andReturn("component3");
- expect(component3.getServiceComponentHosts()).andReturn(
- new HashMap<String, ServiceComponentHost>() {{
- put("host1", componentHost2);
- }});
+
expect(component3.getServiceComponentHosts()).andReturn(ImmutableMap.<String,
ServiceComponentHost>builder()
+ .put("host1", componentHost2)
+ .build());
expect(componentHost2.convertToResponse(null)).andReturn(response2);
expect(componentHost2.getHostName()).andReturn("host1");
@@ -1615,7 +1621,7 @@ public class AmbariManagementControllerImplTest {
public void
testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvidedInQuery()
throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1646,7 +1652,7 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component3", null, null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
@@ -1669,9 +1675,10 @@ public class AmbariManagementControllerImplTest {
expect(stack.getStackName()).andReturn("stackName").anyTimes();
expect(stack.getStackVersion()).andReturn("stackVersion").anyTimes();
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
expect(service.getServiceComponent("component1")).andReturn(component);
+ expect(service.getName()).andReturn("service1").anyTimes();
expect(component.getName()).andReturn("component1");
expect(component.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo",
componentHost1));
expect(componentHost1.convertToResponse(null)).andReturn(response1);
@@ -1679,8 +1686,8 @@ public class AmbariManagementControllerImplTest {
expect(clusters.getClustersForHost("host2")).andThrow(new
HostNotFoundException("host2"));
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component3")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
+ expect(cluster.getServiceByComponentName("component3")).andReturn(service);
expect(service.getServiceComponent("component3")).andReturn(component3);
expect(component3.getName()).andReturn("component3");
expect(component3.getServiceComponentHosts()).andReturn(Collections.singletonMap("foo",
componentHost2));
@@ -1713,7 +1720,7 @@ public class AmbariManagementControllerImplTest {
public void
testGetHostComponents___OR_Predicate_HostNotFoundException_hostProvidedInURL()
throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
MaintenanceStateHelper maintHelper =
createNiceMock(MaintenanceStateHelper.class);
@@ -1730,7 +1737,7 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component3", "host1", null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
@@ -1770,7 +1777,7 @@ public class AmbariManagementControllerImplTest {
public void testGetHostComponents___OR_Predicate_ClusterNotFoundException()
throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
MaintenanceStateHelper maintHelper =
createNiceMock(MaintenanceStateHelper.class);
@@ -1785,7 +1792,7 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component3", "host1", null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
setRequests.add(request2);
setRequests.add(request3);
@@ -1824,7 +1831,7 @@ public class AmbariManagementControllerImplTest {
public void testGetHostComponents___NullHostName() throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1844,10 +1851,10 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, "component1", null, null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
- Map<String, ServiceComponentHost> mapHostComponents = new HashMap<String,
ServiceComponentHost>();
+ Map<String, ServiceComponentHost> mapHostComponents = new HashMap<>();
mapHostComponents.put("foo", componentHost1);
mapHostComponents.put("bar", componentHost2);
@@ -1865,15 +1872,12 @@ public class AmbariManagementControllerImplTest {
new HashMap<String, Host>() {{
put("host1", createNiceMock(Host.class));
}}).anyTimes();
- expect(cluster.getDesiredStackVersion()).andReturn(stack);
- expect(stack.getStackName()).andReturn("stackName");
- expect(stack.getStackVersion()).andReturn("stackVersion");
- expect(ambariMetaInfo.getComponentToService("stackName", "stackVersion",
"component1")).andReturn("service1");
expect(cluster.getService("service1")).andReturn(service);
- expect(service.getServiceComponent("component1")).andReturn(component);
expect(component.getName()).andReturn("component1").anyTimes();
-
+ expect(cluster.getServiceByComponentName("component1")).andReturn(service);
+ expect(service.getServiceComponent("component1")).andReturn(component);
+ expect(service.getName()).andReturn("service1");
expect(component.getServiceComponentHosts()).andReturn(mapHostComponents);
expect(componentHost1.convertToResponse(null)).andReturn(response1);
expect(componentHost2.convertToResponse(null)).andReturn(response2);
@@ -1903,7 +1907,7 @@ public class AmbariManagementControllerImplTest {
public void testGetHostComponents___NullHostName_NullComponentName() throws
Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
StackId stack = createNiceMock(StackId.class);
Cluster cluster = createNiceMock(Cluster.class);
@@ -1927,14 +1931,14 @@ public class AmbariManagementControllerImplTest {
"cluster1", null, null, null, null);
- Set<ServiceComponentHostRequest> setRequests = new
HashSet<ServiceComponentHostRequest>();
+ Set<ServiceComponentHostRequest> setRequests = new HashSet<>();
setRequests.add(request1);
- Map<String, Service> mapServices = new HashMap<String, Service>();
+ Map<String, Service> mapServices = new HashMap<>();
mapServices.put("foo", service1);
mapServices.put("bar", service2);
- Map<String, ServiceComponentHost> mapHostComponents = new HashMap<String,
ServiceComponentHost>();
+ Map<String, ServiceComponentHost> mapHostComponents = new HashMap<>();
mapHostComponents.put("foo", componentHost1);
mapHostComponents.put("bar", componentHost2);
@@ -1994,15 +1998,15 @@ public class AmbariManagementControllerImplTest {
@Test
public void testPopulateServicePackagesInfo() throws Exception {
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
Injector injector = createStrictMock(Injector.class);
MaintenanceStateHelper maintHelper =
createNiceMock(MaintenanceStateHelper.class);
ServiceInfo serviceInfo = createNiceMock(ServiceInfo.class);
- Map<String, String> hostParams = new HashMap<String, String>();
+ Map<String, String> hostParams = new HashMap<>();
String osFamily = "testOSFamily";
- Map<String, ServiceOsSpecific> osSpecifics = new HashMap<String,
ServiceOsSpecific>();
+ Map<String, ServiceOsSpecific> osSpecifics = new HashMap<>();
ServiceOsSpecific.Package package1 = new ServiceOsSpecific.Package();
package1.setName("testrpm1");
@@ -2011,9 +2015,9 @@ public class AmbariManagementControllerImplTest {
ServiceOsSpecific.Package package3 = new ServiceOsSpecific.Package();
package3.setName("testrpm3");
- List<ServiceOsSpecific.Package> packageList1 = new
ArrayList<ServiceOsSpecific.Package>();
+ List<ServiceOsSpecific.Package> packageList1 = new ArrayList<>();
packageList1.add(package1);
- List<ServiceOsSpecific.Package> packageList2 = new
ArrayList<ServiceOsSpecific.Package>();
+ List<ServiceOsSpecific.Package> packageList2 = new ArrayList<>();
packageList2.add(package2);
packageList2.add(package3);
@@ -2033,7 +2037,7 @@ public class AmbariManagementControllerImplTest {
OsFamily osFamilyMock = createNiceMock(OsFamily.class);
-
EasyMock.expect(osFamilyMock.isVersionedOsFamilyExtendedByVersionedFamily("testOSFamily",
"testOSFamily")).andReturn(true).times(3);
+
EasyMock.expect(osFamilyMock.isVersionedOsFamilyExtendedByVersionedFamily("testOSFamily",
"testOSFamily")).andReturn(true).times(3);
replay(maintHelper, injector, clusters, serviceInfo, osFamilyMock);
AmbariManagementControllerImplTest.NestedTestClass nestedTestClass =
this.new NestedTestClass(null, clusters,
@@ -2055,6 +2059,14 @@ public class AmbariManagementControllerImplTest {
String JCE_NAME = "jceName";
String OJDBC_JAR_NAME = "OjdbcJarName";
String SERVER_DB_NAME = "ServerDBName";
+ Map<PropertyInfo, String> notManagedHdfsPathMap = new HashMap<>();
+ PropertyInfo propertyInfo1 = new PropertyInfo();
+ propertyInfo1.setName("1");
+ PropertyInfo propertyInfo2 = new PropertyInfo();
+ propertyInfo2.setName("2");
+ notManagedHdfsPathMap.put(propertyInfo1, "/tmp");
+ notManagedHdfsPathMap.put(propertyInfo2, "/apps/falcon");
+
Set<String> notManagedHdfsPathSet = new HashSet<>(Arrays.asList("/tmp",
"/apps/falcon"));
Gson gson = new Gson();
@@ -2063,8 +2075,6 @@ public class AmbariManagementControllerImplTest {
Cluster cluster = createNiceMock(Cluster.class);
Injector injector = createNiceMock(Injector.class);
Configuration configuration = createNiceMock(Configuration.class);
- ClusterVersionDAO clusterVersionDAO =
createNiceMock(ClusterVersionDAO.class);
- ClusterVersionEntity clusterVersionEntity =
createNiceMock(ClusterVersionEntity.class);
RepositoryVersionEntity repositoryVersionEntity =
createNiceMock(RepositoryVersionEntity.class);
ConfigHelper configHelper = createNiceMock(ConfigHelper.class);
@@ -2085,15 +2095,15 @@ public class AmbariManagementControllerImplTest {
expect(configuration.areHostsSysPrepped()).andReturn("true");
expect(configuration.getDatabaseConnectorNames()).andReturn(new
HashMap<String, String>()).anyTimes();
expect(configuration.getPreviousDatabaseConnectorNames()).andReturn(new
HashMap<String, String>()).anyTimes();
-
expect(clusterVersionDAO.findByClusterAndStateCurrent(clusterName)).andReturn(clusterVersionEntity).anyTimes();
-
expect(clusterVersionEntity.getRepositoryVersion()).andReturn(repositoryVersionEntity).anyTimes();
expect(repositoryVersionEntity.getVersion()).andReturn("1234").anyTimes();
- expect(configHelper.getPropertyValuesWithPropertyType(stackId,
+ expect(repositoryVersionEntity.getStackId()).andReturn(stackId).anyTimes();
+ expect(configHelper.getPropertiesWithPropertyType(stackId,
PropertyInfo.PropertyType.NOT_MANAGED_HDFS_PATH, cluster,
desiredConfigs)).andReturn(
+ notManagedHdfsPathMap);
+ expect(configHelper.filterInvalidPropertyValues(notManagedHdfsPathMap,
NOT_MANAGED_HDFS_PATH_LIST)).andReturn(
notManagedHdfsPathSet);
- replay(manager, clusters, cluster, injector, stackId, configuration,
clusterVersionDAO, clusterVersionEntity,
- repositoryVersionEntity, configHelper);
+ replay(manager, clusters, cluster, injector, stackId, configuration,
repositoryVersionEntity, configHelper);
AmbariManagementControllerImpl ambariManagementControllerImpl =
createMockBuilder(AmbariManagementControllerImpl.class)
@@ -2120,10 +2130,6 @@ public class AmbariManagementControllerImplTest {
f.setAccessible(true);
f.set(helper, configuration);
- f = helperClass.getDeclaredField("clusterVersionDAO");
- f.setAccessible(true);
- f.set(helper, clusterVersionDAO);
-
f = helperClass.getDeclaredField("configHelper");
f.setAccessible(true);
f.set(helper, configHelper);
@@ -2132,12 +2138,12 @@ public class AmbariManagementControllerImplTest {
f.setAccessible(true);
f.set(helper, gson);
- Map<String, String> defaultHostParams =
helper.createDefaultHostParams(cluster);
+ Map<String, String> defaultHostParams =
helper.createDefaultHostParams(cluster, repositoryVersionEntity);
- assertEquals(defaultHostParams.size(), 16);
- assertEquals(defaultHostParams.get(DB_DRIVER_FILENAME), MYSQL_JAR);
- assertEquals(defaultHostParams.get(STACK_NAME), SOME_STACK_NAME);
- assertEquals(defaultHostParams.get(STACK_VERSION), SOME_STACK_VERSION);
+ assertEquals(15, defaultHostParams.size());
+ assertEquals(MYSQL_JAR, defaultHostParams.get(DB_DRIVER_FILENAME));
+ assertEquals(SOME_STACK_NAME, defaultHostParams.get(STACK_NAME));
+ assertEquals(SOME_STACK_VERSION, defaultHostParams.get(STACK_VERSION));
assertEquals("true", defaultHostParams.get(HOST_SYS_PREPPED));
assertEquals("8", defaultHostParams.get(JAVA_VERSION));
assertNotNull(defaultHostParams.get(NOT_MANAGED_HDFS_PATH_LIST));
@@ -2147,10 +2153,10 @@ public class AmbariManagementControllerImplTest {
@Test
public void testSynchronizeLdapUsersAndGroups() throws Exception {
- Set<String> userSet = new HashSet<String>();
+ Set<String> userSet = new HashSet<>();
userSet.add("user1");
- Set<String> groupSet = new HashSet<String>();
+ Set<String> groupSet = new HashSet<>();
groupSet.add("group1");
Injector injector = Guice.createInjector(Modules.override(new
InMemoryDefaultTestModule()).with(new MockModule()));
@@ -2160,7 +2166,7 @@ public class AmbariManagementControllerImplTest {
LdapBatchDto ldapBatchDto = createNiceMock(LdapBatchDto.class);
- Capture<LdapBatchDto> ldapBatchDtoCapture = new Capture<LdapBatchDto>();
+ Capture<LdapBatchDto> ldapBatchDtoCapture = EasyMock.newCapture();
// set expectations
expect(ldapDataPopulator.synchronizeAllLdapUsers(capture(ldapBatchDtoCapture))).andReturn(ldapBatchDto);
@@ -2226,10 +2232,10 @@ public class AmbariManagementControllerImplTest {
this.osFamily = osFamilyMock;
}
- public ServiceOsSpecific testPopulateServicePackagesInfo(ServiceInfo
serviceInfo, Map<String, String> hostParams,
- String osFamily) {
- return super.populateServicePackagesInfo(serviceInfo, hostParams,
osFamily);
- }
+// public ServiceOsSpecific testPopulateServicePackagesInfo(ServiceInfo
serviceInfo, Map<String, String> hostParams,
+// String
osFamily) {
+// return super.populateServicePackagesInfo(serviceInfo, hostParams,
osFamily);
+// }
}
@@ -2237,7 +2243,7 @@ public class AmbariManagementControllerImplTest {
public void testVerifyRepositories() throws Exception {
// member state mocks
Injector injector = createStrictMock(Injector.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
// expectations
// constructor init
@@ -2268,7 +2274,7 @@ public class AmbariManagementControllerImplTest {
f.setAccessible(true);
f.set(controller, configuration);
- Set<RepositoryRequest> requests = new HashSet<RepositoryRequest>();
+ Set<RepositoryRequest> requests = new HashSet<>();
RepositoryRequest request = new RepositoryRequest("stackName",
"stackVersion", "redhat6", "repoId");
request.setBaseUrl("file:///some/repo");
requests.add(request);
@@ -2293,7 +2299,7 @@ public class AmbariManagementControllerImplTest {
ServiceComponent serviceComponent = createNiceMock(ServiceComponent.class);
ServiceComponentHost serviceComponentHost =
createNiceMock(ServiceComponentHost.class);
StackId stackId = createNiceMock(StackId.class);
- Capture<AmbariManagementController> controllerCapture = new
Capture<AmbariManagementController>();
+ Capture<AmbariManagementController> controllerCapture =
EasyMock.newCapture();
// expectations
// constructor init
@@ -2306,26 +2312,27 @@ public class AmbariManagementControllerImplTest {
dummyRepoInfo.setRepoName("repo_name");
expect(clusters.getCluster("c1")).andReturn(cluster).anyTimes();
- expect(cluster.getCurrentStackVersion()).andReturn(stackId);
expect(service.getName()).andReturn("HDFS").anyTimes();
- Map<String, ServiceComponent> serviceComponents = new HashMap<String,
ServiceComponent>();
+ Map<String, ServiceComponent> serviceComponents = new HashMap<>();
serviceComponents.put("NAMENODE", serviceComponent);
expect(service.getServiceComponents()).andReturn(serviceComponents).anyTimes();
- Map<String, ServiceComponentHost> schMap = new HashMap<String,
ServiceComponentHost>();
+ Map<String, ServiceComponentHost> schMap = new HashMap<>();
schMap.put("host1", serviceComponentHost);
expect(serviceComponent.getServiceComponentHosts()).andReturn(schMap).anyTimes();
serviceComponentHost.setRestartRequired(true);
- Set<String> services = new HashSet<String>();
+ Set<String> services = new HashSet<>();
services.add("HDFS");
- expect(ambariMetaInfo.getRackSensitiveServicesNames(null,
null)).andReturn(services);
+ ServiceInfo serviceInfo = new ServiceInfo();
+ serviceInfo.setRestartRequiredAfterRackChange(true);
+ expect(ambariMetaInfo.getService(service)).andReturn(serviceInfo);
- Map<String, Service> serviceMap = new HashMap<String, Service>();
+ Map<String, Service> serviceMap = new HashMap<>();
serviceMap.put("HDFS", service);
expect(cluster.getServices()).andReturn(serviceMap).anyTimes();
@@ -2346,10 +2353,6 @@ public class AmbariManagementControllerImplTest {
public void testCreateClusterWithRepository() throws Exception {
Injector injector = createNiceMock(Injector.class);
- ClusterVersionDAO clusterVersionDAO =
createNiceMock(ClusterVersionDAO.class);
-
expect(clusterVersionDAO.findByClusterAndStackAndVersion(anyObject(String.class),
- anyObject(StackId.class),
anyObject(String.class))).andReturn(null).once();
-
RepositoryVersionEntity repoVersion =
createNiceMock(RepositoryVersionEntity.class);
RepositoryVersionDAO repoVersionDAO =
createNiceMock(RepositoryVersionDAO.class);
expect(repoVersionDAO.findByStackAndVersion(anyObject(StackId.class),
@@ -2358,23 +2361,26 @@ public class AmbariManagementControllerImplTest {
expect(injector.getInstance(MaintenanceStateHelper.class)).andReturn(null).atLeastOnce();
expect(injector.getInstance(Gson.class)).andReturn(null);
expect(injector.getInstance(KerberosHelper.class)).andReturn(createNiceMock(KerberosHelper.class));
-
expect(injector.getInstance(ClusterVersionDAO.class)).andReturn(clusterVersionDAO);
- Cluster cluster = createNiceMock(Cluster.class);
- expect(cluster.getDesiredStackVersion()).andReturn(new
StackId("HDP-2.1")).atLeastOnce();
+ StackId stackId = new StackId("HDP-2.1");
- // this getting called one time means the cluster version is getting
created
- cluster.createClusterVersion(anyObject(StackId.class),
anyObject(String.class), anyObject(String.class),
anyObject(RepositoryVersionState.class));
- expectLastCall().once();
+ Cluster cluster = createNiceMock(Cluster.class);
+ Service service = createNiceMock(Service.class);
+ expect(service.getDesiredStackId()).andReturn(stackId).atLeastOnce();
+ expect(cluster.getServices()).andReturn(ImmutableMap.<String,
Service>builder()
+ .put("HDFS", service)
+ .build());
expect(clusters.getCluster("c1")).andReturn(cluster).atLeastOnce();
+
StackInfo stackInfo = createNiceMock(StackInfo.class);
expect(stackInfo.getWidgetsDescriptorFileLocation()).andReturn(null).once();
expect(ambariMetaInfo.getStack("HDP",
"2.1")).andReturn(stackInfo).atLeastOnce();
+
expect(ambariMetaInfo.getStack(stackId)).andReturn(stackInfo).atLeastOnce();
- replay(injector, clusters, ambariMetaInfo, stackInfo, cluster,
repoVersionDAO, repoVersion, clusterVersionDAO);
+ replay(injector, clusters, ambariMetaInfo, stackInfo, cluster, service,
repoVersionDAO, repoVersion);
AmbariManagementController controller = new
AmbariManagementControllerImpl(null, clusters, injector);
setAmbariMetaInfo(ambariMetaInfo, controller);
@@ -2396,8 +2402,8 @@ public class AmbariManagementControllerImplTest {
controller.createCluster(cr);
// verification
- verify(injector, clusters, ambariMetaInfo, stackInfo, cluster,
repoVersionDAO, repoVersion, clusterVersionDAO);
+ verify(injector, clusters, ambariMetaInfo, stackInfo, cluster,
repoVersionDAO, repoVersion);
}
-}
+}
\ No newline at end of file