JcloudsLocationSecurityGroupCustomizer extends BasicJcloudsLocationCustomizer { @Override public void customize(JcloudsLocation location, ComputeService computeService, Template template) { final Optional<SecurityGroupExtension> securityApi = computeService.getSecurityGroupExtension(); if (!securityApi.isPresent()) { LOG.warn("Security group extension for {} absent; cannot configure security groups in context: {}", computeService, applicationId); } else if (template.getLocation() == null) { LOG.warn("No location has been set on {}; cannot configure security groups in context: {}", template, applicationId); } else { LOG.info("Configuring security groups on location {} in context {}", location, applicationId); SecurityGroupEditor groupEditor = createSecurityGroupEditor(securityApi.get(), template.getLocation()); setSecurityGroupOnTemplate(location, template, groupEditor); } } protected  JcloudsLocationSecurityGroupCustomizer(String applicationId); protected  JcloudsLocationSecurityGroupCustomizer(String applicationId, Supplier<Cidr> sshCidrSupplier); static JcloudsLocationSecurityGroupCustomizer getInstance(String applicationId); static JcloudsLocationSecurityGroupCustomizer getInstance(Entity entity); JcloudsLocationSecurityGroupCustomizer setRetryExceptionPredicate(Predicate<Exception> predicate); JcloudsLocationSecurityGroupCustomizer setSshCidrSupplier(Supplier<Cidr> cidrSupplier); JcloudsLocationSecurityGroupCustomizer addPermissionsToLocation(final JcloudsMachineLocation location,
            IpPermission... permissions); JcloudsLocationSecurityGroupCustomizer addPermissionsToLocation(final JcloudsMachineLocation location,
             SecurityGroupDefinition securityGroupDefinition); JcloudsLocationSecurityGroupCustomizer addPermissionsToLocation(final JcloudsMachineLocation location,
              final Iterable<IpPermission> permissions); Collection<SecurityGroup> addPermissionsToLocationAndReturnSecurityGroup(
        final JcloudsMachineLocation location, final Iterable<IpPermission> permissions); void removePermissionsFromLocation(JcloudsMachineLocation location, Iterable<IpPermission> permissions); @Override void customize(JcloudsLocation location, ComputeService computeService, Template template); String getBrooklynCidrBlock(); static Predicate<Exception> newAwsExceptionRetryPredicate();  }
@Test public void testSecurityGroupAddedWhenJcloudsLocationCustomised() { Template template = mock(Template.class); TemplateOptions templateOptions = mock(TemplateOptions.class); when(template.getLocation()).thenReturn(location); when(template.getOptions()).thenReturn(templateOptions); SecurityGroup group = newGroup("id"); when(securityApi.createSecurityGroup(anyString(), eq(location))).thenReturn(group); when(securityApi.addIpPermission(any(IpPermission.class), eq(group))).thenReturn(group); JcloudsLocation jcloudsLocationA = new JcloudsLocation(MutableMap.of("deferConstruction", true)); JcloudsLocation jcloudsLocationB = new JcloudsLocation(MutableMap.of("deferConstruction", true)); customizer.customize(jcloudsLocationA, computeService, template); customizer.customize(jcloudsLocationB, computeService, template); verify(securityApi).createSecurityGroup(anyString(), eq(location)); verify(securityApi, times(4)).addIpPermission(any(IpPermission.class), eq(group)); verify(templateOptions, times(2)).securityGroups(anyString()); }