mirror of https://github.com/apache/jclouds.git
JCLOUDS-1102: Fix. Rackspace returns a new structure for volume types.
This commit is contained in:
parent
59a0014bdf
commit
74a2a2683f
|
@ -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<String, String> 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<String, String> extraSpecs) {
|
||||
protected VolumeType(String id, String name, @Nullable Date created, @Nullable Date updated, @Nullable Map<String, String> 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() {
|
||||
|
|
|
@ -48,7 +48,7 @@ public class VolumeTypeApiExpectTest extends BaseCinderApiExpectTest {
|
|||
).getVolumeTypeApi("RegionOne");
|
||||
|
||||
Set<? extends VolumeType> 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<VolumeType> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue