Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/292#discussion_r74480881
  
    --- Diff: 
locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizerTest.java
 ---
    @@ -0,0 +1,121 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.location.jclouds.networking;
    +
    +import static org.mockito.Matchers.any;
    +import static org.mockito.Mockito.*;
    +import static org.testng.Assert.assertEquals;
    +
    +import java.util.List;
    +
    +import org.apache.brooklyn.location.jclouds.JcloudsLocation;
    +import org.apache.brooklyn.location.jclouds.JcloudsMachineLocation;
    +import org.apache.brooklyn.util.collections.MutableMap;
    +import org.apache.brooklyn.util.net.Cidr;
    +import org.jclouds.compute.ComputeService;
    +import org.jclouds.compute.domain.Template;
    +import org.jclouds.compute.extensions.SecurityGroupExtension;
    +import org.jclouds.domain.Location;
    +import org.jclouds.net.domain.IpPermission;
    +import org.mockito.Answers;
    +import org.mockito.ArgumentCaptor;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.base.Optional;
    +import com.google.common.base.Supplier;
    +import com.google.common.collect.ImmutableList;
    +
    +public class SharedLocationSecurityGroupCustomizerTest {
    +
    +    TestSharedLocationSecurityGroupCustomizer customizer;
    +    JcloudsLocationSecurityGroupCustomizer sgCustomizer;
    +    ComputeService computeService;
    +    Location location;
    +    SecurityGroupExtension securityApi;
    +    private JcloudsLocation jcloudsLocation = new 
JcloudsLocation(MutableMap.of("deferConstruction", true));
    +
    +    @BeforeMethod
    +    public void setUp() {
    +        sgCustomizer = mock(JcloudsLocationSecurityGroupCustomizer.class);
    +        customizer = new TestSharedLocationSecurityGroupCustomizer();
    +        location = mock(Location.class);
    +        securityApi = mock(SecurityGroupExtension.class);
    +        computeService = mock(ComputeService.class, 
Answers.RETURNS_DEEP_STUBS.get());
    +        
when(computeService.getSecurityGroupExtension()).thenReturn(Optional.of(securityApi));
    +    }
    +
    +    @Test
    +    public void testLocationNameAppended() {
    +        customizer.setLocationName("Fred");
    +        customizer.customize(jcloudsLocation, computeService, 
mock(Template.class));
    +        assertEquals(customizer.sharedGroupId, "Fred-" + 
jcloudsLocation.getId());
    +    }
    +
    +    @Test
    +    public void testCidrIsSetIfAvailable() {
    +        // Set cidr with over specified ip range which will be fixed by 
Cidr object
    +        customizer.setCidr("1.1.1.1/24");
    +        customizer.customize(jcloudsLocation, computeService, 
mock(Template.class));
    +        ArgumentCaptor<Supplier<Cidr>> argumentCaptor = 
ArgumentCaptor.forClass((Class)Supplier.class);
    +        verify(sgCustomizer).setSshCidrSupplier(argumentCaptor.capture());
    +        Cidr cidr = argumentCaptor.getValue().get();
    +        assertEquals(cidr.toString(), "1.1.1.0/24");
    +    }
    +
    +    @Test
    +    public void testCidrNotSetIfNotavailable() {
    +        customizer.customize(jcloudsLocation, computeService, 
mock(Template.class));
    +        verify(sgCustomizer, 
never()).setSshCidrSupplier(any(Supplier.class));
    +    }
    +
    +
    +    @Test
    +    public void testPermissionsSetFromIpRanges() {
    +        customizer.setPortRanges(ImmutableList.of("99-100"));
    +        
when(sgCustomizer.getBrooklynCidrBlock()).thenReturn("10.10.10.10/24");
    +        customizer.customize(jcloudsLocation, computeService, 
mock(JcloudsMachineLocation.class));
    +        ArgumentCaptor<List> listArgumentCaptor = 
ArgumentCaptor.forClass(List.class);
    --- End diff --
    
    Nice unit tests! I hadn't seen `ArgumentCaptor` before. Looks really useful!


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to