From 8c512e2d4e72189eba1d4da366b04f43a0960e76 Mon Sep 17 00:00:00 2001 From: andreisavu Date: Tue, 10 Jan 2012 01:31:11 +0200 Subject: [PATCH] Added parser test for listFirewallRules --- .../cloudstack/domain/FirewallRule.java | 14 ++-- .../parse/ListFirewallRulesResponseTest.java | 72 +++++++++++++++++++ .../resources/listfirewallrulesresponse.json | 4 ++ 3 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListFirewallRulesResponseTest.java create mode 100644 apis/cloudstack/src/test/resources/listfirewallrulesresponse.json diff --git a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java index 276c465632..144a77aa0e 100644 --- a/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java +++ b/apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/FirewallRule.java @@ -60,7 +60,7 @@ public class FirewallRule implements Comparable { private String icmpType; private String ipAddress; - private String ipAddressId; + private long ipAddressId; private Protocol protocol; private String state; @@ -100,7 +100,7 @@ public class FirewallRule implements Comparable { return this; } - public Builder ipAddressId(String ipAddressId) { + public Builder ipAddressId(long ipAddressId) { this.ipAddressId = ipAddressId; return this; } @@ -135,12 +135,12 @@ public class FirewallRule implements Comparable { @SerializedName("ipaddress") private String ipAddress; @SerializedName("ipaddressid") - private String ipAddressId; + private long ipAddressId; private Protocol protocol; private String state; public FirewallRule(long id, String CIDRs, int startPort, int endPort, - String icmpCode, String icmpType, String ipAddress, String ipAddressId, + String icmpCode, String icmpType, String ipAddress, long ipAddressId, Protocol protocol, String state) { this.id = id; this.CIDRs = CIDRs; @@ -187,7 +187,7 @@ public class FirewallRule implements Comparable { return ipAddress; } - public String getIpAddressId() { + public long getIpAddressId() { return ipAddressId; } @@ -217,7 +217,7 @@ public class FirewallRule implements Comparable { return false; if (ipAddress != null ? !ipAddress.equals(that.ipAddress) : that.ipAddress != null) return false; - if (ipAddressId != null ? !ipAddressId.equals(that.ipAddressId) : that.ipAddressId != null) + if (ipAddressId != that.ipAddressId) return false; if (protocol != null ? !protocol.equals(that.protocol) : that.protocol != null) return false; @@ -236,7 +236,7 @@ public class FirewallRule implements Comparable { result = 31 * result + (icmpCode != null ? icmpCode.hashCode() : 0); result = 31 * result + (icmpType != null ? icmpType.hashCode() : 0); result = 31 * result + (ipAddress != null ? ipAddress.hashCode() : 0); - result = 31 * result + (ipAddressId != null ? ipAddressId.hashCode() : 0); + result = 31 * result + (int) (ipAddressId ^ (ipAddressId >>> 32)); result = 31 * result + (protocol != null ? protocol.hashCode() : 0); result = 31 * result + (state != null ? state.hashCode() : 0); return result; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListFirewallRulesResponseTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListFirewallRulesResponseTest.java new file mode 100644 index 0000000000..642a5cbee3 --- /dev/null +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/parse/ListFirewallRulesResponseTest.java @@ -0,0 +1,72 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.parse; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.cloudstack.config.CloudStackParserModule; +import org.jclouds.cloudstack.domain.FirewallRule; +import org.jclouds.json.BaseSetParserTest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import java.util.Set; + +/** + * + * @author Andrei Savu + */ +@Test(groups = "unit") +public class ListFirewallRulesResponseTest extends BaseSetParserTest { + + @Override + protected Injector injector() { + return Guice.createInjector(new CloudStackParserModule(), new GsonModule() { + + @Override + protected void configure() { + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } + + }); + } + + @Override + public String resource() { + return "/listfirewallrulesresponse.json"; + } + + @Override + @SelectJson("firewallrule") + public Set expected() { + Set cidrs = ImmutableSet.of("0.0.0.0/1", "128.0.0.0/1"); + return ImmutableSet.of( + FirewallRule.builder().id(2017).protocol(FirewallRule.Protocol.TCP).startPort(30) + .endPort(35).ipAddressId(2).ipAddress("10.27.27.51").state("Active").CIDRs("0.0.0.0/0").build(), + FirewallRule.builder().id(2016).protocol(FirewallRule.Protocol.TCP).startPort(22) + .endPort(22).ipAddressId(2).ipAddress("10.27.27.51").state("Active").CIDRs("0.0.0.0/0").build(), + FirewallRule.builder().id(10).protocol(FirewallRule.Protocol.TCP).startPort(22) + .endPort(22).ipAddressId(8).ipAddress("10.27.27.57").state("Active").CIDRs("0.0.0.0/0").build() + ); + } + +} diff --git a/apis/cloudstack/src/test/resources/listfirewallrulesresponse.json b/apis/cloudstack/src/test/resources/listfirewallrulesresponse.json new file mode 100644 index 0000000000..e93d76e4cb --- /dev/null +++ b/apis/cloudstack/src/test/resources/listfirewallrulesresponse.json @@ -0,0 +1,4 @@ +{ "listfirewallrulesresponse" : { "count":3 ,"firewallrule" : [ + {"id":2017,"protocol":"tcp","startport":"30","endport":"35","ipaddressid":2,"ipaddress":"10.27.27.51","state":"Active","cidrlist":"0.0.0.0/0"}, + {"id":2016,"protocol":"tcp","startport":"22","endport":"22","ipaddressid":2,"ipaddress":"10.27.27.51","state":"Active","cidrlist":"0.0.0.0/0"}, + {"id":10,"protocol":"tcp","startport":"22","endport":"22","ipaddressid":8,"ipaddress":"10.27.27.57","state":"Active","cidrlist":"0.0.0.0/0"} ] } } \ No newline at end of file