use of org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRulePostiveTest.
void runCreateGlobalLoadBalancerRulePostiveTest() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
RegionVO region = new RegionVO();
region.setGslbEnabled(true);
when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
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);
CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = createCmd.getClass().getSuperclass();
Field regionIdField = _class.getDeclaredField("regionId");
regionIdField.setAccessible(true);
regionIdField.set(createCmd, new Integer(1));
Field algoField = _class.getDeclaredField("algorithm");
algoField.setAccessible(true);
algoField.set(createCmd, "roundrobin");
Field stickyField = _class.getDeclaredField("stickyMethod");
stickyField.setAccessible(true);
stickyField.set(createCmd, "sourceip");
Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
nameField.setAccessible(true);
nameField.set(createCmd, "gslb-rule");
Field descriptionField = _class.getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(createCmd, "testing create gslb-rule");
Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
serviceDomainField.setAccessible(true);
serviceDomainField.set(createCmd, "gslb-rule-domain");
Field serviceTypeField = _class.getDeclaredField("serviceType");
serviceTypeField.setAccessible(true);
serviceTypeField.set(createCmd, "tcp");
try {
gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
} catch (Exception e) {
s_logger.info("exception in testing runCreateGlobalLoadBalancerRulePostiveTest message: " + e.toString());
}
}
use of org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidServiceType.
void runCreateGlobalLoadBalancerRuleInvalidServiceType() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
RegionVO region = new RegionVO();
region.setGslbEnabled(true);
when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
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);
CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = createCmd.getClass().getSuperclass();
Field regionIdField = _class.getDeclaredField("regionId");
regionIdField.setAccessible(true);
regionIdField.set(createCmd, new Integer(1));
Field algoField = _class.getDeclaredField("algorithm");
algoField.setAccessible(true);
algoField.set(createCmd, "roundrobin");
Field stickyField = _class.getDeclaredField("stickyMethod");
stickyField.setAccessible(true);
stickyField.set(createCmd, "sourceip");
Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
nameField.setAccessible(true);
nameField.set(createCmd, "gslb-rule");
Field descriptionField = _class.getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(createCmd, "testing create gslb-rule");
Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
serviceDomainField.setAccessible(true);
serviceDomainField.set(createCmd, "gslb-rule-domain");
Field serviceTypeField = _class.getDeclaredField("serviceType");
serviceTypeField.setAccessible(true);
serviceTypeField.set(createCmd, "invalidtcp");
try {
gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
} catch (InvalidParameterValueException e) {
Assert.assertTrue(e.getMessage().contains("Invalid service type"));
}
}
use of org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidAlgorithm.
void runCreateGlobalLoadBalancerRuleInvalidAlgorithm() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
RegionVO region = new RegionVO();
region.setGslbEnabled(true);
when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
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);
CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = createCmd.getClass().getSuperclass();
Field regionIdField = _class.getDeclaredField("regionId");
regionIdField.setAccessible(true);
regionIdField.set(createCmd, new Integer(1));
Field algoField = _class.getDeclaredField("algorithm");
algoField.setAccessible(true);
algoField.set(createCmd, "invalidalgo");
Field stickyField = _class.getDeclaredField("stickyMethod");
stickyField.setAccessible(true);
stickyField.set(createCmd, "sourceip");
Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
nameField.setAccessible(true);
nameField.set(createCmd, "gslb-rule");
Field descriptionField = _class.getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(createCmd, "testing create gslb-rule");
Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
serviceDomainField.setAccessible(true);
serviceDomainField.set(createCmd, "gslb-rule-domain");
Field serviceTypeField = _class.getDeclaredField("serviceType");
serviceTypeField.setAccessible(true);
serviceTypeField.set(createCmd, "tcp");
try {
gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
} catch (InvalidParameterValueException e) {
Assert.assertTrue(e.getMessage().contains("Invalid Algorithm"));
}
}
use of org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidStickyMethod.
void runCreateGlobalLoadBalancerRuleInvalidStickyMethod() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
when(gslbServiceImpl._gslbRuleDao.persist(any(GlobalLoadBalancerRuleVO.class))).thenReturn(new GlobalLoadBalancerRuleVO());
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
RegionVO region = new RegionVO();
region.setGslbEnabled(true);
when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
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);
CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = createCmd.getClass().getSuperclass();
Field regionIdField = _class.getDeclaredField("regionId");
regionIdField.setAccessible(true);
regionIdField.set(createCmd, new Integer(1));
Field algoField = _class.getDeclaredField("algorithm");
algoField.setAccessible(true);
algoField.set(createCmd, "roundrobin");
Field stickyField = _class.getDeclaredField("stickyMethod");
stickyField.setAccessible(true);
stickyField.set(createCmd, "ivalidstickymethod");
Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
nameField.setAccessible(true);
nameField.set(createCmd, "gslb-rule");
Field descriptionField = _class.getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(createCmd, "testing create gslb-rule");
Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
serviceDomainField.setAccessible(true);
serviceDomainField.set(createCmd, "gslb-rule-domain");
Field serviceTypeField = _class.getDeclaredField("serviceType");
serviceTypeField.setAccessible(true);
serviceTypeField.set(createCmd, "tcp");
try {
gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
} catch (InvalidParameterValueException e) {
Assert.assertTrue(e.getMessage().contains("Invalid persistence"));
}
}
use of org.apache.cloudstack.api.command.user.region.ha.gslb.CreateGlobalLoadBalancerRuleCmd in project cloudstack by apache.
the class GlobalLoadBalancingRulesServiceImplTest method runCreateGlobalLoadBalancerRuleInvalidDomainName.
void runCreateGlobalLoadBalancerRuleInvalidDomainName() throws Exception {
TransactionLegacy txn = TransactionLegacy.open("runCreateGlobalLoadBalancerRulePostiveTest");
GlobalLoadBalancingRulesServiceImpl gslbServiceImpl = new GlobalLoadBalancingRulesServiceImpl();
gslbServiceImpl._accountMgr = Mockito.mock(AccountManager.class);
Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
when(gslbServiceImpl._accountMgr.getAccount(anyLong())).thenReturn(account);
gslbServiceImpl._gslbRuleDao = Mockito.mock(GlobalLoadBalancerRuleDao.class);
gslbServiceImpl._gslbLbMapDao = Mockito.mock(GlobalLoadBalancerLbRuleMapDao.class);
gslbServiceImpl._regionDao = Mockito.mock(RegionDao.class);
RegionVO region = new RegionVO();
region.setGslbEnabled(true);
when(gslbServiceImpl._regionDao.findById(anyInt())).thenReturn(region);
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);
CreateGlobalLoadBalancerRuleCmd createCmd = new CreateGlobalLoadBalancerRuleCmdExtn();
Class<?> _class = createCmd.getClass().getSuperclass();
Field regionIdField = _class.getDeclaredField("regionId");
regionIdField.setAccessible(true);
regionIdField.set(createCmd, new Integer(1));
Field algoField = _class.getDeclaredField("algorithm");
algoField.setAccessible(true);
algoField.set(createCmd, "roundrobin");
Field stickyField = _class.getDeclaredField("stickyMethod");
stickyField.setAccessible(true);
stickyField.set(createCmd, "sourceip");
Field nameField = _class.getDeclaredField("globalLoadBalancerRuleName");
nameField.setAccessible(true);
nameField.set(createCmd, "gslb-rule");
Field descriptionField = _class.getDeclaredField("description");
descriptionField.setAccessible(true);
descriptionField.set(createCmd, "testing create gslb-rule");
Field serviceDomainField = _class.getDeclaredField("serviceDomainName");
serviceDomainField.setAccessible(true);
serviceDomainField.set(createCmd, "gslb-rule-domain");
GlobalLoadBalancerRuleVO gslbRule = new GlobalLoadBalancerRuleVO();
when(gslbServiceImpl._gslbRuleDao.findByDomainName("gslb-rule-domain")).thenReturn(gslbRule);
Field serviceTypeField = _class.getDeclaredField("serviceType");
serviceTypeField.setAccessible(true);
serviceTypeField.set(createCmd, "tcp");
try {
gslbServiceImpl.createGlobalLoadBalancerRule(createCmd);
} catch (InvalidParameterValueException e) {
Assert.assertTrue(e.getMessage().contains("Domain name " + "gslb-rule-domain" + "is in use"));
}
}
Aggregations