17
17
18
18
package org .apache .cloudstack .api .command .user .network ;
19
19
20
- import com .cloud .exception .InsufficientCapacityException ;
21
- import com .cloud .exception .ResourceAllocationException ;
22
- import com .cloud .network .Network ;
23
- import com .cloud .network .NetworkService ;
24
- import com .cloud .offering .NetworkOffering ;
25
- import com .cloud .utils .db .EntityManager ;
26
- import junit .framework .TestCase ;
27
20
import org .apache .cloudstack .api .ResponseGenerator ;
28
21
import org .apache .cloudstack .api .ResponseObject ;
29
22
import org .apache .cloudstack .api .response .NetworkResponse ;
30
23
import org .junit .Assert ;
24
+ import org .junit .Test ;
31
25
import org .junit .runner .RunWith ;
32
26
import org .mockito .InjectMocks ;
33
27
import org .mockito .Mock ;
34
28
import org .mockito .Mockito ;
35
- import org .powermock . modules . junit4 . PowerMockRunner ;
29
+ import org .mockito . junit . MockitoJUnitRunner ;
36
30
import org .springframework .test .util .ReflectionTestUtils ;
37
31
38
- @ RunWith (PowerMockRunner .class )
39
- public class CreateNetworkCmdTest extends TestCase {
32
+ import com .cloud .exception .InsufficientCapacityException ;
33
+ import com .cloud .exception .ResourceAllocationException ;
34
+ import com .cloud .network .Network ;
35
+ import com .cloud .network .NetworkService ;
36
+ import com .cloud .offering .NetworkOffering ;
37
+ import com .cloud .utils .db .EntityManager ;
38
+
39
+ @ RunWith (MockitoJUnitRunner .class )
40
+ public class CreateNetworkCmdTest {
40
41
41
42
@ Mock
42
43
public EntityManager _entityMgr ;
@@ -46,139 +47,161 @@ public class CreateNetworkCmdTest extends TestCase {
46
47
47
48
@ InjectMocks
48
49
CreateNetworkCmd cmd = new CreateNetworkCmd ();
50
+
51
+ @ Test
49
52
public void testGetNetworkOfferingId () {
50
53
Long networkOfferingId = 1L ;
51
54
ReflectionTestUtils .setField (cmd , "networkOfferingId" , networkOfferingId );
52
55
Assert .assertEquals (cmd .getNetworkOfferingId (), networkOfferingId );
53
56
}
54
57
58
+ @ Test
55
59
public void testGetGateway () {
56
60
String gateway = "10.10.10.1" ;
57
61
ReflectionTestUtils .setField (cmd , "gateway" , gateway );
58
62
Assert .assertEquals (cmd .getGateway (), gateway );
59
63
}
60
64
65
+ @ Test
61
66
public void testGetIsolatedPvlan () {
62
67
String isolatedPvlan = "1234" ;
63
68
ReflectionTestUtils .setField (cmd , "isolatedPvlan" , isolatedPvlan );
64
69
Assert .assertEquals (cmd .getIsolatedPvlan (), isolatedPvlan );
65
70
}
66
71
72
+ @ Test
67
73
public void testGetAccountName () {
68
74
String accountName = "admin" ;
69
75
ReflectionTestUtils .setField (cmd , "accountName" , accountName );
70
76
Assert .assertEquals (cmd .getAccountName (), accountName );
71
77
}
72
78
79
+ @ Test
73
80
public void testGetDomainId () {
74
81
Long domainId = 1L ;
75
82
ReflectionTestUtils .setField (cmd , "domainId" , domainId );
76
83
Assert .assertEquals (cmd .getDomainId (), domainId );
77
84
}
78
85
86
+ @ Test
79
87
public void testGetNetmask () {
80
88
String netmask = "255.255.255.0" ;
81
89
ReflectionTestUtils .setField (cmd , "netmask" , netmask );
82
90
Assert .assertEquals (cmd .getNetmask (), netmask );
83
91
}
84
92
93
+ @ Test
85
94
public void testGetStartIp () {
86
95
String startIp = "10.10.10.2" ;
87
96
ReflectionTestUtils .setField (cmd , "startIp" , startIp );
88
97
Assert .assertEquals (cmd .getStartIp (), startIp );
89
98
}
90
99
100
+ @ Test
91
101
public void testGetEndIp () {
92
102
String endIp = "10.10.10.10" ;
93
103
ReflectionTestUtils .setField (cmd , "endIp" , endIp );
94
104
Assert .assertEquals (cmd .getEndIp (), endIp );
95
105
}
96
106
107
+ @ Test
97
108
public void testGetNetworkName () {
98
109
String netName = "net-isolated" ;
99
110
ReflectionTestUtils .setField (cmd , "name" , netName );
100
111
Assert .assertEquals (cmd .getNetworkName (), netName );
101
112
}
102
113
114
+ @ Test
103
115
public void testGetDisplayTextWhenNotEmpty () {
104
116
String description = "Isolated Network" ;
105
117
ReflectionTestUtils .setField (cmd , "displayText" , description );
106
118
Assert .assertEquals (cmd .getDisplayText (), description );
107
119
}
108
120
121
+ @ Test
109
122
public void testGetDisplayTextWhenEmpty () {
110
123
String description = null ;
111
124
String netName = "net-isolated" ;
112
125
ReflectionTestUtils .setField (cmd , "name" , netName );
113
126
Assert .assertEquals (cmd .getDisplayText (), netName );
114
127
}
115
128
129
+ @ Test
116
130
public void testGetNetworkDomain () {
117
131
String netDomain = "cs1cloud.internal" ;
118
132
ReflectionTestUtils .setField (cmd , "networkDomain" , netDomain );
119
133
Assert .assertEquals (cmd .getNetworkDomain (), netDomain );
120
134
}
121
135
136
+ @ Test
122
137
public void testGetProjectId () {
123
138
Long projectId = 1L ;
124
139
ReflectionTestUtils .setField (cmd , "projectId" , projectId );
125
140
Assert .assertEquals (cmd .getProjectId (), projectId );
126
141
}
127
142
143
+ @ Test
128
144
public void testGetAclType () {
129
145
String aclType = "account" ;
130
146
ReflectionTestUtils .setField (cmd , "aclType" , aclType );
131
147
Assert .assertEquals (cmd .getAclType (), aclType );
132
148
}
133
149
150
+ @ Test
134
151
public void testGetSubdomainAccess () {
135
152
Boolean subDomAccess = false ;
136
153
ReflectionTestUtils .setField (cmd , "subdomainAccess" , subDomAccess );
137
154
Assert .assertEquals (cmd .getSubdomainAccess (), subDomAccess );
138
155
}
139
156
157
+ @ Test
140
158
public void testGetVpcId () {
141
159
Long vpcId = 1L ;
142
160
ReflectionTestUtils .setField (cmd , "vpcId" , vpcId );
143
161
Assert .assertEquals (cmd .getVpcId (), vpcId );
144
162
}
145
163
164
+ @ Test
146
165
public void testGetDisplayNetwork () {
147
166
Boolean displayNet = true ;
148
167
ReflectionTestUtils .setField (cmd , "displayNetwork" , displayNet );
149
168
Assert .assertEquals (cmd .getDisplayNetwork (), displayNet );
150
169
}
151
170
171
+ @ Test
152
172
public void testGetExternalId () {
153
173
String externalId = "1" ;
154
174
ReflectionTestUtils .setField (cmd , "externalId" , externalId );
155
175
Assert .assertEquals (cmd .getExternalId (), externalId );
156
176
}
157
177
178
+ @ Test
158
179
public void testGetAssociatedNetworkId () {
159
180
Long associatedNetId = 1L ;
160
181
ReflectionTestUtils .setField (cmd , "associatedNetworkId" , associatedNetId );
161
182
Assert .assertEquals (cmd .getAssociatedNetworkId (), associatedNetId );
162
183
}
163
184
185
+ @ Test
164
186
public void testIsDisplayNullDefaultsToTrue () {
165
187
Boolean displayNetwork = null ;
166
188
ReflectionTestUtils .setField (cmd , "displayNetwork" , displayNetwork );
167
189
Assert .assertTrue (cmd .isDisplay ());
168
190
}
169
191
192
+ @ Test
170
193
public void testGetPhysicalNetworkIdForInvalidNetOfferingId () {
171
194
Long physicalNetworkId = 1L ;
172
195
173
196
ReflectionTestUtils .setField (cmd , "physicalNetworkId" , physicalNetworkId );
174
- Mockito .when (_entityMgr .findById (NetworkOffering .class , 1L )).thenReturn (null );
175
197
try {
176
198
cmd .getPhysicalNetworkId ();
177
199
} catch (Exception e ) {
178
200
Assert .assertTrue (e .getMessage ().startsWith ("Unable to find network offering by ID" ));
179
201
}
180
202
}
181
203
204
+ @ Test
182
205
public void testGetPhysicalNetworkIdForInvalidAssociatedNetId () {
183
206
Long physicalNetworkId = 1L ;
184
207
Long networkOfferingId = 1L ;
@@ -196,6 +219,7 @@ public void testGetPhysicalNetworkIdForInvalidAssociatedNetId() {
196
219
}
197
220
}
198
221
222
+ @ Test
199
223
public void testGetPhysicalNetworkIdForAssociatedNetIdForNonSharedNet () {
200
224
Long physicalNetworkId = 1L ;
201
225
Long networkOfferingId = 1L ;
@@ -215,6 +239,7 @@ public void testGetPhysicalNetworkIdForAssociatedNetIdForNonSharedNet() {
215
239
}
216
240
}
217
241
242
+ @ Test
218
243
public void testGetPhysicalNetworkIdForNonSharedNet () {
219
244
Long physicalNetworkId = 1L ;
220
245
Long networkOfferingId = 1L ;
@@ -230,6 +255,7 @@ public void testGetPhysicalNetworkIdForNonSharedNet() {
230
255
}
231
256
}
232
257
258
+ @ Test
233
259
public void testGetPhysicalNetworkIdForSharedNet () {
234
260
Long physicalNetworkId = 1L ;
235
261
Long networkOfferingId = 1L ;
@@ -245,6 +271,7 @@ public void testGetPhysicalNetworkIdForSharedNet() {
245
271
}
246
272
}
247
273
274
+ @ Test
248
275
public void testGetZoneId () {
249
276
Long physicalNetworkId = 1L ;
250
277
Long networkOfferingId = 1L ;
@@ -258,30 +285,35 @@ public void testGetZoneId() {
258
285
Assert .assertEquals (cmd .getZoneId (), zoneId );
259
286
}
260
287
288
+ @ Test
261
289
public void testGetPublicMtuWhenNotSet () {
262
290
Integer publicMtu = null ;
263
291
ReflectionTestUtils .setField (cmd , "publicMtu" , publicMtu );
264
292
Assert .assertEquals (NetworkService .DEFAULT_MTU , cmd .getPublicMtu ());
265
293
}
266
294
295
+ @ Test
267
296
public void testGetPublicMtuWhenSet () {
268
297
Integer publicMtu = 1450 ;
269
298
ReflectionTestUtils .setField (cmd , "publicMtu" , publicMtu );
270
299
Assert .assertEquals (cmd .getPublicMtu (), publicMtu );
271
300
}
272
301
302
+ @ Test
273
303
public void testGetPrivateMtuWhenNotSet () {
274
304
Integer privateMtu = null ;
275
305
ReflectionTestUtils .setField (cmd , "privateMtu" , privateMtu );
276
306
Assert .assertEquals (NetworkService .DEFAULT_MTU , cmd .getPrivateMtu ());
277
307
}
278
308
309
+ @ Test
279
310
public void testGetPrivateMtuWhenSet () {
280
311
Integer privateMtu = 1250 ;
281
312
ReflectionTestUtils .setField (cmd , "privateMtu" , privateMtu );
282
313
Assert .assertEquals (cmd .getPrivateMtu (), privateMtu );
283
314
}
284
315
316
+ @ Test
285
317
public void testExecute () throws InsufficientCapacityException , ResourceAllocationException {
286
318
ReflectionTestUtils .setField (cmd , "displayText" , "testNetwork" );
287
319
ReflectionTestUtils .setField (cmd , "name" , "testNetwork" );
0 commit comments