CLOUDSTACK-8656: restructure tests to ensure exception throwing

This commit is contained in:
Daan Hoogland 2015-08-14 15:43:54 +02:00
parent 2eee6aa999
commit 07bee3149c
2 changed files with 46 additions and 79 deletions

View File

@ -41,6 +41,7 @@ import com.cloud.utils.component.ComponentContext;
public class VpcApiUnitTest extends TestCase {
@Inject
VpcManagerImpl _vpcService = null;
VpcVO _vo = new VpcVO(1, "new vpc", "new vpc", 1, 1, 1, "0.0.0.0/0", "vpc domain", false, false, false);
@Override
@Before
@ -81,93 +82,68 @@ public class VpcApiUnitTest extends TestCase {
}
}
//1) correct network offering
@Test
public void validateNtwkOffForVpc() {
//validate network offering
//1) correct network offering
VpcVO vo = new VpcVO(1, "new vpc", "new vpc", 1, 1, 1, "0.0.0.0/0", "vpc domain", false, false, false);
boolean result = false;
try {
_vpcService.validateNtwkOffForNtwkInVpc(2L, 1, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null);
_vpcService.validateNtwkOffForNtwkInVpc(2L, 1, "0.0.0.0", "111-", _vo, "10.1.1.1", new AccountVO(), null);
result = true;
} catch (Exception ex) {
} finally {
assertTrue("Validate network offering: Test passed: the offering is valid for vpc creation", result);
}
//2) invalid offering - source nat is not included
result = false;
}
//2) invalid offering - source nat is not included
@Test(expected=InvalidParameterValueException.class)
public void validateNtwkOffForVpcInvalidMissingSourceNat() {
boolean result = false;
try {
_vpcService.validateNtwkOffForNtwkInVpc(2L, 2, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null);
_vpcService.validateNtwkOffForNtwkInVpc(2L, 2, "0.0.0.0", "111-", _vo, "10.1.1.1", new AccountVO(), null);
result = true;
} catch (InvalidParameterValueException ex) {
} finally {
assertFalse("Validate network offering: TEST FAILED, can't use network offering without SourceNat service", result);
}
//3) invalid offering - conserve mode is off
result = false;
}
//3) invalid offering - conserve mode is off
@Test(expected=InvalidParameterValueException.class)
public void validateNtwkOffForVpcInvalidNoConserveMode() {
boolean result = false;
try {
_vpcService.validateNtwkOffForNtwkInVpc(2L, 3, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null);
_vpcService.validateNtwkOffForNtwkInVpc(2L, 3, "0.0.0.0", "111-", _vo, "10.1.1.1", new AccountVO(), null);
result = true;
} catch (InvalidParameterValueException ex) {
} finally {
assertFalse("Validate network offering: TEST FAILED, can't use network offering without conserve mode = true", result);
}
//4) invalid offering - guest type shared
result = false;
}
//4) invalid offering - guest type shared
@Test(expected=InvalidParameterValueException.class)
public void validateNtwkOffForVpcInvalidTypeIsGuest() {
boolean result = false;
try {
_vpcService.validateNtwkOffForNtwkInVpc(2L, 4, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null);
_vpcService.validateNtwkOffForNtwkInVpc(2L, 4, "0.0.0.0", "111-", _vo, "10.1.1.1", new AccountVO(), null);
result = true;
} catch (InvalidParameterValueException ex) {
} finally {
assertFalse("Validate network offering: TEST FAILED, can't use network offering with guest type = Shared", result);
}
//5) Invalid offering - no redundant router support
result = false;
}
//5) Invalid offering - no redundant router support
@Test(expected=InvalidParameterValueException.class)
public void validateNtwkOffForVpcInvalidNoRVRSupport() {
boolean result = false;
try {
_vpcService.validateNtwkOffForNtwkInVpc(2L, 5, "0.0.0.0", "111-", vo, "10.1.1.1", new AccountVO(), null);
_vpcService.validateNtwkOffForNtwkInVpc(2L, 5, "0.0.0.0", "111-", _vo, "10.1.1.1", new AccountVO(), null);
result = true;
} catch (InvalidParameterValueException ex) {
} finally {
assertFalse("TEST FAILED, can't use network offering with guest type = Shared", result);
}
}
// public void destroyVpc() {
// boolean result = false;
// try {
// result = _vpcService.destroyVpc(vo, new AccountVO(), 1L);
// } catch (Exception ex) {
// s_logger.debug(ex);
// } finally {
// assertTrue("Failed to destroy VPC", result);
// }
// }
//
// public void deleteVpc() {
// //delete existing offering
// boolean result = false;
// try {
// List<String> svcs = new ArrayList<String>();
// svcs.add(Service.SourceNat.getName());
// result = _vpcService.deleteVpc(1);
// } catch (Exception ex) {
// } finally {
// assertTrue("Delete vpc: TEST FAILED, vpc failed to delete" + result, result);
// }
//
// //delete non-existing offering
// result = false;
// try {
// List<String> svcs = new ArrayList<String>();
// svcs.add(Service.SourceNat.getName());
// result = _vpcService.deleteVpc(100);
// } catch (Exception ex) {
// } finally {
// assertFalse("Delete vpc: TEST FAILED, true is returned when try to delete non existing vpc" + result, result);
// }
// }
}

