{"action":"created","comment":{"url":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments/74480881","id":74480881,"diff_hunk":"@@ -0,0 +1,121 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+package org.apache.brooklyn.location.jclouds.networking;\n+\n+import static org.mockito.Matchers.any;\n+import static org.mockito.Mockito.*;\n+import static org.testng.Assert.assertEquals;\n+\n+import java.util.List;\n+\n+import org.apache.brooklyn.location.jclouds.JcloudsLocation;\n+import org.apache.brooklyn.location.jclouds.JcloudsMachineLocation;\n+import org.apache.brooklyn.util.collections.MutableMap;\n+import org.apache.brooklyn.util.net.Cidr;\n+import org.jclouds.compute.ComputeService;\n+import org.jclouds.compute.domain.Template;\n+import org.jclouds.compute.extensions.SecurityGroupExtension;\n+import org.jclouds.domain.Location;\n+import org.jclouds.net.domain.IpPermission;\n+import org.mockito.Answers;\n+import org.mockito.ArgumentCaptor;\n+import org.testng.annotations.BeforeMethod;\n+import org.testng.annotations.Test;\n+\n+import com.google.common.base.Optional;\n+import com.google.common.base.Supplier;\n+import com.google.common.collect.ImmutableList;\n+\n+public class SharedLocationSecurityGroupCustomizerTest {\n+\n+    TestSharedLocationSecurityGroupCustomizer customizer;\n+    JcloudsLocationSecurityGroupCustomizer sgCustomizer;\n+    ComputeService computeService;\n+    Location location;\n+    SecurityGroupExtension securityApi;\n+    private JcloudsLocation jcloudsLocation = new JcloudsLocation(MutableMap.of(\"deferConstruction\", true));\n+\n+    @BeforeMethod\n+    public void setUp() {\n+        sgCustomizer = mock(JcloudsLocationSecurityGroupCustomizer.class);\n+        customizer = new TestSharedLocationSecurityGroupCustomizer();\n+        location = mock(Location.class);\n+        securityApi = mock(SecurityGroupExtension.class);\n+        computeService = mock(ComputeService.class, Answers.RETURNS_DEEP_STUBS.get());\n+        when(computeService.getSecurityGroupExtension()).thenReturn(Optional.of(securityApi));\n+    }\n+\n+    @Test\n+    public void testLocationNameAppended() {\n+        customizer.setLocationName(\"Fred\");\n+        customizer.customize(jcloudsLocation, computeService, mock(Template.class));\n+        assertEquals(customizer.sharedGroupId, \"Fred-\" + jcloudsLocation.getId());\n+    }\n+\n+    @Test\n+    public void testCidrIsSetIfAvailable() {\n+        // Set cidr with over specified ip range which will be fixed by Cidr object\n+        customizer.setCidr(\"1.1.1.1/24\");\n+        customizer.customize(jcloudsLocation, computeService, mock(Template.class));\n+        ArgumentCaptor<Supplier<Cidr>> argumentCaptor = ArgumentCaptor.forClass((Class)Supplier.class);\n+        verify(sgCustomizer).setSshCidrSupplier(argumentCaptor.capture());\n+        Cidr cidr = argumentCaptor.getValue().get();\n+        assertEquals(cidr.toString(), \"1.1.1.0/24\");\n+    }\n+\n+    @Test\n+    public void testCidrNotSetIfNotavailable() {\n+        customizer.customize(jcloudsLocation, computeService, mock(Template.class));\n+        verify(sgCustomizer, never()).setSshCidrSupplier(any(Supplier.class));\n+    }\n+\n+\n+    @Test\n+    public void testPermissionsSetFromIpRanges() {\n+        customizer.setPortRanges(ImmutableList.of(\"99-100\"));\n+        when(sgCustomizer.getBrooklynCidrBlock()).thenReturn(\"10.10.10.10/24\");\n+        customizer.customize(jcloudsLocation, computeService, mock(JcloudsMachineLocation.class));\n+        ArgumentCaptor<List> listArgumentCaptor = ArgumentCaptor.forClass(List.class);","path":"locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/networking/SharedLocationSecurityGroupCustomizerTest.java","position":94,"original_position":94,"commit_id":"304a79ab18f57e446d0134de01de2cec7580ef3f","original_commit_id":"304a79ab18f57e446d0134de01de2cec7580ef3f","user":{"login":"aledsage","id":593113,"avatar_url":"https://avatars.githubusercontent.com/u/593113?v=3","gravatar_id":"","url":"https://api.github.com/users/aledsage","html_url":"https://github.com/aledsage","followers_url":"https://api.github.com/users/aledsage/followers","following_url":"https://api.github.com/users/aledsage/following{/other_user}","gists_url":"https://api.github.com/users/aledsage/gists{/gist_id}","starred_url":"https://api.github.com/users/aledsage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aledsage/subscriptions","organizations_url":"https://api.github.com/users/aledsage/orgs","repos_url":"https://api.github.com/users/aledsage/repos","events_url":"https://api.github.com/users/aledsage/events{/privacy}","received_events_url":"https://api.github.com/users/aledsage/received_events","type":"User","site_admin":false},"body":"Nice unit tests! I hadn't seen `ArgumentCaptor` before. Looks really useful!","created_at":"2016-08-11T18:50:00Z","updated_at":"2016-08-11T18:50:00Z","html_url":"https://github.com/apache/brooklyn-server/pull/292#discussion_r74480881","pull_request_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/292","_links":{"self":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments/74480881"},"html":{"href":"https://github.com/apache/brooklyn-server/pull/292#discussion_r74480881"},"pull_request":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/292"}}},"pull_request":{"url":"https://api.github.com/repos/apache/brooklyn-server/pulls/292","id":80448506,"html_url":"https://github.com/apache/brooklyn-server/pull/292","diff_url":"https://github.com/apache/brooklyn-server/pull/292.diff","patch_url":"https://github.com/apache/brooklyn-server/pull/292.patch","issue_url":"https://api.github.com/repos/apache/brooklyn-server/issues/292","number":292,"state":"open","locked":false,"title":"Shared location customizer","user":{"login":"duncangrant","id":770352,"avatar_url":"https://avatars.githubusercontent.com/u/770352?v=3","gravatar_id":"","url":"https://api.github.com/users/duncangrant","html_url":"https://github.com/duncangrant","followers_url":"https://api.github.com/users/duncangrant/followers","following_url":"https://api.github.com/users/duncangrant/following{/other_user}","gists_url":"https://api.github.com/users/duncangrant/gists{/gist_id}","starred_url":"https://api.github.com/users/duncangrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duncangrant/subscriptions","organizations_url":"https://api.github.com/users/duncangrant/orgs","repos_url":"https://api.github.com/users/duncangrant/repos","events_url":"https://api.github.com/users/duncangrant/events{/privacy}","received_events_url":"https://api.github.com/users/duncangrant/received_events","type":"User","site_admin":false},"body":"A location customizer that creates a single shared security group for each entity it is applied to as well as an individual entity.  The shared entity allows full tcp and udp traffic within members of the group.\r\n\r\nThis PR includes 85c65ed078060cd01f74732b7cc4bddef8a58006 from @bostko 's #276.\r\n\r\nThe implementation use the JcloudsLocationSecurityGroupCustomizer but has a no arg constructor so can be used in yaml.","created_at":"2016-08-08T13:13:05Z","updated_at":"2016-08-11T18:50:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1fb1daa849d1e54d35265c44f6a512626e0308af","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/292/commits","review_comments_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/292/comments","review_comment_url":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/brooklyn-server/issues/292/comments","statuses_url":"https://api.github.com/repos/apache/brooklyn-server/statuses/304a79ab18f57e446d0134de01de2cec7580ef3f","head":{"label":"duncangrant:extra-customizer","ref":"extra-customizer","sha":"304a79ab18f57e446d0134de01de2cec7580ef3f","user":{"login":"duncangrant","id":770352,"avatar_url":"https://avatars.githubusercontent.com/u/770352?v=3","gravatar_id":"","url":"https://api.github.com/users/duncangrant","html_url":"https://github.com/duncangrant","followers_url":"https://api.github.com/users/duncangrant/followers","following_url":"https://api.github.com/users/duncangrant/following{/other_user}","gists_url":"https://api.github.com/users/duncangrant/gists{/gist_id}","starred_url":"https://api.github.com/users/duncangrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duncangrant/subscriptions","organizations_url":"https://api.github.com/users/duncangrant/orgs","repos_url":"https://api.github.com/users/duncangrant/repos","events_url":"https://api.github.com/users/duncangrant/events{/privacy}","received_events_url":"https://api.github.com/users/duncangrant/received_events","type":"User","site_admin":false},"repo":{"id":58385058,"name":"brooklyn-server","full_name":"duncangrant/brooklyn-server","owner":{"login":"duncangrant","id":770352,"avatar_url":"https://avatars.githubusercontent.com/u/770352?v=3","gravatar_id":"","url":"https://api.github.com/users/duncangrant","html_url":"https://github.com/duncangrant","followers_url":"https://api.github.com/users/duncangrant/followers","following_url":"https://api.github.com/users/duncangrant/following{/other_user}","gists_url":"https://api.github.com/users/duncangrant/gists{/gist_id}","starred_url":"https://api.github.com/users/duncangrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/duncangrant/subscriptions","organizations_url":"https://api.github.com/users/duncangrant/orgs","repos_url":"https://api.github.com/users/duncangrant/repos","events_url":"https://api.github.com/users/duncangrant/events{/privacy}","received_events_url":"https://api.github.com/users/duncangrant/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/duncangrant/brooklyn-server","description":"Mirror of Apache Brooklyn server","fork":true,"url":"https://api.github.com/repos/duncangrant/brooklyn-server","forks_url":"https://api.github.com/repos/duncangrant/brooklyn-server/forks","keys_url":"https://api.github.com/repos/duncangrant/brooklyn-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/duncangrant/brooklyn-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/duncangrant/brooklyn-server/teams","hooks_url":"https://api.github.com/repos/duncangrant/brooklyn-server/hooks","issue_events_url":"https://api.github.com/repos/duncangrant/brooklyn-server/issues/events{/number}","events_url":"https://api.github.com/repos/duncangrant/brooklyn-server/events","assignees_url":"https://api.github.com/repos/duncangrant/brooklyn-server/assignees{/user}","branches_url":"https://api.github.com/repos/duncangrant/brooklyn-server/branches{/branch}","tags_url":"https://api.github.com/repos/duncangrant/brooklyn-server/tags","blobs_url":"https://api.github.com/repos/duncangrant/brooklyn-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/duncangrant/brooklyn-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/duncangrant/brooklyn-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/duncangrant/brooklyn-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/duncangrant/brooklyn-server/statuses/{sha}","languages_url":"https://api.github.com/repos/duncangrant/brooklyn-server/languages","stargazers_url":"https://api.github.com/repos/duncangrant/brooklyn-server/stargazers","contributors_url":"https://api.github.com/repos/duncangrant/brooklyn-server/contributors","subscribers_url":"https://api.github.com/repos/duncangrant/brooklyn-server/subscribers","subscription_url":"https://api.github.com/repos/duncangrant/brooklyn-server/subscription","commits_url":"https://api.github.com/repos/duncangrant/brooklyn-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/duncangrant/brooklyn-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/duncangrant/brooklyn-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/duncangrant/brooklyn-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/duncangrant/brooklyn-server/contents/{+path}","compare_url":"https://api.github.com/repos/duncangrant/brooklyn-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/duncangrant/brooklyn-server/merges","archive_url":"https://api.github.com/repos/duncangrant/brooklyn-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/duncangrant/brooklyn-server/downloads","issues_url":"https://api.github.com/repos/duncangrant/brooklyn-server/issues{/number}","pulls_url":"https://api.github.com/repos/duncangrant/brooklyn-server/pulls{/number}","milestones_url":"https://api.github.com/repos/duncangrant/brooklyn-server/milestones{/number}","notifications_url":"https://api.github.com/repos/duncangrant/brooklyn-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/duncangrant/brooklyn-server/labels{/name}","releases_url":"https://api.github.com/repos/duncangrant/brooklyn-server/releases{/id}","deployments_url":"https://api.github.com/repos/duncangrant/brooklyn-server/deployments","created_at":"2016-05-09T14:56:51Z","updated_at":"2016-05-09T14:57:00Z","pushed_at":"2016-08-08T13:09:51Z","git_url":"git://github.com/duncangrant/brooklyn-server.git","ssh_url":"git@github.com:duncangrant/brooklyn-server.git","clone_url":"https://github.com/duncangrant/brooklyn-server.git","svn_url":"https://github.com/duncangrant/brooklyn-server","homepage":null,"size":30693,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"ddb6acc9238d0ea6fe2a02016d2983d089aacdba","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":47246081,"name":"brooklyn-server","full_name":"apache/brooklyn-server","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/brooklyn-server","description":"Mirror of Apache Brooklyn server","fork":false,"url":"https://api.github.com/repos/apache/brooklyn-server","forks_url":"https://api.github.com/repos/apache/brooklyn-server/forks","keys_url":"https://api.github.com/repos/apache/brooklyn-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/brooklyn-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/brooklyn-server/teams","hooks_url":"https://api.github.com/repos/apache/brooklyn-server/hooks","issue_events_url":"https://api.github.com/repos/apache/brooklyn-server/issues/events{/number}","events_url":"https://api.github.com/repos/apache/brooklyn-server/events","assignees_url":"https://api.github.com/repos/apache/brooklyn-server/assignees{/user}","branches_url":"https://api.github.com/repos/apache/brooklyn-server/branches{/branch}","tags_url":"https://api.github.com/repos/apache/brooklyn-server/tags","blobs_url":"https://api.github.com/repos/apache/brooklyn-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/brooklyn-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/brooklyn-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/brooklyn-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/brooklyn-server/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/brooklyn-server/languages","stargazers_url":"https://api.github.com/repos/apache/brooklyn-server/stargazers","contributors_url":"https://api.github.com/repos/apache/brooklyn-server/contributors","subscribers_url":"https://api.github.com/repos/apache/brooklyn-server/subscribers","subscription_url":"https://api.github.com/repos/apache/brooklyn-server/subscription","commits_url":"https://api.github.com/repos/apache/brooklyn-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/brooklyn-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/brooklyn-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/brooklyn-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/brooklyn-server/contents/{+path}","compare_url":"https://api.github.com/repos/apache/brooklyn-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/brooklyn-server/merges","archive_url":"https://api.github.com/repos/apache/brooklyn-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/brooklyn-server/downloads","issues_url":"https://api.github.com/repos/apache/brooklyn-server/issues{/number}","pulls_url":"https://api.github.com/repos/apache/brooklyn-server/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/brooklyn-server/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/brooklyn-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/brooklyn-server/labels{/name}","releases_url":"https://api.github.com/repos/apache/brooklyn-server/releases{/id}","deployments_url":"https://api.github.com/repos/apache/brooklyn-server/deployments","created_at":"2015-12-02T08:00:06Z","updated_at":"2016-05-30T11:46:29Z","pushed_at":"2016-08-11T15:17:22Z","git_url":"git://github.com/apache/brooklyn-server.git","ssh_url":"git@github.com:apache/brooklyn-server.git","clone_url":"https://github.com/apache/brooklyn-server.git","svn_url":"https://github.com/apache/brooklyn-server","homepage":null,"size":31006,"stargazers_count":10,"watchers_count":10,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":35,"mirror_url":"git://git.apache.org/brooklyn-server.git","open_issues_count":19,"forks":35,"open_issues":19,"watchers":10,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/292"},"html":{"href":"https://github.com/apache/brooklyn-server/pull/292"},"issue":{"href":"https://api.github.com/repos/apache/brooklyn-server/issues/292"},"comments":{"href":"https://api.github.com/repos/apache/brooklyn-server/issues/292/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/292/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/brooklyn-server/pulls/292/commits"},"statuses":{"href":"https://api.github.com/repos/apache/brooklyn-server/statuses/304a79ab18f57e446d0134de01de2cec7580ef3f"}}}}
{"actor":{"display_login":"aledsage"}}