Merge pull request #1249 from jclouds/ultra-listzones

UltraDNS SSL, error handling, list and get zones
This commit is contained in:
Adrian Cole 2013-01-27 15:08:50 -08:00
commit e085086617
38 changed files with 1738 additions and 20 deletions

View File

@ -34,7 +34,7 @@
<packaging>bundle</packaging>
<properties>
<test.ultradns-ws.endpoint>http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01</test.ultradns-ws.endpoint>
<test.ultradns-ws.endpoint>https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01</test.ultradns-ws.endpoint>
<test.ultradns-ws.api-version>v01</test.ultradns-ws.api-version>
<test.ultradns-ws.build-version></test.ultradns-ws.build-version>
<test.ultradns-ws.identity></test.ultradns-ws.identity>

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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
* <p/>
*
* @see <a href="https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01?wsdl" />
* @see <a href="https://www.ultradns.net/api/NUS_API_XML_SOAP.pdf" />
* @author Adrian Cole
*/
@ -48,9 +50,13 @@ public interface UltraDNSWSAsyncApi {
*/
@Named("getAccountsListOfUser")
@POST
@Path("/")
@XMLResponseParser(AccountHandler.class)
@Payload("<getAccountsListOfUser/>")
@Payload("<v01:getAccountsListOfUser/>")
ListenableFuture<Account> getCurrentAccount();
/**
* Provides asynchronous access to Zone features.
*/
@Delegate
ZoneAsyncApi getZoneApi();
}

View File

@ -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);
}
}

View File

@ -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());
}

View File

@ -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;
}
}

View File

@ -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<UltraDNSWSApi, UltraDNSWSAsyncApi> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>>builder()
.build();
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, 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);
}
}

View File

@ -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;

View File

@ -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<String> primarySrc;
private Zone(String id, String name, Type type, int typeCode, String accountId, String ownerId,
DNSSECStatus dnssecStatus, Optional<String> 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<String> 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<String> 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());
}
}
}

View File

@ -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);
}
}
}

View File

@ -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<Zone> listByAccount(String accountId) throws ResourceNotFoundException;
/**
* Lists all zones in the specified account of type
*
* @throws ResourceNotFoundException
* if the account doesn't exist
*/
FluentIterable<Zone> listByAccountAndType(String accountId, Type type) throws ResourceNotFoundException;
}

View File

@ -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 <a href="https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01?wsdl" />
* @see <a href="https://www.ultradns.net/api/NUS_API_XML_SOAP.pdf" />
* @author Adrian Cole
*/
@RequestFilters(SOAPWrapWithPasswordAuth.class)
@VirtualHost
public interface ZoneAsyncApi {
/**
* @see ZoneApi#get(String)
*/
@Named("getGeneralPropertiesForZone")
@POST
@XMLResponseParser(ZonePropertiesHandler.class)
@Payload("<v01:getGeneralPropertiesForZone><zoneName>{zoneName}</zoneName></v01:getGeneralPropertiesForZone>")
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<ZoneProperties> get(@PayloadParam("zoneName") String name);
/**
* @see ZoneApi#listByAccount(String)
*/
@Named("getZonesOfAccount")
@POST
@XMLResponseParser(ZoneListHandler.class)
@Payload("<v01:getZonesOfAccount><accountId>{accountId}</accountId><zoneType>all</zoneType></v01:getZonesOfAccount>")
ListenableFuture<FluentIterable<Zone>> listByAccount(@PayloadParam("accountId") String accountId)
throws ResourceNotFoundException;
/**
* @see ZoneApi#listByAccountAndType(String, Type)
*/
@Named("getZonesOfAccount")
@POST
@XMLResponseParser(ZoneListHandler.class)
@Payload("<v01:getZonesOfAccount><accountId>{accountId}</accountId><zoneType>{zoneType}</zoneType></v01:getZonesOfAccount>")
ListenableFuture<FluentIterable<Zone>> listByAccountAndType(@PayloadParam("accountId") String accountId,
@PayloadParam("zoneType") Type type) throws ResourceNotFoundException;
}

View File

@ -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("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" ")
.append("xmlns=\"http://webservice.api.ultra.neustar.com/v01/\"><soapenv:Header>")
.append("xmlns:v01=\"http://webservice.api.ultra.neustar.com/v01/\"><soapenv:Header>")
.append("<wsse:Security xmlns:wsse=\"").append(WSSE_NS).append("\"><wsse:UsernameToken>")
.append("<wsse:Username>%s</wsse:Username><wsse:Password>%s</wsse:Password>")
.append("</wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body>").toString();

View File

@ -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<UltraWSExceptionHandler> handlers;
@Inject
UltraDNSWSErrorHandler(Factory factory, Provider<UltraWSExceptionHandler> 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;
}
}

