Search in sources :

Example 1 with DeleteGlobalLoadBalancerRuleCmd

use of org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd in project cloudstack by apache.

the class GlobalLoadBalancingRulesServiceImplTest method runDeleteGlobalLoadBalancerRuleTestWithLbRules.

void runDeleteGlobalLoadBalancerRuleTestWithLbRules() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDeleteGlobalLoadBalancerRuleTestWithLbRules");
    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);
    DeleteGlobalLoadBalancerRuleCmd deleteCmd = new DeleteGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = deleteCmd.getClass().getSuperclass();
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    Field gslbRuleId = _class.getDeclaredField("id");
    gslbRuleId.setAccessible(true);
    gslbRuleId.set(deleteCmd, new Long(1));
    GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO("test-gslb-rule", "test-gslb-rule", "test-domain", "roundrobin", "sourceip", "tcp", 1, 1, 1, GlobalLoadBalancerRule.State.Active);
    when(gslbServiceImpl._gslbRuleDao.findById(new Long(1))).thenReturn(gslbRule);
    GlobalLoadBalancerLbRuleMapVO gslbLmMap = new GlobalLoadBalancerLbRuleMapVO(1, 1, 1);
    List<GlobalLoadBalancerLbRuleMapVO> gslbLbMapVos = new ArrayList<GlobalLoadBalancerLbRuleMapVO>();
    gslbLbMapVos.add(gslbLmMap);
    when(gslbServiceImpl._gslbLbMapDao.listByGslbRuleId(new Long(1))).thenReturn(gslbLbMapVos);
    try {
        gslbServiceImpl.deleteGlobalLoadBalancerRule(deleteCmd);
        Assert.assertTrue(gslbRule.getState() == GlobalLoadBalancerRule.State.Revoke);
        Assert.assertTrue(gslbLmMap.isRevoke() == true);
    } catch (Exception e) {
        s_logger.info("exception in testing runDeleteGlobalLoadBalancerRuleTestWithLbRules. " + e.toString());
    }
}
Also used : ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) Account(com.cloud.user.Account) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) IPAddressDao(com.cloud.network.dao.IPAddressDao) RulesManager(com.cloud.network.rules.RulesManager) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) NetworkDao(com.cloud.network.dao.NetworkDao) Matchers.anyLong(org.mockito.Matchers.anyLong) DeleteGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Example 2 with DeleteGlobalLoadBalancerRuleCmd

use of org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd in project cloudstack by apache.

the class GlobalLoadBalancingRulesServiceImplTest method runDeleteGlobalLoadBalancerRuleTestWithNoLbRules.

void runDeleteGlobalLoadBalancerRuleTestWithNoLbRules() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDeleteGlobalLoadBalancerRuleTestWithNoLbRules");
    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);
    DeleteGlobalLoadBalancerRuleCmd deleteCmd = new DeleteGlobalLoadBalancerRuleCmdExtn();
    Class<?> _class = deleteCmd.getClass().getSuperclass();
    Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
    Field gslbRuleId = _class.getDeclaredField("id");
    gslbRuleId.setAccessible(true);
    gslbRuleId.set(deleteCmd, new Long(1));
    GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO("test-gslb-rule", "test-gslb-rule", "test-domain", "roundrobin", "sourceip", "tcp", 1, 1, 1, GlobalLoadBalancerRule.State.Active);
    when(gslbServiceImpl._gslbRuleDao.findById(new Long(1))).thenReturn(gslbRule);
    GlobalLoadBalancerLbRuleMapVO gslbLbMap = new GlobalLoadBalancerLbRuleMapVO();
    gslbLbMap.setGslbLoadBalancerId(1);
    gslbLbMap.setLoadBalancerId(1);
    List<GlobalLoadBalancerLbRuleMapVO> gslbLbMapList = new ArrayList<GlobalLoadBalancerLbRuleMapVO>();
    gslbLbMapList.add(gslbLbMap);
    when(gslbServiceImpl._gslbLbMapDao.listByGslbRuleId(new Long(1))).thenReturn(gslbLbMapList);
    try {
        gslbServiceImpl.deleteGlobalLoadBalancerRule(deleteCmd);
        Assert.assertTrue(gslbRule.getState() == GlobalLoadBalancerRule.State.Revoke);
    } catch (Exception e) {
        s_logger.info("exception in testing runDeleteGlobalLoadBalancerRuleTestWithNoLbRules. " + e.toString());
    }
}
Also used : ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) Account(com.cloud.user.Account) LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) AgentManager(com.cloud.agent.AgentManager) IPAddressDao(com.cloud.network.dao.IPAddressDao) RulesManager(com.cloud.network.rules.RulesManager) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) NetworkDao(com.cloud.network.dao.NetworkDao) Matchers.anyLong(org.mockito.Matchers.anyLong) DeleteGlobalLoadBalancerRuleCmd(org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd) AccountManager(com.cloud.user.AccountManager) RegionDao(org.apache.cloudstack.region.dao.RegionDao)

Aggregations

AgentManager (com.cloud.agent.AgentManager)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 IPAddressDao (com.cloud.network.dao.IPAddressDao)2 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)2 NetworkDao (com.cloud.network.dao.NetworkDao)2 RulesManager (com.cloud.network.rules.RulesManager)2 Account (com.cloud.user.Account)2 AccountManager (com.cloud.user.AccountManager)2 AccountVO (com.cloud.user.AccountVO)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 DeleteGlobalLoadBalancerRuleCmd (org.apache.cloudstack.api.command.user.region.ha.gslb.DeleteGlobalLoadBalancerRuleCmd)2 ConfigurationDao (org.apache.cloudstack.framework.config.dao.ConfigurationDao)2 RegionDao (org.apache.cloudstack.region.dao.RegionDao)2 Matchers.anyLong (org.mockito.Matchers.anyLong)2