added content test for softlayer

This commit is contained in:
Adrian Cole 2011-09-12 21:56:31 -07:00
parent 0c91e3ae37
commit 508372bbfa
4 changed files with 57 additions and 4 deletions

View File

@ -102,4 +102,33 @@ public class Datacenter implements Comparable<Datacenter> {
public Builder toBuilder() {
return Builder.fromDatacenter(this);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Datacenter other = (Datacenter) obj;
if (id != other.id)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + id + ", name=" + name + ", longName=" + longName + "]";
}
}

View File

@ -53,6 +53,7 @@ public interface DatacenterAsyncClient {
*/
@GET
@Path("/SoftLayer_Location_Datacenter/Datacenters.json")
@QueryParams(keys = "objectMask", values = "locationAddress")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<Set<Datacenter>> listDatacenters();

View File

@ -44,7 +44,7 @@ public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest<Data
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json HTTP/1.1");
"GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json?objectMask=locationAddress HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
@ -53,7 +53,7 @@ public class DatacenterAsyncClientTest extends BaseSoftLayerAsyncClientTest<Data
httpRequest = Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest);
assertRequestLineEquals(httpRequest,
"GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json HTTP/1.1");
"GET https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters.json?objectMask=locationAddress HTTP/1.1");
// for example, using basic authentication, we should get "only one"
// header
assertNonPayloadHeadersEqual(httpRequest,

View File

@ -27,6 +27,9 @@ import org.jclouds.softlayer.domain.Datacenter;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
/**
* Tests behavior of {@code DatacenterClient}
*
@ -43,14 +46,14 @@ public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest {
private DatacenterClient client;
@Test
public void testListDatacenters() throws Exception {
public void testListDatacenters() {
Set<Datacenter> response = client.listDatacenters();
assert null != response;
assertTrue(response.size() >= 0);
for (Datacenter vg : response) {
Datacenter newDetails = client.getDatacenter(vg.getId());
assertEquals(vg.getId(), newDetails.getId());
checkDatacenter(vg);
checkDatacenter(newDetails);
}
}
@ -60,4 +63,24 @@ public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest {
assert vg.getLongName() != null : vg;
}
@Test
public void testListDatacentersContent() {
Builder<Datacenter> expected = ImmutableSet.<Datacenter> builder();
expected.add(Datacenter.builder().id(3).name("dal01").longName("Dallas").build());
expected.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build());
expected.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build());
expected.add(Datacenter.builder().id(2).name("dal00").longName("Corporate HQ").build());
expected.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build());
expected.add(Datacenter.builder().id(154770).name("dal02").longName("Dallas 2").build());
expected.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build());
expected.add(Datacenter.builder().id(167093).name("hou01").longName("Houston 1").build());
expected.add(Datacenter.builder().id(167094).name("lon01").longName("London 1").build());
expected.add(Datacenter.builder().id(167092).name("dal04").longName("Dallas 4").build());
expected.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build());
expected.add(Datacenter.builder().id(142775).name("hou02").longName("Houston 2").build());
expected.add(Datacenter.builder().id(142776).name("dal07").longName("Dallas 7").build());
expected.add(Datacenter.builder().id(154820).name("dal06").longName("Dallas 6").build());
Set<Datacenter> response = client.listDatacenters();
assertEquals(response.toString(), expected.build().toString());
}
}