mirror of https://github.com/apache/jclouds.git
Issue 871: only providers can have null parent
This commit is contained in:
parent
41daa057d8
commit
75071831f9
|
@ -80,8 +80,10 @@ import com.google.common.collect.ImmutableSet;
|
||||||
* @author Oleksiy Yarmula
|
* @author Oleksiy Yarmula
|
||||||
*/
|
*/
|
||||||
public class EC2TemplateBuilderTest {
|
public class EC2TemplateBuilderTest {
|
||||||
private static final Location location = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
|
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build();
|
||||||
.description("us-east-1").build();
|
|
||||||
|
protected Location location = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description("us-east-1")
|
||||||
|
.parent(provider).build();
|
||||||
|
|
||||||
public static final Hardware CC1_4XLARGE = cc1_4xlarge().supportsImageIds(ImmutableSet.of("us-east-1/cc-image"))
|
public static final Hardware CC1_4XLARGE = cc1_4xlarge().supportsImageIds(ImmutableSet.of("us-east-1/cc-image"))
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.ec2.compute.internal;
|
package org.jclouds.ec2.compute.internal;
|
||||||
|
|
||||||
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.classextension.EasyMock.createMock;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.classextension.EasyMock.replay;
|
import static org.easymock.EasyMock.verify;
|
||||||
import static org.easymock.classextension.EasyMock.verify;
|
|
||||||
import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
import static org.jclouds.ec2.compute.domain.EC2HardwareBuilder.c1_medium;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
@ -39,8 +39,6 @@ import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
|
||||||
import org.jclouds.compute.domain.internal.TemplateBuilderImplTest;
|
import org.jclouds.compute.domain.internal.TemplateBuilderImplTest;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.domain.LocationBuilder;
|
|
||||||
import org.jclouds.domain.LocationScope;
|
|
||||||
import org.jclouds.ec2.compute.domain.RegionAndName;
|
import org.jclouds.ec2.compute.domain.RegionAndName;
|
||||||
import org.jclouds.ec2.compute.functions.ImagesToRegionAndIdMap;
|
import org.jclouds.ec2.compute.functions.ImagesToRegionAndIdMap;
|
||||||
import org.jclouds.ec2.compute.options.EC2TemplateOptions;
|
import org.jclouds.ec2.compute.options.EC2TemplateOptions;
|
||||||
|
@ -49,9 +47,9 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.base.Functions;
|
import com.google.common.base.Functions;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.common.cache.LoadingCache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
@ -104,10 +102,9 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testParseOnDemand() {
|
public void testParseOnDemand() {
|
||||||
Location location = new LocationBuilder().scope(LocationScope.REGION).id("region").description("region").build();
|
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(location));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(Sets
|
||||||
.<Image> newLinkedHashSet());
|
.<Image> newLinkedHashSet());
|
||||||
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -121,8 +118,8 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
||||||
expect(knownImage.getId()).andReturn("region/ami").atLeastOnce();
|
expect(knownImage.getId()).andReturn("us-east-1/ami").atLeastOnce();
|
||||||
expect(knownImage.getLocation()).andReturn(location).atLeastOnce();
|
expect(knownImage.getLocation()).andReturn(region).atLeastOnce();
|
||||||
expect(knownImage.getName()).andReturn(null).atLeastOnce();
|
expect(knownImage.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(knownImage.getDescription()).andReturn(null).atLeastOnce();
|
expect(knownImage.getDescription()).andReturn(null).atLeastOnce();
|
||||||
expect(knownImage.getVersion()).andReturn(null).atLeastOnce();
|
expect(knownImage.getVersion()).andReturn(null).atLeastOnce();
|
||||||
|
@ -143,10 +140,10 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location,
|
TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.imageId("region/ami").build().getImage(), knownImage);
|
assertEquals(template.imageId("us-east-1/ami").build().getImage(), knownImage);
|
||||||
|
|
||||||
verify(knownImage);
|
verify(knownImage);
|
||||||
verify(os);
|
verify(os);
|
||||||
|
@ -158,10 +155,9 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testParseOnDemandWithoutRegionEncodedIntoId() {
|
public void testParseOnDemandWithoutRegionEncodedIntoId() {
|
||||||
Location location = new LocationBuilder().scope(LocationScope.REGION).id("region").description("region").build();
|
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(location));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
|
||||||
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
.<Hardware> of(c1_medium().build()));
|
.<Hardware> of(c1_medium().build()));
|
||||||
|
@ -172,7 +168,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
Image knownImage = createMock(Image.class);
|
Image knownImage = createMock(Image.class);
|
||||||
expect(knownImage.getId()).andReturn("region/ami").anyTimes();
|
expect(knownImage.getId()).andReturn("region/ami").anyTimes();
|
||||||
expect(knownImage.getProviderId()).andReturn("ami").anyTimes();
|
expect(knownImage.getProviderId()).andReturn("ami").anyTimes();
|
||||||
expect(knownImage.getLocation()).andReturn(location).anyTimes();
|
expect(knownImage.getLocation()).andReturn(region).anyTimes();
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
||||||
|
@ -181,7 +177,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, location,
|
TemplateBuilderImpl template = createTemplateBuilder(knownImage, locations, images, sizes, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
try {
|
try {
|
||||||
template.imageId("ami").build();
|
template.imageId("ami").build();
|
||||||
|
@ -198,10 +194,9 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test(expectedExceptions = NoSuchElementException.class)
|
@Test(expectedExceptions = NoSuchElementException.class)
|
||||||
public void testParseOnDemandNotFound() {
|
public void testParseOnDemandNotFound() {
|
||||||
Location location = new LocationBuilder().scope(LocationScope.REGION).id("region").description("region").build();
|
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(location));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of());
|
||||||
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
.<Hardware> of(c1_medium().build()));
|
.<Hardware> of(c1_medium().build()));
|
||||||
|
@ -213,7 +208,7 @@ public class EC2TemplateBuilderImplTest extends TemplateBuilderImplTest {
|
||||||
Image knownImage = createMock(Image.class);
|
Image knownImage = createMock(Image.class);
|
||||||
expect(knownImage.getId()).andReturn("region/ami").anyTimes();
|
expect(knownImage.getId()).andReturn("region/ami").anyTimes();
|
||||||
expect(knownImage.getProviderId()).andReturn("ami").anyTimes();
|
expect(knownImage.getProviderId()).andReturn("ami").anyTimes();
|
||||||
expect(knownImage.getLocation()).andReturn(location).anyTimes();
|
expect(knownImage.getLocation()).andReturn(region).anyTimes();
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("region");
|
expect(defaultLocation.getId()).andReturn("region");
|
||||||
expect(optionsProvider.get()).andReturn(defaultOptions);
|
expect(optionsProvider.get()).andReturn(defaultOptions);
|
||||||
|
|
|
@ -17,9 +17,11 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.jclouds.compute.domain.internal;
|
package org.jclouds.compute.domain.internal;
|
||||||
|
import static com.google.common.base.Preconditions.*;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.ComputeMetadata;
|
import org.jclouds.compute.domain.ComputeMetadata;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.domain.LocationScope;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
@ -29,7 +31,7 @@ import com.google.common.base.Supplier;
|
||||||
*
|
*
|
||||||
* If the input location is null, then the data isn't location sensitive
|
* If the input location is null, then the data isn't location sensitive
|
||||||
*
|
*
|
||||||
* If the input location is a parent of the specified location, then we are ok.
|
* If the input location equals, is a parent or grandparent of the specified location, then we are ok.
|
||||||
*/
|
*/
|
||||||
public class LocationPredicate implements Predicate<ComputeMetadata> {
|
public class LocationPredicate implements Predicate<ComputeMetadata> {
|
||||||
private final Supplier<Location> locationSupplier;
|
private final Supplier<Location> locationSupplier;
|
||||||
|
@ -41,12 +43,28 @@ public class LocationPredicate implements Predicate<ComputeMetadata> {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(ComputeMetadata input) {
|
public boolean apply(ComputeMetadata input) {
|
||||||
Location location = locationSupplier.get();
|
Location location = locationSupplier.get();
|
||||||
boolean returnVal = true;
|
if (location == null)
|
||||||
if (location != null && input.getLocation() != null)
|
return true;
|
||||||
returnVal = location.equals(input.getLocation()) || location.getParent() != null
|
|
||||||
|
if (location.equals(input.getLocation()))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
checkArgument(
|
||||||
|
location.getParent() != null || location.getScope() == LocationScope.PROVIDER,
|
||||||
|
"only locations of scope PROVIDER can have a null parent; arg: %s",
|
||||||
|
location);
|
||||||
|
|
||||||
|
if (input.getLocation() == null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
checkState(
|
||||||
|
input.getLocation().getParent() != null || input.getLocation().getScope() == LocationScope.PROVIDER,
|
||||||
|
"only locations of scope PROVIDER can have a null parent; input: %s",
|
||||||
|
input.getLocation());
|
||||||
|
|
||||||
|
return location.equals(input.getLocation()) || location.getParent() != null
|
||||||
&& location.getParent().equals(input.getLocation()) || location.getParent().getParent() != null
|
&& location.getParent().equals(input.getLocation()) || location.getParent().getParent() != null
|
||||||
&& location.getParent().getParent().equals(input.getLocation());
|
&& location.getParent().getParent().equals(input.getLocation());
|
||||||
return returnVal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -150,32 +150,12 @@ public class LocationPredicateTest {
|
||||||
Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build();
|
Hardware md = new HardwareBuilder().id("foo").location(otherRegion).build();
|
||||||
assertFalse(predicate.apply(md));
|
assertFalse(predicate.apply(md));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* a provider is not an assignable location.
|
|
||||||
*
|
|
||||||
* For example, all cloud providers to date, vms are assigned to zones or
|
|
||||||
* regions, and listAssignableLocations does not include elements of PROVIDER scope.
|
|
||||||
* <p/>
|
|
||||||
*
|
|
||||||
* If someone somehow gets a hold of a provider instance, this should throw an IllegalArgumentException.
|
|
||||||
* Asking to assign this to a provider, is not the correct syntax for
|
|
||||||
*
|
|
||||||
* FIXME: this should not NPE,
|
|
||||||
*/
|
|
||||||
@Test(enabled = false, expectedExceptions = IllegalArgumentException.class)
|
|
||||||
public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAProviderAndInputLocationAsOpposedToNull() {
|
|
||||||
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(provider));
|
|
||||||
Hardware md = new HardwareBuilder().id("foo").location(region).build();
|
|
||||||
predicate.apply(md);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
||||||
*
|
*
|
||||||
* FIXME: this should not NPE,
|
|
||||||
*/
|
*/
|
||||||
@Test(enabled = false, expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedRegion() {
|
public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedRegion() {
|
||||||
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region));
|
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region));
|
||||||
Hardware md = new HardwareBuilder().id("foo").location(orphanedRegion).build();
|
Hardware md = new HardwareBuilder().id("foo").location(orphanedRegion).build();
|
||||||
|
@ -185,9 +165,8 @@ public class LocationPredicateTest {
|
||||||
/**
|
/**
|
||||||
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
||||||
*
|
*
|
||||||
* FIXME: this should not NPE,
|
|
||||||
*/
|
*/
|
||||||
@Test(enabled = false, expectedExceptions = IllegalStateException.class)
|
@Test(expectedExceptions = IllegalStateException.class)
|
||||||
public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedZone() {
|
public void testThrowIllegalStateExceptionWhenInputIsAnOrphanedZone() {
|
||||||
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region));
|
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(region));
|
||||||
Hardware md = new HardwareBuilder().id("foo").location(orphanedZone).build();
|
Hardware md = new HardwareBuilder().id("foo").location(orphanedZone).build();
|
||||||
|
@ -197,9 +176,8 @@ public class LocationPredicateTest {
|
||||||
/**
|
/**
|
||||||
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
||||||
*
|
*
|
||||||
* FIXME: this should not NPE,
|
|
||||||
*/
|
*/
|
||||||
@Test(enabled = false, expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedRegion() {
|
public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedRegion() {
|
||||||
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(orphanedRegion));
|
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(orphanedRegion));
|
||||||
Hardware md = new HardwareBuilder().id("foo").location(region).build();
|
Hardware md = new HardwareBuilder().id("foo").location(region).build();
|
||||||
|
@ -209,9 +187,8 @@ public class LocationPredicateTest {
|
||||||
/**
|
/**
|
||||||
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
* Only the PROVIDER scope should have a null parent, It is an illegal state if a ZONE or REGION are orphaned
|
||||||
*
|
*
|
||||||
* FIXME: this should not NPE,
|
|
||||||
*/
|
*/
|
||||||
@Test(enabled = false, expectedExceptions = IllegalArgumentException.class)
|
@Test(expectedExceptions = IllegalArgumentException.class)
|
||||||
public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedZone() {
|
public void testThrowIllegalArgumentExceptionWhenWhenISpecifyAnOrphanedZone() {
|
||||||
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(orphanedZone));
|
LocationPredicate predicate = new LocationPredicate(Suppliers.ofInstance(orphanedZone));
|
||||||
Hardware md = new HardwareBuilder().id("foo").location(region).build();
|
Hardware md = new HardwareBuilder().id("foo").location(region).build();
|
||||||
|
|
|
@ -42,6 +42,7 @@ import org.jclouds.compute.domain.Volume;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
import org.jclouds.compute.options.TemplateOptions;
|
||||||
import org.jclouds.compute.predicates.ImagePredicates;
|
import org.jclouds.compute.predicates.ImagePredicates;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
|
import org.jclouds.domain.LocationBuilder;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -56,17 +57,20 @@ import com.google.common.collect.ImmutableSet;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", singleThreaded = true)
|
@Test(groups = "unit", singleThreaded = true)
|
||||||
public class TemplateBuilderImplTest {
|
public class TemplateBuilderImplTest {
|
||||||
|
Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("aws-ec2").description("aws-ec2").build();
|
||||||
|
|
||||||
|
protected Location region = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description("us-east-1")
|
||||||
|
.parent(provider).build();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testLocationPredicateWhenComputeMetadataIsNotLocationBound() {
|
public void testLocationPredicateWhenComputeMetadataIsNotLocationBound() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
|
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId").build();
|
Hardware hardware = new HardwareBuilder().id("hardwareId").build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
|
||||||
image));
|
image));
|
||||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -75,25 +79,22 @@ public class TemplateBuilderImplTest {
|
||||||
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
Provider<TemplateBuilder> templateBuilderProvider = createMock(Provider.class);
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
|
||||||
expect(image.getLocation()).andReturn(defaultLocation).anyTimes();
|
expect(image.getLocation()).andReturn(region).anyTimes();
|
||||||
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
||||||
expect(defaultLocation.getId()).andReturn("location").anyTimes();
|
|
||||||
|
|
||||||
replay(image);
|
replay(image);
|
||||||
replay(os);
|
replay(os);
|
||||||
replay(defaultTemplate);
|
replay(defaultTemplate);
|
||||||
replay(defaultLocation);
|
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, defaultLocation,
|
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
assert template.locationPredicate.apply(hardware);
|
assert template.locationPredicate.apply(hardware);
|
||||||
|
|
||||||
verify(image);
|
verify(image);
|
||||||
verify(os);
|
verify(os);
|
||||||
verify(defaultTemplate);
|
verify(defaultTemplate);
|
||||||
verify(defaultLocation);
|
|
||||||
verify(optionsProvider);
|
verify(optionsProvider);
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +102,6 @@ public class TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testResolveImages() {
|
public void testResolveImages() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
Image image2 = createMock(Image.class);
|
Image image2 = createMock(Image.class);
|
||||||
|
@ -110,7 +110,7 @@ public class TemplateBuilderImplTest {
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId").build();
|
Hardware hardware = new HardwareBuilder().id("hardwareId").build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
|
||||||
image, image2));
|
image, image2));
|
||||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -127,8 +127,8 @@ public class TemplateBuilderImplTest {
|
||||||
expect(image2.getVersion()).andReturn("imageVersion");
|
expect(image2.getVersion()).andReturn("imageVersion");
|
||||||
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
||||||
expect(image2.getOperatingSystem()).andReturn(os2).atLeastOnce();
|
expect(image2.getOperatingSystem()).andReturn(os2).atLeastOnce();
|
||||||
expect(image.getLocation()).andReturn(defaultLocation).anyTimes();
|
expect(image.getLocation()).andReturn(region).anyTimes();
|
||||||
expect(image2.getLocation()).andReturn(defaultLocation).anyTimes();
|
expect(image2.getLocation()).andReturn(region).anyTimes();
|
||||||
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
||||||
expect(image2.getProviderId()).andReturn("imageId2").anyTimes();
|
expect(image2.getProviderId()).andReturn("imageId2").anyTimes();
|
||||||
expect(os.getName()).andReturn("osName");
|
expect(os.getName()).andReturn("osName");
|
||||||
|
@ -139,18 +139,16 @@ public class TemplateBuilderImplTest {
|
||||||
expect(os2.getDescription()).andReturn("osDescription");
|
expect(os2.getDescription()).andReturn("osDescription");
|
||||||
expect(os.getArch()).andReturn("X86_64").atLeastOnce();
|
expect(os.getArch()).andReturn("X86_64").atLeastOnce();
|
||||||
expect(os2.getArch()).andReturn("X86_64").atLeastOnce();
|
expect(os2.getArch()).andReturn("X86_64").atLeastOnce();
|
||||||
expect(defaultLocation.getId()).andReturn("location").anyTimes();
|
|
||||||
|
|
||||||
replay(image);
|
replay(image);
|
||||||
replay(image2);
|
replay(image2);
|
||||||
replay(os);
|
replay(os);
|
||||||
replay(os2);
|
replay(os2);
|
||||||
replay(defaultTemplate);
|
replay(defaultTemplate);
|
||||||
replay(defaultLocation);
|
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, defaultLocation,
|
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.resolveImage(hardware, images.get()), image2);
|
assertEquals(template.resolveImage(hardware, images.get()), image2);
|
||||||
|
@ -160,7 +158,6 @@ public class TemplateBuilderImplTest {
|
||||||
verify(os);
|
verify(os);
|
||||||
verify(os2);
|
verify(os2);
|
||||||
verify(defaultTemplate);
|
verify(defaultTemplate);
|
||||||
verify(defaultLocation);
|
|
||||||
verify(optionsProvider);
|
verify(optionsProvider);
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
@ -168,7 +165,6 @@ public class TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testArchWins() {
|
public void testArchWins() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
Image image2 = createMock(Image.class);
|
Image image2 = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
|
@ -177,7 +173,7 @@ public class TemplateBuilderImplTest {
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId").build();
|
Hardware hardware = new HardwareBuilder().id("hardwareId").build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of(
|
||||||
image, image2));
|
image, image2));
|
||||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -188,13 +184,12 @@ public class TemplateBuilderImplTest {
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("myregion").anyTimes();
|
|
||||||
|
|
||||||
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
expect(image.getLocation()).andReturn(region).atLeastOnce();
|
||||||
expect(image2.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
expect(image2.getLocation()).andReturn(region).atLeastOnce();
|
||||||
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
||||||
expect(image2.getOperatingSystem()).andReturn(os2).atLeastOnce();
|
expect(image2.getOperatingSystem()).andReturn(os2).atLeastOnce();
|
||||||
expect(image.getId()).andReturn("myregion/1").atLeastOnce();
|
expect(image.getId()).andReturn("us-east-1/1").atLeastOnce();
|
||||||
expect(image.getProviderId()).andReturn("1").anyTimes();
|
expect(image.getProviderId()).andReturn("1").anyTimes();
|
||||||
expect(image2.getProviderId()).andReturn("2").anyTimes();
|
expect(image2.getProviderId()).andReturn("2").anyTimes();
|
||||||
|
|
||||||
|
@ -206,11 +201,10 @@ public class TemplateBuilderImplTest {
|
||||||
replay(os);
|
replay(os);
|
||||||
replay(os2);
|
replay(os2);
|
||||||
replay(defaultTemplate);
|
replay(defaultTemplate);
|
||||||
replay(defaultLocation);
|
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, defaultLocation,
|
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.smallest().osArchMatches("X86_32").build().getImage(), image);
|
assertEquals(template.smallest().osArchMatches("X86_32").build().getImage(), image);
|
||||||
|
@ -220,7 +214,6 @@ public class TemplateBuilderImplTest {
|
||||||
verify(os);
|
verify(os);
|
||||||
verify(os2);
|
verify(os2);
|
||||||
verify(defaultTemplate);
|
verify(defaultTemplate);
|
||||||
verify(defaultLocation);
|
|
||||||
verify(optionsProvider);
|
verify(optionsProvider);
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
@ -228,15 +221,14 @@ public class TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testHardwareWithImageIdPredicateOnlyAcceptsImage() {
|
public void testHardwareWithImageIdPredicateOnlyAcceptsImage() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
|
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("myregion/imageId"))
|
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("us-east-1/imageId"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||||
.<Image> of(image));
|
.<Image> of(image));
|
||||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -246,15 +238,14 @@ public class TemplateBuilderImplTest {
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||||
expect(image.getId()).andReturn("myregion/imageId").atLeastOnce();
|
expect(image.getId()).andReturn("us-east-1/imageId").atLeastOnce();
|
||||||
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
expect(image.getLocation()).andReturn(region).atLeastOnce();
|
||||||
expect(image.getName()).andReturn(null).atLeastOnce();
|
expect(image.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getVersion()).andReturn(null).atLeastOnce();
|
expect(image.getVersion()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
||||||
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("myregion").anyTimes();
|
|
||||||
|
|
||||||
expect(os.getName()).andReturn(null).atLeastOnce();
|
expect(os.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(os.getVersion()).andReturn(null).atLeastOnce();
|
expect(os.getVersion()).andReturn(null).atLeastOnce();
|
||||||
|
@ -263,24 +254,21 @@ public class TemplateBuilderImplTest {
|
||||||
expect(os.getArch()).andReturn(null).atLeastOnce();
|
expect(os.getArch()).andReturn(null).atLeastOnce();
|
||||||
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
||||||
|
|
||||||
expect(defaultLocation.getScope()).andReturn(LocationScope.PROVIDER).atLeastOnce();
|
|
||||||
|
|
||||||
replay(image);
|
replay(image);
|
||||||
replay(os);
|
replay(os);
|
||||||
replay(defaultTemplate);
|
replay(defaultTemplate);
|
||||||
replay(defaultLocation);
|
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, defaultLocation,
|
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
template.imageId("myregion/imageId").build();
|
template.imageId("us-east-1/imageId").build();
|
||||||
|
|
||||||
verify(image);
|
verify(image);
|
||||||
verify(os);
|
verify(os);
|
||||||
verify(defaultTemplate);
|
verify(defaultTemplate);
|
||||||
verify(defaultLocation);
|
|
||||||
verify(optionsProvider);
|
verify(optionsProvider);
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
@ -288,15 +276,14 @@ public class TemplateBuilderImplTest {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testHardwareWithImageIdPredicateOnlyAcceptsImageWhenLocationNull() {
|
public void testHardwareWithImageIdPredicateOnlyAcceptsImageWhenLocationNull() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
|
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("myregion/imageId"))
|
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("us-east-1/imageId"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||||
.<Image> of(image));
|
.<Image> of(image));
|
||||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -306,7 +293,7 @@ public class TemplateBuilderImplTest {
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||||
expect(image.getId()).andReturn("myregion/imageId").atLeastOnce();
|
expect(image.getId()).andReturn("us-east-1/imageId").atLeastOnce();
|
||||||
expect(image.getLocation()).andReturn(null).atLeastOnce();
|
expect(image.getLocation()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getName()).andReturn(null).atLeastOnce();
|
expect(image.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
||||||
|
@ -314,8 +301,6 @@ public class TemplateBuilderImplTest {
|
||||||
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
||||||
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("myregion").anyTimes();
|
|
||||||
|
|
||||||
expect(os.getName()).andReturn(null).atLeastOnce();
|
expect(os.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(os.getVersion()).andReturn(null).atLeastOnce();
|
expect(os.getVersion()).andReturn(null).atLeastOnce();
|
||||||
expect(os.getFamily()).andReturn(null).atLeastOnce();
|
expect(os.getFamily()).andReturn(null).atLeastOnce();
|
||||||
|
@ -323,21 +308,20 @@ public class TemplateBuilderImplTest {
|
||||||
expect(os.getArch()).andReturn(null).atLeastOnce();
|
expect(os.getArch()).andReturn(null).atLeastOnce();
|
||||||
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
||||||
|
|
||||||
replay(image, os, defaultTemplate, defaultLocation, optionsProvider, templateBuilderProvider);
|
replay(image, os, defaultTemplate, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, defaultLocation,
|
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
template.imageId("myregion/imageId").build();
|
template.imageId("us-east-1/imageId").build();
|
||||||
|
|
||||||
verify(image, os, defaultTemplate, defaultLocation, optionsProvider, templateBuilderProvider);
|
verify(image, os, defaultTemplate, optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testHardwareWithImageIdPredicateOnlyDoesntImage() {
|
public void testHardwareWithImageIdPredicateOnlyDoesntImage() {
|
||||||
Location defaultLocation = createMock(Location.class);
|
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
OperatingSystem os = createMock(OperatingSystem.class);
|
OperatingSystem os = createMock(OperatingSystem.class);
|
||||||
|
|
||||||
|
@ -345,7 +329,7 @@ public class TemplateBuilderImplTest {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||||
.<Image> of(image));
|
.<Image> of(image));
|
||||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -355,15 +339,14 @@ public class TemplateBuilderImplTest {
|
||||||
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
TemplateBuilder defaultTemplate = createMock(TemplateBuilder.class);
|
||||||
|
|
||||||
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
expect(optionsProvider.get()).andReturn(new TemplateOptions());
|
||||||
expect(image.getId()).andReturn("myregion/imageId").atLeastOnce();
|
expect(image.getId()).andReturn("us-east-1/imageId").atLeastOnce();
|
||||||
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
expect(image.getLocation()).andReturn(region).atLeastOnce();
|
||||||
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
||||||
expect(image.getName()).andReturn(null).atLeastOnce();
|
expect(image.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getVersion()).andReturn(null).atLeastOnce();
|
expect(image.getVersion()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
expect(image.getProviderId()).andReturn("imageId").anyTimes();
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("myregion").anyTimes();
|
|
||||||
|
|
||||||
expect(os.getName()).andReturn(null).atLeastOnce();
|
expect(os.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(os.getVersion()).andReturn(null).atLeastOnce();
|
expect(os.getVersion()).andReturn(null).atLeastOnce();
|
||||||
|
@ -372,29 +355,25 @@ public class TemplateBuilderImplTest {
|
||||||
expect(os.getArch()).andReturn(null).atLeastOnce();
|
expect(os.getArch()).andReturn(null).atLeastOnce();
|
||||||
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
||||||
|
|
||||||
expect(defaultLocation.getScope()).andReturn(LocationScope.PROVIDER).atLeastOnce();
|
|
||||||
|
|
||||||
replay(image);
|
replay(image);
|
||||||
replay(os);
|
replay(os);
|
||||||
replay(defaultTemplate);
|
replay(defaultTemplate);
|
||||||
replay(defaultLocation);
|
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(image, locations, images, hardwares, defaultLocation,
|
TemplateBuilderImpl template = createTemplateBuilder(image, locations, images, hardwares, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
try {
|
try {
|
||||||
template.imageId("myregion/imageId").build();
|
template.imageId("us-east-1/imageId").build();
|
||||||
assert false;
|
assert false;
|
||||||
} catch (NoSuchElementException e) {
|
} catch (NoSuchElementException e) {
|
||||||
// make sure big data is not in the exception message
|
// make sure big data is not in the exception message
|
||||||
assertEquals(
|
assertEquals(
|
||||||
e.getMessage(),
|
e.getMessage(),
|
||||||
"no hardware profiles support images matching params: [biggest=false, fastest=false, imageName=null, imageDescription=null, imageId=myregion/imageId, imagePredicate=null, imageVersion=null, location=EasyMock for interface org.jclouds.domain.Location, minCores=0.0, minRam=0, osFamily=null, osName=null, osDescription=null, osVersion=null, osArch=null, os64Bit=false, hardwareId=null, hypervisor=null]");
|
"no hardware profiles support images matching params: [biggest=false, fastest=false, imageName=null, imageDescription=null, imageId=us-east-1/imageId, imagePredicate=null, imageVersion=null, location=[id=us-east-1, scope=REGION, description=us-east-1, parent=aws-ec2, iso3166Codes=[], metadata={}], minCores=0.0, minRam=0, osFamily=null, osName=null, osDescription=null, osVersion=null, osArch=null, os64Bit=false, hardwareId=null, hypervisor=null]");
|
||||||
verify(image);
|
verify(image);
|
||||||
verify(os);
|
verify(os);
|
||||||
verify(defaultTemplate);
|
verify(defaultTemplate);
|
||||||
verify(defaultLocation);
|
|
||||||
verify(optionsProvider);
|
verify(optionsProvider);
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
@ -485,13 +464,12 @@ public class TemplateBuilderImplTest {
|
||||||
public void testSuppliedImageLocationWiderThanDefault() {
|
public void testSuppliedImageLocationWiderThanDefault() {
|
||||||
TemplateOptions from = provideTemplateOptions();
|
TemplateOptions from = provideTemplateOptions();
|
||||||
|
|
||||||
Location defaultLocation = createMock(Location.class);
|
|
||||||
Image image = createMock(Image.class);
|
Image image = createMock(Image.class);
|
||||||
|
|
||||||
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("myregion/foo")).build();
|
Hardware hardware = new HardwareBuilder().id("hardwareId").supportsImage(ImagePredicates.idEquals("us-east-1/foo")).build();
|
||||||
|
|
||||||
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||||
.<Image> of(image));
|
.<Image> of(image));
|
||||||
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
|
||||||
|
@ -504,10 +482,9 @@ public class TemplateBuilderImplTest {
|
||||||
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
TemplateOptions defaultOptions = createMock(TemplateOptions.class);
|
||||||
expect(optionsProvider.get()).andReturn(from).atLeastOnce();
|
expect(optionsProvider.get()).andReturn(from).atLeastOnce();
|
||||||
|
|
||||||
expect(defaultLocation.getId()).andReturn("myregion").atLeastOnce();
|
|
||||||
|
|
||||||
expect(image.getId()).andReturn("myregion/foo").atLeastOnce();
|
expect(image.getId()).andReturn("us-east-1/foo").atLeastOnce();
|
||||||
expect(image.getLocation()).andReturn(defaultLocation).atLeastOnce();
|
expect(image.getLocation()).andReturn(region).atLeastOnce();
|
||||||
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
expect(image.getOperatingSystem()).andReturn(os).atLeastOnce();
|
||||||
expect(image.getName()).andReturn(null).atLeastOnce();
|
expect(image.getName()).andReturn(null).atLeastOnce();
|
||||||
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
expect(image.getDescription()).andReturn(null).atLeastOnce();
|
||||||
|
@ -521,26 +498,23 @@ public class TemplateBuilderImplTest {
|
||||||
expect(os.getArch()).andReturn(null).atLeastOnce();
|
expect(os.getArch()).andReturn(null).atLeastOnce();
|
||||||
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
expect(os.is64Bit()).andReturn(false).atLeastOnce();
|
||||||
|
|
||||||
expect(defaultLocation.getScope()).andReturn(LocationScope.HOST).atLeastOnce();
|
|
||||||
|
|
||||||
replay(defaultOptions);
|
replay(defaultOptions);
|
||||||
replay(imageLocation);
|
replay(imageLocation);
|
||||||
replay(image);
|
replay(image);
|
||||||
replay(os);
|
replay(os);
|
||||||
replay(defaultLocation);
|
|
||||||
replay(optionsProvider);
|
replay(optionsProvider);
|
||||||
replay(templateBuilderProvider);
|
replay(templateBuilderProvider);
|
||||||
|
|
||||||
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, defaultLocation,
|
TemplateBuilderImpl template = createTemplateBuilder(null, locations, images, hardwares, region,
|
||||||
optionsProvider, templateBuilderProvider);
|
optionsProvider, templateBuilderProvider);
|
||||||
|
|
||||||
assertEquals(template.imageId("myregion/foo").locationId("myregion").build().getLocation(), defaultLocation);
|
assertEquals(template.imageId("us-east-1/foo").locationId(region.getId()).build().getLocation(), region);
|
||||||
|
|
||||||
verify(defaultOptions);
|
verify(defaultOptions);
|
||||||
verify(imageLocation);
|
verify(imageLocation);
|
||||||
verify(image);
|
verify(image);
|
||||||
verify(os);
|
verify(os);
|
||||||
verify(defaultLocation);
|
|
||||||
verify(optionsProvider);
|
verify(optionsProvider);
|
||||||
verify(templateBuilderProvider);
|
verify(templateBuilderProvider);
|
||||||
}
|
}
|
||||||
|
@ -814,17 +788,16 @@ public class TemplateBuilderImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMatchesHardwareWithIdPredicate() {
|
public void testMatchesHardwareWithIdPredicate() {
|
||||||
final Location defaultLocation = createMock(Location.class);
|
|
||||||
|
|
||||||
final Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
final Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
|
||||||
.<Location> of(defaultLocation));
|
.<Location> of(region));
|
||||||
final Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
final Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
|
||||||
.<Image> of(
|
.<Image> of(
|
||||||
new ImageBuilder()
|
new ImageBuilder()
|
||||||
.ids("Ubuntu 11.04 x64")
|
.ids("Ubuntu 11.04 x64")
|
||||||
.name("Ubuntu 11.04 x64")
|
.name("Ubuntu 11.04 x64")
|
||||||
.description("Ubuntu 11.04 x64")
|
.description("Ubuntu 11.04 x64")
|
||||||
.location(defaultLocation)
|
.location(region)
|
||||||
.operatingSystem(
|
.operatingSystem(
|
||||||
OperatingSystem.builder().name("Ubuntu 11.04 x64").description("Ubuntu 11.04 x64")
|
OperatingSystem.builder().name("Ubuntu 11.04 x64").description("Ubuntu 11.04 x64")
|
||||||
.is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build(),
|
.is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build(),
|
||||||
|
@ -832,7 +805,7 @@ public class TemplateBuilderImplTest {
|
||||||
.ids("Ubuntu 11.04 64-bit")
|
.ids("Ubuntu 11.04 64-bit")
|
||||||
.name("Ubuntu 11.04 64-bit")
|
.name("Ubuntu 11.04 64-bit")
|
||||||
.description("Ubuntu 11.04 64-bit")
|
.description("Ubuntu 11.04 64-bit")
|
||||||
.location(defaultLocation)
|
.location(region)
|
||||||
.operatingSystem(
|
.operatingSystem(
|
||||||
OperatingSystem.builder().name("Ubuntu 11.04 64-bit").description("Ubuntu 11.04 64-bit")
|
OperatingSystem.builder().name("Ubuntu 11.04 64-bit").description("Ubuntu 11.04 64-bit")
|
||||||
.is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build()));
|
.is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build()));
|
||||||
|
@ -844,14 +817,14 @@ public class TemplateBuilderImplTest {
|
||||||
"Falkenberg", "Xen", 1, 512, 5)).ram(512)
|
"Falkenberg", "Xen", 1, 512, 5)).ram(512)
|
||||||
.processors(ImmutableList.of(new Processor(1, 1.0)))
|
.processors(ImmutableList.of(new Processor(1, 1.0)))
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) 5, true, true))).hypervisor("Xen")
|
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) 5, true, true))).hypervisor("Xen")
|
||||||
.location(defaultLocation)
|
.location(region)
|
||||||
.supportsImage(ImagePredicates.idIn(ImmutableSet.of("Ubuntu 11.04 x64"))).build(),
|
.supportsImage(ImagePredicates.idIn(ImmutableSet.of("Ubuntu 11.04 x64"))).build(),
|
||||||
new HardwareBuilder()
|
new HardwareBuilder()
|
||||||
.ids(String.format("datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)",
|
.ids(String.format("datacenter(%s)platform(%s)cpuCores(%d)memorySizeMB(%d)diskSizeGB(%d)",
|
||||||
"Falkenberg", "OpenVZ", 1, 512, 5)).ram(512)
|
"Falkenberg", "OpenVZ", 1, 512, 5)).ram(512)
|
||||||
.processors(ImmutableList.of(new Processor(1, 1.0)))
|
.processors(ImmutableList.of(new Processor(1, 1.0)))
|
||||||
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) 5, true, true))).hypervisor("OpenVZ")
|
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) 5, true, true))).hypervisor("OpenVZ")
|
||||||
.location(defaultLocation)
|
.location(region)
|
||||||
.supportsImage(ImagePredicates.idIn(ImmutableSet.of("Ubuntu 11.04 64-bit"))).build()));
|
.supportsImage(ImagePredicates.idIn(ImmutableSet.of("Ubuntu 11.04 64-bit"))).build()));
|
||||||
|
|
||||||
final Provider<TemplateOptions> optionsProvider = new Provider<TemplateOptions>() {
|
final Provider<TemplateOptions> optionsProvider = new Provider<TemplateOptions>() {
|
||||||
|
@ -866,13 +839,10 @@ public class TemplateBuilderImplTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TemplateBuilder get() {
|
public TemplateBuilder get() {
|
||||||
return createTemplateBuilder(null, locations, images, hardwares, defaultLocation, optionsProvider, this);
|
return createTemplateBuilder(null, locations, images, hardwares, region, optionsProvider, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
expect(defaultLocation.getId()).andReturn("region").anyTimes();
|
|
||||||
|
|
||||||
replay(defaultLocation);
|
|
||||||
|
|
||||||
TemplateBuilder templateBuilder = templateBuilderProvider.get().minRam(512).osFamily(OsFamily.UBUNTU)
|
TemplateBuilder templateBuilder = templateBuilderProvider.get().minRam(512).osFamily(OsFamily.UBUNTU)
|
||||||
.hypervisorMatches("OpenVZ").osVersionMatches("1[10].[10][04]").os64Bit(true);
|
.hypervisorMatches("OpenVZ").osVersionMatches("1[10].[10][04]").os64Bit(true);
|
||||||
|
@ -881,6 +851,5 @@ public class TemplateBuilderImplTest {
|
||||||
assertEquals(template.getHardware().getHypervisor(), "OpenVZ");
|
assertEquals(template.getHardware().getHypervisor(), "OpenVZ");
|
||||||
assertEquals(template.getImage().getId(), "Ubuntu 11.04 64-bit");
|
assertEquals(template.getImage().getId(), "Ubuntu 11.04 64-bit");
|
||||||
|
|
||||||
verify(defaultLocation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue