JCLOUDS-471: Adds pool field to FloatingIP and updated related tests.

This commit is contained in:
Jeremy Daggett 2014-02-16 21:36:35 -08:00 committed by Jeremy Daggett
parent 8c8fe83f3e
commit 235092e517
6 changed files with 71 additions and 31 deletions

View File

@ -31,7 +31,6 @@ import com.google.common.base.Objects.ToStringHelper;
* A Floating IP is an IP address that can be created and associated with a
* Server instance. Floating IPs can also be disassociated and deleted from a
* Server instance.
*
*/
public class FloatingIP implements Comparable<FloatingIP> {
@ -50,6 +49,7 @@ public class FloatingIP implements Comparable<FloatingIP> {
protected String ip;
protected String fixedIp;
protected String instanceId;
protected String pool;
/**
* @see FloatingIP#getId()
@ -83,8 +83,16 @@ public class FloatingIP implements Comparable<FloatingIP> {
return self();
}
/**
* @see FloatingIP#getPool()
*/
public T pool(String pool) {
this.pool = pool;
return self();
}
public FloatingIP build() {
return new FloatingIP(id, ip, fixedIp, instanceId);
return new FloatingIP(id, ip, fixedIp, instanceId, pool);
}
public T fromFloatingIP(FloatingIP in) {
@ -92,7 +100,8 @@ public class FloatingIP implements Comparable<FloatingIP> {
.id(in.getId())
.ip(in.getIp())
.fixedIp(in.getFixedIp())
.instanceId(in.getInstanceId());
.instanceId(in.getInstanceId())
.pool(in.getPool());
}
}
@ -109,15 +118,17 @@ public class FloatingIP implements Comparable<FloatingIP> {
private final String fixedIp;
@Named("instance_id")
private final String instanceId;
private final String pool;
@ConstructorProperties({
"id", "ip", "fixed_ip", "instance_id"
"id", "ip", "fixed_ip", "instance_id", "pool"
})
protected FloatingIP(String id, String ip, @Nullable String fixedIp, @Nullable String instanceId) {
protected FloatingIP(String id, String ip, @Nullable String fixedIp, @Nullable String instanceId, @Nullable String pool) {
this.id = checkNotNull(id, "id");
this.ip = checkNotNull(ip, "ip");
this.fixedIp = fixedIp;
this.instanceId = instanceId;
this.pool = pool;
}
public String getId() {
@ -138,9 +149,14 @@ public class FloatingIP implements Comparable<FloatingIP> {
return this.instanceId;
}
@Nullable
public String getPool() {
return this.pool;
}
@Override
public int hashCode() {
return Objects.hashCode(id, ip, fixedIp, instanceId);
return Objects.hashCode(id, ip, fixedIp, instanceId, pool);
}
@Override
@ -151,12 +167,13 @@ public class FloatingIP implements Comparable<FloatingIP> {
return Objects.equal(this.id, that.id)
&& Objects.equal(this.ip, that.ip)
&& Objects.equal(this.fixedIp, that.fixedIp)
&& Objects.equal(this.instanceId, that.instanceId);
&& Objects.equal(this.instanceId, that.instanceId)
&& Objects.equal(this.pool, that.pool);
}
protected ToStringHelper string() {
return Objects.toStringHelper(this)
.add("id", id).add("ip", ip).add("fixedIp", fixedIp).add("instanceId", instanceId);
.add("id", id).add("ip", ip).add("fixedIp", fixedIp).add("instanceId", instanceId).add("pool", pool);
}
@Override

View File

@ -34,7 +34,7 @@ import com.google.common.base.Optional;
import com.google.common.collect.Multimap;
/**
* Tests behavior of {@code ServerApi}
* Tests the behavior of the {@link FloatingIPApi}
*/
@Test(groups = "live", testName = "FloatingIPApiLiveTest")
public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
@ -58,7 +58,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
assertEquals(newDetails.getIp(), ip.getIp());
assertEquals(newDetails.getFixedIp(), ip.getFixedIp());
assertEquals(newDetails.getInstanceId(), ip.getInstanceId());
assertEquals(newDetails.getPool(), ip.getPool());
}
}
}

View File

@ -32,6 +32,9 @@ import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests parsing of {@link FloatingIP} JSON data.
*/
@Test(groups = "unit", testName = "ParseFloatingIPListTest")
public class ParseFloatingIPListTest extends BaseSetParserTest<FloatingIP> {
@ -44,8 +47,11 @@ public class ParseFloatingIPListTest extends BaseSetParserTest<FloatingIP> {
@SelectJson("floating_ips")
@Consumes(MediaType.APPLICATION_JSON)
public Set<FloatingIP> expected() {
return ImmutableSet.of(FloatingIP.builder().id("1").instanceId("12").ip("10.0.0.3").fixedIp("11.0.0.1").build(),
FloatingIP.builder().id("2").instanceId(null).ip("10.0.0.5").fixedIp(null).build());
return ImmutableSet.of(
FloatingIP.builder().id("1").instanceId("12").ip("10.0.0.3").fixedIp("11.0.0.1").pool("nova").build(),
FloatingIP.builder().id("2").instanceId(null).ip("10.0.0.5").fixedIp(null).pool("nova").build(),
FloatingIP.builder().id("3").instanceId("13").ip("10.0.0.13").fixedIp("11.0.0.3").build(),
FloatingIP.builder().id("4").instanceId("14").ip("10.0.0.14").fixedIp("11.0.0.4").pool(null).build());
}
protected Injector injector() {

View File

@ -29,6 +29,9 @@ import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Test to parse a {@link FloatingIP}
*/
@Test(groups = "unit", testName = "ParseFloatingIPTest")
public class ParseFloatingIPTest extends BaseItemParserTest<FloatingIP> {
@ -41,7 +44,7 @@ public class ParseFloatingIPTest extends BaseItemParserTest<FloatingIP> {
@SelectJson("floating_ip")
@Consumes(MediaType.APPLICATION_JSON)
public FloatingIP expected() {
return FloatingIP.builder().id("1").instanceId("123").fixedIp("10.0.0.2").ip("10.0.0.3").build();
return FloatingIP.builder().id("1").instanceId("123").fixedIp("10.0.0.2").ip("10.0.0.3").pool("nova").build();
}
protected Injector injector() {

View File

@ -1,9 +1,9 @@
{
"floating_ip" :
{
"floating_ip": {
"id": 1,
"ip": "10.0.0.3",
"fixed_ip": "10.0.0.2",
"instance_id" : 123
"instance_id": 123,
"pool": "nova"
}
}

View File

@ -4,13 +4,27 @@
"instance_id": 12,
"ip" : "10.0.0.3",
"fixed_ip": "11.0.0.1",
"id" : 1
"id" : 1,
"pool": "nova"
},
{
"instance_id": null,
"ip": "10.0.0.5",
"fixed_ip": null,
"id": 2
"id": 2,
"pool": "nova"
},
{
"instance_id": 13,
"ip": "10.0.0.13",
"fixed_ip": "11.0.0.3",
"id": 3
},
{
"instance_id": 14,
"ip": "10.0.0.14",
"fixed_ip": "11.0.0.4",
"id": 4
}
]
}