AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService, Manager, StateListener<State, VirtualMachine.Event, VirtualMachine> { @DB @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group") public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long projectId, Long domainId, String affinityGroupName) { AffinityGroupVO group = getAffinityGroup(affinityGroupId, account, projectId, domainId, affinityGroupName); Account caller = CallContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, AccessType.OperateEntry, true, group); final Long affinityGroupIdFinal = group.getId(); deleteAffinityGroup(affinityGroupIdFinal); Pair<Class<?>, Long> params = new Pair<Class<?>, Long>(AffinityGroup.class, affinityGroupIdFinal); _messageBus.publish(_name, EntityManager.MESSAGE_REMOVE_ENTITY_EVENT, PublishScope.LOCAL, params); if (s_logger.isDebugEnabled()) { s_logger.debug("Deleted affinity group id=" + affinityGroupIdFinal); } return true; }  List<AffinityGroupProcessor> getAffinityGroupProcessors(); void setAffinityGroupProcessors(List<AffinityGroupProcessor> affinityProcessors); @DB @Override @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_CREATE, eventDescription = "Creating Affinity Group", create = true) AffinityGroup createAffinityGroup(CreateAffinityGroupCmd createAffinityGroupCmd); @DB @Override AffinityGroup createAffinityGroup(final String accountName, final Long projectId, final Long domainId, final String affinityGroupName, final String affinityGroupType,
        final String description); @DB @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting affinity group") boolean deleteAffinityGroup(Long affinityGroupId, String account, Long projectId, Long domainId, String affinityGroupName); @Override List<String> listAffinityGroupTypes(); @Override boolean isAdminControlledGroup(AffinityGroup group); @Override boolean configure(final String name, final Map<String, Object> params); @Override boolean start(); @Override boolean stop(); @Override String getName(); @Override AffinityGroup getAffinityGroup(Long groupId); @Override boolean preStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vo, boolean status, Object opaque); @Override boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, VirtualMachine vo, boolean status, Object opaque); @Override UserVm updateVMAffinityGroups(Long vmId, List<Long> affinityGroupIds); @Override boolean isAffinityGroupProcessorAvailable(String affinityGroupType); @Override boolean isAffinityGroupAvailableInDomain(long affinityGroupId, long domainId); static final Logger s_logger; }
@Test public void shouldDeleteDomainLevelAffinityGroup() { AffinityGroupVO mockGroup = Mockito.mock(AffinityGroupVO.class); when(mockGroup.getId()).thenReturn(2L); when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(mockGroup); _affinityService.deleteAffinityGroup(2L, null, null, DOMAIN_ID, null); Mockito.verify(_affinityGroupDao).expunge(2L); }
@Test public void shouldDeleteAffintyGroupById() { AffinityGroupVO mockGroup = Mockito.mock(AffinityGroupVO.class); when(mockGroup.getId()).thenReturn(1L); when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(mockGroup); _affinityService.deleteAffinityGroup(1L, ACCOUNT_NAME, null, DOMAIN_ID, null); Mockito.verify(_affinityGroupDao).expunge(1L); }
@Test(expected = InvalidParameterValueException.class) public void deleteAffinityGroupInvalidIdTest() throws ResourceInUseException { when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_groupDao.findById(20L)).thenReturn(null); _affinityService.deleteAffinityGroup(20L, ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME); }
@Test(expected = InvalidParameterValueException.class) public void deleteAffinityGroupInvalidIdName() throws ResourceInUseException { when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_acctMgr.finalyzeAccountId(ACCOUNT_NAME, DOMAIN_ID, null, true)).thenReturn(200L); when(_groupDao.findByAccountAndName(200L, AFFINITY_GROUP_NAME)).thenReturn(null); _affinityService.deleteAffinityGroup(null, ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME); }
@Test(expected = InvalidParameterValueException.class) public void deleteAffinityGroupNullIdName() throws ResourceInUseException { when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); _affinityService.deleteAffinityGroup(null, ACCOUNT_NAME, null, DOMAIN_ID, null); }