Nuking redundant assert in nova test, adding CloudStack IngressRule->IpPermission converter
Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/0b7a1b4d Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/0b7a1b4d Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/0b7a1b4d Branch: refs/heads/jclouds-101 Commit: 0b7a1b4dc60c511de9c4d1567d4232457178eb73 Parents: a412872 Author: Andrew Bayer <[email protected]> Authored: Thu Jun 13 10:29:53 2013 -0700 Committer: Andrew Bayer <[email protected]> Committed: Thu Jun 13 10:29:53 2013 -0700 ---------------------------------------------------------------------- .../functions/IngressRuleToIpPermission.java | 55 ++++++++++++++++++ .../IngressRuleToIpPermissionTest.java | 61 ++++++++++++++++++++ .../SecurityGroupRuleToIpPermissionTest.java | 1 - 3 files changed, 116 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/0b7a1b4d/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermission.java ---------------------------------------------------------------------- diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermission.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermission.java new file mode 100644 index 0000000..ed04568 --- /dev/null +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermission.java @@ -0,0 +1,55 @@ +/* + * 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.jclouds.cloudstack.compute.functions; + +import javax.annotation.Resource; +import javax.inject.Named; + +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.cloudstack.domain.IngressRule; +import org.jclouds.logging.Logger; +import org.jclouds.net.domain.IpPermission; +import org.jclouds.net.domain.IpProtocol; + +import com.google.common.base.Function; + + +/** + * A function for transforming a CloudStack-specific IngressRule into a generic + * IpPermission object. + * + * @author Andrew Bayer + */ +public class IngressRuleToIpPermission implements Function<IngressRule, IpPermission> { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + + public IngressRuleToIpPermission() { + } + + @Override + public IpPermission apply(IngressRule rule) { + IpPermission.Builder builder = IpPermission.builder(); + builder.ipProtocol(IpProtocol.fromValue(rule.getProtocol())); + builder.fromPort(rule.getStartPort()); + builder.toPort(rule.getEndPort()); + builder.cidrBlock(rule.getCIDR()); + + return builder.build(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/0b7a1b4d/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermissionTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermissionTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermissionTest.java new file mode 100644 index 0000000..0f5babb --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/functions/IngressRuleToIpPermissionTest.java @@ -0,0 +1,61 @@ +/* + * 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.jclouds.cloudstack.compute.functions; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.jclouds.cloudstack.domain.IngressRule; +import org.jclouds.net.domain.IpPermission; +import org.jclouds.net.domain.IpProtocol; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + + +/** + * Tests for the function for transforming a cloudstack specific IngressRule into a generic + * IpPermission object. + * + * @author Andrew Bayer + */ +public class IngressRuleToIpPermissionTest { + + @Test + public void testApplyWithTCP() { + IngressRule ruleToConvert = IngressRule.builder() + .id("some-id") + .account("some-account") + .securityGroupName("some-group-name") + .protocol(IpProtocol.TCP.toString()) + .startPort(10) + .endPort(20) + .CIDR("0.0.0.0/0") + .build(); + + IngressRuleToIpPermission converter = new IngressRuleToIpPermission(); + + IpPermission convertedPerm = converter.apply(ruleToConvert); + + assertEquals(convertedPerm.getIpProtocol(), IpProtocol.fromValue(ruleToConvert.getProtocol())); + assertEquals(convertedPerm.getFromPort(), ruleToConvert.getStartPort()); + assertEquals(convertedPerm.getToPort(), ruleToConvert.getEndPort()); + assertEquals(convertedPerm.getCidrBlocks(), ImmutableSet.of("0.0.0.0/0")); + assertTrue(convertedPerm.getTenantIdGroupNamePairs().size() == 0); + assertTrue(convertedPerm.getGroupIds().size() == 0); + } +} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/0b7a1b4d/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java ---------------------------------------------------------------------- diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java index b0b70eb..1702a13 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java @@ -80,7 +80,6 @@ public class SecurityGroupRuleToIpPermissionTest { assertEquals(convertedPerm.getIpProtocol(), ruleToConvert.getIpProtocol()); assertEquals(convertedPerm.getFromPort(), ruleToConvert.getFromPort()); assertEquals(convertedPerm.getToPort(), ruleToConvert.getToPort()); - assertEquals(convertedPerm.getToPort(), ruleToConvert.getToPort()); assertEquals(convertedPerm.getCidrBlocks(), ImmutableSet.of("0.0.0.0/0")); assertTrue(convertedPerm.getTenantIdGroupNamePairs().size() == 0); }
