Skip to content

Commit 2ca7584

Browse files
author
Alena Prokharchyk
committed
Fixed VPC api unittests
1 parent 8d8a0eb commit 2ca7584

4 files changed

Lines changed: 91 additions & 152 deletions

File tree

server/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@
153153
<exclude>com/cloud/snapshot/*</exclude>
154154
<exclude>com/cloud/storage/dao/*</exclude>
155155
<exclude>com/cloud/vm/dao/*</exclude>
156-
<exclude>com/cloud/vpc/*</exclude>
157156
<exclude>com/cloud/api/ListPerfTest.java</exclude>
158157
<exclude>com/cloud/network/vpn/RemoteAccessVpnTest.java</exclude>
159158
<exclude>com/cloud/network/security/SecurityGroupManagerImpl2Test.java</exclude>

server/test/com/cloud/vpc/Site2SiteVpnTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2626

2727
@RunWith(SpringJUnit4ClassRunner.class)
28-
@ContextConfiguration(locations="classpath:/testContext.xml")
28+
@ContextConfiguration(locations="classpath:/VpcTestContext.xml")
2929
public class Site2SiteVpnTest {
3030
private final static Logger s_logger = Logger.getLogger(Site2SiteVpnTest.class);
3131

server/test/com/cloud/vpc/VpcApiUnitTest.java

Lines changed: 48 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import junit.framework.TestCase;
2525

26-
import org.apache.log4j.Logger;
2726
import org.junit.Before;
2827
import org.junit.Test;
2928
import org.junit.runner.RunWith;
@@ -40,68 +39,18 @@
4039
@RunWith(SpringJUnit4ClassRunner.class)
4140
@ContextConfiguration(locations = "classpath:/VpcTestContext.xml")
4241
public class VpcApiUnitTest extends TestCase{
43-
private static final Logger s_logger = Logger.getLogger(VpcApiUnitTest.class);
4442
@Inject VpcManagerImpl _vpcService = null;
4543

46-
@Override
4744
@Before
4845
public void setUp() throws Exception {
4946
ComponentContext.initComponentsLifeCycle();
5047
}
5148

52-
@Test
53-
public void test() {
54-
s_logger.debug("Starting test for VpcService interface");
55-
//Vpc service methods
56-
//getActiveVpc();
57-
//deleteVpc();
58-
59-
//Vpc manager methods
60-
validateNtwkOffForVpc();
61-
//destroyVpc();
62-
63-
}
64-
65-
protected void deleteVpc() {
66-
//delete existing offering
67-
boolean result = false;
68-
String msg = null;
69-
try {
70-
List<String> svcs = new ArrayList<String>();
71-
svcs.add(Service.SourceNat.getName());
72-
result = _vpcService.deleteVpc(1);
73-
} catch (Exception ex) {
74-
msg = ex.getMessage();
75-
} finally {
76-
if (result) {
77-
s_logger.debug("Delete vpc: Test passed, vpc is deleted");
78-
} else {
79-
s_logger.error("Delete vpc: TEST FAILED, vpc failed to delete " + msg);
80-
}
81-
}
82-
83-
//delete non-existing offering
84-
result = false;
85-
msg = null;
86-
try {
87-
List<String> svcs = new ArrayList<String>();
88-
svcs.add(Service.SourceNat.getName());
89-
result = _vpcService.deleteVpc(100);
90-
} catch (Exception ex) {
91-
msg = ex.getMessage();
92-
} finally {
93-
if (!result) {
94-
s_logger.debug("Delete vpc: Test passed, non existing vpc failed to delete ");
95-
} else {
96-
s_logger.error("Delete vpc: TEST FAILED, true is returned when try to delete non existing vpc");
97-
}
98-
}
99-
}
10049

101-
protected void getActiveVpc() {
50+
@Test
51+
public void getActiveVpc() {
10252
//test for active vpc
10353
boolean result = false;
104-
String msg = null;
10554
Vpc vpc = null;
10655
try {
10756
List<String> svcs = new ArrayList<String>();
@@ -111,18 +60,12 @@ protected void getActiveVpc() {
11160
result = true;
11261
}
11362
} catch (Exception ex) {
114-
msg = ex.getMessage();
11563
} finally {
116-
if (result) {
117-
s_logger.debug("Get active Vpc: Test passed, active vpc is returned");
118-
} else {
119-
s_logger.error("Get active Vpc: TEST FAILED, active vpc is not returned " + msg);
120-
}
64+
assertTrue("Get active Vpc: TEST FAILED, active vpc is not returned", result);
12165
}
12266

12367
//test for inactive vpc
12468
result = false;
125-
msg = null;
12669
vpc = null;
12770
try {
12871
List<String> svcs = new ArrayList<String>();
@@ -132,66 +75,43 @@ protected void getActiveVpc() {
13275
result = true;
13376
}
13477
} catch (Exception ex) {
135-
msg = ex.getMessage();
13678
} finally {
137-
if (!result) {
138-
s_logger.debug("Get active Vpc: Test passed, no vpc is returned");
139-
} else {
140-
s_logger.error("Get active Vpc: TEST FAILED, non active vpc is returned");
141-
}
79+
assertFalse("Get active Vpc: TEST FAILED, non active vpc is returned", result);
14280
}
14381
}
14482

145-
protected void destroyVpc() {
146-
try {
147-
_vpcService.destroyVpc(_vpcService.getVpc(1), new AccountVO(), 1L);
148-
} catch (Exception ex) {
149-
s_logger.error("Destroy VPC TEST FAILED due to exc ", ex);
150-
}
151-
}
15283

153-
protected void validateNtwkOffForVpc() {
84+
@Test
85+
public void validateNtwkOffForVpc() {
15486
//validate network offering
15587
//1) correct network offering
15688
boolean result = false;
15789
try {
15890
_vpcService.validateNtwkOffForNtwkInVpc(2L, 1, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
15991
result = true;
160-
s_logger.debug("Validate network offering: Test passed: the offering is valid for vpc creation");
16192
} catch (Exception ex) {
162-
s_logger.error("Validate network offering: TEST FAILED due to exc ", ex);
93+
} finally {
94+
assertTrue("Validate network offering: Test passed: the offering is valid for vpc creation", result);
16395
}
16496

16597
//2) invalid offering - source nat is not included
16698
result = false;
167-
String msg = null;
16899
try {
169100
_vpcService.validateNtwkOffForNtwkInVpc(2L, 2, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
170101
result = true;
171102
} catch (InvalidParameterValueException ex) {
172-
msg = ex.getMessage();
173103
} finally {
174-
if (!result) {
175-
s_logger.debug("Validate network offering: Test passed: " + msg);
176-
} else {
177-
s_logger.error("Validate network offering: TEST FAILED, can't use network offering without SourceNat service");
178-
}
104+
assertFalse("Validate network offering: TEST FAILED, can't use network offering without SourceNat service", result);
179105
}
180106

181107
//3) invalid offering - conserve mode is off
182108
result = false;
183-
msg = null;
184109
try {
185110
_vpcService.validateNtwkOffForNtwkInVpc(2L, 3, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
186111
result = true;
187112
} catch (InvalidParameterValueException ex) {
188-
msg = ex.getMessage();
189113
} finally {
190-
if (!result) {
191-
s_logger.debug("Validate network offering: Test passed: " + msg);
192-
} else {
193-
s_logger.error("Validate network offering: TEST FAILED, can't use network offering without conserve mode = true");
194-
}
114+
assertFalse("Validate network offering: TEST FAILED, can't use network offering without conserve mode = true", result);
195115
}
196116

197117
//4) invalid offering - guest type shared
@@ -200,13 +120,8 @@ protected void validateNtwkOffForVpc() {
200120
_vpcService.validateNtwkOffForNtwkInVpc(2L, 4, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
201121
result = true;
202122
} catch (InvalidParameterValueException ex) {
203-
msg = ex.getMessage();
204123
} finally {
205-
if (!result) {
206-
s_logger.debug("Validate network offering: Test passed: " + msg);
207-
} else {
208-
s_logger.error("Validate network offering: TEST FAILED, can't use network offering with guest type = Shared");
209-
}
124+
assertFalse("Validate network offering: TEST FAILED, can't use network offering with guest type = Shared", result);
210125
}
211126

212127
//5) Invalid offering - no redundant router support
@@ -215,30 +130,44 @@ protected void validateNtwkOffForVpc() {
215130
_vpcService.validateNtwkOffForNtwkInVpc(2L, 5, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
216131
result = true;
217132
} catch (InvalidParameterValueException ex) {
218-
msg = ex.getMessage();
219133
} finally {
220-
if (!result) {
221-
s_logger.debug("Validate network offering: Test passed: " + msg);
222-
} else {
223-
s_logger.error("TEST FAILED, can't use network offering with guest type = Shared");
224-
}
225-
}
226-
227-
//6) Only one network in the VPC can support LB service - negative scenario
228-
result = false;
229-
try {
230-
_vpcService.validateNtwkOffForNtwkInVpc(2L, 6, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
231-
result = true;
232-
s_logger.debug("Validate network offering: Test passed: the offering is valid for vpc creation");
233-
} catch (InvalidParameterValueException ex) {
234-
msg = ex.getMessage();
235-
} finally {
236-
if (!result) {
237-
s_logger.debug("Test passed : " + msg);
238-
} else {
239-
s_logger.error("Validate network offering: TEST FAILED, can't use network offering with guest type = Shared");
240-
}
134+
assertFalse("TEST FAILED, can't use network offering with guest type = Shared", result);
241135
}
242136
}
243-
137+
138+
139+
// public void destroyVpc() {
140+
// boolean result = false;
141+
// try {
142+
// result = _vpcService.destroyVpc(_vpcService.getVpc(1), new AccountVO(), 1L);
143+
// } catch (Exception ex) {
144+
// s_logger.debug(ex);
145+
// } finally {
146+
// assertTrue("Failed to destroy VPC", result);
147+
// }
148+
// }
149+
//
150+
// public void deleteVpc() {
151+
// //delete existing offering
152+
// boolean result = false;
153+
// try {
154+
// List<String> svcs = new ArrayList<String>();
155+
// svcs.add(Service.SourceNat.getName());
156+
// result = _vpcService.deleteVpc(1);
157+
// } catch (Exception ex) {
158+
// } finally {
159+
// assertTrue("Delete vpc: TEST FAILED, vpc failed to delete" + result, result);
160+
// }
161+
//
162+
// //delete non-existing offering
163+
// result = false;
164+
// try {
165+
// List<String> svcs = new ArrayList<String>();
166+
// svcs.add(Service.SourceNat.getName());
167+
// result = _vpcService.deleteVpc(100);
168+
// } catch (Exception ex) {
169+
// } finally {
170+
// assertFalse("Delete vpc: TEST FAILED, true is returned when try to delete non existing vpc" + result, result);
171+
// }
172+
// }
244173
}

0 commit comments

Comments
 (0)