diff --git a/labs/ultradns-ws/pom.xml b/labs/ultradns-ws/pom.xml index 54d5b8e452..7eb19947cc 100644 --- a/labs/ultradns-ws/pom.xml +++ b/labs/ultradns-ws/pom.xml @@ -34,7 +34,7 @@ bundle - http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01 + https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01 v01 diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java index 991d486326..20aedfc7b6 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java @@ -37,5 +37,4 @@ public interface UltraDNSWSApi { * Returns the account of the current user. */ Account getCurrentAccount(); - } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java index d7cb135302..30c007e374 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java @@ -67,7 +67,7 @@ public class UltraDNSWSApiMetadata extends BaseRestApiMetadata { .credentialName("Password") .version("v01") .documentation(URI.create("https://www.ultradns.net/api/NUS_API_XML_SOAP.pdf")) - .defaultEndpoint("http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01") + .defaultEndpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") .defaultProperties(UltraDNSWSApiMetadata.defaultProperties()) .defaultModule(UltraDNSWSRestClientModule.class); } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java index 002a3f71a2..adaaefe7c9 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java @@ -20,7 +20,6 @@ package org.jclouds.ultradns.ws; import javax.inject.Named; import javax.ws.rs.POST; -import javax.ws.rs.Path; import org.jclouds.rest.annotations.Payload; import org.jclouds.rest.annotations.RequestFilters; @@ -36,6 +35,7 @@ import com.google.common.util.concurrent.ListenableFuture; * Provides access to Neustar UltraDNS via the SOAP API *

* + * @see * @see * @author Adrian Cole */ @@ -48,9 +48,7 @@ public interface UltraDNSWSAsyncApi { */ @Named("getAccountsListOfUser") @POST - @Path("/") @XMLResponseParser(AccountHandler.class) - @Payload("") + @Payload("") ListenableFuture getCurrentAccount(); - } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSError.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSError.java new file mode 100644 index 0000000000..1952ee0b91 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSError.java @@ -0,0 +1,68 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Adrian Cole + */ +public final class UltraDNSWSError { + public static UltraDNSWSError fromCodeAndDescription(int code, String description) { + return new UltraDNSWSError(code, description); + } + + private final int code; + private final String description; + + private UltraDNSWSError(int code, String description) { + this.code = code; + this.description = checkNotNull(description, "description for code %s", code); + } + + /** + * The error code. ex {@code 1801} + */ + public int getCode() { + return code; + } + + /** + * The description of the error. ex {@code Zone does not exist in the system.} + */ + public String getDescription() { + return description; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + UltraDNSWSError that = UltraDNSWSError.class.cast(obj); + return equal(this.code, that.code) && equal(this.description, that.description); + } + + @Override + public String toString() { + return String.format("Error %s: %s", code, description); + } +} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java index 270fe11e6f..1a0b1b3cc0 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java @@ -63,7 +63,7 @@ public class UltraDNSWSProviderMetadata extends BaseProviderMetadata { .homepage(URI.create("http://www.neustar.biz/enterprise/dns-services/what-is-external-dns")) .console(URI.create("https://www.ultradns.net")) .iso3166Codes("US-CA", "US-VA") // TODO - .endpoint("http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") .defaultProperties(UltraDNSWSProviderMetadata.defaultProperties()); } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSResponseException.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSResponseException.java new file mode 100644 index 0000000000..1137a4a2e6 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSResponseException.java @@ -0,0 +1,44 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws; + +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; + +/** + * @see UltraDNSWSError + * @author Adrian Cole + */ +public class UltraDNSWSResponseException extends HttpResponseException { + + private static final long serialVersionUID = 5493782874839736777L; + + private final UltraDNSWSError error; + + public UltraDNSWSResponseException(HttpCommand command, HttpResponse response, UltraDNSWSError error) { + super(error.toString(), command, response); + this.error = error; + } + + public UltraDNSWSError getError() { + return error; + } + +} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java index 46239aa14c..cda0c00f96 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.java @@ -20,10 +20,16 @@ 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.handlers.UltraDNSWSErrorHandler; import com.google.common.collect.ImmutableMap; @@ -34,11 +40,23 @@ import com.google.common.collect.ImmutableMap; */ @ConfiguresRestClient public class UltraDNSWSRestClientModule extends RestClientModule { - - public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class>builder() + + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() .build(); - + public UltraDNSWSRestClientModule() { super(DELEGATE_MAP); } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(UltraDNSWSErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(UltraDNSWSErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(UltraDNSWSErrorHandler.class); + } + + @Override + protected void bindRetryHandlers() { + bind(HttpRetryHandler.class).annotatedWith(ServerError.class).toInstance(HttpRetryHandler.NEVER_RETRY); + } } diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java index ebf3b20d41..fd9b41bc76 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java @@ -39,7 +39,7 @@ public final class Account { } /** - * The id of the account. ex {@code 01233CB945FAC523} + * The id of the account. ex {@code AAAAAAAAAAAAAAAA} */ public String getId() { return id; diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java index 93411f2579..de551644d2 100644 --- a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java @@ -39,7 +39,7 @@ public class SOAPWrapWithPasswordAuth implements HttpRequestFilter { static final String WSSE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; static final String SOAP_PREFIX = new StringBuilder() .append("") + .append("xmlns:v01=\"http://webservice.api.ultra.neustar.com/v01/\">") .append("") .append("%s%s") .append("").toString(); diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java new file mode 100644 index 0000000000..3baaefb891 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandler.java @@ -0,0 +1,84 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws.handlers; + +import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; +import static org.jclouds.http.HttpUtils.releasePayload; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.rest.ResourceNotFoundException; +import org.jclouds.ultradns.ws.UltraDNSWSError; +import org.jclouds.ultradns.ws.UltraDNSWSResponseException; +import org.jclouds.ultradns.ws.xml.UltraWSExceptionHandler; + +/** + * @author Adrian Cole + */ +@Singleton +public class UltraDNSWSErrorHandler implements HttpErrorHandler { + + private final Factory factory; + private final Provider handlers; + + @Inject + UltraDNSWSErrorHandler(Factory factory, Provider handlers) { + this.factory = factory; + this.handlers = handlers; + } + + public void handleError(HttpCommand command, HttpResponse response) { + Exception exception = new HttpResponseException(command, response); + try { + byte[] data = closeClientButKeepContentStream(response); + String message = data != null ? new String(data) : null; + if (message != null) { + exception = new HttpResponseException(command, response, message); + String contentType = response.getPayload().getContentMetadata().getContentType(); + if (contentType != null && (contentType.indexOf("xml") != -1 || contentType.indexOf("unknown") != -1)) { + UltraDNSWSError error = factory.create(handlers.get()).parse(message); + if (error != null) { + exception = refineException(new UltraDNSWSResponseException(command, response, error)); + } + } + } else { + exception = new HttpResponseException(command, response); + } + } finally { + releasePayload(response); + command.setException(exception); + } + } + + private Exception refineException(UltraDNSWSResponseException exception) { + switch (exception.getError().getCode()) { + case 2401: + return new ResourceNotFoundException(exception.getError().getDescription(), exception); + } + return exception; + } + +} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/UltraWSExceptionHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/UltraWSExceptionHandler.java new file mode 100644 index 0000000000..fdf2e9897d --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/UltraWSExceptionHandler.java @@ -0,0 +1,61 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws.xml; + +import static org.jclouds.util.SaxUtils.currentOrNull; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.ultradns.ws.UltraDNSWSError; + +/** + * + * @author Adrian Cole + */ +public class UltraWSExceptionHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private StringBuilder currentText = new StringBuilder(); + private int code = -1; + private String description; + + @Override + public UltraDNSWSError getResult() { + try { + return code > 0 ? UltraDNSWSError.fromCodeAndDescription(code, description) : null; + } finally { + code = -1; + description = null; + } + } + + @Override + public void endElement(String uri, String name, String qName) { + if (qName.equals("errorCode")) { + code = Integer.parseInt(currentOrNull(currentText)); + } else if (qName.equals("errorDescription")) { + description = currentOrNull(currentText); + } + currentText = new StringBuilder(); + } + + @Override + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java index a75d569a8d..946ca8d0b8 100644 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.java @@ -33,8 +33,8 @@ import org.testng.annotations.Test; public class UltraDNSWSApiExpectTest extends BaseUltraDNSWSApiExpectTest { HttpRequest getCurrentAccount = HttpRequest.builder().method("POST") - .endpoint("http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01/") - .addHeader("Host", "ultra-api.ultradns.com:8008") + .endpoint("https://ultra-api.ultradns.com:8443/UltraDNS_WS/v01") + .addHeader("Host", "ultra-api.ultradns.com:8443") .payload(payloadFromResourceWithContentType("/get_current_account.xml", "application/xml")).build(); HttpResponse getCurrentAccountResponse = HttpResponse.builder().statusCode(200) @@ -42,10 +42,10 @@ public class UltraDNSWSApiExpectTest extends BaseUltraDNSWSApiExpectTest { public void testGetCurrentAccountWhenResponseIs2xx() { - UltraDNSWSApi apiWhenWithOptionsExist = requestSendsResponse(getCurrentAccount, getCurrentAccountResponse); + UltraDNSWSApi success = requestSendsResponse(getCurrentAccount, getCurrentAccountResponse); assertEquals( - apiWhenWithOptionsExist.getCurrentAccount().toString(), + success.getCurrentAccount().toString(), new GetAccountsListOfUserResponseTest().expected().toString()); } } diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java new file mode 100644 index 0000000000..6e1241bf54 --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/handlers/UltraDNSWSErrorHandlerTest.java @@ -0,0 +1,79 @@ +/** + * 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); + + } + + private Payload payloadFromResource(String resource) { + try { + return payloadFromStringWithContentType(toStringAndClose(getClass().getResourceAsStream(resource)), + "application/xml"); + } catch (IOException e) { + throw propagate(e); + } + } +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java index a3038a64fa..5957eb2965 100644 --- a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.java @@ -30,7 +30,7 @@ import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test +@Test(testName = "GetAccountsListOfUserResponseTest") public class GetAccountsListOfUserResponseTest extends BaseHandlerTest { public void test() { @@ -45,7 +45,7 @@ public class GetAccountsListOfUserResponseTest extends BaseHandlerTest { } public Account expected() { - return Account.fromIdAndName("01233CB945FAC523", "jclouds"); + return Account.fromIdAndName("AAAAAAAAAAAAAAAA", "jclouds"); } } diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/UltraWSExceptionTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/UltraWSExceptionTest.java new file mode 100644 index 0000000000..3cb99f311e --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/UltraWSExceptionTest.java @@ -0,0 +1,51 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.ultradns.ws.UltraDNSWSError; +import org.jclouds.ultradns.ws.xml.UltraWSExceptionHandler; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(testName = "UltraWSExceptionTest") +public class UltraWSExceptionTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/zone_doesnt_exist.xml"); + + UltraDNSWSError expected = expected(); + + UltraWSExceptionHandler handler = injector.getInstance(UltraWSExceptionHandler.class); + UltraDNSWSError result = factory.create(handler).parse(is); + + assertEquals(result, expected); + } + + public UltraDNSWSError expected() { + return UltraDNSWSError.fromCodeAndDescription(1801, "Zone does not exist in the system."); + } + +} diff --git a/labs/ultradns-ws/src/test/resources/account.xml b/labs/ultradns-ws/src/test/resources/account.xml index f82e7994b5..735c069aee 100644 --- a/labs/ultradns-ws/src/test/resources/account.xml +++ b/labs/ultradns-ws/src/test/resources/account.xml @@ -3,7 +3,7 @@ - diff --git a/labs/ultradns-ws/src/test/resources/account_doesnt_exist.xml b/labs/ultradns-ws/src/test/resources/account_doesnt_exist.xml new file mode 100644 index 0000000000..7deae99fb0 --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/account_doesnt_exist.xml @@ -0,0 +1,14 @@ + + + + soap:Server + Fault occurred while processing. + + + 2401 + Account not found in the system. ID: AAAAAAAAAAAAAAAA + + + + + \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/get_current_account.xml b/labs/ultradns-ws/src/test/resources/get_current_account.xml index 17ab2413f6..d8192021a2 100644 --- a/labs/ultradns-ws/src/test/resources/get_current_account.xml +++ b/labs/ultradns-ws/src/test/resources/get_current_account.xml @@ -1 +1 @@ -identitycredential \ No newline at end of file +identitycredential \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/list_zones_by_account.xml b/labs/ultradns-ws/src/test/resources/list_zones_by_account.xml new file mode 100644 index 0000000000..8e633c0a78 --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/list_zones_by_account.xml @@ -0,0 +1 @@ +identitycredentialAAAAAAAAAAAAAAAAall \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/zone_doesnt_exist.xml b/labs/ultradns-ws/src/test/resources/zone_doesnt_exist.xml new file mode 100644 index 0000000000..6abc45ec12 --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/zone_doesnt_exist.xml @@ -0,0 +1,14 @@ + + + + soap:Server + Fault occurred while processing. + + + 1801 + Zone does not exist in the system. + + + + + \ No newline at end of file