Issue 158: undid circular dependency I created

This commit is contained in:
Adrian Cole 2011-09-16 17:53:00 -07:00
parent 89db566131
commit 6ad10cd185
2 changed files with 20 additions and 24 deletions

View File

@ -21,28 +21,28 @@ package org.jclouds.softlayer.compute.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Provider;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.softlayer.domain.Address;
import org.jclouds.softlayer.domain.Datacenter;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
/**
* Converts an Datacenter into a Location.
*/
public class DatacenterToLocation implements Function<Datacenter,Location> {
private final Provider<Supplier<Location>> provider;
private final JustProvider provider;
// allow us to lazy discover the provider of a resource
@Inject
public DatacenterToLocation(Provider<Supplier<Location>> provider) {
public DatacenterToLocation(JustProvider provider) {
this.provider = checkNotNull(provider, "provider");
}
@ -53,7 +53,7 @@ public class DatacenterToLocation implements Function<Datacenter,Location> {
.description(datacenter.getLongName())
.id(Long.toString(datacenter.getId()))
.iso3166Codes(createIso3166Codes(datacenter.getLocationAddress()))
.parent(provider.get().get())
.parent(Iterables.getOnlyElement(provider.get()))
.build();
}

View File

@ -18,43 +18,40 @@
*/
package org.jclouds.softlayer.compute.functions;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import java.net.URI;
import java.util.Set;
import org.jclouds.domain.Location;
import org.jclouds.location.suppliers.JustProvider;
import org.jclouds.softlayer.domain.Address;
import org.jclouds.softlayer.domain.Datacenter;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.google.common.base.Suppliers;
import com.google.inject.util.Providers;
import java.util.Set;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import com.google.common.collect.ImmutableSet;
/**
* Tests {@code DatacenterToLocation}
*
* @author Jason King
*/
@Test(singleThreaded = true,groups = "unit")
@Test(singleThreaded = true, groups = "unit")
public class DatacenterToLocationTest {
private DatacenterToLocation function;
@BeforeMethod
public void setup() {
function = new DatacenterToLocation(Providers.of(Suppliers.ofInstance((Location) null)));
function = new DatacenterToLocation(new JustProvider(ImmutableSet.<String>of(), "softlayer", URI.create("foo")));
}
@Test
public void testDatacenterToLocation() {
Datacenter address = Datacenter.builder().id(1)
.longName("This is Texas!")
.locationAddress(Address.builder()
.country("US")
.state("TX")
.description("This is Texas!").build()).build();
Datacenter address = Datacenter.builder().id(1).longName("This is Texas!").locationAddress(
Address.builder().country("US").state("TX").description("This is Texas!").build()).build();
Location location = function.apply(address);
@ -66,8 +63,7 @@ public class DatacenterToLocationTest {
@Test
public void testGetIso3166CodeNoCountryAndState() {
Datacenter address = Datacenter.builder().id(1)
.longName("Nowhere").build();
Datacenter address = Datacenter.builder().id(1).longName("Nowhere").build();
Location location = function.apply(address);
assertEquals(location.getId(), Long.toString(address.getId()));