diff --git a/labs/pom.xml b/labs/pom.xml index 2ecac0a6d8..3d4eee2be5 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -66,5 +66,6 @@ route53 dynect aws-route53 + ultradns-ws diff --git a/labs/ultradns-ws/pom.xml b/labs/ultradns-ws/pom.xml new file mode 100644 index 0000000000..a4bef1f225 --- /dev/null +++ b/labs/ultradns-ws/pom.xml @@ -0,0 +1,107 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.6.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + ultradns-ws + jcloud ultradns-ws provider + jclouds components to access UltraDNS Web Services API + bundle + + + http://ultra-api.ultradns.com:8008/UltraDNS_WS/v01 + v01 + + + + + org.jclouds.ultradns.ws*;version="${project.version}" + org.jclouds*;version="${project.version}",* + + + + + org.jclouds + jclouds-core + ${project.version} + jar + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.ultradns-ws.endpoint} + ${test.ultradns-ws.api-version} + ${test.ultradns-ws.build-version} + ${test.ultradns-ws.identity} + ${test.ultradns-ws.credential} + + + + + + + + + + + + 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 new file mode 100644 index 0000000000..5e37e6a5df --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApi.java @@ -0,0 +1,37 @@ +/** + * 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.ultradns.ws.domain.Account; + +/** + * Provides access to Neustar UltraDNS via the SOAP API + *

