|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
1 | 18 | package org.apache.cloudstack.network.contrail.model; |
2 | | -import java.util.UUID; |
| 19 | + |
| 20 | +import static org.mockito.Matchers.anyLong; |
| 21 | +import static org.mockito.Mockito.mock; |
| 22 | +import static org.mockito.Mockito.when; |
3 | 23 |
|
4 | 24 | import java.io.IOException; |
| 25 | +import java.util.UUID; |
5 | 26 |
|
6 | | -import org.apache.cloudstack.network.contrail.management.*; |
7 | | -import org.apache.cloudstack.network.contrail.model.*; |
| 27 | +import junit.framework.TestCase; |
| 28 | +import net.juniper.contrail.api.ApiConnector; |
| 29 | +import net.juniper.contrail.api.ApiConnectorMock; |
8 | 30 |
|
9 | 31 | import org.apache.log4j.Logger; |
10 | | -import org.junit.runner.RunWith; |
| 32 | +import org.junit.Test; |
11 | 33 |
|
12 | | -import static org.mockito.Mockito.*; |
| 34 | +import org.apache.cloudstack.network.contrail.management.ContrailManagerImpl; |
| 35 | +import org.apache.cloudstack.network.contrail.management.ModelDatabase; |
13 | 36 |
|
14 | 37 | import com.cloud.network.Network; |
15 | 38 | import com.cloud.network.dao.NetworkVO; |
16 | 39 | import com.cloud.vm.VMInstanceVO; |
17 | 40 | import com.cloud.vm.VirtualMachine; |
18 | 41 | import com.cloud.vm.dao.UserVmDao; |
19 | | -import com.cloud.uservm.UserVm; |
20 | | - |
21 | | -import net.juniper.contrail.api.ApiConnectorMock; |
22 | | -import net.juniper.contrail.api.ApiConnectorFactory; |
23 | | -import net.juniper.contrail.api.ApiObjectBase; |
24 | | -import net.juniper.contrail.api.types.Domain; |
25 | | -import net.juniper.contrail.api.types.InstanceIp; |
26 | | -import net.juniper.contrail.api.types.NetworkIpam; |
27 | | -import net.juniper.contrail.api.types.SubnetType; |
28 | | -import net.juniper.contrail.api.types.VirtualMachineInterface; |
29 | | -import net.juniper.contrail.api.types.VirtualNetwork; |
30 | | -import net.juniper.contrail.api.types.VnSubnetsType; |
31 | | -import net.juniper.contrail.api.types.NetworkPolicy; |
32 | | -import net.juniper.contrail.api.types.Project; |
33 | | -import net.juniper.contrail.api.types.FloatingIp; |
34 | | -import net.juniper.contrail.api.types.VnSubnetsType; |
35 | | -import net.juniper.contrail.api.types.ServiceInstance; |
36 | | -import net.juniper.contrail.api.ApiConnector; |
37 | | - |
38 | | -import org.junit.runner.RunWith; |
39 | | -import org.junit.After; |
40 | | -import org.junit.Before; |
41 | | -import org.junit.BeforeClass; |
42 | | -import org.junit.AfterClass; |
43 | | -import org.junit.Ignore; |
44 | | -import org.junit.Test; |
45 | | -import junit.framework.TestCase; |
46 | 42 |
|
47 | 43 | public class VirtualMachineModelTest extends TestCase { |
48 | 44 | private static final Logger s_logger = |
@@ -78,49 +74,49 @@ public void testVirtualMachineDBLookup() { |
78 | 74 | public void testCreateVirtualMachine() throws IOException { |
79 | 75 |
|
80 | 76 | String uuid = UUID.randomUUID().toString(); |
81 | | - ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class); |
82 | | - ModelController controller = mock(ModelController.class); |
| 77 | + ContrailManagerImpl contrailMgr = mock(ContrailManagerImpl.class); |
| 78 | + ModelController controller = mock(ModelController.class); |
83 | 79 | ApiConnector api = new ApiConnectorMock(null, 0); |
84 | | - when(controller.getManager()).thenReturn(contrailMgr); |
85 | | - when(controller.getApiAccessor()).thenReturn(api); |
| 80 | + when(controller.getManager()).thenReturn(contrailMgr); |
| 81 | + when(controller.getApiAccessor()).thenReturn(api); |
86 | 82 |
|
87 | | - // Create Virtual-Network (VN) |
| 83 | + // Create Virtual-Network (VN) |
88 | 84 | NetworkVO network = mock(NetworkVO.class); |
89 | | - when(network.getName()).thenReturn("testnetwork"); |
90 | | - when(network.getState()).thenReturn(Network.State.Allocated); |
91 | | - when(network.getGateway()).thenReturn("10.1.1.1"); |
92 | | - when(network.getCidr()).thenReturn("10.1.1.0/24"); |
93 | | - when(network.getPhysicalNetworkId()).thenReturn(42L); |
94 | | - when(network.getDomainId()).thenReturn(10L); |
95 | | - when(network.getAccountId()).thenReturn(42L); |
96 | | - |
97 | | - when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork"); |
98 | | - when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId"); |
99 | | - |
100 | | - // Create Virtual-Machine (VM) |
| 85 | + when(network.getName()).thenReturn("testnetwork"); |
| 86 | + when(network.getState()).thenReturn(Network.State.Allocated); |
| 87 | + when(network.getGateway()).thenReturn("10.1.1.1"); |
| 88 | + when(network.getCidr()).thenReturn("10.1.1.0/24"); |
| 89 | + when(network.getPhysicalNetworkId()).thenReturn(42L); |
| 90 | + when(network.getDomainId()).thenReturn(10L); |
| 91 | + when(network.getAccountId()).thenReturn(42L); |
| 92 | + |
| 93 | + when(contrailMgr.getCanonicalName(network)).thenReturn("testnetwork"); |
| 94 | + when(contrailMgr.getProjectId(network.getDomainId(), network.getAccountId())).thenReturn("testProjectId"); |
| 95 | + |
| 96 | + // Create Virtual-Machine (VM) |
101 | 97 | VMInstanceVO vm = mock(VMInstanceVO.class); |
102 | | - when(vm.getInstanceName()).thenReturn("testVM1"); |
103 | | - when(vm.getState()).thenReturn(VirtualMachine.State.Starting); |
104 | | - when(vm.getDomainId()).thenReturn(10L); |
105 | | - when(vm.getAccountId()).thenReturn(42L); |
| 98 | + when(vm.getInstanceName()).thenReturn("testVM1"); |
| 99 | + when(vm.getState()).thenReturn(VirtualMachine.State.Starting); |
| 100 | + when(vm.getDomainId()).thenReturn(10L); |
| 101 | + when(vm.getAccountId()).thenReturn(42L); |
106 | 102 |
|
107 | | - UserVmDao VmDao = mock(UserVmDao.class); |
108 | | - when(VmDao.findById(anyLong())).thenReturn(null); |
109 | | - when(controller.getVmDao()).thenReturn(VmDao); |
| 103 | + UserVmDao VmDao = mock(UserVmDao.class); |
| 104 | + when(VmDao.findById(anyLong())).thenReturn(null); |
| 105 | + when(controller.getVmDao()).thenReturn(VmDao); |
110 | 106 |
|
111 | 107 | VirtualMachineModel vmModel = new VirtualMachineModel(vm, uuid); |
112 | 108 |
|
113 | 109 | assertEquals(vmModel.getInstanceName(), "testVM1"); |
114 | 110 | assertEquals(vmModel.getUuid(), uuid); |
115 | 111 |
|
116 | 112 | vmModel.build(controller, vm); |
117 | | - try { |
| 113 | + try { |
118 | 114 | vmModel.update(controller); |
119 | | - } catch (Exception ex) { |
120 | | - fail("virtual-network update failed "); |
121 | | - } |
| 115 | + } catch (Exception ex) { |
| 116 | + fail("virtual-network update failed "); |
| 117 | + } |
122 | 118 |
|
123 | | - //verify |
| 119 | + //verify |
124 | 120 | assertTrue(vmModel.verify(controller)); |
125 | 121 |
|
126 | 122 | } |
|
0 commit comments