Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

package org.apache.cloudstack.network.contrail.model;

import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
Expand Down Expand Up @@ -44,26 +45,19 @@

public class InstanceIpModelTest extends TestCase {
private static final Logger s_logger =
Logger.getLogger(InstanceIpModelTest.class);
Logger.getLogger(InstanceIpModelTest.class);

@Test
public void testCreateInstanceIp() throws IOException {

ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
ModelController controller = mock(ModelController.class);
ModelController controller = mock(ModelController.class);
ApiConnector api = new ApiConnectorMock(null, 0);
when(controller.getApiAccessor()).thenReturn(api);
when(controller.getManager()).thenReturn(contrailMgr);

// Create Virtual-Network (VN)
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(Network.State.Implemented);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
NetworkVO network = MockNetworkVO.getNetwork(Network.State.Implemented);
NetworkDao networkDao = mock(NetworkDao.class);
when(networkDao.findById(anyLong())).thenReturn(network);
when(controller.getNetworkDao()).thenReturn(networkDao);
Expand All @@ -86,7 +80,7 @@ public void testCreateInstanceIp() throws IOException {
when(vm.getState()).thenReturn(VirtualMachine.State.Running);
when(vm.getDomainId()).thenReturn(10L);
when(vm.getAccountId()).thenReturn(42L);
UserVmDao VmDao = mock(UserVmDao.class);
UserVmDao VmDao = mock(UserVmDao.class);
when(VmDao.findById(anyLong())).thenReturn(null);
when(controller.getVmDao()).thenReturn(VmDao);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.network.contrail.model;

import com.cloud.network.Network;
import com.cloud.network.dao.NetworkVO;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class MockNetworkVO {

private NetworkVO network;

MockNetworkVO(Network.State state) {
network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(state);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
}

public NetworkVO getNetwork() {
return network;
}

public static NetworkVO getNetwork(Network.State state) {
MockNetworkVO mockNetwork = new MockNetworkVO(state);
return mockNetwork.getNetwork();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.

package org.apache.cloudstack.network.contrail.model;

import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
Expand Down Expand Up @@ -45,27 +46,20 @@

public class VMInterfaceModelTest extends TestCase {
private static final Logger s_logger =
Logger.getLogger(VMInterfaceModelTest.class);
Logger.getLogger(VMInterfaceModelTest.class);

@Test
public void testCreateVMInterface() throws IOException {

String uuid;
ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
ModelController controller = mock(ModelController.class);
ModelController controller = mock(ModelController.class);
ApiConnector api = new ApiConnectorMock(null, 0);
when(controller.getManager()).thenReturn(contrailMgr);
when(controller.getApiAccessor()).thenReturn(api);

// Create Virtual-Network (VN)
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(Network.State.Implemented);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
NetworkVO network = MockNetworkVO.getNetwork(Network.State.Implemented);
NetworkDao networkDao = mock(NetworkDao.class);
when(networkDao.findById(anyLong())).thenReturn(network);
when(controller.getNetworkDao()).thenReturn(networkDao);
Expand All @@ -88,7 +82,7 @@ public void testCreateVMInterface() throws IOException {
when(vm.getState()).thenReturn(VirtualMachine.State.Running);
when(vm.getDomainId()).thenReturn(10L);
when(vm.getAccountId()).thenReturn(42L);
UserVmDao VmDao = mock(UserVmDao.class);
UserVmDao VmDao = mock(UserVmDao.class);
when(VmDao.findById(anyLong())).thenReturn(null);
when(controller.getVmDao()).thenReturn(VmDao);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ public class VirtualMachineModelTest extends TestCase {
@Test
public void testVirtualMachineDBLookup() {
ModelDatabase db = new ModelDatabase();
VMInstanceVO vm = mock(VMInstanceVO.class);
VMInstanceVO vm = mock(VMInstanceVO.class);

// Create 3 dummy Virtual Machine model objects
// Add these models to database.
// Each VM is identified by unique UUId.
VirtualMachineModel vm0 = new VirtualMachineModel(vm, "fbc1f8fa-4b78-45ee-bba0-b551dbf72353");
VirtualMachineModel vm0 = new VirtualMachineModel(vm, "fbc1f8fa-4b78-45ee-bba0-b551dbf72353");
db.getVirtualMachines().add(vm0);

VirtualMachineModel vm1 = new VirtualMachineModel(vm, "fbc1f8fa-4b78-45ee-bba0-b551dbf83464");
VirtualMachineModel vm1 = new VirtualMachineModel(vm, "fbc1f8fa-4b78-45ee-bba0-b551dbf83464");
db.getVirtualMachines().add(vm1);

VirtualMachineModel vm2 = new VirtualMachineModel(vm, "fbc1f8fa-4b78-45ee-bba0-b551dbf94575");
VirtualMachineModel vm2 = new VirtualMachineModel(vm, "fbc1f8fa-4b78-45ee-bba0-b551dbf94575");
db.getVirtualMachines().add(vm2);

s_logger.debug("No of Vitual Machines added to database : " + db.getVirtualMachines().size());
Expand All @@ -74,20 +74,13 @@ public void testCreateVirtualMachine() throws IOException {

String uuid = UUID.randomUUID().toString();
ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
ModelController controller = mock(ModelController.class);
ModelController controller = mock(ModelController.class);
ApiConnector api = new ApiConnectorMock(null, 0);
when(controller.getManager()).thenReturn(contrailMgr);
when(controller.getApiAccessor()).thenReturn(api);

// Create Virtual-Network (VN)
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(Network.State.Allocated);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
NetworkVO network = MockNetworkVO.getNetwork(Network.State.Allocated);

when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
Expand All @@ -99,7 +92,7 @@ public void testCreateVirtualMachine() throws IOException {
when(vm.getDomainId()).thenReturn(10L);
when(vm.getAccountId()).thenReturn(42L);

UserVmDao VmDao = mock(UserVmDao.class);
UserVmDao VmDao = mock(UserVmDao.class);
when(VmDao.findById(anyLong())).thenReturn(null);
when(controller.getVmDao()).thenReturn(VmDao);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,34 +115,13 @@ public void setUp() throws IOException {
when(vn3.getNetworkPolicy()).thenReturn(policyRefs3);

//Virtual-Network 1
NetworkVO network1 = mock(NetworkVO.class);
when(network1.getName()).thenReturn("testnetwork");
when(network1.getState()).thenReturn(State.Allocated);
when(network1.getGateway()).thenReturn("10.1.1.1");
when(network1.getCidr()).thenReturn("10.1.1.0/24");
when(network1.getPhysicalNetworkId()).thenReturn(42L);
when(network1.getDomainId()).thenReturn(10L);
when(network1.getAccountId()).thenReturn(42L);
NetworkVO network1 = MockNetworkVO.getNetwork(State.Allocated);

//Virtual-Network 2
NetworkVO network2 = mock(NetworkVO.class);
when(network2.getName()).thenReturn("Testnetwork");
when(network2.getState()).thenReturn(State.Allocated);
when(network2.getGateway()).thenReturn("10.1.1.1");
when(network2.getCidr()).thenReturn("10.1.1.0/24");
when(network2.getPhysicalNetworkId()).thenReturn(42L);
when(network2.getDomainId()).thenReturn(10L);
when(network2.getAccountId()).thenReturn(42L);
NetworkVO network2 = MockNetworkVO.getNetwork(State.Allocated);

//Virtual-Network 3
NetworkVO network3 = mock(NetworkVO.class);
when(network3.getName()).thenReturn("Testnetwork");
when(network3.getState()).thenReturn(State.Allocated);
when(network3.getGateway()).thenReturn("10.1.1.1");
when(network3.getCidr()).thenReturn("10.1.1.0/24");
when(network3.getPhysicalNetworkId()).thenReturn(42L);
when(network3.getDomainId()).thenReturn(10L);
when(network3.getAccountId()).thenReturn(42L);
NetworkVO network3 = MockNetworkVO.getNetwork(State.Allocated);

when(contrailMgr.getCanonicalName(network1)).thenReturn("testnetwork");
when(contrailMgr.getProjectId(network1.getDomainId(), network1.getAccountId())).thenReturn("testProjectId");
Expand Down Expand Up @@ -179,20 +158,13 @@ public void testCreateVirtualNetwork() throws IOException {

String uuid = UUID.randomUUID().toString();
ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class);
ModelController controller = mock(ModelController.class);
ModelController controller = mock(ModelController.class);
ApiConnector api = new ApiConnectorMock(null, 0);
when(controller.getManager()).thenReturn(contrailMgr);
when(controller.getApiAccessor()).thenReturn(api);

// Create Virtual-Network (VN)
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Allocated);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(network.getDomainId()).thenReturn(10L);
when(network.getAccountId()).thenReturn(42L);
NetworkVO network = MockNetworkVO.getNetwork(State.Allocated);

when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork");
when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId");
Expand Down