From b4624161ae844e280b3cde5465e3b59f54eb3751 Mon Sep 17 00:00:00 2001 From: Arvind Nadendla Date: Sat, 18 Jun 2016 23:49:38 -0700 Subject: [PATCH] Make links nullable --- .../openstack/v2_0/domain/Resource.java | 9 +++--- .../parse/ParseExtensionListNormalTest.java | 26 +++++++++-------- .../test/resources/extension_list_normal.json | 28 ++++++++++++++++--- .../src/test/resources/flavor_new.json | 3 +- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java index 18248354a1..df5231ad88 100644 --- a/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java +++ b/apis/openstack-keystone/src/main/java/org/jclouds/openstack/v2_0/domain/Resource.java @@ -49,7 +49,7 @@ public class Resource implements Comparable { protected String id; protected String name; - protected Set links = ImmutableSet.of(); + protected Set links; /** * @see Resource#getId() @@ -71,12 +71,12 @@ public class Resource implements Comparable { * @see Resource#getLinks() */ public T links(Set 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 { protected Resource(String id, @Nullable String name, @Nullable Set links) { this.id = checkNotNull(id, "id"); this.name = name; - this.links = links == null ? ImmutableSet.of() : ImmutableSet.copyOf(checkNotNull(links, "links")); + this.links = links == null ? null : ImmutableSet.copyOf(links); } /** @@ -132,6 +132,7 @@ public class Resource implements Comparable { /** * @return the links of the id address allocated to the new server */ + @Nullable public Set getLinks() { return this.links; } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseExtensionListNormalTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseExtensionListNormalTest.java index 8bdef8a504..8a65a29be2 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseExtensionListNormalTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/parse/ParseExtensionListNormalTest.java @@ -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 { @Consumes(MediaType.APPLICATION_JSON) public Set 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() { diff --git a/apis/openstack-nova/src/test/resources/extension_list_normal.json b/apis/openstack-nova/src/test/resources/extension_list_normal.json index 211338d14f..e672575218 100644 --- a/apis/openstack-nova/src/test/resources/extension_list_normal.json +++ b/apis/openstack-nova/src/test/resources/extension_list_normal.json @@ -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" diff --git a/apis/openstack-nova/src/test/resources/flavor_new.json b/apis/openstack-nova/src/test/resources/flavor_new.json index 82089932d5..b3fd7a6b80 100644 --- a/apis/openstack-nova/src/test/resources/flavor_new.json +++ b/apis/openstack-nova/src/test/resources/flavor_new.json @@ -4,7 +4,6 @@ "name": "128 MB Server", "ram": 128, "disk": 10, - "vcpus": 1, - "links": [] + "vcpus": 1 } }