Applied fixes suggested in last review

Renamed VirtualMachineTemplateWithZone to
VirtualMachineTemplateInVirtualDatacenter and encoded the id using a
slash instead of the hyphen.
This commit is contained in:
Ignasi Barrera 2012-10-21 22:44:24 +02:00
parent 26f801058d
commit e9502ab81e
7 changed files with 67 additions and 61 deletions

View File

@ -22,14 +22,14 @@ package org.jclouds.abiquo.compute.config;
import org.jclouds.abiquo.compute.functions.DatacenterToLocation; import org.jclouds.abiquo.compute.functions.DatacenterToLocation;
import org.jclouds.abiquo.compute.functions.VirtualDatacenterToLocation; import org.jclouds.abiquo.compute.functions.VirtualDatacenterToLocation;
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToImage; import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateToImage;
import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateWithZoneToHardware; import org.jclouds.abiquo.compute.functions.VirtualMachineTemplateInVirtualDatacenterToHardware;
import org.jclouds.abiquo.compute.functions.VirtualMachineToNodeMetadata; import org.jclouds.abiquo.compute.functions.VirtualMachineToNodeMetadata;
import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions; import org.jclouds.abiquo.compute.options.AbiquoTemplateOptions;
import org.jclouds.abiquo.compute.strategy.AbiquoComputeServiceAdapter; import org.jclouds.abiquo.compute.strategy.AbiquoComputeServiceAdapter;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine; import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.ComputeServiceAdapter;
import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
@ -52,7 +52,7 @@ import com.google.inject.TypeLiteral;
*/ */
public class AbiquoComputeServiceContextModule public class AbiquoComputeServiceContextModule
extends extends
ComputeServiceAdapterContextModule<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter> ComputeServiceAdapterContextModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>
{ {
@Override @Override
@ -60,7 +60,7 @@ public class AbiquoComputeServiceContextModule
{ {
super.configure(); super.configure();
bind( bind(
new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter>>() new TypeLiteral<ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>>()
{ {
}).to(AbiquoComputeServiceAdapter.class); }).to(AbiquoComputeServiceAdapter.class);
bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>() bind(new TypeLiteral<Function<VirtualMachine, NodeMetadata>>()
@ -69,9 +69,9 @@ public class AbiquoComputeServiceContextModule
bind(new TypeLiteral<Function<VirtualMachineTemplate, Image>>() bind(new TypeLiteral<Function<VirtualMachineTemplate, Image>>()
{ {
}).to(VirtualMachineTemplateToImage.class); }).to(VirtualMachineTemplateToImage.class);
bind(new TypeLiteral<Function<VirtualMachineTemplateWithZone, Hardware>>() bind(new TypeLiteral<Function<VirtualMachineTemplateInVirtualDatacenter, Hardware>>()
{ {
}).to(VirtualMachineTemplateWithZoneToHardware.class); }).to(VirtualMachineTemplateInVirtualDatacenterToHardware.class);
bind(new TypeLiteral<Function<Datacenter, Location>>() bind(new TypeLiteral<Function<Datacenter, Location>>()
{ {
}).to(DatacenterToLocation.class); }).to(DatacenterToLocation.class);
@ -80,7 +80,7 @@ public class AbiquoComputeServiceContextModule
}).to(VirtualDatacenterToLocation.class); }).to(VirtualDatacenterToLocation.class);
bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON); bind(ImplicitLocationSupplier.class).to(OnlyLocationOrFirstZone.class).in(Scopes.SINGLETON);
bind(TemplateOptions.class).to(AbiquoTemplateOptions.class); bind(TemplateOptions.class).to(AbiquoTemplateOptions.class);
install(new LocationsFromComputeServiceAdapterModule<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter>() install(new LocationsFromComputeServiceAdapterModule<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>()
{ {
}); });
} }

View File

