Make links nullable

This commit is contained in:
Arvind Nadendla 2016-06-18 23:49:38 -07:00 committed by Zack Shoylev
parent 7016b040d7
commit b4624161ae
4 changed files with 45 additions and 21 deletions

View File

@ -49,7 +49,7 @@ public class Resource implements Comparable<Resource> {
protected String id;
protected String name;
protected Set<Link> links = ImmutableSet.of();
protected Set<Link> links;
/**
* @see Resource#getId()
@ -71,12 +71,12 @@ public class Resource implements Comparable<Resource> {
* @see Resource#getLinks()
*/
public T links(Set<Link> links) {
this.links = ImmutableSet.copyOf(checkNotNull(links, "links"));
this.links = links == null ? null : ImmutableSet.copyOf(links);
return self();
}
public T links(Link... in) {
return links(ImmutableSet.copyOf(in));
return links(in == null ? null : ImmutableSet.copyOf(in));
}
public Resource build() {
@ -108,7 +108,7 @@ public class Resource implements Comparable<Resource> {
protected Resource(String id, @Nullable String name, @Nullable Set<Link> links) {
this.id = checkNotNull(id, "id");
this.name = name;
this.links = links == null ? ImmutableSet.<Link>of() : ImmutableSet.copyOf(checkNotNull(links, "links"));
this.links = links == null ? null : ImmutableSet.copyOf(links);
}
/**
@ -132,6 +132,7 @@ public class Resource implements Comparable<Resource> {
/**
* @return the links of the id address allocated to the new server
*/
@Nullable
public Set<Link> getLinks() {
return this.links;
}

View File

@ -27,6 +27,7 @@ import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.v2_0.config.NovaParserModule;
import org.jclouds.openstack.v2_0.domain.Extension;
import org.jclouds.openstack.v2_0.domain.Link;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
@ -47,22 +48,25 @@ public class ParseExtensionListNormalTest extends BaseSetParserTest<Extension> {
@Consumes(MediaType.APPLICATION_JSON)
public Set<Extension> expected() {
return ImmutableSet.of(
Extension.builder().alias("os-keypairs").name("Keypairs")
.namespace(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-08-08T00:00:00+00:00"))
.description("Keypair Support").build(),
Extension.builder().alias("os-volumes").name("Volumes")
.namespace(URI.create("http://docs.openstack.org/ext/volumes/api/v1.1"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-03-25T00:00:00+00:00"))
.description("Volumes support").build(),
Extension.builder().alias("os-keypairs").name("Keypairs").namespace(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-08-08T00:00:00+00:00")).description("Keypair Support")
.links(Link.builder().relation(Link.Relation.SELF).href(URI.create("http://docs.openstack.org/ext/keypairs/api/v1.1")).build())
.build(),
Extension.builder().alias("os-volumes").name("Volumes").namespace(URI.create("http://docs.openstack.org/ext/volumes/api/v1.1"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-03-25T00:00:00+00:00")).description("Volumes support")
.links(Link.builder().relation(Link.Relation.SELF).href(URI.create("http://docs.openstack.org/ext/volumes/api/v1.1")).build())
.build(),
Extension.builder().alias("security_groups").name("SecurityGroups")
.namespace(URI.create("http://docs.openstack.org/ext/securitygroups/api/v1.1"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-07-21T00:00:00+00:00"))
.description("Security group support").build(),
.description("Security group support")
.links(Link.builder().relation(Link.Relation.SELF).href(URI.create("http://docs.openstack.org/ext/securitygroups/api/v1.1")).build())
.build(),
Extension.builder().alias("os-floating-ips").name("Floating_ips")
.namespace(URI.create("http://docs.openstack.org/ext/floating_ips/api/v1.1"))
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-06-16T00:00:00+00:00"))
.description("Floating IPs support").build());
.updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-06-16T00:00:00+00:00")).description("Floating IPs support")
.links(Link.builder().relation(Link.Relation.SELF).href(URI.create("http://docs.openstack.org/ext/floating_ips/api/v1.1")).build())
.build());
}
protected Injector injector() {

View File

@ -3,7 +3,12 @@
{
"updated": "2011-08-08T00:00:00+00:00",
"name": "Keypairs",
"links": [],
"links": [
{
"rel": "self",
"href": "http://docs.openstack.org/ext/keypairs/api/v1.1"
}
],
"namespace": "http://docs.openstack.org/ext/keypairs/api/v1.1",
"alias": "os-keypairs",
"description": "Keypair Support"
@ -11,7 +16,12 @@
{
"updated": "2011-03-25T00:00:00+00:00",
"name": "Volumes",
"links": [],
"links": [
{
"rel": "self",
"href": "http://docs.openstack.org/ext/volumes/api/v1.1"
}
],
"namespace": "http://docs.openstack.org/ext/volumes/api/v1.1",
"alias": "os-volumes",
"description": "Volumes support"
@ -19,7 +29,12 @@
{
"updated": "2011-07-21T00:00:00+00:00",
"name": "SecurityGroups",
"links": [],
"links": [
{
"rel": "self",
"href": "http://docs.openstack.org/ext/securitygroups/api/v1.1"
}
],
"namespace": "http://docs.openstack.org/ext/securitygroups/api/v1.1",
"alias": "security_groups",
"description": "Security group support"
@ -27,7 +42,12 @@
{
"updated": "2011-06-16T00:00:00+00:00",
"name": "Floating_ips",
"links": [],
"links": [
{
"rel": "self",
"href": "http://docs.openstack.org/ext/floating_ips/api/v1.1"
}
],
"namespace": "http://docs.openstack.org/ext/floating_ips/api/v1.1",
"alias": "os-floating-ips",
"description": "Floating IPs support"

View File

@ -4,7 +4,6 @@
"name": "128 MB Server",
"ram": 128,
"disk": 10,
"vcpus": 1,
"links": []
"vcpus": 1
}
}