mirror of https://github.com/apache/jclouds.git
restructured softlayer into separate feature classes
This commit is contained in:
parent
0e18bbeba5
commit
743b94c767
|
@ -154,6 +154,9 @@ swift.propertiesbuilder=org.jclouds.openstack.swift.SwiftPropertiesBuilder
|
|||
cloudstack.contextbuilder=org.jclouds.cloudstack.CloudStackContextBuilder
|
||||
cloudstack.propertiesbuilder=org.jclouds.cloudstack.CloudStackPropertiesBuilder
|
||||
|
||||
softlayer.contextbuilder=org.jclouds.softlayer.SoftLayerContextBuilder
|
||||
softlayer.propertiesbuilder=org.jclouds.softlayer.SoftLayerPropertiesBuilder
|
||||
|
||||
cloudfiles-us.contextbuilder=org.jclouds.cloudfiles.CloudFilesContextBuilder
|
||||
cloudfiles-us.propertiesbuilder=org.jclouds.rackspace.cloudfiles.CloudFilesUSPropertiesBuilder
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -19,22 +19,8 @@
|
|||
|
||||
package org.jclouds.softlayer;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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 org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.softlayer.features.VirtualGuestAsyncClient;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to SoftLayer via their REST API.
|
||||
|
@ -44,25 +30,12 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Path("/v{jclouds.api-version}")
|
||||
public interface SoftLayerAsyncClient {
|
||||
|
||||
/**
|
||||
* @see SoftLayerClient#listVirtualGuests
|
||||
* Provides asynchronous access to VirtualGuest features.
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Account/VirtualGuests.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<VirtualGuest>> listVirtualGuests();
|
||||
@Delegate
|
||||
VirtualGuestAsyncClient getVirtualGuestClient();
|
||||
|
||||
/**
|
||||
* @see SoftLayerClient#getVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/SoftLayer_Virtual_Guest/{id}.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<VirtualGuest> getVirtualGuest(@PathParam("id") long id);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -19,11 +19,11 @@
|
|||
|
||||
package org.jclouds.softlayer;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.softlayer.features.VirtualGuestClient;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to SoftLayer.
|
||||
|
@ -33,21 +33,13 @@ import org.jclouds.softlayer.domain.VirtualGuest;
|
|||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface SoftLayerClient {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an account's associated virtual guest objects.
|
||||
* Provides synchronous access to VirtualGuest features.
|
||||
*/
|
||||
Set<VirtualGuest> listVirtualGuests();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* id of the virtual guest
|
||||
* @return virtual guest or null if not found
|
||||
*/
|
||||
VirtualGuest getVirtualGuest(long id);
|
||||
@Delegate
|
||||
VirtualGuestClient getVirtualGuestClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ package org.jclouds.softlayer;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.softlayer.config.SoftLayerRestClientModule;
|
||||
import org.jclouds.rest.RestContextBuilder;
|
||||
import org.jclouds.softlayer.config.SoftLayerRestClientModule;
|
||||
|
||||
import com.google.inject.Module;
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.jclouds.softlayer.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.HttpErrorHandler;
|
||||
import org.jclouds.http.HttpRetryHandler;
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
|
@ -32,8 +34,12 @@ 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.VirtualGuestAsyncClient;
|
||||
import org.jclouds.softlayer.features.VirtualGuestClient;
|
||||
import org.jclouds.softlayer.handlers.SoftLayerErrorHandler;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
/**
|
||||
* Configures the SoftLayer connection.
|
||||
*
|
||||
|
@ -43,8 +49,12 @@ import org.jclouds.softlayer.handlers.SoftLayerErrorHandler;
|
|||
@ConfiguresRestClient
|
||||
public class SoftLayerRestClientModule extends RestClientModule<SoftLayerClient, SoftLayerAsyncClient> {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
|
||||
.put(VirtualGuestClient.class, VirtualGuestAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public SoftLayerRestClientModule() {
|
||||
super(SoftLayerClient.class, SoftLayerAsyncClient.class);
|
||||
super(SoftLayerClient.class, SoftLayerAsyncClient.class, DELEGATE_MAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.Set;
|
||||
|
||||
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 org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to VirtualGuest via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see VirtualGuestClient
|
||||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
@Path("/v{jclouds.api-version}")
|
||||
public interface VirtualGuestAsyncClient {
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#listVirtualGuests
|
||||
*/
|
||||
@GET
|
||||
@Path("/VirtualGuest_Account/VirtualGuests.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<VirtualGuest>> listVirtualGuests();
|
||||
|
||||
/**
|
||||
* @see VirtualGuestClient#getVirtualGuest
|
||||
*/
|
||||
@GET
|
||||
@Path("/VirtualGuest_Virtual_Guest/{id}.json")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<VirtualGuest> getVirtualGuest(@PathParam("id") long id);
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to VirtualGuest.
|
||||
* <p/>
|
||||
*
|
||||
* @see VirtualGuestAsyncClient
|
||||
* @see <a href="http://sldn.softlayer.com/wiki/index.php/REST" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS)
|
||||
public interface VirtualGuestClient {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return an account's associated virtual guest objects.
|
||||
*/
|
||||
Set<VirtualGuest> listVirtualGuests();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
* id of the virtual guest
|
||||
* @return virtual guest or null if not found
|
||||
*/
|
||||
VirtualGuest getVirtualGuest(long id);
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -19,83 +19,35 @@
|
|||
|
||||
package org.jclouds.softlayer;
|
||||
|
||||
import static org.jclouds.rest.RestContextFactory.contextSpec;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.http.functions.ParseJson;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.softlayer.features.BaseSoftLayerAsyncClientTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code SoftLayerAsyncClient}
|
||||
* Tests behavior of {@code SoftLayerAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class SoftLayerAsyncClientTest extends RestClientTest<SoftLayerAsyncClient> {
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "SoftLayerAsyncClientTest")
|
||||
public class SoftLayerAsyncClientTest extends BaseSoftLayerAsyncClientTest<SoftLayerAsyncClient> {
|
||||
|
||||
public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SoftLayerAsyncClient.class.getMethod("listVirtualGuests");
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// now make sure request filters apply by replaying
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json 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);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
private SoftLayerAsyncClient asyncClient;
|
||||
private SoftLayerClient syncClient;
|
||||
|
||||
public void testSync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert syncClient.getVirtualGuestClient() != null;
|
||||
}
|
||||
|
||||
public void testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SoftLayerAsyncClient.class.getMethod("getVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.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 void checkFilters(HttpRequest request) {
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
assert asyncClient.getVirtualGuestClient() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -104,9 +56,16 @@ public class SoftLayerAsyncClientTest extends RestClientTest<SoftLayerAsyncClien
|
|||
};
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@Override
|
||||
public RestContextSpec<SoftLayerClient, SoftLayerAsyncClient> createContextSpec() {
|
||||
return contextSpec("softlayer", "https://api.softlayer.com/rest", "3", "", "identity", "credential",
|
||||
SoftLayerClient.class, SoftLayerAsyncClient.class);
|
||||
protected void setupFactory() throws IOException {
|
||||
super.setupFactory();
|
||||
asyncClient = injector.getInstance(SoftLayerAsyncClient.class);
|
||||
syncClient = injector.getInstance(SoftLayerClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 java.util.Properties;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
||||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public abstract class BaseSoftLayerAsyncClientTest<T> extends RestClientTest<T> {
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
assertEquals(request.getFilters().size(), 1);
|
||||
assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestContextSpec<SoftLayerClient, SoftLayerAsyncClient> createContextSpec() {
|
||||
Properties props = new Properties();
|
||||
return new RestContextFactory().createContextSpec("softlayer", "apiKey", "secretKey", props);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.softlayer.SoftLayerAsyncClient;
|
||||
import org.jclouds.softlayer.SoftLayerClient;
|
||||
import org.jclouds.softlayer.SoftLayerContextBuilder;
|
||||
import org.jclouds.softlayer.SoftLayerPropertiesBuilder;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SoftLayerClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live")
|
||||
public class BaseSoftLayerClientLiveTest {
|
||||
|
||||
protected RestContext<SoftLayerClient, SoftLayerAsyncClient> context;
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity");
|
||||
String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential");
|
||||
|
||||
Properties restProperties = new Properties();
|
||||
restProperties.setProperty("softlayer.contextbuilder", SoftLayerContextBuilder.class.getName());
|
||||
restProperties.setProperty("softlayer.propertiesbuilder", SoftLayerPropertiesBuilder.class.getName());
|
||||
|
||||
context = new RestContextFactory(restProperties).createContext("softlayer", identity, credential,
|
||||
ImmutableSet.<Module> of(new Log4JLoggingModule()));
|
||||
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.ParseJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests annotation parsing of {@code VirtualGuestAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<VirtualGuestAsyncClient> {
|
||||
|
||||
public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualGuestAsyncClient.class.getMethod("listVirtualGuests");
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/VirtualGuest_Account/VirtualGuests.json HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
// now make sure request filters apply by replaying
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/VirtualGuest_Account/VirtualGuests.json HTTP/1.1");
|
||||
// for example, using basic authentication, we should get "only one"
|
||||
// header
|
||||
assertNonPayloadHeadersEqual(httpRequest,
|
||||
"Accept: application/json\nAuthorization: Basic YXBpS2V5OnNlY3JldEtleQ==\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, ParseJson.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VirtualGuestAsyncClient.class.getMethod("getVirtualGuest", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 1234);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/VirtualGuest_Virtual_Guest/1234.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<VirtualGuestAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<VirtualGuestAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -17,57 +17,31 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.softlayer;
|
||||
package org.jclouds.softlayer.features;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SoftLayerClient}
|
||||
* Tests behavior of {@code VirtualGuestClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live")
|
||||
public class SoftLayerClientLiveTest {
|
||||
|
||||
private SoftLayerClient client;
|
||||
private RestContext<SoftLayerClient, SoftLayerAsyncClient> context;
|
||||
|
||||
public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest {
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupClient() {
|
||||
String identity = checkNotNull(System.getProperty("test.softlayer.identity"), "test.softlayer.identity");
|
||||
String credential = checkNotNull(System.getProperty("test.softlayer.credential"), "test.softlayer.credential");
|
||||
|
||||
Properties restProperties = new Properties();
|
||||
restProperties.setProperty("softlayer.contextbuilder", SoftLayerContextBuilder.class.getName());
|
||||
restProperties.setProperty("softlayer.propertiesbuilder", SoftLayerPropertiesBuilder.class.getName());
|
||||
|
||||
context = new RestContextFactory(restProperties).createContext("softlayer", identity, credential, ImmutableSet
|
||||
.<Module> of(new Log4JLoggingModule()));
|
||||
|
||||
client = context.getApi();
|
||||
super.setupClient();
|
||||
client = context.getApi().getVirtualGuestClient();
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
void tearDown() {
|
||||
if (context != null)
|
||||
context.close();
|
||||
}
|
||||
private VirtualGuestClient client;
|
||||
|
||||
@Test
|
||||
public void testListVirtualGuests() throws Exception {
|
Loading…
Reference in New Issue