@ -26,7 +26,7 @@ import javax.inject.Singleton;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.HardwareBuilder; import org.jclouds.compute.domain.HardwareBuilder;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
@ -47,8 +47,8 @@ import com.google.common.base.Function;
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
@Singleton @Singleton
public class VirtualMachineTemplateWithZoneToHardware implements public class VirtualMachineTemplateInVirtualDatacenterToHardware implements
Function<VirtualMachineTemplateWithZone, Hardware> Function<VirtualMachineTemplateInVirtualDatacenter, Hardware>
{ {
/** The default core speed, 2.0Ghz. */ /** The default core speed, 2.0Ghz. */
public static final double DEFAULT_CORE_SPEED = 2.0; public static final double DEFAULT_CORE_SPEED = 2.0;
@ -56,7 +56,7 @@ public class VirtualMachineTemplateWithZoneToHardware implements
private final Function<VirtualDatacenter, Location> virtualDatacenterToLocation; private final Function<VirtualDatacenter, Location> virtualDatacenterToLocation;
@Inject @Inject
public VirtualMachineTemplateWithZoneToHardware( public VirtualMachineTemplateInVirtualDatacenterToHardware(
final Function<VirtualDatacenter, Location> virtualDatacenterToLocation) final Function<VirtualDatacenter, Location> virtualDatacenterToLocation)
{ {
this.virtualDatacenterToLocation = this.virtualDatacenterToLocation =
@ -64,14 +64,15 @@ public class VirtualMachineTemplateWithZoneToHardware implements
} }
@Override @Override
public Hardware apply(final VirtualMachineTemplateWithZone templateWithZone) public Hardware apply(
final VirtualMachineTemplateInVirtualDatacenter templateInVirtualDatacenter)
{ {
VirtualMachineTemplate template = templateWithZone.getTemplate(); VirtualMachineTemplate template = templateInVirtualDatacenter.getTemplate();
VirtualDatacenter zone = templateWithZone.getZone(); VirtualDatacenter virtualDatacenter = templateInVirtualDatacenter.getZone();
HardwareBuilder builder = new HardwareBuilder(); HardwareBuilder builder = new HardwareBuilder();
builder.providerId(template.getId().toString()); builder.providerId(template.getId().toString());
builder.id(template.getId().toString() + "-" + zone.getId()); builder.id(template.getId().toString() + "/" + virtualDatacenter.getId());
builder.uri(template.getURI()); builder.uri(template.getURI());
builder.name(template.getName()); builder.name(template.getName());
@ -79,8 +80,8 @@ public class VirtualMachineTemplateWithZoneToHardware implements
builder.ram(template.getRamRequired()); builder.ram(template.getRamRequired());
// Location information // Location information
builder.location(virtualDatacenterToLocation.apply(zone)); builder.location(virtualDatacenterToLocation.apply(virtualDatacenter));
builder.hypervisor(zone.getHypervisorType().name()); builder.hypervisor(virtualDatacenter.getHypervisorType().name());
builder.supportsImage(ImagePredicates.idEquals(template.getId().toString())); builder.supportsImage(ImagePredicates.idEquals(template.getId().toString()));
VolumeBuilder volumeBuilder = new VolumeBuilder(); VolumeBuilder volumeBuilder = new VolumeBuilder();

View File

@ -32,7 +32,7 @@ import javax.inject.Singleton;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine; import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.network.Ip; import org.jclouds.abiquo.domain.network.Ip;
import org.jclouds.abiquo.domain.network.PrivateIp; import org.jclouds.abiquo.domain.network.PrivateIp;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
@ -62,7 +62,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
private final VirtualMachineTemplateToImage virtualMachineTemplateToImage; private final VirtualMachineTemplateToImage virtualMachineTemplateToImage;
private final VirtualMachineTemplateWithZoneToHardware virtualMachineTemplateToHardware; private final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware;
private final VirtualMachineStateToNodeState virtualMachineStateToNodeState; private final VirtualMachineStateToNodeState virtualMachineStateToNodeState;
@ -71,7 +71,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
@Inject @Inject
public VirtualMachineToNodeMetadata( public VirtualMachineToNodeMetadata(
final VirtualMachineTemplateToImage virtualMachineTemplateToImage, final VirtualMachineTemplateToImage virtualMachineTemplateToImage,
final VirtualMachineTemplateWithZoneToHardware virtualMachineTemplateToHardware, final VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware,
final VirtualMachineStateToNodeState virtualMachineStateToNodeState, final VirtualMachineStateToNodeState virtualMachineStateToNodeState,
final Function<VirtualDatacenter, Location> virtualDatacenterToLocation) final Function<VirtualDatacenter, Location> virtualDatacenterToLocation)
{ {
@ -110,7 +110,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
// Hardware details // Hardware details
Hardware defaultHardware = Hardware defaultHardware =
virtualMachineTemplateToHardware virtualMachineTemplateToHardware
.apply(new VirtualMachineTemplateWithZone(template, vdc)); .apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
Hardware hardware = Hardware hardware =
HardwareBuilder HardwareBuilder
@ -118,7 +118,7 @@ public class VirtualMachineToNodeMetadata implements Function<VirtualMachine, No
.ram(vm.getRam()) .ram(vm.getRam())
.processors( .processors(
Lists.newArrayList(new Processor(vm.getCpu(), Lists.newArrayList(new Processor(vm.getCpu(),
VirtualMachineTemplateWithZoneToHardware.DEFAULT_CORE_SPEED))) // VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED))) //
.build(); .build();
builder.hardware(hardware); builder.hardware(hardware);

View File

@ -37,7 +37,7 @@ import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine; import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.enterprise.Enterprise; import org.jclouds.abiquo.domain.enterprise.Enterprise;
import org.jclouds.abiquo.domain.infrastructure.Datacenter; import org.jclouds.abiquo.domain.infrastructure.Datacenter;
import org.jclouds.abiquo.domain.network.PublicIp; import org.jclouds.abiquo.domain.network.PublicIp;
@ -74,7 +74,7 @@ import com.google.inject.Inject;
@Singleton @Singleton
public class AbiquoComputeServiceAdapter public class AbiquoComputeServiceAdapter
implements implements
ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateWithZone, VirtualMachineTemplate, VirtualDatacenter> ComputeServiceAdapter<VirtualMachine, VirtualMachineTemplateInVirtualDatacenter, VirtualMachineTemplate, VirtualDatacenter>
{ {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
@ -168,29 +168,29 @@ public class AbiquoComputeServiceAdapter
} }
@Override @Override
public Iterable<VirtualMachineTemplateWithZone> listHardwareProfiles() public Iterable<VirtualMachineTemplateInVirtualDatacenter> listHardwareProfiles()
{ {
// In Abiquo, images are scoped to a region (physical datacenter), and hardware profiles are // In Abiquo, images are scoped to a region (physical datacenter), and hardware profiles are
// scoped to a zone (a virtual datacenter in the region, with a concrete virtualization // scoped to a zone (a virtual datacenter in the region, with a concrete virtualization
// technology) // technology)
return concat(transform(listImages(), return concat(transform(listImages(),
new Function<VirtualMachineTemplate, Iterable<VirtualMachineTemplateWithZone>>() new Function<VirtualMachineTemplate, Iterable<VirtualMachineTemplateInVirtualDatacenter>>()
{ {
@Override @Override
public Iterable<VirtualMachineTemplateWithZone> apply( public Iterable<VirtualMachineTemplateInVirtualDatacenter> apply(
final VirtualMachineTemplate template) final VirtualMachineTemplate template)
{ {
Iterable<VirtualDatacenter> compatibleZones = Iterable<VirtualDatacenter> compatibleZones =
compatibleVirtualDatacenters.execute(template); compatibleVirtualDatacenters.execute(template);
return transform(compatibleZones, return transform(compatibleZones,
new Function<VirtualDatacenter, VirtualMachineTemplateWithZone>() new Function<VirtualDatacenter, VirtualMachineTemplateInVirtualDatacenter>()
{ {
@Override @Override
public VirtualMachineTemplateWithZone apply(final VirtualDatacenter vdc) public VirtualMachineTemplateInVirtualDatacenter apply(final VirtualDatacenter vdc)
{ {
return new VirtualMachineTemplateWithZone(template, vdc); return new VirtualMachineTemplateInVirtualDatacenter(template, vdc);
} }
}); });
} }

View File

@ -26,13 +26,13 @@ import static com.google.common.base.Preconditions.checkNotNull;
* *
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
public class VirtualMachineTemplateWithZone public class VirtualMachineTemplateInVirtualDatacenter
{ {
private VirtualMachineTemplate template; private VirtualMachineTemplate template;
private VirtualDatacenter zone; private VirtualDatacenter zone;
public VirtualMachineTemplateWithZone(final VirtualMachineTemplate template, public VirtualMachineTemplateInVirtualDatacenter(final VirtualMachineTemplate template,
final VirtualDatacenter zone) final VirtualDatacenter zone)
{ {
super(); super();

View File

@ -34,7 +34,7 @@ import org.jclouds.abiquo.AbiquoApi;
import org.jclouds.abiquo.AbiquoAsyncApi; import org.jclouds.abiquo.AbiquoAsyncApi;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Volume; import org.jclouds.compute.domain.Volume;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
@ -48,20 +48,20 @@ import com.abiquo.server.core.cloud.VirtualDatacenterDto;
import com.google.common.base.Function; import com.google.common.base.Function;
/** /**
* Unit tests for the {@link VirtualMachineTemplateWithZoneToHardware} function. * Unit tests for the {@link VirtualMachineTemplateInVirtualDatacenterToHardware} function.
* *
* @author Ignasi Barrera * @author Ignasi Barrera
*/ */
@Test(groups = "unit", testName = "VirtualMachineTemplateToHardwareTest") @Test(groups = "unit", testName = "VirtualMachineTemplateInVirtualDatacenterToHardwareTest")
public class VirtualMachineTemplateWithZoneToHardwareTest public class VirtualMachineTemplateInVirtualDatacenterToHardwareTest
{ {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testVirtualMachineTemplateToHardware() public void testVirtualMachineTemplateToHardware()
{ {
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class); RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function = VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation); new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5); dto.setId(5);
@ -78,12 +78,13 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04); vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto); VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc)); Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation); verify(vdcToLocation);
assertEquals(hardware.getProviderId(), template.getId().toString()); assertEquals(hardware.getProviderId(), template.getId().toString());
assertEquals(hardware.getId(), template.getId() + "-" + vdc.getId()); assertEquals(hardware.getId(), template.getId() + "/" + vdc.getId());
assertEquals(hardware.getName(), template.getName()); assertEquals(hardware.getName(), template.getName());
assertEquals(hardware.getUri(), URI.create("http://foo/bar")); assertEquals(hardware.getUri(), URI.create("http://foo/bar"));
@ -91,7 +92,7 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
assertEquals(hardware.getProcessors().size(), 1); assertEquals(hardware.getProcessors().size(), 1);
assertEquals(hardware.getProcessors().get(0).getCores(), (double) template.getCpuRequired()); assertEquals(hardware.getProcessors().get(0).getCores(), (double) template.getCpuRequired());
assertEquals(hardware.getProcessors().get(0).getSpeed(), assertEquals(hardware.getProcessors().get(0).getSpeed(),
VirtualMachineTemplateWithZoneToHardware.DEFAULT_CORE_SPEED); VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED);
assertEquals(hardware.getVolumes().size(), 1); assertEquals(hardware.getVolumes().size(), 1);
assertEquals(hardware.getVolumes().get(0).getSize(), 50F); assertEquals(hardware.getVolumes().get(0).getSize(), 50F);
@ -105,8 +106,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{ {
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class); RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function = VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation); new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5); dto.setId(5);
@ -122,7 +123,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04); vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto); VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc)); Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation); verify(vdcToLocation);
@ -135,14 +137,14 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{ {
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class); RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function = VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation); new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplate template = VirtualMachineTemplate template =
wrap(context, VirtualMachineTemplate.class, new VirtualMachineTemplateDto()); wrap(context, VirtualMachineTemplate.class, new VirtualMachineTemplateDto());
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, new VirtualDatacenterDto()); VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, new VirtualDatacenterDto());
function.apply(new VirtualMachineTemplateWithZone(template, vdc)); function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -150,8 +152,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{ {
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class); RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function = VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation); new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5); dto.setId(5);
@ -166,7 +168,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04); vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto); VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc)); Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation); verify(vdcToLocation);
@ -179,8 +182,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{ {
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class); RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function = VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation); new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
dto.setId(5); dto.setId(5);
@ -195,7 +198,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04); vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto); VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc)); Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation); verify(vdcToLocation);
@ -207,8 +211,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
{ {
RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class); RestContext<AbiquoApi, AbiquoAsyncApi> context = EasyMock.createMock(RestContext.class);
Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation();
VirtualMachineTemplateWithZoneToHardware function = VirtualMachineTemplateInVirtualDatacenterToHardware function =
new VirtualMachineTemplateWithZoneToHardware(vdcToLocation); new VirtualMachineTemplateInVirtualDatacenterToHardware(vdcToLocation);
// VirtualMachineTemplate domain object does not have a builder, it is read only // VirtualMachineTemplate domain object does not have a builder, it is read only
VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto();
@ -224,7 +228,8 @@ public class VirtualMachineTemplateWithZoneToHardwareTest
vdcDto.setHypervisorType(HypervisorType.VMX_04); vdcDto.setHypervisorType(HypervisorType.VMX_04);
VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto); VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto);
Hardware hardware = function.apply(new VirtualMachineTemplateWithZone(template, vdc)); Hardware hardware =
function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc));
verify(vdcToLocation); verify(vdcToLocation);

