Added parser test for listFirewallRules

This commit is contained in:
andreisavu 2012-01-10 01:31:11 +02:00
parent c018e81eb3
commit 8c512e2d4e
3 changed files with 83 additions and 7 deletions

View File

@ -60,7 +60,7 @@ public class FirewallRule implements Comparable<FirewallRule> {
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<FirewallRule> {
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<FirewallRule> {
@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<FirewallRule> {
return ipAddress;
}
public String getIpAddressId() {
public long getIpAddressId() {
return ipAddressId;
}
@ -217,7 +217,7 @@ public class FirewallRule implements Comparable<FirewallRule> {
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<FirewallRule> {
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;

View File

@ -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<FirewallRule> {
@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<FirewallRule> expected() {
Set<String> 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()
);
}
}

View File

@ -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"} ] } }