You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2014/07/16 11:20:46 UTC
[4/9] [JCLOUDS-474] refactor SoftLayer support
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystemsTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystemsTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystemsTest.java
new file mode 100644
index 0000000..6bda6f0
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/functions/internal/OperatingSystemsTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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.softlayer.compute.functions.internal;
+
+import static org.testng.Assert.assertEquals;
+
+import org.jclouds.compute.domain.OsFamily;
+import org.testng.annotations.Test;
+
+@Test(singleThreaded = true, groups = "unit")
+public class OperatingSystemsTest {
+
+ @Test
+ public void testOsFamily() {
+ assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.CENTOS), OsFamily.CENTOS);
+ assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.DEBIAN), OsFamily.DEBIAN);
+ assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.RHEL), OsFamily.RHEL);
+ assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.UBUNTU), OsFamily.UBUNTU);
+ assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.WINDOWS), OsFamily.WINDOWS);
+ assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.CLOUD_LINUX), OsFamily.CLOUD_LINUX);
+ assertEquals(OperatingSystems.osFamily().apply(OperatingSystems.VYATTACE), OsFamily.LINUX);
+ }
+
+ @Test
+ public void testOsBits() {
+ assertEquals(OperatingSystems.bits().apply("UBUNTU_12_64").intValue(), 64);
+ assertEquals(OperatingSystems.bits().apply("UBUNTU_12_32").intValue(), 32);
+ }
+
+ @Test
+ public void testOsVersion() {
+ assertEquals(OperatingSystems.version().apply("12.04-64 Minimal for VSI"), "12.04");
+ assertEquals(OperatingSystems.version().apply("STD 32 bit"), "STD");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java
index 744c073..47f8b3d 100644
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/domain/AddressTest.java
@@ -18,9 +18,6 @@ package org.jclouds.softlayer.domain;
import org.testng.annotations.Test;
-/**
- * Tests {@code Address}
- */
@Test(singleThreaded = true, groups = "unit")
public class AddressTest {
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiExpectTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiExpectTest.java
new file mode 100644
index 0000000..407e812
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiExpectTest.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.softlayer.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.softlayer.SoftLayerApi;
+import org.jclouds.softlayer.parse.GetVirtualGuestBlockDeviceTemplateGroupsResponseTest;
+import org.jclouds.softlayer.parse.ListVirtualGuestsResponseTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+@Test(groups = "unit", testName = "AccountApiExpectTest")
+public class AccountApiExpectTest extends BaseSoftLayerApiExpectTest {
+
+ public void testListVirtualGuestsWhenResponseIs2xx() {
+
+ HttpRequest listVirtualGuestsRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse listVirtualGuestsResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/account_list.json")).build();
+
+ SoftLayerApi api = requestSendsResponse(listVirtualGuestsRequest, listVirtualGuestsResponse);
+
+ assertEquals(api.getAccountApi().listVirtualGuests(),
+ new ListVirtualGuestsResponseTest().expected());
+ }
+
+ public void testListVirtualGuestsWhenResponseIs4xx() {
+
+ HttpRequest listVirtualGuestsRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse listVirtualGuestsResponse = HttpResponse.builder().statusCode(404).build();
+
+ SoftLayerApi api = requestSendsResponse(listVirtualGuestsRequest, listVirtualGuestsResponse);
+
+ assertTrue(Iterables.isEmpty(api.getAccountApi().listVirtualGuests()));
+ }
+
+ public void testGetBlockDeviceTemplateGroupsWhenResponseIs2xx() {
+
+ HttpRequest getVirtualGuestBlockDeviceTemplateGroup = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getVirtualGuestBlockDeviceTemplateGroupResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/account_get_block_devices_template_groups.json")).build();
+
+ SoftLayerApi api = requestSendsResponse(getVirtualGuestBlockDeviceTemplateGroup, getVirtualGuestBlockDeviceTemplateGroupResponse);
+
+ assertEquals(api.getAccountApi().getBlockDeviceTemplateGroups(),
+ new GetVirtualGuestBlockDeviceTemplateGroupsResponseTest().expected());
+ }
+
+ public void testGetBlockDeviceTemplateGroupsWhenResponseIs4xx() {
+
+ HttpRequest getObjectRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build();
+
+ SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse);
+
+ assertTrue(Iterables.isEmpty(api.getAccountApi().getBlockDeviceTemplateGroups()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java
index f192ece..c53fef4 100644
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiLiveTest.java
@@ -16,12 +16,14 @@
*/
package org.jclouds.softlayer.features;
-import static org.testng.Assert.assertTrue;
+import org.jclouds.softlayer.domain.VirtualGuest;
+import org.jclouds.softlayer.domain.VirtualGuestBlockDeviceTemplateGroup;
+import org.testng.annotations.Test;
import java.util.Set;
-import org.jclouds.softlayer.domain.ProductPackage;
-import org.testng.annotations.Test;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
/**
* Tests behavior of {@code AccountApi}
@@ -30,16 +32,42 @@ import org.testng.annotations.Test;
public class AccountApiLiveTest extends BaseSoftLayerApiLiveTest {
@Test
- public void testGetActivePackages() {
- Set<ProductPackage> response = api.getAccountApi().getActivePackages();
- assert null != response;
+ public void testGetBlockDeviceTemplateGroups() {
+ Set<VirtualGuestBlockDeviceTemplateGroup> privateImages = api().getBlockDeviceTemplateGroups();
+ assertNotNull(privateImages);
+ for (VirtualGuestBlockDeviceTemplateGroup privateImage : privateImages) {
+ assertTrue(privateImage.getId() > 0, "id must be greater than 0");
+ assertTrue(privateImage.getStatusId() > 0, "status id must be greater than 0");
+ assertTrue(privateImage.getAccountId() > 0, "id must be greater than 0");
+ }
+ }
+ @Test
+ public void testListVirtualGuests() throws Exception {
+ Set<VirtualGuest> response = api().listVirtualGuests();
assertTrue(response.size() >= 0);
- for (ProductPackage productPackage : response) {
- assert productPackage.getId() > 0 : response;
- assert productPackage.getName() != null : response;
- assert productPackage.getDescription() != null : response;
- assertTrue(productPackage.getItems().isEmpty());
+ for (VirtualGuest vg : response) {
+ checkVirtualGuest(vg);
}
}
+
+ private AccountApi api() {
+ return api.getAccountApi();
+ }
+
+ private void checkVirtualGuest(VirtualGuest vg) {
+ if (vg.getActiveTransactionCount() == 0) {
+ assertNotNull(vg.getDomain(), "domain must be not null");
+ assertNotNull(vg.getFullyQualifiedDomainName(), "fullyQualifiedDomainName must be not null");
+ assertNotNull(vg.getHostname(), "hostname must be not null");
+ assertTrue(vg.getId() > 0, "id must be greater than 0");
+ assertTrue(vg.getMaxCpu() > 0, "maxCpu must be greater than 0");
+ assertNotNull(vg.getMaxCpuUnits(), "maxCpuUnits must be not null");
+ assertTrue(vg.getMaxMemory() > 0, "maxMemory must be greater than 0");
+ assertTrue(vg.getStartCpus() > 0, "startCpus must be greater than 0");
+ assertTrue(vg.getStatusId() > 0, "statusId must be greater than 0");
+ assertNotNull(vg.getUuid(), "uuid must be not null");
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.java
deleted file mode 100644
index 7cf7406..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.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.softlayer.features;
-
-import static org.jclouds.reflect.Reflection2.method;
-
-import java.io.IOException;
-
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.http.functions.ParseJson;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-/**
- * Tests annotation parsing of {@code AccountApi}
- */
-@Test(groups = "unit")
-public class AccountApiTest extends BaseSoftLayerApiTest<AccountApi> {
-
- public void testGetActivePackages() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AccountApi.class, "getActivePackages");
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(
- httpRequest,
- "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/ActivePackages.json HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiExpectTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiExpectTest.java
new file mode 100644
index 0000000..8a6a23a
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiExpectTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.softlayer.features;
+
+import org.jclouds.providers.ProviderMetadata;
+import org.jclouds.rest.internal.BaseRestApiExpectTest;
+import org.jclouds.softlayer.SoftLayerApi;
+import org.jclouds.softlayer.SoftLayerProviderMetadata;
+
+public abstract class BaseSoftLayerApiExpectTest extends BaseRestApiExpectTest<SoftLayerApi> {
+
+ @Override
+ public ProviderMetadata createProviderMetadata() {
+ return new SoftLayerProviderMetadata();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java
index 1ba09e9..bda65df 100644
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java
@@ -29,4 +29,5 @@ public class BaseSoftLayerApiLiveTest extends BaseApiLiveTest<SoftLayerApi> {
public BaseSoftLayerApiLiveTest() {
this.provider = "softlayer";
}
+
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.java
deleted file mode 100644
index f9c55d6..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.java
+++ /dev/null
@@ -1,40 +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.softlayer.features;
-
-import static org.testng.Assert.assertEquals;
-
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.filters.BasicAuthentication;
-import org.jclouds.providers.ProviderMetadata;
-import org.jclouds.rest.internal.BaseAsyncClientTest;
-import org.jclouds.softlayer.SoftLayerProviderMetadata;
-
-public abstract class BaseSoftLayerApiTest<T> extends BaseAsyncClientTest<T> {
-
- @Override
- protected void checkFilters(HttpRequest request) {
- assertEquals(request.getFilters().size(), 1);
- assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
- }
-
- @Override
- public ProviderMetadata createProviderMetadata() {
- return new SoftLayerProviderMetadata();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiExpectTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiExpectTest.java
new file mode 100644
index 0000000..2317a3a
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiExpectTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.softlayer.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.softlayer.parse.GetDatacenterResponseTest;
+import org.jclouds.softlayer.parse.ListDatacentersResponseTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests annotation parsing of {@code DatacenterAsyncClient}
+ */
+@Test(groups = "unit")
+public class DatacenterApiExpectTest extends BaseSoftLayerApiExpectTest {
+
+ public void testListDatacentersWhenResponseIs2xx() {
+
+ HttpRequest listDatacentersRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse listDatacentersResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/datacenter_list.json")).build();
+
+ DatacenterApi api = requestSendsResponse(listDatacentersRequest, listDatacentersResponse).getDatacenterApi();
+
+ assertEquals(api.listDatacenters(),
+ new ListDatacentersResponseTest().expected());
+ }
+
+ public void testListDatacenterWhenResponseIs4xx() {
+
+ HttpRequest listDatacentersRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse listDatacentersResponse = HttpResponse.builder().statusCode(404).build();
+
+ DatacenterApi api = requestSendsResponse(listDatacentersRequest, listDatacentersResponse).getDatacenterApi();
+
+ assertTrue(Iterables.isEmpty(api.listDatacenters()));
+ }
+
+ public void testGetDatacenterWhenResponseIs2xx() {
+
+ HttpRequest getDatacenterRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getDatacenterResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/datacenter_get.json")).build();
+
+ DatacenterApi api = requestSendsResponse(getDatacenterRequest, getDatacenterResponse).getDatacenterApi();
+
+ assertEquals(api.getDatacenter(265592),
+ new GetDatacenterResponseTest().expected());
+ }
+
+ public void testGetDatacenterWhenResponseIs4xx() {
+
+ HttpRequest getDatacenterRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getDatacenterResponse = HttpResponse.builder().statusCode(404).build();
+
+ DatacenterApi api = requestSendsResponse(getDatacenterRequest, getDatacenterResponse).getDatacenterApi();
+
+ assertNull(api.getDatacenter(265592));
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java
index 281e23c..f7a86d9 100644
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java
@@ -16,18 +16,18 @@
*/
package org.jclouds.softlayer.features;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Set;
-
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
import org.jclouds.softlayer.domain.Address;
import org.jclouds.softlayer.domain.Datacenter;
import org.jclouds.softlayer.domain.Region;
import org.testng.annotations.Test;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
+import java.util.Set;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
/**
* Tests behavior of {@code DatacenterApi}
@@ -38,7 +38,7 @@ public class DatacenterApiLiveTest extends BaseSoftLayerApiLiveTest {
@Test
public void testListDatacenters() {
Set<Datacenter> response = api().listDatacenters();
- assert null != response;
+ assertNotNull(response);
assertTrue(response.size() >= 0);
for (Datacenter vg : response) {
Datacenter newDetails = api().getDatacenter(vg.getId());
@@ -51,29 +51,30 @@ public class DatacenterApiLiveTest extends BaseSoftLayerApiLiveTest {
public void testListDatacentersContent() {
Builder<Datacenter> builder = ImmutableSet.builder();
builder.add(Datacenter.builder().id(265592).name("ams01").longName("Amsterdam 1").build());
+ builder.add(Datacenter.builder().id(358698).name("wdc03").longName("Ashburn, VA 3").build());
builder.add(Datacenter.builder().id(3).name("dal01").longName("Dallas").build());
- builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build());
- builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build());
- builder.add(Datacenter.builder().id(2).name("dal00").longName("Corporate HQ").build());
- builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build());
builder.add(Datacenter.builder().id(154770).name("dal02").longName("Dallas 2").build());
- builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build());
- builder.add(Datacenter.builder().id(167093).name("hou01").longName("Houston 1").build());
- builder.add(Datacenter.builder().id(167094).name("lon01").longName("London 1").build());
builder.add(Datacenter.builder().id(167092).name("dal04").longName("Dallas 4").build());
- builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build());
- builder.add(Datacenter.builder().id(142775).name("hou02").longName("Houston 2").build());
- builder.add(Datacenter.builder().id(142776).name("dal07").longName("Dallas 7").build());
+ builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build());
builder.add(Datacenter.builder().id(154820).name("dal06").longName("Dallas 6").build());
+ builder.add(Datacenter.builder().id(142776).name("dal07").longName("Dallas 7").build());
+ builder.add(Datacenter.builder().id(352494).name("hkg02").longName("Hong Kong 2").build());
+ builder.add(Datacenter.builder().id(142775).name("hou02").longName("Houston 2").build());
+ builder.add(Datacenter.builder().id(358694).name("lon02").longName("London 2").build());
+ builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build());
+ builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build());
+ builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build());
+ builder.add(Datacenter.builder().id(448994).name("tor01").longName("Toronto 1").build());
+ builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC 1").build());
+
Set<Datacenter> response = api().listDatacenters();
Set<Datacenter> expected = builder.build();
assertEquals(response.size(), expected.size());
- assertTrue(response.containsAll(expected));
- for (Datacenter datacenter : response) {
+ for(Datacenter datacenter: response) {
Address address = datacenter.getLocationAddress();
- if (address != null) checkAddress(address);
+ if(address!=null) checkAddress(address);
}
}
@@ -82,19 +83,19 @@ public class DatacenterApiLiveTest extends BaseSoftLayerApiLiveTest {
}
private void checkDatacenter(Datacenter dc) {
- assert dc.getId() > 0 : dc;
- assert dc.getName() != null : dc;
- assert dc.getLongName() != null : dc;
- for (Region region : dc.getRegions()) checkRegion(region);
+ assertNotNull(dc.getId());
+ assertNotNull(dc.getName());
+ assertNotNull(dc.getLongName());
+ for( Region region: dc.getRegions()) checkRegion(region);
}
private void checkRegion(Region region) {
- assert !region.getDescription().isEmpty() : region;
- assert !region.getKeyname().isEmpty() : region;
+ assertNotNull(region.getDescription());
+ assertNotNull(region.getKeyname());
}
private void checkAddress(Address address) {
- assert address.getId() > 0 : address;
- assert address.getCountry() != null : address;
+ assertNotNull(address.getId());
+ assertNotNull(address.getCountry());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java
deleted file mode 100644
index 506bc96..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java
+++ /dev/null
@@ -1,83 +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.softlayer.features;
-
-import static org.jclouds.reflect.Reflection2.method;
-
-import java.io.IOException;
-
-import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.http.functions.ParseJson;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.reflect.Invokable;
-/**
- * Tests annotation parsing of {@code DatacenterApi}
- */
-@Test(groups = "unit")
-public class DatacenterApiTest extends BaseSoftLayerApiTest<DatacenterApi> {
-
- public void testListDatacenters() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(DatacenterApi.class, "listDatacenters");
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
-
- assertRequestLineEquals(httpRequest,
- "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json?objectMask=locationAddress%3Bregions HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- // now make sure request filters apply by replaying
- httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
- httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
-
- assertRequestLineEquals(httpRequest,
- "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json?objectMask=locationAddress%3Bregions HTTP/1.1");
- // for example, using basic authentication, we should get "only one"
- // header
- assertNonPayloadHeadersEqual(httpRequest,
- "Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-
- public void testGetDatacenter() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(DatacenterApi.class, "getDatacenter", long.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
-
- assertRequestLineEquals(httpRequest,
- "GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/1234.json?objectMask=locationAddress%3Bregions HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java
deleted file mode 100644
index fd64c81..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java
+++ /dev/null
@@ -1,216 +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.softlayer.features;
-
-import static org.jclouds.softlayer.predicates.ProductItemPredicates.capacity;
-import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode;
-import static org.jclouds.softlayer.predicates.ProductItemPredicates.units;
-import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.jclouds.softlayer.compute.functions.ProductItems;
-import org.jclouds.softlayer.domain.Address;
-import org.jclouds.softlayer.domain.Datacenter;
-import org.jclouds.softlayer.domain.ProductItem;
-import org.jclouds.softlayer.domain.ProductItemCategory;
-import org.jclouds.softlayer.domain.ProductItemPrice;
-import org.jclouds.softlayer.domain.ProductPackage;
-import org.jclouds.softlayer.domain.Region;
-import org.testng.annotations.BeforeGroups;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicates;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-
-/**
- * Tests behavior of {@code ProductPackageApi}
- */
-@Test(groups = "live", singleThreaded = true, testName = "ProductPackageApiLiveTest")
-public class ProductPackageApiLiveTest extends BaseSoftLayerApiLiveTest {
-
- /**
- * Name of the package used for ordering virtual guests. For real this is
- * passed in using the property
- *
- * @{code org.jclouds.softlayer.reference.SoftLayerConstants.
- * PROPERTY_SOFTLAYER_VIRTUALGUEST_PACKAGE_NAME}
- */
- public static final String CLOUD_SERVER_PACKAGE_NAME = "Cloud Server";
-
- @BeforeGroups(groups = { "live" })
- public void setup() {
- super.setup();
- client = api.getProductPackageApi();
- accountApi = api.getAccountApi();
-
- // This is used several times, so cache to speed up the test.
- cloudServerPackageId = Iterables.find(accountApi.getActivePackages(), named(CLOUD_SERVER_PACKAGE_NAME))
- .getId();
- cloudServerProductPackage = client.getProductPackage(cloudServerPackageId);
- }
-
- private ProductPackageApi client;
- private AccountApi accountApi;
-
- private int cloudServerPackageId;
- private ProductPackage cloudServerProductPackage;
-
- @Test
- public void testGetProductPackage() {
- for (ProductPackage productPackage : accountApi.getActivePackages()) {
- ProductPackage response = client.getProductPackage(productPackage.getId());
-
- assert null != response;
- assert response.getId() > 0 : response;
- assert response.getName() != null : response;
- assert response.getDescription() != null : response;
-
- assertTrue(response.getItems().size() >= 0);
- for (ProductItem item : response.getItems()) {
- // ProductItem newDetails = client.getProductItem(item.getId());
- // assertEquals(item.getId(), newDetails.getId());
- checkProductItem(item);
- }
-
- assertTrue(response.getDatacenters().size() > 0);
- for (Datacenter datacenter : response.getDatacenters()) {
- checkDatacenter(datacenter);
- }
- }
- }
-
- @Test
- public void testDatacentersForCloudLayer() {
-
- ImmutableSet.Builder<Datacenter> builder = ImmutableSet.builder();
- builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build());
- builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build());
- builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build());
- builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build());
- builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build());
- builder.add(Datacenter.builder().id(265592).name("ams01").longName("Amsterdam 1").build());
-
- Set<Datacenter> expected = builder.build();
-
- Set<Datacenter> datacenters = cloudServerProductPackage.getDatacenters();
- assert datacenters.size() == expected.size() : datacenters;
- assertTrue(datacenters.containsAll(expected));
-
- for (Datacenter dataCenter : datacenters) {
- Address address = dataCenter.getLocationAddress();
- assertNotNull(address);
- checkAddress(address);
- }
- }
-
- @Test
- public void testGetOneGBRamPrice() {
- // Predicate p =
- // Predicates.and(ProductItemPredicates.categoryCode("ram"),ProductItemPredicates.capacity(1.0f));
- Iterable<ProductItem> ramItems = Iterables.filter(cloudServerProductPackage.getItems(),
- Predicates.and(categoryCode("ram"), capacity(1.0f)));
-
- // capacity is key in GB (1Gb = 1.0f)
- Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity());
-
- ProductItemPrice price = ProductItems.price().apply(ramToProductItem.get(1.0f));
- assert Integer.valueOf(1644).equals(price.getId());
- }
-
- @Test
- public void testGetTwoCPUCoresPrice() {
- // If use ProductItemPredicates.categoryCode("guest_core") get duplicate
- // capacities (units =
- // PRIVATE_CORE and N/A)
- Iterable<ProductItem> cpuItems = Iterables.filter(cloudServerProductPackage.getItems(),
- Predicates.and(units("PRIVATE_CORE"), capacity(2.0f)));
-
- // number of cores is the key
- Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity());
-
- ProductItemPrice price = ProductItems.price().apply(coresToProductItem.get(2.0f));
- assert Integer.valueOf(1963).equals(price.getId());
- }
-
- @Test
- public void testGetUbuntuPrice() {
- Iterable<ProductItem> operatingSystems = Iterables.filter(cloudServerProductPackage.getItems(),
- categoryCode("os"));
-
- Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description());
-
- ProductItemPrice price = ProductItems.price().apply(
- osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)"));
- assert Integer.valueOf(1693).equals(price.getId());
- }
-
- private void checkProductItem(ProductItem item) {
- assert item.getId() > 0 : item;
- assert item.getDescription() != null : item;
- checkCategories(item.getCategories());
- // units and capacity may be null
-
- assertTrue(item.getPrices().size() >= 0);
-
- for (ProductItemPrice price : item.getPrices()) {
- // ProductItemPrice newDetails =
- // client.getProductItemPrice(prices.getId());
- // assertEquals(item.getId(), newDetails.getId());
- checkPrice(price);
- }
- }
-
- private void checkPrice(ProductItemPrice price) {
- assert price.getId() > 0 : price;
- assert price.getItemId() > 0 : price;
- assert price.getRecurringFee() != null || price.getHourlyRecurringFee() != null : price;
- }
-
- private void checkDatacenter(Datacenter datacenter) {
- assert datacenter.getId() > 0 : datacenter;
- assert datacenter.getName() != null : datacenter;
- assert datacenter.getLongName() != null : datacenter;
- for (Region region : datacenter.getRegions())
- checkRegion(region);
- }
-
- private void checkRegion(Region region) {
- assert !region.getDescription().isEmpty() : region;
- assert !region.getKeyname().isEmpty() : region;
- }
-
- private void checkAddress(Address address) {
- assert address.getId() > 0 : address;
- assert address.getCountry() != null : address;
- if (!ImmutableSet.of("SG", "NL").contains(address.getCountry()))
- assert address.getState() != null : address;
- }
-
- private void checkCategories(Set<ProductItemCategory> categories) {
- for (ProductItemCategory category : categories) {
- assert category.getId() > 0 : category;
- assert category.getName() != null : category;
- assert category.getCategoryCode() != null : category;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.java
deleted file mode 100644
index 711264d..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.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.softlayer.features;
-
-import static org.jclouds.reflect.Reflection2.method;
-
-import java.io.IOException;
-
-import org.jclouds.Fallbacks.NullOnNotFoundOr404;
-import org.jclouds.http.functions.ParseJson;
-import org.jclouds.rest.internal.GeneratedHttpRequest;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.reflect.Invokable;
-/**
- * Tests annotation parsing of {@code ProductPackageApi}
- */
-@Test(groups = "unit")
-public class ProductPackageApiTest extends BaseSoftLayerApiTest<ProductPackageApi> {
-
- public void testGetProductPackage() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(ProductPackageApi.class, "getProductPackage", long.class);
- GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
-
- assertRequestLineEquals(
- httpRequest,
- "GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/1234.json?objectMask=items.prices%3Bitems.categories%3Blocations.locationAddress%3Blocations.regions HTTP/1.1");
- assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
- assertPayloadEquals(httpRequest, null, null, false);
-
- assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
- assertSaxResponseParserClassEquals(method, null);
- assertFallbackClassEquals(method, NullOnNotFoundOr404.class);
-
- checkFilters(httpRequest);
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiExpectTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiExpectTest.java
new file mode 100644
index 0000000..c8286c2
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiExpectTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.softlayer.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.softlayer.parse.GetAllObjectsResponseTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests annotation parsing of {@code DatacenterAsyncClient}
+ */
+@Test(groups = "unit")
+public class SoftwareDescriptionApiExpectTest extends BaseSoftLayerApiExpectTest {
+
+ public void testGetAllObjectsWhenResponseIs2xx() {
+
+ HttpRequest getAllObjectsRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Software_Description/getAllObjects?objectMask=id%3Bname%3Bversion%3BoperatingSystem%3BlongDescription%3BreferenceCode")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+ HttpResponse getAllObjectsResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/software_description_list.json")).build();
+ SoftwareDescriptionApi api = requestSendsResponse(getAllObjectsRequest, getAllObjectsResponse).getSoftwareDescriptionApi();
+ assertEquals(api.getAllObjects(), new GetAllObjectsResponseTest().expected());
+ }
+
+ public void testGetAllObjectsWhenResponseIs4xx() {
+
+ HttpRequest getAllObjectsRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Software_Description/getAllObjects?objectMask=id%3Bname%3Bversion%3BoperatingSystem%3BlongDescription%3BreferenceCode")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+ HttpResponse getAllObjectsResponse = HttpResponse.builder().statusCode(404).build();
+ SoftwareDescriptionApi api = requestSendsResponse(getAllObjectsRequest, getAllObjectsResponse).getSoftwareDescriptionApi();
+ assertTrue(Iterables.isEmpty(api.getAllObjects()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiLiveTest.java
new file mode 100644
index 0000000..0948c6f
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/SoftwareDescriptionApiLiveTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.softlayer.features;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import java.util.Set;
+
+import org.jclouds.softlayer.domain.SoftwareDescription;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code SoftwareDescriptionApi}
+ */
+@Test(groups = "live")
+public class SoftwareDescriptionApiLiveTest extends BaseSoftLayerApiLiveTest {
+
+ @Test
+ public void testGetAllObjects() {
+ Set<SoftwareDescription> response = api().getAllObjects();
+ assertNotNull(response);
+ assertTrue(response.size() >= 0);
+ }
+
+ private SoftwareDescriptionApi api() {
+ return api.getSoftwareDescriptionApi();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java
index a12a7e5..cfba677 100644
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.java
@@ -16,39 +16,261 @@
*/
package org.jclouds.softlayer.features;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import javax.ws.rs.core.MediaType;
+
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
-import org.jclouds.rest.internal.BaseRestClientExpectTest;
import org.jclouds.softlayer.SoftLayerApi;
+import org.jclouds.softlayer.domain.Datacenter;
+import org.jclouds.softlayer.domain.OperatingSystem;
+import org.jclouds.softlayer.domain.VirtualGuest;
+import org.jclouds.softlayer.parse.CreateVirtualGuestResponseTest;
+import org.jclouds.softlayer.parse.GetCreateObjectOptionsResponseTest;
+import org.jclouds.softlayer.parse.GetVirtualGuestResponseTest;
import org.testng.annotations.Test;
-@Test(groups = "unit", testName = "SoftLayerClientExpectTest")
-public class VirtualGuestApiExpectTest extends BaseRestClientExpectTest<SoftLayerApi> {
+import com.google.common.collect.ImmutableSet;
+
+@Test(groups = "unit", testName = "VirtualGuestApiExpectTest")
+public class VirtualGuestApiExpectTest extends BaseSoftLayerApiExpectTest {
+
+ public void testGetVirtualGuestWhenResponseIs2xx() {
+
+ HttpRequest getVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getVirtualGuestResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/virtual_guest_get.json")).build();
+
+ SoftLayerApi api = requestSendsResponse(getVirtualGuest, getVirtualGuestResponse);
+
+ assertEquals(api.getVirtualGuestApi().getVirtualGuest(3001812),
+ new GetVirtualGuestResponseTest().expected());
+ }
+
+ public void testGetVirtualGuestWhenResponseIs4xx() {
+
+ HttpRequest getObjectRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build();
+ SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse);
+ assertNull(api.getVirtualGuestApi().getVirtualGuest(3001812));
+ }
+
+ public void testCreateVirtualGuestWhenResponseIs2xx() {
+
+ HttpRequest createVirtualGuest = HttpRequest.builder().method("POST")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
+ .payload(payloadFromResourceWithContentType("/virtual_guest_create.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse createVirtualGuestResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/virtual_guest_create_response.json")).build();
+
+ VirtualGuestApi api = requestSendsResponse(createVirtualGuest, createVirtualGuestResponse).getVirtualGuestApi();
+ VirtualGuest virtualGuest = createVirtualGuest();
+ VirtualGuest result = api.createVirtualGuest(virtualGuest);
+ assertEquals(result, new CreateVirtualGuestResponseTest().expected());
+ }
+
+ public void testCreateVirtualGuestWhenResponseIs4xx() {
+
+ HttpRequest createVirtualGuest = HttpRequest.builder().method("POST")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
+ .payload(payloadFromResourceWithContentType("/virtual_guest_create.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse createVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
+ SoftLayerApi api = requestSendsResponse(createVirtualGuest, createVirtualGuestResponse);
+ VirtualGuest virtualGuest = createVirtualGuest();
+ assertNull(api.getVirtualGuestApi().createVirtualGuest(virtualGuest));
+ }
+
+ public void testDeleteVirtualGuestWhenResponseIs2xx() {
+
+ HttpRequest deleteVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/deleteObject")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
+ .build();
+
+ HttpResponse deleteVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
+
+ VirtualGuestApi api = requestSendsResponse(deleteVirtualGuest, deleteVirtualGuestResponse).getVirtualGuestApi();
+ assertTrue(api.deleteVirtualGuest(1301396));
+ }
+
+ public void testDeleteVirtualGuestWhenResponseIs4xx() {
+
+ HttpRequest deleteVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/deleteObject")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
+ .build();
+
+ HttpResponse deleteVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
+ VirtualGuestApi api = requestSendsResponse(deleteVirtualGuest, deleteVirtualGuestResponse).getVirtualGuestApi();
+ assertFalse(api.deleteVirtualGuest(1301396));
+ }
+
+ private VirtualGuest createVirtualGuest() {
+ return VirtualGuest.builder()
+ .domain("example.com")
+ .hostname("host1")
+ .id(1301396)
+ .maxMemory(1024)
+ .startCpus(1)
+ .localDiskFlag(true)
+ .operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST")
+ .operatingSystemReferenceCode("UBUNTU_LATEST")
+ .build())
+ .datacenter(Datacenter.builder().name("test").build())
+ .build();
+ }
+
+ public void testGetCreateObjectOptionsWhenResponseIs2xx() {
+
+ HttpRequest getVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getVirtualGuestResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/container_virtual_guest_configuration.json")).build();
+ SoftLayerApi api = requestSendsResponse(getVirtualGuest, getVirtualGuestResponse);
- public VirtualGuestApiExpectTest() {
- provider = "softlayer";
+ assertEquals(api.getVirtualGuestApi().getCreateObjectOptions(),
+ new GetCreateObjectOptionsResponseTest().expected());
}
-
- public void testCancelGuestReturnsTrueOn200AndFalseOn404() {
-
- HttpRequest cancelGuest11 = HttpRequest.builder().method("GET")
- .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Billing_Item/11/cancelService.json")
- .addHeader("Accept", "application/json")
- .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
- HttpResponse found = HttpResponse.builder().statusCode(200).build();
+ public void testGetCreateObjectOptionsWhenResponseIs4xx() {
- SoftLayerApi clientWhenServiceExists = requestSendsResponse(cancelGuest11, found);
-
- assert clientWhenServiceExists.getVirtualGuestApi().cancelService(11l);
+ HttpRequest getObjectRequest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build();
+ SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse);
+ assertNull(api.getVirtualGuestApi().getCreateObjectOptions());
+ }
+
+ public void testRebootHardVirtualGuestWhenResponseIs2xx() {
+
+ HttpRequest rebootHardVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/rebootHard.json")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse rebootHardVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
+ SoftLayerApi api = requestSendsResponse(rebootHardVirtualGuest, rebootHardVirtualGuestResponse);
+ api.getVirtualGuestApi().rebootHardVirtualGuest(1301396);
+ }
+
+ public void testRebootHardVirtualGuestWhenResponseIs4xx() {
+
+ HttpRequest rebootHardVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/rebootHard.json")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse rebootHardVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
+ SoftLayerApi api = requestSendsResponse(rebootHardVirtualGuest, rebootHardVirtualGuestResponse);
+ api.getVirtualGuestApi().rebootHardVirtualGuest(1301396);
+ }
+
+ public void testPauseVirtualGuestWhenResponseIs2xx() {
+
+ HttpRequest pauseVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/pause.json")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse pauseVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
+ SoftLayerApi api = requestSendsResponse(pauseVirtualGuest, pauseVirtualGuestResponse);
+ api.getVirtualGuestApi().pauseVirtualGuest(1301396);
+ }
+ public void testPauseVirtualGuestWhenResponseIs4xx() {
+
+ HttpRequest pauseVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/pause.json")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse pauseVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
+ SoftLayerApi api = requestSendsResponse(pauseVirtualGuest, pauseVirtualGuestResponse);
+ api.getVirtualGuestApi().pauseVirtualGuest(1301396);
+ }
+
+ public void testResumeVirtualGuestWhenResponseIs2xx() {
+
+ HttpRequest resumeVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/resume.json")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse resumeVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
+ SoftLayerApi api = requestSendsResponse(resumeVirtualGuest, resumeVirtualGuestResponse);
+ api.getVirtualGuestApi().resumeVirtualGuest(1301396);
+ }
+
+ public void testResumeVirtualGuestWhenResponseIs4xx() {
+
+ HttpRequest resumeVirtualGuest = HttpRequest.builder().method("GET")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/resume.json")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
+
+ HttpResponse resumeVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
+ SoftLayerApi api = requestSendsResponse(resumeVirtualGuest, resumeVirtualGuestResponse);
+ api.getVirtualGuestApi().resumeVirtualGuest(1301396);
+ }
+
+ public void testSetTagsOnVirtualGuestWhenResponseIs2xx() {
+
+ HttpRequest setTagsOnVirtualGuest = HttpRequest.builder().method("POST")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/setTags")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
+ .payload(payloadFromResourceWithContentType("/virtual_guest_set_tags.json", MediaType.APPLICATION_JSON))
+ .build();
+
+ HttpResponse setTagsOnVirtualGuestResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/virtual_guest_set_tags_response.json")).build();
+
+ SoftLayerApi api = requestSendsResponse(setTagsOnVirtualGuest, setTagsOnVirtualGuestResponse);
+ VirtualGuest virtualGuest = createVirtualGuest();
+ assertTrue(api.getVirtualGuestApi().setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3")));
+ }
- HttpResponse notFound = HttpResponse.builder().statusCode(404).build();
+ public void testSetTagsOnVirtualGuestWhenResponseIs4xx() {
- SoftLayerApi clientWhenServiceDoesntExist = requestSendsResponse(cancelGuest11, notFound);
-
- assert !clientWhenServiceDoesntExist.getVirtualGuestApi().cancelService(11l);
+ HttpRequest setTagsOnVirtualGuest = HttpRequest.builder().method("POST")
+ .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/setTags")
+ .addHeader("Accept", "application/json")
+ .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
+ .payload(payloadFromResourceWithContentType("/virtual_guest_set_tags.json", MediaType.APPLICATION_JSON))
+ .build();
+ HttpResponse setTagsOnVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
+ SoftLayerApi api = requestSendsResponse(setTagsOnVirtualGuest, setTagsOnVirtualGuestResponse);
+ VirtualGuest virtualGuest = createVirtualGuest();
+ assertFalse(api.getVirtualGuestApi().setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3")));
}
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/717a545b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java
index 14fbe65..81948b5 100644
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java
@@ -16,38 +16,30 @@
*/
package org.jclouds.softlayer.features;
-import static org.jclouds.softlayer.predicates.ProductItemPredicates.capacity;
-import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode;
-import static org.jclouds.softlayer.predicates.ProductItemPredicates.units;
-import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named;
+import static com.google.common.base.Preconditions.checkState;
+import static org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter.VirtualGuestHasLoginDetailsPresent;
+import static org.jclouds.util.Predicates2.retry;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
-
-import java.util.Map;
import java.util.Properties;
-import java.util.Random;
import java.util.Set;
import org.jclouds.softlayer.SoftLayerApi;
-import org.jclouds.softlayer.compute.functions.ProductItems;
-import org.jclouds.softlayer.domain.ProductItem;
-import org.jclouds.softlayer.domain.ProductItemPrice;
-import org.jclouds.softlayer.domain.ProductOrder;
-import org.jclouds.softlayer.domain.ProductOrderReceipt;
-import org.jclouds.softlayer.domain.ProductPackage;
+import org.jclouds.softlayer.domain.ContainerVirtualGuestConfiguration;
+import org.jclouds.softlayer.domain.Datacenter;
+import org.jclouds.softlayer.domain.OperatingSystem;
+import org.jclouds.softlayer.domain.TagReference;
import org.jclouds.softlayer.domain.VirtualGuest;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import com.google.common.base.Predicates;
+import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
import com.google.inject.Injector;
-import com.google.inject.Key;
import com.google.inject.Module;
-import com.google.inject.TypeLiteral;
/**
* Tests behavior of {@code VirtualGuestApi}
@@ -55,87 +47,117 @@ import com.google.inject.TypeLiteral;
@Test(groups = "live")
public class VirtualGuestApiLiveTest extends BaseSoftLayerApiLiveTest {
- private static final String TEST_HOSTNAME_PREFIX = "livetest";
+ public static final String DATACENTER = "dal05";
- @Test
- public void testListVirtualGuests() throws Exception {
- Set<VirtualGuest> response = api().listVirtualGuests();
- assert null != response;
- assertTrue(response.size() >= 0);
- for (VirtualGuest vg : response) {
- VirtualGuest newDetails = api().getVirtualGuest(vg.getId());
- assertEquals(vg.getId(), newDetails.getId());
- checkVirtualGuest(vg);
- }
- }
+ private VirtualGuestApi virtualGuestApi;
+ private Predicate<VirtualGuest> loginDetailsTester;
+ private VirtualGuestHasLoginDetailsPresent virtualGuestHasLoginDetailsPresent;
+ private long guestLoginDelay = 60 * 60 * 1000;
- @Test(enabled = false, groups = "live")
- public void testCancelAndPlaceOrder() {
+ private VirtualGuest virtualGuest = null;
- // This method was not working needs testing out.
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ virtualGuestApi = api.getVirtualGuestApi();
+ }
- // TODO: Should also check if there are active transactions before trying to cancel.
- // objectMask: virtualGuests.activeTransaction
- for (VirtualGuest guest : api().listVirtualGuests()) {
- if (guest.getHostname().startsWith(TEST_HOSTNAME_PREFIX)) {
- if (guest.getBillingItemId() != -1) {
- api().cancelService(guest.getBillingItemId());
- }
- }
+ @AfterClass(groups = {"integration", "live"})
+ protected void tearDownContext() {
+ if (virtualGuest != null) {
+ destroyMachine(virtualGuest);
+ virtualGuest = null;
}
+ }
- int pkgId = Iterables.find(api.getAccountApi().getActivePackages(),
- named(ProductPackageApiLiveTest.CLOUD_SERVER_PACKAGE_NAME)).getId();
- ProductPackage productPackage = api.getProductPackageApi().getProductPackage(pkgId);
-
- Iterable<ProductItem> ramItems = Iterables.filter(productPackage.getItems(), Predicates.and(categoryCode("ram"),
- capacity(2.0f)));
-
- Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity());
-
- ProductItemPrice ramPrice = ProductItems.price().apply(ramToProductItem.get(2.0f));
-
- Iterable<ProductItem> cpuItems = Iterables.filter(productPackage.getItems(), Predicates.and(
- units("PRIVATE_CORE"), capacity(2.0f)));
- Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity());
-
- ProductItemPrice cpuPrice = ProductItems.price().apply(coresToProductItem.get(2.0f));
-
- Iterable<ProductItem> operatingSystems = Iterables.filter(productPackage.getItems(), categoryCode("os"));
- Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description());
- ProductItemPrice osPrice = ProductItems.price().apply(
- osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)"));
-
- Builder<ProductItemPrice> prices = ImmutableSet.builder();
- prices.addAll(defaultPrices);
- prices.add(ramPrice);
- prices.add(cpuPrice);
- prices.add(osPrice);
+ @Override
+ protected SoftLayerApi create(Properties props, Iterable<Module> modules) {
+ Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
+ virtualGuestHasLoginDetailsPresent = injector.getInstance(VirtualGuestHasLoginDetailsPresent.class);
+ loginDetailsTester = retry(virtualGuestHasLoginDetailsPresent, guestLoginDelay);
+ return injector.getInstance(SoftLayerApi.class);
+ }
- VirtualGuest guest = VirtualGuest.builder().domain("jclouds.org").hostname(
- TEST_HOSTNAME_PREFIX + new Random().nextInt()).build();
+ @Test
+ public void testGetCreateObjectOptions() {
+ ContainerVirtualGuestConfiguration configurationOption = api().getCreateObjectOptions();
+ assertNotNull(configurationOption);
+ }
- ProductOrder order = ProductOrder.builder().packageId(pkgId).quantity(1).useHourlyPricing(true).prices(
- prices.build()).virtualGuests(guest).build();
+ @Test
+ public void testCreateVirtualGuest() throws Exception {
+ VirtualGuest virtualGuestRequest = VirtualGuest.builder()
+ .domain("jclouds.org")
+ .hostname("virtualGuestApiLiveTest")
+ .startCpus(1)
+ .maxMemory(1024)
+ .operatingSystem(OperatingSystem.builder().id("CENTOS_6_64").operatingSystemReferenceCode("CENTOS_6_64").build())
+ .datacenter(Datacenter.builder().name(DATACENTER).build())
+ .build();
+
+ virtualGuest = virtualGuestApi.createVirtualGuest(virtualGuestRequest);
+ boolean orderInSystem = loginDetailsTester.apply(virtualGuest);
+ checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", virtualGuest,
+ Long.toString(guestLoginDelay));
+ virtualGuest = virtualGuestApi.getVirtualGuest(virtualGuest.getId());
+ checkVirtualGuest(virtualGuest);
+ assertNotNull(virtualGuest.getPrimaryIpAddress(), "primaryIpAddress must be not null");
+ assertNotNull(virtualGuest.getPrimaryBackendIpAddress(), "backendIpAddress must be not null");
+ }
- ProductOrderReceipt receipt = api().orderVirtualGuest(order);
- ProductOrder order2 = receipt.getOrderDetails();
- VirtualGuest result = Iterables.get(order2.getVirtualGuests(), 0);
+ @Test(dependsOnMethods = "testCreateVirtualGuest")
+ public void testGetVirtualGuest() throws Exception {
+ VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId());
+ assertEquals(found, virtualGuest);
+ }
- ProductOrder order3 = api().getOrderTemplate(result.getId());
+ @Test(dependsOnMethods = "testGetVirtualGuest")
+ public void testSetTagsOnVirtualGuest() throws Exception {
+ ImmutableSet<String> tags = ImmutableSet.of("test", "jclouds");
+ assertTrue(virtualGuestApi.setTags(virtualGuest.getId(), tags));
+ VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId());
+ Set<TagReference> tagReferences = found.getTagReferences();
+ assertNotNull(tagReferences);
+ for (String tag : tags) {
+ Iterables.contains(tagReferences, tag);
+ }
+ }
- assertEquals(order.getPrices(), order3.getPrices());
- assertNotNull(receipt);
+ @Test(dependsOnMethods = "testSetTagsOnVirtualGuest")
+ public void testPauseVirtualGuest() throws Exception {
+ virtualGuestApi.pauseVirtualGuest(virtualGuest.getId());
+ checkState(retry(new Predicate<VirtualGuest>() {
+ public boolean apply(VirtualGuest guest) {
+ guest = api().getVirtualGuest(virtualGuest.getId());
+ return guest.getPowerState().getKeyName() == VirtualGuest.State.PAUSED;
+ }
+ }, 5*60*1000).apply(virtualGuest), "%s still not paused!", virtualGuest);
+ VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId());
+ assertTrue(found.getPowerState().getKeyName() == VirtualGuest.State.PAUSED);
}
- private Iterable<ProductItemPrice> defaultPrices;
+ @Test(dependsOnMethods = "testPauseVirtualGuest")
+ public void testResumeVirtualGuest() throws Exception {
+ virtualGuestApi.resumeVirtualGuest(virtualGuest.getId());
+ checkState(retry(new Predicate<VirtualGuest>() {
+ public boolean apply(VirtualGuest guest) {
+ guest = api().getVirtualGuest(virtualGuest.getId());
+ return guest.getPowerState().getKeyName() == VirtualGuest.State.RUNNING;
+ }
+ }, 5*60*1000).apply(virtualGuest), "%s still not running!", virtualGuest);
+ VirtualGuest found = virtualGuestApi.getVirtualGuest(virtualGuest.getId());
+ assertTrue(found.getPowerState().getKeyName() == VirtualGuest.State.RUNNING);
+ }
- @Override
- protected SoftLayerApi create(Properties props, Iterable<Module> modules) {
- Injector injector = newBuilder().modules(modules).overrides(props).buildInjector();
- defaultPrices = injector.getInstance(Key.get(new TypeLiteral<Iterable<ProductItemPrice>>() {
- }));
- return injector.getInstance(SoftLayerApi.class);
+ private void destroyMachine(final VirtualGuest virtualGuest) {
+ checkState(retry(new Predicate<VirtualGuest>() {
+ public boolean apply(VirtualGuest guest) {
+ guest = api().getVirtualGuest(virtualGuest.getId());
+ return guest.getActiveTransactionCount() == 0;
+ }
+ }, 5*60*1000).apply(virtualGuest), "%s still has active transactions!", virtualGuest);
+ assertTrue(api().deleteVirtualGuest(virtualGuest.getId()));
}
private VirtualGuestApi api() {
@@ -143,25 +165,15 @@ public class VirtualGuestApiLiveTest extends BaseSoftLayerApiLiveTest {
}
private void checkVirtualGuest(VirtualGuest vg) {
- if (vg.getBillingItemId() == -1)
- return;// Quotes and shutting down guests
-
- assert vg.getAccountId() > 0 : vg;
- assert vg.getCreateDate() != null : vg;
- assert vg.getDomain() != null : vg;
- assert vg.getFullyQualifiedDomainName() != null : vg;
- assert vg.getHostname() != null : vg;
- assert vg.getId() > 0 : vg;
- assert vg.getMaxCpu() > 0 : vg;
- assert vg.getMaxCpuUnits() != null : vg;
- assert vg.getMaxMemory() > 0 : vg;
- assert vg.getMetricPollDate() != null : vg;
- assert vg.getModifyDate() != null : vg;
- assert vg.getStartCpus() > 0 : vg;
- assert vg.getStatusId() >= 0 : vg;
- assert vg.getUuid() != null : vg;
- assert vg.getPrimaryBackendIpAddress() != null : vg;
- assert vg.getPrimaryIpAddress() != null : vg;
+ if (vg.getActiveTransactionCount() == 0) {
+ assertNotNull(vg.getDomain(), "domain must be not null");
+ assertNotNull(vg.getFullyQualifiedDomainName(), "fullyQualifiedDomainName must be not null");
+ assertNotNull(vg.getHostname(), "hostname must be not null");
+ assertTrue(vg.getId() > 0, "id must be greater than 0");
+ assertTrue(vg.getMaxCpu() > 0, "maxCpu must be greater than 0");
+ assertTrue(vg.getMaxMemory() > 0, "maxMemory must be greater than 0");
+ assertTrue(vg.getStatusId() > 0, "statusId must be greater than 0");
+ }
}
}