From ec439c65b712673d603df707b6a536e076da41d8 Mon Sep 17 00:00:00 2001 From: adriancole Date: Sun, 7 Apr 2013 21:59:31 -0700 Subject: [PATCH] added ability to read directional pools and records in ultradns --- .../jclouds/ultradns/ws/UltraDNSWSApi.java | 13 +- .../ws/config/UltraDNSWSHttpApiModule.java | 1 + .../ultradns/ws/domain/DirectionalGroup.java | 120 +++++++++++ .../ultradns/ws/domain/DirectionalPool.java | 190 +++++++++++++++++ .../ultradns/ws/domain/DirectionalRecord.java | 174 ++++++++++++++++ .../ws/domain/DirectionalRecordDetail.java | 194 ++++++++++++++++++ .../ws/domain/DirectionalRecordType.java | 62 ++++++ .../ws/features/DirectionalPoolApi.java | 84 ++++++++ .../ws/xml/DirectionalPoolListHandler.java | 71 +++++++ .../xml/DirectionalRecordDetailHandler.java | 93 +++++++++ .../DirectionalRecordDetailListHandler.java | 64 ++++++ .../DirectionalPoolApiExpectTest.java | 67 ++++++ .../features/DirectionalPoolApiLiveTest.java | 144 +++++++++++++ ...ectionalDNSRecordsForHostResponseTest.java | 74 +++++++ ...GetDirectionalPoolsByZoneResponseTest.java | 66 ++++++ .../directionalpool_doesnt_exist.xml | 16 ++ .../src/test/resources/directionalpools.xml | 14 ++ .../src/test/resources/directionalrecords.xml | 19 ++ .../test/resources/list_directionalpools.xml | 1 + .../resources/list_directionalrecords.xml | 1 + 20 files changed, 1467 insertions(+), 1 deletion(-) create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalPool.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecord.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordType.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalPoolApi.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalPoolListHandler.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java create mode 100644 providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailListHandler.java create mode 100644 providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java create mode 100644 providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java create mode 100644 providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSRecordsForHostResponseTest.java create mode 100644 providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalPoolsByZoneResponseTest.java create mode 100644 providers/ultradns-ws/src/test/resources/directionalpool_doesnt_exist.xml create mode 100644 providers/ultradns-ws/src/test/resources/directionalpools.xml create mode 100644 providers/ultradns-ws/src/test/resources/directionalrecords.xml create mode 100644 providers/ultradns-ws/src/test/resources/list_directionalpools.xml create mode 100644 providers/ultradns-ws/src/test/resources/list_directionalrecords.xml 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 2869d26115..b4c27c1bed 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,10 +19,10 @@ package org.jclouds.ultradns.ws; import java.io.Closeable; +import java.util.Map; import javax.inject.Named; import javax.ws.rs.POST; -import java.util.Map; import org.jclouds.rest.annotations.Delegate; import org.jclouds.rest.annotations.Payload; @@ -32,6 +32,7 @@ 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.features.DirectionalPoolApi; import org.jclouds.ultradns.ws.features.ResourceRecordApi; import org.jclouds.ultradns.ws.features.RoundRobinPoolApi; import org.jclouds.ultradns.ws.features.TaskApi; @@ -39,6 +40,7 @@ import org.jclouds.ultradns.ws.features.TrafficControllerPoolApi; import org.jclouds.ultradns.ws.features.ZoneApi; import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; import org.jclouds.ultradns.ws.xml.AccountHandler; +import org.jclouds.ultradns.ws.xml.RegionListHandler; /** * Provides access to Neustar UltraDNS via the SOAP API @@ -101,6 +103,15 @@ public interface UltraDNSWSApi extends Closeable { @Delegate TrafficControllerPoolApi getTrafficControllerPoolApiForZone(@PayloadParam("zoneName") String zoneName); + /** + * Provides access to Directional Pool features. + * + * @param zoneName + * zoneName including a trailing dot + */ + @Delegate + DirectionalPoolApi getDirectionalPoolApiForZone(@PayloadParam("zoneName") String zoneName); + /** * Provides access to Task features. */ diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSHttpApiModule.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSHttpApiModule.java index 9c23387cd1..1a4d83e730 100644 --- a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSHttpApiModule.java +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSHttpApiModule.java @@ -28,6 +28,7 @@ import org.jclouds.rest.config.HttpApiModule; import org.jclouds.ultradns.ws.UltraDNSWSApi; import org.jclouds.ultradns.ws.handlers.UltraDNSWSErrorHandler; + /** * Configures the UltraDNSWS connection. * 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 new file mode 100644 index 0000000000..72c51f6d01 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalGroup.java @@ -0,0 +1,120 @@ +/** + * 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 com.google.common.base.Objects; +import com.google.common.base.Optional; + +/** + * @author Adrian Cole + */ +public class DirectionalGroup { + private final String id; + private final String name; + private final Optional description; + + private DirectionalGroup(String id, String name, Optional description) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name"); + this.description = checkNotNull(description, "description"); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } + + public Optional getDescription() { + return description; + } + + @Override + public int hashCode() { + return Objects.hashCode(id, name, description); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + 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) && equal(this.description, that.description); + } + + @Override + public String toString() { + return toStringHelper("").omitNullValues().add("id", id).add("name", name) + .add("description", description.orNull()).toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String id; + private String name; + private Optional description = Optional.absent(); + + /** + * @see DirectionalGroup#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see DirectionalGroup#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see DirectionalGroup#getDescription() + */ + public Builder description(String description) { + this.description = Optional.fromNullable(description); + return this; + } + + public DirectionalGroup build() { + return new DirectionalGroup(id, name, description); + } + + public Builder from(DirectionalGroup in) { + return id(in.id).name(in.name).description(in.description.orNull()); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalPool.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalPool.java new file mode 100644 index 0000000000..7941e143ca --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalPool.java @@ -0,0 +1,190 @@ +/** + * 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.Preconditions.checkNotNull; + +import com.google.common.base.Objects; +import com.google.common.base.Optional; + +/** + * Records are resolved in consideration of the location of the requestor. + * + * @author Adrian Cole + */ +public final class DirectionalPool { + + private final String zoneId; + private final String id; + private final Optional description; + private final String dname; + private final Type type; + private final TieBreak tieBreak; + + private DirectionalPool(String zoneId, String id, Optional description, String dname, Type type, + TieBreak tieBreak) { + this.zoneId = checkNotNull(zoneId, "zoneId"); + this.id = checkNotNull(id, "id"); + this.description = checkNotNull(description, "description for %s", id); + this.dname = checkNotNull(dname, "dname for %s", id); + this.type = type; + this.tieBreak = tieBreak; + } + + public String getZoneId() { + return zoneId; + } + + public String getId() { + return id; + } + + /** + * The dname of the pool. ex. {@code jclouds.org.} + */ + public String getName() { + return dname; + } + + /** + * The description of the pool. ex. {@code My Pool} + */ + public Optional getDescription() { + return description; + } + + public Type getType() { + return type; + } + + /** + * if {@link #getType} is {@link Type#MIXED}, this can be + * {@link TieBreak#SOURCEIP} or {@link TieBreak#GEOLOCATION}, otherwise + * {@link TieBreak#GEOLOCATION} + */ + public TieBreak getTieBreak() { + return tieBreak; + } + + public static enum Type { + GEOLOCATION, SOURCEIP, MIXED; + } + + public static enum TieBreak { + GEOLOCATION, SOURCEIP; + } + + @Override + public int hashCode() { + return Objects.hashCode(zoneId, id, description, dname); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + DirectionalPool that = DirectionalPool.class.cast(obj); + return Objects.equal(this.zoneId, that.zoneId) && Objects.equal(this.id, that.id) + && Objects.equal(this.description, that.description) && Objects.equal(this.dname, that.dname); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("zoneId", zoneId).add("id", id).add("name", dname) + .add("description", description.orNull()).add("type", type).add("tieBreak", tieBreak).toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String zoneId; + private String id; + private Optional description = Optional.absent(); + private String dname; + private Type type = Type.GEOLOCATION; + private TieBreak tieBreak = TieBreak.GEOLOCATION; + + /** + * @see DirectionalPool#getZoneId() + */ + public Builder zoneId(String zoneId) { + this.zoneId = zoneId; + return this; + } + + /** + * @see DirectionalPool#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see DirectionalPool#getName() + */ + public Builder name(String dname) { + this.dname = dname; + return this; + } + + /** + * @see DirectionalPool#getDescription() + */ + public Builder description(String description) { + this.description = Optional.fromNullable(description); + return this; + } + + /** + * @see DirectionalPool#getType() + */ + public Builder type(Type type) { + this.type = type; + return this; + } + + /** + * @see DirectionalPool#getTieBreak() + */ + public Builder tieBreak(TieBreak tieBreak) { + this.tieBreak = tieBreak; + return this; + } + + public DirectionalPool build() { + return new DirectionalPool(zoneId, id, description, dname, type, tieBreak); + } + + public Builder from(DirectionalPool in) { + return this.zoneId(in.zoneId).id(in.id).description(in.description.orNull()).name(in.dname).type(in.type) + .tieBreak(in.tieBreak); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecord.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecord.java new file mode 100644 index 0000000000..89e03b0a6a --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecord.java @@ -0,0 +1,174 @@ +/** + * 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.Functions.toStringFunction; +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Iterables.transform; + +import java.util.List; + +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableList; + +/** + * @author Adrian Cole + */ +public class DirectionalRecord { + private final String type; + private final int ttl; + private final boolean noResponseRecord; + private final List infoValues; + + private DirectionalRecord(String type, int ttl, boolean noResponseRecord, List infoValues) { + this.type = checkNotNull(type, "type"); + checkArgument(ttl >= 0, "ttl must be >= 0"); + this.ttl = ttl; + this.noResponseRecord = noResponseRecord; + this.infoValues = checkNotNull(infoValues, "infoValues"); + } + + /** + * the type. ex. {@code A} + */ + public String getType() { + return type; + } + + public int getTTL() { + return ttl; + } + + /** + * true if blocks traffic from specified regions by returning No Error, No + * Response. + */ + public boolean isNoResponseRecord() { + return noResponseRecord; + } + + /** + * {@link #getType() type}-specific binary values. + */ + public List getRData() { + return infoValues; + } + + @Override + public int hashCode() { + return Objects.hashCode(noResponseRecord, type, ttl, infoValues); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + DirectionalRecord that = DirectionalRecord.class.cast(obj); + return equal(this.type, that.type) && equal(this.ttl, that.ttl) + && equal(this.noResponseRecord, that.noResponseRecord) && equal(this.infoValues, that.infoValues); + } + + @Override + public String toString() { + return toStringHelper("").add("type", type).add("ttl", ttl).add("noResponseRecord", noResponseRecord) + .add("infoValues", infoValues).toString(); + } + + public static Builder drBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return drBuilder().from(this); + } + + public final static class Builder { + private String type; + private int ttl = -1; + private boolean noResponseRecord; + private ImmutableList.Builder infoValues = ImmutableList. builder(); + + /** + * @see DirectionalRecord#getType() + */ + public Builder type(String type) { + this.type = type; + return this; + } + + /** + * @see DirectionalRecord#getTTL() + */ + public Builder ttl(int ttl) { + this.ttl = ttl; + return this; + } + + /** + * @see DirectionalRecord#isNoResponseRecord() + */ + public Builder noResponseRecord(boolean noResponseRecord) { + this.noResponseRecord = noResponseRecord; + return this; + } + + /** + * adds to current values + * + * @see DirectionalRecord#getRData() + */ + public Builder infoValue(Object infoValue) { + this.infoValues.add(infoValue.toString()); + return this; + } + + /** + * replaces current values + * + * @see DirectionalRecord#getRData() + */ + public Builder rdata(Object infoValue) { + this.infoValues = ImmutableList. builder().add(infoValue.toString()); + return this; + } + + /** + * replaces current values + * + * @see DirectionalRecord#getRData() + */ + public Builder rdata(Iterable infoValues) { + this.infoValues = ImmutableList. builder().addAll(transform(infoValues, toStringFunction())); + return this; + } + + public DirectionalRecord build() { + return new DirectionalRecord(type, ttl, noResponseRecord, infoValues.build()); + } + + public Builder from(DirectionalRecord in) { + return type(in.type).ttl(in.ttl).noResponseRecord(in.noResponseRecord).rdata(in.infoValues); + } + } +} 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 new file mode 100644 index 0000000000..aae0031084 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordDetail.java @@ -0,0 +1,194 @@ +/** + * 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 com.google.common.base.Objects; +import com.google.common.base.Optional; + +/** + * @author Adrian Cole + */ +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 DirectionalRecord record; + + private DirectionalRecordDetail(String zoneName, String name, String id, + Optional geolocationGroup, Optional group, + Optional sourceIpGroup, DirectionalRecord record) { + this.zoneName = checkNotNull(zoneName, "zoneName"); + this.name = checkNotNull(name, "name"); + this.id = checkNotNull(id, "id"); + this.group = checkNotNull(group, "group of %s/%s/%s", zoneName, name, id); + this.geolocationGroup = checkNotNull(geolocationGroup, "geolocationGroup of %s/%s/%s", zoneName, name, id); + this.sourceIpGroup = checkNotNull(sourceIpGroup, "sourceIpGroup of %s/%s/%s", zoneName, name, id); + this.record = checkNotNull(record, "record of %s/%s/%s", zoneName, name, id); + } + + public String getZoneName() { + return zoneName; + } + + public String getName() { + return name; + } + + public String getId() { + return id; + } + + public Optional getGroup() { + return group; + } + + public Optional getGeolocationGroup() { + return geolocationGroup; + } + + public Optional getSourceIpGroup() { + return sourceIpGroup; + } + + public DirectionalRecord getRecord() { + return record; + } + + @Override + public int hashCode() { + return Objects.hashCode(zoneName, name, id); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + DirectionalRecordDetail that = DirectionalRecordDetail.class.cast(obj); + return equal(this.zoneName, that.zoneName) && equal(this.name, that.name) && equal(this.id, that.id); + } + + @Override + public String toString() { + return toStringHelper("").omitNullValues().add("zoneName", zoneName).add("name", name).add("id", id) + .add("group", group.orNull()).add("geolocationGroup", geolocationGroup.orNull()) + .add("sourceIpGroup", sourceIpGroup.orNull()).add("record", record).toString(); + } + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + 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 DirectionalRecord record; + + /** + * @see DirectionalRecordDetail#getZoneName() + */ + public Builder zoneName(String zoneName) { + this.zoneName = zoneName; + return this; + } + + /** + * @see DirectionalRecordDetail#getName() + */ + public Builder name(String name) { + this.name = name; + return this; + } + + /** + * @see DirectionalRecordDetail#getId() + */ + public Builder id(String id) { + this.id = id; + return this; + } + + /** + * @see DirectionalRecordDetail#getGroup() + */ + public Builder group(DirectionalGroup group) { + this.group = Optional.fromNullable(group); + return this; + } + + /** + * @see DirectionalRecordDetail#getGeolocationGroup() + */ + public Builder geolocationGroup(DirectionalGroup geolocationGroup) { + this.geolocationGroup = Optional.fromNullable(geolocationGroup); + return this; + } + + /** + * @see DirectionalRecordDetail#getSourceIpGroup() + */ + public Builder sourceIpGroup(DirectionalGroup sourceIpGroup) { + this.sourceIpGroup = Optional.fromNullable(sourceIpGroup); + return this; + } + + /** + * @see DirectionalRecordDetail#getRecord() + */ + public Builder record(DirectionalRecord record) { + this.record = record; + return this; + } + + /** + * @see DirectionalRecordDetail#getRecord() + */ + public Builder record(DirectionalRecord.Builder record) { + this.record = record.build(); + return this; + } + + public DirectionalRecordDetail build() { + return new DirectionalRecordDetail(zoneName, name, id, group, geolocationGroup, sourceIpGroup, record); + } + + public Builder from(DirectionalRecordDetail in) { + return this.zoneName(in.zoneName).name(in.name).id(in.id).group(in.group.orNull()) + .geolocationGroup(in.geolocationGroup.orNull()).sourceIpGroup(in.sourceIpGroup.orNull()) + .record(in.record); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordType.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordType.java new file mode 100644 index 0000000000..97b4b6bfcd --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/DirectionalRecordType.java @@ -0,0 +1,62 @@ +/** + * 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; + +/** + * currently supported {@link ResourceRecord#getType() types} for directional + * groups. + * + * @author Adrian Cole + */ +public enum DirectionalRecordType { + // A/CNAME + IPV4(1), + + // AAAA/CNAME + IPV6(28), + + TXT(16), + + SRV(33), + + PTR(12), + + RP(17), + + HINFO(13), + + NAPTR(35), + + MX(15); + + private final int code; + + private DirectionalRecordType(int code) { + this.code = code; + } + + /** + * The {@link ResourceRecord#getType() type} that can be used in directional + * groups. + */ + public int getCode() { + return code; + } + +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalPoolApi.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalPoolApi.java new file mode 100644 index 0000000000..59ed329c8c --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/DirectionalPoolApi.java @@ -0,0 +1,84 @@ +/** + * 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.features; + +import javax.inject.Named; +import javax.ws.rs.POST; + +import org.jclouds.Fallbacks.EmptyFluentIterableOnNotFoundOr404; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Payload; +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.DirectionalPool; +import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; +import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; +import org.jclouds.ultradns.ws.xml.DirectionalPoolListHandler; +import org.jclouds.ultradns.ws.xml.DirectionalRecordDetailListHandler; + +import com.google.common.collect.FluentIterable; + +/** + * @see + * @see + * @author Adrian Cole + */ +@RequestFilters(SOAPWrapWithPasswordAuth.class) +@VirtualHost +public interface DirectionalPoolApi { + + /** + * Returns all directional pools in the zone. + * + * @throws ResourceNotFoundException + * if the zone doesn't exist + */ + @Named("getDirectionalPoolsOfZone") + @POST + @XMLResponseParser(DirectionalPoolListHandler.class) + @Payload("{zoneName}") + FluentIterable list() throws ResourceNotFoundException; + + /** + * Returns all the directional pool records in the zone with the fully + * qualified {@link hostName} and {@link rrType} + * + * @param hostName + * fully qualified hostname including the trailing dot. + * @param rrType + * type value, with special casing: for {@code A} or {@code CNAME} + * of ipv4 hosts, this is {@code 1}; for {@code AAAA} or + * {@code CNAME} of ipv4 hosts, this is {@code 28} + * @return empty if there are not pools for the specified host or no records + * exist for the type. + * @throws ResourceNotFoundException + * if the zone doesn't exist + */ + @Named("getDirectionalDNSRecordsForHost") + @POST + @XMLResponseParser(DirectionalRecordDetailListHandler.class) + @Fallback(EmptyFluentIterableOnNotFoundOr404.class) + @Payload("{zoneName}{hostName}{poolRecordType}") + FluentIterable listRecordsByNameAndType( + @PayloadParam("hostName") String dname, @PayloadParam("poolRecordType") int type) + throws ResourceNotFoundException; +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalPoolListHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalPoolListHandler.java new file mode 100644 index 0000000000..70c271802d --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalPoolListHandler.java @@ -0,0 +1,71 @@ +/** + * 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.xml; + +import static org.jclouds.util.SaxUtils.cleanseAttributes; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.ultradns.ws.domain.DirectionalPool; +import org.jclouds.ultradns.ws.domain.DirectionalPool.TieBreak; +import org.jclouds.ultradns.ws.domain.DirectionalPool.Type; +import org.xml.sax.Attributes; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; + +/** + * + * @author Adrian Cole + */ +public class DirectionalPoolListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> { + + private final Builder pools = ImmutableSet. builder(); + + @Override + public FluentIterable getResult() { + return FluentIterable.from(pools.build()); + } + + @Override + public void startElement(String url, String name, String qName, Attributes attrs) { + if (equalsOrSuffix(qName, "DirectionalPoolData")) { + Map attributes = cleanseAttributes(attrs); + + DirectionalPool.Builder pool = DirectionalPool.builder() + .zoneId(attributes.get("Zoneid")) + .id(attributes.get("dirpoolid")) + .name(attributes.get("Pooldname")) + .description(attributes.get("Description")); + + String type = attributes.get("DirPoolType"); + if (type != null) + pool.type(Type.valueOf(type)); + + String tieBreak = attributes.get("TieBreak"); + if (tieBreak != null) + pool.tieBreak(TieBreak.valueOf(tieBreak)); + + pools.add(pool.build()); + } + } +} 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 new file mode 100644 index 0000000000..d6dd91d894 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailHandler.java @@ -0,0 +1,93 @@ +/** + * 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.xml; + +import static org.jclouds.util.SaxUtils.cleanseAttributes; +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 org.jclouds.ultradns.ws.domain.DirectionalRecord; +import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; +import org.xml.sax.Attributes; + +/** + * + * @author Adrian Cole + */ +public class DirectionalRecordDetailHandler extends + ParseSax.HandlerForGeneratedRequestWithResult { + + private DirectionalRecordDetail.Builder drd = DirectionalRecordDetail.builder(); + private DirectionalRecord.Builder dr = DirectionalRecord.drBuilder(); + + private String zoneName; + private String dname; + + @Override + public DirectionalRecordDetail getResult() { + try { + return drd.record(dr.build()).build(); + } finally { + drd = DirectionalRecordDetail.builder().zoneName(zoneName).name(dname); + dr = DirectionalRecord.drBuilder(); + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = cleanseAttributes(attrs); + if (attributes.containsKey("ZoneName")) { + zoneName = attributes.get("ZoneName"); + dname = attributes.get("DName"); + drd.zoneName(zoneName).name(dname); + } + if (attributes.containsKey("DirPoolRecordId")) { + drd.id(attributes.get("DirPoolRecordId")); + } + if (attributes.containsKey("GroupId")) { + drd.group(DirectionalGroup.builder() + .id(attributes.get("GroupId")) + .name(attributes.get("GroupName")) + .description(attributes.get("GroupDescription")).build()); + } + if (attributes.containsKey("GeolocationGroupId")) { + drd.geolocationGroup(DirectionalGroup.builder() + .id(attributes.get("GeolocationGroupId")) + .name(attributes.get("GeolocationGroupName")) + .description(attributes.get("GeolocationGroupDescription")).build()); + } + if (attributes.containsKey("SourceIPGroupId")) { + drd.sourceIpGroup(DirectionalGroup.builder() + .id(attributes.get("SourceIPGroupId")) + .name(attributes.get("SourceIPGroupName")) + .description(attributes.get("SourceIPGroupDescription")).build()); + } + if (attributes.containsKey("recordType")) { + dr.type(attributes.get("recordType")); + dr.ttl(Integer.parseInt(attributes.get("TTL"))); + dr.noResponseRecord("true".equalsIgnoreCase(attributes.get("noResponseRecord"))); + } + if (equalsOrSuffix(qName, "InfoValues")) { + dr.rdata(attributes.values()); + } + } +} diff --git a/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailListHandler.java b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailListHandler.java new file mode 100644 index 0000000000..76cc2e8d84 --- /dev/null +++ b/providers/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/DirectionalRecordDetailListHandler.java @@ -0,0 +1,64 @@ +/** + * 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.xml; + +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.ultradns.ws.domain.DirectionalRecordDetail; +import org.xml.sax.Attributes; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSet.Builder; +import com.google.inject.Inject; + +/** + * + * @author Adrian Cole + */ +public class DirectionalRecordDetailListHandler extends + ParseSax.HandlerForGeneratedRequestWithResult> { + + private final DirectionalRecordDetailHandler directionalRecordHandler; + + private final Builder drs = ImmutableSet. builder(); + + @Inject + public DirectionalRecordDetailListHandler(DirectionalRecordDetailHandler directionalRecordHandler) { + this.directionalRecordHandler = directionalRecordHandler; + } + + @Override + public FluentIterable getResult() { + return FluentIterable.from(drs.build()); + } + + @Override + public void startElement(String url, String name, String qName, Attributes attributes) { + directionalRecordHandler.startElement(url, name, qName, attributes); + } + + @Override + public void endElement(String uri, String name, String qName) { + if (equalsOrSuffix(qName, "DirectionalDNSRecordDetail")) { + drs.add(directionalRecordHandler.getResult()); + } + } +} diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java new file mode 100644 index 0000000000..63c027a3d9 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiExpectTest.java @@ -0,0 +1,67 @@ +/** + * 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.features; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.ultradns.ws.UltraDNSWSApi; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest; +import org.jclouds.ultradns.ws.parse.GetDirectionalDNSRecordsForHostResponseTest; +import org.jclouds.ultradns.ws.parse.GetDirectionalPoolsByZoneResponseTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "DirectionalPoolApiExpectTest") +public class DirectionalPoolApiExpectTest extends BaseUltraDNSWSApiExpectTest { + + HttpRequest list = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/list_directionalpools.xml", "application/xml")).build(); + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/directionalpools.xml", "application/xml")).build(); + + public void testListWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(list, listResponse); + + assertEquals(success.getDirectionalPoolApiForZone("jclouds.org.").list().toString(), + new GetDirectionalPoolsByZoneResponseTest().expected().toString()); + } + + HttpRequest listRecords = HttpRequest.builder().method("POST") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443") + .payload(payloadFromResourceWithContentType("/list_directionalrecords.xml", "application/xml")).build(); + + HttpResponse listRecordsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/directionalrecords.xml", "application/xml")).build(); + + public void testListRecordsWhenResponseIs2xx() { + UltraDNSWSApi success = requestSendsResponse(listRecords, listRecordsResponse); + + assertEquals( + success.getDirectionalPoolApiForZone("jclouds.org.").listRecordsByNameAndType("www.jclouds.org.", 1).toString(), + new GetDirectionalDNSRecordsForHostResponseTest().expected().toString()); + } +} 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 new file mode 100644 index 0000000000..2076b018a5 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/DirectionalPoolApiLiveTest.java @@ -0,0 +1,144 @@ +/** + * 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 WATCANTIES 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.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + +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.Zone; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "DirectionalPoolApiLiveTest") +public class DirectionalPoolApiLiveTest extends BaseUltraDNSWSApiLiveTest { + + private Account account; + + @Override + @BeforeClass(groups = { "integration", "live" }) + public void setup() { + super.setup(); + account = api.getCurrentAccount(); + } + + @Test + public void testListDirectionalPools() { + for (Zone zone : api.getZoneApi().listByAccount(account.getId())) { + for (DirectionalPool pool : api(zone.getName()).list()) { + checkDirectional(pool); + } + } + } + + private void checkDirectional(DirectionalPool pool) { + assertNotNull(pool.getZoneId(), "ZoneId cannot be null " + pool); + assertNotNull(pool.getId(), "Id cannot be null " + pool); + assertNotNull(pool.getName(), "DName cannot be null " + pool); + assertNotNull(pool.getDescription(), "Description cannot be null " + pool); + assertNotNull(pool.getType(), "Type cannot be null " + pool); + assertNotNull(pool.getTieBreak(), "TieBreak cannot be null " + pool); + } + + Set allDirectionalGroups = Sets.newLinkedHashSet(); + + @Test + public void testListDirectionalRecords() { + for (Zone zone : api.getZoneApi().listByAccount(account.getId())) { + for (DirectionalPool pool : api(zone.getName()).list()) { + for (DirectionalRecordType type : EnumSet.allOf(DirectionalRecordType.class)) { + for (DirectionalRecordDetail rr : api(zone.getName()) + .listRecordsByNameAndType(pool.getName(), type.getCode())) { + checkDirectionalRecordDetail(rr); + Iterable groups = Optional.presentInstances(ImmutableSet.of(rr.getGroup(), + rr.getGeolocationGroup(), rr.getGeolocationGroup())); + assertFalse(Iterables.isEmpty(groups), "No groups " + rr); + for (DirectionalGroup group : groups) { + allDirectionalGroups.add(group); + assertNotNull(group.getId(), "Id cannot be null " + group); + assertNotNull(group.getName(), "Name cannot be null " + group); + assertNotNull(group.getDescription(), "Description cannot be null " + group); + } + assertEquals(rr.getZoneName(), zone.getName()); + assertEquals(rr.getName(), pool.getName()); + switch (pool.getType()) { + case GEOLOCATION: + assertNotNull(rr.getGeolocationGroup().or(rr.getGroup()).orNull(), + "GeolocationGroup or Group must be present " + rr); + assertNull(rr.getSourceIpGroup().orNull(), "SourceIpGroup must be absent " + rr); + break; + case SOURCEIP: + assertNotNull(rr.getSourceIpGroup().or(rr.getGroup()).orNull(), + "SourceIpGroup or Group must be present " + rr); + assertNull(rr.getGeolocationGroup().orNull(), "GeolocationGroup must be absent " + rr); + break; + case MIXED: + assertNotNull(rr.getGeolocationGroup().or(rr.getSourceIpGroup()).or(rr.getGroup()).orNull(), + "GeolocationGroup, SourceIpGroup or Group must be present " + rr); + break; + } + } + } + } + } + } + + static void checkDirectionalRecord(DirectionalRecord rr) { + assertNotNull(rr.getType(), "Type cannot be null " + rr); + assertNotNull(rr.getTTL(), "TTL cannot be null " + rr); + assertNotNull(rr.getRData(), "InfoValues cannot be null " + rr); + } + + static void checkDirectionalRecordDetail(DirectionalRecordDetail rr) { + assertNotNull(rr.getZoneName(), "ZoneName cannot be null " + rr); + assertNotNull(rr.getName(), "DName cannot be null " + rr); + assertNotNull(rr.getId(), "Id cannot be null " + rr); + assertNotNull(rr.getZoneName(), "ZoneName cannot be null " + rr); + checkDirectionalRecord(rr.getRecord()); + } + + @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Parent Zone does not exist in the system.") + public void testListDirectionalsWhenZoneIdNotFound() { + api("AAAAAAAAAAAAAAAA").list(); + } + + private DirectionalPoolApi api(String zoneName) { + return api.getDirectionalPoolApiForZone(zoneName); + } +} 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 new file mode 100644 index 0000000000..a3942c7f5e --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalDNSRecordsForHostResponseTest.java @@ -0,0 +1,74 @@ +/** + * 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.parse; + +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; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Test(testName = "GetDirectionalDNSRecordsForHostResponseTest") +public class GetDirectionalDNSRecordsForHostResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/directionalrecords.xml"); + + FluentIterable expected = expected(); + + DirectionalRecordDetailListHandler handler = injector.getInstance(DirectionalRecordDetailListHandler.class); + FluentIterable result = factory.create(handler).parse(is); + + assertEquals(result.toSet().toString(), expected.toSet().toString()); + } + + public FluentIterable expected() { + return FluentIterable.from(ImmutableSet. builder() + .add(DirectionalRecordDetail.builder() + .zoneName("directional-example.com.") + .name("chaos.directional-example.com.") + .id("06093C2D10CB1CB1") + .geolocationGroup(DirectionalGroup.builder() + .id("06093C2D10CB1CB2") + .name("Geolocation field") + .build()) + .sourceIpGroup(DirectionalGroup.builder() + .id("06093C2D10CB1CB4") + .name("172.16.1.0/24") + .build()) + .record(DirectionalRecord.drBuilder() + .type("A") + .ttl(60) + .noResponseRecord(false) + .rdata("172.16.1.1").build()).build()) + .build()); + } + +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalPoolsByZoneResponseTest.java b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalPoolsByZoneResponseTest.java new file mode 100644 index 0000000000..75f6266092 --- /dev/null +++ b/providers/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetDirectionalPoolsByZoneResponseTest.java @@ -0,0 +1,66 @@ +/** + * 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 WADirectionalANTIES 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.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.ultradns.ws.domain.DirectionalPool; +import org.jclouds.ultradns.ws.domain.DirectionalPool.TieBreak; +import org.jclouds.ultradns.ws.domain.DirectionalPool.Type; +import org.jclouds.ultradns.ws.xml.DirectionalPoolListHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; + +/** + * @author Adrian Cole + */ +@Test(testName = "GetDirectionalPoolsByZoneResponseTest") +public class GetDirectionalPoolsByZoneResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/directionalpools.xml"); + + FluentIterable expected = expected(); + + DirectionalPoolListHandler handler = injector.getInstance(DirectionalPoolListHandler.class); + FluentIterable result = factory.create(handler).parse(is); + + assertEquals(result.toSet().toString(), expected.toSet().toString()); + } + + public FluentIterable expected() { + return FluentIterable.from(ImmutableList. builder() + .add(DirectionalPool.builder() + .zoneId("0000000000000001") + .id("000000000000000A") + .name("mixy.jclouds.org.") + .type(Type.MIXED) + .tieBreak(TieBreak.GEOLOCATION) + .description("mixy").build()) + .add(DirectionalPool.builder() + .zoneId("0000000000000002") + .id("000000000000000B") + .name("geo.jclouds.org.").build()).build()); + } +} \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/directionalpool_doesnt_exist.xml b/providers/ultradns-ws/src/test/resources/directionalpool_doesnt_exist.xml new file mode 100644 index 0000000000..19cc7fbfb8 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/directionalpool_doesnt_exist.xml @@ -0,0 +1,16 @@ + + + + soap:Server + Fault occurred while processing. + + + 2142 + No Pool or Multiple pools of same type exists for the PoolName : foo.jclouds.org. + + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/directionalpools.xml b/providers/ultradns-ws/src/test/resources/directionalpools.xml new file mode 100644 index 0000000000..1dc04a86d1 --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/directionalpools.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/directionalrecords.xml b/providers/ultradns-ws/src/test/resources/directionalrecords.xml new file mode 100644 index 0000000000..43a54752ab --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/directionalrecords.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/providers/ultradns-ws/src/test/resources/list_directionalpools.xml b/providers/ultradns-ws/src/test/resources/list_directionalpools.xml new file mode 100644 index 0000000000..782383d66d --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/list_directionalpools.xml @@ -0,0 +1 @@ +identitycredentialjclouds.org. \ No newline at end of file diff --git a/providers/ultradns-ws/src/test/resources/list_directionalrecords.xml b/providers/ultradns-ws/src/test/resources/list_directionalrecords.xml new file mode 100644 index 0000000000..85fc7025bb --- /dev/null +++ b/providers/ultradns-ws/src/test/resources/list_directionalrecords.xml @@ -0,0 +1 @@ +identitycredentialjclouds.org.www.jclouds.org.1 \ No newline at end of file