mirror of https://github.com/apache/jclouds.git
Issue 158 added Address class and included in api calls. Provides iso3166 code
This commit is contained in:
parent
5d53be270c
commit
43141bcf78
|
@ -0,0 +1,142 @@
|
|||
/**
|
||||
* 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.domain;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jason King
|
||||
* @see <a href= "http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account_Address"
|
||||
* />
|
||||
*/
|
||||
public class Address implements Comparable<Address> {
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private long id = -1;
|
||||
private String country;
|
||||
private String state;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder country(String country) {
|
||||
this.country = country;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(String state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Address build() {
|
||||
return new Address(id, country, state);
|
||||
}
|
||||
|
||||
public static Builder fromAddress(Address in) {
|
||||
return Address.builder().id(in.getId()).country(in.getCountry()).state(in.getState());
|
||||
}
|
||||
}
|
||||
|
||||
private long id = -1;
|
||||
private String country;
|
||||
private String state;
|
||||
|
||||
// for deserializer
|
||||
Address() {
|
||||
|
||||
}
|
||||
|
||||
public Address(long id, String country, String state) {
|
||||
this.id = id;
|
||||
this.country = country;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Address arg0) {
|
||||
return new Long(id).compareTo(arg0.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The unique id of the address.
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The country of the address.
|
||||
*/
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The state of the address.
|
||||
*/
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TThe iso3166 code.
|
||||
* This is a derived value of the form 'country-state'
|
||||
*/
|
||||
public String getIso3166Code() {
|
||||
return ""+country+"-"+state;
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return Builder.fromAddress(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;
|
||||
Address other = (Address) obj;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", country=" + country + ", state=" + state + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -33,6 +33,7 @@ public class Datacenter implements Comparable<Datacenter> {
|
|||
private long id = -1;
|
||||
private String name;
|
||||
private String longName;
|
||||
private Address locationAddress;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
|
@ -49,28 +50,35 @@ public class Datacenter implements Comparable<Datacenter> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder locationAddress(Address locationAddress) {
|
||||
this.locationAddress = locationAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Datacenter build() {
|
||||
return new Datacenter(id, name, longName);
|
||||
return new Datacenter(id, name, longName, locationAddress);
|
||||
}
|
||||
|
||||
public static Builder fromDatacenter(Datacenter in) {
|
||||
return Datacenter.builder().id(in.getId()).name(in.getName()).longName(in.getLongName());
|
||||
return Datacenter.builder().id(in.getId()).name(in.getName()).longName(in.getLongName()).locationAddress(in.getLocationAddress());
|
||||
}
|
||||
}
|
||||
|
||||
private long id = -1;
|
||||
private String name;
|
||||
private String longName;
|
||||
private Address locationAddress;
|
||||
|
||||
// for deserializer
|
||||
Datacenter() {
|
||||
|
||||
}
|
||||
|
||||
public Datacenter(long id, String name, String longName) {
|
||||
public Datacenter(long id, String name, String longName, Address locationAddress) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.longName = longName;
|
||||
this.locationAddress = locationAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -99,6 +107,13 @@ public class Datacenter implements Comparable<Datacenter> {
|
|||
return longName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A location's physical address (optional).
|
||||
*/
|
||||
public Address getLocationAddress() {
|
||||
return locationAddress;
|
||||
}
|
||||
|
||||
public Builder toBuilder() {
|
||||
return Builder.fromDatacenter(this);
|
||||
}
|
||||
|
@ -127,7 +142,7 @@ public class Datacenter implements Comparable<Datacenter> {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[id=" + id + ", name=" + name + ", longName=" + longName + "]";
|
||||
return "[id=" + id + ", country=" + name + ", state=" + longName + "], locationAddress=" + locationAddress + "]";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ import javax.ws.rs.core.MediaType;
|
|||
@RequestFilters(BasicAuthentication.class)
|
||||
@Path("/v{jclouds.api-version}")
|
||||
public interface ProductPackageAsyncClient {
|
||||
public static String PRODUCT_MASK = "items;locations";
|
||||
public static String PRODUCT_MASK = "items;locations.locationAddress";
|
||||
|
||||
/**
|
||||
* @see ProductPackageClient#getProductPackage
|
||||
|
|
|
@ -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.domain;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.AssertJUnit.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests {@code Address}
|
||||
*
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(sequential = true,groups = "unit")
|
||||
public class AddressTest {
|
||||
|
||||
@Test
|
||||
public void testGetIso3166Code() {
|
||||
Address address = Address.builder().id(1).country("US").state("TX").build();
|
||||
assertEquals(address.getIso3166Code(),"US-TX");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetIso3166CodeNullData() {
|
||||
Address address = Address.builder().id(1).build();
|
||||
assertEquals(address.getIso3166Code(),"null-null");
|
||||
}
|
||||
}
|
|
@ -23,6 +23,7 @@ import static org.testng.Assert.assertTrue;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.softlayer.domain.Address;
|
||||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -57,30 +58,44 @@ public class DatacenterClientLiveTest extends BaseSoftLayerClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkDatacenter(Datacenter vg) {
|
||||
assert vg.getId() > 0 : vg;
|
||||
assert vg.getName() != null : vg;
|
||||
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());
|
||||
Builder<Datacenter> builder = ImmutableSet.<Datacenter> builder();
|
||||
builder.add(Datacenter.builder().id(3).name("dal01").longName("Dallas").build());
|
||||
builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build());
|
||||
builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build());
|
||||
builder.add(Datacenter.builder().id(2).name("dal00").longName("Corporate HQ").build());
|
||||
builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build());
|
||||
builder.add(Datacenter.builder().id(154770).name("dal02").longName("Dallas 2").build());
|
||||
builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build());
|
||||
builder.add(Datacenter.builder().id(167093).name("hou01").longName("Houston 1").build());
|
||||
builder.add(Datacenter.builder().id(167094).name("lon01").longName("London 1").build());
|
||||
builder.add(Datacenter.builder().id(167092).name("dal04").longName("Dallas 4").build());
|
||||
builder.add(Datacenter.builder().id(224092).name("sng01").longName("Singapore 1").build());
|
||||
builder.add(Datacenter.builder().id(142775).name("hou02").longName("Houston 2").build());
|
||||
builder.add(Datacenter.builder().id(142776).name("dal07").longName("Dallas 7").build());
|
||||
builder.add(Datacenter.builder().id(154820).name("dal06").longName("Dallas 6").build());
|
||||
Set<Datacenter> response = client.listDatacenters();
|
||||
assertEquals(response.toString(), expected.build().toString());
|
||||
Set<Datacenter> expected = builder.build();
|
||||
|
||||
assertEquals(response.size(),expected.size());
|
||||
assertTrue(response.containsAll(expected));
|
||||
|
||||
for( Datacenter datacenter: response) {
|
||||
Address address = datacenter.getLocationAddress();
|
||||
if(address!=null) checkAddress(address);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDatacenter(Datacenter dc) {
|
||||
assert dc.getId() > 0 : dc;
|
||||
assert dc.getName() != null : dc;
|
||||
assert dc.getLongName() != null : dc;
|
||||
}
|
||||
|
||||
private void checkAddress(Address address) {
|
||||
assert address.getId() >0 : address;
|
||||
assert address.getCountry() != null : address;
|
||||
assert address.getState() != null : address;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ public class ProductPackageAsyncClientTest extends BaseSoftLayerAsyncClientTest<
|
|||
|
||||
assertRequestLineEquals(
|
||||
httpRequest,
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/1234.json?objectMask=items%3Blocations HTTP/1.1");
|
||||
"GET https://api.softlayer.com/rest/v3/SoftLayer_Product_Package/1234.json?objectMask=items%3Blocations.locationAddress HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
|
|
|
@ -23,10 +23,7 @@ import static org.testng.Assert.assertNotNull;
|
|||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.softlayer.domain.Datacenter;
|
||||
import org.jclouds.softlayer.domain.ProductItem;
|
||||
import org.jclouds.softlayer.domain.ProductItemPrice;
|
||||
import org.jclouds.softlayer.domain.ProductPackage;
|
||||
import org.jclouds.softlayer.domain.*;
|
||||
import org.jclouds.softlayer.util.SoftLayerUtils;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -76,28 +73,32 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDatacentersForCloudLayer() {
|
||||
@Test
|
||||
public void testDatacentersForCloudLayer() {
|
||||
|
||||
ImmutableSet.Builder<Datacenter> builder = ImmutableSet.builder();
|
||||
builder.add(Datacenter.builder().id(3).name("dal01").longName("Dallas").build());
|
||||
builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build());
|
||||
builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build());
|
||||
builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build());
|
||||
builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build());
|
||||
ImmutableSet.Builder<Datacenter> builder = ImmutableSet.builder();
|
||||
builder.add(Datacenter.builder().id(3).name("dal01").longName("Dallas").build());
|
||||
builder.add(Datacenter.builder().id(18171).name("sea01").longName("Seattle").build());
|
||||
builder.add(Datacenter.builder().id(37473).name("wdc01").longName("Washington, DC").build());
|
||||
builder.add(Datacenter.builder().id(138124).name("dal05").longName("Dallas 5").build());
|
||||
builder.add(Datacenter.builder().id(168642).name("sjc01").longName("San Jose 1").build());
|
||||
|
||||
Set<Datacenter> expected = builder.build();
|
||||
Set<Datacenter> expected = builder.build();
|
||||
|
||||
Long productPackageId = SoftLayerUtils.getProductPackageId(accountClient,CLOUD_SERVER_PACKAGE_NAME);
|
||||
assertNotNull(productPackageId);
|
||||
|
||||
ProductPackage productPackage = client.getProductPackage(productPackageId);
|
||||
Set<Datacenter> datacenters = productPackage.getDatacenters();
|
||||
assertEquals(datacenters.size(), expected.size());
|
||||
assertTrue(datacenters.containsAll(expected));
|
||||
}
|
||||
Long productPackageId = SoftLayerUtils.getProductPackageId(accountClient,CLOUD_SERVER_PACKAGE_NAME);
|
||||
assertNotNull(productPackageId);
|
||||
|
||||
ProductPackage productPackage = client.getProductPackage(productPackageId);
|
||||
Set<Datacenter> datacenters = productPackage.getDatacenters();
|
||||
assertEquals(datacenters.size(), expected.size());
|
||||
assertTrue(datacenters.containsAll(expected));
|
||||
|
||||
for(Datacenter dataCenter: datacenters) {
|
||||
Address address = dataCenter.getLocationAddress();
|
||||
assertNotNull(address);
|
||||
checkAddress(address);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkProductItem(ProductItem item) {
|
||||
assert item.getId() > 0 : item;
|
||||
|
@ -120,10 +121,15 @@ public class ProductPackageClientLiveTest extends BaseSoftLayerClientLiveTest {
|
|||
assert price.getRecurringFee() != null || price.getHourlyRecurringFee() != null : price;
|
||||
}
|
||||
|
||||
private void checkDatacenter(Datacenter datacenter) {
|
||||
assert datacenter.getId() > 0 : datacenter;
|
||||
assert datacenter.getName() != null : datacenter;
|
||||
assert datacenter.getLongName() != null : datacenter;
|
||||
}
|
||||
private void checkDatacenter(Datacenter datacenter) {
|
||||
assert datacenter.getId() > 0 : datacenter;
|
||||
assert datacenter.getName() != null : datacenter;
|
||||
assert datacenter.getLongName() != null : datacenter;
|
||||
}
|
||||
|
||||
private void checkAddress(Address address) {
|
||||
assert address.getId() >0 : address;
|
||||
assert address.getCountry() != null : address;
|
||||
assert address.getState() != null : address;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue