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/08/02 03:14:10 UTC
[2/3] Remove async from softlayer
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..ccee098
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountApiTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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}
+ *
+ * @author Jason King
+ */
+@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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountAsyncClientTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountAsyncClientTest.java
deleted file mode 100644
index a5ff473..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountAsyncClientTest.java
+++ /dev/null
@@ -1,55 +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 AccountAsyncClient}
- *
- * @author Jason King
- */
-@Test(groups = "unit")
-public class AccountAsyncClientTest extends BaseSoftLayerAsyncClientTest<AccountAsyncClient> {
-
- public void testGetActivePackages() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(AccountAsyncClient.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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java
deleted file mode 100644
index 936c784..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java
+++ /dev/null
@@ -1,47 +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.assertTrue;
-
-import java.util.Set;
-
-import org.jclouds.softlayer.domain.ProductPackage;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code AccountClient}
- *
- * @author Jason King
- */
-@Test(groups = "live")
-public class AccountClientLiveTest extends BaseSoftLayerClientLiveTest {
-
- @Test
- public void testGetActivePackages() {
- Set<ProductPackage> response = api.getAccountClient().getActivePackages();
- assert null != response;
-
- 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());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..3bf529f
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiLiveTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.apis.BaseApiLiveTest;
+import org.jclouds.softlayer.SoftLayerApi;
+import org.testng.annotations.Test;
+
+/**
+ * Tests behavior of {@code SoftLayerApi}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live")
+public class BaseSoftLayerApiLiveTest extends BaseApiLiveTest<SoftLayerApi> {
+
+ public BaseSoftLayerApiLiveTest() {
+ this.provider = "softlayer";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..31da8ffd
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerApiTest.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.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;
+
+/**
+ * @author Adrian Cole
+ */
+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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java
deleted file mode 100644
index bcf103b..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerAsyncClientTest.java
+++ /dev/null
@@ -1,43 +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;
-
-/**
- * @author Adrian Cole
- */
-public abstract class BaseSoftLayerAsyncClientTest<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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java
deleted file mode 100644
index 109a0aa..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/BaseSoftLayerClientLiveTest.java
+++ /dev/null
@@ -1,34 +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 org.jclouds.apis.BaseApiLiveTest;
-import org.jclouds.softlayer.SoftLayerClient;
-import org.testng.annotations.Test;
-
-/**
- * Tests behavior of {@code SoftLayerClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live")
-public class BaseSoftLayerClientLiveTest extends BaseApiLiveTest<SoftLayerClient> {
-
- public BaseSoftLayerClientLiveTest() {
- this.provider = "softlayer";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..ad9df2e
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiLiveTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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 java.util.Set;
+
+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;
+
+/**
+ * Tests behavior of {@code DatacenterApi}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live")
+public class DatacenterApiLiveTest extends BaseSoftLayerApiLiveTest {
+
+ @Test
+ public void testListDatacenters() {
+ Set<Datacenter> response = api().listDatacenters();
+ assert null != response;
+ assertTrue(response.size() >= 0);
+ for (Datacenter vg : response) {
+ Datacenter newDetails = api().getDatacenter(vg.getId());
+ assertEquals(vg.getId(), newDetails.getId());
+ checkDatacenter(newDetails);
+ }
+ }
+
+ @Test
+ 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(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(154820).name("dal06").longName("Dallas 6").build());
+ Set<Datacenter> response = api().listDatacenters();
+ Set<Datacenter> expected = builder.build();
+
+ assertEquals(response.size(),expected.size());
+ assertTrue(response.containsAll(expected));
+
+ for(Datacenter datacenter: response) {
+ Address address = datacenter.getLocationAddress();
+ if(address!=null) checkAddress(address);
+ }
+ }
+
+ private DatacenterApi api() {
+ return api.getDatacenterApi();
+ }
+
+ 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);
+ }
+
+ 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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..7a7a37a
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterApiTest.java
@@ -0,0 +1,85 @@
+/*
+ * 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}
+ *
+ * @author Adrian Cole
+ */
+@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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java
deleted file mode 100644
index fd38c1d..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterAsyncClientTest.java
+++ /dev/null
@@ -1,85 +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 DatacenterAsyncClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "unit")
-public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest<DatacenterAsyncClient> {
-
- public void testListDatacenters() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(DatacenterAsyncClient.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(DatacenterAsyncClient.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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java
deleted file mode 100644
index 438efd1..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/DatacenterClientLiveTest.java
+++ /dev/null
@@ -1,102 +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 static org.testng.Assert.assertTrue;
-
-import java.util.Set;
-
-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;
-
-/**
- * Tests behavior of {@code DatacenterClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live")
-public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest {
-
- @Test
- public void testListDatacenters() {
- Set<Datacenter> response = api().listDatacenters();
- assert null != response;
- assertTrue(response.size() >= 0);
- for (Datacenter vg : response) {
- Datacenter newDetails = api().getDatacenter(vg.getId());
- assertEquals(vg.getId(), newDetails.getId());
- checkDatacenter(newDetails);
- }
- }
-
- @Test
- 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(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(154820).name("dal06").longName("Dallas 6").build());
- Set<Datacenter> response = api().listDatacenters();
- Set<Datacenter> expected = builder.build();
-
- assertEquals(response.size(),expected.size());
- assertTrue(response.containsAll(expected));
-
- for(Datacenter datacenter: response) {
- Address address = datacenter.getLocationAddress();
- if(address!=null) checkAddress(address);
- }
- }
-
- private DatacenterClient api() {
- return api.getDatacenterClient();
- }
-
- 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);
- }
-
- 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;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..90172f1
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiLiveTest.java
@@ -0,0 +1,218 @@
+/*
+ * 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}
+ *
+ * @author Adrian Cole
+ */
+@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/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..196a99e
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageApiTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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}
+ *
+ * @author Adrian Cole
+ */
+@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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageAsyncClientTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageAsyncClientTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageAsyncClientTest.java
deleted file mode 100644
index ed7c354..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageAsyncClientTest.java
+++ /dev/null
@@ -1,55 +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 ProductPackageAsyncClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "unit")
-public class ProductPackageAsyncClientTest extends BaseSoftLayerAsyncClientTest<ProductPackageAsyncClient> {
-
- public void testGetProductPackage() throws SecurityException, NoSuchMethodException, IOException {
- Invokable<?, ?> method = method(ProductPackageAsyncClient.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/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java
deleted file mode 100644
index 7d3dc9c..0000000
--- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/ProductPackageClientLiveTest.java
+++ /dev/null
@@ -1,218 +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 ProductPackageClient}
- *
- * @author Adrian Cole
- */
-@Test(groups = "live", singleThreaded = true, testName = "ProductPackageClientLiveTest")
-public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
-
- /**
- * 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.getProductPackageClient();
- accountClient = api.getAccountClient();
-
- // This is used several times, so cache to speed up the test.
- cloudServerPackageId = Iterables.find(accountClient.getActivePackages(), named(CLOUD_SERVER_PACKAGE_NAME))
- .getId();
- cloudServerProductPackage = client.getProductPackage(cloudServerPackageId);
- }
-
- private ProductPackageClient client;
- private AccountClient accountClient;
-
- private int cloudServerPackageId;
- private ProductPackage cloudServerProductPackage;
-
- @Test
- public void testGetProductPackage() {
- for (ProductPackage productPackage : accountClient.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/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..b35c139
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiExpectTest.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 org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.rest.internal.BaseRestClientExpectTest;
+import org.jclouds.softlayer.SoftLayerApi;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "unit", testName = "SoftLayerClientExpectTest")
+public class VirtualGuestApiExpectTest extends BaseRestClientExpectTest<SoftLayerApi> {
+
+
+ public VirtualGuestApiExpectTest() {
+ provider = "softlayer";
+ }
+
+ 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();
+
+ SoftLayerApi clientWhenServiceExists = requestSendsResponse(cancelGuest11, found);
+
+ assert clientWhenServiceExists.getVirtualGuestApi().cancelService(11l);
+
+
+ HttpResponse notFound = HttpResponse.builder().statusCode(404).build();
+
+ SoftLayerApi clientWhenServiceDoesntExist = requestSendsResponse(cancelGuest11, notFound);
+
+ assert !clientWhenServiceDoesntExist.getVirtualGuestApi().cancelService(11l);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/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
new file mode 100644
index 0000000..fb69a7c
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiLiveTest.java
@@ -0,0 +1,169 @@
+/*
+ * 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.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.VirtualGuest;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicates;
+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}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live")
+public class VirtualGuestApiLiveTest extends BaseSoftLayerApiLiveTest {
+
+ private static final String TEST_HOSTNAME_PREFIX = "livetest";
+
+ @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);
+ }
+ }
+
+ @Test(enabled = false, groups = "live")
+ public void testCancelAndPlaceOrder() {
+
+ // This method was not working needs testing out.
+
+ // 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());
+ }
+ }
+ }
+
+ 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);
+
+ VirtualGuest guest = VirtualGuest.builder().domain("jclouds.org").hostname(
+ TEST_HOSTNAME_PREFIX + new Random().nextInt()).build();
+
+ ProductOrder order = ProductOrder.builder().packageId(pkgId).quantity(1).useHourlyPricing(true).prices(
+ prices.build()).virtualGuests(guest).build();
+
+ ProductOrderReceipt receipt = api().orderVirtualGuest(order);
+ ProductOrder order2 = receipt.getOrderDetails();
+ VirtualGuest result = Iterables.get(order2.getVirtualGuests(), 0);
+
+ ProductOrder order3 = api().getOrderTemplate(result.getId());
+
+ assertEquals(order.getPrices(), order3.getPrices());
+ assertNotNull(receipt);
+ }
+
+ private Iterable<ProductItemPrice> defaultPrices;
+
+ @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 VirtualGuestApi api() {
+ return api.getVirtualGuestApi();
+ }
+
+ 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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiTest.java
----------------------------------------------------------------------
diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiTest.java
new file mode 100644
index 0000000..499c018
--- /dev/null
+++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestApiTest.java
@@ -0,0 +1,175 @@
+/*
+ * 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.Fallbacks.VoidOnNotFoundOr404;
+import org.jclouds.http.functions.ParseJson;
+import org.jclouds.http.functions.ReleasePayloadAndReturn;
+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 VirtualGuestApi}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "unit")
+public class VirtualGuestApiTest extends BaseSoftLayerApiTest<VirtualGuestApi> {
+
+ public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(VirtualGuestApi.class, "listVirtualGuests");
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());
+
+ assertRequestLineEquals(
+ httpRequest,
+ "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=virtualGuests.powerState%3BvirtualGuests.networkVlans%3BvirtualGuests.operatingSystem.passwords%3BvirtualGuests.datacenter%3BvirtualGuests.billingItem 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_Account/VirtualGuests.json?objectMask=virtualGuests.powerState%3BvirtualGuests.networkVlans%3BvirtualGuests.operatingSystem.passwords%3BvirtualGuests.datacenter%3BvirtualGuests.billingItem 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 testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(VirtualGuestApi.class, "getVirtualGuest", long.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
+
+ assertRequestLineEquals(
+ httpRequest,
+ "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem 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);
+
+ }
+
+ public void testRebootHardVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(VirtualGuestApi.class, "rebootHardVirtualGuest", long.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
+
+ assertRequestLineEquals(httpRequest,
+ "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/rebootHard.json HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testPowerOffVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(VirtualGuestApi.class, "powerOffVirtualGuest", long.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
+
+ assertRequestLineEquals(httpRequest,
+ "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOff.json HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testPowerOnVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(VirtualGuestApi.class, "powerOnVirtualGuest", long.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
+
+ assertRequestLineEquals(httpRequest,
+ "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOn.json HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testPauseVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(VirtualGuestApi.class, "pauseVirtualGuest", long.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
+
+ assertRequestLineEquals(httpRequest,
+ "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/pause.json HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+
+ public void testResumeVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
+ Invokable<?, ?> method = method(VirtualGuestApi.class, "resumeVirtualGuest", long.class);
+ GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234));
+
+ assertRequestLineEquals(httpRequest,
+ "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/resume.json HTTP/1.1");
+ assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
+ assertPayloadEquals(httpRequest, null, null, false);
+
+ assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
+ assertSaxResponseParserClassEquals(method, null);
+ assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);
+
+ checkFilters(httpRequest);
+
+ }
+}