AffinityGroupServiceImpl extends ManagerBase implements AffinityGroupService, Manager, StateListener<State, VirtualMachine.Event, VirtualMachine> { @DB @Override @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_CREATE, eventDescription = "Creating Affinity Group", create = true) public AffinityGroup createAffinityGroup(CreateAffinityGroupCmd createAffinityGroupCmd) { return createAffinityGroup(createAffinityGroupCmd.getAccountName(), createAffinityGroupCmd.getProjectId(), createAffinityGroupCmd.getDomainId(), createAffinityGroupCmd.getAffinityGroupName(), createAffinityGroupCmd.getAffinityGroupType(), createAffinityGroupCmd.getDescription()); }  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 createAffinityGroupFromCmdTest() { when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_groupDao.isNameInUse(anyLong(), anyLong(), eq(AFFINITY_GROUP_NAME))).thenReturn(false); CreateAffinityGroupCmd mockCreateAffinityGroupCmd = Mockito.mock(CreateAffinityGroupCmd.class); when(mockCreateAffinityGroupCmd.getProjectId()).thenReturn(PROJECT_ID); when(mockCreateAffinityGroupCmd.getAffinityGroupName()).thenReturn(AFFINITY_GROUP_NAME); when(mockCreateAffinityGroupCmd.getAffinityGroupType()).thenReturn("mock"); when(mockCreateAffinityGroupCmd.getDescription()).thenReturn("affinity group one"); AffinityGroup group = _affinityService.createAffinityGroup(mockCreateAffinityGroupCmd); assertNotNull("Affinity group 'group1' of type 'mock' failed to create ", group); }
@Test public void createAffinityGroupTest() { when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_groupDao.isNameInUse(anyLong(), anyLong(), eq(AFFINITY_GROUP_NAME))).thenReturn(false); AffinityGroup group = _affinityService.createAffinityGroup(ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME, "mock", "affinity group one"); assertNotNull("Affinity group 'group1' of type 'mock' failed to create ", group); }
@Test(expected = InvalidParameterValueException.class) public void invalidAffinityTypeTest() { when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); _affinityService.createAffinityGroup(ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME, "invalid", "affinity group one"); }
@Test(expected = InvalidParameterValueException.class) public void uniqueAffinityNameTest() { when(_acctMgr.finalizeOwner((Account)anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct); when(_groupDao.isNameInUse(anyLong(), anyLong(), eq(AFFINITY_GROUP_NAME))).thenReturn(true); _affinityService.createAffinityGroup(ACCOUNT_NAME, null, DOMAIN_ID, AFFINITY_GROUP_NAME, "mock", "affinity group two"); }