mirror of https://github.com/apache/jclouds.git
first working operation in joyent
This commit is contained in:
parent
349d74bfaa
commit
98fb68576a
|
@ -18,9 +18,22 @@
|
|||
*/
|
||||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SkipEncoding;
|
||||
import org.jclouds.rest.functions.ReturnEmptyMapOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Datacenter Services
|
||||
|
@ -30,7 +43,16 @@ import org.jclouds.rest.annotations.SkipEncoding;
|
|||
* @see <a href="http://sdc.joyent.org/sdcapi.html">api doc</a>
|
||||
*/
|
||||
@SkipEncoding( { '/', '=' })
|
||||
@Headers(keys="X-Api-Version", values="{jclouds.api-version}")
|
||||
@RequestFilters(BasicAuthentication.class)
|
||||
public interface DatacenterAsyncClient {
|
||||
|
||||
/**
|
||||
* @see DatacenterClient#getDatacenters
|
||||
*/
|
||||
@GET
|
||||
@Path("/my/datacenters")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptyMapOnNotFoundOr404.class)
|
||||
ListenableFuture<Map<String, URI>> getDatacenters();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
@ -32,4 +34,10 @@ import org.jclouds.concurrent.Timeout;
|
|||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||
public interface DatacenterClient {
|
||||
|
||||
/**
|
||||
* Provides a list of all datacenters this cloud is aware of.
|
||||
*
|
||||
* @return keys are the datacenter name, and the value is the URL.
|
||||
*/
|
||||
Map<String, URI> getDatacenters();
|
||||
}
|
||||
|
|
|
@ -18,13 +18,53 @@
|
|||
*/
|
||||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.joyent.sdc.v6_5.SDCClient;
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "DatacenterClientExpectTest")
|
||||
public class DatacenterClientExpectTest extends BaseSDCClientExpectTest {
|
||||
HttpRequest getDatacenters = HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create("https://api.joyentcloud.com/my/datacenters"))
|
||||
.headers(ImmutableMultimap.<String, String> builder()
|
||||
.put("X-Api-Version", "~6.5")
|
||||
.put("Accept", "application/json")
|
||||
.put("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build())
|
||||
.build();
|
||||
|
||||
public void testGetDatacentersWhenResponseIs2xx() {
|
||||
HttpResponse getDatacentersResponse = HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.payload(payloadFromResource("/datacenters.json")).build();
|
||||
|
||||
SDCClient clientWhenDatacentersExists = requestSendsResponse(getDatacenters, getDatacentersResponse);
|
||||
|
||||
assertEquals(clientWhenDatacentersExists.getDatacenterClient().getDatacenters(),
|
||||
ImmutableMap.<String, URI> builder()
|
||||
.put("us-east-1", URI.create("https://us-east-1.api.joyentcloud.com"))
|
||||
.put("us-west-1", URI.create("https://us-west-1.api.joyentcloud.com"))
|
||||
.put("us-sw-1", URI.create("https://us-sw-1.api.joyentcloud.com"))
|
||||
.put("eu-ams-1", URI.create("https://eu-ams-1.api.joyentcloud.com")).build());
|
||||
}
|
||||
|
||||
public void testGetDatacentersWhenResponseIs404() {
|
||||
HttpResponse getDatacentersResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
SDCClient getDatacentersWhenNone = requestSendsResponse(getDatacenters, getDatacentersResponse);
|
||||
|
||||
assertEquals(getDatacentersWhenNone.getDatacenterClient().getDatacenters(), ImmutableMap.of());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.joyent.sdc.v6_5.features;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientLiveTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -27,4 +33,9 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "live", testName = "DatacenterClientLiveTest")
|
||||
public class DatacenterClientLiveTest extends BaseSDCClientLiveTest {
|
||||
|
||||
public void testGetDatacenters(){
|
||||
Map<String, URI> dcs = sdcContext.getApi().getDatacenterClient().getDatacenters();
|
||||
assertNotNull(dcs);
|
||||
assertTrue(dcs.size() > 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{"us-east-1":"https://us-east-1.api.joyentcloud.com","us-west-1":"https://us-west-1.api.joyentcloud.com","us-sw-1":"https://us-sw-1.api.joyentcloud.com","eu-ams-1":"https://eu-ams-1.api.joyentcloud.com"}
|
Loading…
Reference in New Issue