+ * + * @see UltraDNSWSAsyncApi + * @see + * @author Adrian Cole + */ +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 new file mode 100644 index 0000000000..3d430529ad --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSApiMetadata.java @@ -0,0 +1,85 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; +import org.jclouds.ultradns.ws.config.UltraDNSWSRestClientModule; + +import com.google.common.reflect.TypeToken; + +/** + * Implementation of {@link ApiMetadata} for Neustar's UltraDNSWS api. + * + * @author Adrian Cole + */ +public class UltraDNSWSApiMetadata extends BaseRestApiMetadata { + + public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { + private static final long serialVersionUID = 1L; + }; + + @Override + public Builder toBuilder() { + return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); + } + + public UltraDNSWSApiMetadata() { + this(new Builder(UltraDNSWSApi.class, UltraDNSWSAsyncApi.class)); + } + + protected UltraDNSWSApiMetadata(Builder builder) { + super(Builder.class.cast(builder)); + } + + public static Properties defaultProperties() { + Properties properties = BaseRestApiMetadata.defaultProperties(); + return properties; + } + + public static class Builder extends BaseRestApiMetadata.Builder { + + protected Builder(Class api, Class asyncApi) { + super(api, asyncApi); + id("ultradns-ws") + .name("Neustar UltraDNS WS Api") + .identityName("Username") + .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") + .defaultProperties(UltraDNSWSApiMetadata.defaultProperties()) + .defaultModule(UltraDNSWSRestClientModule.class); + } + + @Override + public UltraDNSWSApiMetadata build() { + return new UltraDNSWSApiMetadata(this); + } + + @Override + protected Builder self() { + return this; + } + } +} 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 new file mode 100644 index 0000000000..002a3f71a2 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSAsyncApi.java @@ -0,0 +1,56 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws; + +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; +import org.jclouds.rest.annotations.VirtualHost; +import org.jclouds.rest.annotations.XMLResponseParser; +import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.filters.SOAPWrapWithPasswordAuth; +import org.jclouds.ultradns.ws.xml.AccountHandler; + +import com.google.common.util.concurrent.ListenableFuture; + +/** + * Provides access to Neustar UltraDNS via the SOAP API + *

+ * + * @see + * @author Adrian Cole + */ +@RequestFilters(SOAPWrapWithPasswordAuth.class) +@VirtualHost +public interface UltraDNSWSAsyncApi { + + /** + * @see UltraDNSWSApi#getCurrentAccount() + */ + @Named("getAccountsListOfUser") + @POST + @Path("/") + @XMLResponseParser(AccountHandler.class) + @Payload("") + ListenableFuture getCurrentAccount(); + +} 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 new file mode 100644 index 0000000000..270fe11e6f --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadata.java @@ -0,0 +1,82 @@ +/** + * 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 java.net.URI; +import java.util.Properties; + +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +/** + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Neustar + * UltraDNS. + * + * @author Adrian Cole + */ +public class UltraDNSWSProviderMetadata extends BaseProviderMetadata { + + public static Builder builder() { + return new Builder(); + } + + @Override + public Builder toBuilder() { + return builder().fromProviderMetadata(this); + } + + public UltraDNSWSProviderMetadata() { + super(builder()); + } + + public UltraDNSWSProviderMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder { + + protected Builder() { + id("ultradns-ws") + .name("Neustar UltraDNS WS") + .apiMetadata(new UltraDNSWSApiMetadata()) + .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") + .defaultProperties(UltraDNSWSProviderMetadata.defaultProperties()); + } + + @Override + public UltraDNSWSProviderMetadata build() { + return new UltraDNSWSProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata(ProviderMetadata in) { + super.fromProviderMetadata(in); + return this; + } + + } +} 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 new file mode 100644 index 0000000000..46239aa14c --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/config/UltraDNSWSRestClientModule.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.config; + +import java.util.Map; + +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.config.RestClientModule; +import org.jclouds.ultradns.ws.UltraDNSWSApi; +import org.jclouds.ultradns.ws.UltraDNSWSAsyncApi; + +import com.google.common.collect.ImmutableMap; + +/** + * Configures the UltraDNSWS connection. + * + * @author Adrian Cole + */ +@ConfiguresRestClient +public class UltraDNSWSRestClientModule extends RestClientModule { + + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class>builder() + .build(); + + public UltraDNSWSRestClientModule() { + super(DELEGATE_MAP); + } +} 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 new file mode 100644 index 0000000000..ebf3b20d41 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/domain/Account.java @@ -0,0 +1,71 @@ +/** + * 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; + +/** + * @author Adrian Cole + */ +public final class Account { + public static Account fromIdAndName(String id, String name) { + return new Account(id, name); + } + + private final String id; + private final String name; + + private Account(String id, String name) { + this.id = checkNotNull(id, "id"); + this.name = checkNotNull(name, "name for %s", id); + } + + /** + * The id of the account. ex {@code 01233CB945FAC523} + */ + public String getId() { + return id; + } + + /** + * The name of the account. ex {@code jclouds} + */ + public String getName() { + return name; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Account that = Account.class.cast(obj); + return Objects.equal(this.id, that.id) && Objects.equal(this.name, that.name); + } + + @Override + public String toString() { + return Objects.toStringHelper(this).add("id", id).add("name", name).toString(); + } +} 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 new file mode 100644 index 0000000000..93411f2579 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/filters/SOAPWrapWithPasswordAuth.java @@ -0,0 +1,65 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws.filters; + +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.String.format; + +import javax.inject.Inject; + +import org.jclouds.domain.Credentials; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.location.Provider; + +import com.google.common.base.Supplier; + +/** + * @author Adrian Cole + */ +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("") + .append("%s%s") + .append("").toString(); + static final String SOAP_SUFFIX = ""; + + private final Supplier creds; + + @Inject + public SOAPWrapWithPasswordAuth(@Provider Supplier creds) { + this.creds = creds; + } + + public HttpRequest filter(HttpRequest request) { + checkNotNull(request.getPayload(), "request is not ready to wrap; payload not present"); + Credentials current = creds.get(); + String body = request.getPayload().getRawContent().toString(); + Payload wrappedPayload = Payloads.newStringPayload(new StringBuilder() + .append(format(SOAP_PREFIX, current.identity, current.credential)).append(body).append(SOAP_SUFFIX) + .toString()); + wrappedPayload.getContentMetadata().setContentType("application/xml"); + return request.toBuilder().payload(wrappedPayload).build(); + } +} diff --git a/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountHandler.java b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountHandler.java new file mode 100644 index 0000000000..7b2d1763e9 --- /dev/null +++ b/labs/ultradns-ws/src/main/java/org/jclouds/ultradns/ws/xml/AccountHandler.java @@ -0,0 +1,54 @@ +/** + * 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.cleanseAttributes; +import static org.jclouds.util.SaxUtils.equalsOrSuffix; + +import java.util.Map; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.ultradns.ws.domain.Account; +import org.xml.sax.Attributes; + +/** + * + * @author Adrian Cole + */ +public class AccountHandler extends ParseSax.HandlerForGeneratedRequestWithResult { + + private Account account; + + @Override + public Account getResult() { + try { + return account; + } finally { + account = null; + } + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attrs) { + Map attributes = cleanseAttributes(attrs); + if (equalsOrSuffix(qName, "AccountDetailsData")) { + account = Account.fromIdAndName(attributes.get("accountID"), attributes.get("accountName")); + } + } +} diff --git a/labs/ultradns-ws/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/labs/ultradns-ws/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..316f59897f --- /dev/null +++ b/labs/ultradns-ws/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.ultradns.ws.UltraDNSWSProviderMetadata 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 new file mode 100644 index 0000000000..a75d569a8d --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiExpectTest.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 + * + * Unles 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 expres or implied. See the License for the + * specific language governing permisions and limitations + * under the License. + */ +package org.jclouds.ultradns.ws; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiExpectTest; +import org.jclouds.ultradns.ws.parse.GetAccountsListOfUserResponseTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "UltraDNSWSApiExpectTest") +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") + .payload(payloadFromResourceWithContentType("/get_current_account.xml", "application/xml")).build(); + + HttpResponse getCurrentAccountResponse = HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/account.xml", "application/xml")).build(); + + public void testGetCurrentAccountWhenResponseIs2xx() { + + UltraDNSWSApi apiWhenWithOptionsExist = requestSendsResponse(getCurrentAccount, getCurrentAccountResponse); + + assertEquals( + apiWhenWithOptionsExist.getCurrentAccount().toString(), + new GetAccountsListOfUserResponseTest().expected().toString()); + } +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiLiveTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiLiveTest.java new file mode 100644 index 0000000000..dbce57f4cb --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSApiLiveTest.java @@ -0,0 +1,47 @@ +/** + * 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.Preconditions.checkNotNull; + +import org.jclouds.ultradns.ws.domain.Account; +import org.jclouds.ultradns.ws.internal.BaseUltraDNSWSApiLiveTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "UltraDNSWSApiLiveTest") +public class UltraDNSWSApiLiveTest extends BaseUltraDNSWSApiLiveTest { + + @Test + protected void testGetCurrentAccount() { + Account account = api().getCurrentAccount(); + checkAccount(account); + } + + private void checkAccount(Account account) { + checkNotNull(account.getId(), "Id cannot be null for an Account."); + checkNotNull(account.getName(), "Name cannot be null for Account %s", account); + } + + protected UltraDNSWSApi api() { + return context.getApi(); + } +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadataTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadataTest.java new file mode 100644 index 0000000000..9ba93d7163 --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/UltraDNSWSProviderMetadataTest.java @@ -0,0 +1,35 @@ +/** + * 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.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "UltraDNSWSProviderMetadataTest") +public class UltraDNSWSProviderMetadataTest extends BaseProviderMetadataTest { + + // no dns abstraction, yet + public UltraDNSWSProviderMetadataTest() { + super(new UltraDNSWSProviderMetadata(), new UltraDNSWSApiMetadata()); + } +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSApiExpectTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSApiExpectTest.java new file mode 100644 index 0000000000..882a74313b --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSApiExpectTest.java @@ -0,0 +1,29 @@ +/** + * 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.internal; + +import org.jclouds.ultradns.ws.UltraDNSWSApi; + +/** + * + * @author Adrian Cole + */ +public class BaseUltraDNSWSApiExpectTest extends BaseUltraDNSWSExpectTest { + +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSApiLiveTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSApiLiveTest.java new file mode 100644 index 0000000000..7884b4c9ba --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSApiLiveTest.java @@ -0,0 +1,45 @@ +/** + * 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.internal; + +import org.jclouds.apis.BaseContextLiveTest; +import org.jclouds.ultradns.ws.UltraDNSWSApiMetadata; +import org.jclouds.ultradns.ws.UltraDNSWSAsyncApi; +import org.jclouds.ultradns.ws.UltraDNSWSApi; +import org.jclouds.rest.RestContext; +import org.testng.annotations.Test; + +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseUltraDNSWSApiLiveTest extends BaseContextLiveTest> { + + public BaseUltraDNSWSApiLiveTest() { + provider = "ultradns-ws"; + } + + @Override + protected TypeToken> contextType() { + return UltraDNSWSApiMetadata.CONTEXT_TOKEN; + } +} diff --git a/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSExpectTest.java b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSExpectTest.java new file mode 100644 index 0000000000..6fa7237222 --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/internal/BaseUltraDNSWSExpectTest.java @@ -0,0 +1,32 @@ +/** + * 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.internal; + +import org.jclouds.rest.internal.BaseRestApiExpectTest; + +/** + * + * @author Adrian Cole + */ +public class BaseUltraDNSWSExpectTest extends BaseRestApiExpectTest { + + public BaseUltraDNSWSExpectTest() { + provider = "ultradns-ws"; + } +} 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 new file mode 100644 index 0000000000..a3038a64fa --- /dev/null +++ b/labs/ultradns-ws/src/test/java/org/jclouds/ultradns/ws/parse/GetAccountsListOfUserResponseTest.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.domain.Account; +import org.jclouds.ultradns.ws.xml.AccountHandler; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test +public class GetAccountsListOfUserResponseTest extends BaseHandlerTest { + + public void test() { + InputStream is = getClass().getResourceAsStream("/account.xml"); + + Account expected = expected(); + + AccountHandler handler = injector.getInstance(AccountHandler.class); + Account result = factory.create(handler).parse(is); + + assertEquals(result, expected); + } + + public Account expected() { + return Account.fromIdAndName("01233CB945FAC523", "jclouds"); + } + +} diff --git a/labs/ultradns-ws/src/test/resources/account.xml b/labs/ultradns-ws/src/test/resources/account.xml new file mode 100644 index 0000000000..f82e7994b5 --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/account.xml @@ -0,0 +1,11 @@ + + + + + + + + + \ 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 new file mode 100644 index 0000000000..17ab2413f6 --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/get_current_account.xml @@ -0,0 +1 @@ +identitycredential \ No newline at end of file diff --git a/labs/ultradns-ws/src/test/resources/logback.xml b/labs/ultradns-ws/src/test/resources/logback.xml new file mode 100644 index 0000000000..9679b2e03a --- /dev/null +++ b/labs/ultradns-ws/src/test/resources/logback.xml @@ -0,0 +1,38 @@ + + + + target/test-data/jclouds.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-wire.log + + + %d %-5p [%c] [%thread] %m%n + + + + + + + + + + + + + + + + + + + + + + +