Search in sources :

Example 16 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class GlobalLoadBalancingRulesServiceImplTest method runAssignToGlobalLoadBalancerRuleTestSameZoneLb.

void runAssignToGlobalLoadBalancerRuleTestSameZoneLb() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runAssignToGlobalLoadBalancerRuleTestSameZoneLb");
    GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
    gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
    gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
    gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
    gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
    gslbServiceImpl._rulesMgr = Mockito.mock(RulesManager.class);
    gslbServiceImpl._lbDao = Mockito.mock(LoadBalancerDao.class);
    gslbServiceImpl._networkDao = Mockito.mock(NetworkDao.class);
    gslbServiceImpl._globalConfigDao = Mockito.mock(ConfigurationDao.class);
    gslbServiceImpl._ipAddressDao = Mockito.mock(IPAddressDao.class);
    gslbServiceImpl._agentMgr = Mockito.mock(AgentManager.class);
    AssignToGlobalLoadBalancerRuleCmd assignCmd = new AssignToGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = assignCmd.getClass().getSuperclass();
    Account account = new AccountVO("testaccount", 3, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    Field gslbRuleId = _class.getDeclaredField("id");
    gslbRuleId.setAccessible(true);
    gslbRuleId.set(assignCmd, new Long(1));
    GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO("test-gslb-rule", "test-gslb-rule", "test-domain", "roundrobin", "sourceip", "tcp", 1, 3, 1, GlobalLoadBalancerRule.State.Active);
    when(gslbServiceImpl._gslbRuleDao.findById(new Long(1))).thenReturn(gslbRule);
    LoadBalancerVO lbRule1 = new LoadBalancerVO();
    lbRule1.setState(FirewallRule.State.Active);
    Field networkIdField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("networkId");
    Field accountIdField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("accountId");
    Field domainIdField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("domainId");
    networkIdField1.setAccessible(true);
    accountIdField1.setAccessible(true);
    domainIdField1.setAccessible(true);
    networkIdField1.set(lbRule1, new Long(1));
    accountIdField1.set(lbRule1, new Long(3));
    domainIdField1.set(lbRule1, new Long(1));
    Field idField1 = LoadBalancerVO.class.getSuperclass().getDeclaredField("id");
    idField1.setAccessible(true);
    idField1.set(lbRule1, new Long(1));
    LoadBalancerVO lbRule2 = new LoadBalancerVO();
    lbRule2.setState(FirewallRule.State.Active);
    Field networkIdField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("networkId");
    Field accountIdField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("accountId");
    Field domainIdField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("domainId");
    networkIdField2.setAccessible(true);
    accountIdField2.setAccessible(true);
    domainIdField2.setAccessible(true);
    networkIdField2.set(lbRule2, new Long(1));
    accountIdField2.set(lbRule2, new Long(3));
    domainIdField2.set(lbRule2, new Long(1));
    Field idField2 = LoadBalancerVO.class.getSuperclass().getDeclaredField("id");
    idField2.setAccessible(true);
    idField2.set(lbRule2, new Long(2));
    when(gslbServiceImpl._lbDao.findById(new Long(1))).thenReturn(lbRule1);
    when(gslbServiceImpl._lbDao.findById(new Long(2))).thenReturn(lbRule2);
    Field lbRules = _class.getDeclaredField("loadBalancerRulesIds");
    lbRules.setAccessible(true);
    List<Long> lbRuleIds = new ArrayList<Long>();
    lbRuleIds.add(new Long(1));
    lbRuleIds.add(new Long(2));
    lbRules.set(assignCmd, lbRuleIds);
    NetworkVO networkVo = new NetworkVO();
    Field dcID = NetworkVO.class.getDeclaredField("dataCenterId");
    dcID.setAccessible(true);
    dcID.set(networkVo, new Long(1));
    when(gslbServiceImpl._networkDao.findById(new Long(1))).thenReturn(networkVo);
    try {
        gslbServiceImpl.assignToGlobalLoadBalancerRule(assignCmd);
    } catch (InvalidParameterValueException e) {
        s_logger.info(e.getMessage());
        Assert.assertTrue(e.getMessage().contains("Load balancer rule specified should be in unique zone"));
    }
}
Also used : AssignToGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.AssignToGlobalLoadBalancerRuleCmd) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) Account(com.cloud.user.Account) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) RulesManager(com.cloud.network.rules.RulesManager) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) Field(java.lang.reflect.Field) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkVO(com.cloud.network.dao.NetworkVO) IPAddressDao(com.cloud.network.dao.IPAddressDao) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) NetworkDao(com.cloud.network.dao.NetworkDao) Matchers.anyLong(org.mockito.Matchers.anyLong) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 17 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class UpdateLoadBalancerTest method setUp.

