From f45b9ca849fbe85160c162f77b3e3c1b0b8a4c3c Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Thu, 19 Apr 2012 10:37:17 +0100 Subject: [PATCH] Improving Host Administration extension tests --- .../HostAdministrationClientExpectTest.java | 29 ++++++++++++++++--- .../HostAdministrationClientLiveTest.java | 10 +++++-- .../src/test/resources/hosts_list.json | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientExpectTest.java index 2c0c0f8b7c..54d7036994 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientExpectTest.java @@ -18,16 +18,23 @@ */ package org.jclouds.openstack.nova.v1_1.extensions; +import static org.testng.Assert.assertEquals; + import java.net.URI; +import java.util.Set; import javax.ws.rs.core.MediaType; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpResponse; +import org.jclouds.openstack.nova.v1_1.domain.Host; +import org.jclouds.openstack.nova.v1_1.domain.HostResourceUsage; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientExpectTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; /** * Tests HostAdministrationClient guice wiring and parsing @@ -44,9 +51,16 @@ public class HostAdministrationClientExpectTest extends BaseNovaClientExpectTest responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken)) .endpoint(endpoint).build(), - HttpResponse.builder().statusCode(200).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/hosts_list.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - client.listHosts(); + Host expected = Host.builder().name("ubuntu").service("compute").build(); + + Set result = client.listHosts(); + Host host = Iterables.getOnlyElement(result); + assertEquals(host.getName(), "ubuntu"); + assertEquals(host.getService(), "compute"); + + assertEquals(host, expected); } public void testGet() throws Exception { @@ -55,9 +69,16 @@ public class HostAdministrationClientExpectTest extends BaseNovaClientExpectTest responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, HttpRequest.builder().method("GET").headers(ImmutableMultimap.of("Accept", MediaType.APPLICATION_JSON, "X-Auth-Token", authToken)) .endpoint(endpoint).build(), - HttpResponse.builder().statusCode(200).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); + HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get(); - client.getHostResourceUsage("xyz"); + Set expected = ImmutableSet.of( + HostResourceUsage.builder().memoryMb(16083).project("(total)").cpu(4).diskGb(181).host("ubuntu").build(), + HostResourceUsage.builder().memoryMb(3396).project("(used_now)").cpu(3).diskGb(5).host("ubuntu").build(), + HostResourceUsage.builder().memoryMb(6144).project("(used_max)").cpu(3).diskGb(80).host("ubuntu").build(), + HostResourceUsage.builder().memoryMb(6144).project("f8535069c3fb404cb61c873b1a0b4921").cpu(3).diskGb(80).host("ubuntu").build() + ); + + assertEquals(client.getHostResourceUsage("xyz"), expected); } } diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientLiveTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientLiveTest.java index 1092a5b95d..e79dd89891 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientLiveTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/HostAdministrationClientLiveTest.java @@ -18,11 +18,13 @@ */ package org.jclouds.openstack.nova.v1_1.extensions; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import java.util.Set; import org.jclouds.openstack.nova.v1_1.domain.Host; +import org.jclouds.openstack.nova.v1_1.domain.HostResourceUsage; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; import org.testng.annotations.Test; @@ -36,16 +38,18 @@ import com.google.common.base.Optional; @Test(groups = "live", testName = "HostAdministrationClientLiveTest") public class HostAdministrationClientLiveTest extends BaseNovaClientLiveTest { - public void testListAndGet() throws Exception { for (String zoneId : novaContext.getApi().getConfiguredZones()) { Optional optClient = novaContext.getApi().getHostAdministrationExtensionForZone(zoneId); - if (optClient.isPresent()) { + if (optClient.isPresent() && identity.endsWith(":admin")) { HostAdministrationClient client = optClient.get(); Set hosts = client.listHosts(); assertNotNull(hosts); for(Host host : hosts) { - client.getHostResourceUsage(host.getName()); + for (HostResourceUsage usage : client.getHostResourceUsage(host.getName())) { + assertEquals(usage.getHost(), host.getName()); + assertNotNull(usage); + } } } } diff --git a/apis/openstack-nova/src/test/resources/hosts_list.json b/apis/openstack-nova/src/test/resources/hosts_list.json index b8a2cbd2a8..30d377016b 100644 --- a/apis/openstack-nova/src/test/resources/hosts_list.json +++ b/apis/openstack-nova/src/test/resources/hosts_list.json @@ -1 +1 @@ -["hosts": [{"host_name": "ubuntu", "service": "compute"}] \ No newline at end of file +{"hosts": [{"host_name": "ubuntu", "service": "compute"}]} \ No newline at end of file