From 51b02702f91bb084dd20540190f02232b82617f5 Mon Sep 17 00:00:00 2001 From: Devdeep Singh Date: Thu, 11 Jul 2013 16:01:13 +0530 Subject: [PATCH] CLOUDSTACK-3467: Fixing the unit tests for implicit dedication planner. When fix for bug 2662 was made the unit tests were not updated correctly. The unit tests should have been changed to return the correct mock object (VMInstanceVO) when vmInstanceDao is queried for the vms running on host. --- .../implicitplanner/ImplicitPlannerTest.java | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java index efbb5c2a6f9..e5196688388 100644 --- a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java +++ b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java @@ -202,11 +202,10 @@ public class ImplicitPlannerTest { // Validations. // Check cluster 2 and 3 are not in the cluster list. // Host 6 and 7 should also be in avoid list. - //System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Cluster list should not be empty but ::" + clusterList.toString()); assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty())); boolean foundNeededCluster = false; for (Long cluster : clusterList) { - if (cluster == 4) { + if (cluster != 1) { fail("Found a cluster that shouldn't have been present, cluster id : " + cluster); }else { foundNeededCluster = true; @@ -219,8 +218,7 @@ public class ImplicitPlannerTest { Set hostsThatShouldBeInAvoidList = new HashSet(); hostsThatShouldBeInAvoidList.add(6L); hostsThatShouldBeInAvoidList.add(7L); - //System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Host in avoidlist :: " + hostsThatShouldBeInAvoidList.toString()); - assertFalse("Hosts 6 and 7 that should have been present were not found in avoid list" , + assertTrue("Hosts 6 and 7 that should have been present were not found in avoid list" , hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList)); } @@ -244,14 +242,11 @@ public class ImplicitPlannerTest { // Host 5 and 7 should also be in avoid list. assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty())); boolean foundNeededCluster = false; - //System.out.println("Cluster list 2 should not be present ::" + clusterList.toString()); for (Long cluster : clusterList) { if (cluster != 2) { fail("Found a cluster that shouldn't have been present, cluster id : " + cluster); - }else { + } else { foundNeededCluster = true; - //System.out.println("Cluster list 2 should not be present breaking now" + cluster); - break; } } assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster); @@ -261,7 +256,7 @@ public class ImplicitPlannerTest { Set hostsThatShouldBeInAvoidList = new HashSet(); hostsThatShouldBeInAvoidList.add(5L); hostsThatShouldBeInAvoidList.add(7L); - assertFalse("Hosts 5 and 7 that should have been present were not found in avoid list" , + assertTrue("Hosts 5 and 7 that should have been present were not found in avoid list" , hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList)); } @@ -283,8 +278,7 @@ public class ImplicitPlannerTest { // Validations. // Check cluster list is empty. - //System.out.println("Cluster list should not be empty but ::" + clusterList.toString()); - assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty())); + assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty())); } @Test @@ -360,7 +354,7 @@ public class ImplicitPlannerTest { when(vmProfile.getOwner()).thenReturn(account); when(vmProfile.getVirtualMachine()).thenReturn(vm); when(vmProfile.getId()).thenReturn(12L); - when( vmDao.findById(12L)).thenReturn(userVm); + when(vmDao.findById(12L)).thenReturn(userVm); when(userVm.getAccountId()).thenReturn(accountId); when(vm.getDataCenterId()).thenReturn(dataCenterId); @@ -440,20 +434,20 @@ public class ImplicitPlannerTest { UserVmVO vm3 = mock(UserVmVO.class); when(vm3.getAccountId()).thenReturn(201L); when(vm3.getServiceOfferingId()).thenReturn(offeringIdForVmsOfOtherAccount); - List userVmsForHost1 = new ArrayList(); - List userVmsForHost2 = new ArrayList(); - List userVmsForHost3 = new ArrayList(); - List stoppedVmsForHost = new ArrayList(); + List vmsForHost1 = new ArrayList(); + List vmsForHost2 = new ArrayList(); + List vmsForHost3 = new ArrayList(); + List stoppedVmsForHost = new ArrayList(); // Host 2 is empty. - userVmsForHost1.add(vm1); - userVmsForHost1.add(vm2); - userVmsForHost3.add(vm3); - when(vmDao.listUpByHostId(5L)).thenReturn(userVmsForHost1); - when(vmDao.listUpByHostId(6L)).thenReturn(userVmsForHost2); - when(vmDao.listUpByHostId(7L)).thenReturn(userVmsForHost3); - when(vmDao.listByLastHostId(5L)).thenReturn(stoppedVmsForHost); - when(vmDao.listByLastHostId(6L)).thenReturn(stoppedVmsForHost); - when(vmDao.listByLastHostId(7L)).thenReturn(stoppedVmsForHost); + vmsForHost1.add(vm1); + vmsForHost1.add(vm2); + vmsForHost3.add(vm3); + when(vmInstanceDao.listUpByHostId(5L)).thenReturn(vmsForHost1); + when(vmInstanceDao.listUpByHostId(6L)).thenReturn(vmsForHost2); + when(vmInstanceDao.listUpByHostId(7L)).thenReturn(vmsForHost3); + when(vmInstanceDao.listByLastHostId(5L)).thenReturn(stoppedVmsForHost); + when(vmInstanceDao.listByLastHostId(6L)).thenReturn(stoppedVmsForHost); + when(vmInstanceDao.listByLastHostId(7L)).thenReturn(stoppedVmsForHost); // Mock the offering with which the vm was created. ServiceOfferingVO offeringForVmOfThisAccount = mock(ServiceOfferingVO.class); @@ -589,4 +583,4 @@ public class ImplicitPlannerTest { } } } -} +} \ No newline at end of file