From bec4734461f80dafa9a73c6f5a7f0543cf5a45a9 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 27 Jan 2013 12:11:20 -0800 Subject: [PATCH] added zone list and get commands to ultradns --- .../jclouds/ultradns/ws/UltraDNSWSApi.java | 8 + .../ultradns/ws/UltraDNSWSAsyncApi.java | 8 + .../ws/config/UltraDNSWSRestClientModule.java | 4 +- .../org/jclouds/ultradns/ws/domain/Zone.java | 276 ++++++++++++++++++ .../ultradns/ws/domain/ZoneProperties.java | 170 +++++++++++ .../jclouds/ultradns/ws/features/ZoneApi.java | 60 ++++ .../ultradns/ws/features/ZoneAsyncApi.java | 81 +++++ .../ws/handlers/UltraDNSWSErrorHandler.java | 1 + .../ws/predicates/ZonePredicates.java | 53 ++++ .../jclouds/ultradns/ws/xml/ZoneHandler.java | 63 ++++ .../ultradns/ws/xml/ZoneListHandler.java | 65 +++++ .../ws/xml/ZonePropertiesHandler.java | 72 +++++ .../ws/features/ZoneApiExpectTest.java | 106 +++++++ .../ultradns/ws/features/ZoneApiLiveTest.java | 105 +++++++ .../handlers/UltraDNSWSErrorHandlerTest.java | 21 ++ ...tGeneralPropertiesForZoneResponseTest.java | 56 ++++ .../parse/GetZonesOfAccountResponseTest.java | 70 +++++ .../ws/predicates/ZonePredicatesTest.java | 51 ++++ .../src/test/resources/get_zone.xml | 1 + .../list_zones_by_account_and_type.xml | 1 + .../src/test/resources/zoneproperties.xml | 7 + labs/ultradns-ws/src/test/resources/zones.xml | 10 + 22 files changed, 1288 insertions(+), 1 deletion(-) create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Zone.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/ZoneProperties.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneApi.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/features/ZoneAsyncApi.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/predicates/ZonePredicates.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneHandler.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZoneListHandler.java create mode 100644 labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/ZonePropertiesHandler.java create mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiExpectTest.java create mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/features/ZoneApiLiveTest.java create mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetGeneralPropertiesForZoneResponseTest.java create mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetZonesOfAccountResponseTest.java create mode 100644 labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/predicates/ZonePredicatesTest.java create mode 100644 labs/ultradns-ws/src/test/resources/get_zone.xml create mode 100644 labs/ultradns-ws/src/test/resources/list_zones_by_account_and_type.xml create mode 100644 labs/ultradns-ws/src/test/resources/zoneproperties.xml create mode 100644 labs/ultradns-ws/src/test/resources/zones.xml 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 63e0a1c255..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 @@ -33,4 +35,10 @@ public interface UltraDNSWSApi { * Returns the account of the current user. */ Account getCurrentAccount(); + + /** + * Provides synchronous access to Zone features. + */ + @Delegate + ZoneApi getZoneApi(); } 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 adaaefe7c9..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 @@ -21,11 +21,13 @@ package org.jclouds.ultradns.ws; import javax.inject.Named; import javax.ws.rs.POST; +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; @@ -51,4 +53,10 @@ public interface UltraDNSWSAsyncApi { @XMLResponseParser(AccountHandler.class) @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/config/UltraDNSWSRestClientModule.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java index cda0c00f96..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 @@ -29,6 +29,8 @@ 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; @@ -42,7 +44,7 @@ import com.google.common.collect.ImmutableMap; public class UltraDNSWSRestClientModule extends RestClientModule { public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() - .build(); + .put(ZoneApi.class, ZoneAsyncApi.class).build(); public UltraDNSWSRestClientModule() { super(DELEGATE_MAP); 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/handlers/UltraDNSWSErrorHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java index 3baaefb891..eb2695c9ab 100644 --- 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 @@ -75,6 +75,7 @@ public class UltraDNSWSErrorHandler implements HttpErrorHandler { private Exception refineException(UltraDNSWSResponseException exception) { switch (exception.getError().getCode()) { + case 1801: case 2401: return new ResourceNotFoundException(exception.getError().getDescription(), 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/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/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 index 6e1241bf54..bd31c9b92b 100644 --- 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 @@ -65,7 +65,28 @@ public class UltraDNSWSErrorHandlerTest { 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) { 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/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/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_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/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