@Before
public void setUp() {
    _lbMgr._accountMgr = new MockAccountManagerImpl();
    _lbMgr._autoScaleVmGroupDao = Mockito.mock(AutoScaleVmGroupDao.class);
    _lbMgr._networkDao = netDao;
    _lbMgr._networkModel = netModel;
    _lbMgr._lb2healthcheckDao = Mockito.mock(LBHealthCheckPolicyDao.class);
    _lbMgr._lb2stickinesspoliciesDao = Mockito.mock(LBStickinessPolicyDao.class);
    _lbMgr._lb2VmMapDao = Mockito.mock(LoadBalancerVMMapDao.class);
    _lbMgr._lbCertMapDao = Mockito.mock(LoadBalancerCertMapDao.class);
    _lbMgr._lbDao = lbDao;
    _lbMgr._lbProviders = new ArrayList<LoadBalancingServiceProvider>();
    _lbMgr._lbProviders.add(lbServiceProvider);
    updateLbRuleCmd = new UpdateLoadBalancerRuleCmd();
    AccountVO account = new AccountVO(accountName, domainId, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
}
Also used : LBHealthCheckPolicyDao(com.cloud.network.dao.LBHealthCheckPolicyDao) UserVO(com.cloud.user.UserVO) LoadBalancerCertMapDao(com.cloud.network.dao.LoadBalancerCertMapDao) LoadBalancerVMMapDao(com.cloud.network.dao.LoadBalancerVMMapDao) UpdateLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.loadbalancer.UpdateLoadBalancerRuleCmd) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) AutoScaleVmGroupDao(com.cloud.network.as.dao.AutoScaleVmGroupDao) LBStickinessPolicyDao(com.cloud.network.dao.LBStickinessPolicyDao) AccountVO(com.cloud.user.AccountVO) MockAccountManagerImpl(com.cloud.user.MockAccountManagerImpl) Before(org.junit.Before)