View File

@ -125,15 +125,12 @@ public class CreateNetworkOfferingTest extends TestCase {
assertNotNull("Shared network offering with specifyVlan=true failed to create ", off);
}
@Test
@Test(expected=InvalidParameterValueException.class)
public void createSharedNtwkOffWithNoVlan() {
try {
NetworkOfferingVO off =
NetworkOfferingVO off =
configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, false, Availability.Optional, 200, null, false, Network.GuestType.Shared,
false, null, false, null, true, false, null, false, null, true);
assertNull("Shared network offering with specifyVlan=false was created", off);
} catch (InvalidParameterValueException ex) {
}
assertNull("Shared network offering with specifyVlan=false was created", off);
}
@Test
@ -145,15 +142,12 @@ public class CreateNetworkOfferingTest extends TestCase {
assertNotNull("Shared network offering with specifyIpRanges=true failed to create ", off);
}
@Test
@Test(expected=InvalidParameterValueException.class)
public void createSharedNtwkOffWithoutSpecifyIpRanges() {
try {
NetworkOfferingVO off =
NetworkOfferingVO off =
configMgr.createNetworkOffering("shared", "shared", TrafficType.Guest, null, true, Availability.Optional, 200, null, false, Network.GuestType.Shared,
false, null, false, null, false, false, null, false, null, true);
assertNull("Shared network offering with specifyIpRanges=false was created", off);
} catch (InvalidParameterValueException ex) {
}
false, null, false, null, false, false, null, false, null, true);
assertNull("Shared network offering with specifyIpRanges=false was created", off);
}
//Test Isolated network offerings
@ -183,19 +177,16 @@ public class CreateNetworkOfferingTest extends TestCase {
}
@Test
@Test(expected=InvalidParameterValueException.class)
public void createIsolatedNtwkOffWithSpecifyIpRangesAndSourceNat() {
try {
Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
vrProvider.add(Provider.VirtualRouter);
serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
NetworkOfferingVO off =
Map<Service, Set<Provider>> serviceProviderMap = new HashMap<Network.Service, Set<Network.Provider>>();
Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
vrProvider.add(Provider.VirtualRouter);
serviceProviderMap.put(Network.Service.SourceNat, vrProvider);
NetworkOfferingVO off =
configMgr.createNetworkOffering("isolated", "isolated", TrafficType.Guest, null, false, Availability.Optional, 200, serviceProviderMap, false,
Network.GuestType.Isolated, false, null, false, null, true, false, null, false, null, true);
assertNull("Isolated network offering with specifyIpRanges=true and source nat service enabled, was created", off);
} catch (InvalidParameterValueException ex) {
}
Network.GuestType.Isolated, false, null, false, null, true, false, null, false, null, true);
assertNull("Isolated network offering with specifyIpRanges=true and source nat service enabled, was created", off);
}
@Test