diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java index bdb3fdf273..b1e022b6a2 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerAsyncClient.java @@ -19,6 +19,7 @@ package org.jclouds.softlayer; import org.jclouds.rest.annotations.Delegate; +import org.jclouds.softlayer.features.AccountAsyncClient; import org.jclouds.softlayer.features.DatacenterAsyncClient; import org.jclouds.softlayer.features.ProductPackageAsyncClient; import org.jclouds.softlayer.features.VirtualGuestAsyncClient; @@ -50,4 +51,10 @@ public interface SoftLayerAsyncClient { */ @Delegate ProductPackageAsyncClient getProductPackageClient(); + + /** + * Provides asynchronous access to Account features. + */ + @Delegate + AccountAsyncClient getAccountClient(); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java index 362784d7d5..adc64ec552 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/SoftLayerClient.java @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; +import org.jclouds.softlayer.features.AccountClient; import org.jclouds.softlayer.features.DatacenterClient; import org.jclouds.softlayer.features.ProductPackageClient; import org.jclouds.softlayer.features.VirtualGuestClient; @@ -55,4 +56,9 @@ public interface SoftLayerClient { @Delegate ProductPackageClient getProductPackageClient(); + /** + * Provides synchronous access to Account features. + */ + @Delegate + AccountClient getAccountClient(); } diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java index a4a209efb3..6133465f02 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/config/SoftLayerRestClientModule.java @@ -33,6 +33,8 @@ import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.config.RestClientModule; import org.jclouds.softlayer.SoftLayerAsyncClient; import org.jclouds.softlayer.SoftLayerClient; +import org.jclouds.softlayer.features.AccountAsyncClient; +import org.jclouds.softlayer.features.AccountClient; import org.jclouds.softlayer.features.DatacenterAsyncClient; import org.jclouds.softlayer.features.DatacenterClient; import org.jclouds.softlayer.features.ProductPackageAsyncClient; @@ -56,6 +58,7 @@ public class SoftLayerRestClientModule extends RestClientModule + * + * @see AccountClient + * @see + * @author Jason King + */ +@RequestFilters(BasicAuthentication.class) +@Path("/v{jclouds.api-version}") +public interface AccountAsyncClient { + + /** + * @see AccountClient#getActivePackages() + */ + @GET + @Path("/SoftLayer_Account/ActivePackages.json") + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getActivePackages(); + + +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/AccountClient.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/AccountClient.java new file mode 100644 index 0000000000..301fe41c44 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/features/AccountClient.java @@ -0,0 +1,50 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.features; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.softlayer.domain.ProductPackage; + +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * Provides synchronous access to Account. + *

+ * + * @see AccountAsyncClient + * @see + * @author Jason King + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface AccountClient { + + /** + * + * @return Gets all the active packages. + * This will give you a basic description of the packages that are currently + * active and from which you can order a server or additional services. + * + * Calling ProductPackage.getItems() will return an empty set. + * Use ProductPackageClient.getProductPackage(long id) to obtain items data. + * @see ProductPackageClient#getProductPackage + */ + Set getActivePackages(); + +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountAsyncClientTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountAsyncClientTest.java new file mode 100644 index 0000000000..020d144dff --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountAsyncClientTest.java @@ -0,0 +1,62 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.features; + +import com.google.inject.TypeLiteral; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.functions.ParseJson; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.lang.reflect.Method; + +/** + * Tests annotation parsing of {@code AccountAsyncClient} + * + * @author Jason King + */ +@Test(groups = "unit") +public class AccountAsyncClientTest extends BaseSoftLayerAsyncClientTest { + + public void testGetActivePackages() throws SecurityException, NoSuchMethodException, IOException { + Method method = AccountAsyncClient.class.getMethod("getActivePackages"); + HttpRequest httpRequest = processor.createRequest(method); + + 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); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(httpRequest); + + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } +} diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java new file mode 100644 index 0000000000..3cfa7815c4 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/features/AccountClientLiveTest.java @@ -0,0 +1,59 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.features; + +import org.jclouds.softlayer.domain.ProductItem; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.ProductPackage; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import java.util.Set; + +import static org.testng.Assert.assertTrue; + +/** + * Tests behavior of {@code AccountClient} + * + * @author Jason King + */ +@Test(groups = "live") +public class AccountClientLiveTest extends BaseSoftLayerClientLiveTest { + @BeforeGroups(groups = { "live" }) + public void setupClient() { + super.setupClient(); + client = context.getApi().getAccountClient(); + } + + private AccountClient client; + + @Test + public void testGetActivePackages() { + Set response = client.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()); + } + } +}