Example 18 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class CreatePrivateNetworkTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    networkService._accountMgr = _accountMgr;
    networkService._networkOfferingDao = _networkOfferingDao;
    networkService._physicalNetworkDao = _physicalNetworkDao;
    networkService._dcDao = _dcDao;
    networkService._networksDao = _networkDao;
    networkService._networkMgr = _networkMgr;
    networkService._privateIpDao = _privateIpDao;
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(networkService._accountMgr.getAccount(anyLong())).thenReturn(account);
    NetworkOfferingVO ntwkOff = new NetworkOfferingVO("offer", "fakeOffer", TrafficType.Guest, true, true, null, null, false, null, null, GuestType.Isolated, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false);
    when(networkService._networkOfferingDao.findById(anyLong())).thenReturn(ntwkOff);
    List<NetworkOfferingVO> netofferlist = new ArrayList<NetworkOfferingVO>();
    netofferlist.add(ntwkOff);
    when(networkService._networkOfferingDao.listSystemNetworkOfferings()).thenReturn(netofferlist);
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    DataCenterVO dc = new DataCenterVO(1L, "hut", "op de hei", null, null, null, null, "10.1.1.0/24", "unreal.net", 1L, NetworkType.Advanced, null, null);
    when(networkService._dcDao.lockRow(anyLong(), anyBoolean())).thenReturn(dc);
    when(networkService._networksDao.getPrivateNetwork(anyString(), anyString(), eq(1L), eq(1L), anyLong())).thenReturn(null);
    Network net = new NetworkVO(1L, TrafficType.Guest, Mode.None, BroadcastDomainType.Vlan, 1L, 1L, 1L, 1L, "bla", "fake", "eet.net", GuestType.Isolated, 1L, 1L, ACLType.Account, false, 1L, false);
    when(networkService._networkMgr.createGuestNetwork(eq(ntwkOff.getId()), eq("bla"), eq("fake"), eq("10.1.1.1"), eq("10.1.1.0/24"), anyString(), anyString(), eq(account), anyLong(), eq(physicalNetwork), eq(physicalNetwork.getDataCenterId()), eq(ACLType.Account), anyBoolean(), eq(1L), anyString(), anyString(), anyBoolean(), anyString())).thenReturn(net);
    when(networkService._privateIpDao.findByIpAndSourceNetworkId(net.getId(), "10.1.1.2")).thenReturn(null);
    when(networkService._privateIpDao.findByIpAndSourceNetworkIdAndVpcId(eq(1L), anyString(), eq(1L))).thenReturn(null);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Example 19 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class DedicateGuestVlanRangesTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    networkService._accountMgr = _accountMgr;
    networkService._accountDao = _accountDao;
    networkService._projectMgr = _projectMgr;
    networkService._physicalNetworkDao = _physicalNetworkDao;
    networkService._datacneterVnet = _dataCenterVnetDao;
    networkService._accountGuestVlanMapDao = _accountGuestVlanMapDao;
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(networkService._accountMgr.getAccount(anyLong())).thenReturn(account);
    when(networkService._accountDao.findActiveAccount(anyString(), anyLong())).thenReturn(account);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    Field accountNameField = _dedicateGuestVlanRangeClass.getDeclaredField("accountName");
    accountNameField.setAccessible(true);
    accountNameField.set(dedicateGuestVlanRangesCmd, "accountname");
    Field projectIdField = _dedicateGuestVlanRangeClass.getDeclaredField("projectId");
    projectIdField.setAccessible(true);
    projectIdField.set(dedicateGuestVlanRangesCmd, null);
    Field domainIdField = _dedicateGuestVlanRangeClass.getDeclaredField("domainId");
    domainIdField.setAccessible(true);
    domainIdField.set(dedicateGuestVlanRangesCmd, 1L);
    Field physicalNetworkIdField = _dedicateGuestVlanRangeClass.getDeclaredField("physicalNetworkId");
    physicalNetworkIdField.setAccessible(true);
    physicalNetworkIdField.set(dedicateGuestVlanRangesCmd, 1L);
    Field releaseIdField = _releaseGuestVlanRangeClass.getDeclaredField("id");
    releaseIdField.setAccessible(true);
    releaseIdField.set(releaseDedicatedGuestVlanRangesCmd, 1L);
}
Also used : Account(com.cloud.user.Account) Field(java.lang.reflect.Field) UserVO(com.cloud.user.UserVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Example 20 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class AssignLoadBalancerTest method setUp.

@Before
public void setUp() {
    assignToLbRuleCmd = new AssignToLoadBalancerRuleCmd() {
    };
    // ComponentContext.initComponentsLifeCycle();
    AccountVO account = new AccountVO(accountName, domainId, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    DomainVO domain = new DomainVO("rootDomain", 5L, 5L, "networkDomain");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
}
Also used : DomainVO(com.cloud.domain.DomainVO) AssignToLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.loadbalancer.AssignToLoadBalancerRuleCmd) UserVO(com.cloud.user.UserVO) AccountVO(com.cloud.user.AccountVO) Before(org.junit.Before)

Aggregations

AccountVO (com.cloud.user.AccountVO)139 Account (com.cloud.user.Account)65 Test (org.junit.Test)52 UserVO (com.cloud.user.UserVO)44 Field (java.lang.reflect.Field)41 ArrayList (java.util.ArrayList)40 DomainVO (com.cloud.domain.DomainVO)32 AccountManager (com.cloud.user.AccountManager)27 Before (org.junit.Before)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)21 Date (java.util.Date)16 QuotaAccountVO (org.apache.cloudstack.quota.vo.QuotaAccountVO)16 DomainDao (com.cloud.domain.dao.DomainDao)14 SslCertDao (com.cloud.network.dao.SslCertDao)14 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)13 NetworkDao (com.cloud.network.dao.NetworkDao)13 NetworkVO (com.cloud.network.dao.NetworkVO)13