Update Nova extension tests to use covariant returns

This commit is contained in:
Andrew Donald Kennedy 2012-08-23 08:04:37 +03:00
parent 7d70b5ddc3
commit fec936ca36
14 changed files with 31 additions and 29 deletions

View File

@ -25,6 +25,8 @@ import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import java.util.Set;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
@ -47,7 +49,7 @@ public class LoadFloatingIpsForInstanceTest {
FloatingIP testIp = FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build();
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn(ImmutableSet.<FloatingIP>of(testIp)).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn((Set) ImmutableSet.<FloatingIP>of(testIp)).atLeastOnce();
replay(api);
replay(ipApi);
@ -67,7 +69,7 @@ public class LoadFloatingIpsForInstanceTest {
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn(ImmutableSet.<FloatingIP>of()).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn((Set) ImmutableSet.<FloatingIP>of()).atLeastOnce();
replay(api);
replay(ipApi);
@ -89,7 +91,7 @@ public class LoadFloatingIpsForInstanceTest {
expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
expect(ipApi.listFloatingIPs()).andReturn(
ImmutableSet.<FloatingIP>of(FloatingIP.builder().id("1").ip("1.1.1.1").build()))
(Set) ImmutableSet.<FloatingIP>of(FloatingIP.builder().id("1").ip("1.1.1.1").build()))
.atLeastOnce();
replay(api);

View File

@ -52,7 +52,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
if (!apiOption.isPresent())
continue;
FloatingIPApi api = apiOption.get();
Set<FloatingIP> response = api.listFloatingIPs();
Set<? extends FloatingIP> response = api.listFloatingIPs();
assert null != response;
assertTrue(response.size() >= 0);
for (FloatingIP ip : response) {
@ -77,7 +77,7 @@ public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
FloatingIP floatingIP = api.allocate();
assertNotNull(floatingIP);
Set<FloatingIP> response = api.listFloatingIPs();
Set<? extends FloatingIP> response = api.listFloatingIPs();
boolean ipInSet = false;
for (FloatingIP ip : response) {
if (ip.getId().equals(floatingIP.getId()))

View File

@ -59,7 +59,7 @@ public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
Host expected = Host.builder().name("ubuntu").service("compute").build();
Set<Host> result = api.listHosts();
Set<? extends Host> result = api.listHosts();
Host host = Iterables.getOnlyElement(result);
assertEquals(host.getName(), "ubuntu");
assertEquals(host.getService(), "compute");

View File

@ -65,7 +65,7 @@ public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest {
public void testListAndGet() throws Exception {
if (optApi.isPresent()) {
HostAdministrationApi api = optApi.get();
Set<Host> hosts = api.listHosts();
Set<? extends Host> hosts = api.listHosts();
assertNotNull(hosts);
for (Host host : hosts) {
for (HostResourceUsage usage : api.getHostResourceUsage(host.getName())) {

View File

@ -78,7 +78,7 @@ public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest {
public void testListAndGetAggregate() {
if (apiOption.isPresent()) {
HostAggregateApi api = apiOption.get();
Set<HostAggregate> aggregates = api.listAggregates();
Set<? extends HostAggregate> aggregates = api.listAggregates();
for (HostAggregate aggregate : aggregates) {
assertNotNull(aggregate.getId());
assertNotNull(aggregate.getName());

View File

@ -38,7 +38,7 @@ public class KeyPairApiLiveTest extends BaseNovaApiLiveTest {
public void testListKeyPairs() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) {
KeyPairApi api = novaContext.getApi().getKeyPairExtensionForZone(zoneId).get();
Set<Map<String, KeyPair>> keyPairsList = api.listKeyPairs();
Set<? extends Map<String, ? extends KeyPair>> keyPairsList = api.listKeyPairs();
assertNotNull(keyPairsList);
}
}

View File

@ -44,7 +44,7 @@ public class SecurityGroupApiLiveTest extends BaseNovaApiLiveTest {
public void listSecurityGroups() throws Exception {
for (String zoneId : novaContext.getApi().getConfiguredZones()) {
SecurityGroupApi api = novaContext.getApi().getSecurityGroupExtensionForZone(zoneId).get();
Set<SecurityGroup> securityGroupsList = api.listSecurityGroups();
Set<? extends SecurityGroup> securityGroupsList = api.listSecurityGroups();
assertNotNull(securityGroupsList);
}
}

View File

@ -58,7 +58,7 @@ public class SimpleTenantUsageApiExpectTest extends BaseNovaApiExpectTest {
.payload(payloadFromResource("/simple_tenant_usages.json")).build())
.getSimpleTenantUsageExtensionForZone("az-1.region-a.geo-1").get();
Set<SimpleTenantUsage> results = api.listTenantUsages();
Set<? extends SimpleTenantUsage> results = api.listTenantUsages();
SimpleTenantUsage usage = Iterables.getOnlyElement(results);
assertEquals(usage.getTenantId(), "f8535069c3fb404cb61c873b1a0b4921");

View File

@ -41,7 +41,7 @@ public class SimpleTenantUsageApiLiveTest extends BaseNovaApiLiveTest {
Optional<? extends SimpleTenantUsageApi> optApi = novaContext.getApi().getSimpleTenantUsageExtensionForZone(zoneId);
if (optApi.isPresent() && identity.endsWith(":admin")) {
SimpleTenantUsageApi api = optApi.get();
Set<SimpleTenantUsage> usages = api.listTenantUsages();
Set<? extends SimpleTenantUsage> usages = api.listTenantUsages();
assertNotNull(usages);
for (SimpleTenantUsage usage : usages) {
SimpleTenantUsage details = api.getTenantUsage(usage.getTenantId());

View File

@ -55,7 +55,7 @@ public class VirtualInterfaceApiLiveTest extends BaseNovaApiLiveTest {
Server testServer = null;
try {
testServer = createServerInZone(zone);
Set<VirtualInterface> results = apiOption.get().listVirtualInterfacesForServer(testServer.getId());
Set<? extends VirtualInterface> results = apiOption.get().listVirtualInterfacesForServer(testServer.getId());
for (VirtualInterface vif : results) {
assertNotNull(vif.getId());
assertNotNull(vif.getMacAddress());

View File

@ -62,7 +62,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<Volume> volumes = api.listVolumes();
Set<? extends Volume> volumes = api.listVolumes();
assertEquals(volumes, ImmutableSet.of(testVolume()));
}
@ -75,7 +75,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(404).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<Volume> volumes = api.listVolumes();
Set<? extends Volume> volumes = api.listVolumes();
assertTrue(volumes.isEmpty());
}
@ -88,7 +88,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_list_detail.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<Volume> volumes = api.listVolumesInDetail();
Set<? extends Volume> volumes = api.listVolumesInDetail();
assertEquals(volumes, ImmutableSet.of(testVolume()));
}
@ -101,7 +101,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(404).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<Volume> volumes = api.listVolumesInDetail();
Set<? extends Volume> volumes = api.listVolumesInDetail();
assertTrue(volumes.isEmpty());
}
@ -203,7 +203,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/attachment_list.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<VolumeAttachment> attachments = api.listAttachmentsOnServer("instance-1");
Set<? extends VolumeAttachment> attachments = api.listAttachmentsOnServer("instance-1");
assertEquals(attachments, ImmutableSet.of(testAttachment()));
// double-check individual fields
VolumeAttachment attachment = Iterables.getOnlyElement(attachments);
@ -312,7 +312,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<VolumeSnapshot> snapshots = api.listSnapshots();
Set<? extends VolumeSnapshot> snapshots = api.listSnapshots();
assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
}
@ -325,7 +325,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(404).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<VolumeSnapshot> snapshots = api.listSnapshots();
Set<? extends VolumeSnapshot> snapshots = api.listSnapshots();
assertTrue(snapshots.isEmpty());
}
@ -363,7 +363,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/snapshot_list_detail.json")).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<VolumeSnapshot> snapshots = api.listSnapshotsInDetail();
Set<? extends VolumeSnapshot> snapshots = api.listSnapshotsInDetail();
assertEquals(snapshots, ImmutableSet.of(testSnapshot()));
// double-check individual fields
@ -385,7 +385,7 @@ public class VolumeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(404).build()
).getVolumeExtensionForZone("az-1.region-a.geo-1").get();
Set<VolumeSnapshot> snapshots = api.listSnapshotsInDetail();
Set<? extends VolumeSnapshot> snapshots = api.listSnapshotsInDetail();
assertTrue(snapshots.isEmpty());
}

View File

@ -108,7 +108,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest {
@Test(dependsOnMethods = "testCreateVolume")
public void testListVolumes() {
if (volumeOption.isPresent()) {
Set<Volume> volumes = volumeOption.get().listVolumes();
Set<? extends Volume> volumes = volumeOption.get().listVolumes();
assertNotNull(volumes);
boolean foundIt = false;
for (Volume vol : volumes) {
@ -125,7 +125,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest {
@Test(dependsOnMethods = "testCreateVolume")
public void testListVolumesInDetail() {
if (volumeOption.isPresent()) {
Set<Volume> volumes = volumeOption.get().listVolumesInDetail();
Set<? extends Volume> volumes = volumeOption.get().listVolumesInDetail();
assertNotNull(volumes);
boolean foundIt = false;
for (Volume vol : volumes) {
@ -174,7 +174,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest {
@Test(dependsOnMethods = "testCreateSnapshot")
public void testListSnapshots() {
if (volumeOption.isPresent()) {
Set<VolumeSnapshot> snapshots = volumeOption.get().listSnapshots();
Set<? extends VolumeSnapshot> snapshots = volumeOption.get().listSnapshots();
assertNotNull(snapshots);
boolean foundIt = false;
for (VolumeSnapshot snap : snapshots) {
@ -193,7 +193,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest {
@Test(dependsOnMethods = "testCreateSnapshot")
public void testListSnapshotsInDetail() {
if (volumeOption.isPresent()) {
Set<VolumeSnapshot> snapshots = volumeOption.get().listSnapshotsInDetail();
Set<? extends VolumeSnapshot> snapshots = volumeOption.get().listSnapshotsInDetail();
assertNotNull(snapshots);
boolean foundIt = false;
for (VolumeSnapshot snap : snapshots) {
@ -225,7 +225,7 @@ public class VolumeApiLiveTest extends BaseNovaApiLiveTest {
try {
final String serverId = server_id = createServerInZone(zone).getId();
Set<VolumeAttachment> attachments = volumeOption.get().listAttachmentsOnServer(serverId);
Set<? extends VolumeAttachment> attachments = volumeOption.get().listAttachmentsOnServer(serverId);
assertNotNull(attachments);
final int before = attachments.size();

View File

@ -57,7 +57,7 @@ public class VolumeTypeApiExpectTest extends BaseNovaApiExpectTest {
HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_list.json")).build()
).getVolumeTypeExtensionForZone("az-1.region-a.geo-1").get();
Set<VolumeType> types = api.listVolumeTypes();
Set<? extends VolumeType> types = api.listVolumeTypes();
assertEquals(types, ImmutableSet.of(testVolumeType()));
}

View File

@ -96,7 +96,7 @@ public class VolumeTypeApiLiveTest extends BaseNovaApiLiveTest {
@Test(dependsOnMethods = "testCreateVolumeType")
public void testListVolumeTypes() {
if (volumeTypeOption.isPresent()) {
Set<VolumeType> volumeTypes = volumeTypeOption.get().listVolumeTypes();
Set<? extends VolumeType> volumeTypes = volumeTypeOption.get().listVolumeTypes();
assertNotNull(volumeTypes);
boolean foundIt = false;
for (VolumeType vt : volumeTypes) {