You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2013/04/30 21:04:17 UTC
[2/2] git commit: updated refs/heads/internallb to b7cf870
InternalLb: more unittests for internal lb element
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b7cf8700
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b7cf8700
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b7cf8700
Branch: refs/heads/internallb
Commit: b7cf8700749893abcac1d3a3d20ec32c4cb5d37f
Parents: 63bb98e
Author: Alena Prokharchyk <al...@citrix.com>
Authored: Tue Apr 30 10:31:28 2013 -0700
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Tue Apr 30 11:58:42 2013 -0700
----------------------------------------------------------------------
.../ElementChildTestConfiguration.java | 124 +++++
.../InternalLbElementServiceTest.java | 190 +++++++
.../internallbelement/InternalLbElementTest.java | 226 +++++++++
.../ElementChildTestConfiguration.java | 116 -----
.../internallbvm/InternalLBVMManagerTest.java | 388 ---------------
.../internallbvm/InternalLBVMServiceTest.java | 291 -----------
.../internallbvm/InternalLbElementServiceTest.java | 190 -------
.../internallbvm/LbChildTestConfiguration.java | 164 ------
.../internallbvmmgr/InternalLBVMManagerTest.java | 388 +++++++++++++++
.../internallbvmmgr/InternalLBVMServiceTest.java | 291 +++++++++++
.../internallbvmmgr/LbChildTestConfiguration.java | 164 ++++++
.../test/resources/lb_element.xml | 2 +-
.../test/resources/lb_mgr.xml | 2 +-
.../test/resources/lb_svc.xml | 2 +-
14 files changed, 1386 insertions(+), 1152 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/ElementChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/ElementChildTestConfiguration.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/ElementChildTestConfiguration.java
new file mode 100644
index 0000000..801020d
--- /dev/null
+++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/ElementChildTestConfiguration.java
@@ -0,0 +1,124 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.internallbelement;
+
+import java.io.IOException;
+
+import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
+import org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDao;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.core.type.filter.TypeFilter;
+
+import com.cloud.configuration.ConfigurationManager;
+import com.cloud.dc.dao.AccountVlanMapDaoImpl;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.NetworkServiceMapDao;
+import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
+import com.cloud.network.dao.VirtualRouterProviderDao;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.component.SpringComponentScanUtils;
+import com.cloud.vm.dao.DomainRouterDao;
+
+@Configuration
+@ComponentScan(
+ basePackageClasses={
+ AccountVlanMapDaoImpl.class
+ },
+ includeFilters={@Filter(value=ElementChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
+ useDefaultFilters=false
+ )
+
+public class ElementChildTestConfiguration {
+ public static class Library implements TypeFilter {
+ @Bean
+ public AccountManager accountManager() {
+ return Mockito.mock(AccountManager.class);
+ }
+
+
+ @Bean
+ public DomainRouterDao domainRouterDao() {
+ return Mockito.mock(DomainRouterDao.class);
+ }
+
+ @Bean
+ public VirtualRouterProviderDao virtualRouterProviderDao() {
+ return Mockito.mock(VirtualRouterProviderDao.class);
+ }
+
+ @Bean
+ public NetworkModel networkModel() {
+ return Mockito.mock(NetworkModel.class);
+ }
+
+
+ @Bean
+ public NetworkManager networkManager() {
+ return Mockito.mock(NetworkManager.class);
+ }
+
+
+ @Bean
+ public PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao() {
+ return Mockito.mock(PhysicalNetworkServiceProviderDao.class);
+ }
+
+ @Bean
+ public NetworkServiceMapDao networkServiceMapDao() {
+ return Mockito.mock(NetworkServiceMapDao.class);
+ }
+
+ @Bean
+ public InternalLoadBalancerVMManager internalLoadBalancerVMManager() {
+ return Mockito.mock(InternalLoadBalancerVMManager.class);
+ }
+
+ @Bean
+ public ConfigurationManager confugurationManager() {
+ return Mockito.mock(ConfigurationManager.class);
+ }
+
+
+ @Bean
+ public ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao() {
+ return Mockito.mock(ApplicationLoadBalancerRuleDao.class);
+ }
+
+ @Bean
+ public DataCenterDao dataCenterDao() {
+ return Mockito.mock(DataCenterDao.class);
+ }
+
+
+
+ @Override
+ public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
+ mdr.getClassMetadata().getClassName();
+ ComponentScan cs = ElementChildTestConfiguration.class.getAnnotation(ComponentScan.class);
+ return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java
new file mode 100644
index 0000000..f0e951c
--- /dev/null
+++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementServiceTest.java
@@ -0,0 +1,190 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.internallbelement;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.network.VirtualRouterProvider;
+import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
+import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
+import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
+import com.cloud.network.dao.VirtualRouterProviderDao;
+import com.cloud.network.element.VirtualRouterProviderVO;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.component.ComponentContext;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations="classpath:/lb_element.xml")
+public class InternalLbElementServiceTest {
+ //The interface to test
+ @Inject InternalLoadBalancerElementService _lbElSvc;
+
+ //Mocked interfaces
+ @Inject AccountManager _accountMgr;
+ @Inject VirtualRouterProviderDao _vrProviderDao;
+ @Inject PhysicalNetworkServiceProviderDao _pNtwkProviderDao;
+
+ long validElId = 1L;
+ long nonExistingElId = 2L;
+ long invalidElId = 3L; //not of VirtualRouterProviderType
+
+ long validProviderId = 1L;
+ long nonExistingProviderId = 2L;
+ long invalidProviderId = 3L;
+
+
+ @Before
+ public void setUp() {
+
+ ComponentContext.initComponentsLifeCycle();
+ VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
+ VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.VirtualRouter);
+
+ Mockito.when(_vrProviderDao.findById(validElId)).thenReturn(validElement);
+ Mockito.when(_vrProviderDao.findById(invalidElId)).thenReturn(invalidElement);
+
+ Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
+
+ Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
+
+ PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
+ PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
+
+ Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider);
+ Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider);
+
+ Mockito.when(_vrProviderDao.persist(Mockito.any(VirtualRouterProviderVO.class))).thenReturn(validElement);
+ }
+
+ //TESTS FOR getInternalLoadBalancerElement METHOD
+
+
+ @Test (expected = InvalidParameterValueException.class)
+ public void findNonExistingVm() {
+ String expectedExcText = null;
+ try {
+ _lbElSvc.getInternalLoadBalancerElement(nonExistingElId);
+ } catch (InvalidParameterValueException e) {
+ expectedExcText = e.getMessage();
+ throw e;
+ } finally {
+ assertEquals("Test failed. The non-existing intenral lb provider was found"
+ + expectedExcText, expectedExcText, "Unable to find InternalLoadBalancerElementService by id");
+ }
+ }
+
+
+ @Test (expected = InvalidParameterValueException.class)
+ public void findInvalidVm() {
+ String expectedExcText = null;
+ try {
+ _lbElSvc.getInternalLoadBalancerElement(invalidElId);
+ } catch (InvalidParameterValueException e) {
+ expectedExcText = e.getMessage();
+ throw e;
+ } finally {
+ assertEquals("Test failed. The non-existing intenral lb provider was found"
+ + expectedExcText, expectedExcText, "Unable to find InternalLoadBalancerElementService by id");
+ }
+ }
+
+
+ @Test
+ public void findValidVm() {
+ VirtualRouterProvider provider = null;
+ try {
+ provider = _lbElSvc.getInternalLoadBalancerElement(validElId);
+ } finally {
+ assertNotNull("Test failed. Couldn't find the VR provider by the valid id",provider);
+ }
+ }
+
+
+ //TESTS FOR configureInternalLoadBalancerElement METHOD
+
+ @Test (expected = InvalidParameterValueException.class)
+ public void configureNonExistingVm() {
+
+ _lbElSvc.configureInternalLoadBalancerElement(nonExistingElId, true);
+
+ }
+
+
+ @Test (expected = InvalidParameterValueException.class)
+ public void ConfigureInvalidVm() {
+ _lbElSvc.configureInternalLoadBalancerElement(invalidElId, true);
+ }
+
+
+ @Test
+ public void enableProvider() {
+ VirtualRouterProvider provider = null;
+ try {
+ provider = _lbElSvc.configureInternalLoadBalancerElement(validElId, true);
+ } finally {
+ assertNotNull("Test failed. Couldn't find the VR provider by the valid id ",provider);
+ assertTrue("Test failed. The provider wasn't eanbled ", provider.isEnabled());
+ }
+ }
+
+ @Test
+ public void disableProvider() {
+ VirtualRouterProvider provider = null;
+ try {
+ provider = _lbElSvc.configureInternalLoadBalancerElement(validElId, false);
+ } finally {
+ assertNotNull("Test failed. Couldn't find the VR provider by the valid id ",provider);
+ assertFalse("Test failed. The provider wasn't disabled ", provider.isEnabled());
+ }
+ }
+
+ //TESTS FOR addInternalLoadBalancerElement METHOD
+
+ @Test (expected = InvalidParameterValueException.class)
+ public void addToNonExistingProvider() {
+
+ _lbElSvc.addInternalLoadBalancerElement(nonExistingProviderId);
+
+ }
+
+ @Test (expected = InvalidParameterValueException.class)
+ public void addToInvalidProvider() {
+ _lbElSvc.addInternalLoadBalancerElement(invalidProviderId);
+ }
+
+ @Test
+ public void addToExistingProvider() {
+ _lbElSvc.addInternalLoadBalancerElement(validProviderId);
+ }
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementTest.java
new file mode 100644
index 0000000..e4e5ca0
--- /dev/null
+++ b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbelement/InternalLbElementTest.java
@@ -0,0 +1,226 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.internallbelement;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.network.element.InternalLoadBalancerElement;
+import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
+import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.cloud.agent.api.to.LoadBalancerTO;
+import com.cloud.configuration.ConfigurationManager;
+import com.cloud.dc.DataCenter.NetworkType;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
+import com.cloud.network.addr.PublicIp;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
+import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
+import com.cloud.network.dao.VirtualRouterProviderDao;
+import com.cloud.network.element.VirtualRouterProviderVO;
+import com.cloud.network.lb.LoadBalancingRule;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.LoadBalancerContainer.Scheme;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.net.Ip;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations="classpath:/lb_element.xml")
+public class InternalLbElementTest {
+ //The class to test
+ @Inject InternalLoadBalancerElement _lbEl;
+
+ //Mocked interfaces
+ @Inject AccountManager _accountMgr;
+ @Inject VirtualRouterProviderDao _vrProviderDao;
+ @Inject PhysicalNetworkServiceProviderDao _pNtwkProviderDao;
+ @Inject InternalLoadBalancerVMManager _internalLbMgr;
+ @Inject ConfigurationManager _configMgr;
+
+ long validElId = 1L;
+ long nonExistingElId = 2L;
+ long invalidElId = 3L; //not of VirtualRouterProviderType
+ long notEnabledElId = 4L;
+
+ long validProviderId = 1L;
+ long nonExistingProviderId = 2L;
+ long invalidProviderId = 3L;
+
+
+ @Before
+ public void setUp() {
+
+ ComponentContext.initComponentsLifeCycle();
+ VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
+ validElement.setEnabled(true);
+ VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.VirtualRouter);
+ VirtualRouterProviderVO notEnabledElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
+
+ Mockito.when(_vrProviderDao.findByNspIdAndType(validElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
+ Mockito.when(_vrProviderDao.findByNspIdAndType(invalidElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(invalidElement);
+ Mockito.when(_vrProviderDao.findByNspIdAndType(notEnabledElId, VirtualRouterProviderType.InternalLbVm)).thenReturn(notEnabledElement);
+
+ Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
+
+ Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
+
+ PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
+ PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
+
+ Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider);
+ Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider);
+
+ Mockito.when(_vrProviderDao.persist(Mockito.any(VirtualRouterProviderVO.class))).thenReturn(validElement);
+
+ DataCenterVO dc = new DataCenterVO
+ (1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
+ Mockito.when(_configMgr.getZone(Mockito.anyLong())).thenReturn(dc);
+ }
+
+ //TEST FOR getProvider() method
+
+ @Test
+ public void verifyProviderName() {
+ Provider pr = _lbEl.getProvider();
+ assertEquals("Wrong provider is returned", pr.getName(), Provider.InternalLbVm.getName());
+ }
+
+ //TEST FOR isReady() METHOD
+
+ @Test
+ public void verifyValidProviderState() {
+ PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
+ provider = setId(provider, validElId);
+ boolean isReady = _lbEl.isReady(provider);
+ assertTrue("Valid provider is returned as not ready", isReady);
+ }
+
+
+ @Test
+ public void verifyNonExistingProviderState() {
+ PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
+ provider = setId(provider, nonExistingElId);
+ boolean isReady = _lbEl.isReady(provider);
+ assertFalse("Non existing provider is returned as ready", isReady);
+ }
+
+
+ @Test
+ public void verifyInvalidProviderState() {
+ PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
+ provider = setId(provider, invalidElId);
+ boolean isReady = _lbEl.isReady(provider);
+ assertFalse("Not valid provider is returned as ready", isReady);
+ }
+
+ @Test
+ public void verifyNotEnabledProviderState() {
+ PhysicalNetworkServiceProviderVO provider = new PhysicalNetworkServiceProviderVO();
+ provider = setId(provider, notEnabledElId);
+ boolean isReady = _lbEl.isReady(provider);
+ assertFalse("Not enabled provider is returned as ready", isReady);
+ }
+
+ //TEST FOR canEnableIndividualServices METHOD
+ @Test
+ public void verifyCanEnableIndividualSvc() {
+ boolean result = _lbEl.canEnableIndividualServices();
+ assertTrue("Wrong value is returned by canEnableIndividualSvc", result);
+ }
+
+ //TEST FOR verifyServicesCombination METHOD
+ @Test
+ public void verifyServicesCombination() {
+ boolean result = _lbEl.verifyServicesCombination(new HashSet<Service>());
+ assertTrue("Wrong value is returned by verifyServicesCombination", result);
+ }
+
+
+ //TEST FOR applyIps METHOD
+ @Test
+ public void verifyApplyIps() throws ResourceUnavailableException {
+ List<PublicIp> ips = new ArrayList<PublicIp>();
+ boolean result = _lbEl.applyIps(new NetworkVO(), ips, new HashSet<Service>());
+ assertTrue("Wrong value is returned by applyIps method", result);
+ }
+
+
+ //TEST FOR updateHealthChecks METHOD
+ @Test
+ public void verifyUpdateHealthChecks() throws ResourceUnavailableException {
+ List<LoadBalancerTO> check = _lbEl.updateHealthChecks(new NetworkVO(), new ArrayList<LoadBalancingRule>());
+ assertNull("Wrong value is returned by updateHealthChecks method", check);
+ }
+
+ //TEST FOR validateLBRule METHOD
+ @Test
+ public void verifyValidateLBRule() throws ResourceUnavailableException {
+ ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin",
+ 1L, 1L, 1L, new Ip("10.10.10.1"), 1L, Scheme.Internal);
+ lb.setState(FirewallRule.State.Add);
+
+ LoadBalancingRule rule = new LoadBalancingRule(lb, null,
+ null, null, new Ip("10.10.10.1"));
+
+
+ boolean result = _lbEl.validateLBRule(new NetworkVO(), rule);
+ assertTrue("Wrong value is returned by validateLBRule method", result);
+ }
+
+
+ private static PhysicalNetworkServiceProviderVO setId(PhysicalNetworkServiceProviderVO vo, long id) {
+ PhysicalNetworkServiceProviderVO voToReturn = vo;
+ Class<?> c = voToReturn.getClass();
+ try {
+ Field f = c.getDeclaredField("id");
+ f.setAccessible(true);
+ f.setLong(voToReturn, id);
+ } catch (NoSuchFieldException ex) {
+ return null;
+ } catch (IllegalAccessException ex) {
+ return null;
+ }
+
+ return voToReturn;
+ }
+
+
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/ElementChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/ElementChildTestConfiguration.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/ElementChildTestConfiguration.java
deleted file mode 100644
index 6d55060..0000000
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/ElementChildTestConfiguration.java
+++ /dev/null
@@ -1,116 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.internallbvm;
-
-import java.io.IOException;
-
-import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
-import org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDao;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.ComponentScan.Filter;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.FilterType;
-import org.springframework.core.type.classreading.MetadataReader;
-import org.springframework.core.type.classreading.MetadataReaderFactory;
-import org.springframework.core.type.filter.TypeFilter;
-
-import com.cloud.configuration.ConfigurationManager;
-import com.cloud.dc.dao.AccountVlanMapDaoImpl;
-import com.cloud.network.NetworkManager;
-import com.cloud.network.NetworkModel;
-import com.cloud.network.dao.NetworkServiceMapDao;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
-import com.cloud.network.dao.VirtualRouterProviderDao;
-import com.cloud.user.AccountManager;
-import com.cloud.utils.component.SpringComponentScanUtils;
-import com.cloud.vm.dao.DomainRouterDao;
-
-@Configuration
-@ComponentScan(
- basePackageClasses={
- AccountVlanMapDaoImpl.class
- },
- includeFilters={@Filter(value=ElementChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
- useDefaultFilters=false
- )
-
-public class ElementChildTestConfiguration {
- public static class Library implements TypeFilter {
- @Bean
- public AccountManager accountManager() {
- return Mockito.mock(AccountManager.class);
- }
-
-
- @Bean
- public DomainRouterDao domainRouterDao() {
- return Mockito.mock(DomainRouterDao.class);
- }
-
- @Bean
- public VirtualRouterProviderDao virtualRouterProviderDao() {
- return Mockito.mock(VirtualRouterProviderDao.class);
- }
-
- @Bean
- public NetworkModel networkModel() {
- return Mockito.mock(NetworkModel.class);
- }
-
-
- @Bean
- public NetworkManager networkManager() {
- return Mockito.mock(NetworkManager.class);
- }
-
-
- @Bean
- public PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao() {
- return Mockito.mock(PhysicalNetworkServiceProviderDao.class);
- }
-
- @Bean
- public NetworkServiceMapDao networkServiceMapDao() {
- return Mockito.mock(NetworkServiceMapDao.class);
- }
-
- @Bean
- public InternalLoadBalancerVMManager internalLoadBalancerVMManager() {
- return Mockito.mock(InternalLoadBalancerVMManager.class);
- }
-
- @Bean
- public ConfigurationManager confugurationManager() {
- return Mockito.mock(ConfigurationManager.class);
- }
-
-
- @Bean
- public ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao() {
- return Mockito.mock(ApplicationLoadBalancerRuleDao.class);
- }
-
- @Override
- public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
- mdr.getClassMetadata().getClassName();
- ComponentScan cs = ElementChildTestConfiguration.class.getAnnotation(ComponentScan.class);
- return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMManagerTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMManagerTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMManagerTest.java
deleted file mode 100644
index ddf488b..0000000
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMManagerTest.java
+++ /dev/null
@@ -1,388 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.internallbvm;
-
-import java.lang.reflect.Field;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.inject.Inject;
-
-import junit.framework.TestCase;
-
-import org.apache.cloudstack.network.lb.ApplicationLoadBalancerRuleVO;
-import org.apache.cloudstack.network.lb.InternalLoadBalancerVMManager;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import com.cloud.agent.AgentManager;
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.manager.Commands;
-import com.cloud.dc.DataCenter.NetworkType;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.exception.AgentUnavailableException;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.OperationTimedoutException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.network.NetworkModel;
-import com.cloud.network.dao.NetworkVO;
-import com.cloud.network.lb.LoadBalancingRule;
-import com.cloud.network.router.VirtualRouter;
-import com.cloud.network.router.VirtualRouter.Role;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.network.rules.LoadBalancerContainer.Scheme;
-import com.cloud.service.ServiceOfferingVO;
-import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.user.Account;
-import com.cloud.user.AccountManager;
-import com.cloud.user.AccountVO;
-import com.cloud.user.User;
-import com.cloud.utils.component.ComponentContext;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.net.Ip;
-import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.NicVO;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.VirtualMachineManager;
-import com.cloud.vm.dao.DomainRouterDao;
-import com.cloud.vm.dao.NicDao;
-
-/**
- * Set of unittests for InternalLoadBalancerVMManager
- *
- */
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations="classpath:/lb_mgr.xml")
-public class InternalLBVMManagerTest extends TestCase {
- //The interface to test
- @Inject InternalLoadBalancerVMManager _lbVmMgr;
-
- //Mocked interfaces
- @Inject AccountManager _accountMgr;
- @Inject ServiceOfferingDao _svcOffDao;
- @Inject DomainRouterDao _domainRouterDao;
- @Inject NicDao _nicDao;
- @Inject AgentManager _agentMgr;
- @Inject NetworkModel _ntwkModel;
- @Inject VirtualMachineManager _itMgr;
- @Inject DataCenterDao _dcDao;
-
- long validNtwkId = 1L;
- long invalidNtwkId = 2L;
- String requestedIp = "10.1.1.1";
- DomainRouterVO vm = null;
- NetworkVO ntwk = createNetwork();
- long validVmId = 1L;
- long invalidVmId = 2L;
-
- @Before
- public void setUp() {
- //mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
- Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
- ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
- 1, 1, 1, false, "alena", false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
- off = setId(off, 1);
- Mockito.when(_svcOffDao.persistSystemServiceOffering(Mockito.any(ServiceOfferingVO.class))).thenReturn(off);
-
- ComponentContext.initComponentsLifeCycle();
-
- vm = new DomainRouterVO(1L,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
- false, 0,false,null,false,false,
- VirtualMachine.Type.InternalLoadBalancerVm, null);
- vm.setRole(Role.INTERNAL_LB_VM);
- vm = setId(vm, 1);
- vm.setPrivateIpAddress("10.2.2.2");
- NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
- nic.setIp4Address(requestedIp);
-
- List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
- List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
- nonEmptyList.add(vm);
-
- Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
- Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
-
- Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
- Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
-
- Answer answer= new Answer(null, true, null);
- Answer[] answers = new Answer[1];
- answers[0] = answer;
-
- try {
- Mockito.when(_agentMgr.send(Mockito.anyLong(), Mockito.any(Commands.class))).thenReturn(answers);
- } catch (AgentUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (OperationTimedoutException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- createNetwork();
- Mockito.when(_ntwkModel.getNetwork(Mockito.anyLong())).thenReturn(ntwk);
-
-
- Mockito.when(_itMgr.toNicTO(Mockito.any(NicProfile.class), Mockito.any(HypervisorType.class))).thenReturn(null);
- Mockito.when(_domainRouterDao.findById(Mockito.anyLong())).thenReturn(vm);
- DataCenterVO dc = new DataCenterVO
- (1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
- Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
-
-
- try {
- Mockito.when(_itMgr.expunge(Mockito.any(DomainRouterVO.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
- Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
-
- }
-
- protected NetworkVO createNetwork() {
- ntwk = new NetworkVO();
- try {
- ntwk.setBroadcastUri(new URI("somevlan"));
- } catch (URISyntaxException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- ntwk = setId(ntwk, 1L);
- return ntwk;
- }
-
- //TESTS FOR findInternalLbVms METHOD
-
- @Test
- public void findInternalLbVmsForInvalidNetwork() {
- List<? extends VirtualRouter> vms = _lbVmMgr.findInternalLbVms(invalidNtwkId, new Ip(requestedIp));
- assertTrue("Non empty vm list was returned for invalid network id", vms.isEmpty());
- }
-
- @Test
- public void findInternalLbVmsForValidNetwork() {
- List<? extends VirtualRouter> vms = _lbVmMgr.findInternalLbVms(validNtwkId, new Ip(requestedIp));
- assertTrue("Empty vm list was returned for valid network id", !vms.isEmpty());
- }
-
-
- //TESTS FOR applyLoadBalancingRules METHOD
- @Test
- public void applyEmptyRulesSet() {
- boolean result = false;
- List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
- try {
- result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), new ArrayList<LoadBalancingRule>(), vms);
- } catch (ResourceUnavailableException e) {
-
- } finally {
- assertTrue("Got failure when tried to apply empty list of rules", result);
- }
- }
-
- @Test (expected = CloudRuntimeException.class)
- public void applyWithEmptyVmsSet() {
- boolean result = false;
- List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
- List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
- LoadBalancingRule rule = new LoadBalancingRule(null, null,
- null, null, null);
-
- rules.add(rule);
- try {
- result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
- } catch (ResourceUnavailableException e) {
- } finally {
- assertFalse("Got success when tried to apply with the empty internal lb vm list", result);
- }
- }
-
- @Test (expected = ResourceUnavailableException.class)
- public void applyToVmInStartingState() throws ResourceUnavailableException {
- boolean result = false;
- List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
- vm.setState(State.Starting);
- vms.add(vm);
-
- List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
- LoadBalancingRule rule = new LoadBalancingRule(null, null,
- null, null, null);
-
- rules.add(rule);
- try {
- result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
- } finally {
- assertFalse("Rules were applied to vm in Starting state", result);
- }
- }
-
-
- @Test
- public void applyToVmInStoppedState() throws ResourceUnavailableException {
- boolean result = false;
- List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
- vm.setState(State.Stopped);
- vms.add(vm);
-
- List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
- LoadBalancingRule rule = new LoadBalancingRule(null, null,
- null, null, null);
-
- rules.add(rule);
- try {
- result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
- } finally {
- assertTrue("Rules failed to apply to vm in Stopped state", result);
- }
- }
-
-
- @Test
- public void applyToVmInStoppingState() throws ResourceUnavailableException {
- boolean result = false;
- List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
- vm.setState(State.Stopping);
- vms.add(vm);
-
- List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
- LoadBalancingRule rule = new LoadBalancingRule(null, null,
- null, null, null);
-
- rules.add(rule);
- try {
- result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
- } finally {
- assertTrue("Rules failed to apply to vm in Stopping state", result);
- }
- }
-
-
- @Test
- public void applyToVmInRunningState() throws ResourceUnavailableException {
- boolean result = false;
- List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
- vm.setState(State.Running);
- vms.add(vm);
-
- List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
- ApplicationLoadBalancerRuleVO lb = new ApplicationLoadBalancerRuleVO(null, null, 22, 22, "roundrobin",
- 1L, 1L, 1L, new Ip(requestedIp), 1L, Scheme.Internal);
- lb.setState(FirewallRule.State.Add);
-
- LoadBalancingRule rule = new LoadBalancingRule(lb, null,
- null, null, new Ip(requestedIp));
-
- rules.add(rule);
-
- ntwk.getId();
-
- try {
- result = _lbVmMgr.applyLoadBalancingRules(ntwk, rules, vms);
- } finally {
- assertTrue("Rules failed to apply to vm in Running state", result);
- }
- }
-
-
- //TESTS FOR destroyInternalLbVm METHOD
- @Test
- public void destroyNonExistingVM() throws ResourceUnavailableException, ConcurrentOperationException {
- boolean result = false;
-
- try {
- result = _lbVmMgr.destroyInternalLbVm(invalidVmId, new AccountVO(), 1L);
- } finally {
- assertTrue("Failed to destroy non-existing vm", result);
- }
- }
-
- @Test
- public void destroyExistingVM() throws ResourceUnavailableException, ConcurrentOperationException {
- boolean result = false;
-
- try {
- result = _lbVmMgr.destroyInternalLbVm(validVmId, new AccountVO(), 1L);
- } finally {
- assertTrue("Failed to destroy valid vm", result);
- }
- }
-
-
- private static ServiceOfferingVO setId(ServiceOfferingVO vo, long id) {
- ServiceOfferingVO voToReturn = vo;
- Class<?> c = voToReturn.getClass();
- try {
- Field f = c.getSuperclass().getDeclaredField("id");
- f.setAccessible(true);
- f.setLong(voToReturn, id);
- } catch (NoSuchFieldException ex) {
- return null;
- } catch (IllegalAccessException ex) {
- return null;
- }
-
- return voToReturn;
- }
-
-
- private static NetworkVO setId(NetworkVO vo, long id) {
- NetworkVO voToReturn = vo;
- Class<?> c = voToReturn.getClass();
- try {
- Field f = c.getDeclaredField("id");
- f.setAccessible(true);
- f.setLong(voToReturn, id);
- } catch (NoSuchFieldException ex) {
- return null;
- } catch (IllegalAccessException ex) {
- return null;
- }
-
- return voToReturn;
- }
-
- private static DomainRouterVO setId(DomainRouterVO vo, long id) {
- DomainRouterVO voToReturn = vo;
- Class<?> c = voToReturn.getClass();
- try {
- Field f = c.getSuperclass().getDeclaredField("id");
- f.setAccessible(true);
- f.setLong(voToReturn, id);
- } catch (NoSuchFieldException ex) {
- return null;
- } catch (IllegalAccessException ex) {
- return null;
- }
-
- return voToReturn;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMServiceTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMServiceTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMServiceTest.java
deleted file mode 100644
index f271311..0000000
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLBVMServiceTest.java
+++ /dev/null
@@ -1,291 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.internallbvm;
-
-import java.lang.reflect.Field;
-import java.util.Map;
-
-import javax.inject.Inject;
-
-import junit.framework.TestCase;
-
-import org.apache.cloudstack.network.lb.InternalLoadBalancerVMService;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.OperationTimedoutException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.exception.StorageUnavailableException;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.network.router.VirtualRouter;
-import com.cloud.network.router.VirtualRouter.Role;
-import com.cloud.service.ServiceOfferingVO;
-import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.user.Account;
-import com.cloud.user.AccountManager;
-import com.cloud.user.AccountVO;
-import com.cloud.user.User;
-import com.cloud.utils.component.ComponentContext;
-import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineManager;
-import com.cloud.vm.dao.DomainRouterDao;
-
-/**
- * Set of unittests for InternalLoadBalancerVMService
- *
- */
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations="classpath:/lb_svc.xml")
-@SuppressWarnings("unchecked")
-public class InternalLBVMServiceTest extends TestCase {
- //The interface to test
- @Inject InternalLoadBalancerVMService _lbVmSvc;
-
- //Mocked interfaces
- @Inject AccountManager _accountMgr;
- @Inject ServiceOfferingDao _svcOffDao;
- @Inject DomainRouterDao _domainRouterDao;
- @Inject VirtualMachineManager _itMgr;
-
- long validVmId = 1L;
- long nonExistingVmId = 2L;
- long nonInternalLbVmId = 3L;
-
- @Before
- public void setUp() {
- //mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
- Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
- ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
- 1, 1, 1, false, "alena", false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
- off = setId(off, 1);
- Mockito.when(_svcOffDao.persistSystemServiceOffering(Mockito.any(ServiceOfferingVO.class))).thenReturn(off);
-
- ComponentContext.initComponentsLifeCycle();
-
- DomainRouterVO validVm = new DomainRouterVO(validVmId,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
- false, 0,false,null,false,false,
- VirtualMachine.Type.InternalLoadBalancerVm, null);
- validVm.setRole(Role.INTERNAL_LB_VM);
- DomainRouterVO nonInternalLbVm = new DomainRouterVO(validVmId,off.getId(),1,"alena",1,HypervisorType.XenServer,1,1,1,
- false, 0,false,null,false,false,
- VirtualMachine.Type.DomainRouter, null);
- nonInternalLbVm.setRole(Role.VIRTUAL_ROUTER);
-
- Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm);
- Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null);
- Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm);
-
- try {
- Mockito.when(_itMgr.start(Mockito.any(DomainRouterVO.class),
- Mockito.any(Map.class), Mockito.any(User.class), Mockito.any(Account.class), Mockito.any(DeploymentPlan.class))).thenReturn(validVm);
- } catch (InsufficientCapacityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- try {
- Mockito.when(_itMgr.advanceStop(Mockito.any(DomainRouterVO.class), Mockito.any(Boolean.class), Mockito.any(User.class), Mockito.any(Account.class))).thenReturn(true);
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (OperationTimedoutException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConcurrentOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- //TESTS FOR START COMMAND
-
-
- @Test (expected = InvalidParameterValueException.class)
- public void startNonExistingVm() {
- String expectedExcText = null;
- try {
- _lbVmSvc.startInternalLbVm(nonExistingVmId, _accountMgr.getAccount(1L), 1L);
- } catch (StorageUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InsufficientCapacityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConcurrentOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvalidParameterValueException e) {
- expectedExcText = e.getMessage();
- throw e;
- } finally {
- assertEquals("Test failed. The non-existing internal lb vm was attempted to start"
- + expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
- }
- }
-
- @Test (expected = InvalidParameterValueException.class)
- public void startNonInternalLbVmVm() {
- String expectedExcText = null;
- try {
- _lbVmSvc.startInternalLbVm(nonInternalLbVmId, _accountMgr.getAccount(1L), 1L);
- } catch (StorageUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InsufficientCapacityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConcurrentOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }catch (InvalidParameterValueException e) {
- expectedExcText = e.getMessage();
- throw e;
- } finally {
- assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to start"
- + expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
- }
- }
-
- @Test
- public void startValidLbVmVm() {
- VirtualRouter vr = null;
- try {
- vr = _lbVmSvc.startInternalLbVm(validVmId, _accountMgr.getAccount(1L), 1L);
- } catch (StorageUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InsufficientCapacityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConcurrentOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- assertNotNull("Internal LB vm is null which means it failed to start " + vr, vr);
- }
- }
-
-
- //TEST FOR STOP COMMAND
- @Test (expected = InvalidParameterValueException.class)
- public void stopNonExistingVm() {
- String expectedExcText = null;
- try {
- _lbVmSvc.stopInternalLbVm(nonExistingVmId, false,_accountMgr.getAccount(1L), 1L);
- } catch (StorageUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConcurrentOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvalidParameterValueException e) {
- expectedExcText = e.getMessage();
- throw e;
- } finally {
- assertEquals("Test failed. The non-existing internal lb vm was attempted to stop"
- + expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
- }
- }
-
-
- @Test (expected = InvalidParameterValueException.class)
- public void stopNonInternalLbVmVm() {
- String expectedExcText = null;
- try {
- _lbVmSvc.stopInternalLbVm(nonInternalLbVmId, false, _accountMgr.getAccount(1L), 1L);
- } catch (StorageUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConcurrentOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }catch (InvalidParameterValueException e) {
- expectedExcText = e.getMessage();
- throw e;
- } finally {
- assertEquals("Test failed. The existing vm of not Internal lb vm type was attempted to stop"
- + expectedExcText, expectedExcText, "Can't find internal lb vm by id specified");
- }
- }
-
-
- @Test
- public void stopValidLbVmVm() {
- VirtualRouter vr = null;
- try {
- vr = _lbVmSvc.stopInternalLbVm(validVmId, false, _accountMgr.getAccount(1L), 1L);
- } catch (StorageUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ConcurrentOperationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ResourceUnavailableException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
- assertNotNull("Internal LB vm is null which means it failed to stop " + vr, vr);
- }
- }
-
-
-
- private static ServiceOfferingVO setId(ServiceOfferingVO vo, long id) {
- ServiceOfferingVO voToReturn = vo;
- Class<?> c = voToReturn.getClass();
- try {
- Field f = c.getSuperclass().getDeclaredField("id");
- f.setAccessible(true);
- f.setLong(voToReturn, id);
- } catch (NoSuchFieldException ex) {
- return null;
- } catch (IllegalAccessException ex) {
- return null;
- }
-
- return voToReturn;
- }
-}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLbElementServiceTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLbElementServiceTest.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLbElementServiceTest.java
deleted file mode 100644
index c2d311d..0000000
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/InternalLbElementServiceTest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.internallbvm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import javax.inject.Inject;
-
-import org.apache.cloudstack.network.element.InternalLoadBalancerElementService;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.network.VirtualRouterProvider;
-import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
-import com.cloud.network.dao.VirtualRouterProviderDao;
-import com.cloud.network.element.VirtualRouterProviderVO;
-import com.cloud.user.AccountManager;
-import com.cloud.utils.component.ComponentContext;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations="classpath:/lb_element.xml")
-public class InternalLbElementServiceTest {
- //The interface to test
- @Inject InternalLoadBalancerElementService _lbElSvc;
-
- //Mocked interfaces
- @Inject AccountManager _accountMgr;
- @Inject VirtualRouterProviderDao _vrProviderDao;
- @Inject PhysicalNetworkServiceProviderDao _pNtwkProviderDao;
-
- long validElId = 1L;
- long nonExistingElId = 2L;
- long invalidElId = 3L; //not of VirtualRouterProviderType
-
- long validProviderId = 1L;
- long nonExistingProviderId = 2L;
- long invalidProviderId = 3L;
-
-
- @Before
- public void setUp() {
-
- ComponentContext.initComponentsLifeCycle();
- VirtualRouterProviderVO validElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.InternalLbVm);
- VirtualRouterProviderVO invalidElement = new VirtualRouterProviderVO(1, VirtualRouterProviderType.VirtualRouter);
-
- Mockito.when(_vrProviderDao.findById(validElId)).thenReturn(validElement);
- Mockito.when(_vrProviderDao.findById(invalidElId)).thenReturn(invalidElement);
-
- Mockito.when(_vrProviderDao.persist(validElement)).thenReturn(validElement);
-
- Mockito.when(_vrProviderDao.findByNspIdAndType(validProviderId, VirtualRouterProviderType.InternalLbVm)).thenReturn(validElement);
-
- PhysicalNetworkServiceProviderVO validProvider = new PhysicalNetworkServiceProviderVO(1, "InternalLoadBalancerElement");
- PhysicalNetworkServiceProviderVO invalidProvider = new PhysicalNetworkServiceProviderVO(1, "Invalid name!");
-
- Mockito.when(_pNtwkProviderDao.findById(validProviderId)).thenReturn(validProvider);
- Mockito.when(_pNtwkProviderDao.findById(invalidProviderId)).thenReturn(invalidProvider);
-
- Mockito.when(_vrProviderDao.persist(Mockito.any(VirtualRouterProviderVO.class))).thenReturn(validElement);
- }
-
- //TESTS FOR getInternalLoadBalancerElement METHOD
-
-
- @Test (expected = InvalidParameterValueException.class)
- public void findNonExistingVm() {
- String expectedExcText = null;
- try {
- _lbElSvc.getInternalLoadBalancerElement(nonExistingElId);
- } catch (InvalidParameterValueException e) {
- expectedExcText = e.getMessage();
- throw e;
- } finally {
- assertEquals("Test failed. The non-existing intenral lb provider was found"
- + expectedExcText, expectedExcText, "Unable to find InternalLoadBalancerElementService by id");
- }
- }
-
-
- @Test (expected = InvalidParameterValueException.class)
- public void findInvalidVm() {
- String expectedExcText = null;
- try {
- _lbElSvc.getInternalLoadBalancerElement(invalidElId);
- } catch (InvalidParameterValueException e) {
- expectedExcText = e.getMessage();
- throw e;
- } finally {
- assertEquals("Test failed. The non-existing intenral lb provider was found"
- + expectedExcText, expectedExcText, "Unable to find InternalLoadBalancerElementService by id");
- }
- }
-
-
- @Test
- public void findValidVm() {
- VirtualRouterProvider provider = null;
- try {
- provider = _lbElSvc.getInternalLoadBalancerElement(validElId);
- } finally {
- assertNotNull("Test failed. Couldn't find the VR provider by the valid id",provider);
- }
- }
-
-
- //TESTS FOR configureInternalLoadBalancerElement METHOD
-
- @Test (expected = InvalidParameterValueException.class)
- public void configureNonExistingVm() {
-
- _lbElSvc.configureInternalLoadBalancerElement(nonExistingElId, true);
-
- }
-
-
- @Test (expected = InvalidParameterValueException.class)
- public void ConfigureInvalidVm() {
- _lbElSvc.configureInternalLoadBalancerElement(invalidElId, true);
- }
-
-
- @Test
- public void enableProvider() {
- VirtualRouterProvider provider = null;
- try {
- provider = _lbElSvc.configureInternalLoadBalancerElement(validElId, true);
- } finally {
- assertNotNull("Test failed. Couldn't find the VR provider by the valid id ",provider);
- assertTrue("Test failed. The provider wasn't eanbled ", provider.isEnabled());
- }
- }
-
- @Test
- public void disableProvider() {
- VirtualRouterProvider provider = null;
- try {
- provider = _lbElSvc.configureInternalLoadBalancerElement(validElId, false);
- } finally {
- assertNotNull("Test failed. Couldn't find the VR provider by the valid id ",provider);
- assertFalse("Test failed. The provider wasn't disabled ", provider.isEnabled());
- }
- }
-
- //TESTS FOR addInternalLoadBalancerElement METHOD
-
- @Test (expected = InvalidParameterValueException.class)
- public void addToNonExistingProvider() {
-
- _lbElSvc.addInternalLoadBalancerElement(nonExistingProviderId);
-
- }
-
- @Test (expected = InvalidParameterValueException.class)
- public void addToInvalidProvider() {
- _lbElSvc.addInternalLoadBalancerElement(invalidProviderId);
- }
-
- @Test
- public void addToExistingProvider() {
- _lbElSvc.addInternalLoadBalancerElement(validProviderId);
- }
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b7cf8700/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/LbChildTestConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/LbChildTestConfiguration.java b/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/LbChildTestConfiguration.java
deleted file mode 100644
index bdad5f4..0000000
--- a/plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvm/LbChildTestConfiguration.java
+++ /dev/null
@@ -1,164 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package org.apache.cloudstack.internallbvm;
-
-import java.io.IOException;
-
-import org.apache.cloudstack.network.lb.dao.ApplicationLoadBalancerRuleDao;
-import org.mockito.Mockito;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.ComponentScan.Filter;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.FilterType;
-import org.springframework.core.type.classreading.MetadataReader;
-import org.springframework.core.type.classreading.MetadataReaderFactory;
-import org.springframework.core.type.filter.TypeFilter;
-
-import com.cloud.agent.AgentManager;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.dao.AccountVlanMapDaoImpl;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.network.NetworkManager;
-import com.cloud.network.NetworkModel;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
-import com.cloud.network.dao.VirtualRouterProviderDao;
-import com.cloud.network.lb.LoadBalancingRulesManager;
-import com.cloud.offerings.dao.NetworkOfferingDao;
-import com.cloud.resource.ResourceManager;
-import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.user.AccountManager;
-import com.cloud.utils.component.SpringComponentScanUtils;
-import com.cloud.vm.VirtualMachineManager;
-import com.cloud.vm.dao.DomainRouterDao;
-import com.cloud.vm.dao.NicDao;
-
-@Configuration
-@ComponentScan(
- basePackageClasses={
- AccountVlanMapDaoImpl.class
- },
- includeFilters={@Filter(value=LbChildTestConfiguration.Library.class, type=FilterType.CUSTOM)},
- useDefaultFilters=false
- )
-
- public class LbChildTestConfiguration {
-
- public static class Library implements TypeFilter {
-
-
- @Bean
- public AccountManager accountManager() {
- return Mockito.mock(AccountManager.class);
- }
-
- @Bean
- public VirtualMachineManager virtualMachineManager() {
- return Mockito.mock(VirtualMachineManager.class);
- }
-
- @Bean
- public DomainRouterDao domainRouterDao() {
- return Mockito.mock(DomainRouterDao.class);
- }
-
- @Bean
- public ConfigurationDao configurationDao() {
- return Mockito.mock(ConfigurationDao.class);
- }
-
- @Bean
- public VirtualRouterProviderDao virtualRouterProviderDao() {
- return Mockito.mock(VirtualRouterProviderDao.class);
- }
-
- @Bean
- public ApplicationLoadBalancerRuleDao applicationLoadBalancerRuleDao() {
- return Mockito.mock(ApplicationLoadBalancerRuleDao.class);
- }
-
- @Bean
- public NetworkModel networkModel() {
- return Mockito.mock(NetworkModel.class);
- }
-
- @Bean
- public LoadBalancingRulesManager loadBalancingRulesManager() {
- return Mockito.mock(LoadBalancingRulesManager.class);
- }
-
- @Bean
- public NicDao nicDao() {
- return Mockito.mock(NicDao.class);
- }
-
- @Bean
- public NetworkDao networkDao() {
- return Mockito.mock(NetworkDao.class);
- }
-
- @Bean
- public NetworkManager networkManager() {
- return Mockito.mock(NetworkManager.class);
- }
-
- @Bean
- public ServiceOfferingDao serviceOfferingDao() {
- return Mockito.mock(ServiceOfferingDao.class);
- }
-
- @Bean
- public PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao() {
- return Mockito.mock(PhysicalNetworkServiceProviderDao.class);
- }
-
- @Bean
- public NetworkOfferingDao networkOfferingDao() {
- return Mockito.mock(NetworkOfferingDao.class);
- }
-
- @Bean
- public VMTemplateDao vmTemplateDao() {
- return Mockito.mock(VMTemplateDao.class);
- }
-
- @Bean
- public ResourceManager resourceManager() {
- return Mockito.mock(ResourceManager.class);
- }
-
- @Bean
- public AgentManager agentManager() {
- return Mockito.mock(AgentManager.class);
- }
-
- @Bean
- public DataCenterDao dataCenterDao() {
- return Mockito.mock(DataCenterDao.class);
- }
-
- @Override
- public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException {
- mdr.getClassMetadata().getClassName();
- ComponentScan cs = LbChildTestConfiguration.class.getAnnotation(ComponentScan.class);
- return SpringComponentScanUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(), cs);
- }
-
- }
-}