diff --git a/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeType.java b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeType.java index 596b984ea6..6990381bd2 100644 --- a/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeType.java +++ b/apis/openstack-cinder/src/main/java/org/jclouds/openstack/cinder/v1/domain/VolumeType.java @@ -16,20 +16,18 @@ */ package org.jclouds.openstack.cinder.v1.domain; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.beans.ConstructorProperties; -import java.util.Date; -import java.util.Map; - -import javax.inject.Named; - -import org.jclouds.javax.annotation.Nullable; - import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; +import org.jclouds.javax.annotation.Nullable; + +import javax.inject.Named; +import java.beans.ConstructorProperties; +import java.util.Date; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; /** * An Openstack Cinder Volume Type. @@ -89,7 +87,10 @@ public class VolumeType { * @see VolumeType#getExtraSpecs() */ public T extraSpecs(Map extraSpecs) { - this.extraSpecs = ImmutableMap.copyOf(checkNotNull(extraSpecs, "extraSpecs")); + if (extraSpecs != null) + { + this.extraSpecs = ImmutableMap.copyOf(extraSpecs); + } return self(); } @@ -126,12 +127,15 @@ public class VolumeType { @ConstructorProperties({ "id", "name", "created_at", "updated_at", "extra_specs" }) - protected VolumeType(String id, String name, @Nullable Date created, @Nullable Date updated, Map extraSpecs) { + protected VolumeType(String id, String name, @Nullable Date created, @Nullable Date updated, @Nullable Map extraSpecs) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name"); this.created = Optional.fromNullable(created); this.updated = Optional.fromNullable(updated); - this.extraSpecs = ImmutableMap.copyOf(checkNotNull(extraSpecs, "extraSpecs")); + if (extraSpecs == null) + this.extraSpecs = ImmutableMap.of(); + else + this.extraSpecs = ImmutableMap.copyOf(extraSpecs); } public String getId() { diff --git a/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/VolumeTypeApiExpectTest.java b/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/VolumeTypeApiExpectTest.java index 2166ef3bc8..28b1e59a62 100644 --- a/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/VolumeTypeApiExpectTest.java +++ b/apis/openstack-cinder/src/test/java/org/jclouds/openstack/cinder/v1/features/VolumeTypeApiExpectTest.java @@ -48,7 +48,7 @@ public class VolumeTypeApiExpectTest extends BaseCinderApiExpectTest { ).getVolumeTypeApi("RegionOne"); Set types = api.list().toSet(); - assertEquals(types, ImmutableSet.of(testVolumeType())); + assertEquals(types, testVolumeTypes()); } public void testGetVolumeType() { @@ -72,4 +72,19 @@ public class VolumeTypeApiExpectTest extends BaseCinderApiExpectTest { .extraSpecs(ImmutableMap.of("test", "value1", "test1", "wibble")) .build(); } + public Set testVolumeTypes() { + VolumeType firstVolumeType = testVolumeType(); + VolumeType secondVolumeTypeWithEmptyExtraSpecs = VolumeType.builder() + .id("2") + .name("jclouds-test-2") + .created(dateService.iso8601SecondsDateParse("2012-05-10 12:33:06")) + .build(); + VolumeType thirdVolumeTypeWithNullableExtraSpecs = VolumeType.builder() + .id("3") + .name("jclouds-test-3") + .created(dateService.iso8601SecondsDateParse("2012-05-10 12:33:06")) + .extraSpecs(null) + .build(); + return ImmutableSet.of(firstVolumeType, secondVolumeTypeWithEmptyExtraSpecs, thirdVolumeTypeWithNullableExtraSpecs); + } } diff --git a/apis/openstack-cinder/src/test/resources/volume_type_list_simple.json b/apis/openstack-cinder/src/test/resources/volume_type_list_simple.json index 02eb792182..ce7408c769 100644 --- a/apis/openstack-cinder/src/test/resources/volume_type_list_simple.json +++ b/apis/openstack-cinder/src/test/resources/volume_type_list_simple.json @@ -11,6 +11,24 @@ }, "deleted_at": null, "id": 1 + }, + { + "name": "jclouds-test-2", + "deleted": false, + "created_at": "2012-05-10 12:33:06", + "updated_at": null, + "extra_specs": {}, + "deleted_at": null, + "id": 2 + }, + { + "name": "jclouds-test-3", + "deleted": false, + "created_at": "2012-05-10 12:33:06", + "updated_at": null, + "extra_specs": null, + "deleted_at": null, + "id": 3 } ] }