From 07bee3149ca182bf87c3bd21cbeb3b6362e18763 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Fri, 14 Aug 2015 15:43:54 +0200 Subject: [PATCH] CLOUDSTACK-8656: restructure tests to ensure exception throwing --- server/test/com/cloud/vpc/VpcApiUnitTest.java | 86 +++++++------------ .../CreateNetworkOfferingTest.java | 39 ++++----- 2 files changed, 46 insertions(+), 79 deletions(-) diff --git a/server/test/com/cloud/vpc/VpcApiUnitTest.java b/server/test/com/cloud/vpc/VpcApiUnitTest.java index f4056358d4e..7043f2265d3 100644 --- a/server/test/com/cloud/vpc/VpcApiUnitTest.java +++ b/server/test/com/cloud/vpc/VpcApiUnitTest.java @@ -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 svcs = new ArrayList(); -// 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 svcs = new ArrayList(); -// 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); -// } -// } } diff --git a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java index 466adb52e09..5d2eb4c4970 100644 --- a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java +++ b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java @@ -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> serviceProviderMap = new HashMap>(); - Set vrProvider = new HashSet(); - vrProvider.add(Provider.VirtualRouter); - serviceProviderMap.put(Network.Service.SourceNat, vrProvider); - NetworkOfferingVO off = + Map> serviceProviderMap = new HashMap>(); + Set vrProvider = new HashSet(); + 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