mirror of https://github.com/apache/cloudstack.git
refactor test mocks to use lenient behavior
This commit is contained in:
parent
cd37b81147
commit
d62b9f3b73
|
|
@ -651,7 +651,7 @@ public class KubernetesClusterManagerImplTest {
|
||||||
public void testValidateNodeAffinityGroupsAntiAffinityNewNodeOnDifferentHost() {
|
public void testValidateNodeAffinityGroupsAntiAffinityNewNodeOnDifferentHost() {
|
||||||
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
||||||
Mockito.when(cluster.getId()).thenReturn(1L);
|
Mockito.when(cluster.getId()).thenReturn(1L);
|
||||||
Mockito.when(cluster.getName()).thenReturn("test-cluster");
|
Mockito.lenient().when(cluster.getName()).thenReturn("test-cluster");
|
||||||
|
|
||||||
Long newNodeId = 100L;
|
Long newNodeId = 100L;
|
||||||
Long existingWorkerVmId = 200L;
|
Long existingWorkerVmId = 200L;
|
||||||
|
|
@ -660,7 +660,7 @@ public class KubernetesClusterManagerImplTest {
|
||||||
|
|
||||||
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
||||||
Mockito.when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
Mockito.when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
||||||
Mockito.when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
Mockito.lenient().when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
||||||
|
|
||||||
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
||||||
Mockito.when(newNode.getHostId()).thenReturn(newNodeHostId);
|
Mockito.when(newNode.getHostId()).thenReturn(newNodeHostId);
|
||||||
|
|
@ -688,7 +688,7 @@ public class KubernetesClusterManagerImplTest {
|
||||||
public void testValidateNodeAffinityGroupsAffinityNewNodeOnSameHost() {
|
public void testValidateNodeAffinityGroupsAffinityNewNodeOnSameHost() {
|
||||||
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
||||||
Mockito.when(cluster.getId()).thenReturn(1L);
|
Mockito.when(cluster.getId()).thenReturn(1L);
|
||||||
Mockito.when(cluster.getName()).thenReturn("test-cluster");
|
Mockito.lenient().when(cluster.getName()).thenReturn("test-cluster");
|
||||||
|
|
||||||
Long newNodeId = 100L;
|
Long newNodeId = 100L;
|
||||||
Long existingWorkerVmId = 200L;
|
Long existingWorkerVmId = 200L;
|
||||||
|
|
@ -696,7 +696,7 @@ public class KubernetesClusterManagerImplTest {
|
||||||
|
|
||||||
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
||||||
Mockito.when(affinityGroup.getType()).thenReturn("host affinity");
|
Mockito.when(affinityGroup.getType()).thenReturn("host affinity");
|
||||||
Mockito.when(affinityGroup.getName()).thenReturn("affinity-group");
|
Mockito.lenient().when(affinityGroup.getName()).thenReturn("affinity-group");
|
||||||
|
|
||||||
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
||||||
Mockito.when(newNode.getHostId()).thenReturn(sharedHostId);
|
Mockito.when(newNode.getHostId()).thenReturn(sharedHostId);
|
||||||
|
|
@ -775,12 +775,12 @@ public class KubernetesClusterManagerImplTest {
|
||||||
Long sharedHostId = 1000L;
|
Long sharedHostId = 1000L;
|
||||||
|
|
||||||
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
||||||
Mockito.when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
Mockito.lenient().when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
||||||
Mockito.when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
Mockito.when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
||||||
|
|
||||||
VMInstanceVO newNode1 = Mockito.mock(VMInstanceVO.class);
|
VMInstanceVO newNode1 = Mockito.mock(VMInstanceVO.class);
|
||||||
Mockito.when(newNode1.getHostId()).thenReturn(sharedHostId);
|
Mockito.when(newNode1.getHostId()).thenReturn(sharedHostId);
|
||||||
Mockito.when(newNode1.getInstanceName()).thenReturn("new-node-vm-1");
|
Mockito.lenient().when(newNode1.getInstanceName()).thenReturn("new-node-vm-1");
|
||||||
|
|
||||||
VMInstanceVO newNode2 = Mockito.mock(VMInstanceVO.class);
|
VMInstanceVO newNode2 = Mockito.mock(VMInstanceVO.class);
|
||||||
Mockito.when(newNode2.getHostId()).thenReturn(sharedHostId);
|
Mockito.when(newNode2.getHostId()).thenReturn(sharedHostId);
|
||||||
|
|
@ -805,7 +805,7 @@ public class KubernetesClusterManagerImplTest {
|
||||||
public void testValidateNodeAffinityGroupsAntiAffinityMultipleNewNodesOnDifferentHosts() {
|
public void testValidateNodeAffinityGroupsAntiAffinityMultipleNewNodesOnDifferentHosts() {
|
||||||
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
||||||
Mockito.when(cluster.getId()).thenReturn(1L);
|
Mockito.when(cluster.getId()).thenReturn(1L);
|
||||||
Mockito.when(cluster.getName()).thenReturn("test-cluster");
|
Mockito.lenient().when(cluster.getName()).thenReturn("test-cluster");
|
||||||
|
|
||||||
Long newNodeId1 = 100L;
|
Long newNodeId1 = 100L;
|
||||||
Long newNodeId2 = 101L;
|
Long newNodeId2 = 101L;
|
||||||
|
|
@ -813,8 +813,8 @@ public class KubernetesClusterManagerImplTest {
|
||||||
Long hostId2 = 1001L;
|
Long hostId2 = 1001L;
|
||||||
|
|
||||||
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
||||||
Mockito.when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
Mockito.lenient().when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
||||||
Mockito.when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
Mockito.lenient().when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
||||||
|
|
||||||
VMInstanceVO newNode1 = Mockito.mock(VMInstanceVO.class);
|
VMInstanceVO newNode1 = Mockito.mock(VMInstanceVO.class);
|
||||||
Mockito.when(newNode1.getHostId()).thenReturn(hostId1);
|
Mockito.when(newNode1.getHostId()).thenReturn(hostId1);
|
||||||
|
|
@ -839,13 +839,13 @@ public class KubernetesClusterManagerImplTest {
|
||||||
public void testValidateNodeAffinityGroupsNodeWithNullHost() {
|
public void testValidateNodeAffinityGroupsNodeWithNullHost() {
|
||||||
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
||||||
Mockito.when(cluster.getId()).thenReturn(1L);
|
Mockito.when(cluster.getId()).thenReturn(1L);
|
||||||
Mockito.when(cluster.getName()).thenReturn("test-cluster");
|
Mockito.lenient().when(cluster.getName()).thenReturn("test-cluster");
|
||||||
|
|
||||||
Long newNodeId = 100L;
|
Long newNodeId = 100L;
|
||||||
|
|
||||||
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
||||||
Mockito.when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
Mockito.lenient().when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
||||||
Mockito.when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
Mockito.lenient().when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
||||||
|
|
||||||
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
||||||
Mockito.when(newNode.getHostId()).thenReturn(null);
|
Mockito.when(newNode.getHostId()).thenReturn(null);
|
||||||
|
|
@ -859,20 +859,20 @@ public class KubernetesClusterManagerImplTest {
|
||||||
|
|
||||||
kubernetesClusterManager.validateNodeAffinityGroups(Arrays.asList(newNodeId), cluster);
|
kubernetesClusterManager.validateNodeAffinityGroups(Arrays.asList(newNodeId), cluster);
|
||||||
|
|
||||||
Mockito.verify(vmInstanceDao).findById(newNodeId);
|
Mockito.verify(vmInstanceDao, Mockito.atLeastOnce()).findById(newNodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateNodeAffinityGroupsNullNode() {
|
public void testValidateNodeAffinityGroupsNullNode() {
|
||||||
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
||||||
Mockito.when(cluster.getId()).thenReturn(1L);
|
Mockito.when(cluster.getId()).thenReturn(1L);
|
||||||
Mockito.when(cluster.getName()).thenReturn("test-cluster");
|
Mockito.lenient().when(cluster.getName()).thenReturn("test-cluster");
|
||||||
|
|
||||||
Long newNodeId = 100L;
|
Long newNodeId = 100L;
|
||||||
|
|
||||||
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
||||||
Mockito.when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
Mockito.lenient().when(affinityGroup.getType()).thenReturn("host anti-affinity");
|
||||||
Mockito.when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
Mockito.lenient().when(affinityGroup.getName()).thenReturn("anti-affinity-group");
|
||||||
|
|
||||||
Mockito.when(kubernetesClusterAffinityGroupMapDao.listAffinityGroupIdsByClusterIdAndNodeType(1L, WORKER.name()))
|
Mockito.when(kubernetesClusterAffinityGroupMapDao.listAffinityGroupIdsByClusterIdAndNodeType(1L, WORKER.name()))
|
||||||
.thenReturn(Arrays.asList(10L));
|
.thenReturn(Arrays.asList(10L));
|
||||||
|
|
@ -883,21 +883,21 @@ public class KubernetesClusterManagerImplTest {
|
||||||
|
|
||||||
kubernetesClusterManager.validateNodeAffinityGroups(Arrays.asList(newNodeId), cluster);
|
kubernetesClusterManager.validateNodeAffinityGroups(Arrays.asList(newNodeId), cluster);
|
||||||
|
|
||||||
Mockito.verify(vmInstanceDao).findById(newNodeId);
|
Mockito.verify(vmInstanceDao, Mockito.atLeastOnce()).findById(newNodeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateNodeAffinityGroupsAffinityNoExistingWorkers() {
|
public void testValidateNodeAffinityGroupsAffinityNoExistingWorkers() {
|
||||||
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
KubernetesCluster cluster = Mockito.mock(KubernetesCluster.class);
|
||||||
Mockito.when(cluster.getId()).thenReturn(1L);
|
Mockito.when(cluster.getId()).thenReturn(1L);
|
||||||
Mockito.when(cluster.getName()).thenReturn("test-cluster");
|
Mockito.lenient().when(cluster.getName()).thenReturn("test-cluster");
|
||||||
|
|
||||||
Long newNodeId = 100L;
|
Long newNodeId = 100L;
|
||||||
Long newNodeHostId = 1000L;
|
Long newNodeHostId = 1000L;
|
||||||
|
|
||||||
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
AffinityGroupVO affinityGroup = Mockito.mock(AffinityGroupVO.class);
|
||||||
Mockito.when(affinityGroup.getType()).thenReturn("host affinity");
|
Mockito.lenient().when(affinityGroup.getType()).thenReturn("host affinity");
|
||||||
Mockito.when(affinityGroup.getName()).thenReturn("affinity-group");
|
Mockito.lenient().when(affinityGroup.getName()).thenReturn("affinity-group");
|
||||||
|
|
||||||
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
VMInstanceVO newNode = Mockito.mock(VMInstanceVO.class);
|
||||||
Mockito.when(newNode.getHostId()).thenReturn(newNodeHostId);
|
Mockito.when(newNode.getHostId()).thenReturn(newNodeHostId);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue