converted RegionToTerritories to a multimap and normalized use of IdAndName

This commit is contained in:
adriancole 2013-04-15 11:05:11 -07:00
parent 25a0b73436
commit 8c18f3ba1b
23 changed files with 193 additions and 428 deletions

View File

@ -19,7 +19,6 @@
package org.jclouds.ultradns.ws; package org.jclouds.ultradns.ws;
import java.io.Closeable; import java.io.Closeable;
import java.util.Map;
import javax.inject.Named; import javax.inject.Named;
import javax.ws.rs.POST; 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.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.ultradns.ws.domain.Account; import org.jclouds.ultradns.ws.domain.IdAndName;
import org.jclouds.ultradns.ws.domain.Region;
import org.jclouds.ultradns.ws.features.DirectionalGroupApi; import org.jclouds.ultradns.ws.features.DirectionalGroupApi;
import org.jclouds.ultradns.ws.features.DirectionalPoolApi; import org.jclouds.ultradns.ws.features.DirectionalPoolApi;
import org.jclouds.ultradns.ws.features.ResourceRecordApi; 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.AccountHandler;
import org.jclouds.ultradns.ws.xml.RegionListHandler; import org.jclouds.ultradns.ws.xml.RegionListHandler;
import com.google.common.collect.Multimap;
/** /**
* Provides access to Neustar UltraDNS via the SOAP API * Provides access to Neustar UltraDNS via the SOAP API
* <p/> * <p/>
@ -60,7 +60,7 @@ public interface UltraDNSWSApi extends Closeable {
@POST @POST
@XMLResponseParser(AccountHandler.class) @XMLResponseParser(AccountHandler.class)
@Payload("<v01:getAccountsListOfUser/>") @Payload("<v01:getAccountsListOfUser/>")
Account getCurrentAccount(); IdAndName getCurrentAccount();
/** /**
* Lists the directional regions available in the account. * Lists the directional regions available in the account.
@ -69,7 +69,7 @@ public interface UltraDNSWSApi extends Closeable {
@POST @POST
@XMLResponseParser(RegionListHandler.class) @XMLResponseParser(RegionListHandler.class)
@Payload("<v01:getAvailableRegions/>") @Payload("<v01:getAvailableRegions/>")
Map<Integer, Region> getRegionsById(); Multimap<IdAndName, String> getRegionsById();
/** /**
* Provides access to Zone features. * Provides access to Zone features.

View File

@ -23,30 +23,49 @@ import static com.google.common.base.Objects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Objects; 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 * @author Adrian Cole
*/ */
public class DirectionalGroup { public class DirectionalGroup extends ForwardingMultimap<String, String> {
private final String id;
private final String name; private final String name;
private final Optional<String> description;
private final Multimap<String, String> regionToTerritories;
private DirectionalGroup(String id, String name) { private DirectionalGroup(String name, Optional<String> description,
this.id = checkNotNull(id, "id"); Multimap<String, String> regionToTerritories) {
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
} this.description = checkNotNull(description, "description of %s", name);
this.regionToTerritories = checkNotNull(regionToTerritories, "regionToTerritories of %s", name);
public String getId() {
return id;
} }
public String getName() { public String getName() {
return name; return name;
} }
public Optional<String> getDescription() {
return description;
}
public Multimap<String, String> getRegionToTerritories() {
return regionToTerritories;
}
@Override
protected Multimap<String, String> delegate() {
return regionToTerritories;
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(id, name); return Objects.hashCode(name, regionToTerritories);
} }
@Override @Override
@ -56,12 +75,13 @@ public class DirectionalGroup {
if (obj == null || getClass() != obj.getClass()) if (obj == null || getClass() != obj.getClass())
return false; return false;
DirectionalGroup that = DirectionalGroup.class.cast(obj); 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 @Override
public String toString() { 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() { public static Builder builder() {
@ -73,16 +93,10 @@ public class DirectionalGroup {
} }
public final static class Builder { public final static class Builder {
private String id;
private String name; private String name;
private Optional<String> description = Optional.absent();
/** private ImmutableMultimap.Builder<String, String> regionToTerritories = ImmutableMultimap
* @see DirectionalGroup#getId() .<String, String> builder();
*/
public Builder id(String id) {
this.id = id;
return this;
}
/** /**
* @see DirectionalGroup#getName() * @see DirectionalGroup#getName()
@ -92,12 +106,50 @@ public class DirectionalGroup {
return this; 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<String> 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<String, String> regionToTerritories) {
this.regionToTerritories = ImmutableMultimap.<String, String> builder().putAll(regionToTerritories);
return this;
}
public DirectionalGroup build() { public DirectionalGroup build() {
return new DirectionalGroup(id, name); return new DirectionalGroup(name, description, regionToTerritories.build());
} }
public Builder from(DirectionalGroup in) { public Builder from(DirectionalGroup in) {
return id(in.id).name(in.name); return name(in.getName()).regionToTerritories(in.getRegionToTerritories());
} }
} }
} }

View File

@ -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<Region> {
private final String name;
private final Set<Region> regions;
private DirectionalGroupNameAndRegions(String name, Set<Region> regions) {
this.name = checkNotNull(name, "name");
this.regions = checkNotNull(regions, "regions of %s", name);
}
public String getName() {
return name;
}
public Set<Region> getRegions() {
return regions;
}
@Override
protected Set<Region> 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<Region> regions = ImmutableSet.<Region> 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<Region> regions) {
this.regions = ImmutableSet.<Region> 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());
}
}
}

View File

@ -33,14 +33,14 @@ public class DirectionalRecordDetail {
private final String zoneName; private final String zoneName;
private final String name; private final String name;
private final String id; private final String id;
private final Optional<DirectionalGroup> group; private final Optional<IdAndName> group;
private final Optional<DirectionalGroup> geolocationGroup; private final Optional<IdAndName> geolocationGroup;
private final Optional<DirectionalGroup> sourceIpGroup; private final Optional<IdAndName> sourceIpGroup;
private final DirectionalRecord record; private final DirectionalRecord record;
private DirectionalRecordDetail(String zoneName, String name, String id, private DirectionalRecordDetail(String zoneName, String name, String id,
Optional<DirectionalGroup> group, Optional<DirectionalGroup> geolocationGroup, Optional<IdAndName> group, Optional<IdAndName> geolocationGroup,
Optional<DirectionalGroup> sourceIpGroup, DirectionalRecord record) { Optional<IdAndName> sourceIpGroup, DirectionalRecord record) {
this.zoneName = checkNotNull(zoneName, "zoneName"); this.zoneName = checkNotNull(zoneName, "zoneName");
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.id = checkNotNull(id, "id"); 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()} * group containing all regions that you have not specifically configured in {@link #getGeolocationGroup()}
*/ */
public Optional<DirectionalGroup> getGroup() { public Optional<IdAndName> getGroup() {
return group; return group;
} }
/** /**
* group containing territories. * group containing territories.
*/ */
public Optional<DirectionalGroup> getGeolocationGroup() { public Optional<IdAndName> getGeolocationGroup() {
return geolocationGroup; return geolocationGroup;
} }
/** /**
* group containing IPV4 or IPV6 ranges. * group containing IPV4 or IPV6 ranges.
*/ */
public Optional<DirectionalGroup> getSourceIpGroup() { public Optional<IdAndName> getSourceIpGroup() {
return sourceIpGroup; return sourceIpGroup;
} }
@ -121,9 +121,9 @@ public class DirectionalRecordDetail {
private String zoneName; private String zoneName;
private String name; private String name;
private String id; private String id;
private Optional<DirectionalGroup> group = Optional.absent(); private Optional<IdAndName> group = Optional.absent();
private Optional<DirectionalGroup> geolocationGroup = Optional.absent(); private Optional<IdAndName> geolocationGroup = Optional.absent();
private Optional<DirectionalGroup> sourceIpGroup = Optional.absent(); private Optional<IdAndName> sourceIpGroup = Optional.absent();
private DirectionalRecord record; private DirectionalRecord record;
/** /**
@ -153,7 +153,7 @@ public class DirectionalRecordDetail {
/** /**
* @see DirectionalRecordDetail#getGroup() * @see DirectionalRecordDetail#getGroup()
*/ */
public Builder group(DirectionalGroup group) { public Builder group(IdAndName group) {
this.group = Optional.fromNullable(group); this.group = Optional.fromNullable(group);
return this; return this;
} }
@ -161,7 +161,7 @@ public class DirectionalRecordDetail {
/** /**
* @see DirectionalRecordDetail#getGeolocationGroup() * @see DirectionalRecordDetail#getGeolocationGroup()
*/ */
public Builder geolocationGroup(DirectionalGroup geolocationGroup) { public Builder geolocationGroup(IdAndName geolocationGroup) {
this.geolocationGroup = Optional.fromNullable(geolocationGroup); this.geolocationGroup = Optional.fromNullable(geolocationGroup);
return this; return this;
} }
@ -169,7 +169,7 @@ public class DirectionalRecordDetail {
/** /**
* @see DirectionalRecordDetail#getSourceIpGroup() * @see DirectionalRecordDetail#getSourceIpGroup()
*/ */
public Builder sourceIpGroup(DirectionalGroup sourceIpGroup) { public Builder sourceIpGroup(IdAndName sourceIpGroup) {
this.sourceIpGroup = Optional.fromNullable(sourceIpGroup); this.sourceIpGroup = Optional.fromNullable(sourceIpGroup);
return this; return this;
} }

View File

@ -25,28 +25,28 @@ import com.google.common.base.Objects;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public final class Account { public final class IdAndName {
public static Account fromIdAndName(String id, String name) { public static IdAndName fromIdAndName(String id, String name) {
return new Account(id, name); return new IdAndName(id, name);
} }
private final String id; private final String id;
private final String name; private final String name;
private Account(String id, String name) { private IdAndName(String id, String name) {
this.id = checkNotNull(id, "id"); this.id = checkNotNull(id, "id");
this.name = checkNotNull(name, "name for %s", 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() { public String getId() {
return id; return id;
} }
/** /**
* The name of the account. ex {@code jclouds} * The name of the resource. ex {@code jclouds}
*/ */
public String getName() { public String getName() {
return name; return name;
@ -65,7 +65,7 @@ public final class Account {
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; 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); return Objects.equal(this.id, that.id) && Objects.equal(this.name, that.name);
} }

View File

@ -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<String> {
private final String name;
private final Set<String> territoryNames;
private Region(String name, Set<String> territoryNames) {
this.name = checkNotNull(name, "name");
this.territoryNames = checkNotNull(territoryNames, "territoryNames of %s", name);
}
public String getName() {
return name;
}
public Set<String> getTerritoryNames() {
return territoryNames;
}
@Override
protected Set<String> 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<String> territoryNames = ImmutableSet.<String> 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<String> territoryNames) {
this.territoryNames = ImmutableSet.<String> 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());
}
}
}

View File

@ -36,7 +36,6 @@ import org.jclouds.ultradns.ws.binders.DirectionalGroupCoordinatesToXML;
import org.jclouds.ultradns.ws.domain.AccountLevelGroup; import org.jclouds.ultradns.ws.domain.AccountLevelGroup;
import org.jclouds.ultradns.ws.domain.DirectionalGroup; import org.jclouds.ultradns.ws.domain.DirectionalGroup;
import org.jclouds.ultradns.ws.domain.DirectionalGroupCoordinates; 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.domain.DirectionalRecordDetail;
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
import org.jclouds.ultradns.ws.xml.AccountLevelGroupsHandler; import org.jclouds.ultradns.ws.xml.AccountLevelGroupsHandler;
@ -68,7 +67,7 @@ public interface DirectionalGroupApi {
@Fallback(NullOnNotFoundOr404.class) @Fallback(NullOnNotFoundOr404.class)
@Payload("<v01:getDirectionalDNSGroupDetails><GroupId>{GroupId}</GroupId></v01:getDirectionalDNSGroupDetails>") @Payload("<v01:getDirectionalDNSGroupDetails><GroupId>{GroupId}</GroupId></v01:getDirectionalDNSGroupDetails>")
@Nullable @Nullable
DirectionalGroupNameAndRegions get(@PayloadParam("GroupId") String groupId); DirectionalGroup get(@PayloadParam("GroupId") String groupId);
/** /**
* Returns all account-level groups. * Returns all account-level groups.

View File

@ -82,7 +82,7 @@ public interface RoundRobinPoolApi {
* @param hostname * @param hostname
* {@link RoundRobinPool#getDName() dname} of the RR pool {ex. * {@link RoundRobinPool#getDName() dname} of the RR pool {ex.
* www.jclouds.org.} * www.jclouds.org.}
* @return the {@code guid} of the new record * @return the {@code guid} of the new pool
* @throws ResourceAlreadyExistsException * @throws ResourceAlreadyExistsException
* if a pool already exists with the same attrs * if a pool already exists with the same attrs
*/ */

View File

@ -24,19 +24,19 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
import org.jclouds.http.functions.ParseSax; 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; import org.xml.sax.Attributes;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class AccountHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Account> { public class AccountHandler extends ParseSax.HandlerForGeneratedRequestWithResult<IdAndName> {
private Account account; private IdAndName account;
@Override @Override
public Account getResult() { public IdAndName getResult() {
try { try {
return account; return account;
} finally { } finally {
@ -48,7 +48,7 @@ public class AccountHandler extends ParseSax.HandlerForGeneratedRequestWithResul
public void startElement(String uri, String localName, String qName, Attributes attrs) { public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (equalsOrSuffix(qName, "AccountDetailsData")) { if (equalsOrSuffix(qName, "AccountDetailsData")) {
account = Account.fromIdAndName(attributes.get("accountID"), attributes.get("accountName")); account = IdAndName.fromIdAndName(attributes.get("accountID"), attributes.get("accountName"));
} }
} }
} }

View File

@ -21,9 +21,8 @@ package org.jclouds.ultradns.ws.xml;
import static org.jclouds.util.SaxUtils.equalsOrSuffix; import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; import org.jclouds.ultradns.ws.domain.DirectionalGroup;
import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions.Builder; import org.jclouds.ultradns.ws.domain.DirectionalGroup.Builder;
import org.jclouds.ultradns.ws.domain.Region;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -32,12 +31,12 @@ import com.google.common.base.Splitter;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class DirectionalGroupNameAndRegionsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<DirectionalGroupNameAndRegions> { public class DirectionalGroupNameAndRegionsHandler extends ParseSax.HandlerForGeneratedRequestWithResult<DirectionalGroup> {
private final Builder group = DirectionalGroupNameAndRegions.builder(); private final Builder group = DirectionalGroup.builder();
@Override @Override
public DirectionalGroupNameAndRegions getResult() { public DirectionalGroup getResult() {
return group.build(); return group.build();
} }
@ -46,11 +45,9 @@ public class DirectionalGroupNameAndRegionsHandler extends ParseSax.HandlerForGe
if (equalsOrSuffix(qName, "DirectionalDNSGroupDetail")) { if (equalsOrSuffix(qName, "DirectionalDNSGroupDetail")) {
group.name(attrs.getValue("GroupName")); group.name(attrs.getValue("GroupName"));
} else if (equalsOrSuffix(qName, "RegionForNewGroups")) { } else if (equalsOrSuffix(qName, "RegionForNewGroups")) {
String regionName = attrs.getValue("RegionName");
Iterable<String> territories = Splitter.on(';').split(attrs.getValue("TerritoryName")); Iterable<String> territories = Splitter.on(';').split(attrs.getValue("TerritoryName"));
Region region = Region.builder() group.mapRegionToTerritories(regionName, territories);
.name(attrs.getValue("RegionName"))
.territoryNames(territories).build();
group.addRegion(region);
} }
} }
} }

View File

@ -24,7 +24,7 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
import org.jclouds.http.functions.ParseSax; 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.DirectionalRecord;
import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -64,19 +64,14 @@ public class DirectionalRecordDetailHandler extends
drd.id(attributes.get("DirPoolRecordId")); drd.id(attributes.get("DirPoolRecordId"));
} }
if (attributes.containsKey("GroupId")) { if (attributes.containsKey("GroupId")) {
drd.group(DirectionalGroup.builder() drd.group(fromIdAndName(attributes.get("GroupId"), attributes.get("GroupName")));
.id(attributes.get("GroupId"))
.name(attributes.get("GroupName")).build());
} }
if (attributes.containsKey("GeolocationGroupId")) { if (attributes.containsKey("GeolocationGroupId")) {
drd.geolocationGroup(DirectionalGroup.builder() drd.geolocationGroup(fromIdAndName(attributes.get("GeolocationGroupId"),
.id(attributes.get("GeolocationGroupId")) attributes.get("GeolocationGroupName")));
.name(attributes.get("GeolocationGroupName")).build());
} }
if (attributes.containsKey("SourceIPGroupId")) { if (attributes.containsKey("SourceIPGroupId")) {
drd.sourceIpGroup(DirectionalGroup.builder() drd.sourceIpGroup(fromIdAndName(attributes.get("SourceIPGroupId"), attributes.get("SourceIPGroupName")));
.id(attributes.get("SourceIPGroupId"))
.name(attributes.get("SourceIPGroupName")).build());
} }
if (attributes.containsKey("recordType")) { if (attributes.containsKey("recordType")) {
dr.type(attributes.get("recordType")); dr.type(attributes.get("recordType"));

View File

@ -24,23 +24,24 @@ import static org.jclouds.util.SaxUtils.equalsOrSuffix;
import java.util.Map; import java.util.Map;
import org.jclouds.http.functions.ParseSax; 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 org.xml.sax.Attributes;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableMap.Builder; import com.google.common.collect.ImmutableMultimap.Builder;
import com.google.common.collect.Multimap;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class RegionListHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Map<Integer, Region>> { public class RegionListHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Multimap<IdAndName, String>> {
private final Builder<Integer, Region> regions = ImmutableMap.<Integer, Region> builder(); private final Builder<IdAndName, String> regions = ImmutableMultimap.<IdAndName, String> builder();
@Override @Override
public Map<Integer, Region> getResult() { public Multimap<IdAndName, String> getResult() {
return regions.build(); return regions.build();
} }
@ -48,12 +49,8 @@ public class RegionListHandler extends ParseSax.HandlerForGeneratedRequestWithRe
public void startElement(String url, String name, String qName, Attributes attrs) { public void startElement(String url, String name, String qName, Attributes attrs) {
if (equalsOrSuffix(qName, "Region")) { if (equalsOrSuffix(qName, "Region")) {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
int id = Integer.parseInt(attributes.get("RegionID")); IdAndName region = IdAndName.fromIdAndName(attributes.get("RegionID"), attributes.get("RegionName"));
Iterable<String> territories = Splitter.on(';').split(attributes.get("TerritoryName")); regions.putAll(region, Splitter.on(';').split(attributes.get("TerritoryName")));
Region region = Region.builder()
.name(attributes.get("RegionName"))
.territoryNames(territories).build();
regions.put(id, region);
} }
} }
} }

View File

@ -20,12 +20,11 @@ package org.jclouds.ultradns.ws;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.Collection;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.jclouds.ultradns.ws.domain.Account; import org.jclouds.ultradns.ws.domain.IdAndName;
import org.jclouds.ultradns.ws.domain.Region;
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -37,26 +36,26 @@ public class UltraDNSWSApiLiveTest extends BaseUltraDNSWSApiLiveTest {
@Test @Test
protected void testGetCurrentAccount() { protected void testGetCurrentAccount() {
Account account = api.getCurrentAccount(); IdAndName account = api.getCurrentAccount();
checkAccount(account); checkAccount(account);
} }
private void checkAccount(Account account) { private void checkAccount(IdAndName account) {
assertNotNull(account.getId(), "Id cannot be null for " + account); assertNotNull(account.getId(), "Id cannot be null for " + account);
assertNotNull(account.getName(), "Name cannot be null for " + account); assertNotNull(account.getName(), "Name cannot be null for " + account);
} }
@Test @Test
public void testListRegions() { public void testListRegions() {
for (Entry<Integer, Region> region : api.getRegionsById().entrySet()) { for (Entry<IdAndName, Collection<String>> region : api.getRegionsById().asMap().entrySet()) {
checkRegion(region); checkRegion(region);
} }
} }
private void checkRegion(Entry<Integer, Region> region) { private void checkRegion(Entry<IdAndName, Collection<String>> region) {
assertTrue(region.getKey() > 0, "Id cannot be negative " + region); assertNotNull(region.getKey().getId(), "Id cannot be null " + region);
assertNotNull(region.getValue().getName(), "Name cannot be null " + region); assertNotNull(region.getKey().getName(), "Name cannot be null " + region);
assertNotNull(region.getValue().getTerritoryNames(), "TerritoryNames cannot be null " + region); assertNotNull(region.getValue(), "TerritoryNames cannot be null " + region);
assertFalse(region.getValue().getTerritoryNames().isEmpty(), "TerritoryNames cannot be empty " + region); assertFalse(region.getValue().isEmpty(), "TerritoryNames cannot be empty " + region);
} }
} }

View File

@ -26,10 +26,10 @@ import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import org.jclouds.rest.ResourceNotFoundException; 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.AccountLevelGroup;
import org.jclouds.ultradns.ws.domain.DirectionalGroupCoordinates; 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.DirectionalPool;
import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail;
import org.jclouds.ultradns.ws.domain.DirectionalRecordType; import org.jclouds.ultradns.ws.domain.DirectionalRecordType;
@ -46,7 +46,7 @@ import com.google.common.collect.Sets;
@Test(groups = "live", singleThreaded = true, testName = "DirectionalGroupApiLiveTest") @Test(groups = "live", singleThreaded = true, testName = "DirectionalGroupApiLiveTest")
public class DirectionalGroupApiLiveTest extends BaseUltraDNSWSApiLiveTest { public class DirectionalGroupApiLiveTest extends BaseUltraDNSWSApiLiveTest {
private Account account; private IdAndName account;
@Override @Override
@BeforeClass(groups = { "integration", "live" }) @BeforeClass(groups = { "integration", "live" })
@ -81,7 +81,7 @@ public class DirectionalGroupApiLiveTest extends BaseUltraDNSWSApiLiveTest {
@Test @Test
public void testGetDirectionalGroup() { public void testGetDirectionalGroup() {
for (AccountLevelGroup group : api().listAccountLevelGroups()) { for (AccountLevelGroup group : api().listAccountLevelGroups()) {
DirectionalGroupNameAndRegions withRegions = api().get(group.getId()); DirectionalGroup withRegions = api().get(group.getId());
assertEquals(withRegions.getName(), group.getName()); assertEquals(withRegions.getName(), group.getName());
assertTrue(withRegions.size() > 0); assertTrue(withRegions.size() > 0);
} }

View File

@ -27,12 +27,11 @@ import java.util.EnumSet;
import java.util.Set; import java.util.Set;
import org.jclouds.rest.ResourceNotFoundException; 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.DirectionalPool;
import org.jclouds.ultradns.ws.domain.DirectionalRecord; import org.jclouds.ultradns.ws.domain.DirectionalRecord;
import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail;
import org.jclouds.ultradns.ws.domain.DirectionalRecordType; 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.domain.Zone;
import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
@ -49,7 +48,7 @@ import com.google.common.collect.Sets;
@Test(groups = "live", singleThreaded = true, testName = "DirectionalPoolApiLiveTest") @Test(groups = "live", singleThreaded = true, testName = "DirectionalPoolApiLiveTest")
public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
private Account account; private IdAndName account;
@Override @Override
@BeforeClass(groups = { "integration", "live" }) @BeforeClass(groups = { "integration", "live" })
@ -76,7 +75,7 @@ public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
assertNotNull(pool.getTieBreak(), "TieBreak cannot be null " + pool); assertNotNull(pool.getTieBreak(), "TieBreak cannot be null " + pool);
} }
Set<DirectionalGroup> allDirectionalGroups = Sets.newLinkedHashSet(); Set<IdAndName> allDirectionalGroups = Sets.newLinkedHashSet();
@Test @Test
public void testListDirectionalRecords() { public void testListDirectionalRecords() {
@ -86,10 +85,10 @@ public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
for (DirectionalRecordDetail rr : api(zone.getName()) for (DirectionalRecordDetail rr : api(zone.getName())
.listRecordsByNameAndType(pool.getName(), type.getCode())) { .listRecordsByNameAndType(pool.getName(), type.getCode())) {
checkDirectionalRecordDetail(rr); checkDirectionalRecordDetail(rr);
Iterable<DirectionalGroup> groups = Optional.presentInstances(ImmutableSet.of(rr.getGroup(), Iterable<IdAndName> groups = Optional.presentInstances(ImmutableSet.of(rr.getGroup(),
rr.getGeolocationGroup(), rr.getGeolocationGroup())); rr.getGeolocationGroup(), rr.getGeolocationGroup()));
assertFalse(Iterables.isEmpty(groups), "No groups " + rr); assertFalse(Iterables.isEmpty(groups), "No groups " + rr);
for (DirectionalGroup group : groups) { for (IdAndName group : groups) {
allDirectionalGroups.add(group); allDirectionalGroups.add(group);
assertNotNull(group.getId(), "Id cannot be null " + group); assertNotNull(group.getId(), "Id cannot be null " + group);
assertNotNull(group.getName(), "Name cannot be null " + group); assertNotNull(group.getName(), "Name cannot be null " + group);

View File

@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicLong;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; 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.ResourceRecord;
import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata;
import org.jclouds.ultradns.ws.domain.Zone; import org.jclouds.ultradns.ws.domain.Zone;
@ -53,7 +53,7 @@ import com.google.common.collect.FluentIterable;
public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest { public class ResourceRecordApiLiveTest extends BaseUltraDNSWSApiLiveTest {
private String zoneName = System.getProperty("user.name").replace('.', '-') + ".rr.ultradnstest.jclouds.org."; private String zoneName = System.getProperty("user.name").replace('.', '-') + ".rr.ultradnstest.jclouds.org.";
private Account account; private IdAndName account;
@Override @Override
@BeforeClass(groups = { "integration", "live" }) @BeforeClass(groups = { "integration", "live" })

View File

@ -29,7 +29,7 @@ import static org.testng.Assert.fail;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; 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.ResourceRecord;
import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata; import org.jclouds.ultradns.ws.domain.ResourceRecordMetadata;
import org.jclouds.ultradns.ws.domain.RoundRobinPool; import org.jclouds.ultradns.ws.domain.RoundRobinPool;
@ -50,7 +50,7 @@ import com.google.common.collect.FluentIterable;
public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { public class RoundRobinPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
private String zoneName = System.getProperty("user.name").replace('.', '-') + ".rrpool.ultradnstest.jclouds.org."; private String zoneName = System.getProperty("user.name").replace('.', '-') + ".rrpool.ultradnstest.jclouds.org.";
private Account account; private IdAndName account;
@Override @Override
@BeforeClass(groups = { "integration", "live" }) @BeforeClass(groups = { "integration", "live" })

View File

@ -30,7 +30,7 @@ import static org.testng.Assert.fail;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; 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.PoolRecordSpec;
import org.jclouds.ultradns.ws.domain.TrafficControllerPool; import org.jclouds.ultradns.ws.domain.TrafficControllerPool;
import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord; import org.jclouds.ultradns.ws.domain.TrafficControllerPoolRecord;
@ -53,7 +53,7 @@ import com.google.common.collect.ImmutableSet;
public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { public class TrafficControllerPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest {
private String zoneName = System.getProperty("user.name").replace('.', '-') + ".tcpool.ultradnstest.jclouds.org."; private String zoneName = System.getProperty("user.name").replace('.', '-') + ".tcpool.ultradnstest.jclouds.org.";
private Account account; private IdAndName account;
@Override @Override
@BeforeClass(groups = { "integration", "live" }) @BeforeClass(groups = { "integration", "live" })

View File

@ -29,7 +29,7 @@ import static org.testng.Assert.fail;
import org.jclouds.rest.ResourceNotFoundException; import org.jclouds.rest.ResourceNotFoundException;
import org.jclouds.ultradns.ws.UltraDNSWSExceptions.ResourceAlreadyExistsException; 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;
import org.jclouds.ultradns.ws.domain.Zone.Type; import org.jclouds.ultradns.ws.domain.Zone.Type;
import org.jclouds.ultradns.ws.domain.ZoneProperties; import org.jclouds.ultradns.ws.domain.ZoneProperties;
@ -45,7 +45,7 @@ import com.google.common.collect.FluentIterable;
@Test(groups = "live", testName = "ZoneApiLiveTest") @Test(groups = "live", testName = "ZoneApiLiveTest")
public class ZoneApiLiveTest extends BaseUltraDNSWSApiLiveTest { public class ZoneApiLiveTest extends BaseUltraDNSWSApiLiveTest {
private Account account; private IdAndName account;
@Override @Override
@BeforeClass(groups = { "integration", "live" }) @BeforeClass(groups = { "integration", "live" })

View File

@ -23,7 +23,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; 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.jclouds.ultradns.ws.xml.AccountHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -36,16 +36,16 @@ public class GetAccountsListOfUserResponseTest extends BaseHandlerTest {
public void test() { public void test() {
InputStream is = getClass().getResourceAsStream("/account.xml"); InputStream is = getClass().getResourceAsStream("/account.xml");
Account expected = expected(); IdAndName expected = expected();
AccountHandler handler = injector.getInstance(AccountHandler.class); AccountHandler handler = injector.getInstance(AccountHandler.class);
Account result = factory.create(handler).parse(is); IdAndName result = factory.create(handler).parse(is);
assertEquals(result, expected); assertEquals(result, expected);
} }
public Account expected() { public IdAndName expected() {
return Account.fromIdAndName("AAAAAAAAAAAAAAAA", "jclouds"); return IdAndName.fromIdAndName("AAAAAAAAAAAAAAAA", "jclouds");
} }
} }

View File

@ -18,18 +18,19 @@
*/ */
package org.jclouds.ultradns.ws.parse; package org.jclouds.ultradns.ws.parse;
import static org.jclouds.ultradns.ws.domain.IdAndName.fromIdAndName;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.util.Map;
import org.jclouds.http.functions.BaseHandlerTest; 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.jclouds.ultradns.ws.xml.RegionListHandler;
import org.testng.annotations.Test; 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.ImmutableSet;
import com.google.common.collect.Multimap;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -40,26 +41,22 @@ public class GetAvailableRegionsResponseTest extends BaseHandlerTest {
public void test() { public void test() {
InputStream is = getClass().getResourceAsStream("/regions.xml"); InputStream is = getClass().getResourceAsStream("/regions.xml");
Map<Integer, Region> expected = expected(); Multimap<IdAndName, String> expected = expected();
RegionListHandler handler = injector.getInstance(RegionListHandler.class); RegionListHandler handler = injector.getInstance(RegionListHandler.class);
Map<Integer, Region> result = factory.create(handler).parse(is); Multimap<IdAndName, String> result = factory.create(handler).parse(is);
assertEquals(result.toString(), expected.toString()); assertEquals(result.toString(), expected.toString());
} }
public Map<Integer, Region> expected() { public Multimap<IdAndName, String> expected() {
return ImmutableMap.<Integer, Region> builder() return ImmutableMultimap.<IdAndName, String> builder()
.put(14, Region.builder() .put(fromIdAndName("14", "Anonymous Proxy (A1)"), "Anonymous Proxy")
.name("Anonymous Proxy (A1)") .putAll(fromIdAndName("3", "Antarctica"), ImmutableSet.<String> builder()
.addTerritoryName("Anonymous Proxy").build()) .add("Antarctica")
.put(3, Region.builder() .add("Bouvet Island")
.name("Antarctica") .add("French Southern Territories")
.territoryNames(ImmutableSet.<String> builder() .build())
.add("Antarctica")
.add("Bouvet Island")
.add("French Southern Territories").build())
.build())
.build(); .build();
} }
} }

View File

@ -23,11 +23,12 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.ultradns.ws.domain.DirectionalGroupNameAndRegions; import org.jclouds.ultradns.ws.domain.DirectionalGroup;
import org.jclouds.ultradns.ws.domain.Region;
import org.jclouds.ultradns.ws.xml.DirectionalGroupNameAndRegionsHandler; import org.jclouds.ultradns.ws.xml.DirectionalGroupNameAndRegionsHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -37,27 +38,22 @@ public class GetDirectionalDNSGroupDetailsResponseTest extends BaseHandlerTest {
public void test() { public void test() {
InputStream is = getClass().getResourceAsStream("/directionalgroup.xml"); InputStream is = getClass().getResourceAsStream("/directionalgroup.xml");
DirectionalGroupNameAndRegions expected = expected(); DirectionalGroup expected = expected();
DirectionalGroupNameAndRegionsHandler handler = injector.getInstance(DirectionalGroupNameAndRegionsHandler.class); 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()); assertEquals(result.toString(), expected.toString());
} }
public DirectionalGroupNameAndRegions expected() { public DirectionalGroup expected() {
return DirectionalGroupNameAndRegions.builder() return DirectionalGroup.builder()
.name("NON-EU") .name("NON-EU")
.addRegion(Region.builder() .mapRegionToTerritory("Anonymous Proxy (A1)", "Anonymous Proxy")
.name("Anonymous Proxy (A1)") .mapRegionToTerritory("Mexico", "Mexico")
.addTerritoryName("Anonymous Proxy").build()) .mapRegionToTerritories("Antarctica", ImmutableList.<String> builder()
.addRegion(Region.builder() .add("Bouvet Island")
.name("Mexico") .add("French Southern Territories")
.addTerritoryName("Mexico").build()) .add("Antarctica").build()).build();
.addRegion(Region.builder()
.name("Antarctica")
.addTerritoryName("Bouvet Island")
.addTerritoryName("French Southern Territories")
.addTerritoryName("Antarctica").build()).build();
} }
} }

View File

@ -18,12 +18,12 @@
*/ */
package org.jclouds.ultradns.ws.parse; package org.jclouds.ultradns.ws.parse;
import static org.jclouds.ultradns.ws.domain.IdAndName.fromIdAndName;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; 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.DirectionalRecord;
import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail;
import org.jclouds.ultradns.ws.xml.DirectionalRecordDetailListHandler; import org.jclouds.ultradns.ws.xml.DirectionalRecordDetailListHandler;
@ -55,10 +55,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest
.zoneName("geo.jclouds.org.") .zoneName("geo.jclouds.org.")
.name("www.geo.jclouds.org.") .name("www.geo.jclouds.org.")
.id("A000000000000001") .id("A000000000000001")
.geolocationGroup(DirectionalGroup.builder() .geolocationGroup(fromIdAndName("C000000000000001", "southamerica"))
.id("C000000000000001")
.name("southamerica")
.build())
.record(DirectionalRecord.drBuilder() .record(DirectionalRecord.drBuilder()
.type("CNAME") .type("CNAME")
.ttl(300) .ttl(300)
@ -68,10 +65,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest
.zoneName("geo.jclouds.org.") .zoneName("geo.jclouds.org.")
.name("www.geo.jclouds.org.") .name("www.geo.jclouds.org.")
.id("A000000000000002") .id("A000000000000002")
.group(DirectionalGroup.builder() .group(fromIdAndName("B000000000000001", "All Non-Configured Regions"))
.id("B000000000000001")
.name("All Non-Configured Regions")
.build())
.record(DirectionalRecord.drBuilder() .record(DirectionalRecord.drBuilder()
.type("A") .type("A")
.ttl(500) .ttl(500)
@ -81,10 +75,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest
.zoneName("geo.jclouds.org.") .zoneName("geo.jclouds.org.")
.name("www.geo.jclouds.org.") .name("www.geo.jclouds.org.")
.id("A000000000000003") .id("A000000000000003")
.geolocationGroup(DirectionalGroup.builder() .geolocationGroup(fromIdAndName("C000000000000002", "antarctica-unsupported"))
.id("C000000000000002")
.name("antarctica-unsupported")
.build())
.record(DirectionalRecord.drBuilder() .record(DirectionalRecord.drBuilder()
.type("A") .type("A")
.ttl(0) .ttl(0)
@ -94,10 +85,7 @@ public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest
.zoneName("geo.jclouds.org.") .zoneName("geo.jclouds.org.")
.name("www.geo.jclouds.org.") .name("www.geo.jclouds.org.")
.id("A000000000000004") .id("A000000000000004")
.geolocationGroup(DirectionalGroup.builder() .geolocationGroup(fromIdAndName("C000000000000003", "alazona"))
.id("C000000000000003")
.name("alazona")
.build())
.record(DirectionalRecord.drBuilder() .record(DirectionalRecord.drBuilder()
.type("A") .type("A")
.ttl(86400) // default .ttl(86400) // default