From c684a59cb35e3b2de7f42da787b5539c0ce3e40d Mon Sep 17 00:00:00 2001 From: Dies Koper Date: Mon, 6 Aug 2012 23:26:59 +1000 Subject: [PATCH] add predicates and template builder live tests for location scopes SYSTEM and NETWORK --- .../internal/BaseTemplateBuilderLiveTest.java | 16 +++++++++ .../predicates/LocationPredicates.java | 34 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseTemplateBuilderLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseTemplateBuilderLiveTest.java index 26c77437c2..e6943f482d 100644 --- a/compute/src/test/java/org/jclouds/compute/internal/BaseTemplateBuilderLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseTemplateBuilderLiveTest.java @@ -205,6 +205,22 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseComputeServiceCont || location.getParent().getIso3166Codes().containsAll(location.getIso3166Codes()) : location + " ||" + location.getParent(); break; + case SYSTEM: + Location systemParent = location.getParent(); + // loop up to root, which must be the provider + while (systemParent.getParent() != null) { + systemParent = systemParent.getParent(); + } + assertProvider(systemParent); + break; + case NETWORK: + Location networkParent = location.getParent(); + // loop up to root, which must be the provider + while (networkParent.getParent() != null) { + networkParent = networkParent.getParent(); + } + assertProvider(networkParent); + break; case HOST: Location provider2 = location.getParent().getParent().getParent(); // zone can be a direct descendant of provider diff --git a/core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java b/core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java index 3719cf3c00..f9e38c7b1d 100644 --- a/core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java +++ b/core/src/main/java/org/jclouds/location/predicates/LocationPredicates.java @@ -86,6 +86,40 @@ public class LocationPredicates { } } + public static Predicate isSystem() { + return IsSystem.INSTANCE; + } + + static enum IsSystem implements Predicate { + INSTANCE; + @Override + public boolean apply(Location input) { + return input.getScope() == LocationScope.SYSTEM; + } + + @Override + public String toString() { + return "isSystem()"; + } + } + + public static Predicate isNetwork() { + return IsNetwork.INSTANCE; + } + + static enum IsNetwork implements Predicate { + INSTANCE; + @Override + public boolean apply(Location input) { + return input.getScope() == LocationScope.NETWORK; + } + + @Override + public String toString() { + return "isNetwork()"; + } + } + public static Predicate idEquals(String id) { return new IdEquals(id); }