CLOUDSTACK-8656: restructure tests to ensure exception throwing Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/07bee314 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/07bee314 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/07bee314
Branch: refs/heads/master Commit: 07bee3149ca182bf87c3bd21cbeb3b6362e18763 Parents: 2eee6aa Author: Daan Hoogland <[email protected]> Authored: Fri Aug 14 15:43:54 2015 +0200 Committer: Daan Hoogland <[email protected]> Committed: Fri Aug 14 15:43:54 2015 +0200 ---------------------------------------------------------------------- server/test/com/cloud/vpc/VpcApiUnitTest.java | 86 +++++++------------- .../CreateNetworkOfferingTest.java | 39 ++++----- 2 files changed, 46 insertions(+), 79 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07bee314/server/test/com/cloud/vpc/VpcApiUnitTest.java ---------------------------------------------------------------------- diff --git a/server/test/com/cloud/vpc/VpcApiUnitTest.java b/server/test/com/cloud/vpc/VpcApiUnitTest.java index f405635..7043f22 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<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); -// } -// } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07bee314/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java ---------------------------------------------------------------------- diff --git a/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java b/server/test/org/apache/cloudstack/networkoffering/CreateNetworkOfferingTest.java index 466adb5..5d2eb4c 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<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
