cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [5/7] git commit: updated refs/heads/4.6 to 6d3fffa
Date Mon, 07 Dec 2015 20:19:00 GMT
CLOUDSTACK-9106 - Adds a test to cover the changes in the applyVpnUsers() method

   - Changed the NetworkTopologyContext class just to make the private member accessible from
the test
   - Added a test class to cover the positive scenario of the VpcVirtualRouterElementTest.applyVpnUsers()
method.
   - Covering when there is either no VPC or no routers.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/5973f4ea
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/5973f4ea
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/5973f4ea

Branch: refs/heads/4.6
Commit: 5973f4ea77ed3328e74c79069dcf5b1eff2f049f
Parents: 13eb789
Author: Wilder Rodrigues <wrodrigues@schubergphilis.com>
Authored: Mon Dec 7 13:42:29 2015 +0100
Committer: Wilder Rodrigues <wrodrigues@schubergphilis.com>
Committed: Mon Dec 7 13:42:29 2015 +0100

----------------------------------------------------------------------
 .../topology/NetworkTopologyContext.java        |  16 ++
 .../element/VpcVirtualRouterElementTest.java    | 188 +++++++++++++++++++
 2 files changed, 204 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5973f4ea/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
b/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
index 8ddc836..473770c 100644
--- a/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
+++ b/server/src/org/apache/cloudstack/network/topology/NetworkTopologyContext.java
@@ -49,4 +49,20 @@ public class NetworkTopologyContext {
         }
         return _flyweight.get(dc.getNetworkType());
     }
+
+    /**
+     * Method used for tests purpose only. Please do not use it to set the AdvanceNetworkTopology
and it is managed by Spring.
+     * @param advancedNetworkTopology
+     */
+    public void setAdvancedNetworkTopology(final AdvancedNetworkTopology advancedNetworkTopology)
{
+        _advancedNetworkTopology = advancedNetworkTopology;
+    }
+
+    /**
+     *  Method used for tests purpose only. Please do not use it to set the BasicNetworkTopology
and it is managed by Spring.
+     * @param basicNetworkTopology
+     */
+    public void setBasicNetworkTopology(final BasicNetworkTopology basicNetworkTopology)
{
+        _basicNetworkTopology = basicNetworkTopology;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/5973f4ea/server/test/com/cloud/network/element/VpcVirtualRouterElementTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/element/VpcVirtualRouterElementTest.java b/server/test/com/cloud/network/element/VpcVirtualRouterElementTest.java
new file mode 100644
index 0000000..d044f5b
--- /dev/null
+++ b/server/test/com/cloud/network/element/VpcVirtualRouterElementTest.java
@@ -0,0 +1,188 @@
+// 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 com.cloud.network.element;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.network.topology.AdvancedNetworkTopology;
+import org.apache.cloudstack.network.topology.BasicNetworkTopology;
+import org.apache.cloudstack.network.topology.NetworkTopologyContext;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.RemoteAccessVpn;
+import com.cloud.network.VpnUser;
+import com.cloud.network.router.VpcVirtualNetworkApplianceManagerImpl;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.utils.db.EntityManager;
+import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.dao.DomainRouterDao;
+
+@RunWith(MockitoJUnitRunner.class)
+public class VpcVirtualRouterElementTest {
+    @Mock
+    DataCenterDao _dcDao;
+    @Mock private DomainRouterDao _routerDao;
+
+    @Mock
+    EntityManager _entityMgr;
+
+    @Mock
+    NetworkTopologyContext networkTopologyContext;
+
+    @InjectMocks
+    VpcVirtualNetworkApplianceManagerImpl _vpcRouterMgr;
+
+    @InjectMocks
+    VpcVirtualRouterElement vpcVirtualRouterElement;
+
+
+    @Test
+    public void testApplyVpnUsers() {
+        vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
+
+        final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
+        final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
+
+        networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
+        networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
+        networkTopologyContext.init();
+
+        final Vpc vpc = Mockito.mock(Vpc.class);
+        final DataCenterVO dataCenterVO = Mockito.mock(DataCenterVO.class);
+        final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
+        final DomainRouterVO domainRouterVO1 = Mockito.mock(DomainRouterVO.class);
+        final DomainRouterVO domainRouterVO2 = Mockito.mock(DomainRouterVO.class);
+        final VpnUser vpnUser1 = Mockito.mock(VpnUser.class);
+        final VpnUser vpnUser2 = Mockito.mock(VpnUser.class);
+
+        final List<VpnUser> users = new ArrayList<VpnUser>();
+        users.add(vpnUser1);
+        users.add(vpnUser2);
+
+        final List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
+        routers.add(domainRouterVO1);
+        routers.add(domainRouterVO2);
+
+        final Long vpcId = new Long(1l);
+        final Long zoneId = new Long(1l);
+
+        when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
+        when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(routers);
+        when(_entityMgr.findById(Vpc.class, vpcId)).thenReturn(vpc);
+        when(vpc.getZoneId()).thenReturn(zoneId);
+        when(_dcDao.findById(zoneId)).thenReturn(dataCenterVO);
+        when(networkTopologyContext.retrieveNetworkTopology(dataCenterVO)).thenReturn(advancedNetworkTopology);
+
+        try {
+            when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO1)).thenReturn(new
String[]{"user1", "user2"});
+            when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO2)).thenReturn(new
String[]{"user3", "user4"});
+        } catch (final ResourceUnavailableException e) {
+            fail(e.getMessage());
+        }
+
+        try {
+            final String [] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn,
users);
+
+            assertNotNull(results);
+            assertEquals(results[0], "user1");
+            assertEquals(results[1], "user2");
+            assertEquals(results[2], "user3");
+            assertEquals(results[3], "user4");
+        } catch (final ResourceUnavailableException e) {
+            fail(e.getMessage());
+        }
+
+        verify(remoteAccessVpn, times(1)).getVpcId();
+        verify(vpc, times(1)).getZoneId();
+        verify(_dcDao, times(1)).findById(zoneId);
+        verify(networkTopologyContext, times(1)).retrieveNetworkTopology(dataCenterVO);
+    }
+
+    @Test
+    public void testApplyVpnUsersException1() {
+        vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
+
+        final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
+        final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
+
+        networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
+        networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
+        networkTopologyContext.init();
+
+        final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
+        final List<VpnUser> users = new ArrayList<VpnUser>();
+
+        when(remoteAccessVpn.getVpcId()).thenReturn(null);
+
+        try {
+            final String [] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn,
users);
+            assertNull(results);
+        } catch (final ResourceUnavailableException e) {
+            fail(e.getMessage());
+        }
+
+        verify(remoteAccessVpn, times(1)).getVpcId();
+    }
+
+    @Test
+    public void testApplyVpnUsersException2() {
+        vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
+
+        final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
+        final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
+
+        networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
+        networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
+        networkTopologyContext.init();
+
+        final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
+
+        final List<VpnUser> users = new ArrayList<VpnUser>();
+
+        final Long vpcId = new Long(1l);
+
+        when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
+        when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(null);
+
+        try {
+            final String [] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn,
users);
+
+            assertNull(results);
+        } catch (final ResourceUnavailableException e) {
+            fail(e.getMessage());
+        }
+
+        verify(remoteAccessVpn, times(1)).getVpcId();
+    }
+}
\ No newline at end of file


Mime
View raw message