View File

@ -33,7 +33,7 @@ import org.jclouds.abiquo.domain.cloud.VirtualAppliance;
import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; import org.jclouds.abiquo.domain.cloud.VirtualDatacenter;
import org.jclouds.abiquo.domain.cloud.VirtualMachine; import org.jclouds.abiquo.domain.cloud.VirtualMachine;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate;
import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateWithZone; import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter;
import org.jclouds.abiquo.domain.network.ExternalIp; import org.jclouds.abiquo.domain.network.ExternalIp;
import org.jclouds.abiquo.domain.network.Ip; import org.jclouds.abiquo.domain.network.Ip;
import org.jclouds.abiquo.domain.network.PrivateIp; import org.jclouds.abiquo.domain.network.PrivateIp;
@ -157,13 +157,13 @@ public class VirtualMachineToNodeMetadataTest
return templateToImage; return templateToImage;
} }
private VirtualMachineTemplateWithZoneToHardware templateToHardware() private VirtualMachineTemplateInVirtualDatacenterToHardware templateToHardware()
{ {
VirtualMachineTemplateWithZoneToHardware virtualMachineTemplateToHardware = VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware =
EasyMock.createMock(VirtualMachineTemplateWithZoneToHardware.class); EasyMock.createMock(VirtualMachineTemplateInVirtualDatacenterToHardware.class);
expect( expect(
virtualMachineTemplateToHardware.apply(anyObject(VirtualMachineTemplateWithZone.class))) virtualMachineTemplateToHardware.apply(anyObject(VirtualMachineTemplateInVirtualDatacenter.class)))
.andReturn(hardware); .andReturn(hardware);
replay(virtualMachineTemplateToHardware); replay(virtualMachineTemplateToHardware);