You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ab...@apache.org on 2013/07/01 21:14:59 UTC
[12/24] JCLOUDS-151 - CloudStack refactored to remove async,
*Client renamed to *Api.
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java
deleted file mode 100644
index 00e3b86..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientLiveTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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 static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.cloudstack.options.ListConfigurationEntriesOptions.Builder.name;
-import static org.testng.Assert.assertEquals;
-
-import java.util.Set;
-
-import org.jclouds.cloudstack.domain.ConfigurationEntry;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.testng.annotations.Test;
-import org.testng.collections.Sets;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-
-/**
- * Tests behavior of {@code GlobalConfigurationClient}
- *
- * @author Andrei Savu
- */
-@Test(groups = "live", singleThreaded = true, testName = "GlobalConfigurationClientLiveTest")
-public class GlobalConfigurationClientLiveTest extends BaseCloudStackClientLiveTest {
-
- @Test
- public void testListConfigurationEntries() {
- skipIfNotGlobalAdmin();
-
- Set<ConfigurationEntry> entries = globalAdminClient
- .getConfigurationClient().listConfigurationEntries();
-
- Set<String> categories = Sets.newHashSet();
- for (ConfigurationEntry entry : entries) {
- checkConfigurationEntry(entry);
- categories.add(entry.getCategory());
- }
-
- assert categories.containsAll(ImmutableSet.<Object>of("Network", "Advanced", "Premium",
- "Storage", "Usage", "Snapshots", "Account Defaults", "Console Proxy", "Alert"));
- }
-
- @Test
- public void testUpdateConfigurationEntry() {
- skipIfNotGlobalAdmin();
-
- Set<ConfigurationEntry> entries = globalAdminClient
- .getConfigurationClient().listConfigurationEntries();
-
- long expungeDelay = Long.parseLong(getValueByName(entries, "expunge.delay"));
- assert expungeDelay > 0;
-
- globalAdminClient.getConfigurationClient()
- .updateConfigurationEntry("expunge.delay", "" + (expungeDelay + 1));
-
- long newDelay = Long.parseLong(getOnlyElement(globalAdminClient.getConfigurationClient()
- .listConfigurationEntries(name("expunge.delay"))).getValue());
- assertEquals(newDelay, expungeDelay + 1);
-
- globalAdminClient.getConfigurationClient()
- .updateConfigurationEntry("expunge.delay", "" + expungeDelay);
- }
-
- private void checkConfigurationEntry(ConfigurationEntry entry) {
- assertEquals(entry, getEntryByName(globalAdminClient.getConfigurationClient()
- .listConfigurationEntries(name(entry.getName())), entry.getName()));
- assert entry.getCategory() != null : entry;
- assert entry.getDescription() != null : entry;
- assert entry.getName() != null : entry;
- }
-
- private String getValueByName(Set<ConfigurationEntry> entries, String name) {
- return getEntryByName(entries, name).getValue();
- }
-
- private ConfigurationEntry getEntryByName(Set<ConfigurationEntry> entries, final String name) {
- return Iterables.find(entries, new Predicate<ConfigurationEntry>() {
- @Override
- public boolean apply(ConfigurationEntry entry) {
- return entry != null && Objects.equal(name, entry.getName());
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiExpectTest.java
new file mode 100644
index 0000000..e9d86d1
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiExpectTest.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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 static org.jclouds.cloudstack.options.UpdateDomainOptions.Builder.name;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.net.URI;
+
+import org.jclouds.cloudstack.CloudStackContext;
+import org.jclouds.cloudstack.domain.Domain;
+import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.testng.annotations.Test;
+
+/**
+ * Test the CloudStack GlobalDomainApi
+ *
+ * @author Andrei Savu
+ */
+@Test(groups = "unit", testName = "GlobalDomainApiExpectTest")
+public class GlobalDomainApiExpectTest extends BaseCloudStackExpectTest<GlobalDomainApi> {
+
+ public void testCreateDomainWhenResponseIs2xx() {
+ GlobalDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&command=createDomain&" +
+ "name=test&apiKey=identity&signature=6cxzEo7h63G0hgTTMLm4lGsSDK8%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/createdomainresponse.json"))
+ .build());
+
+ assertEquals(client.createDomain("test"),
+ Domain.builder().id("10").name("test").level(1).parentDomainId("1")
+ .parentDomainName("ROOT").hasChild(false).build());
+ }
+
+ public void testCreateDomainWhenResponseIs404() {
+ GlobalDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&command=createDomain&" +
+ "name=test&apiKey=identity&signature=6cxzEo7h63G0hgTTMLm4lGsSDK8%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(404)
+ .build());
+
+ assertNull(client.createDomain("test"));
+ }
+
+ public void testUpdateDomainWhenResponseIs2xx() {
+ GlobalDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf/aB6qt%2BqIj%2BmcwFIo%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/updatedomainresponse.json"))
+ .build());
+
+ assertEquals(client.updateDomain("10", name("test-2")),
+ Domain.builder().id("10").name("test-2").level(1).parentDomainId("1")
+ .parentDomainName("ROOT").hasChild(false).build());
+ }
+
+ public void testUpdateDomainWhenResponseIs404() {
+ GlobalDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf/aB6qt%2BqIj%2BmcwFIo%3D"))
+ .addHeader("Accept", "application/json")
+ .build(),
+ HttpResponse.builder()
+ .statusCode(404)
+ .build());
+
+ assertNull(client.updateDomain("10", name("test-2")));
+ }
+
+ public void testDeleteOnlyDomain() {
+ GlobalDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=deleteDomain&cleanup=false&id=1&apiKey=identity&signature=/5aLbigg612t9IrZi0JZO7CyiOU%3D"))
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/deletedomainresponse.json"))
+ .build());
+
+ client.deleteOnlyDomain("1");
+ }
+
+ public void testDeleteDomainAndAttachedResources() {
+ GlobalDomainApi client = requestSendsResponse(
+ HttpRequest.builder()
+ .method("GET")
+ .endpoint(
+ URI.create("http://localhost:8080/client/api?response=json&" +
+ "command=deleteDomain&cleanup=true&id=1&apiKey=identity&signature=grL7JStvtYUT89Jr0D8FgwMyJpU%3D"))
+ .build(),
+ HttpResponse.builder()
+ .statusCode(200)
+ .payload(payloadFromResource("/deletedomainresponse.json"))
+ .build());
+
+ client.deleteDomainAndAttachedResources("1");
+ }
+
+ @Override
+ protected GlobalDomainApi clientFrom(CloudStackContext context) {
+ return context.getGlobalApi().getDomainClient();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiLiveTest.java
new file mode 100644
index 0000000..fc613ef
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainApiLiveTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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 static com.google.common.collect.Iterables.find;
+import static org.jclouds.cloudstack.options.UpdateDomainOptions.Builder.name;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import org.jclouds.cloudstack.domain.Domain;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicate;
+
+/**
+ * Tests behavior of {@code GlobalDomainApi}
+ *
+ * @author Andrei Savu
+ */
+@Test(groups = "live", singleThreaded = true, testName = "GlobalDomainApiLiveTest")
+public class GlobalDomainApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ private GlobalDomainApi domainClient;
+ private Domain rootDomain;
+
+ @BeforeMethod
+ public void before() {
+ domainClient = globalAdminClient.getDomainClient();
+ rootDomain = find(domainClient.listDomains(), new Predicate<Domain>() {
+ @Override
+ public boolean apply(Domain domain) {
+ return domain != null && domain.getName().equals("ROOT");
+ }
+ });
+ }
+
+ @Test
+ public void testCreateUpdateDeleteDomain() {
+ skipIfNotDomainAdmin();
+
+ Domain domain = null;
+ try {
+ domain = domainClient.createDomain(prefix + "-domain");
+ checkDomain(domain, rootDomain, prefix + "-domain");
+
+ Domain updated = domainClient.updateDomain(domain.getId(), name(prefix + "-domain-2"));
+ checkDomain(updated, rootDomain, prefix + "-domain-2");
+ assertEquals(updated.getId(), domain.getId());
+
+ } finally {
+ if (domain != null) {
+ domainClient.deleteDomainAndAttachedResources(domain.getId());
+ }
+ }
+ assertNull(domainClient.getDomainById(domain.getId()));
+ }
+
+ private void checkDomain(Domain domain, Domain rootDomain, String expectedName) {
+ assertEquals(domain.getParentDomainId(), rootDomain.getId());
+ assertEquals(domain.getName(), expectedName);
+ assertEquals(domain.getParentDomainName(), rootDomain.getName());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java
deleted file mode 100644
index 89de1a4..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientExpectTest.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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 static org.jclouds.cloudstack.options.UpdateDomainOptions.Builder.name;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-
-import java.net.URI;
-
-import org.jclouds.cloudstack.CloudStackContext;
-import org.jclouds.cloudstack.domain.Domain;
-import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-/**
- * Test the CloudStack GlobalDomainClient
- *
- * @author Andrei Savu
- */
-@Test(groups = "unit", testName = "GlobalDomainClientExpectTest")
-public class GlobalDomainClientExpectTest extends BaseCloudStackExpectTest<GlobalDomainClient> {
-
- public void testCreateDomainWhenResponseIs2xx() {
- GlobalDomainClient client = requestSendsResponse(
- HttpRequest.builder()
- .method("GET")
- .endpoint(
- URI.create("http://localhost:8080/client/api?response=json&command=createDomain&" +
- "name=test&apiKey=identity&signature=6cxzEo7h63G0hgTTMLm4lGsSDK8%3D"))
- .addHeader("Accept", "application/json")
- .build(),
- HttpResponse.builder()
- .statusCode(200)
- .payload(payloadFromResource("/createdomainresponse.json"))
- .build());
-
- assertEquals(client.createDomain("test"),
- Domain.builder().id("10").name("test").level(1).parentDomainId("1")
- .parentDomainName("ROOT").hasChild(false).build());
- }
-
- public void testCreateDomainWhenResponseIs404() {
- GlobalDomainClient client = requestSendsResponse(
- HttpRequest.builder()
- .method("GET")
- .endpoint(
- URI.create("http://localhost:8080/client/api?response=json&command=createDomain&" +
- "name=test&apiKey=identity&signature=6cxzEo7h63G0hgTTMLm4lGsSDK8%3D"))
- .addHeader("Accept", "application/json")
- .build(),
- HttpResponse.builder()
- .statusCode(404)
- .build());
-
- assertNull(client.createDomain("test"));
- }
-
- public void testUpdateDomainWhenResponseIs2xx() {
- GlobalDomainClient client = requestSendsResponse(
- HttpRequest.builder()
- .method("GET")
- .endpoint(
- URI.create("http://localhost:8080/client/api?response=json&" +
- "command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf/aB6qt%2BqIj%2BmcwFIo%3D"))
- .addHeader("Accept", "application/json")
- .build(),
- HttpResponse.builder()
- .statusCode(200)
- .payload(payloadFromResource("/updatedomainresponse.json"))
- .build());
-
- assertEquals(client.updateDomain("10", name("test-2")),
- Domain.builder().id("10").name("test-2").level(1).parentDomainId("1")
- .parentDomainName("ROOT").hasChild(false).build());
- }
-
- public void testUpdateDomainWhenResponseIs404() {
- GlobalDomainClient client = requestSendsResponse(
- HttpRequest.builder()
- .method("GET")
- .endpoint(
- URI.create("http://localhost:8080/client/api?response=json&" +
- "command=updateDomain&id=10&name=test-2&apiKey=identity&signature=5t1eUf2Eyf/aB6qt%2BqIj%2BmcwFIo%3D"))
- .addHeader("Accept", "application/json")
- .build(),
- HttpResponse.builder()
- .statusCode(404)
- .build());
-
- assertNull(client.updateDomain("10", name("test-2")));
- }
-
- public void testDeleteOnlyDomain() {
- GlobalDomainClient client = requestSendsResponse(
- HttpRequest.builder()
- .method("GET")
- .endpoint(
- URI.create("http://localhost:8080/client/api?response=json&" +
- "command=deleteDomain&cleanup=false&id=1&apiKey=identity&signature=/5aLbigg612t9IrZi0JZO7CyiOU%3D"))
- .build(),
- HttpResponse.builder()
- .statusCode(200)
- .payload(payloadFromResource("/deletedomainresponse.json"))
- .build());
-
- client.deleteOnlyDomain("1");
- }
-
- public void testDeleteDomainAndAttachedResources() {
- GlobalDomainClient client = requestSendsResponse(
- HttpRequest.builder()
- .method("GET")
- .endpoint(
- URI.create("http://localhost:8080/client/api?response=json&" +
- "command=deleteDomain&cleanup=true&id=1&apiKey=identity&signature=grL7JStvtYUT89Jr0D8FgwMyJpU%3D"))
- .build(),
- HttpResponse.builder()
- .statusCode(200)
- .payload(payloadFromResource("/deletedomainresponse.json"))
- .build());
-
- client.deleteDomainAndAttachedResources("1");
- }
-
- @Override
- protected GlobalDomainClient clientFrom(CloudStackContext context) {
- return context.getGlobalContext().getApi().getDomainClient();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java
deleted file mode 100644
index 8f75404..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalDomainClientLiveTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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 static com.google.common.collect.Iterables.find;
-import static org.jclouds.cloudstack.options.UpdateDomainOptions.Builder.name;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-
-import org.jclouds.cloudstack.domain.Domain;
-import org.jclouds.cloudstack.internal.BaseCloudStackClientLiveTest;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicate;
-
-/**
- * Tests behavior of {@code GlobalDomainClient}
- *
- * @author Andrei Savu
- */
-@Test(groups = "live", singleThreaded = true, testName = "GlobalDomainClientLiveTest")
-public class GlobalDomainClientLiveTest extends BaseCloudStackClientLiveTest {
-
- private GlobalDomainClient domainClient;
- private Domain rootDomain;
-
- @BeforeMethod
- public void before() {
- domainClient = globalAdminClient.getDomainClient();
- rootDomain = find(domainClient.listDomains(), new Predicate<Domain>() {
- @Override
- public boolean apply(Domain domain) {
- return domain != null && domain.getName().equals("ROOT");
- }
- });
- }
-
- @Test
- public void testCreateUpdateDeleteDomain() {
- skipIfNotDomainAdmin();
-
- Domain domain = null;
- try {
- domain = domainClient.createDomain(prefix + "-domain");
- checkDomain(domain, rootDomain, prefix + "-domain");
-
- Domain updated = domainClient.updateDomain(domain.getId(), name(prefix + "-domain-2"));
- checkDomain(updated, rootDomain, prefix + "-domain-2");
- assertEquals(updated.getId(), domain.getId());
-
- } finally {
- if (domain != null) {
- domainClient.deleteDomainAndAttachedResources(domain.getId());
- }
- }
- assertNull(domainClient.getDomainById(domain.getId()));
- }
-
- private void checkDomain(Domain domain, Domain rootDomain, String expectedName) {
- assertEquals(domain.getParentDomainId(), rootDomain.getId());
- assertEquals(domain.getName(), expectedName);
- assertEquals(domain.getParentDomainName(), rootDomain.getName());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiExpectTest.java
new file mode 100644
index 0000000..1a70232
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiExpectTest.java
@@ -0,0 +1,377 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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 static org.testng.Assert.assertEquals;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Set;
+import java.util.TimeZone;
+
+import org.jclouds.cloudstack.CloudStackContext;
+import org.jclouds.cloudstack.domain.AllocationState;
+import org.jclouds.cloudstack.domain.Cluster;
+import org.jclouds.cloudstack.domain.Host;
+import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
+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 com.google.common.collect.ImmutableSet;
+
+/**
+ * Test the CloudStack GlobalHostApi
+ *
+ * @author Richard Downer
+ */
+@Test(groups = "unit", testName = "GlobalConfigurationApiExpectTest")
+public class GlobalHostApiExpectTest extends BaseCloudStackExpectTest<GlobalHostApi> {
+
+ @Test
+ public void testListHostsWhenResponseIs2xx() {
+ HttpRequest request = HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=listHosts&listAll=true&apiKey=identity&signature=NnYyyEy30G3V2dcIt7w4WZ68AU8%3D")
+ .addHeader("Accept", "application/json").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, "GMT+02:00");
+ Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00");
+ 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("223098941760041").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").hasEnough
Capacity(false).allocationState(AllocationState.ENABLED).build();
+
+ Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
+ lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00");
+ created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
+ 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(AllocationState.ENABLED).build();
+
+ lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
+ created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 35, 51, "GMT+02:00");
+ 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("223098941760041").localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build();
+
+ lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
+ created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 36, 46, "GMT+02:00");
+ 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("223098941760041").localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(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("http://localhost:8080/client/api?response=json&command=listHosts&listAll=true&apiKey=identity&signature=NnYyyEy30G3V2dcIt7w4WZ68AU8%3D")
+ .addHeader("Accept", "application/json").build();
+ HttpResponse response = HttpResponse.builder().statusCode(404).build();
+ GlobalHostApi client = requestSendsResponse(request, response);
+
+ assertEquals(client.listHosts(), ImmutableSet.of());
+ }
+
+ HttpRequest addHost = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "addHost")
+ .addQueryParam("zoneid", "1")
+ .addQueryParam("url", "http%3A//example.com")
+ .addQueryParam("hypervisor", "XenServer")
+ .addQueryParam("username", "fred")
+ .addQueryParam("password", "sekrit")
+ .addQueryParam("hosttags", "")
+ .addQueryParam("allocationstate", "Enabled")
+ .addQueryParam("clusterid", "1")
+ .addQueryParam("clustername", "Xen%20Clust%201")
+ .addQueryParam("podid", "1")
+ .addQueryParam("apiKey", "identity")
+ .addQueryParam("signature", "ExGaljKKQIlVbWk5hd0BnnjmBzs=")
+ .addHeader("Accept", "application/json").build();
+
+ @Test
+ public void testAddHostWhenResponseIs2xx() {
+ HttpResponse response = HttpResponse.builder()
+ .payload(payloadFromResource("/addhostresponse.json"))
+ .statusCode(200).build();
+
+ Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
+ Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00");
+ 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("223098941760041").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").hasEno
ughCapacity(false).allocationState(AllocationState.ENABLED).build();
+
+ Host actual = requestSendsResponse(addHost, response).addHost("1", "http://example.com", "XenServer", "fred", "sekrit",
+ AddHostOptions.Builder.hostTags(ImmutableSet.<String>of()).allocationState(AllocationState.ENABLED).clusterId("1").clusterName("Xen Clust 1").podId("1"));
+
+ assertEquals(actual, expected);
+ }
+
+ @Test
+ public void testUpdateHostWhenResponseIs2xx() {
+ HttpRequest request = HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=updateHost&id=1&allocationstate=Enabled&hosttags=&oscategoryid=5&apiKey=identity&signature=qTxNq9yQG8S108giqS/ROFzgev8%3D")
+ .addHeader("Accept", "application/json").build();
+ HttpResponse response = HttpResponse.builder()
+ .payload(payloadFromResource("/updatehostresponse.json"))
+ .statusCode(200).build();
+
+ Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
+ Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00");
+ 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("223098941760041").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").hasEno
ughCapacity(false).allocationState(AllocationState.ENABLED).build();
+
+ Host actual = requestSendsResponse(request, response).updateHost("1", UpdateHostOptions.Builder.allocationState(AllocationState.ENABLED).hostTags(ImmutableSet.<String>of()).osCategoryId("5"));
+
+ assertEquals(actual, expected);
+ }
+
+ HttpRequest updateHostPassword = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "updateHostPassword")
+ .addQueryParam("hostid", "1")
+ .addQueryParam("username", "fred")
+ .addQueryParam("password", "sekrit")
+ .addQueryParam("apiKey", "identity")
+ .addQueryParam("signature", "g9nMKDWoiU72y0HhaRFekZCgfJc=")
+ .addHeader("Accept", "application/json").build();
+
+ @Test
+ public void testUpdateHostPasswordWhenResponseIs2xx() {
+ HttpResponse response = HttpResponse.builder()
+ .statusCode(200).build();
+ requestSendsResponse(updateHostPassword, response).updateHostPassword("1", "fred", "sekrit");
+ }
+
+ @Test
+ public void testDeleteHostWhenResponseIs2xx() {
+ HttpRequest request = HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=deleteHost&id=1&forced=true&forcedestroylocalstorage=true&apiKey=identity&signature=ZdvO1BWBkdPiDAjsVlKtqDe6N7k%3D")
+ .addHeader("Accept", "application/json")
+ .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("http://localhost:8080/client/api?response=json&command=prepareHostForMaintenance&id=1&apiKey=identity&signature=9tDwdox/xAKmZr9kVrR6Ttnxf3U%3D")
+ .addHeader("Accept", "application/json").build();
+ HttpResponse response = HttpResponse.builder()
+ .payload(payloadFromResource("/preparehostformaintenanceresponse.json"))
+ .statusCode(200).build();
+
+ String actual = requestSendsResponse(request, response).prepareHostForMaintenance("1");
+ assertEquals(actual, "2036");
+ }
+
+ @Test
+ public void testCancelHostMaintenanceWhenResponseIs2xx() {
+ HttpRequest request = HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=cancelHostMaintenance&id=1&apiKey=identity&signature=9RduzuBoyRZKNTzAoVqUo9gRTfk%3D")
+ .addHeader("Accept", "application/json").build();
+ HttpResponse response = HttpResponse.builder()
+ .payload(payloadFromResource("/cancelhostmaintenanceresponse.json"))
+ .statusCode(200).build();
+
+ String actual = requestSendsResponse(request, response).cancelHostMaintenance("1");
+ assertEquals(actual, "2036");
+ }
+
+ @Test
+ public void testReconnectHostWhenResponseIs2xx() {
+ HttpRequest request = HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=reconnectHost&id=1&apiKey=identity&signature=wJEF02vwdyOnJOTa%2BWMMK906aRU%3D")
+ .addHeader("Accept", "application/json").build();
+ HttpResponse response = HttpResponse.builder()
+ .payload(payloadFromResource("/reconnecthostresponse.json"))
+ .statusCode(200).build();
+
+ String actual = requestSendsResponse(request, response).reconnectHost("1");
+ assertEquals(actual, "2036");
+ }
+
+ @Test
+ public void testAddSecondaryStorageWhenResponseIs2xx() {
+ HttpRequest request = HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=addSecondaryStorage&url=nfs%3A//10.26.26.165/mnt/nfs/cs_sec&zoneid=1&apiKey=identity&signature=MccRKx1yPP43ImiO70WlhVDlAIA%3D")
+ .addHeader("Accept", "application/json").build();
+ HttpResponse response = HttpResponse.builder()
+ .payload(payloadFromResource("/addsecondarystorageresponse.json"))
+ .statusCode(200).build();
+
+ Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
+ Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00");
+ Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
+ 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(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("http://localhost:8080/client/api?response=json&command=listClusters&listAll=true&apiKey=identity&signature=lbimqg0OKIq8sgQBpNmi4oQNFog%3D")
+ .addHeader("Accept", "application/json").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(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(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("http://localhost:8080/client/api?response=json&command=listClusters&listAll=true&apiKey=identity&signature=lbimqg0OKIq8sgQBpNmi4oQNFog%3D")
+ .addHeader("Accept", "application/json").build();
+ HttpResponse response = HttpResponse.builder().statusCode(404).build();
+ GlobalHostApi client = requestSendsResponse(request, response);
+
+ assertEquals(client.listClusters(), ImmutableSet.of());
+ }
+
+ HttpRequest addCluster = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "addCluster")
+ .addQueryParam("zoneid", "1")
+ .addQueryParam("clustername", "Xen Clust 1")
+ .addQueryParam("clustertype", "CloudManaged")
+ .addQueryParam("hypervisor", "XenServer")
+ .addQueryParam("allocationstate", "Enabled")
+ .addQueryParam("podid", "1")
+ .addQueryParam("url", "http://example.com/cluster")
+ .addQueryParam("username", "fred")
+ .addQueryParam("password", "sekrit")
+ .addQueryParam("apiKey", "identity")
+ .addQueryParam("signature", "2uIQ5qF0bVycXK111wxvogWp1Yw=")
+ .addHeader("Accept", "application/json").build();
+
+ @Test
+ public void testAddClusterWhenResponseIs2xx() {
+ 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(AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
+
+ Cluster actual = requestSendsResponse(addCluster, response).addCluster("1", "Xen Clust 1", Host.ClusterType.CLOUD_MANAGED, "XenServer", AddClusterOptions.Builder.allocationState(AllocationState.ENABLED).podId("1").url("http://example.com/cluster").username("fred").password("sekrit"));
+
+ assertEquals(actual, expected);
+ }
+
+ HttpRequest updateCluster = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "updateCluster")
+ .addQueryParam("id", "1")
+ .addQueryParam("allocationstate", "Enabled")
+ .addQueryParam("clustername", "Xen Clust 1")
+ .addQueryParam("clustertype", "CloudManaged")
+ .addQueryParam("hypervisor", "XenServer")
+ .addQueryParam("managedstate", "Managed")
+ .addQueryParam("apiKey", "identity")
+ .addQueryParam("signature", "/wbuYKwInciSXWkUf05lEfJZShQ=")
+ .addHeader("Accept", "application/json").build();
+
+ @Test
+ public void testUpdateClusterWhenResponseIs2xx() {
+ 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(AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
+
+ Cluster actual = requestSendsResponse(updateCluster, response).updateCluster("1", UpdateClusterOptions.Builder.allocationState(AllocationState.ENABLED).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).hypervisor("XenServer").managedState(Cluster.ManagedState.MANAGED));
+
+ assertEquals(actual, expected);
+ }
+
+ HttpRequest updateClusterPassword = HttpRequest.builder().method("GET")
+ .endpoint("http://localhost:8080/client/api")
+ .addQueryParam("response", "json")
+ .addQueryParam("command", "updateHostPassword")
+ .addQueryParam("clusterid", "1")
+ .addQueryParam("username", "fred")
+ .addQueryParam("password", "sekrit")
+ .addQueryParam("apiKey", "identity")
+ .addQueryParam("signature", "xwc83%2BoYK0cuAiFQAlg/7/1IVHE=")
+ .addHeader("Accept", "application/json").build();
+
+ @Test
+ public void testUpdateClusterPasswordWhenResponseIs2xx() {
+ HttpResponse response = HttpResponse.builder()
+ .statusCode(200).build();
+ requestSendsResponse(updateClusterPassword, response).updateClusterPassword("1", "fred", "sekrit");
+ }
+
+ @Test
+ public void testDeleteClusterWhenResponseIs2xx() {
+ HttpRequest request = HttpRequest.builder()
+ .method("GET")
+ .endpoint("http://localhost:8080/client/api?response=json&command=deleteCluster&id=1&apiKey=identity&signature=CKH26MFgKGY7Sosd17LjBMNa3AI%3D")
+ .addHeader("Accept", "application/json").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 GlobalHostApi clientFrom(CloudStackContext context) {
+ return context.getGlobalApi().getHostClient();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiLiveTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiLiveTest.java
new file mode 100644
index 0000000..50fcdc8
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiLiveTest.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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 static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Set;
+
+import org.jclouds.cloudstack.domain.AllocationState;
+import org.jclouds.cloudstack.domain.Cluster;
+import org.jclouds.cloudstack.domain.Host;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiLiveTest;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Strings;
+
+/**
+ * Tests behavior of {@code GlobalHostApi}
+ *
+ * @author Andrei Savu
+ */
+@Test(groups = "live", singleThreaded = true, testName = "GlobalHostApiLiveTest")
+public class GlobalHostApiLiveTest extends BaseCloudStackApiLiveTest {
+
+ @Test(groups = "live", enabled = true)
+ public void testListHosts() throws Exception {
+ skipIfNotGlobalAdmin();
+
+ Set<Host> hosts = globalAdminClient.getHostClient().listHosts();
+ assert hosts.size() > 0 : hosts;
+
+ for(Host host : hosts) {
+ checkHost(host);
+ }
+ }
+
+ private void checkHost(Host host) {
+ if (host.getType() == Host.Type.ROUTING) {
+ assert host.getCpuNumber() > 0;
+ assert host.getAverageLoad() >= 0;
+ assert host.getHypervisor() != null;
+ }
+ assert host.getAllocationState() != null;
+ assert host.getEvents() != null;
+ if (host.getType() == Host.Type.SECONDARY_STORAGE_VM) {
+ assert host.getName().startsWith("s-");
+ }
+ if (host.getType() == Host.Type.CONSOLE_PROXY) {
+ assert host.getName().startsWith("v-");
+ }
+ }
+
+ @Test(groups = "live", enabled = true)
+ public void testListClusters() throws Exception {
+ skipIfNotGlobalAdmin();
+
+ Set<Cluster> clusters = globalAdminClient.getHostClient().listClusters();
+ assert clusters.size() > 0 : clusters;
+
+ for(Cluster cluster : clusters) {
+ checkCluster(cluster);
+ }
+ }
+
+ private void checkCluster(Cluster cluster) {
+ assertNotNull(cluster.getId());
+ assertFalse(Strings.isNullOrEmpty(cluster.getName()));
+ assertNotEquals(AllocationState.UNKNOWN, cluster.getAllocationState());
+ assertNotEquals(Host.ClusterType.UNKNOWN, cluster.getClusterType());
+ assertFalse(Strings.isNullOrEmpty(cluster.getHypervisor()));
+ assertNotEquals(Cluster.ManagedState.UNRECOGNIZED, cluster.getManagedState());
+ assertNotNull(cluster.getPodId());
+ assertFalse(Strings.isNullOrEmpty(cluster.getPodName()));
+ assertNotNull(cluster.getZoneId());
+ assertFalse(Strings.isNullOrEmpty(cluster.getZoneName()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiTest.java
new file mode 100644
index 0000000..e9bb947
--- /dev/null
+++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostApiTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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 static org.jclouds.reflect.Reflection2.method;
+
+import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
+import org.jclouds.cloudstack.internal.BaseCloudStackApiTest;
+import org.jclouds.cloudstack.options.ListHostsOptions;
+import org.jclouds.http.functions.ParseFirstJsonValueNamed;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.reflect.Invokable;
+/**
+ * Tests behavior of {@code GlobalHostApi}
+ *
+ * @author Andrei Savu
+ */
+@Test(groups = "unit", testName = "GlobalHostApiTest")
+public class GlobalHostApiTest extends BaseCloudStackApiTest<GlobalHostApi> {
+
+ public void testListHosts() throws Exception {
+ Invokable<?, ?> method = method(GlobalHostApi.class, "listHosts", ListHostsOptions[].class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(httpRequest,
+ "GET http://localhost:8080/client/api?response=json&command=listHosts&listAll=true HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java
deleted file mode 100644
index 565dbd9..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostAsyncClientTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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 static org.jclouds.reflect.Reflection2.method;
-
-import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
-import org.jclouds.cloudstack.internal.BaseCloudStackAsyncClientTest;
-import org.jclouds.cloudstack.options.ListHostsOptions;
-import org.jclouds.http.functions.ParseFirstJsonValueNamed;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-/**
- * Tests behavior of {@code GlobalHostAsyncClient}
- *
- * @author Andrei Savu
- */
-@Test(groups = "unit", testName = "GlobalHostAsyncClientTest")
-public class GlobalHostAsyncClientTest extends BaseCloudStackAsyncClientTest<GlobalHostAsyncClient> {
-
- public void testListHosts() throws Exception {
- Invokable<?, ?> method = method(GlobalHostAsyncClient.class, "listHosts", ListHostsOptions[].class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET http://localhost:8080/client/api?response=json&command=listHosts&listAll=true HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/c6986efd/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java
----------------------------------------------------------------------
diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java
deleted file mode 100644
index c85967c..0000000
--- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalHostClientExpectTest.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF 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 static org.testng.Assert.assertEquals;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Set;
-import java.util.TimeZone;
-
-import org.jclouds.cloudstack.CloudStackContext;
-import org.jclouds.cloudstack.domain.AllocationState;
-import org.jclouds.cloudstack.domain.Cluster;
-import org.jclouds.cloudstack.domain.Host;
-import org.jclouds.cloudstack.internal.BaseCloudStackExpectTest;
-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 com.google.common.collect.ImmutableSet;
-
-/**
- * Test the CloudStack GlobalHostClient
- *
- * @author Richard Downer
- */
-@Test(groups = "unit", testName = "GlobalConfigurationClientExpectTest")
-public class GlobalHostClientExpectTest extends BaseCloudStackExpectTest<GlobalHostClient> {
-
- @Test
- public void testListHostsWhenResponseIs2xx() {
- HttpRequest request = HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=listHosts&listAll=true&apiKey=identity&signature=NnYyyEy30G3V2dcIt7w4WZ68AU8%3D")
- .addHeader("Accept", "application/json").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, "GMT+02:00");
- Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00");
- 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("223098941760041").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").hasEnough
Capacity(false).allocationState(AllocationState.ENABLED).build();
-
- Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
- lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00");
- created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
- 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(AllocationState.ENABLED).build();
-
- lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
- created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 35, 51, "GMT+02:00");
- 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("223098941760041").localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(AllocationState.ENABLED).build();
-
- lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
- created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 36, 46, "GMT+02:00");
- 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("223098941760041").localStorageActive(false).created(created).events("PrepareUnmanaged; HypervisorVersionChanged; ManagementServerDown; PingTimeout; AgentDisconnected; MaintenanceRequested; HostDown; AgentConnected; StartAgentRebalance; ShutdownRequested; Ping").hasEnoughCapacity(false).allocationState(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("http://localhost:8080/client/api?response=json&command=listHosts&listAll=true&apiKey=identity&signature=NnYyyEy30G3V2dcIt7w4WZ68AU8%3D")
- .addHeader("Accept", "application/json").build();
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
- GlobalHostClient client = requestSendsResponse(request, response);
-
- assertEquals(client.listHosts(), ImmutableSet.of());
- }
-
- HttpRequest addHost = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "addHost")
- .addQueryParam("zoneid", "1")
- .addQueryParam("url", "http%3A//example.com")
- .addQueryParam("hypervisor", "XenServer")
- .addQueryParam("username", "fred")
- .addQueryParam("password", "sekrit")
- .addQueryParam("hosttags", "")
- .addQueryParam("allocationstate", "Enabled")
- .addQueryParam("clusterid", "1")
- .addQueryParam("clustername", "Xen%20Clust%201")
- .addQueryParam("podid", "1")
- .addQueryParam("apiKey", "identity")
- .addQueryParam("signature", "ExGaljKKQIlVbWk5hd0BnnjmBzs=")
- .addHeader("Accept", "application/json").build();
-
- @Test
- public void testAddHostWhenResponseIs2xx() {
- HttpResponse response = HttpResponse.builder()
- .payload(payloadFromResource("/addhostresponse.json"))
- .statusCode(200).build();
-
- Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
- Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00");
- 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("223098941760041").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").hasEno
ughCapacity(false).allocationState(AllocationState.ENABLED).build();
-
- Host actual = requestSendsResponse(addHost, response).addHost("1", "http://example.com", "XenServer", "fred", "sekrit",
- AddHostOptions.Builder.hostTags(ImmutableSet.<String>of()).allocationState(AllocationState.ENABLED).clusterId("1").clusterName("Xen Clust 1").podId("1"));
-
- assertEquals(actual, expected);
- }
-
- @Test
- public void testUpdateHostWhenResponseIs2xx() {
- HttpRequest request = HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=updateHost&id=1&allocationstate=Enabled&hosttags=&oscategoryid=5&apiKey=identity&signature=qTxNq9yQG8S108giqS/ROFzgev8%3D")
- .addHeader("Accept", "application/json").build();
- HttpResponse response = HttpResponse.builder()
- .payload(payloadFromResource("/updatehostresponse.json"))
- .statusCode(200).build();
-
- Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 54, 43, "GMT+02:00");
- Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 28, 36, "GMT+02:00");
- 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("223098941760041").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").hasEno
ughCapacity(false).allocationState(AllocationState.ENABLED).build();
-
- Host actual = requestSendsResponse(request, response).updateHost("1", UpdateHostOptions.Builder.allocationState(AllocationState.ENABLED).hostTags(ImmutableSet.<String>of()).osCategoryId("5"));
-
- assertEquals(actual, expected);
- }
-
- HttpRequest updateHostPassword = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "updateHostPassword")
- .addQueryParam("hostid", "1")
- .addQueryParam("username", "fred")
- .addQueryParam("password", "sekrit")
- .addQueryParam("apiKey", "identity")
- .addQueryParam("signature", "g9nMKDWoiU72y0HhaRFekZCgfJc=")
- .addHeader("Accept", "application/json").build();
-
- @Test
- public void testUpdateHostPasswordWhenResponseIs2xx() {
- HttpResponse response = HttpResponse.builder()
- .statusCode(200).build();
- requestSendsResponse(updateHostPassword, response).updateHostPassword("1", "fred", "sekrit");
- }
-
- @Test
- public void testDeleteHostWhenResponseIs2xx() {
- HttpRequest request = HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=deleteHost&id=1&forced=true&forcedestroylocalstorage=true&apiKey=identity&signature=ZdvO1BWBkdPiDAjsVlKtqDe6N7k%3D")
- .addHeader("Accept", "application/json")
- .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("http://localhost:8080/client/api?response=json&command=prepareHostForMaintenance&id=1&apiKey=identity&signature=9tDwdox/xAKmZr9kVrR6Ttnxf3U%3D")
- .addHeader("Accept", "application/json").build();
- HttpResponse response = HttpResponse.builder()
- .payload(payloadFromResource("/preparehostformaintenanceresponse.json"))
- .statusCode(200).build();
-
- String actual = requestSendsResponse(request, response).prepareHostForMaintenance("1");
- assertEquals(actual, "2036");
- }
-
- @Test
- public void testCancelHostMaintenanceWhenResponseIs2xx() {
- HttpRequest request = HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=cancelHostMaintenance&id=1&apiKey=identity&signature=9RduzuBoyRZKNTzAoVqUo9gRTfk%3D")
- .addHeader("Accept", "application/json").build();
- HttpResponse response = HttpResponse.builder()
- .payload(payloadFromResource("/cancelhostmaintenanceresponse.json"))
- .statusCode(200).build();
-
- String actual = requestSendsResponse(request, response).cancelHostMaintenance("1");
- assertEquals(actual, "2036");
- }
-
- @Test
- public void testReconnectHostWhenResponseIs2xx() {
- HttpRequest request = HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=reconnectHost&id=1&apiKey=identity&signature=wJEF02vwdyOnJOTa%2BWMMK906aRU%3D")
- .addHeader("Accept", "application/json").build();
- HttpResponse response = HttpResponse.builder()
- .payload(payloadFromResource("/reconnecthostresponse.json"))
- .statusCode(200).build();
-
- String actual = requestSendsResponse(request, response).reconnectHost("1");
- assertEquals(actual, "2036");
- }
-
- @Test
- public void testAddSecondaryStorageWhenResponseIs2xx() {
- HttpRequest request = HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=addSecondaryStorage&url=nfs%3A//10.26.26.165/mnt/nfs/cs_sec&zoneid=1&apiKey=identity&signature=MccRKx1yPP43ImiO70WlhVDlAIA%3D")
- .addHeader("Accept", "application/json").build();
- HttpResponse response = HttpResponse.builder()
- .payload(payloadFromResource("/addsecondarystorageresponse.json"))
- .statusCode(200).build();
-
- Date disconnected = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
- Date lastPinged = makeDate(1970, Calendar.JANUARY, 16, 0, 42, 30, "GMT+02:00");
- Date created = makeDate(2011, Calendar.NOVEMBER, 26, 23, 33, 38, "GMT+02:00");
- 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(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("http://localhost:8080/client/api?response=json&command=listClusters&listAll=true&apiKey=identity&signature=lbimqg0OKIq8sgQBpNmi4oQNFog%3D")
- .addHeader("Accept", "application/json").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(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(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("http://localhost:8080/client/api?response=json&command=listClusters&listAll=true&apiKey=identity&signature=lbimqg0OKIq8sgQBpNmi4oQNFog%3D")
- .addHeader("Accept", "application/json").build();
- HttpResponse response = HttpResponse.builder().statusCode(404).build();
- GlobalHostClient client = requestSendsResponse(request, response);
-
- assertEquals(client.listClusters(), ImmutableSet.of());
- }
-
- HttpRequest addCluster = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "addCluster")
- .addQueryParam("zoneid", "1")
- .addQueryParam("clustername", "Xen Clust 1")
- .addQueryParam("clustertype", "CloudManaged")
- .addQueryParam("hypervisor", "XenServer")
- .addQueryParam("allocationstate", "Enabled")
- .addQueryParam("podid", "1")
- .addQueryParam("url", "http://example.com/cluster")
- .addQueryParam("username", "fred")
- .addQueryParam("password", "sekrit")
- .addQueryParam("apiKey", "identity")
- .addQueryParam("signature", "2uIQ5qF0bVycXK111wxvogWp1Yw=")
- .addHeader("Accept", "application/json").build();
-
- @Test
- public void testAddClusterWhenResponseIs2xx() {
- 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(AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
-
- Cluster actual = requestSendsResponse(addCluster, response).addCluster("1", "Xen Clust 1", Host.ClusterType.CLOUD_MANAGED, "XenServer", AddClusterOptions.Builder.allocationState(AllocationState.ENABLED).podId("1").url("http://example.com/cluster").username("fred").password("sekrit"));
-
- assertEquals(actual, expected);
- }
-
- HttpRequest updateCluster = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "updateCluster")
- .addQueryParam("id", "1")
- .addQueryParam("allocationstate", "Enabled")
- .addQueryParam("clustername", "Xen Clust 1")
- .addQueryParam("clustertype", "CloudManaged")
- .addQueryParam("hypervisor", "XenServer")
- .addQueryParam("managedstate", "Managed")
- .addQueryParam("apiKey", "identity")
- .addQueryParam("signature", "/wbuYKwInciSXWkUf05lEfJZShQ=")
- .addHeader("Accept", "application/json").build();
-
- @Test
- public void testUpdateClusterWhenResponseIs2xx() {
- 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(AllocationState.ENABLED).managedState(Cluster.ManagedState.MANAGED).build();
-
- Cluster actual = requestSendsResponse(updateCluster, response).updateCluster("1", UpdateClusterOptions.Builder.allocationState(AllocationState.ENABLED).clusterName("Xen Clust 1").clusterType(Host.ClusterType.CLOUD_MANAGED).hypervisor("XenServer").managedState(Cluster.ManagedState.MANAGED));
-
- assertEquals(actual, expected);
- }
-
- HttpRequest updateClusterPassword = HttpRequest.builder().method("GET")
- .endpoint("http://localhost:8080/client/api")
- .addQueryParam("response", "json")
- .addQueryParam("command", "updateHostPassword")
- .addQueryParam("clusterid", "1")
- .addQueryParam("username", "fred")
- .addQueryParam("password", "sekrit")
- .addQueryParam("apiKey", "identity")
- .addQueryParam("signature", "xwc83%2BoYK0cuAiFQAlg/7/1IVHE=")
- .addHeader("Accept", "application/json").build();
-
- @Test
- public void testUpdateClusterPasswordWhenResponseIs2xx() {
- HttpResponse response = HttpResponse.builder()
- .statusCode(200).build();
- requestSendsResponse(updateClusterPassword, response).updateClusterPassword("1", "fred", "sekrit");
- }
-
- @Test
- public void testDeleteClusterWhenResponseIs2xx() {
- HttpRequest request = HttpRequest.builder()
- .method("GET")
- .endpoint("http://localhost:8080/client/api?response=json&command=deleteCluster&id=1&apiKey=identity&signature=CKH26MFgKGY7Sosd17LjBMNa3AI%3D")
- .addHeader("Accept", "application/json").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();
- }
-}