mirror of https://github.com/apache/jclouds.git
added zone list and get commands to ultradns
This commit is contained in:
parent
ef862775ec
commit
bec4734461
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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("<v01:getAccountsListOfUser/>")
|
||||
ListenableFuture<Account> getCurrentAccount();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Zone features.
|
||||
*/
|
||||
@Delegate
|
||||
ZoneAsyncApi getZoneApi();
|
||||
}
|
||||
|
|
|
@ -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<UltraDNSWSApi, UltraDNSWSAsyncApi> {
|
||||
|
||||
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()
|
||||
.build();
|
||||
.put(ZoneApi.class, ZoneAsyncApi.class).build();
|
||||
|
||||
public UltraDNSWSRestClientModule() {
|
||||
super(DELEGATE_MAP);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 + ")";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
Loading…
Reference in New Issue