diff --git a/labs/ultradns-ws/pom.xml b/labs/ultradns-ws/pom.xml
index a4bef1f225..163b0c0977 100644
--- a/labs/ultradns-ws/pom.xml
+++ b/labs/ultradns-ws/pom.xml
@@ -34,7 +34,7 @@
bundle
- http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01
+ https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01
v01
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java
index 5e37e6a5df..a0119c3b3d 100644
--- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java
@@ -18,7 +18,9 @@
*/
package org.jclouds.ultradns.ws;
+import org.jclouds.rest.annotations.Delegate;
import org.jclouds.ultradns.ws.domain.Account;
+import org.jclouds.ultradns.ws.features.ZoneApi;
/**
* Provides access to Neustar UltraDNS via the SOAP API
@@ -34,4 +36,9 @@ public interface UltraDNSWSApi {
*/
Account getCurrentAccount();
+ /**
+ * Provides synchronous access to Zone features.
+ */
+ @Delegate
+ ZoneApi getZoneApi();
}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java
index 3d430529ad..a82a68fd14 100644
--- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java
@@ -67,7 +67,7 @@ public class UltraDNSWSApiMetadata extends BaseRestApiMetadata {
.credentialName("Password")
.version("v01")
.documentation(URI.create("https://www.ultradns.net/api/NUS_API_XML_SOAP.pdf"))
- .defaultEndpoint("http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01")
+ .defaultEndpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.defaultProperties(UltraDNSWSApiMetadata.defaultProperties())
.defaultModule(UltraDNSWSRestClientModule.class);
}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java
index 002a3f71a2..766bb3c554 100644
--- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java
@@ -20,13 +20,14 @@ package org.jclouds.ultradns.ws;
import javax.inject.Named;
import javax.ws.rs.POST;
-import javax.ws.rs.Path;
+import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.Payload;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.ultradns.ws.domain.Account;
+import org.jclouds.ultradns.ws.features.ZoneAsyncApi;
import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
import org.jclouds.ultradns.ws.xml.AccountHandler;
@@ -36,6 +37,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* Provides access to Neustar UltraDNS via the SOAP API
*
*
+ * @see
* @see
* @author Adrian Cole
*/
@@ -48,9 +50,13 @@ public interface UltraDNSWSAsyncApi {
*/
@Named("getAccountsListOfUser")
@POST
- @Path("/")
@XMLResponseParser(AccountHandler.class)
- @Payload("")
+ @Payload("")
ListenableFuture getCurrentAccount();
+ /**
+ * Provides asynchronous access to Zone features.
+ */
+ @Delegate
+ ZoneAsyncApi getZoneApi();
}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSError.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSError.java
new file mode 100644
index 0000000000..1952ee0b91
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSError.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws;
+
+import static com.google.common.base.Objects.equal;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * @author Adrian Cole
+ */
+public final class UltraDNSWSError {
+ public static UltraDNSWSError fromCodeAndDescription(int code, String description) {
+ return new UltraDNSWSError(code, description);
+ }
+
+ private final int code;
+ private final String description;
+
+ private UltraDNSWSError(int code, String description) {
+ this.code = code;
+ this.description = checkNotNull(description, "description for code %s", code);
+ }
+
+ /**
+ * The error code. ex {@code 1801}
+ */
+ public int getCode() {
+ return code;
+ }
+
+ /**
+ * The description of the error. ex {@code Zone does not exist in the system.}
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || getClass() != obj.getClass())
+ return false;
+ UltraDNSWSError that = UltraDNSWSError.class.cast(obj);
+ return equal(this.code, that.code) && equal(this.description, that.description);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Error %s: %s", code, description);
+ }
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java
index 270fe11e6f..1a0b1b3cc0 100644
--- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java
@@ -63,7 +63,7 @@ public class UltraDNSWSProviderMetadata extends BaseProviderMetadata {
.homepage(URI.create("http://www.neustar.biz/enterprise/dns-services/what-is-external-dns"))
.console(URI.create("https://www.ultradns.net"))
.iso3166Codes("US-CA", "US-VA") // TODO
- .endpoint("http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01")
+ .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
.defaultProperties(UltraDNSWSProviderMetadata.defaultProperties());
}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSResponseException.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSResponseException.java
new file mode 100644
index 0000000000..1137a4a2e6
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSResponseException.java
@@ -0,0 +1,44 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws;
+
+import org.jclouds.http.HttpCommand;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.http.HttpResponseException;
+
+/**
+ * @see UltraDNSWSError
+ * @author Adrian Cole
+ */
+public class UltraDNSWSResponseException extends HttpResponseException {
+
+ private static final long serialVersionUID = 5493782874839736777L;
+
+ private final UltraDNSWSError error;
+
+ public UltraDNSWSResponseException(HttpCommand command, HttpResponse response, UltraDNSWSError error) {
+ super(error.toString(), command, response);
+ this.error = error;
+ }
+
+ public UltraDNSWSError getError() {
+ return error;
+ }
+
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java
index 46239aa14c..a6fcadef82 100644
--- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java
@@ -20,10 +20,18 @@ package org.jclouds.ultradns.ws.config;
import java.util.Map;
+import org.jclouds.http.HttpErrorHandler;
+import org.jclouds.http.HttpRetryHandler;
+import org.jclouds.http.annotation.ClientError;
+import org.jclouds.http.annotation.Redirection;
+import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.config.RestClientModule;
import org.jclouds.ultradns.ws.UltraDNSWSApi;
import org.jclouds.ultradns.ws.UltraDNSWSAsyncApi;
+import org.jclouds.ultradns.ws.features.ZoneApi;
+import org.jclouds.ultradns.ws.features.ZoneAsyncApi;
+import org.jclouds.ultradns.ws.handlers.UltraDNSWSErrorHandler;
import com.google.common.collect.ImmutableMap;
@@ -34,11 +42,23 @@ import com.google.common.collect.ImmutableMap;
*/
@ConfiguresRestClient
public class UltraDNSWSRestClientModule extends RestClientModule {
-
- public static final Map, Class>> DELEGATE_MAP = ImmutableMap., Class>>builder()
- .build();
-
+
+ public static final Map, Class>> DELEGATE_MAP = ImmutableMap., Class>> builder()
+ .put(ZoneApi.class, ZoneAsyncApi.class).build();
+
public UltraDNSWSRestClientModule() {
super(DELEGATE_MAP);
}
+
+ @Override
+ protected void bindErrorHandlers() {
+ bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(UltraDNSWSErrorHandler.class);
+ bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(UltraDNSWSErrorHandler.class);
+ bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(UltraDNSWSErrorHandler.class);
+ }
+
+ @Override
+ protected void bindRetryHandlers() {
+ bind(HttpRetryHandler.class).annotatedWith(ServerError.class).toInstance(HttpRetryHandler.NEVER_RETRY);
+ }
}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java
index ebf3b20d41..fd9b41bc76 100644
--- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java
@@ -39,7 +39,7 @@ public final class Account {
}
/**
- * The id of the account. ex {@code 01233CB945FAC523}
+ * The id of the account. ex {@code AAAAAAAAAAAAAAAA}
*/
public String getId() {
return id;
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java
new file mode 100644
index 0000000000..372f5b803c
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java
@@ -0,0 +1,276 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+public final class Zone {
+
+ private final String id;
+ private final String name;
+ private final Type type;
+ private final int typeCode;
+ private final String accountId;
+ private final String ownerId;
+ private final DNSSECStatus dnssecStatus;
+ private final Optional primarySrc;
+
+ private Zone(String id, String name, Type type, int typeCode, String accountId, String ownerId,
+ DNSSECStatus dnssecStatus, Optional primarySrc) {
+ this.id = checkNotNull(id, "id");
+ this.name = checkNotNull(name, "name");
+ this.typeCode = typeCode;
+ this.type = checkNotNull(type, "type for %s", name);
+ this.accountId = checkNotNull(accountId, "accountId for %s", name);
+ this.ownerId = checkNotNull(ownerId, "ownerId for %s", name);
+ this.dnssecStatus = checkNotNull(dnssecStatus, "dnssecStatus for %s", name);
+ this.primarySrc = checkNotNull(primarySrc, "primarySrc for %s", primarySrc);
+ }
+
+ /**
+ * The ID of the zone.
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * The name of the domain. ex. {@code jclouds.org.} or {@code 0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.}
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * The type of the zone
+ */
+ public Type getType() {
+ return type;
+ }
+
+ /**
+ * The type of the zone
+ */
+ public int getTypeCode() {
+ return typeCode;
+ }
+
+ /**
+ * The account which this domain is a part of
+ */
+ public String getAccountId() {
+ return accountId;
+ }
+
+ /**
+ * The user that created this zone.
+ */
+ public String getOwnerId() {
+ return ownerId;
+ }
+
+ /**
+ * signed status of the zone
+ */
+ public DNSSECStatus getDNSSECStatus() {
+ return dnssecStatus;
+ }
+
+ /**
+ * present when {@link #getType} is {@link Type#SECONDARY}. ex. {@code 192.168.1.23}
+ */
+ public Optional getPrimarySrc() {
+ return primarySrc;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(id, name, accountId);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Zone that = Zone.class.cast(obj);
+ return Objects.equal(this.id, that.id) && Objects.equal(this.name, that.name)
+ && Objects.equal(this.accountId, that.accountId);
+ }
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this).omitNullValues().add("id", id).add("name", name).add("type", type)
+ .add("accountId", accountId).add("ownerId", ownerId).add("dnssecStatus", dnssecStatus)
+ .add("primarySrc", primarySrc.orNull()).toString();
+ }
+
+ public static enum Type {
+
+ PRIMARY(1), SECONDARY(2), ALIAS(3), UNRECOGNIZED(-1);
+
+ private final int code;
+
+ Type(int code) {
+ this.code = code;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ @Override
+ public String toString(){
+ return this.name().toLowerCase();
+ }
+
+ public static Type fromValue(String type) {
+ return fromValue(Integer.parseInt(checkNotNull(type, "type")));
+ }
+
+ public static Type fromValue(int code) {
+ switch (code) {
+ case 1:
+ return PRIMARY;
+ case 2:
+ return SECONDARY;
+ case 3:
+ return ALIAS;
+ default:
+ return UNRECOGNIZED;
+ }
+ }
+ }
+
+ public static enum DNSSECStatus {
+
+ SIGNED, UNSIGNED, UNRECOGNIZED;
+
+ public static DNSSECStatus fromValue(String status) {
+ try {
+ return valueOf(checkNotNull(status, "status"));
+ } catch (IllegalArgumentException e) {
+ return UNRECOGNIZED;
+ }
+ }
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public Builder toBuilder() {
+ return builder().from(this);
+ }
+
+ public final static class Builder {
+ private String id;
+ private String name;
+ private Type type;
+ private int typeCode = -1;
+ private String accountId;
+ private String ownerId;
+ private DNSSECStatus dnssecStatus;
+ private Optional primarySrc = Optional.absent();
+
+ /**
+ * @see Zone#getId()
+ */
+ public Builder id(String id) {
+ this.id = id;
+ return this;
+ }
+
+ /**
+ * @see Zone#getName()
+ */
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * @see Zone#getType()
+ */
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * @see Zone#getTypeCode()
+ */
+ public Builder typeCode(int typeCode) {
+ this.typeCode = typeCode;
+ this.type = Type.fromValue(typeCode);
+ return this;
+ }
+
+ /**
+ * @see Zone#getAccountId()
+ */
+ public Builder accountId(String accountId) {
+ this.accountId = accountId;
+ return this;
+ }
+
+ /**
+ * @see Zone#getOwnerId()
+ */
+ public Builder ownerId(String ownerId) {
+ this.ownerId = ownerId;
+ return this;
+ }
+
+ /**
+ * @see Zone#getDNSSECStatus()
+ */
+ public Builder dnssecStatus(DNSSECStatus dnssecStatus) {
+ this.dnssecStatus = dnssecStatus;
+ return this;
+ }
+
+ /**
+ * @see Zone#getPrimarySrc()
+ */
+ public Builder primarySrc(String primarySrc) {
+ this.primarySrc = Optional.fromNullable(primarySrc);
+ return this;
+ }
+
+ public Zone build() {
+ return new Zone(id, name, type, typeCode, accountId, ownerId, dnssecStatus, primarySrc);
+ }
+
+ public Builder from(Zone in) {
+ return this.id(in.id).name(in.name).typeCode(in.typeCode).type(in.type).accountId(in.accountId)
+ .ownerId(in.ownerId).dnssecStatus(in.dnssecStatus).primarySrc(in.primarySrc.orNull());
+ }
+ }
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java
new file mode 100644
index 0000000000..87a8485e3b
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java
@@ -0,0 +1,170 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.domain;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Date;
+
+import org.jclouds.ultradns.ws.domain.Zone.Type;
+
+import com.google.common.base.Objects;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+public final class ZoneProperties {
+
+ private final String name;
+ private final Type type;
+ private final int typeCode;
+ private final Date modified;
+ private final int resourceRecordCount;
+
+ private ZoneProperties(String name, Type type, int typeCode, Date modified, int resourceRecordCount) {
+ this.name = checkNotNull(name, "name");
+ this.typeCode = typeCode;
+ this.type = checkNotNull(type, "type for %s", name);
+ this.modified = checkNotNull(modified, "modified for %s", name);
+ this.resourceRecordCount = checkNotNull(resourceRecordCount, "resourceRecordCount for %s", name);
+ }
+
+ /**
+ * The name of the domain. ex. {@code jclouds.org.} or {@code 0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.}
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * The type of the zone
+ */
+ public Type getType() {
+ return type;
+ }
+
+ /**
+ * The type of the zone
+ */
+ public int getTypeCode() {
+ return typeCode;
+ }
+
+ /**
+ * Last time the zone was modified
+ */
+ public Date getModified() {
+ return modified;
+ }
+
+ /**
+ * The count of records in this zone.
+ */
+ public int getResourceRecordCount() {
+ return resourceRecordCount;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(name);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null || getClass() != obj.getClass())
+ return false;
+ ZoneProperties that = ZoneProperties.class.cast(obj);
+ return Objects.equal(this.name, that.name);
+ }
+
+ @Override
+ public String toString() {
+ return Objects.toStringHelper(this).add("name", name).add("type", type)
+ .add("modified", modified).add("resourceRecordCount", resourceRecordCount).toString();
+ }
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public Builder toBuilder() {
+ return builder().from(this);
+ }
+
+ public final static class Builder {
+ private String name;
+ private Type type;
+ private int typeCode = -1;
+ private Date modified;
+ private int resourceRecordCount;
+
+ /**
+ * @see ZoneProperties#getName()
+ */
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * @see ZoneProperties#getType()
+ */
+ public Builder type(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ /**
+ * @see ZoneProperties#getTypeCode()
+ */
+ public Builder typeCode(int typeCode) {
+ this.typeCode = typeCode;
+ this.type = Type.fromValue(typeCode);
+ return this;
+ }
+
+ /**
+ * @see ZoneProperties#getModified()
+ */
+ public Builder modified(Date modified) {
+ this.modified = modified;
+ return this;
+ }
+
+ /**
+ * @see ZoneProperties#getResourceRecordCount()
+ */
+ public Builder resourceRecordCount(int resourceRecordCount) {
+ this.resourceRecordCount = resourceRecordCount;
+ return this;
+ }
+
+ public ZoneProperties build() {
+ return new ZoneProperties(name, type, typeCode, modified, resourceRecordCount);
+ }
+
+ public Builder from(ZoneProperties in) {
+ return this.name(in.name).typeCode(in.typeCode).type(in.type).modified(in.modified)
+ .resourceRecordCount(in.resourceRecordCount);
+ }
+ }
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneApi.java
new file mode 100644
index 0000000000..efb4b15d54
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneApi.java
@@ -0,0 +1,60 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.features;
+
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.jclouds.ultradns.ws.domain.Zone.Type;
+import org.jclouds.ultradns.ws.domain.ZoneProperties;
+
+import com.google.common.collect.FluentIterable;
+
+/**
+ * @see ZoneAsyncApi
+ * @author Adrian Cole
+ */
+public interface ZoneApi {
+
+ /**
+ * Retrieves information about the specified zone
+ *
+ * @param name
+ * Name of the zone to get information about.
+ * @return null if not found
+ */
+ @Nullable
+ ZoneProperties get(String name);
+
+ /**
+ * Lists all zones in the specified account.
+ *
+ * @throws ResourceNotFoundException
+ * if the account doesn't exist
+ */
+ FluentIterable listByAccount(String accountId) throws ResourceNotFoundException;
+
+ /**
+ * Lists all zones in the specified account of type
+ *
+ * @throws ResourceNotFoundException
+ * if the account doesn't exist
+ */
+ FluentIterable listByAccountAndType(String accountId, Type type) throws ResourceNotFoundException;
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneAsyncApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneAsyncApi.java
new file mode 100644
index 0000000000..a831f1363a
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneAsyncApi.java
@@ -0,0 +1,81 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.features;
+
+import javax.inject.Named;
+import javax.ws.rs.POST;
+
+import org.jclouds.Fallbacks.NullOnNotFoundOr404;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.rest.annotations.Fallback;
+import org.jclouds.rest.annotations.Payload;
+import org.jclouds.rest.annotations.PayloadParam;
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.VirtualHost;
+import org.jclouds.rest.annotations.XMLResponseParser;
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.jclouds.ultradns.ws.domain.Zone.Type;
+import org.jclouds.ultradns.ws.domain.ZoneProperties;
+import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth;
+import org.jclouds.ultradns.ws.xml.ZoneListHandler;
+import org.jclouds.ultradns.ws.xml.ZonePropertiesHandler;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.util.concurrent.ListenableFuture;
+
+/**
+ * @see ZoneApi
+ * @see
+ * @see
+ * @author Adrian Cole
+ */
+@RequestFilters(SOAPWrapWithPasswordAuth.class)
+@VirtualHost
+public interface ZoneAsyncApi {
+
+ /**
+ * @see ZoneApi#get(String)
+ */
+ @Named("getGeneralPropertiesForZone")
+ @POST
+ @XMLResponseParser(ZonePropertiesHandler.class)
+ @Payload("{zoneName}")
+ @Fallback(NullOnNotFoundOr404.class)
+ ListenableFuture get(@PayloadParam("zoneName") String name);
+
+ /**
+ * @see ZoneApi#listByAccount(String)
+ */
+ @Named("getZonesOfAccount")
+ @POST
+ @XMLResponseParser(ZoneListHandler.class)
+ @Payload("{accountId}all")
+ ListenableFuture> listByAccount(@PayloadParam("accountId") String accountId)
+ throws ResourceNotFoundException;
+
+ /**
+ * @see ZoneApi#listByAccountAndType(String, Type)
+ */
+ @Named("getZonesOfAccount")
+ @POST
+ @XMLResponseParser(ZoneListHandler.class)
+ @Payload("{accountId}{zoneType}")
+ ListenableFuture> listByAccountAndType(@PayloadParam("accountId") String accountId,
+ @PayloadParam("zoneType") Type type) throws ResourceNotFoundException;
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java
index 93411f2579..de551644d2 100644
--- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java
@@ -39,7 +39,7 @@ public class SOAPWrapWithPasswordAuth implements HttpRequestFilter {
static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
static final String SOAP_PREFIX = new StringBuilder()
.append("")
+ .append("xmlns:v01=\"http://webservice.api.ultra.neustar.com/v01/\">")
.append("")
.append("%s%s")
.append("").toString();
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java
new file mode 100644
index 0000000000..eb2695c9ab
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java
@@ -0,0 +1,85 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.handlers;
+
+import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
+import static org.jclouds.http.HttpUtils.releasePayload;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpCommand;
+import org.jclouds.http.HttpErrorHandler;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.http.HttpResponseException;
+import org.jclouds.http.functions.ParseSax.Factory;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.ultradns.ws.UltraDNSWSError;
+import org.jclouds.ultradns.ws.UltraDNSWSResponseException;
+import org.jclouds.ultradns.ws.xml.UltraWSExceptionHandler;
+
+/**
+ * @author Adrian Cole
+ */
+@Singleton
+public class UltraDNSWSErrorHandler implements HttpErrorHandler {
+
+ private final Factory factory;
+ private final Provider handlers;
+
+ @Inject
+ UltraDNSWSErrorHandler(Factory factory, Provider handlers) {
+ this.factory = factory;
+ this.handlers = handlers;
+ }
+
+ public void handleError(HttpCommand command, HttpResponse response) {
+ Exception exception = new HttpResponseException(command, response);
+ try {
+ byte[] data = closeClientButKeepContentStream(response);
+ String message = data != null ? new String(data) : null;
+ if (message != null) {
+ exception = new HttpResponseException(command, response, message);
+ String contentType = response.getPayload().getContentMetadata().getContentType();
+ if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) {
+ UltraDNSWSError error = factory.create(handlers.get()).parse(message);
+ if (error != null) {
+ exception = refineException(new UltraDNSWSResponseException(command, response, error));
+ }
+ }
+ } else {
+ exception = new HttpResponseException(command, response);
+ }
+ } finally {
+ releasePayload(response);
+ command.setException(exception);
+ }
+ }
+
+ private Exception refineException(UltraDNSWSResponseException exception) {
+ switch (exception.getError().getCode()) {
+ case 1801:
+ case 2401:
+ return new ResourceNotFoundException(exception.getError().getDescription(), exception);
+ }
+ return exception;
+ }
+
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/predicates/ZonePredicates.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/predicates/ZonePredicates.java
new file mode 100644
index 0000000000..72e6b84b31
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/predicates/ZonePredicates.java
@@ -0,0 +1,53 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.predicates;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.jclouds.ultradns.ws.domain.Zone.Type;
+
+import com.google.common.base.Predicate;
+
+/**
+ * Predicates handy when working with Zone Types
+ *
+ * @author Adrian Cole
+ */
+public class ZonePredicates {
+
+ /**
+ * matches zones of the given type
+ */
+ public static Predicate typeEquals(final Type type) {
+ checkNotNull(type, "type must be defined");
+
+ return new Predicate() {
+ @Override
+ public boolean apply(Zone zone) {
+ return type.equals(zone.getType());
+ }
+
+ @Override
+ public String toString() {
+ return "typeEquals(" + type + ")";
+ }
+ };
+ }
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/UltraWSExceptionHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/UltraWSExceptionHandler.java
new file mode 100644
index 0000000000..fdf2e9897d
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/UltraWSExceptionHandler.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.xml;
+
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.ultradns.ws.UltraDNSWSError;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+public class UltraWSExceptionHandler extends ParseSax.HandlerForGeneratedRequestWithResult {
+
+ private StringBuilder currentText = new StringBuilder();
+ private int code = -1;
+ private String description;
+
+ @Override
+ public UltraDNSWSError getResult() {
+ try {
+ return code > 0 ? UltraDNSWSError.fromCodeAndDescription(code, description) : null;
+ } finally {
+ code = -1;
+ description = null;
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String name, String qName) {
+ if (qName.equals("errorCode")) {
+ code = Integer.parseInt(currentOrNull(currentText));
+ } else if (qName.equals("errorDescription")) {
+ description = currentOrNull(currentText);
+ }
+ currentText = new StringBuilder();
+ }
+
+ @Override
+ public void characters(char ch[], int start, int length) {
+ currentText.append(ch, start, length);
+ }
+
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.java
new file mode 100644
index 0000000000..3cac2f282f
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.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.ultradns.ws.xml;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.util.SaxUtils.cleanseAttributes;
+import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+
+import java.util.Map;
+
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.jclouds.ultradns.ws.domain.Zone.DNSSECStatus;
+import org.xml.sax.Attributes;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+public class ZoneHandler extends ParseSax.HandlerForGeneratedRequestWithResult {
+
+ private Zone zone;
+
+ @Override
+ public Zone getResult() {
+ try {
+ return zone;
+ } finally {
+ zone = null;
+ }
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attrs) {
+ Map attributes = cleanseAttributes(attrs);
+ if (equalsOrSuffix(qName, "UltraZone")) {
+ zone = Zone.builder()
+ .id(attributes.get("zoneId"))
+ .name(attributes.get("zoneName"))
+ .typeCode(Integer.parseInt(checkNotNull(attributes.get("zoneType"), "zoneType")))
+ .accountId(attributes.get("accountId"))
+ .ownerId(attributes.get("owner"))
+ .dnssecStatus(DNSSECStatus.fromValue(attributes.get("dnssecStatus")))
+ .primarySrc(attributes.get("primarySrc")).build();
+ }
+ }
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneListHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneListHandler.java
new file mode 100644
index 0000000000..f4d91229da
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneListHandler.java
@@ -0,0 +1,65 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.xml;
+
+import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.xml.sax.Attributes;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import com.google.inject.Inject;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+public class ZoneListHandler extends ParseSax.HandlerForGeneratedRequestWithResult> {
+
+ private final ZoneHandler zoneHandler;
+
+ private Builder zones = ImmutableSet. builder();
+
+ @Inject
+ public ZoneListHandler(ZoneHandler zoneHandler) {
+ this.zoneHandler = zoneHandler;
+ }
+
+ @Override
+ public FluentIterable getResult() {
+ return FluentIterable.from(zones.build());
+ }
+
+ @Override
+ public void startElement(String url, String name, String qName, Attributes attributes) {
+ if (equalsOrSuffix(qName, "UltraZone")) {
+ zoneHandler.startElement(url, name, qName, attributes);
+ }
+ }
+
+ @Override
+ public void endElement(String uri, String name, String qName) {
+ if (equalsOrSuffix(qName, "UltraZone")) {
+ zones.add(zoneHandler.getResult());
+ }
+ }
+}
diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZonePropertiesHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZonePropertiesHandler.java
new file mode 100644
index 0000000000..92f9d17404
--- /dev/null
+++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZonePropertiesHandler.java
@@ -0,0 +1,72 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.xml;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.util.SaxUtils.cleanseAttributes;
+import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.jclouds.date.DateService;
+import org.jclouds.http.functions.ParseSax;
+import org.jclouds.ultradns.ws.domain.Zone.Type;
+import org.jclouds.ultradns.ws.domain.ZoneProperties;
+import org.xml.sax.Attributes;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+public class ZonePropertiesHandler extends ParseSax.HandlerForGeneratedRequestWithResult {
+
+ private final DateService dateService;
+
+ @Inject
+ ZonePropertiesHandler(DateService dateService) {
+ this.dateService = dateService;
+ }
+
+ private ZoneProperties zone;
+
+ @Override
+ public ZoneProperties getResult() {
+ try {
+ return zone;
+ } finally {
+ zone = null;
+ }
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attrs) {
+ Map attributes = cleanseAttributes(attrs);
+ if (equalsOrSuffix(qName, "GeneralZoneProperties")) {
+ Type type = Type.valueOf(checkNotNull(attributes.get("zoneType"), "zoneType").toUpperCase());
+ int count = Integer.parseInt(checkNotNull(attributes.get("resourceRecordCount"), "resourceRecordCount"));
+ zone = ZoneProperties.builder()
+ .name(attributes.get("name"))
+ .typeCode(type.getCode())
+ .resourceRecordCount(count)
+ .modified(dateService.iso8601DateParse(attributes.get("modified"))).build();
+ }
+ }
+}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java
index a75d569a8d..946ca8d0b8 100644
--- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java
@@ -33,8 +33,8 @@ import org.testng.annotations.Test;
public class UltraDNSWSApiExpectTest extends BaseUltraDNSWSApiExpectTest {
HttpRequest getCurrentAccount = HttpRequest.builder().method("POST")
- .endpoint("http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01/")
- .addHeader("Host", "ultra-api.ultradns.com:8008")
+ .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
+ .addHeader("Host", "ultra-api.ultradns.com:8443")
.payload(payloadFromResourceWithContentType("/get_current_account.xml", "application/xml")).build();
HttpResponse getCurrentAccountResponse = HttpResponse.builder().statusCode(200)
@@ -42,10 +42,10 @@ public class UltraDNSWSApiExpectTest extends BaseUltraDNSWSApiExpectTest {
public void testGetCurrentAccountWhenResponseIs2xx() {
- UltraDNSWSApi apiWhenWithOptionsExist = requestSendsResponse(getCurrentAccount, getCurrentAccountResponse);
+ UltraDNSWSApi success = requestSendsResponse(getCurrentAccount, getCurrentAccountResponse);
assertEquals(
- apiWhenWithOptionsExist.getCurrentAccount().toString(),
+ success.getCurrentAccount().toString(),
new GetAccountsListOfUserResponseTest().expected().toString());
}
}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiExpectTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiExpectTest.java
new file mode 100644
index 0000000000..5955c800d0
--- /dev/null
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiExpectTest.java
@@ -0,0 +1,106 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.ultradns.ws.UltraDNSWSApi;
+import org.jclouds.ultradns.ws.domain.Zone.Type;
+import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest;
+import org.jclouds.ultradns.ws.parse.GetGeneralPropertiesForZoneResponseTest;
+import org.jclouds.ultradns.ws.parse.GetZonesOfAccountResponseTest;
+import org.testng.annotations.Test;
+
+/**
+ * @author Adrian Cole
+ */
+@Test(groups = "unit", testName = "ZoneApiExpectTest")
+public class ZoneApiExpectTest extends BaseUltraDNSWSApiExpectTest {
+ HttpRequest get = HttpRequest.builder().method("POST")
+ .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
+ .addHeader("Host", "ultra-api.ultradns.com:8443")
+ .payload(payloadFromResourceWithContentType("/get_zone.xml", "application/xml")).build();
+
+ HttpResponse getResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResourceWithContentType("/zoneproperties.xml", "application/xml")).build();
+
+ public void testGetWhenResponseIs2xx() {
+ UltraDNSWSApi success = requestSendsResponse(get, getResponse);
+
+ assertEquals(
+ success.getZoneApi().get("jclouds.org.").toString(),
+ new GetGeneralPropertiesForZoneResponseTest().expected().toString());
+ }
+
+ HttpResponse zoneDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
+ .payload(payloadFromResource("/zone_doesnt_exist.xml")).build();
+
+ public void testGetWhenResponseError2401() {
+ UltraDNSWSApi notFound = requestSendsResponse(get, zoneDoesntExist);
+ assertNull(notFound.getZoneApi().get("jclouds.org."));
+ }
+
+ HttpRequest listByAccount = HttpRequest.builder().method("POST")
+ .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
+ .addHeader("Host", "ultra-api.ultradns.com:8443")
+ .payload(payloadFromResourceWithContentType("/list_zones_by_account.xml", "application/xml")).build();
+
+ HttpResponse listByAccountResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResourceWithContentType("/zones.xml", "application/xml")).build();
+
+ public void testListByAccountWhenResponseIs2xx() {
+ UltraDNSWSApi success = requestSendsResponse(listByAccount, listByAccountResponse);
+
+ assertEquals(
+ success.getZoneApi().listByAccount("AAAAAAAAAAAAAAAA").toString(),
+ new GetZonesOfAccountResponseTest().expected().toString());
+ }
+
+ HttpResponse accountDoesntExist = HttpResponse.builder().message("Server Error").statusCode(500)
+ .payload(payloadFromResource("/account_doesnt_exist.xml")).build();
+
+ @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Account not found in the system. ID: AAAAAAAAAAAAAAAA")
+ public void testListByAccountWhenResponseError2401() {
+ UltraDNSWSApi notFound = requestSendsResponse(listByAccount, accountDoesntExist);
+ notFound.getZoneApi().listByAccount("AAAAAAAAAAAAAAAA");
+ }
+
+ HttpRequest listByAccountAndType = HttpRequest.builder().method("POST")
+ .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
+ .addHeader("Host", "ultra-api.ultradns.com:8443")
+ .payload(payloadFromResourceWithContentType("/list_zones_by_account_and_type.xml", "application/xml")).build();
+
+ public void testListByAccountAndTypeWhenResponseIs2xx() {
+ UltraDNSWSApi success = requestSendsResponse(listByAccountAndType, listByAccountResponse);
+
+ assertEquals(
+ success.getZoneApi().listByAccountAndType("AAAAAAAAAAAAAAAA", Type.PRIMARY).toString(),
+ new GetZonesOfAccountResponseTest().expected().toString());
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Account not found in the system. ID: AAAAAAAAAAAAAAAA")
+ public void testListByAccountAndTypeWhenResponseError2401() {
+ UltraDNSWSApi notFound = requestSendsResponse(listByAccountAndType, accountDoesntExist);
+ notFound.getZoneApi().listByAccountAndType("AAAAAAAAAAAAAAAA", Type.PRIMARY);
+ }
+}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java
new file mode 100644
index 0000000000..9481bf6531
--- /dev/null
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java
@@ -0,0 +1,105 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.features;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.ultradns.ws.domain.Zone.Type.PRIMARY;
+import static org.jclouds.ultradns.ws.predicates.ZonePredicates.typeEquals;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.*;
+
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.ultradns.ws.domain.Account;
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.jclouds.ultradns.ws.domain.ZoneProperties;
+import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.FluentIterable;
+
+/**
+ * @author Adrian Cole
+ */
+@Test(groups = "live", testName = "ZoneApiLiveTest")
+public class ZoneApiLiveTest extends BaseUltraDNSWSApiLiveTest {
+
+ private Account account;
+
+ @Override
+ @BeforeClass(groups = { "integration", "live" })
+ public void setupContext() {
+ super.setupContext();
+ account = context.getApi().getCurrentAccount();
+ }
+
+ private void checkZone(Zone zone) {
+ checkNotNull(zone.getId(), "Id cannot be null for a Zone %s", zone);
+ checkNotNull(zone.getName(), "Name cannot be null for a Zone %s", zone);
+ checkNotNull(zone.getType(), "Type cannot be null for a Zone %s", zone);
+ assertTrue(zone.getTypeCode() > 0, "TypeCode must be positive for a Zone " + zone);
+ assertEquals(zone.getTypeCode(), zone.getType().getCode());
+ checkNotNull(zone.getAccountId(), "AccountId cannot be null for a Zone %s", zone);
+ assertEquals(zone.getAccountId(), account.getId());
+ checkNotNull(zone.getOwnerId(), "OwnerId cannot be null for a Zone %s", zone);
+ checkNotNull(zone.getDNSSECStatus(), "DNSSECStatus cannot be null for a Zone %s", zone);
+ checkNotNull(zone.getPrimarySrc(), "While PrimarySrc can be null for a Zone, its Optional wrapper cannot %s",
+ zone);
+ }
+
+ @Test
+ public void testListZonesByAccount() {
+ FluentIterable response = api().listByAccount(account.getId());
+
+ for (Zone zone : response) {
+ checkZone(zone);
+ }
+
+ if (response.anyMatch(typeEquals(PRIMARY))) {
+ assertEquals(api().listByAccountAndType(account.getId(), PRIMARY).toSet(), response
+ .filter(typeEquals(PRIMARY)).toSet());
+ }
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class, expectedExceptionsMessageRegExp = "Account not found in the system. ID: AAAAAAAAAAAAAAAA")
+ public void testListZonesByAccountWhenAccountIdNotFound() {
+ api().listByAccount("AAAAAAAAAAAAAAAA");
+ }
+
+ @Test
+ public void testGetZone() {
+ for (Zone zone : api().listByAccount(account.getId())) {
+ ZoneProperties zoneProperties = api().get(zone.getName());
+ assertEquals(zoneProperties.getName(), zone.getName());
+ assertEquals(zoneProperties.getType(), zone.getType());
+ assertEquals(zoneProperties.getTypeCode(), zone.getTypeCode());
+ checkNotNull(zoneProperties.getModified(), "Modified cannot be null for a Zone %s", zone);
+ assertTrue(zoneProperties.getResourceRecordCount() >= 0, "ResourceRecordCount must be positive or zero for a Zone " + zone);
+ }
+ }
+
+ @Test
+ public void testGetZoneWhenNotFound() {
+ assertNull(api().get("AAAAAAAAAAAAAAAA"));
+ }
+
+ protected ZoneApi api() {
+ return context.getApi().getZoneApi();
+ }
+}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java
new file mode 100644
index 0000000000..bd31c9b92b
--- /dev/null
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.handlers;
+
+import static com.google.common.base.Throwables.propagate;
+import static org.jclouds.rest.internal.BaseRestApiExpectTest.payloadFromStringWithContentType;
+import static org.jclouds.util.Strings2.toStringAndClose;
+import static org.testng.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.jclouds.http.HttpCommand;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.http.functions.config.SaxParserModule;
+import org.jclouds.io.Payload;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.jclouds.ultradns.ws.UltraDNSWSResponseException;
+import org.testng.annotations.Test;
+
+import com.google.inject.Guice;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "unit" )
+public class UltraDNSWSErrorHandlerTest {
+ UltraDNSWSErrorHandler function = Guice.createInjector(new SaxParserModule()).getInstance(
+ UltraDNSWSErrorHandler.class);
+
+ @Test
+ public void testCode2401SetsResourceNotFoundException() throws IOException {
+ HttpRequest request = HttpRequest.builder().method("POST")
+ .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
+ .addHeader("Host", "ultra-api.ultradns.com:8443")
+ .payload(payloadFromResource("/list_zones_by_account.xml")).build();
+ HttpCommand command = new HttpCommand(request);
+ HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
+ .payload(payloadFromResource("/account_doesnt_exist.xml")).build();
+
+ function.handleError(command, response);
+
+ assertEquals(command.getException().getClass(), ResourceNotFoundException.class);
+ assertEquals(command.getException().getMessage(), "Account not found in the system. ID: AAAAAAAAAAAAAAAA");
+
+ UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause());
+
+ assertEquals(exception.getMessage(), "Error 2401: Account not found in the system. ID: AAAAAAAAAAAAAAAA");
+ assertEquals(exception.getError().getDescription(), "Account not found in the system. ID: AAAAAAAAAAAAAAAA");
+ assertEquals(exception.getError().getCode(), 2401);
+ }
+
+ @Test
+ public void testCode1801SetsResourceNotFoundException() throws IOException {
+ HttpRequest request = HttpRequest.builder().method("POST")
+ .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01")
+ .addHeader("Host", "ultra-api.ultradns.com:8443")
+ .payload(payloadFromResource("/get_zone.xml")).build();
+ HttpCommand command = new HttpCommand(request);
+ HttpResponse response = HttpResponse.builder().message("Server Error").statusCode(500)
+ .payload(payloadFromResource("/zone_doesnt_exist.xml")).build();
+
+ function.handleError(command, response);
+
+ assertEquals(command.getException().getClass(), ResourceNotFoundException.class);
+ assertEquals(command.getException().getMessage(), "Zone does not exist in the system.");
+
+ UltraDNSWSResponseException exception = UltraDNSWSResponseException.class.cast(command.getException().getCause());
+
+ assertEquals(exception.getMessage(), "Error 1801: Zone does not exist in the system.");
+ assertEquals(exception.getError().getDescription(), "Zone does not exist in the system.");
+ assertEquals(exception.getError().getCode(), 1801);
+ }
+
+ private Payload payloadFromResource(String resource) {
+ try {
+ return payloadFromStringWithContentType(toStringAndClose(getClass().getResourceAsStream(resource)),
+ "application/xml");
+ } catch (IOException e) {
+ throw propagate(e);
+ }
+ }
+}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java
index a3038a64fa..5957eb2965 100644
--- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java
@@ -30,7 +30,7 @@ import org.testng.annotations.Test;
/**
* @author Adrian Cole
*/
-@Test
+@Test(testName = "GetAccountsListOfUserResponseTest")
public class GetAccountsListOfUserResponseTest extends BaseHandlerTest {
public void test() {
@@ -45,7 +45,7 @@ public class GetAccountsListOfUserResponseTest extends BaseHandlerTest {
}
public Account expected() {
- return Account.fromIdAndName("01233CB945FAC523", "jclouds");
+ return Account.fromIdAndName("AAAAAAAAAAAAAAAA", "jclouds");
}
}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetGeneralPropertiesForZoneResponseTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetGeneralPropertiesForZoneResponseTest.java
new file mode 100644
index 0000000000..409bd3f510
--- /dev/null
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetGeneralPropertiesForZoneResponseTest.java
@@ -0,0 +1,56 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.parse;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.jclouds.ultradns.ws.domain.ZoneProperties;
+import org.jclouds.ultradns.ws.xml.ZonePropertiesHandler;
+import org.testng.annotations.Test;
+
+/**
+ * @author Adrian Cole
+ */
+@Test(testName = "GetGeneralPropertiesForZoneResponseTest")
+public class GetGeneralPropertiesForZoneResponseTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/zoneproperties.xml");
+
+ ZoneProperties expected = expected();
+
+ ZonePropertiesHandler handler = injector.getInstance(ZonePropertiesHandler.class);
+ ZoneProperties result = factory.create(handler).parse(is);
+
+ assertEquals(result.toString(), expected.toString());
+ }
+
+ public ZoneProperties expected() {
+ return ZoneProperties.builder()
+ .name("jclouds.org.")
+ .typeCode(1)
+ .resourceRecordCount(17)
+ .modified(new SimpleDateFormatDateService().iso8601DateParse("2010-09-05 04:04:17.0"))
+ .build();
+ }
+}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetZonesOfAccountResponseTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetZonesOfAccountResponseTest.java
new file mode 100644
index 0000000000..adae5692f3
--- /dev/null
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetZonesOfAccountResponseTest.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, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.parse;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.jclouds.ultradns.ws.domain.Zone.DNSSECStatus;
+import org.jclouds.ultradns.ws.xml.ZoneListHandler;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Adrian Cole
+ */
+@Test(testName = "GetZonesOfAccountResponseTest")
+public class GetZonesOfAccountResponseTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/zones.xml");
+
+ FluentIterable expected = expected();
+
+ ZoneListHandler handler = injector.getInstance(ZoneListHandler.class);
+ FluentIterable result = factory.create(handler).parse(is);
+
+ assertEquals(result.toSet().toString(), expected.toSet().toString());
+ }
+
+ public FluentIterable expected() {
+ return FluentIterable.from(ImmutableSet. builder()
+ .add(Zone.builder()
+ .name("jclouds.org.")
+ .typeCode(1)
+ .accountId("AAAAAAAAAAAAAAAA")
+ .ownerId("EEEEEEEEEEEEEEEE")
+ .id("0000000000000001")
+ .dnssecStatus(DNSSECStatus.UNSIGNED).build())
+ .add(Zone.builder()
+ .name("0.1.2.3.4.5.6.7.ip6.arpa.")
+ .typeCode(1)
+ .accountId("AAAAAAAAAAAAAAAA")
+ .ownerId("EEEEEEEEEEEEEEEE")
+ .id("0000000000000002")
+ .dnssecStatus(DNSSECStatus.UNSIGNED).build())
+ .build());
+ }
+
+}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/UltraWSExceptionTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/UltraWSExceptionTest.java
new file mode 100644
index 0000000000..3cb99f311e
--- /dev/null
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/UltraWSExceptionTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.parse;
+
+import static org.testng.Assert.assertEquals;
+
+import java.io.InputStream;
+
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.jclouds.ultradns.ws.UltraDNSWSError;
+import org.jclouds.ultradns.ws.xml.UltraWSExceptionHandler;
+import org.testng.annotations.Test;
+
+/**
+ * @author Adrian Cole
+ */
+@Test(testName = "UltraWSExceptionTest")
+public class UltraWSExceptionTest extends BaseHandlerTest {
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/zone_doesnt_exist.xml");
+
+ UltraDNSWSError expected = expected();
+
+ UltraWSExceptionHandler handler = injector.getInstance(UltraWSExceptionHandler.class);
+ UltraDNSWSError result = factory.create(handler).parse(is);
+
+ assertEquals(result, expected);
+ }
+
+ public UltraDNSWSError expected() {
+ return UltraDNSWSError.fromCodeAndDescription(1801, "Zone does not exist in the system.");
+ }
+
+}
diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/predicates/ZonePredicatesTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/predicates/ZonePredicatesTest.java
new file mode 100644
index 0000000000..88d3883cba
--- /dev/null
+++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/predicates/ZonePredicatesTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.ultradns.ws.predicates;
+
+import static org.jclouds.ultradns.ws.predicates.ZonePredicates.typeEquals;
+
+import org.jclouds.ultradns.ws.domain.Zone;
+import org.jclouds.ultradns.ws.domain.Zone.DNSSECStatus;
+import org.jclouds.ultradns.ws.domain.Zone.Type;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "unit", testName = "ZonePredicatesTest")
+public class ZonePredicatesTest {
+ Zone zone = Zone.builder()
+ .name("jclouds.org.")
+ .typeCode(1)
+ .accountId("AAAAAAAAAAAAAAAA")
+ .ownerId("EEEEEEEEEEEEEEEE")
+ .id("0000000000000001")
+ .dnssecStatus(DNSSECStatus.UNSIGNED).build();
+
+ @Test
+ public void testTypeEqualsWhenEqual() {
+ assert typeEquals(Type.PRIMARY).apply(zone);
+ }
+
+ @Test
+ public void testTypeEqualsWhenNotEqual() {
+ assert !typeEquals(Type.SECONDARY).apply(zone);
+ }
+}
diff --git a/labs/ultradns-ws/src/test/resources/account.xml b/labs/ultradns-ws/src/test/resources/account.xml
index f82e7994b5..735c069aee 100644
--- a/labs/ultradns-ws/src/test/resources/account.xml
+++ b/labs/ultradns-ws/src/test/resources/account.xml
@@ -3,7 +3,7 @@
-
diff --git a/labs/ultradns-ws/src/test/resources/account_doesnt_exist.xml b/labs/ultradns-ws/src/test/resources/account_doesnt_exist.xml
new file mode 100644
index 0000000000..7deae99fb0
--- /dev/null
+++ b/labs/ultradns-ws/src/test/resources/account_doesnt_exist.xml
@@ -0,0 +1,14 @@
+
+
+
+ soap:Server
+ Fault occurred while processing.
+
+
+ 2401
+ Account not found in the system. ID: AAAAAAAAAAAAAAAA
+
+
+
+
+
\ No newline at end of file
diff --git a/labs/ultradns-ws/src/test/resources/get_current_account.xml b/labs/ultradns-ws/src/test/resources/get_current_account.xml
index 17ab2413f6..d8192021a2 100644
--- a/labs/ultradns-ws/src/test/resources/get_current_account.xml
+++ b/labs/ultradns-ws/src/test/resources/get_current_account.xml
@@ -1 +1 @@
-identitycredential
\ No newline at end of file
+identitycredential
\ No newline at end of file
diff --git a/labs/ultradns-ws/src/test/resources/get_zone.xml b/labs/ultradns-ws/src/test/resources/get_zone.xml
new file mode 100644
index 0000000000..f36abe0909
--- /dev/null
+++ b/labs/ultradns-ws/src/test/resources/get_zone.xml
@@ -0,0 +1 @@
+identitycredentialjclouds.org.
\ No newline at end of file
diff --git a/labs/ultradns-ws/src/test/resources/list_zones_by_account.xml b/labs/ultradns-ws/src/test/resources/list_zones_by_account.xml
new file mode 100644
index 0000000000..8e633c0a78
--- /dev/null
+++ b/labs/ultradns-ws/src/test/resources/list_zones_by_account.xml
@@ -0,0 +1 @@
+identitycredentialAAAAAAAAAAAAAAAAall
\ No newline at end of file
diff --git a/labs/ultradns-ws/src/test/resources/list_zones_by_account_and_type.xml b/labs/ultradns-ws/src/test/resources/list_zones_by_account_and_type.xml
new file mode 100644
index 0000000000..859d651c47
--- /dev/null
+++ b/labs/ultradns-ws/src/test/resources/list_zones_by_account_and_type.xml
@@ -0,0 +1 @@
+identitycredentialAAAAAAAAAAAAAAAAprimary
\ No newline at end of file
diff --git a/labs/ultradns-ws/src/test/resources/zone_doesnt_exist.xml b/labs/ultradns-ws/src/test/resources/zone_doesnt_exist.xml
new file mode 100644
index 0000000000..6abc45ec12
--- /dev/null
+++ b/labs/ultradns-ws/src/test/resources/zone_doesnt_exist.xml
@@ -0,0 +1,14 @@
+
+
+
+ soap:Server
+ Fault occurred while processing.
+
+
+ 1801
+ Zone does not exist in the system.
+
+
+
+
+
\ No newline at end of file
diff --git a/labs/ultradns-ws/src/test/resources/zoneproperties.xml b/labs/ultradns-ws/src/test/resources/zoneproperties.xml
new file mode 100644
index 0000000000..6acb90dc02
--- /dev/null
+++ b/labs/ultradns-ws/src/test/resources/zoneproperties.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/labs/ultradns-ws/src/test/resources/zones.xml b/labs/ultradns-ws/src/test/resources/zones.xml
new file mode 100644
index 0000000000..1e574d8bd8
--- /dev/null
+++ b/labs/ultradns-ws/src/test/resources/zones.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file