@Test(expected = InvalidParameterValueException.class)
public void updateAffinityGroupVMRunning() throws ResourceInUseException {

    when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
    UserVmVO vm = new UserVmVO(10L, "test", "test", 101L, HypervisorType.Any, 21L, false, false, DOMAIN_ID, 200L, 1, 5L, "", "test", 1L);
    vm.setState(VirtualMachine.State.Running);
    when(_vmDao.findById(10L)).thenReturn(vm);
    List<Long> affinityGroupIds = new ArrayList<Long>();
    affinityGroupIds.add(20L);
    _affinityService.updateVMAffinityGroups(10L, affinityGroupIds);
}