mirror of https://github.com/apache/jclouds.git
Issue 158: add getProductPackage to softlayer
This commit is contained in:
parent
b577cb8da0
commit
073eba9699
sandbox-providers/softlayer/src
main/java/org/jclouds/softlayer
test/java/org/jclouds/softlayer
|
@ -20,6 +20,7 @@ package org.jclouds.softlayer;
|
|||
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.softlayer.features.DatacenterAsyncClient;
|
||||
import org.jclouds.softlayer.features.ProductPackageAsyncClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
|
||||
|
||||
/**
|
||||
|
@ -43,4 +44,10 @@ public interface SoftLayerAsyncClient {
|
|||
*/
|
||||
@Delegate
|
||||
DatacenterAsyncClient getDatacenterClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to ProductPackage features.
|
||||
*/
|
||||
@Delegate
|
||||
ProductPackageAsyncClient getProductPackageClient();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.softlayer.features.DatacenterClient;
|
||||
import org.jclouds.softlayer.features.ProductPackageClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestClient;
|
||||
|
||||
/**
|
||||
|
@ -47,4 +48,11 @@ public interface SoftLayerClient {
|
|||
*/
|
||||
@Delegate
|
||||
DatacenterClient getDatacenterClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to ProductPackage features.
|
||||
*/
|
||||
@Delegate
|
||||
ProductPackageClient getProductPackageClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ import org.jclouds.softlayer.SoftLayerAsyncClient;
|
|||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
import org.jclouds.softlayer.features.DatacenterAsyncClient;
|
||||
import org.jclouds.softlayer.features.DatacenterClient;
|
||||
import org.jclouds.softlayer.features.ProductPackageAsyncClient;
|
||||
import org.jclouds.softlayer.features.ProductPackageClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestClient;
|
||||
import org.jclouds.softlayer.handlers.SoftLayerErrorHandler;
|
||||
|
@ -53,6 +55,7 @@ public class SoftLayerRestClientModule extends RestClientModule<SoftLayerClient,
|
|||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)//
|
||||
.put(DatacenterClient.class, DatacenterAsyncClient.class)//
|
||||
.put(ProductPackageClient.class, ProductPackageAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public SoftLayerRestClientModule() {
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* 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 javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to ProductPackage via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see ProductPackageClient
|
||||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Path("/v{jclouds.api-version}")
|
||||
public interface ProductPackageAsyncClient {
|
||||
public static String PRODUCT_MASK = "items";
|
||||
|
||||
/**
|
||||
* @see ProductPackageClient#getProductPackage
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Product_Package/{id}.json")
|
||||
@QueryParams(keys = "objectMask", values = PRODUCT_MASK)
|
||||
// @Consumes(MediaType.APPLICATION_JSON)
|
||||
// @ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<String> getProductPackage(@PathParam("id") long id);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* 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 java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to ProductPackage.
|
||||
* <p/>
|
||||
*
|
||||
* @see ProductPackageAsyncClient
|
||||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)
|
||||
public interface ProductPackageClient {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* id of the product package
|
||||
* @return product package or null if not found
|
||||
*/
|
||||
String getProductPackage(long id);
|
||||
|
||||
}
|
|
@ -44,11 +44,13 @@ public class SoftLayerAsyncClientTest extends BaseSoftLayerAsyncClientTest<SoftL
|
|||
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert syncClient.getVirtualGuestClient() != null;
|
||||
assert syncClient.getDatacenterClient() != null;
|
||||
assert syncClient.getProductPackageClient() != null;
|
||||
}
|
||||
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert asyncClient.getVirtualGuestClient() != null;
|
||||
assert asyncClient.getDatacenterClient() != null;
|
||||
assert asyncClient.getProductPackageClient() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* 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 java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.ReturnStringIf2xx;
|
||||
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
Method method = ProductPackageAsyncClient.class.getMethod("getProductPackage", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/1234.json?objectMask=items HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ReturnStringIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<ProductPackageAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<ProductPackageAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* 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.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ProductPackageClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live")
|
||||
public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
client = context.getApi().getProductPackageClient();
|
||||
}
|
||||
|
||||
private ProductPackageClient client;
|
||||
|
||||
@Test
|
||||
public void testGetProductPackage() {
|
||||
client.getProductPackage(46);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue