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 9d7a857383
commit 7a013fab7e
6 changed files with 67 additions and 38 deletions

View File

@ -31,28 +31,26 @@ 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.
*
* @author Jeremy Daggett
* @author chamerling
*/
*/
public class FloatingIP implements Comparable<FloatingIP> {
public static Builder<?> builder() {
public static Builder<?> builder() {
return new ConcreteBuilder();
}
public Builder<?> toBuilder() {
return new ConcreteBuilder().fromFloatingIP(this);
}
public abstract static class Builder<T extends Builder<T>> {
public abstract static class Builder<T extends Builder<T>> {
protected abstract T self();
protected String id;
protected String ip;
protected String fixedIp;
protected String instanceId;
protected String pool;
/**
* @see FloatingIP#getId()
*/
@ -85,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) {
@ -94,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());
}
}
@ -111,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() {
@ -140,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
@ -153,14 +167,15 @@ 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
public String toString() {
return string().toString();

View File

@ -34,9 +34,7 @@ import com.google.common.base.Optional;
import com.google.common.collect.Multimap;
/**
* Tests behavior of {@code ServerApi}
*
* @author Adrian Cole
* Tests the behavior of the {@link FloatingIPApi}
*/
@Test(groups = "live", testName = "FloatingIPApiLiveTest")
public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
@ -60,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

@ -33,8 +33,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
/**
*
* @author Michael Arnold
* Tests parsing of {@link FloatingIP} JSON data.
*/
@Test(groups = "unit", testName = "ParseFloatingIPListTest")
public class ParseFloatingIPListTest extends BaseSetParserTest<FloatingIP> {
@ -48,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

@ -30,7 +30,7 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Michael Arnold
* Test to parse a {@link FloatingIP}
*/
@Test(groups = "unit", testName = "ParseFloatingIPTest")
public class ParseFloatingIPTest extends BaseItemParserTest<FloatingIP> {
@ -44,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" :
{
"id" : 1,
"ip" : "10.0.0.3",
"fixed_ip" : "10.0.0.2",
"instance_id" : 123
}
}
"floating_ip": {
"id": 1,
"ip": "10.0.0.3",
"fixed_ip": "10.0.0.2",
"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
}
]
}
}