Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3AFE4200CAF for ; Thu, 22 Jun 2017 13:15:18 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 398F5160BE7; Thu, 22 Jun 2017 11:15:18 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 841FE160BE5 for ; Thu, 22 Jun 2017 13:15:17 +0200 (CEST) Received: (qmail 32946 invoked by uid 500); 22 Jun 2017 11:15:16 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 32935 invoked by uid 99); 22 Jun 2017 11:15:16 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Jun 2017 11:15:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 88850DFA28; Thu, 22 Jun 2017 11:15:13 +0000 (UTC) From: Graeme-Miller To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #742: DefaultAzureArmNetworkCreator improvement... Content-Type: text/plain Message-Id: <20170622111514.88850DFA28@git1-us-west.apache.org> Date: Thu, 22 Jun 2017 11:15:13 +0000 (UTC) archived-at: Thu, 22 Jun 2017 11:15:18 -0000 Github user Graeme-Miller commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/742#discussion_r123482551 --- Diff: locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/creator/DefaultAzureArmNetworkCreatorTest.java --- @@ -90,62 +97,44 @@ public void testPreExisting() { verify(azureComputeApi).getSubnetApi(TEST_RESOURCE_GROUP, TEST_NETWORK_NAME); Map templateOptions = configBag.get(TEMPLATE_OPTIONS); - Map ipOptions = (Map)templateOptions.get("ipOptions"); + Map ipOptions = (Map)templateOptions.get("ipOptions"); assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); assertEquals(ipOptions.get("allocateNewPublicIp"), true); } @Test - public void testVanilla() { - //Setup config bag - ConfigBag configBag = ConfigBag.newInstance(); - configBag.put(CLOUD_REGION_ID, TEST_LOCATION); - - //Setup mocks - when(computeService.getContext().unwrapApi(AzureComputeApi.class)).thenReturn(azureComputeApi); - when(azureComputeApi.getSubnetApi(TEST_RESOURCE_GROUP, TEST_NETWORK_NAME)).thenReturn(subnetApi); - when(subnetApi.get(TEST_SUBNET_NAME)).thenReturn(null).thenReturn(subnet); //null first time, subnet next - when(subnet.id()).thenReturn(TEST_SUBNET_ID); - - when(azureComputeApi.getResourceGroupApi()).thenReturn(resourceGroupApi); - when(resourceGroupApi.get(TEST_RESOURCE_GROUP)).thenReturn(null); - - when(azureComputeApi.getVirtualNetworkApi(TEST_RESOURCE_GROUP)).thenReturn(virtualNetworkApi); - - - //Test - DefaultAzureArmNetworkCreator.createDefaultNetworkAndAddToTemplateOptionsIfRequired(computeService, configBag); - - //verify - verify(subnetApi, times(2)).get(TEST_SUBNET_NAME); - verify(subnet).id(); - verify(azureComputeApi, times(2)).getSubnetApi(TEST_RESOURCE_GROUP, TEST_NETWORK_NAME); - - verify(azureComputeApi, times(2)).getResourceGroupApi(); - verify(resourceGroupApi).get(TEST_RESOURCE_GROUP); - verify(azureComputeApi).getVirtualNetworkApi(TEST_RESOURCE_GROUP); - - Map templateOptions = configBag.get(TEMPLATE_OPTIONS); - Map ipOptions = (Map)templateOptions.get("ipOptions"); - assertEquals(ipOptions.get("subnet"), TEST_SUBNET_ID); - assertEquals(ipOptions.get("allocateNewPublicIp"), true); + public void testVanillaWhereNoResourceGroup() throws Exception { + runVanilla(ImmutableMap.of(), false); } - + @Test - public void testVanillaWhereTemplateOptionsAlreadySpecified() { + public void testVanillaWhereExistingResourceGroup() throws Exception { + runVanilla(ImmutableMap.of(), true); + } + + @Test + public void testVanillaWhereTemplateOptionsAlreadySpecified() throws Exception { + ImmutableMap additionalConfig = ImmutableMap.of(TEMPLATE_OPTIONS, ImmutableMap.of("unrelated-key", "unrelated-value")); + ConfigBag result = runVanilla(additionalConfig, false); + Map templateOptions = result.get(TEMPLATE_OPTIONS); + assertEquals(templateOptions.get("unrelated-key"), "unrelated-value"); + } + + protected ConfigBag runVanilla(Map additionalConfig, boolean resoureGroupExists) throws Exception { --- End diff -- I can see why you've created a generic vanilla test here (looks like it cuts down on code repetition), but I think that it introduces a couple of problems: *) Makes the tests more difficult to understand (the runVanilla method itself is longer than an individual test used to be due to the necessity of adding if blocks to cope with different resource group cases) *) Makes the tests more difficult to maintain (if the mock calls change for one of the tests, you have to modify the generic test and understand what all the other tests that rely on it expect it to do) The tests themselves were pretty short before and as such I don't see a justification for this change. I would suggest reverting this to repeating the code per test. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---