brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graeme-Miller <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #742: DefaultAzureArmNetworkCreator improvement...
Date Thu, 22 Jun 2017 11:15:13 GMT
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<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS);
    -        Map<String, Object> ipOptions = (Map<String, Object>)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<String, Object> templateOptions = configBag.get(TEMPLATE_OPTIONS);
    -        Map<String, Object> ipOptions = (Map<String, Object>)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<String, ?> 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.
---

Mime
View raw message