From bacb21d92dfd48cb738482487c909991ce5e8738 Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 18 Feb 2013 09:09:25 -0800 Subject: [PATCH] added initial rdata implementation for DynECT --- .../java/org/jclouds/dynect/v3/DynECTApi.java | 9 + .../org/jclouds/dynect/v3/DynECTAsyncApi.java | 7 + .../dynect/v3/config/DynECTParserModule.java | 13 +- .../v3/config/DynECTRestClientModule.java | 5 +- .../org/jclouds/dynect/v3/domain/Record.java | 115 +++++++ .../jclouds/dynect/v3/domain/RecordId.java | 166 ++++++++++ .../jclouds/dynect/v3/domain/SOARecord.java | 99 ++++++ .../dynect/v3/domain/rdata/AAAAData.java | 92 ++++++ .../jclouds/dynect/v3/domain/rdata/AData.java | 92 ++++++ .../dynect/v3/domain/rdata/CNAMEData.java | 93 ++++++ .../dynect/v3/domain/rdata/MXData.java | 121 +++++++ .../dynect/v3/domain/rdata/NSData.java | 93 ++++++ .../dynect/v3/domain/rdata/PTRData.java | 92 ++++++ .../dynect/v3/domain/rdata/SOAData.java | 238 ++++++++++++++ .../dynect/v3/domain/rdata/SRVData.java | 172 ++++++++++ .../dynect/v3/domain/rdata/TXTData.java | 92 ++++++ .../jclouds/dynect/v3/features/RecordApi.java | 157 +++++++++ .../dynect/v3/features/RecordAsyncApi.java | 197 ++++++++++++ .../dynect/v3/features/ZoneAsyncApi.java | 4 +- ...xtractNames.java => ExtractZoneNames.java} | 2 +- .../dynect/v3/functions/ToRecordIds.java | 70 ++++ .../v3/predicates/RecordPredicates.java | 55 ++++ .../v3/features/RecordApiExpectTest.java | 302 ++++++++++++++++++ .../dynect/v3/features/RecordApiLiveTest.java | 165 ++++++++++ ...mesTest.java => ExtractZoneNamesTest.java} | 8 +- .../dynect/v3/functions/ToRecordIdsTest.java | 50 +++ .../v3/parse/GetAAAARecordResponseTest.java | 55 ++++ .../v3/parse/GetARecordResponseTest.java | 55 ++++ .../v3/parse/GetCNAMERecordResponseTest.java | 55 ++++ .../v3/parse/GetMXRecordResponseTest.java | 55 ++++ .../v3/parse/GetNSRecordResponseTest.java | 55 ++++ .../v3/parse/GetPTRRecordResponseTest.java | 55 ++++ .../v3/parse/GetRecordResponseTest.java | 64 ++++ .../v3/parse/GetSOARecordResponseTest.java | 63 ++++ .../v3/parse/GetSRVRecordResponseTest.java | 57 ++++ .../v3/parse/GetTXTRecordResponseTest.java | 55 ++++ .../v3/parse/ListRecordsResponseTest.java | 57 ++++ .../v3/parse/ListZonesResponseTest.java | 4 +- .../v3/predicates/RecordPredicatesTest.java | 29 ++ .../src/test/resources/get_record_a.json | 1 + .../src/test/resources/get_record_aaaa.json | 1 + .../src/test/resources/get_record_cname.json | 1 + .../src/test/resources/get_record_mx.json | 1 + .../src/test/resources/get_record_ns.json | 1 + .../src/test/resources/get_record_ptr.json | 1 + .../src/test/resources/get_record_soa.json | 1 + .../src/test/resources/get_record_srv.json | 1 + .../src/test/resources/get_record_txt.json | 1 + .../src/test/resources/list_records.json | 1 + 49 files changed, 3167 insertions(+), 11 deletions(-) create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/RecordId.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordApi.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java rename labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/{ExtractNames.java => ExtractZoneNames.java} (93%) create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ToRecordIds.java create mode 100644 labs/dynect/src/main/java/org/jclouds/dynect/v3/predicates/RecordPredicates.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiLiveTest.java rename labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/{ExtractNamesTest.java => ExtractZoneNamesTest.java} (87%) create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ToRecordIdsTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetAAAARecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetARecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetCNAMERecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetMXRecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetNSRecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetPTRRecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetRecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSOARecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSRVRecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetTXTRecordResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListRecordsResponseTest.java create mode 100644 labs/dynect/src/test/java/org/jclouds/dynect/v3/predicates/RecordPredicatesTest.java create mode 100644 labs/dynect/src/test/resources/get_record_a.json create mode 100644 labs/dynect/src/test/resources/get_record_aaaa.json create mode 100644 labs/dynect/src/test/resources/get_record_cname.json create mode 100644 labs/dynect/src/test/resources/get_record_mx.json create mode 100644 labs/dynect/src/test/resources/get_record_ns.json create mode 100644 labs/dynect/src/test/resources/get_record_ptr.json create mode 100644 labs/dynect/src/test/resources/get_record_soa.json create mode 100644 labs/dynect/src/test/resources/get_record_srv.json create mode 100644 labs/dynect/src/test/resources/get_record_txt.json create mode 100644 labs/dynect/src/test/resources/list_records.json diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java index f22be7992b..f2eaa671e9 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTApi.java @@ -21,7 +21,10 @@ package org.jclouds.dynect.v3; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; +import javax.ws.rs.PathParam; + import org.jclouds.dynect.v3.domain.Job; +import org.jclouds.dynect.v3.features.RecordApi; import org.jclouds.dynect.v3.features.SessionApi; import org.jclouds.dynect.v3.features.ZoneApi; import org.jclouds.javax.annotation.Nullable; @@ -59,4 +62,10 @@ public interface DynECTApi { */ @Delegate ZoneApi getZoneApi(); + + /** + * Provides synchronous access to Record features + */ + @Delegate + RecordApi getRecordApiForZone(@PathParam("zone") String zone); } diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java index 05da1493a2..06b8b7ae8d 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/DynECTAsyncApi.java @@ -28,6 +28,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import org.jclouds.dynect.v3.domain.Job; +import org.jclouds.dynect.v3.features.RecordAsyncApi; import org.jclouds.dynect.v3.features.SessionAsyncApi; import org.jclouds.dynect.v3.features.ZoneAsyncApi; import org.jclouds.dynect.v3.filters.SessionManager; @@ -72,4 +73,10 @@ public interface DynECTAsyncApi { */ @Delegate ZoneAsyncApi getZoneApi(); + + /** + * Provides asynchronous access to Record features + */ + @Delegate + RecordAsyncApi getRecordApiForZone(@PathParam("zone") String zone); } diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java index 5ba2b1a5d7..d0aecfd1ce 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTParserModule.java @@ -26,8 +26,12 @@ import javax.inject.Singleton; import org.jclouds.dynect.v3.domain.SessionCredentials; import com.google.common.collect.ImmutableMap; +import com.google.common.primitives.UnsignedInteger; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.google.inject.AbstractModule; @@ -47,11 +51,11 @@ public class DynECTParserModule extends AbstractModule { public Map provideCustomAdapterBindings() { return new ImmutableMap.Builder() .put(SessionCredentials.class, new SessionCredentialsTypeAdapter()) + .put(UnsignedInteger.class, new UnsignedIntegerAdapter()) .build(); } private static class SessionCredentialsTypeAdapter implements JsonSerializer { - @Override public JsonElement serialize(SessionCredentials src, Type typeOfSrc, JsonSerializationContext context) { JsonObject metadataObject = new JsonObject(); metadataObject.addProperty("customer_name", src.getCustomerName()); @@ -60,4 +64,11 @@ public class DynECTParserModule extends AbstractModule { return metadataObject; } } + + private static class UnsignedIntegerAdapter implements JsonDeserializer { + public UnsignedInteger deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) + throws JsonParseException { + return UnsignedInteger.valueOf(jsonElement.getAsBigInteger().intValue()); + } + } } diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTRestClientModule.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTRestClientModule.java index fb7c183ced..f61a70a414 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTRestClientModule.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/config/DynECTRestClientModule.java @@ -36,6 +36,8 @@ import org.jclouds.Constants; import org.jclouds.concurrent.SingleThreaded; import org.jclouds.dynect.v3.DynECTApi; import org.jclouds.dynect.v3.DynECTAsyncApi; +import org.jclouds.dynect.v3.features.RecordApi; +import org.jclouds.dynect.v3.features.RecordAsyncApi; import org.jclouds.dynect.v3.features.SessionApi; import org.jclouds.dynect.v3.features.SessionAsyncApi; import org.jclouds.dynect.v3.features.ZoneApi; @@ -75,7 +77,8 @@ public class DynECTRestClientModule extends RestClientModule, Class> DELEGATE_MAP = ImmutableMap., Class> builder() .put(SessionApi.class, SessionAsyncApi.class) - .put(ZoneApi.class, ZoneAsyncApi.class).build(); + .put(ZoneApi.class, ZoneAsyncApi.class) + .put(RecordApi.class, RecordAsyncApi.class).build(); public DynECTRestClientModule() { super(DELEGATE_MAP); diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java new file mode 100644 index 0000000000..5aedaf6dd4 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/Record.java @@ -0,0 +1,115 @@ +/** + * 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, String 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.dynect.v3.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import javax.inject.Named; + +import com.google.common.base.Objects.ToStringHelper; + +/** + * @author Adrian Cole + */ +public class Record> extends RecordId { + + private final int ttl; + @Named("rdata") + private final D rdata; + + @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata" }) + protected Record(String zone, String fqdn, String type, long id, int ttl, D rdata) { + super(zone, fqdn, type, id); + this.ttl = checkNotNull(ttl, "ttl of %s", id); + this.rdata = checkNotNull(rdata, "rdata of %s", id); + } + + /** + * The current ttl of the record or zero if default for the zone + */ + public int getTTL() { + return ttl; + } + + /** + * RData defining the record; corresponds to binary master format. Only + * simple data types such as String or Integer are values. + */ + public D getRData() { + return rdata; + } + + @Override + protected ToStringHelper string() { + return super.string().add("ttl", ttl).add("rdata", rdata); + } + + public static > Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().from(this); + } + + public abstract static class Builder, B extends Builder> extends RecordId.Builder { + + protected int ttl; + protected D rdata; + + /** + * @see Record#getTTL() + */ + public B ttl(int ttl) { + this.ttl = ttl; + return self(); + } + + /** + * @see Record#getRData() + */ + public B rdata(D rdata) { + this.rdata = rdata; + return self(); + } + + public Record build() { + return new Record(zone, fqdn, type, id, ttl, rdata); + } + + @Override + public B from(RecordId in) { + if (in instanceof Record) { + @SuppressWarnings("unchecked") + Record record = Record.class.cast(in); + ttl(record.ttl).rdata(record.rdata); + } + return super.from(in); + } + } + + private static class ConcreteBuilder> extends Builder> { + protected ConcreteBuilder self() { + return this; + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/RecordId.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/RecordId.java new file mode 100644 index 0000000000..8a982795d3 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/RecordId.java @@ -0,0 +1,166 @@ +/** + * 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, String 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.dynect.v3.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.beans.ConstructorProperties; + +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; + +/** + * @author Adrian Cole + */ +public class RecordId { + + private final long id; + private final String zone; + private final String fqdn; + private final String type; + + @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id" }) + RecordId(String zone, String fqdn, String type, long id) { + this.id = checkNotNull(id, "id"); + this.fqdn = checkNotNull(fqdn, "fqdn of %s", id); + this.zone = checkNotNull(zone, "zone of %s", id); + this.type = checkNotNull(type, "type of %s", id); + } + + /** + * Name of the zone + */ + public String getZone() { + return zone; + } + + /** + * Fully qualified domain name of a node in the zone + */ + public String getFQDN() { + return fqdn; + } + + /** + * The RRType of the record + */ + public String getType() { + return type; + } + + /** + * The record id + */ + public long getId() { + return id; + } + + @Override + public int hashCode() { + return Objects.hashCode(zone, fqdn, type, id); + } + + /** + * permits equals comparisons with subtypes + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || !(obj instanceof RecordId)) + return false; + RecordId that = RecordId.class.cast(obj); + return equal(this.zone, that.zone) && equal(this.fqdn, that.fqdn) && equal(this.type, that.type) + && equal(this.id, that.id); + } + + @Override + public String toString() { + return string().toString(); + } + + protected ToStringHelper string() { + return toStringHelper(this).add("zone", zone).add("fqdn", fqdn).add("type", type).add("id", id); + } + + public static Builder builder() { + return new ConcreteBuilder(); + } + + public Builder toBuilder() { + return new ConcreteBuilder().from(this); + } + + public abstract static class Builder> { + protected abstract B self(); + + protected String zone; + protected String fqdn; + protected String type; + protected long id; + + /** + * @see RecordId#getZone() + */ + public B zone(String zone) { + this.zone = zone; + return self(); + } + + /** + * @see RecordId#getFQDN() + */ + public B fqdn(String fqdn) { + this.fqdn = fqdn; + return self(); + } + + /** + * @see RecordId#getType() + */ + public B type(String type) { + this.type = type; + return self(); + } + + /** + * @see RecordId#getId() + */ + public B id(long id) { + this.id = id; + return self(); + } + + public RecordId build() { + return new RecordId(zone, fqdn, type, id); + } + + public B from(RecordId in) { + return zone(in.zone).fqdn(in.fqdn).type(in.type).id(in.id); + } + } + + private static class ConcreteBuilder extends Builder { + protected ConcreteBuilder self() { + return this; + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java new file mode 100644 index 0000000000..ec8593a786 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/SOARecord.java @@ -0,0 +1,99 @@ +/** + * 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, String 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.dynect.v3.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; + +import javax.inject.Named; + +import org.jclouds.dynect.v3.domain.Zone.SerialStyle; +import org.jclouds.dynect.v3.domain.rdata.SOAData; + +import com.google.common.base.Objects.ToStringHelper; + +/** + * Start of Authority per RFC 1035 + * + * @author Adrian Cole + */ +public final class SOARecord extends Record { + + @Named("serial_style") + private final SerialStyle serialStyle; + + @ConstructorProperties({ "zone", "fqdn", "record_type", "record_id", "ttl", "rdata", "serial_style" }) + private SOARecord(String zone, String fqdn, String type, long id, int ttl, SOAData rdata, SerialStyle serialStyle) { + super(zone, fqdn, type, id, ttl, rdata); + this.serialStyle = checkNotNull(serialStyle, "serialStyle of %s", id); + } + + /** + * @see Zone#getSerialStyle + */ + public SerialStyle getSerialStyle() { + return serialStyle; + } + + @Override + protected ToStringHelper string() { + return super.string().add("serialStyle", serialStyle); + } + + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder extends Record.Builder { + + private SerialStyle serialStyle; + + /** + * @see Zone#getSerialStyle() + */ + public Builder serialStyle(SerialStyle serialStyle) { + this.serialStyle = serialStyle; + return this; + } + + public SOARecord build() { + return new SOARecord(zone, fqdn, type, id, ttl, rdata, serialStyle); + } + + @Override + public Builder from(RecordId in) { + if (in instanceof SOARecord) { + SOARecord record = SOARecord.class.cast(in); + serialStyle(record.serialStyle); + } + return super.from(in); + } + + @Override + protected Builder self() { + return this; + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java new file mode 100644 index 0000000000..22f9a3dc6c --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AAAAData.java @@ -0,0 +1,92 @@ +/** + * 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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; + +/** + * Corresponds to the binary representation of the {@code AAAA} (Address) RData + * + *

Example

+ * + *
+ * import static org.jclouds.dynect.v3.domain.rdata.NSData.aaaa;
+ * ...
+ * NSData rdata = aaaa("1234:ab00:ff00::6b14:abcd");
+ * 
+ * + * @see RFC 3596 + */ +public class AAAAData extends ForwardingMap { + private final ImmutableMap delegate; + + @ConstructorProperties("address") + private AAAAData(String address) { + this.delegate = ImmutableMap. of("address", checkNotNull(address, "address")); + } + + protected Map delegate() { + return delegate; + } + + /** + * a 128 bit IPv6 address + */ + public String getAddress() { + return get("address").toString(); + } + + public static AAAAData aaaa(String address) { + return builder().address(address).build(); + } + + public static AAAAData.Builder builder() { + return new Builder(); + } + + public AAAAData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String address; + + /** + * @see AAAAData#getAddress() + */ + public AAAAData.Builder address(String address) { + this.address = address; + return this; + } + + public AAAAData build() { + return new AAAAData(address); + } + + public AAAAData.Builder from(AAAAData in) { + return this.address(in.getAddress()); + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java new file mode 100644 index 0000000000..64deaa0afa --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/AData.java @@ -0,0 +1,92 @@ +/** + * 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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; + +/** + * Corresponds to the binary representation of the {@code A} (Address) RData + * + *

Example

+ * + *
+ * import static org.jclouds.dynect.v3.domain.rdata.NSData.a;
+ * ...
+ * NSData rdata = a("ptr.foo.com.");
+ * 
+ * + * @see RFC 1035 + */ +public class AData extends ForwardingMap { + private final ImmutableMap delegate; + + @ConstructorProperties("address") + private AData(String address) { + this.delegate = ImmutableMap. of("address", checkNotNull(address, "address")); + } + + protected Map delegate() { + return delegate; + } + + /** + * a 32-bit internet address + */ + public String getAddress() { + return get("address").toString(); + } + + public static AData a(String address) { + return builder().address(address).build(); + } + + public static AData.Builder builder() { + return new Builder(); + } + + public AData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String address; + + /** + * @see AData#getAddress() + */ + public AData.Builder address(String address) { + this.address = address; + return this; + } + + public AData build() { + return new AData(address); + } + + public AData.Builder from(AData in) { + return this.address(in.getAddress()); + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.java new file mode 100644 index 0000000000..be8c0eda8b --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/CNAMEData.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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; + +/** + * Corresponds to the binary representation of the {@code CNAME} (Canonical Name) RData + * + *

Example

+ * + *
+ * import static org.jclouds.dynect.v3.domain.rdata.NSData.cname;
+ * ...
+ * NSData rdata = cname("cname.foo.com.");
+ * 
+ * + * @see RFC 1035 + */ +public class CNAMEData extends ForwardingMap { + private final ImmutableMap delegate; + + @ConstructorProperties("cname") + private CNAMEData(String cname) { + this.delegate = ImmutableMap. of("cname", checkNotNull(cname, "cname")); + } + + protected Map delegate() { + return delegate; + } + + /** + * domain-name which specifies the canonical or primary name for the owner. + * The owner name is an alias. + */ + public String getCname() { + return get("cname").toString(); + } + + public static CNAMEData cname(String cname) { + return builder().cname(cname).build(); + } + + public static CNAMEData.Builder builder() { + return new Builder(); + } + + public CNAMEData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String cname; + + /** + * @see CNAMEData#getCname() + */ + public CNAMEData.Builder cname(String cname) { + this.cname = cname; + return this; + } + + public CNAMEData build() { + return new CNAMEData(cname); + } + + public CNAMEData.Builder from(CNAMEData in) { + return this.cname(in.getCname()); + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java new file mode 100644 index 0000000000..3e47816642 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/MXData.java @@ -0,0 +1,121 @@ +/** + * 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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; +import com.google.common.primitives.UnsignedInteger; + +/** + * Corresponds to the binary representation of the {@code MX} (Mail Exchange) + * RData + * + *

Example

+ * + *
+ * import static org.jclouds.dynect.v3.domain.rdata.MXData.mx;
+ * ...
+ * MXData rdata = mx(1, "mail.jclouds.org");
+ * 
+ * + * @see RFC 1035 + */ +public class MXData extends ForwardingMap { + + @ConstructorProperties({ "preference", "exchange" }) + private MXData(UnsignedInteger preference, String exchange) { + this.delegate = ImmutableMap. builder().put("preference", checkNotNull(preference, "preference")) + .put("exchange", checkNotNull(exchange, "exchange")).build(); + } + + private final ImmutableMap delegate; + + protected Map delegate() { + return delegate; + } + + /** + * specifies the preference given to this RR among others at the same owner. + * Lower values are preferred. + */ + public UnsignedInteger getPreference() { + return UnsignedInteger.class.cast(get("preference")); + } + + /** + * domain-name which specifies a host willing to act as a mail exchange for + * the owner name. + */ + public String getExchange() { + return String.class.cast(get("exchange")); + } + + public static MXData mx(int preference, String exchange) { + return builder().preference(preference).exchange(exchange).build(); + } + + public static MXData.Builder builder() { + return new Builder(); + } + + public MXData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private UnsignedInteger preference; + private String exchange; + + /** + * @see MXData#getPreference() + */ + public MXData.Builder preference(int preference) { + return preference(UnsignedInteger.valueOf(preference)); + } + + /** + * @see MXData#getPreference() + */ + public MXData.Builder preference(UnsignedInteger preference) { + this.preference = preference; + return this; + } + + /** + * @see MXData#getExchange() + */ + public MXData.Builder exchange(String exchange) { + this.exchange = exchange; + return this; + } + + public MXData build() { + return new MXData(preference, exchange); + } + + public MXData.Builder from(MXData in) { + return this.preference(in.getPreference()).exchange(in.getExchange()); + } + } +} diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.java new file mode 100644 index 0000000000..f1752fec52 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/NSData.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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; + +/** + * Corresponds to the binary representation of the {@code NS} (Name Server) RData + * + *

Example

+ * + *
+ * import static org.jclouds.dynect.v3.domain.rdata.NSData.ns;
+ * ...
+ * NSData rdata = ns("ns.foo.com.");
+ * 
+ * + * @see RFC 1035 + */ +public class NSData extends ForwardingMap { + private final ImmutableMap delegate; + + @ConstructorProperties("nsdname") + private NSData(String nsdname) { + this.delegate = ImmutableMap. of("nsdname", checkNotNull(nsdname, "nsdname")); + } + + protected Map delegate() { + return delegate; + } + + /** + * domain-name which specifies a host which should be authoritative for the + * specified class and domain. + */ + public String getNsdname() { + return get("nsdname").toString(); + } + + public static NSData ns(String nsdname) { + return builder().nsdname(nsdname).build(); + } + + public static NSData.Builder builder() { + return new Builder(); + } + + public NSData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String nsdname; + + /** + * @see NSData#getNsdname() + */ + public NSData.Builder nsdname(String nsdname) { + this.nsdname = nsdname; + return this; + } + + public NSData build() { + return new NSData(nsdname); + } + + public NSData.Builder from(NSData in) { + return this.nsdname(in.getNsdname()); + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java new file mode 100644 index 0000000000..57d2e74826 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/PTRData.java @@ -0,0 +1,92 @@ +/** + * 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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; + +/** + * Corresponds to the binary representation of the {@code PTR} (Pointer) RData + * + *

Example

+ * + *
+ * import static org.jclouds.dynect.v3.domain.rdata.NSData.ptr;
+ * ...
+ * NSData rdata = ptr("ptr.foo.com.");
+ * 
+ * + * @see RFC 1035 + */ +public class PTRData extends ForwardingMap { + private final ImmutableMap delegate; + + @ConstructorProperties("ptrdname") + private PTRData(String ptrdname) { + this.delegate = ImmutableMap. of("ptrdname", checkNotNull(ptrdname, "ptrdname")); + } + + protected Map delegate() { + return delegate; + } + + /** + * domain-name which points to some location in the domain name space. + */ + public String getPtrdname() { + return get("ptrdname").toString(); + } + + public static PTRData ptr(String ptrdname) { + return builder().ptrdname(ptrdname).build(); + } + + public static PTRData.Builder builder() { + return new Builder(); + } + + public PTRData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String ptrdname; + + /** + * @see PTRData#getPtrdname() + */ + public PTRData.Builder ptrdname(String ptrdname) { + this.ptrdname = ptrdname; + return this; + } + + public PTRData build() { + return new PTRData(ptrdname); + } + + public PTRData.Builder from(PTRData in) { + return this.ptrdname(in.getPtrdname()); + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java new file mode 100644 index 0000000000..1ccacaf64c --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SOAData.java @@ -0,0 +1,238 @@ +/** + * 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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; +import com.google.common.primitives.UnsignedInteger; + +/** + * Corresponds to the binary representation of the {@code SOA} (Start of Authority) RData + * + *

Example

+ * + *
+ * SOAData rdata = SOAData.builder()
+ *                        .rname("foo.com.")
+ *                        .mname("admin.foo.com.")
+ *                        .serial(1)
+ *                        .refresh(3600)
+ *                        .retry(600)
+ *                        .expire(604800)
+ *                        .minimum(60).build()
+ * 
+ * + * @see RFC 1035 + */ +public class SOAData extends ForwardingMap { + + @ConstructorProperties({ "mname", "rname", "serial", "refresh", "retry", "expire", "minimum" }) + private SOAData(String mname, String rname, UnsignedInteger serial, UnsignedInteger refresh, UnsignedInteger retry, + UnsignedInteger expire, UnsignedInteger minimum) { + this.delegate = ImmutableMap. builder() + .put("mname", checkNotNull(mname, "mname")) + .put("rname", checkNotNull(rname, "rname of %s", mname)) + .put("serial", checkNotNull(serial, "serial of %s", mname)) + .put("refresh", checkNotNull(refresh, "refresh of %s", mname)) + .put("retry", checkNotNull(retry, "retry of %s", mname)) + .put("expire", checkNotNull(expire, "expire of %s", mname)) + .put("minimum", checkNotNull(minimum, "minimum of %s", mname)).build(); + } + + private final ImmutableMap delegate; + + protected Map delegate() { + return delegate; + } + + /** + * domain-name of the name server that was the original or primary source of + * data for this zone + */ + public String getMname() { + return String.class.cast(get("mname")); + } + + /** + * domain-name which specifies the mailbox of the person responsible for this + * zone. + */ + public String getRname() { + return String.class.cast(get("rname")); + } + + /** + * version number of the original copy of the zone. + */ + public UnsignedInteger getSerial() { + return UnsignedInteger.class.cast(get("serial")); + } + + /** + * time interval before the zone should be refreshed + */ + public UnsignedInteger getRefresh() { + return UnsignedInteger.class.cast(get("refresh")); + } + + /** + * time interval that should elapse before a failed refresh should be retried + */ + public UnsignedInteger getRetry() { + return UnsignedInteger.class.cast(get("retry")); + } + + /** + * time value that specifies the upper limit on the time interval that can + * elapse before the zone is no longer authoritative. + */ + public UnsignedInteger getExpire() { + return UnsignedInteger.class.cast(get("expire")); + } + + /** + * minimum TTL field that should be exported with any RR from this zone. + */ + public UnsignedInteger getMinimum() { + return UnsignedInteger.class.cast(get("minimum")); + } + + public static SOAData.Builder builder() { + return new Builder(); + } + + public SOAData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String mname; + private String rname; + private UnsignedInteger serial; + private UnsignedInteger refresh; + private UnsignedInteger retry; + private UnsignedInteger expire; + private UnsignedInteger minimum; + + /** + * @see SOAData#getMname() + */ + public SOAData.Builder mname(String mname) { + this.mname = mname; + return this; + } + + /** + * @see SOAData#getRname() + */ + public SOAData.Builder rname(String rname) { + this.rname = rname; + return this; + } + + /** + * @see SOAData#getSerial() + */ + public SOAData.Builder serial(UnsignedInteger serial) { + this.serial = serial; + return this; + } + + /** + * @see SOAData#getSerial() + */ + public SOAData.Builder serial(int serial) { + return serial(UnsignedInteger.valueOf(serial)); + } + + /** + * @see SOAData#getRefresh() + */ + public SOAData.Builder refresh(UnsignedInteger refresh) { + this.refresh = refresh; + return this; + } + + /** + * @see SOAData#getRefresh() + */ + public SOAData.Builder refresh(int refresh) { + return refresh(UnsignedInteger.valueOf(refresh)); + } + + /** + * @see SOAData#getRetry() + */ + public SOAData.Builder retry(UnsignedInteger retry) { + this.retry = retry; + return this; + } + + /** + * @see SOAData#getRetry() + */ + public SOAData.Builder retry(int retry) { + return retry(UnsignedInteger.valueOf(retry)); + } + + /** + * @see SOAData#getExpire() + */ + public SOAData.Builder expire(UnsignedInteger expire) { + this.expire = expire; + return this; + } + + /** + * @see SOAData#getExpire() + */ + public SOAData.Builder expire(int expire) { + return expire(UnsignedInteger.valueOf(expire)); + } + + /** + * @see SOAData#getMinimum() + */ + public SOAData.Builder minimum(UnsignedInteger minimum) { + this.minimum = minimum; + return this; + } + + /** + * @see SOAData#getMinimum() + */ + public SOAData.Builder minimum(int minimum) { + return minimum(UnsignedInteger.valueOf(minimum)); + } + + public SOAData build() { + return new SOAData(mname, rname, serial, refresh, retry, expire, minimum); + } + + public SOAData.Builder from(SOAData in) { + return this.mname(in.getMname()).rname(in.getRname()).serial(in.getSerial()).refresh(in.getRefresh()) + .expire(in.getExpire()).minimum(in.getMinimum()); + } + } +} diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java new file mode 100644 index 0000000000..c1a257682c --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/SRVData.java @@ -0,0 +1,172 @@ +/** + * 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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; +import com.google.common.primitives.UnsignedInteger; + +/** + * Corresponds to the binary representation of the {@code SRV} (Service) RData + * + *

Example

+ * + *
+ * SRVData rdata = SRVData.builder()
+ *                        .priority(0)
+ *                        .weight(1)
+ *                        .port(80)
+ *                        .target("www.foo.com.").build()
+ * 
+ * + * @see RFC 2782 + */ +public class SRVData extends ForwardingMap { + + @ConstructorProperties({ "priority", "weight", "port", "target" }) + private SRVData(UnsignedInteger priority, UnsignedInteger weight, UnsignedInteger port, String target) { + this.delegate = ImmutableMap. builder() + .put("priority", checkNotNull(priority, "priority of %s", target)) + .put("weight", checkNotNull(weight, "weight of %s", target)) + .put("port", checkNotNull(port, "port of %s", target)) + .put("target", checkNotNull(target, "target")) + .build(); + } + + private final ImmutableMap delegate; + + protected Map delegate() { + return delegate; + } + + /** + * The priority of this target host. A client MUST attempt to contact the + * target host with the lowest-numbered priority it can reach; target hosts + * with the same priority SHOULD be tried in an order defined by the weight + * field. + */ + public UnsignedInteger getPriority() { + return UnsignedInteger.class.cast(get("priority")); + } + + /** + * The weight field specifies a relative weight for entries with the same + * priority. Larger weights SHOULD be given a proportionately higher + * probability of being selected. + */ + public UnsignedInteger getWeight() { + return UnsignedInteger.class.cast(get("weight")); + } + + /** + * The port on this target host of this service. + */ + public UnsignedInteger getPort() { + return UnsignedInteger.class.cast(get("port")); + } + + /** + * The domain name of the target host. There MUST be one or more address + * records for this name, the name MUST NOT be an alias. + */ + public String getTarget() { + return String.class.cast(get("target")); + } + + public static SRVData.Builder builder() { + return new Builder(); + } + + public SRVData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private UnsignedInteger priority; + private UnsignedInteger weight; + private UnsignedInteger port; + private String target; + + /** + * @see SRVData#getPriority() + */ + public SRVData.Builder priority(UnsignedInteger priority) { + this.priority = priority; + return this; + } + + /** + * @see SRVData#getPriority() + */ + public SRVData.Builder priority(int priority) { + return priority(UnsignedInteger.valueOf(priority)); + } + + /** + * @see SRVData#getWeight() + */ + public SRVData.Builder weight(UnsignedInteger weight) { + this.weight = weight; + return this; + } + + /** + * @see SRVData#getWeight() + */ + public SRVData.Builder weight(int weight) { + return weight(UnsignedInteger.valueOf(weight)); + } + + /** + * @see SRVData#getPort() + */ + public SRVData.Builder port(UnsignedInteger port) { + this.port = port; + return this; + } + + /** + * @see SRVData#getPort() + */ + public SRVData.Builder port(int port) { + return port(UnsignedInteger.valueOf(port)); + } + + /** + * @see SRVData#getTarget() + */ + public SRVData.Builder target(String target) { + this.target = target; + return this; + } + + public SRVData build() { + return new SRVData(priority, weight, port, target); + } + + public SRVData.Builder from(SRVData in) { + return this.priority(in.getPriority()).weight(in.getWeight()).port(in.getPort()).target(in.getTarget()); + } + } +} diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java new file mode 100644 index 0000000000..e20837906b --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/domain/rdata/TXTData.java @@ -0,0 +1,92 @@ +/** + * 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, String 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.dynect.v3.domain.rdata; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.beans.ConstructorProperties; +import java.util.Map; + +import com.google.common.collect.ForwardingMap; +import com.google.common.collect.ImmutableMap; + +/** + * Corresponds to the binary representation of the {@code TXT} (Text) RData + * + *

Example

+ * + *
+ * import static org.jclouds.dynect.v3.domain.rdata.NSData.txt;
+ * ...
+ * NSData rdata = txt("=spf1 ip4:1.1.1.1/24 ip4:2.2.2.2/24 -all");
+ * 
+ * + * @see RFC 1035 + */ +public class TXTData extends ForwardingMap { + private final ImmutableMap delegate; + + @ConstructorProperties("txtdata") + private TXTData(String txtdata) { + this.delegate = ImmutableMap. of("txtdata", checkNotNull(txtdata, "txtdata")); + } + + protected Map delegate() { + return delegate; + } + + /** + * One or more character-strings. + */ + public String getTxtdata() { + return get("txtdata").toString(); + } + + public static TXTData txt(String txtdata) { + return builder().txtdata(txtdata).build(); + } + + public static TXTData.Builder builder() { + return new Builder(); + } + + public TXTData.Builder toBuilder() { + return builder().from(this); + } + + public final static class Builder { + private String txtdata; + + /** + * @see TXTData#getTxtdata() + */ + public TXTData.Builder txtdata(String txtdata) { + this.txtdata = txtdata; + return this; + } + + public TXTData build() { + return new TXTData(txtdata); + } + + public TXTData.Builder from(TXTData in) { + return this.txtdata(in.getTxtdata()); + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordApi.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordApi.java new file mode 100644 index 0000000000..418c6c1027 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordApi.java @@ -0,0 +1,157 @@ +/** + * 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, String 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.dynect.v3.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import java.util.Map; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.dynect.v3.domain.SOARecord; +import org.jclouds.dynect.v3.domain.rdata.AAAAData; +import org.jclouds.dynect.v3.domain.rdata.AData; +import org.jclouds.dynect.v3.domain.rdata.CNAMEData; +import org.jclouds.dynect.v3.domain.rdata.MXData; +import org.jclouds.dynect.v3.domain.rdata.NSData; +import org.jclouds.dynect.v3.domain.rdata.PTRData; +import org.jclouds.dynect.v3.domain.rdata.SRVData; +import org.jclouds.dynect.v3.domain.rdata.TXTData; + +import com.google.common.collect.FluentIterable; + +/** + * @see RecordAsyncApi + * @author Adrian Cole + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface RecordApi { + /** + * Retrieves a list of resource record ids for all records of any type in the + * given zone; + */ + FluentIterable list(); + + /** + * retrieves a resource record without regard to type + * + * @return null if not found + */ + Record> get(RecordId recordId); + + /** + * Gets the {@link AAAARecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getAAAA(String fqdn, long recordId); + + /** + * Gets the {@link ARecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getA(String fqdn, long recordId); + + /** + * Gets the {@link CNAMERecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getCNAME(String fqdn, long recordId); + + /** + * Gets the {@link MXRecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getMX(String fqdn, long recordId); + + /** + * Gets the {@link NSRecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getNS(String fqdn, long recordId); + + /** + * Gets the {@link PTRRecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getPTR(String fqdn, long recordId); + + /** + * Gets the {@link SOARecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + SOARecord getSOA(String fqdn, long recordId); + + /** + * Gets the {@link SRVRecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getSRV(String fqdn, long recordId); + + /** + * Gets the {@link TXTRecord} or null if not present. + * + * @param fqdn + * {@link RecordId#getFQDN()} + * @param recordId + * {@link RecordId#getId()} + * @return null if not found + */ + Record getTXT(String fqdn, long recordId); +} diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java new file mode 100644 index 0000000000..744e6f14e5 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/RecordAsyncApi.java @@ -0,0 +1,197 @@ +/** + * 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, String 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.dynect.v3.features; + +import static com.google.common.base.Preconditions.checkNotNull; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static org.jclouds.http.Uris.uriBuilder; + +import java.net.URI; +import java.util.Map; + +import javax.inject.Named; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.dynect.v3.domain.SOARecord; +import org.jclouds.dynect.v3.domain.rdata.AAAAData; +import org.jclouds.dynect.v3.domain.rdata.AData; +import org.jclouds.dynect.v3.domain.rdata.CNAMEData; +import org.jclouds.dynect.v3.domain.rdata.MXData; +import org.jclouds.dynect.v3.domain.rdata.NSData; +import org.jclouds.dynect.v3.domain.rdata.PTRData; +import org.jclouds.dynect.v3.domain.rdata.SRVData; +import org.jclouds.dynect.v3.domain.rdata.TXTData; +import org.jclouds.dynect.v3.filters.SessionManager; +import org.jclouds.dynect.v3.functions.ToRecordIds; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.ExceptionParser; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.ListenableFuture; + +/** + * + * @see RecordApi + * @see doc + * @author Adrian Cole + */ +// required for all calls +@Produces(APPLICATION_JSON) +@Headers(keys = "API-Version", values = "{jclouds.api-version}") +@RequestFilters(SessionManager.class) +public interface RecordAsyncApi { + + /** + * @see RecordApi#list + */ + @Named("GetAllRecord") + @GET + @Path("/AllRecord/{zone}") + @ResponseParser(ToRecordIds.class) + ListenableFuture> list(); + + /** + * @see RecordApi#get + */ + @Named("GetRecord") + @GET + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture>> get(@BinderParam(RecordIdBinder.class) RecordId recordId); + + static class RecordIdBinder implements Binder { + @SuppressWarnings("unchecked") + @Override + public R bindToRequest(R request, Object recordId) { + RecordId valueToAppend = RecordId.class.cast(checkNotNull(recordId, "recordId")); + URI path = uriBuilder(request.getEndpoint()) + .appendPath("/{type}Record/{zone}/{fqdn}/{id}") + .build(ImmutableMap. builder() + .put("type", valueToAppend.getType()) + .put("zone", valueToAppend.getZone()) + .put("fqdn", valueToAppend.getFQDN()) + .put("id", valueToAppend.getId()).build()); + return (R) request.toBuilder().endpoint(path).build(); + } + } + + /** + * @see RecordApi#getAAAA + */ + @Named("GetAAAARecord") + @GET + @Path("/AAAARecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getAAAA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getA + */ + @Named("GetARecord") + @GET + @Path("/ARecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getCNAME + */ + @Named("GetCNAMERecord") + @GET + @Path("/CNAMERecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getCNAME(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getMX + */ + @Named("GetMXRecord") + @GET + @Path("/MXRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getMX(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getNS + */ + @Named("GetNSRecord") + @GET + @Path("/NSRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getNS(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getPTR + */ + @Named("GetPTRRecord") + @GET + @Path("/PTRRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getPTR(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getSOA + */ + @Named("GetSOARecord") + @GET + @Path("/SOARecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getSOA(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getSRV + */ + @Named("GetSRVRecord") + @GET + @Path("/SRVRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getSRV(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); + + /** + * @see RecordApi#getTXT + */ + @Named("GetTXTRecord") + @GET + @Path("/TXTRecord/{zone}/{fqdn}/{id}") + @SelectJson("data") + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture> getTXT(@PathParam("fqdn") String fqdn, @PathParam("id") long recordId); +} diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java index 2ae22a9262..bbe2fef85f 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/features/ZoneAsyncApi.java @@ -36,7 +36,7 @@ import org.jclouds.dynect.v3.domain.CreatePrimaryZone.ToFQDN; import org.jclouds.dynect.v3.domain.Job; import org.jclouds.dynect.v3.domain.Zone; import org.jclouds.dynect.v3.filters.SessionManager; -import org.jclouds.dynect.v3.functions.ExtractNames; +import org.jclouds.dynect.v3.functions.ExtractZoneNames; import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.Headers; @@ -72,7 +72,7 @@ public interface ZoneAsyncApi { @Named("ListZones") @GET @SelectJson("data") - @Transform(ExtractNames.class) + @Transform(ExtractZoneNames.class) ListenableFuture> list(); /** diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ExtractNames.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ExtractZoneNames.java similarity index 93% rename from labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ExtractNames.java rename to labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ExtractZoneNames.java index d79c627446..6df9142b51 100644 --- a/labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ExtractNames.java +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ExtractZoneNames.java @@ -28,7 +28,7 @@ import com.google.common.collect.FluentIterable; * @author Adrian Cole * */ -public final class ExtractNames implements Function, FluentIterable> { +public final class ExtractZoneNames implements Function, FluentIterable> { public FluentIterable apply(FluentIterable in) { return in.transform(ExtractNameInPath.INSTANCE); } diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ToRecordIds.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ToRecordIds.java new file mode 100644 index 0000000000..8a1ffd5fc2 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/functions/ToRecordIds.java @@ -0,0 +1,70 @@ +/** + * 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, String 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.dynect.v3.functions; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.functions.ParseFirstJsonValueNamed; +import org.jclouds.json.internal.GsonWrapper; + +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; +import com.google.inject.Inject; +import com.google.inject.TypeLiteral; + +/** + * Records come back encoded in REST paths, such as + * {@code /REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976583} + * + * @author Adrian Cole + * + */ +public final class ToRecordIds implements Function> { + private final ParseFirstJsonValueNamed> parser; + + @Inject + public ToRecordIds(GsonWrapper gsonView) { + this.parser = new ParseFirstJsonValueNamed>(checkNotNull(gsonView, "gsonView"), + new TypeLiteral>() { + }, "data"); + } + + public FluentIterable apply(HttpResponse response) { + checkNotNull(response, "response"); + return parser.apply(response).transform(ParsePath.INSTANCE); + } + + static enum ParsePath implements Function { + INSTANCE; + public static final Pattern DEFAULT_PATTERN = Pattern.compile("/REST/([a-zA-Z]+)Record/(.*)/(.*)/([0-9]+)"); + + public RecordId apply(String in) { + Matcher matcher = DEFAULT_PATTERN.matcher(in); + checkState(matcher.find() && matcher.groupCount() == 4, "%s didn't match %s", in, DEFAULT_PATTERN); + return RecordId.builder().type(matcher.group(1)).zone(matcher.group(2)).fqdn(matcher.group(3)) + .id(Long.parseLong(matcher.group(4))).build(); + } + } +} \ No newline at end of file diff --git a/labs/dynect/src/main/java/org/jclouds/dynect/v3/predicates/RecordPredicates.java b/labs/dynect/src/main/java/org/jclouds/dynect/v3/predicates/RecordPredicates.java new file mode 100644 index 0000000000..cf93969628 --- /dev/null +++ b/labs/dynect/src/main/java/org/jclouds/dynect/v3/predicates/RecordPredicates.java @@ -0,0 +1,55 @@ +/** + * 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, String 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.dynect.v3.predicates; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.dynect.v3.domain.RecordId; + +import com.google.common.base.Predicate; + +/** + * Predicates handy when working with Records + * + * @author Adrian Cole + */ +public class RecordPredicates { + + /** + * matches type of the given record + * + * @param type + * @return predicate that matches type + */ + public static Predicate typeEquals(final String type) { + checkNotNull(type, "type must be defined"); + + return new Predicate() { + @Override + public boolean apply(R record) { + return type.equals(record.getType()); + } + + @Override + public String toString() { + return "typeEquals(" + type + ")"; + } + }; + } +} diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java new file mode 100644 index 0000000000..b311360ed4 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiExpectTest.java @@ -0,0 +1,302 @@ +/** + * 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, String 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.dynect.v3.features; + +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +import org.jclouds.dynect.v3.DynECTApi; +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.dynect.v3.internal.BaseDynECTApiExpectTest; +import org.jclouds.dynect.v3.parse.GetAAAARecordResponseTest; +import org.jclouds.dynect.v3.parse.GetARecordResponseTest; +import org.jclouds.dynect.v3.parse.GetCNAMERecordResponseTest; +import org.jclouds.dynect.v3.parse.GetMXRecordResponseTest; +import org.jclouds.dynect.v3.parse.GetNSRecordResponseTest; +import org.jclouds.dynect.v3.parse.GetPTRRecordResponseTest; +import org.jclouds.dynect.v3.parse.GetRecordResponseTest; +import org.jclouds.dynect.v3.parse.GetSOARecordResponseTest; +import org.jclouds.dynect.v3.parse.GetSRVRecordResponseTest; +import org.jclouds.dynect.v3.parse.GetTXTRecordResponseTest; +import org.jclouds.dynect.v3.parse.ListRecordsResponseTest; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "RecordApiExpectTest") +public class RecordApiExpectTest extends BaseDynECTApiExpectTest { + HttpRequest getSOA = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/SOARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse soaResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_soa.json", APPLICATION_JSON)).build(); + + RecordId soaId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("SOA") + .id(50976579l).build(); + + public void testGetWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getSOA, soaResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").get(soaId).toString(), + new GetRecordResponseTest().expected().toString()); + } + + public void testGetWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getSOA, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").get(soaId)); + } + + HttpRequest getAAAA = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/AAAARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse aaaaResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_aaaa.json", APPLICATION_JSON)).build(); + + RecordId aaaaId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("AAAA") + .id(50976579l).build(); + + public void testGetAAAAWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getAAAA, aaaaResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getAAAA(aaaaId.getFQDN(), aaaaId.getId()).toString(), + new GetAAAARecordResponseTest().expected().toString()); + } + + public void testGetAAAAWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getAAAA, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getAAAA(aaaaId.getFQDN(), aaaaId.getId())); + } + + HttpRequest getA = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/ARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse aResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_a.json", APPLICATION_JSON)).build(); + + RecordId aId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("A") + .id(50976579l).build(); + + public void testGetAWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getA, aResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getA(aId.getFQDN(), aId.getId()).toString(), + new GetARecordResponseTest().expected().toString()); + } + + public void testGetAWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getA, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getA(aId.getFQDN(), aId.getId())); + } + + HttpRequest getCNAME = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/CNAMERecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse cnameResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_cname.json", APPLICATION_JSON)).build(); + + RecordId cnameId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("CNAME") + .id(50976579l).build(); + + public void testGetCNAMEWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getCNAME, cnameResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getCNAME(cnameId.getFQDN(), cnameId.getId()).toString(), + new GetCNAMERecordResponseTest().expected().toString()); + } + + public void testGetCNAMEWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getCNAME, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getCNAME(cnameId.getFQDN(), cnameId.getId())); + } + + HttpRequest getMX = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/MXRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse mxResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_mx.json", APPLICATION_JSON)).build(); + + RecordId mxId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("MX") + .id(50976579l).build(); + + public void testGetMXWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getMX, mxResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getMX(mxId.getFQDN(), mxId.getId()).toString(), + new GetMXRecordResponseTest().expected().toString()); + } + + public void testGetMXWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getMX, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getMX(mxId.getFQDN(), mxId.getId())); + } + + HttpRequest getNS = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse nsResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_ns.json", APPLICATION_JSON)).build(); + + RecordId nsId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("NS") + .id(50976579l).build(); + + public void testGetNSWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getNS, nsResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getNS(nsId.getFQDN(), nsId.getId()).toString(), + new GetNSRecordResponseTest().expected().toString()); + } + + public void testGetNSWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getNS, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getNS(nsId.getFQDN(), nsId.getId())); + } + + HttpRequest getPTR = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/PTRRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse ptrResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_ptr.json", APPLICATION_JSON)).build(); + + RecordId ptrId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("PTR") + .id(50976579l).build(); + + public void testGetPTRWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getPTR, ptrResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getPTR(ptrId.getFQDN(), ptrId.getId()).toString(), + new GetPTRRecordResponseTest().expected().toString()); + } + + public void testGetPTRWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getPTR, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getPTR(ptrId.getFQDN(), ptrId.getId())); + } + + public void testGetSOAWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getSOA, soaResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getSOA(soaId.getFQDN(), soaId.getId()).toString(), + new GetSOARecordResponseTest().expected().toString()); + } + + public void testGetSOAWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getSOA, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getSOA(soaId.getFQDN(), soaId.getId())); + } + + HttpRequest getSRV = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/SRVRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse srvResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_srv.json", APPLICATION_JSON)).build(); + + RecordId srvId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("SRV") + .id(50976579l).build(); + + public void testGetSRVWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getSRV, srvResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getSRV(srvId.getFQDN(), srvId.getId()).toString(), + new GetSRVRecordResponseTest().expected().toString()); + } + + HttpRequest getTXT = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/TXTRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse txtResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/get_record_txt.json", APPLICATION_JSON)).build(); + + RecordId txtId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("TXT") + .id(50976579l).build(); + + public void testGetTXTWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, getTXT, txtResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getTXT(txtId.getFQDN(), txtId.getId()).toString(), + new GetTXTRecordResponseTest().expected().toString()); + } + + public void testGetTXTWhenResponseIs404() { + DynECTApi fail = requestsSendResponses(createSession, createSessionResponse, getTXT, notFound); + assertNull(fail.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").getTXT(txtId.getFQDN(), txtId.getId())); + } + + HttpRequest list = HttpRequest.builder().method("GET") + .endpoint("https://api2.dynect.net/REST/AllRecord/adrianc.zone.dynecttest.jclouds.org") + .addHeader("API-Version", "3.3.7") + .addHeader("Auth-Token", authToken) + .payload(emptyJsonPayload()).build(); + + HttpResponse listResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/list_records.json", APPLICATION_JSON)).build(); + + public void testListWhenResponseIs2xx() { + DynECTApi success = requestsSendResponses(createSession, createSessionResponse, list, listResponse); + assertEquals(success.getRecordApiForZone("adrianc.zone.dynecttest.jclouds.org").list().toString(), + new ListRecordsResponseTest().expected().toString()); + } +} diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiLiveTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiLiveTest.java new file mode 100644 index 0000000000..d94dac659b --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/features/RecordApiLiveTest.java @@ -0,0 +1,165 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, String 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.dynect.v3.features; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.util.logging.Logger.getAnonymousLogger; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.util.Map; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.dynect.v3.domain.SOARecord; +import org.jclouds.dynect.v3.domain.rdata.AAAAData; +import org.jclouds.dynect.v3.domain.rdata.AData; +import org.jclouds.dynect.v3.domain.rdata.CNAMEData; +import org.jclouds.dynect.v3.domain.rdata.MXData; +import org.jclouds.dynect.v3.domain.rdata.NSData; +import org.jclouds.dynect.v3.domain.rdata.PTRData; +import org.jclouds.dynect.v3.domain.rdata.SOAData; +import org.jclouds.dynect.v3.domain.rdata.SRVData; +import org.jclouds.dynect.v3.domain.rdata.TXTData; +import org.jclouds.dynect.v3.internal.BaseDynECTApiLiveTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "RecordApiLiveTest") +public class RecordApiLiveTest extends BaseDynECTApiLiveTest { + + private void checkRecordId(RecordId record) { + assertTrue(record.getId() > 0, "Id cannot be zero for RecordId: " + record); + checkNotNull(record.getType(), "Type cannot be null for RecordId: %s", record); + checkNotNull(record.getFQDN(), "FQDN cannot be null for RecordId: %s", record); + checkNotNull(record.getZone(), "Serial cannot be null for RecordId: %s", record); + } + + private void checkRecord(Record> record) { + checkRecordId(record); + assertTrue(record.getRData().size() > 0, "RData entries should be present for cannot be zero for Record: " + + record); + assertTrue(record.getTTL() > -1, "TTL cannot be negative for RecordId: " + record); + } + + @Test + protected void testListAndGetRecords() { + for (String zone : context.getApi().getZoneApi().list()) { + RecordApi api = context.getApi().getRecordApiForZone(zone); + ImmutableList records = api.list().toImmutableList(); + getAnonymousLogger().info("zone: " + zone + " record count: " + records.size()); + + for (RecordId recordId : records) { + Record> record; + if ("AAAA".equals(recordId.getType())) { + record = checkAAAARecord(api.getAAAA(recordId.getFQDN(), recordId.getId())); + } else if ("A".equals(recordId.getType())) { + record = checkARecord(api.getA(recordId.getFQDN(), recordId.getId())); + } else if ("CNAME".equals(recordId.getType())) { + record = checkCNAMERecord(api.getCNAME(recordId.getFQDN(), recordId.getId())); + } else if ("MX".equals(recordId.getType())) { + record = checkMXRecord(api.getMX(recordId.getFQDN(), recordId.getId())); + } else if ("NS".equals(recordId.getType())) { + record = checkNSRecord(api.getNS(recordId.getFQDN(), recordId.getId())); + } else if ("PTR".equals(recordId.getType())) { + record = checkPTRRecord(api.getPTR(recordId.getFQDN(), recordId.getId())); + } else if ("SOA".equals(recordId.getType())) { + record = checkSOARecord(api.getSOA(recordId.getFQDN(), recordId.getId())); + } else if ("SRV".equals(recordId.getType())) { + record = checkSRVRecord(api.getSRV(recordId.getFQDN(), recordId.getId())); + } else if ("TXT".equals(recordId.getType())) { + record = checkTXTRecord(api.getTXT(recordId.getFQDN(), recordId.getId())); + } else { + record = api.get(recordId); + } + assertEquals(record, recordId); + checkRecord(record); + } + } + } + + private Record checkAAAARecord(Record record) { + AAAAData rdata = record.getRData(); + checkNotNull(rdata.getAddress(), "rdata.address cannot be null for AAAARecord: %s", record); + return record; + } + + private Record checkARecord(Record record) { + AData rdata = record.getRData(); + checkNotNull(rdata.getAddress(), "rdata.address cannot be null for ARecord: %s", record); + return record; + } + + private Record checkCNAMERecord(Record record) { + CNAMEData rdata = record.getRData(); + checkNotNull(rdata.getCname(), "rdata.cname cannot be null for CNAMERecord: %s", record); + return record; + } + + private Record checkMXRecord(Record record) { + MXData rdata = record.getRData(); + checkNotNull(rdata.getPreference(), "rdata.preference cannot be null for MXRecord: %s", record); + checkNotNull(rdata.getExchange(), "rdata.exchange cannot be null for MXRecord: %s", record); + return record; + } + + private Record checkNSRecord(Record record) { + NSData rdata = record.getRData(); + checkNotNull(rdata.getNsdname(), "rdata.nsdname cannot be null for NSRecord: %s", record); + return record; + } + + private Record checkPTRRecord(Record record) { + PTRData rdata = record.getRData(); + checkNotNull(rdata.getPtrdname(), "rdata.ptrdname cannot be null for PTRRecord: %s", record); + return record; + } + + private SOARecord checkSOARecord(SOARecord record) { + checkNotNull(record.getSerialStyle(), "SerialStyle cannot be null for SOARecord: %s", record); + SOAData rdata = record.getRData(); + checkNotNull(rdata.getMname(), "rdata.mname cannot be null for SOARecord: %s", record); + checkNotNull(rdata.getRname(), "rdata.rname cannot be null for SOARecord: %s", record); + checkNotNull(rdata.getSerial(), "rdata.serial cannot be null for SOARecord: %s", record); + checkNotNull(rdata.getRefresh(), "rdata.refresh cannot be null for SOARecord: %s", record); + checkNotNull(rdata.getRetry(), "rdata.retry cannot be null for SOARecord: %s", record); + checkNotNull(rdata.getExpire(), "rdata.expire cannot be null for SOARecord: %s", record); + checkNotNull(rdata.getMinimum(), "rdata.minimum cannot be null for SOARecord: %s", record); + return record; + } + + private Record checkSRVRecord(Record record) { + SRVData rdata = record.getRData(); + checkNotNull(rdata.getPriority(), "rdata.priority cannot be null for SRVRecord: %s", record); + checkNotNull(rdata.getWeight(), "rdata.weight cannot be null for SRVRecord: %s", record); + checkNotNull(rdata.getPort(), "rdata.port cannot be null for SRVRecord: %s", record); + checkNotNull(rdata.getTarget(), "rdata.target cannot be null for SRVRecord: %s", record); + return record; + } + + private Record checkTXTRecord(Record record) { + TXTData rdata = record.getRData(); + checkNotNull(rdata.getTxtdata(), "rdata.txtdata cannot be null for TXTRecord: %s", record); + return record; + } +} diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ExtractNamesTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ExtractZoneNamesTest.java similarity index 87% rename from labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ExtractNamesTest.java rename to labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ExtractZoneNamesTest.java index 8935cda76c..35fb2c7d9c 100644 --- a/labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ExtractNamesTest.java +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ExtractZoneNamesTest.java @@ -21,7 +21,7 @@ package org.jclouds.dynect.v3.functions; import static org.testng.Assert.assertEquals; -import org.jclouds.dynect.v3.functions.ExtractNames.ExtractNameInPath; +import org.jclouds.dynect.v3.functions.ExtractZoneNames.ExtractNameInPath; import org.testng.annotations.Test; import com.google.common.collect.FluentIterable; @@ -31,14 +31,14 @@ import com.google.common.collect.ImmutableSet; * @author Adrian Cole */ @Test(groups = "unit") -public class ExtractNamesTest { - ExtractNames fn = new ExtractNames(); +public class ExtractZoneNamesTest { + ExtractZoneNames fn = new ExtractZoneNames(); public void testExtractNameInPath() { assertEquals(ExtractNameInPath.INSTANCE.apply("/REST/Zone/jclouds.org/"), "jclouds.org"); } - public void testExtractNames() { + public void testExtractZoneNames() { assertEquals(fn.apply(FluentIterable.from(ImmutableSet.of("/REST/Zone/jclouds.org/"))).toImmutableSet(), ImmutableSet.of("jclouds.org")); } diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ToRecordIdsTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ToRecordIdsTest.java new file mode 100644 index 0000000000..946c73eff4 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/functions/ToRecordIdsTest.java @@ -0,0 +1,50 @@ +/** + * 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.dynect.v3.functions; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.dynect.v3.functions.ToRecordIds.ParsePath; +import org.jclouds.json.internal.GsonWrapper; +import org.testng.annotations.Test; + +import com.google.gson.Gson; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ToRecordIdsTest { + ToRecordIds fn = new ToRecordIds(new GsonWrapper(new Gson())); + RecordId recordId = RecordId.builder() + .id(50976583) + .type("NS") + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .build(); + + public void testParsePath() { + assertEquals( + ParsePath.INSTANCE + .apply("/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976583"), + recordId); + } +} diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetAAAARecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetAAAARecordResponseTest.java new file mode 100644 index 0000000000..93374c0478 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetAAAARecordResponseTest.java @@ -0,0 +1,55 @@ +/** + * 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, String 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.dynect.v3.parse; +import static org.jclouds.dynect.v3.domain.rdata.AAAAData.aaaa; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.AAAAData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetAAAARecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_aaaa.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("egg.org") + .fqdn("egg.org") + .type("AAAA") + .id(50959331) + .ttl(86400) + .rdata(aaaa("2406:bbbb:ff00::6b14:aaaa")) + .build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetARecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetARecordResponseTest.java new file mode 100644 index 0000000000..bffd860aad --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetARecordResponseTest.java @@ -0,0 +1,55 @@ +/** + * 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, String 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.dynect.v3.parse; +import static org.jclouds.dynect.v3.domain.rdata.AData.a; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.AData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetARecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_a.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("egg.org") + .fqdn("egg.org") + .type("A") + .id(50959331) + .ttl(86400) + .rdata(a("1.1.1.1")) + .build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetCNAMERecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetCNAMERecordResponseTest.java new file mode 100644 index 0000000000..15cb8b56d8 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetCNAMERecordResponseTest.java @@ -0,0 +1,55 @@ +/** + * 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, String 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.dynect.v3.parse; +import static org.jclouds.dynect.v3.domain.rdata.CNAMEData.cname; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.CNAMEData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetCNAMERecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_cname.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("egg.org") + .fqdn("egg.org") + .type("CNAME") + .id(50959331) + .ttl(86400) + .rdata(cname("prod-LB-359594650.us-east-1.elb.amazonaws.com.")) + .build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetMXRecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetMXRecordResponseTest.java new file mode 100644 index 0000000000..6d9ca6cdb4 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetMXRecordResponseTest.java @@ -0,0 +1,55 @@ +/** + * 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, String 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.dynect.v3.parse; +import static org.jclouds.dynect.v3.domain.rdata.MXData.mx; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.MXData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetMXRecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_mx.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("egg.org") + .fqdn("egg.org") + .type("MX") + .id(50959331) + .ttl(86400) + .rdata(mx(10, "mail.egg.org.")) + .build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetNSRecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetNSRecordResponseTest.java new file mode 100644 index 0000000000..093964c758 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetNSRecordResponseTest.java @@ -0,0 +1,55 @@ +/** + * 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.dynect.v3.parse; +import static org.jclouds.dynect.v3.domain.rdata.NSData.ns; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.NSData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetNSRecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_ns.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("egg.org") + .fqdn("egg.org") + .type("NS") + .id(50959331) + .ttl(86400) + .rdata(ns("ns4.p28.dynect.net.")) + .build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetPTRRecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetPTRRecordResponseTest.java new file mode 100644 index 0000000000..8a12ec8544 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetPTRRecordResponseTest.java @@ -0,0 +1,55 @@ +/** + * 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, String 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.dynect.v3.parse; +import static org.jclouds.dynect.v3.domain.rdata.PTRData.ptr; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.PTRData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetPTRRecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_ptr.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("egg.org") + .fqdn("1.2.3.0.0.0.0.0.0.0.0.0.0.0.0.0.d.9.2.1.4.0.0.7.0.c.6.8.0.0.a.2.ip6.arpa") + .type("PTR") + .id(50959331) + .ttl(86400) + .rdata(ptr("egg.org.")) + .build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetRecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetRecordResponseTest.java new file mode 100644 index 0000000000..496338b088 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetRecordResponseTest.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.dynect.v3.parse; + +import java.util.Map; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetRecordResponseTest extends BaseDynECTParseTest>> { + + @Override + public String resource() { + return "/get_record_soa.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record> expected() { + return Record.> builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("SOA") + .id(50976579l) + .ttl(3600) + // TODO: default parse to unsigned + .rdata(ImmutableMap. builder() + .put("rname", "1\\.5\\.7-SNAPSHOT@jclouds.org.") + .put("retry", 600.0) + .put("mname", "ns1.p28.dynect.net.") + .put("minimum", 60.0) + .put("refresh", 3600.0) + .put("expire", 604800.0) + .put("serial", 1.0).build()).build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSOARecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSOARecordResponseTest.java new file mode 100644 index 0000000000..3b689458c3 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSOARecordResponseTest.java @@ -0,0 +1,63 @@ +/** + * 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.dynect.v3.parse; + +import static org.jclouds.dynect.v3.domain.Zone.SerialStyle.INCREMENT; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.SOARecord; +import org.jclouds.dynect.v3.domain.rdata.SOAData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetSOARecordResponseTest extends BaseDynECTParseTest { + + @Override + public String resource() { + return "/get_record_soa.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public SOARecord expected() { + return SOARecord.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("SOA") + .id(50976579l) + .ttl(3600) + .serialStyle(INCREMENT) + .rdata(SOAData.builder() + .rname("1\\.5\\.7-SNAPSHOT@jclouds.org.") + .retry(600) + .mname("ns1.p28.dynect.net.") + .minimum(60) + .refresh(3600) + .expire(604800) + .serial(1).build()).build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSRVRecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSRVRecordResponseTest.java new file mode 100644 index 0000000000..e0e7858868 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetSRVRecordResponseTest.java @@ -0,0 +1,57 @@ +/** + * 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.dynect.v3.parse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.SRVData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetSRVRecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_srv.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("_http._tcp.www.jclouds.org.") + .type("SRV") + .id(50976579l) + .ttl(3600) + .rdata(SRVData.builder() + .priority(0) + .weight(2) + .port(80) + .target("www.jclouds.org.").build()).build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetTXTRecordResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetTXTRecordResponseTest.java new file mode 100644 index 0000000000..f5209b3a99 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/GetTXTRecordResponseTest.java @@ -0,0 +1,55 @@ +/** + * 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, String 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.dynect.v3.parse; +import static org.jclouds.dynect.v3.domain.rdata.TXTData.txt; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.dynect.v3.domain.Record; +import org.jclouds.dynect.v3.domain.rdata.TXTData; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.SelectJson; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class GetTXTRecordResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/get_record_txt.json"; + } + + @Override + @SelectJson("data") + @Consumes(MediaType.APPLICATION_JSON) + public Record expected() { + return Record. builder() + .zone("egg.org") + .fqdn("sm._domainkey.email.egg.org") + .type("TXT") + .id(50959331) + .ttl(86400) + .rdata(txt("k=rsa\\; p=4KAtUdsUGRtjPHE1rsyFYs8XVzvdke8pXnoo+80Kj5b6C37rnyCmZ0w1R5LY==")) + .build(); + } +} \ No newline at end of file diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListRecordsResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListRecordsResponseTest.java new file mode 100644 index 0000000000..ee9dbdcd73 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListRecordsResponseTest.java @@ -0,0 +1,57 @@ +/** + * 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.dynect.v3.parse; + +import org.jclouds.dynect.v3.domain.RecordId; +import org.jclouds.dynect.v3.domain.RecordId.Builder; +import org.jclouds.dynect.v3.functions.ToRecordIds; +import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; +import org.jclouds.rest.annotations.ResponseParser; +import org.testng.annotations.Test; + +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit") +public class ListRecordsResponseTest extends BaseDynECTParseTest> { + + @Override + public String resource() { + return "/list_records.json"; + } + + @Override + @ResponseParser(ToRecordIds.class) + public FluentIterable expected() { + Builder builder = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org"); + return FluentIterable.from(ImmutableSet. builder() + .add(builder.type("SOA").id(50976579l).build()) + .add(builder.type("NS").id(50976580l).build()) + .add(builder.type("NS").id(50976581l).build()) + .add(builder.type("NS").id(50976582l).build()) + .add(builder.type("NS").id(50976583l).build()) + .build()); + } +} diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListZonesResponseTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListZonesResponseTest.java index 41e1b2e6c8..3bb5bb219a 100644 --- a/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListZonesResponseTest.java +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/parse/ListZonesResponseTest.java @@ -21,7 +21,7 @@ package org.jclouds.dynect.v3.parse; import static com.google.common.base.Functions.compose; -import org.jclouds.dynect.v3.functions.ExtractNames; +import org.jclouds.dynect.v3.functions.ExtractZoneNames; import org.jclouds.dynect.v3.internal.BaseDynECTParseTest; import org.jclouds.http.HttpResponse; import org.jclouds.rest.annotations.SelectJson; @@ -52,6 +52,6 @@ public class ListZonesResponseTest extends BaseDynECTParseTest> parser(Injector i) { - return compose(new ExtractNames(), super.parser(i)); + return compose(new ExtractZoneNames(), super.parser(i)); } } diff --git a/labs/dynect/src/test/java/org/jclouds/dynect/v3/predicates/RecordPredicatesTest.java b/labs/dynect/src/test/java/org/jclouds/dynect/v3/predicates/RecordPredicatesTest.java new file mode 100644 index 0000000000..868100c7f8 --- /dev/null +++ b/labs/dynect/src/test/java/org/jclouds/dynect/v3/predicates/RecordPredicatesTest.java @@ -0,0 +1,29 @@ +package org.jclouds.dynect.v3.predicates; + +import static org.jclouds.dynect.v3.predicates.RecordPredicates.typeEquals; + +import org.jclouds.dynect.v3.domain.RecordId; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit") +public class RecordPredicatesTest { + RecordId recordId = RecordId.builder() + .zone("adrianc.zone.dynecttest.jclouds.org") + .fqdn("adrianc.zone.dynecttest.jclouds.org") + .type("SOA") + .id(50976579l).build(); + + @Test + public void testTypeEqualsWhenEqual() { + assert typeEquals("SOA").apply(recordId); + } + + @Test + public void testTypeEqualsWhenNotEqual() { + assert !typeEquals("NS").apply(recordId); + } +} diff --git a/labs/dynect/src/test/resources/get_record_a.json b/labs/dynect/src/test/resources/get_record_a.json new file mode 100644 index 0000000000..8c3b1db8ca --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_a.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "egg.org", "ttl": 86400, "fqdn": "egg.org", "record_type": "A", "rdata": {"address": "1.1.1.1"}, "record_id": 50959331}, "job_id": 274279510, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_aaaa.json b/labs/dynect/src/test/resources/get_record_aaaa.json new file mode 100644 index 0000000000..7173d69a87 --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_aaaa.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "egg.org", "ttl": 86400, "fqdn": "egg.org", "record_type": "AAAA", "rdata": {"address": "2406:bbbb:ff00::6b14:aaaa"}, "record_id": 50959331}, "job_id": 274279510, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_cname.json b/labs/dynect/src/test/resources/get_record_cname.json new file mode 100644 index 0000000000..29048414b9 --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_cname.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "egg.org", "ttl": 86400, "fqdn": "egg.org", "record_type": "CNAME", "rdata": {"cname": "prod-LB-359594650.us-east-1.elb.amazonaws.com."}, "record_id": 50959331}, "job_id": 274279510, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_mx.json b/labs/dynect/src/test/resources/get_record_mx.json new file mode 100644 index 0000000000..e5387c8d9d --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_mx.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "egg.org", "ttl": 86400, "fqdn": "egg.org", "record_type": "MX", "rdata": {"preference": 10, "exchange": "mail.egg.org."}, "record_id": 50959331}, "job_id": 274279510, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_ns.json b/labs/dynect/src/test/resources/get_record_ns.json new file mode 100644 index 0000000000..c26c2dabdb --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_ns.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "egg.org", "ttl": 86400, "fqdn": "egg.org", "record_type": "NS", "rdata": {"nsdname": "ns4.p28.dynect.net."}, "record_id": 50959331}, "job_id": 274279510, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_ptr.json b/labs/dynect/src/test/resources/get_record_ptr.json new file mode 100644 index 0000000000..4e9120e173 --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_ptr.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "egg.org", "ttl": 86400, "fqdn": "1.2.3.0.0.0.0.0.0.0.0.0.0.0.0.0.d.9.2.1.4.0.0.7.0.c.6.8.0.0.a.2.ip6.arpa", "record_type": "PTR", "rdata": {"ptrdname": "egg.org."}, "record_id": 50959331}, "job_id": 274279510, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_soa.json b/labs/dynect/src/test/resources/get_record_soa.json new file mode 100644 index 0000000000..c7460ccb44 --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_soa.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "adrianc.zone.dynecttest.jclouds.org", "ttl": 3600, "fqdn": "adrianc.zone.dynecttest.jclouds.org", "record_type": "SOA", "rdata": {"rname": "1\\.5\\.7-SNAPSHOT@jclouds.org.", "retry": 600, "mname": "ns1.p28.dynect.net.", "minimum": 60, "refresh": 3600, "expire": 604800, "serial": 1}, "record_id": 50976579, "serial_style": "increment"}, "job_id": 273523378, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_srv.json b/labs/dynect/src/test/resources/get_record_srv.json new file mode 100644 index 0000000000..d231cbde5b --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_srv.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "adrianc.zone.dynecttest.jclouds.org", "ttl": 3600, "fqdn": "_http._tcp.www.jclouds.org.", "record_type": "SRV", "rdata": {"priority": 0, "weight": 2, "port": 80, "target": "www.jclouds.org."}, "record_id": 50976579}, "job_id": 273523378, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/get_record_txt.json b/labs/dynect/src/test/resources/get_record_txt.json new file mode 100644 index 0000000000..ab5d3395fd --- /dev/null +++ b/labs/dynect/src/test/resources/get_record_txt.json @@ -0,0 +1 @@ +{"status": "success", "data": {"zone": "egg.org", "ttl": 86400, "fqdn": "sm._domainkey.email.egg.org", "record_type": "TXT", "rdata": {"txtdata": "k=rsa\\; p=4KAtUdsUGRtjPHE1rsyFYs8XVzvdke8pXnoo+80Kj5b6C37rnyCmZ0w1R5LY=="}, "record_id": 50959331}, "job_id": 274279510, "msgs": [{"INFO": "get: Found the record", "SOURCE": "API-B", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file diff --git a/labs/dynect/src/test/resources/list_records.json b/labs/dynect/src/test/resources/list_records.json new file mode 100644 index 0000000000..05e8da098d --- /dev/null +++ b/labs/dynect/src/test/resources/list_records.json @@ -0,0 +1 @@ +{"status": "success", "data": ["/REST/SOARecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976579", "/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976580", "/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976581", "/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976582", "/REST/NSRecord/adrianc.zone.dynecttest.jclouds.org/adrianc.zone.dynecttest.jclouds.org/50976583"], "job_id": 273523368, "msgs": [{"INFO": "get_tree: Here is your zone tree", "SOURCE": "BLL", "ERR_CD": null, "LVL": "INFO"}]} \ No newline at end of file