| /** |
| * Licensed to jclouds, Inc. (jclouds) under one or more |
| * contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. jclouds licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| package org.jclouds.cloudstack.features; |
| |
| import com.google.common.base.Strings; |
| import com.google.common.collect.ImmutableMultimap; |
| import com.google.common.collect.ImmutableSet; |
| import org.jclouds.cloudstack.CloudStackContext; |
| import org.jclouds.cloudstack.domain.Cluster; |
| import org.jclouds.cloudstack.domain.ConfigurationEntry; |
| import org.jclouds.cloudstack.domain.Host; |
| import org.jclouds.cloudstack.options.AddClusterOptions; |
| import org.jclouds.cloudstack.options.AddHostOptions; |
| import org.jclouds.cloudstack.options.AddSecondaryStorageOptions; |
| import org.jclouds.cloudstack.options.DeleteHostOptions; |
| import org.jclouds.cloudstack.options.UpdateClusterOptions; |
| import org.jclouds.cloudstack.options.UpdateHostOptions; |
| import org.jclouds.http.HttpRequest; |
| import org.jclouds.http.HttpResponse; |
| import org.testng.annotations.Test; |
| |
| import java.net.URI; |
| import java.util.Calendar; |
| import java.util.Collections; |
| import java.util.Date; |
| import java.util.Set; |
| import java.util.TimeZone; |
| |
| import static org.testng.Assert.assertEquals; |
| import static org.testng.Assert.assertNull; |
| |
| /** |
| * Test the CloudStack GlobalHostClient |
| * |
| * @author Richard Downer |
| */ |
| @Test(groups = "unit", testName = "GlobalConfigurationClientExpectTest") |
| public class GlobalHostClientExpectTest extends BaseCloudStackRestClientExpectTest<GlobalHostClient> { |
| |
| @Test |
| public void testListHostsWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listHosts&apiKey=identity&signature=wsv4UBgXxURW0pNlso4MT9E052s%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/listhostsresponse.json")) |
| .statusCode(200).build(); |
| |
| Set<Host> actual = requestSendsResponse(request, response).listHosts(); |
| |
| Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); |
| Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC"); |
| Host host1 = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build(); |
| |
| Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); |
| lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "UTC"); |
| created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); |
| Host host2 = Host.builder().id(2).name("nfs://10.26.26.165/mnt/nfs/cs_sec").state(Host.State.ALERT).disconnected(disconnected).type(Host.Type.SECONDARY_STORAGE).ipAddress("nfs").zoneId(1).zoneName("Dev Zone 1").version("2.2.12.20110928142833").hypervisor("None").lastPinged(lastPinged).localStorageActive(false).created(created).events("ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build(); |
| |
| lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); |
| created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 35, 51, "UTC"); |
| Host host3 = Host.builder().id(3).name("s-1-VM").state(Host.State.UP).type(Host.Type.SECONDARY_STORAGE_VM).ipAddress("10.26.26.81").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").lastPinged(lastPinged).managementServerId(223098941760041L).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build(); |
| |
| lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); |
| created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 36, 46, "UTC"); |
| Host host4 = Host.builder().id(4).name("v-2-VM").state(Host.State.UP).type(Host.Type.CONSOLE_PROXY).ipAddress("10.26.26.96").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").lastPinged(lastPinged).managementServerId(223098941760041L).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build(); |
| |
| Set<Host> expected = ImmutableSet.of(host1, host2, host3, host4); |
| |
| assertEquals(actual, expected); |
| } |
| |
| @Test |
| public void testListHostsEmptyOn404() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listHosts&apiKey=identity&signature=wsv4UBgXxURW0pNlso4MT9E052s%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder().statusCode(404).build(); |
| GlobalHostClient client = requestSendsResponse(request, response); |
| |
| assertEquals(client.listHosts(), ImmutableSet.of()); |
| } |
| |
| @Test |
| public void testAddHostWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addHost&zoneid=1&hypervisor=XenServer&url=http%3A%2F%2Fexample.com&username=fred&password=sekrit&hosttags=&allocationstate=Enabled&clusterid=1&clustername=Xen%20Clust%201&podid=1&apiKey=identity&signature=ExGaljKKQIlVbWk5hd0BnnjmBzs%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/addhostresponse.json")) |
| .statusCode(200).build(); |
| |
| Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); |
| Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC"); |
| Host expected = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build(); |
| |
| Host actual = requestSendsResponse(request, response).addHost(1, "http://example.com", "XenServer", "fred", "sekrit", |
| AddHostOptions.Builder.hostTags(Collections.<String>emptySet()).allocationState(Host.AllocationState.ENABLED).clusterId(1).clusterName("Xen Clust 1").podId(1)); |
| |
| assertEquals(actual, expected); |
| } |
| |
| @Test |
| public void testUpdateHostWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateHost&id=1&allocationstate=Enabled&hosttags=&oscategoryid=5&apiKey=identity&signature=qTxNq9yQG8S108giqS%2FROFzgev8%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/updatehostresponse.json")) |
| .statusCode(200).build(); |
| |
| Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "UTC"); |
| Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "UTC"); |
| Host expected = Host.builder().id(1).name("cs2-xevsrv.alucloud.local").state(Host.State.UP).type(Host.Type.ROUTING).ipAddress("10.26.26.107").zoneId(1).zoneName("Dev Zone 1").podId(1).podName("Dev Pod 1").version("2.2.12.20110928142833").hypervisor("XenServer").cpuNumber(24).cpuSpeed(2266).cpuAllocated("2.76%").cpuUsed("0.1%").cpuWithOverProvisioning(54384.0F).networkKbsRead(4443).networkKbsWrite(15048).memoryTotal(100549733760L).memoryAllocated(3623878656L).memoryUsed(3623878656L).capabilities("xen-3.0-x86_64 , xen-3.0-x86_32p , hvm-3.0-x86_32 , hvm-3.0-x86_32p , hvm-3.0-x86_64").lastPinged(lastPinged).managementServerId(223098941760041L).clusterId(1).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hostTags("").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build(); |
| |
| Host actual = requestSendsResponse(request, response).updateHost(1, UpdateHostOptions.Builder.allocationState(Host.AllocationState.ENABLED).hostTags(Collections.<String>emptySet()).osCategoryId(5)); |
| |
| assertEquals(actual, expected); |
| } |
| |
| @Test |
| public void testUpdateHostPasswordWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateHostPassword&hostid=1&password=sekrit&username=fred&apiKey=identity&signature=g9nMKDWoiU72y0HhaRFekZCgfJc%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .statusCode(200).build(); |
| |
| requestSendsResponse(request, response).updateHostPassword(1, "fred", "sekrit"); |
| } |
| |
| @Test |
| public void testDeleteHostWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=deleteHost&id=1&forced=true&forcedestroylocalstorage=true&apiKey=identity&signature=ZdvO1BWBkdPiDAjsVlKtqDe6N7k%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .statusCode(200).build(); |
| |
| requestSendsResponse(request, response).deleteHost(1, DeleteHostOptions.Builder.forced(true).forceDestroyLocalStorage(true)); |
| } |
| |
| @Test |
| public void testPrepareHostForMaintenanceWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=prepareHostForMaintenance&id=1&apiKey=identity&signature=9tDwdox%2FxAKmZr9kVrR6Ttnxf3U%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/preparehostformaintenanceresponse.json")) |
| .statusCode(200).build(); |
| |
| Long actual = requestSendsResponse(request, response).prepareHostForMaintenance(1); |
| assertEquals(actual, Long.valueOf(2036L)); |
| } |
| |
| @Test |
| public void testCancelHostMaintenanceWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=cancelHostMaintenance&id=1&apiKey=identity&signature=9RduzuBoyRZKNTzAoVqUo9gRTfk%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/cancelhostmaintenanceresponse.json")) |
| .statusCode(200).build(); |
| |
| Long actual = requestSendsResponse(request, response).cancelHostMaintenance(1); |
| assertEquals(actual, Long.valueOf(2036L)); |
| } |
| |
| @Test |
| public void testReconnectHostWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=reconnectHost&id=1&apiKey=identity&signature=wJEF02vwdyOnJOTa%2BWMMK906aRU%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/reconnecthostresponse.json")) |
| .statusCode(200).build(); |
| |
| Long actual = requestSendsResponse(request, response).reconnectHost(1); |
| assertEquals(actual, Long.valueOf(2036L)); |
| } |
| |
| @Test |
| public void testAddSecondaryStorageWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addSecondaryStorage&url=nfs%3A%2F%2F10.26.26.165%2Fmnt%2Fnfs%2Fcs_sec&zoneid=1&apiKey=identity&signature=MccRKx1yPP43ImiO70WlhVDlAIA%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/addsecondarystorageresponse.json")) |
| .statusCode(200).build(); |
| |
| Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); |
| Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "UTC"); |
| Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "UTC"); |
| Host expected = Host.builder().id(2).name("nfs://10.26.26.165/mnt/nfs/cs_sec").state(Host.State.ALERT).disconnected(disconnected).type(Host.Type.SECONDARY_STORAGE).ipAddress("nfs").zoneId(1).zoneName("Dev Zone 1").version("2.2.12.20110928142833").hypervisor("None").lastPinged(lastPinged).localStorageActive(false).created(created).events("ManagementServerDown; AgentDisconnected; Remove; MaintenanceRequested; AgentConnected; Ping").hasEnoughCapacity(false).allocationState(Host.AllocationState.ENABLED).build(); |
| |
| Host actual = requestSendsResponse(request, response).addSecondaryStorage("nfs://10.26.26.165/mnt/nfs/cs_sec", AddSecondaryStorageOptions.Builder.zoneId(1)); |
| |
| assertEquals(actual, expected); |
| } |
| |
| @Test |
| public void testListClustersWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listClusters&apiKey=identity&signature=MWOOe7bm1J14DIfLjAGqsSVb8oo%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/listclustersresponse.json")) |
| .statusCode(200).build(); |
| |
| Set<Cluster> actual = requestSendsResponse(request, response).listClusters(); |
| |
| Cluster cluster1 = Cluster.builder().id(1).name("Xen Clust 1").podId(1).podName("Dev Pod 1").zoneId(1).zoneName("Dev Zone 1").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build(); |
| Cluster cluster2 = Cluster.builder().id(2).name("Xen Clust 1").podId(2).podName("Dev Pod 2").zoneId(2).zoneName("Dev Zone 2").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build(); |
| ImmutableSet<Cluster> expected = ImmutableSet.of(cluster1, cluster2); |
| |
| assertEquals(actual, expected); |
| } |
| |
| @Test |
| public void testListClustersEmptyOn404() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=listClusters&apiKey=identity&signature=MWOOe7bm1J14DIfLjAGqsSVb8oo%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder().statusCode(404).build(); |
| GlobalHostClient client = requestSendsResponse(request, response); |
| |
| assertEquals(client.listClusters(), ImmutableSet.of()); |
| } |
| |
| @Test |
| public void testAddClusterWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=addCluster&zoneid=1&clustertype=CloudManaged&clustername=Xen%20Clust%201&hypervisor=XenServer&allocationstate=Enabled&podid=1&url=http%3A%2F%2Fexample.com%2Fcluster&username=fred&password=sekrit&apiKey=identity&signature=2uIQ5qF0bVycXK111wxvogWp1Yw%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/addclusterresponse.json")) |
| .statusCode(200).build(); |
| |
| Cluster expected = Cluster.builder().id(1).name("Xen Clust 1").podId(1).podName("Dev Pod 1").zoneId(1).zoneName("Dev Zone 1").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build(); |
| |
| Cluster actual = requestSendsResponse(request, response).addCluster(1, "Xen Clust 1", Host.ClusterType.CLOUD_MANAGED, "XenServer", AddClusterOptions.Builder.allocationState(Host.AllocationState.ENABLED).podId(1).url("http://example.com/cluster").username("fred").password("sekrit")); |
| |
| assertEquals(actual, expected); |
| } |
| |
| @Test |
| public void testUpdateClusterWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateCluster&id=1&allocationstate=Enabled&clustername=Xen%20Clust%201&clustertype=CloudManaged&hypervisor=XenServer&managedstate=Managed&apiKey=identity&signature=%2FwbuYKwInciSXWkUf05lEfJZShQ%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .payload(payloadFromResource("/updateclusterresponse.json")) |
| .statusCode(200).build(); |
| |
| Cluster expected = Cluster.builder().id(1).name("Xen Clust 1").podId(1).podName("Dev Pod 1").zoneId(1).zoneName("Dev Zone 1").hypervisor("XenServer").clusterType(Host.ClusterType.CLOUD_MANAGED).allocationState(Host.AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build(); |
| |
| Cluster actual = requestSendsResponse(request, response).updateCluster(1, UpdateClusterOptions.Builder.allocationState(Host.AllocationState.ENABLED).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).hypervisor("XenServer").managedState(Cluster.ManagedState.MANAGED)); |
| |
| assertEquals(actual, expected); |
| } |
| |
| @Test |
| public void testUpdateClusterPasswordWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=updateHostPassword&clusterid=1&password=sekrit&username=fred&apiKey=identity&signature=xwc83%2BoYK0cuAiFQAlg%2F7%2F1IVHE%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .statusCode(200).build(); |
| |
| requestSendsResponse(request, response).updateClusterPassword(1, "fred", "sekrit"); |
| } |
| |
| @Test |
| public void testDeleteClusterWhenResponseIs2xx() { |
| HttpRequest request = HttpRequest.builder() |
| .method("GET") |
| .endpoint(URI.create("http://localhost:8080/client/api?response=json&command=deleteCluster&id=1&apiKey=identity&signature=CKH26MFgKGY7Sosd17LjBMNa3AI%3D")) |
| .headers(ImmutableMultimap.<String, String>builder().put("Accept", "application/json").build()) |
| .build(); |
| HttpResponse response = HttpResponse.builder() |
| .statusCode(200).build(); |
| |
| requestSendsResponse(request, response).deleteCluster(1); |
| } |
| |
| private Date makeDate(int year, int month, int date, int hour, int minute, int second, String timeZoneName) { |
| Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(timeZoneName)); |
| cal.set(Calendar.YEAR, year); |
| cal.set(Calendar.MONTH, month); |
| cal.set(Calendar.DATE, date); |
| cal.set(Calendar.HOUR_OF_DAY, hour); |
| cal.set(Calendar.MINUTE, minute); |
| cal.set(Calendar.SECOND, second); |
| cal.set(Calendar.MILLISECOND, 0); |
| return cal.getTime(); |
| } |
| |
| @Override |
| protected GlobalHostClient clientFrom(CloudStackContext context) { |
| return context.getGlobalContext().getApi().getHostClient(); |
| } |
| } |