View File

@ -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<Zone> typeEquals(final Type type) {
checkNotNull(type, "type must be defined");
return new Predicate<Zone>() {
@Override
public boolean apply(Zone zone) {
return type.equals(zone.getType());
}
@Override
public String toString() {
return "typeEquals(" + type + ")";
}
};
}
}

View File

@ -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<UltraDNSWSError> {
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);
}
}

View File

@ -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<Zone> {
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<String, String> 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();
}
}
}

View File

@ -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<FluentIterable<Zone>> {
private final ZoneHandler zoneHandler;
private Builder<Zone> zones = ImmutableSet.<Zone> builder();
@Inject
public ZoneListHandler(ZoneHandler zoneHandler) {
this.zoneHandler = zoneHandler;
}
@Override
public FluentIterable<Zone> 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());
}
}
}

View File

@ -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<ZoneProperties> {
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<String, String> 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();
}
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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<Zone> 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();
}
}

View File

@ -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);
}
}
}

View File

@ -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");
}
}

View File

@ -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();
}
}

View File

@ -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<Zone> expected = expected();
ZoneListHandler handler = injector.getInstance(ZoneListHandler.class);
FluentIterable<Zone> result = factory.create(handler).parse(is);
assertEquals(result.toSet().toString(), expected.toSet().toString());
}
public FluentIterable<Zone> expected() {
return FluentIterable.from(ImmutableSet.<Zone> 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());
}
}

View File

@ -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.");
}
}

View File

@ -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);
}
}

View File

@ -3,7 +3,7 @@
<ns1:getAccountsListOfUserResponse
xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<AccountsList xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">
<ns2:AccountDetailsData accountID="01233CB945FAC523"
<ns2:AccountDetailsData accountID="AAAAAAAAAAAAAAAA"
accountName="jclouds" />
</AccountsList>
</ns1:getAccountsListOfUserResponse>

View File

@ -0,0 +1,14 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
<detail>
<ns1:UltraWSException xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<errorCode xsi:type="xs:int" xmlns:ns2="http://schema.ultraservice.neustar.com/v01/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">2401</errorCode>
<errorDescription xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">Account not found in the system. ID: AAAAAAAAAAAAAAAA</errorDescription>
</ns1:UltraWSException>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

View File

@ -1 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password>credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><getAccountsListOfUser/></soapenv:Body></soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password>credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getAccountsListOfUser/></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password>credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getGeneralPropertiesForZone><zoneName>jclouds.org.</zoneName></v01:getGeneralPropertiesForZone></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password>credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getZonesOfAccount><accountId>AAAAAAAAAAAAAAAA</accountId><zoneType>all</zoneType></v01:getZonesOfAccount></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v01="http://webservice.api.ultra.neustar.com/v01/"><soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsse:UsernameToken><wsse:Username>identity</wsse:Username><wsse:Password>credential</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header><soapenv:Body><v01:getZonesOfAccount><accountId>AAAAAAAAAAAAAAAA</accountId><zoneType>primary</zoneType></v01:getZonesOfAccount></soapenv:Body></soapenv:Envelope>

View File

@ -0,0 +1,14 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Fault occurred while processing.</faultstring>
<detail>
<ns1:UltraWSException xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<errorCode xsi:type="xs:int" xmlns:ns2="http://schema.ultraservice.neustar.com/v01/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1801</errorCode>
<errorDescription xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">Zone does not exist in the system.</errorDescription>
</ns1:UltraWSException>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1,7 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getGeneralPropertiesForZoneResponse xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<GeneralZoneProperties resourceRecordCount="17" name="jclouds.org." zoneType="primary" modified="2010-09-05 04:04:17.0" xmlns:ns2="http://schema.ultraservice.neustar.com/v01/"/>
</ns1:getGeneralPropertiesForZoneResponse>
</soap:Body>
</soap:Envelope>

View File

@ -0,0 +1,10 @@
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:getZonesOfAccountResponse xmlns:ns1="http://webservice.api.ultra.neustar.com/v01/">
<ZoneList xmlns:ns2="http://schema.ultraservice.neustar.com/v01/">
<ns2:UltraZone zoneName="jclouds.org." zoneType="1" accountId="AAAAAAAAAAAAAAAA" owner="EEEEEEEEEEEEEEEE" zoneId="0000000000000001" dnssecStatus="UNSIGNED"/>
<ns2:UltraZone zoneName="0.1.2.3.4.5.6.7.ip6.arpa." zoneType="1" accountId="AAAAAAAAAAAAAAAA" owner="EEEEEEEEEEEEEEEE" zoneId="0000000000000002" dnssecStatus="UNSIGNED"/>
</ZoneList>
</ns1:getZonesOfAccountResponse>
</soap:Body>
</soap:Envelope>