public void testWhenPort22AndToItselfAuthorizesIngressOnce() throws ExecutionException {
AWSSecurityGroupClient client = createMock(AWSSecurityGroupClient.class);
Predicate<RegionAndName> tester = Predicates.alwaysTrue();
SecurityGroup group = createNiceMock(SecurityGroup.class);
Set<SecurityGroup> groups = ImmutableSet.<SecurityGroup> of(group);
ImmutableSet.Builder<IpPermission> permissions = ImmutableSet.builder();
permissions.add(IpPermission.builder()
.fromPort(22)
.toPort(22)
.ipProtocol(IpProtocol.TCP)
.ipRange("0.0.0.0/0")
.build());
permissions.add(IpPermission.builder()
.fromPort(0)
.toPort(65535)
.ipProtocol(IpProtocol.TCP)
.userIdGroupPair("ownerId", "group")
.build());
permissions.add(IpPermission.builder()
.fromPort(0)
.toPort(65535)
.ipProtocol(IpProtocol.UDP)
.userIdGroupPair("ownerId", "group")
.build());
client.createSecurityGroupInRegion("region", "group", "group");
expect(group.getOwnerId()).andReturn("ownerId");
expect(group.getId()).andReturn("sg-123456");
expect(client.describeSecurityGroupsInRegion("region", "group")).andReturn(Set.class.cast(groups));
client.authorizeSecurityGroupIngressInRegion("region", "sg-123456", permissions.build());
expect(client.describeSecurityGroupsInRegion("region", "group")).andReturn(Set.class.cast(groups));