Issue 158: Added AccountClient and getActivePackages method

This commit is contained in:
Jason King 2011-09-07 18:02:39 +01:00
parent bedfee376a
commit 442782dca3
7 changed files with 245 additions and 0 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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<SoftLayerClient,
.put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)//
.put(DatacenterClient.class, DatacenterAsyncClient.class)//
.put(ProductPackageClient.class, ProductPackageAsyncClient.class)//
.put(AccountClient.class, AccountAsyncClient.class)//
.build();
public SoftLayerRestClientModule() {

View File

@ -0,0 +1,58 @@
/**
* 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.common.util.concurrent.ListenableFuture;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.softlayer.domain.ProductPackage;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import java.util.Set;
/**
* Provides asynchronous access to Account via their REST API.
* <p/>
*
* @see AccountClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @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<Set<ProductPackage>> getActivePackages();
}

View File

@ -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.
* <p/>
*
* @see AccountAsyncClient
* @see <a href="http://sldn.softlayer.com/article/REST" />
* @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<ProductPackage> getActivePackages();
}

View File

@ -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<AccountAsyncClient> {
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<RestAnnotationProcessor<AccountAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<AccountAsyncClient>>() {
};
}
}

View File

@ -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<ProductPackage> 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());
}
}
}