4141import com .cloud .storage .dao .VolumeDao ;
4242import com .cloud .user .Account ;
4343import com .cloud .user .AccountManager ;
44+ import com .cloud .user .AccountVO ;
4445import com .cloud .user .dao .AccountDao ;
4546import com .cloud .user .dao .UserDao ;
4647import com .cloud .uservm .UserVm ;
@@ -136,6 +137,8 @@ public class VMSnapshotManagerTest {
136137 VMSnapshotDetailsDao _vmSnapshotDetailsDao ;
137138 @ Mock
138139 UserVmManager _userVmManager ;
140+ @ Mock
141+ private AccountVO accountVOMock ;
139142
140143 private static final long TEST_VM_ID = 3L ;
141144 private static final long SERVICE_OFFERING_ID = 1L ;
@@ -285,8 +288,12 @@ public void testCreateVMSnapshotF3() throws AgentUnavailableException, Operation
285288 @ SuppressWarnings ("unchecked" )
286289 @ Test (expected = CloudRuntimeException .class )
287290 public void testAllocVMSnapshotF4 () throws ResourceAllocationException {
291+ long accountId = 1L ;
288292 List <VMSnapshotVO > mockList = mock (List .class );
289293 when (mockList .size ()).thenReturn (10 );
294+ when (_userVMDao .findById (TEST_VM_ID )).thenReturn (vmMock );
295+ when (userVm .getAccountId ()).thenReturn (accountId );
296+ when (_accountMgr .getAccount (accountId )).thenReturn (accountVOMock );
290297 when (_vmSnapshotDao .findByVm (TEST_VM_ID )).thenReturn (mockList );
291298 _vmSnapshotMgr .allocVMSnapshot (TEST_VM_ID , "" , "" , true );
292299 }
@@ -295,15 +302,23 @@ public void testAllocVMSnapshotF4() throws ResourceAllocationException {
295302 @ SuppressWarnings ("unchecked" )
296303 @ Test (expected = CloudRuntimeException .class )
297304 public void testAllocVMSnapshotF5 () throws ResourceAllocationException {
305+ long accountId = 1L ;
298306 List <SnapshotVO > mockList = mock (List .class );
299307 when (mockList .size ()).thenReturn (1 );
308+ when (_userVMDao .findById (TEST_VM_ID )).thenReturn (vmMock );
309+ when (userVm .getAccountId ()).thenReturn (accountId );
310+ when (_accountMgr .getAccount (accountId )).thenReturn (accountVOMock );
300311 when (_snapshotDao .listByInstanceId (TEST_VM_ID , Snapshot .State .Creating , Snapshot .State .CreatedOnPrimary , Snapshot .State .BackingUp )).thenReturn (mockList );
301312 _vmSnapshotMgr .allocVMSnapshot (TEST_VM_ID , "" , "" , true );
302313 }
303314
304315 // successful creation case
305316 @ Test
306317 public void testCreateVMSnapshot () throws AgentUnavailableException , OperationTimedoutException , ResourceAllocationException , NoTransitionException {
318+ long accountId = 1L ;
319+ when (_userVMDao .findById (TEST_VM_ID )).thenReturn (vmMock );
320+ when (userVm .getAccountId ()).thenReturn (accountId );
321+ when (_accountMgr .getAccount (accountId )).thenReturn (accountVOMock );
307322 when (vmMock .getState ()).thenReturn (State .Running );
308323 _vmSnapshotMgr .allocVMSnapshot (TEST_VM_ID , "" , "" , true );
309324 }
0 commit comments