From 8c18f3ba1bc4e380b062d44565fa36a9f36e7a7b Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 15 Apr 2013 11:05:11 -0700 Subject: [PATCH] converted RegionToTerritories to a multimap and normalized use of IdAndName --- .../jclouds/ultradns/ws/UltraDNSWSApi.java | 10 +- .../ultradns/ws/domain/DirectionalGroup.java | 96 ++++++++++--- .../DirectionalGroupNameAndRegions.java | 127 ------------------ .../ws/domain/DirectionalRecordDetail.java | 28 ++-- .../domain/{Account.java => IdAndName.java} | 14 +- .../jclouds/ultradns/ws/domain/Region.java | 127 ------------------ .../ws/features/DirectionalGroupApi.java | 3 +- .../ws/features/RoundRobinPoolApi.java | 2 +- .../ultradns/ws/xml/AccountHandler.java | 10 +- ...DirectionalGroupNameAndRegionsHandler.java | 17 +-- .../xml/DirectionalRecordDetailHandler.java | 15 +-- .../ultradns/ws/xml/RegionListHandler.java | 21 ++- .../ultradns/ws/UltraDNSWSApiLiveTest.java | 21 ++- .../features/DirectionalGroupApiLiveTest.java | 8 +- .../features/DirectionalPoolApiLiveTest.java | 11 +- .../features/ResourceRecordApiLiveTest.java | 4 +- .../features/RoundRobinPoolApiLiveTest.java | 4 +- .../TrafficControllerPoolApiLiveTest.java | 4 +- .../ultradns/ws/features/ZoneApiLiveTest.java | 4 +- .../GetAccountsListOfUserResponseTest.java | 10 +- .../GetAvailableRegionsResponseTest.java | 31 ++--- ...irectionalDNSGroupDetailsResponseTest.java | 32 ++--- ...ectionalDNSRecordsForHostResponseTest.java | 22 +-- 23 files changed, 193 insertions(+), 428 deletions(-) delete mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupNameAndRegions.java rename providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/{Account.java => IdAndName.java} (83%) delete mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Region.java diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java index c302348f49..bb571a0400 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java @@ -19,7 +19,6 @@ package org.jclouds.ultradns.ws; import java.io.Closeable; -import java.util.Map; import javax.inject.Named; import javax.ws.rs.POST; @@ -30,8 +29,7 @@ import org.jclouds.rest.annotations.PayloadParam; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; -import org.jclouds.ultradns.ws.domain.Account; -import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.features.DirectionalGroupApi; import org.jclouds.ultradns.ws.features.DirectionalPoolApi; import org.jclouds.ultradns.ws.features.ResourceRecordApi; @@ -43,6 +41,8 @@ import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.xml.AccountHandler; import org.jclouds.ultradns.ws.xml.RegionListHandler; +import com.google.common.collect.Multimap; + /** * Provides access to Neustar UltraDNS via the SOAP API *

@@ -60,7 +60,7 @@ public interface UltraDNSWSApi extends Closeable { @POST @XMLResponseParser(AccountHandler.class) @Payload("") - Account getCurrentAccount(); + IdAndName getCurrentAccount(); /** * Lists the directional regions available in the account. @@ -69,7 +69,7 @@ public interface UltraDNSWSApi extends Closeable { @POST @XMLResponseParser(RegionListHandler.class) @Payload("") - Map getRegionsById(); + Multimap getRegionsById(); /** * Provides access to Zone features. diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java index 7caaf52d0c..d43236e2c8 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java @@ -23,30 +23,49 @@ import static com.google.common.base.Objects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.collect.ForwardingMultimap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.Multimap; /** + * A region is a set of territory names. + * * @author Adrian Cole */ -public class DirectionalGroup { - private final String id; +public class DirectionalGroup extends ForwardingMultimap { + private final String name; + private final Optional description; + private final Multimap regionToTerritories; - private DirectionalGroup(String id, String name) { - this.id = checkNotNull(id, "id"); + private DirectionalGroup(String name, Optional description, + Multimap regionToTerritories) { this.name = checkNotNull(name, "name"); - } - - public String getId() { - return id; + this.description = checkNotNull(description, "description of %s", name); + this.regionToTerritories = checkNotNull(regionToTerritories, "regionToTerritories of %s", name); } public String getName() { return name; } + public Optional getDescription() { + return description; + } + + public Multimap getRegionToTerritories() { + return regionToTerritories; + } + + @Override + protected Multimap delegate() { + return regionToTerritories; + } + @Override public int hashCode() { - return Objects.hashCode(id, name); + return Objects.hashCode(name, regionToTerritories); } @Override @@ -56,12 +75,13 @@ public class DirectionalGroup { if (obj == null || getClass() != obj.getClass()) return false; DirectionalGroup that = DirectionalGroup.class.cast(obj); - return equal(this.id, that.id) && equal(this.name, that.name); + return equal(this.name, that.name) && equal(this.regionToTerritories, that.regionToTerritories); } @Override public String toString() { - return toStringHelper(this).omitNullValues().add("id", id).add("name", name).toString(); + return toStringHelper(this).omitNullValues().add("name", name).add("description", description.orNull()) + .add("regionToTerritories", regionToTerritories).toString(); } public static Builder builder() { @@ -73,16 +93,10 @@ public class DirectionalGroup { } public final static class Builder { - private String id; private String name; - - /** - * @see DirectionalGroup#getId() - */ - public Builder id(String id) { - this.id = id; - return this; - } + private Optional description = Optional.absent(); + private ImmutableMultimap.Builder regionToTerritories = ImmutableMultimap + . builder(); /** * @see DirectionalGroup#getName() @@ -92,12 +106,50 @@ public class DirectionalGroup { return this; } + /** + * @see DirectionalGroup#getDescription() + */ + public Builder description(String description) { + this.description = Optional.fromNullable(description); + return this; + } + + /** + * adds to current regionToTerritories + * + * @see DirectionalGroup#getRegionToTerritories() + */ + public Builder mapRegionToTerritories(String region, Iterable territories) { + this.regionToTerritories.putAll(region, territories); + return this; + } + + /** + * adds to current regionToTerritories + * + * @see DirectionalGroup#getRegionToTerritories() + */ + public Builder mapRegionToTerritory(String region, String territory) { + this.regionToTerritories.put(region, territory); + return this; + } + + /** + * replaces current regionToTerritories + * + * @see DirectionalGroup#getRegionToTerritories() + */ + public Builder regionToTerritories(Multimap regionToTerritories) { + this.regionToTerritories = ImmutableMultimap. builder().putAll(regionToTerritories); + return this; + } + public DirectionalGroup build() { - return new DirectionalGroup(id, name); + return new DirectionalGroup(name, description, regionToTerritories.build()); } public Builder from(DirectionalGroup in) { - return id(in.id).name(in.name); + return name(in.getName()).regionToTerritories(in.getRegionToTerritories()); } } } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupNameAndRegions.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupNameAndRegions.java deleted file mode 100644 index 9c7b55f8bb..0000000000 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroupNameAndRegions.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.ultradns.ws.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Set; - -import com.google.common.base.Objects; -import com.google.common.collect.ForwardingSet; -import com.google.common.collect.ImmutableSet; - -/** - * A region is a set of territory names. - * - * @author Adrian Cole - */ -public class DirectionalGroupNameAndRegions extends ForwardingSet { - - private final String name; - private final Set regions; - - private DirectionalGroupNameAndRegions(String name, Set regions) { - this.name = checkNotNull(name, "name"); - this.regions = checkNotNull(regions, "regions of %s", name); - } - - public String getName() { - return name; - } - - public Set getRegions() { - return regions; - } - - @Override - protected Set delegate() { - return regions; - } - - @Override - public int hashCode() { - return Objects.hashCode(name, regions); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; - DirectionalGroupNameAndRegions that = DirectionalGroupNameAndRegions.class.cast(obj); - return equal(this.name, that.name) && equal(this.regions, that.regions); - } - - @Override - public String toString() { - return toStringHelper(this).add("name", name).add("regions", regions).toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().from(this); - } - - public final static class Builder { - private String name; - private ImmutableSet.Builder regions = ImmutableSet. builder(); - - /** - * @see DirectionalGroupNameAndRegions#getName() - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * adds to current regions - * - * @see DirectionalGroupNameAndRegions#getRegions() - */ - public Builder addRegion(Region region) { - this.regions.add(region); - return this; - } - - /** - * replaces current regions - * - * @see DirectionalGroupNameAndRegions#getRegions() - */ - public Builder regions(Iterable regions) { - this.regions = ImmutableSet. builder().addAll(regions); - return this; - } - - public DirectionalGroupNameAndRegions build() { - return new DirectionalGroupNameAndRegions(name, regions.build()); - } - - public Builder from(DirectionalGroupNameAndRegions in) { - return name(in.getName()).regions(in.getRegions()); - } - } -} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java index 0a5a27f194..c19977d07b 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java @@ -33,14 +33,14 @@ public class DirectionalRecordDetail { private final String zoneName; private final String name; private final String id; - private final Optional group; - private final Optional geolocationGroup; - private final Optional sourceIpGroup; + private final Optional group; + private final Optional geolocationGroup; + private final Optional sourceIpGroup; private final DirectionalRecord record; private DirectionalRecordDetail(String zoneName, String name, String id, - Optional group, Optional geolocationGroup, - Optional sourceIpGroup, DirectionalRecord record) { + Optional group, Optional geolocationGroup, + Optional sourceIpGroup, DirectionalRecord record) { this.zoneName = checkNotNull(zoneName, "zoneName"); this.name = checkNotNull(name, "name"); this.id = checkNotNull(id, "id"); @@ -65,21 +65,21 @@ public class DirectionalRecordDetail { /** * group containing all regions that you have not specifically configured in {@link #getGeolocationGroup()} */ - public Optional getGroup() { + public Optional getGroup() { return group; } /** * group containing territories. */ - public Optional getGeolocationGroup() { + public Optional getGeolocationGroup() { return geolocationGroup; } /** * group containing IPV4 or IPV6 ranges. */ - public Optional getSourceIpGroup() { + public Optional getSourceIpGroup() { return sourceIpGroup; } @@ -121,9 +121,9 @@ public class DirectionalRecordDetail { private String zoneName; private String name; private String id; - private Optional group = Optional.absent(); - private Optional geolocationGroup = Optional.absent(); - private Optional sourceIpGroup = Optional.absent(); + private Optional group = Optional.absent(); + private Optional geolocationGroup = Optional.absent(); + private Optional sourceIpGroup = Optional.absent(); private DirectionalRecord record; /** @@ -153,7 +153,7 @@ public class DirectionalRecordDetail { /** * @see DirectionalRecordDetail#getGroup() */ - public Builder group(DirectionalGroup group) { + public Builder group(IdAndName group) { this.group = Optional.fromNullable(group); return this; } @@ -161,7 +161,7 @@ public class DirectionalRecordDetail { /** * @see DirectionalRecordDetail#getGeolocationGroup() */ - public Builder geolocationGroup(DirectionalGroup geolocationGroup) { + public Builder geolocationGroup(IdAndName geolocationGroup) { this.geolocationGroup = Optional.fromNullable(geolocationGroup); return this; } @@ -169,7 +169,7 @@ public class DirectionalRecordDetail { /** * @see DirectionalRecordDetail#getSourceIpGroup() */ - public Builder sourceIpGroup(DirectionalGroup sourceIpGroup) { + public Builder sourceIpGroup(IdAndName sourceIpGroup) { this.sourceIpGroup = Optional.fromNullable(sourceIpGroup); return this; } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/IdAndName.java similarity index 83% rename from providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java rename to providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/IdAndName.java index 202af85a72..764232d0c2 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/IdAndName.java @@ -25,28 +25,28 @@ import com.google.common.base.Objects; /** * @author Adrian Cole */ -public final class Account { - public static Account fromIdAndName(String id, String name) { - return new Account(id, name); +public final class IdAndName { + public static IdAndName fromIdAndName(String id, String name) { + return new IdAndName(id, name); } private final String id; private final String name; - private Account(String id, String name) { + private IdAndName(String id, String name) { this.id = checkNotNull(id, "id"); this.name = checkNotNull(name, "name for %s", id); } /** - * The id of the account. ex {@code AAAAAAAAAAAAAAAA} + * The id of the resource. ex {@code AAAAAAAAAAAAAAAA} */ public String getId() { return id; } /** - * The name of the account. ex {@code jclouds} + * The name of the resource. ex {@code jclouds} */ public String getName() { return name; @@ -65,7 +65,7 @@ public final class Account { return false; if (getClass() != obj.getClass()) return false; - Account that = Account.class.cast(obj); + IdAndName that = IdAndName.class.cast(obj); return Objects.equal(this.id, that.id) && Objects.equal(this.name, that.name); } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Region.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Region.java deleted file mode 100644 index 23ea0fd7cf..0000000000 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Region.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.ultradns.ws.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Set; - -import com.google.common.base.Objects; -import com.google.common.collect.ForwardingSet; -import com.google.common.collect.ImmutableSet; - -/** - * A region is a set of territory names. - * - * @author Adrian Cole - */ -public class Region extends ForwardingSet { - - private final String name; - private final Set territoryNames; - - private Region(String name, Set territoryNames) { - this.name = checkNotNull(name, "name"); - this.territoryNames = checkNotNull(territoryNames, "territoryNames of %s", name); - } - - public String getName() { - return name; - } - - public Set getTerritoryNames() { - return territoryNames; - } - - @Override - protected Set delegate() { - return territoryNames; - } - - @Override - public int hashCode() { - return Objects.hashCode(name, territoryNames); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; - Region that = Region.class.cast(obj); - return equal(this.name, that.name) && equal(this.territoryNames, that.territoryNames); - } - - @Override - public String toString() { - return toStringHelper(this).add("name", name).add("territoryNames", territoryNames).toString(); - } - - public static Builder builder() { - return new Builder(); - } - - public Builder toBuilder() { - return builder().from(this); - } - - public final static class Builder { - private String name; - private ImmutableSet.Builder territoryNames = ImmutableSet. builder(); - - /** - * @see Region#getName() - */ - public Builder name(String name) { - this.name = name; - return this; - } - - /** - * adds to current territoryNames - * - * @see Region#getTerritoryNames() - */ - public Builder addTerritoryName(String territoryName) { - this.territoryNames.add(territoryName); - return this; - } - - /** - * replaces current territoryNames - * - * @see Region#getTerritoryNames() - */ - public Builder territoryNames(Iterable territoryNames) { - this.territoryNames = ImmutableSet. builder().addAll(territoryNames); - return this; - } - - public Region build() { - return new Region(name, territoryNames.build()); - } - - public Builder from(Region in) { - return name(in.getName()).territoryNames(in.getTerritoryNames()); - } - } -} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalGroupApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalGroupApi.java index 70e1436a94..4f5c0d255d 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalGroupApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalGroupApi.java @@ -36,7 +36,6 @@ import org.jclouds.ultradns.ws.binders.DirectionalGroupCoordinatesToXML; import org.jclouds.ultradns.ws.domain.AccountLevelGroup; import org.jclouds.ultradns.ws.domain.DirectionalGroup; import org.jclouds.ultradns.ws.domain.DirectionalGroupCoordinates; -import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.xml.AccountLevelGroupsHandler; @@ -68,7 +67,7 @@ public interface DirectionalGroupApi { @Fallback(NullOnNotFoundOr404.class) @Payload("{GroupId}") @Nullable - DirectionalGroupNameAndRegions get(@PayloadParam("GroupId") String groupId); + DirectionalGroup get(@PayloadParam("GroupId") String groupId); /** * Returns all account-level groups. diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java index 80c198499a..4e355b5e6f 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApi.java @@ -82,7 +82,7 @@ public interface RoundRobinPoolApi { * @param hostname * {@link RoundRobinPool#getDName() dname} of the RR pool {ex. * www.jclouds.org.} - * @return the {@code guid} of the new record + * @return the {@code guid} of the new pool * @throws ResourceAlreadyExistsException * if a pool already exists with the same attrs */ diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountHandler.java index 7b2d1763e9..8a89823295 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountHandler.java @@ -24,19 +24,19 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix; import java.util.Map; import org.jclouds.http.functions.ParseSax; -import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.xml.sax.Attributes; /** * * @author Adrian Cole */ -public class AccountHandler extends ParseSax.HandlerForGeneratedRequestWithResult { +public class AccountHandler extends ParseSax.HandlerForGeneratedRequestWithResult { - private Account account; + private IdAndName account; @Override - public Account getResult() { + public IdAndName getResult() { try { return account; } finally { @@ -48,7 +48,7 @@ public class AccountHandler extends ParseSax.HandlerForGeneratedRequestWithResul public void startElement(String uri, String localName, String qName, Attributes attrs) { Map attributes = cleanseAttributes(attrs); if (equalsOrSuffix(qName, "AccountDetailsData")) { - account = Account.fromIdAndName(attributes.get("accountID"), attributes.get("accountName")); + account = IdAndName.fromIdAndName(attributes.get("accountID"), attributes.get("accountName")); } } } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalGroupNameAndRegionsHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalGroupNameAndRegionsHandler.java index 800a9bd16f..17be49ae14 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalGroupNameAndRegionsHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalGroupNameAndRegionsHandler.java @@ -21,9 +21,8 @@ package org.jclouds.ultradns.ws.xml; import static org.jclouds.util.SaxUtils.equalsOrSuffix; import org.jclouds.http.functions.ParseSax; -import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; -import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions.Builder; -import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.domain.DirectionalGroup; +import org.jclouds.ultradns.ws.domain.DirectionalGroup.Builder; import org.xml.sax.Attributes; import com.google.common.base.Splitter; @@ -32,12 +31,12 @@ import com.google.common.base.Splitter; * * @author Adrian Cole */ -public class DirectionalGroupNameAndRegionsHandler extends ParseSax.HandlerForGeneratedRequestWithResult { +public class DirectionalGroupNameAndRegionsHandler extends ParseSax.HandlerForGeneratedRequestWithResult { - private final Builder group = DirectionalGroupNameAndRegions.builder(); + private final Builder group = DirectionalGroup.builder(); @Override - public DirectionalGroupNameAndRegions getResult() { + public DirectionalGroup getResult() { return group.build(); } @@ -46,11 +45,9 @@ public class DirectionalGroupNameAndRegionsHandler extends ParseSax.HandlerForGe if (equalsOrSuffix(qName, "DirectionalDNSGroupDetail")) { group.name(attrs.getValue("GroupName")); } else if (equalsOrSuffix(qName, "RegionForNewGroups")) { + String regionName = attrs.getValue("RegionName"); Iterable territories = Splitter.on(';').split(attrs.getValue("TerritoryName")); - Region region = Region.builder() - .name(attrs.getValue("RegionName")) - .territoryNames(territories).build(); - group.addRegion(region); + group.mapRegionToTerritories(regionName, territories); } } } diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java index 7c967aaa2f..3bf7914c87 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java @@ -24,7 +24,7 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix; import java.util.Map; import org.jclouds.http.functions.ParseSax; -import org.jclouds.ultradns.ws.domain.DirectionalGroup; +import static org.jclouds.ultradns.ws.domain.IdAndName.*; import org.jclouds.ultradns.ws.domain.DirectionalRecord; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.xml.sax.Attributes; @@ -64,19 +64,14 @@ public class DirectionalRecordDetailHandler extends drd.id(attributes.get("DirPoolRecordId")); } if (attributes.containsKey("GroupId")) { - drd.group(DirectionalGroup.builder() - .id(attributes.get("GroupId")) - .name(attributes.get("GroupName")).build()); + drd.group(fromIdAndName(attributes.get("GroupId"), attributes.get("GroupName"))); } if (attributes.containsKey("GeolocationGroupId")) { - drd.geolocationGroup(DirectionalGroup.builder() - .id(attributes.get("GeolocationGroupId")) - .name(attributes.get("GeolocationGroupName")).build()); + drd.geolocationGroup(fromIdAndName(attributes.get("GeolocationGroupId"), + attributes.get("GeolocationGroupName"))); } if (attributes.containsKey("SourceIPGroupId")) { - drd.sourceIpGroup(DirectionalGroup.builder() - .id(attributes.get("SourceIPGroupId")) - .name(attributes.get("SourceIPGroupName")).build()); + drd.sourceIpGroup(fromIdAndName(attributes.get("SourceIPGroupId"), attributes.get("SourceIPGroupName"))); } if (attributes.containsKey("recordType")) { dr.type(attributes.get("recordType")); diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RegionListHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RegionListHandler.java index 6c47f3bf3e..dc52ea1095 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RegionListHandler.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/RegionListHandler.java @@ -24,23 +24,24 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix; import java.util.Map; import org.jclouds.http.functions.ParseSax; -import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.xml.sax.Attributes; import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableMultimap.Builder; +import com.google.common.collect.Multimap; /** * * @author Adrian Cole */ -public class RegionListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { +public class RegionListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { - private final Builder regions = ImmutableMap. builder(); + private final Builder regions = ImmutableMultimap. builder(); @Override - public Map getResult() { + public Multimap getResult() { return regions.build(); } @@ -48,12 +49,8 @@ public class RegionListHandler extends ParseSax.HandlerForGeneratedRequestWithRe public void startElement(String url, String name, String qName, Attributes attrs) { if (equalsOrSuffix(qName, "Region")) { Map attributes = cleanseAttributes(attrs); - int id = Integer.parseInt(attributes.get("RegionID")); - Iterable territories = Splitter.on(';').split(attributes.get("TerritoryName")); - Region region = Region.builder() - .name(attributes.get("RegionName")) - .territoryNames(territories).build(); - regions.put(id, region); + IdAndName region = IdAndName.fromIdAndName(attributes.get("RegionID"), attributes.get("RegionName")); + regions.putAll(region, Splitter.on(';').split(attributes.get("TerritoryName"))); } } } diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiLiveTest.java index d6046fd1e7..e7a4727298 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiLiveTest.java @@ -20,12 +20,11 @@ package org.jclouds.ultradns.ws; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import java.util.Collection; import java.util.Map.Entry; -import org.jclouds.ultradns.ws.domain.Account; -import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; import org.testng.annotations.Test; @@ -37,26 +36,26 @@ public class UltraDNSWSApiLiveTest extends BaseUltraDNSWSApiLiveTest { @Test protected void testGetCurrentAccount() { - Account account = api.getCurrentAccount(); + IdAndName account = api.getCurrentAccount(); checkAccount(account); } - private void checkAccount(Account account) { + private void checkAccount(IdAndName account) { assertNotNull(account.getId(), "Id cannot be null for " + account); assertNotNull(account.getName(), "Name cannot be null for " + account); } @Test public void testListRegions() { - for (Entry region : api.getRegionsById().entrySet()) { + for (Entry> region : api.getRegionsById().asMap().entrySet()) { checkRegion(region); } } - private void checkRegion(Entry region) { - assertTrue(region.getKey() > 0, "Id cannot be negative " + region); - assertNotNull(region.getValue().getName(), "Name cannot be null " + region); - assertNotNull(region.getValue().getTerritoryNames(), "TerritoryNames cannot be null " + region); - assertFalse(region.getValue().getTerritoryNames().isEmpty(), "TerritoryNames cannot be empty " + region); + private void checkRegion(Entry> region) { + assertNotNull(region.getKey().getId(), "Id cannot be null " + region); + assertNotNull(region.getKey().getName(), "Name cannot be null " + region); + assertNotNull(region.getValue(), "TerritoryNames cannot be null " + region); + assertFalse(region.getValue().isEmpty(), "TerritoryNames cannot be empty " + region); } } diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiLiveTest.java index 0f67e65b87..b876072873 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalGroupApiLiveTest.java @@ -26,10 +26,10 @@ import java.util.EnumSet; import java.util.Set; import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.domain.AccountLevelGroup; import org.jclouds.ultradns.ws.domain.DirectionalGroupCoordinates; -import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; +import org.jclouds.ultradns.ws.domain.DirectionalGroup; import org.jclouds.ultradns.ws.domain.DirectionalPool; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.domain.DirectionalRecordType; @@ -46,7 +46,7 @@ import com.google.common.collect.Sets; @Test(groups = "live", singleThreaded = true, testName = "DirectionalGroupApiLiveTest") public class DirectionalGroupApiLiveTest extends BaseUltraDNSWSApiLiveTest { - private Account account; + private IdAndName account; @Override @BeforeClass(groups = { "integration", "live" }) @@ -81,7 +81,7 @@ public class DirectionalGroupApiLiveTest extends BaseUltraDNSWSApiLiveTest { @Test public void testGetDirectionalGroup() { for (AccountLevelGroup group : api().listAccountLevelGroups()) { - DirectionalGroupNameAndRegions withRegions = api().get(group.getId()); + DirectionalGroup withRegions = api().get(group.getId()); assertEquals(withRegions.getName(), group.getName()); assertTrue(withRegions.size() > 0); } diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java index b7929c03f8..118c8cc0d0 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java @@ -27,12 +27,11 @@ import java.util.EnumSet; import java.util.Set; import org.jclouds.rest.ResourceNotFoundException; -import org.jclouds.ultradns.ws.domain.Account; -import org.jclouds.ultradns.ws.domain.DirectionalGroup; import org.jclouds.ultradns.ws.domain.DirectionalPool; import org.jclouds.ultradns.ws.domain.DirectionalRecord; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.domain.DirectionalRecordType; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.domain.Zone; import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; import org.testng.annotations.BeforeClass; @@ -49,7 +48,7 @@ import com.google.common.collect.Sets; @Test(groups = "live", singleThreaded = true, testName = "DirectionalPoolApiLiveTest") public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { - private Account account; + private IdAndName account; @Override @BeforeClass(groups = { "integration", "live" }) @@ -76,7 +75,7 @@ public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { assertNotNull(pool.getTieBreak(), "TieBreak cannot be null " + pool); } - Set allDirectionalGroups = Sets.newLinkedHashSet(); + Set allDirectionalGroups = Sets.newLinkedHashSet(); @Test public void testListDirectionalRecords() { @@ -86,10 +85,10 @@ public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { for (DirectionalRecordDetail rr : api(zone.getName()) .listRecordsByNameAndType(pool.getName(), type.getCode())) { checkDirectionalRecordDetail(rr); - Iterable groups = Optional.presentInstances(ImmutableSet.of(rr.getGroup(), + Iterable groups = Optional.presentInstances(ImmutableSet.of(rr.getGroup(), rr.getGeolocationGroup(), rr.getGeolocationGroup())); assertFalse(Iterables.isEmpty(groups), "No groups " + rr); - for (DirectionalGroup group : groups) { + for (IdAndName group : groups) { allDirectionalGroups.add(group); assertNotNull(group.getId(), "Id cannot be null " + group); assertNotNull(group.getName(), "Name cannot be null " + group); diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java index ea8f08e309..e31c9caa6b 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ResourceRecordApiLiveTest.java @@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; -import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.domain.ResourceRecord; import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import org.jclouds.ultradns.ws.domain.Zone; @@ -53,7 +53,7 @@ import com.google.common.collect.FluentIterable; public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest { private String zoneName = System.getProperty("user.name").replace('.', '-') + ".rr.ultradnstest.jclouds.org."; - private Account account; + private IdAndName account; @Override @BeforeClass(groups = { "integration", "live" }) diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java index 29ee70a8a3..7bcea4edd0 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/RoundRobinPoolApiLiveTest.java @@ -29,7 +29,7 @@ import static org.testng.Assert.fail; import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; -import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.domain.ResourceRecord; import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import org.jclouds.ultradns.ws.domain.RoundRobinPool; @@ -50,7 +50,7 @@ import com.google.common.collect.FluentIterable; public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { private String zoneName = System.getProperty("user.name").replace('.', '-') + ".rrpool.ultradnstest.jclouds.org."; - private Account account; + private IdAndName account; @Override @BeforeClass(groups = { "integration", "live" }) diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java index f0480698c9..c54817001a 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/TrafficControllerPoolApiLiveTest.java @@ -30,7 +30,7 @@ import static org.testng.Assert.fail; import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; -import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.domain.PoolRecordSpec; import org.jclouds.ultradns.ws.domain.TrafficControllerPool; import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord; @@ -53,7 +53,7 @@ import com.google.common.collect.ImmutableSet; public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { private String zoneName = System.getProperty("user.name").replace('.', '-') + ".tcpool.ultradnstest.jclouds.org."; - private Account account; + private IdAndName account; @Override @BeforeClass(groups = { "integration", "live" }) diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java index 3c4df6aa61..af31d52cdc 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java @@ -29,7 +29,7 @@ import static org.testng.Assert.fail; import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; -import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.domain.Zone; import org.jclouds.ultradns.ws.domain.Zone.Type; import org.jclouds.ultradns.ws.domain.ZoneProperties; @@ -45,7 +45,7 @@ import com.google.common.collect.FluentIterable; @Test(groups = "live", testName = "ZoneApiLiveTest") public class ZoneApiLiveTest extends BaseUltraDNSWSApiLiveTest { - private Account account; + private IdAndName account; @Override @BeforeClass(groups = { "integration", "live" }) diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java index 5957eb2965..dc87545aae 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java @@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.xml.AccountHandler; import org.testng.annotations.Test; @@ -36,16 +36,16 @@ public class GetAccountsListOfUserResponseTest extends BaseHandlerTest { public void test() { InputStream is = getClass().getResourceAsStream("/account.xml"); - Account expected = expected(); + IdAndName expected = expected(); AccountHandler handler = injector.getInstance(AccountHandler.class); - Account result = factory.create(handler).parse(is); + IdAndName result = factory.create(handler).parse(is); assertEquals(result, expected); } - public Account expected() { - return Account.fromIdAndName("AAAAAAAAAAAAAAAA", "jclouds"); + public IdAndName expected() { + return IdAndName.fromIdAndName("AAAAAAAAAAAAAAAA", "jclouds"); } } diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAvailableRegionsResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAvailableRegionsResponseTest.java index 303ab7c640..20f560c6ba 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAvailableRegionsResponseTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAvailableRegionsResponseTest.java @@ -18,18 +18,19 @@ */ package org.jclouds.ultradns.ws.parse; +import static org.jclouds.ultradns.ws.domain.IdAndName.fromIdAndName; import static org.testng.Assert.assertEquals; import java.io.InputStream; -import java.util.Map; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.domain.IdAndName; import org.jclouds.ultradns.ws.xml.RegionListHandler; import org.testng.annotations.Test; -import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; /** * @author Adrian Cole @@ -40,26 +41,22 @@ public class GetAvailableRegionsResponseTest extends BaseHandlerTest { public void test() { InputStream is = getClass().getResourceAsStream("/regions.xml"); - Map expected = expected(); + Multimap expected = expected(); RegionListHandler handler = injector.getInstance(RegionListHandler.class); - Map result = factory.create(handler).parse(is); + Multimap result = factory.create(handler).parse(is); assertEquals(result.toString(), expected.toString()); } - public Map expected() { - return ImmutableMap. builder() - .put(14, Region.builder() - .name("Anonymous Proxy (A1)") - .addTerritoryName("Anonymous Proxy").build()) - .put(3, Region.builder() - .name("Antarctica") - .territoryNames(ImmutableSet. builder() - .add("Antarctica") - .add("Bouvet Island") - .add("French Southern Territories").build()) - .build()) + public Multimap expected() { + return ImmutableMultimap. builder() + .put(fromIdAndName("14", "Anonymous Proxy (A1)"), "Anonymous Proxy") + .putAll(fromIdAndName("3", "Antarctica"), ImmutableSet. builder() + .add("Antarctica") + .add("Bouvet Island") + .add("French Southern Territories") + .build()) .build(); } } diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSGroupDetailsResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSGroupDetailsResponseTest.java index 85ff3bfc63..2f84f3c3fa 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSGroupDetailsResponseTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSGroupDetailsResponseTest.java @@ -23,11 +23,12 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; -import org.jclouds.ultradns.ws.domain.Region; +import org.jclouds.ultradns.ws.domain.DirectionalGroup; import org.jclouds.ultradns.ws.xml.DirectionalGroupNameAndRegionsHandler; import org.testng.annotations.Test; +import com.google.common.collect.ImmutableList; + /** * @author Adrian Cole */ @@ -37,27 +38,22 @@ public class GetDirectionalDNSGroupDetailsResponseTest extends BaseHandlerTest { public void test() { InputStream is = getClass().getResourceAsStream("/directionalgroup.xml"); - DirectionalGroupNameAndRegions expected = expected(); + DirectionalGroup expected = expected(); DirectionalGroupNameAndRegionsHandler handler = injector.getInstance(DirectionalGroupNameAndRegionsHandler.class); - DirectionalGroupNameAndRegions result = factory.create(handler).parse(is); + DirectionalGroup result = factory.create(handler).parse(is); assertEquals(result.toString(), expected.toString()); } - public DirectionalGroupNameAndRegions expected() { - return DirectionalGroupNameAndRegions.builder() - .name("NON-EU") - .addRegion(Region.builder() - .name("Anonymous Proxy (A1)") - .addTerritoryName("Anonymous Proxy").build()) - .addRegion(Region.builder() - .name("Mexico") - .addTerritoryName("Mexico").build()) - .addRegion(Region.builder() - .name("Antarctica") - .addTerritoryName("Bouvet Island") - .addTerritoryName("French Southern Territories") - .addTerritoryName("Antarctica").build()).build(); + public DirectionalGroup expected() { + return DirectionalGroup.builder() + .name("NON-EU") + .mapRegionToTerritory("Anonymous Proxy (A1)", "Anonymous Proxy") + .mapRegionToTerritory("Mexico", "Mexico") + .mapRegionToTerritories("Antarctica", ImmutableList. builder() + .add("Bouvet Island") + .add("French Southern Territories") + .add("Antarctica").build()).build(); } } \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSRecordsForHostResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSRecordsForHostResponseTest.java index fecda7e0e7..26b94865db 100644 --- a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSRecordsForHostResponseTest.java +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSRecordsForHostResponseTest.java @@ -18,12 +18,12 @@ */ package org.jclouds.ultradns.ws.parse; +import static org.jclouds.ultradns.ws.domain.IdAndName.fromIdAndName; import static org.testng.Assert.assertEquals; import java.io.InputStream; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.ultradns.ws.domain.DirectionalGroup; import org.jclouds.ultradns.ws.domain.DirectionalRecord; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.xml.DirectionalRecordDetailListHandler; @@ -55,10 +55,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest .zoneName("geo.jclouds.org.") .name("www.geo.jclouds.org.") .id("A000000000000001") - .geolocationGroup(DirectionalGroup.builder() - .id("C000000000000001") - .name("southamerica") - .build()) + .geolocationGroup(fromIdAndName("C000000000000001", "southamerica")) .record(DirectionalRecord.drBuilder() .type("CNAME") .ttl(300) @@ -68,10 +65,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest .zoneName("geo.jclouds.org.") .name("www.geo.jclouds.org.") .id("A000000000000002") - .group(DirectionalGroup.builder() - .id("B000000000000001") - .name("All Non-Configured Regions") - .build()) + .group(fromIdAndName("B000000000000001", "All Non-Configured Regions")) .record(DirectionalRecord.drBuilder() .type("A") .ttl(500) @@ -81,10 +75,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest .zoneName("geo.jclouds.org.") .name("www.geo.jclouds.org.") .id("A000000000000003") - .geolocationGroup(DirectionalGroup.builder() - .id("C000000000000002") - .name("antarctica-unsupported") - .build()) + .geolocationGroup(fromIdAndName("C000000000000002", "antarctica-unsupported")) .record(DirectionalRecord.drBuilder() .type("A") .ttl(0) @@ -94,10 +85,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest .zoneName("geo.jclouds.org.") .name("www.geo.jclouds.org.") .id("A000000000000004") - .geolocationGroup(DirectionalGroup.builder() - .id("C000000000000003") - .name("alazona") - .build()) + .geolocationGroup(fromIdAndName("C000000000000003", "alazona")) .record(DirectionalRecord.drBuilder() .type("A") .ttl(86400) // default