Rename Azure HostedService -> CloudService to match documentation.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/1f907d2a Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/1f907d2a Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/1f907d2a Branch: refs/heads/master Commit: 1f907d2a748c038a70b5e8317217ae1880c62b30 Parents: a53689f Author: Adrian Cole <[email protected]> Authored: Tue Oct 21 21:55:20 2014 -0700 Committer: Adrian Cole <[email protected]> Committed: Wed Oct 22 17:11:19 2014 -0700 ---------------------------------------------------------------------- .../jclouds/azurecompute/AzureComputeApi.java | 9 +- .../azurecompute/domain/CloudService.java | 178 +++++++++++++++++++ .../jclouds/azurecompute/domain/Deployment.java | 2 +- .../org/jclouds/azurecompute/domain/Disk.java | 2 +- .../azurecompute/domain/HostedService.java | 178 ------------------- .../azurecompute/features/CloudServiceApi.java | 130 ++++++++++++++ .../azurecompute/features/HostedServiceApi.java | 130 -------------- .../jclouds/azurecompute/features/ImageApi.java | 4 +- .../azurecompute/features/LocationApi.java | 2 +- .../azurecompute/xml/CloudServiceHandler.java | 127 +++++++++++++ .../azurecompute/xml/HostedServiceHandler.java | 127 ------------- .../xml/ListCloudServicesHandler.java | 69 +++++++ .../xml/ListHostedServicesHandler.java | 69 ------- .../features/CloudServiceApiLiveTest.java | 143 +++++++++++++++ .../features/CloudServiceApiMockTest.java | 138 ++++++++++++++ .../features/HostedServiceApiLiveTest.java | 145 --------------- .../features/HostedServiceApiMockTest.java | 138 -------------- .../xml/CloudServiceHandlerTest.java | 55 ++++++ .../xml/HostedServiceHandlerTest.java | 55 ------ .../xml/ListCloudServicesHandlerTest.java | 71 ++++++++ .../xml/ListHostedServicesHandlerTest.java | 71 -------- .../src/test/resources/hostedservice.xml | 2 +- .../src/test/resources/hostedservices.xml | 2 +- 23 files changed, 923 insertions(+), 924 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java index 7dc946b..ec037a3 100644 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/AzureComputeApi.java @@ -18,9 +18,10 @@ package org.jclouds.azurecompute; import java.io.Closeable; import javax.ws.rs.PathParam; + +import org.jclouds.azurecompute.features.CloudServiceApi; import org.jclouds.azurecompute.features.DeploymentApi; import org.jclouds.azurecompute.features.DiskApi; -import org.jclouds.azurecompute.features.HostedServiceApi; import org.jclouds.azurecompute.features.ImageApi; import org.jclouds.azurecompute.features.LocationApi; import org.jclouds.azurecompute.features.OperationApi; @@ -37,7 +38,7 @@ import org.jclouds.rest.annotations.Delegate; public interface AzureComputeApi extends Closeable { /** * The Service Management API includes operations for listing the available data center locations - * for a hosted service in your subscription. + * for a cloud service in your subscription. * * @see <a href="http://msdn.microsoft.com/en-us/library/gg441299">docs</a> */ @@ -45,13 +46,13 @@ public interface AzureComputeApi extends Closeable { LocationApi getLocationApi(); /** - * The Service Management API includes operations for managing the hosted services beneath your + * The Service Management API includes operations for managing the cloud services beneath your * subscription. * * @see <a href="http://msdn.microsoft.com/en-us/library/ee460812">docs</a> */ @Delegate - HostedServiceApi getHostedServiceApi(); + CloudServiceApi getCloudServiceApi(); /** * The Service Management API includes operations for managing the virtual machines in your http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/CloudService.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/CloudService.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/CloudService.java new file mode 100644 index 0000000..bc29be7 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/CloudService.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.domain; + +import static com.google.common.base.Objects.equal; +import static com.google.common.base.Objects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Date; +import java.util.Map; + +import org.jclouds.javax.annotation.Nullable; + +import com.google.common.base.Objects; + +/** + * System properties for the specified cloud service. These properties include the service name and + * service type; the name of the affinity group to which the service belongs, or its location if it + * is not part of an affinity group. + * + * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a> + */ +public final class CloudService { + public enum Status { + CREATING, CREATED, DELETING, DELETED, CHANGING, RESOLVING_DNS, + UNRECOGNIZED; + } + + /** + * The name of the cloud service. This name is the DNS prefix name and can be used to access the + * cloud service. + * + * <p/>For example, if the service name is MyService you could access the access the service by + * calling: http://MyService.cloudapp.net + */ + public String name() { + return name; + } + + /** + * The geo-location of the cloud service in Windows Azure, if the cloud service is not + * associated with an affinity group. If a location has been specified, the AffinityGroup element + * is not returned. + */ + @Nullable public String location() { + return location; + } + + /** + * The affinity group with which this cloud service is associated, if any. If the service is + * associated with an affinity group, the Location element is not returned. + */ + @Nullable public String affinityGroup() { + return affinityGroup; + } + + /** + * The name can be up to 100 characters in length. The name can be used identify the storage account for your + * tracking purposes. + */ + public String label() { + return label; + } + + @Nullable public String description() { + return description; + } + + public Status status() { + return status; + } + + public Date created() { + return created; + } + + public Date lastModified() { + return lastModified; + } + + /** + * Represents the name of an extended cloud service property. Each extended property must have + * both a defined name and value. You can have a maximum of 50 extended property name/value + * pairs. + * + * <p/>The maximum length of the Name element is 64 characters, only alphanumeric characters and + * underscores are valid in the Name, and the name must start with a letter. Each extended + * property value has a maximum length of 255 characters. + */ + public Map<String, String> extendedProperties() { + return extendedProperties; + } + + public static CloudService create(String name, String location, String affinityGroup, String label, + String description, Status status, Date created, Date lastModified, Map<String, String> extendedProperties) { + return new CloudService(name, location, affinityGroup, label, description, status, created, lastModified, + extendedProperties); + } + + // TODO: Remove from here down with @AutoValue. + private CloudService(String name, String location, String affinityGroup, String label, String description, + Status status, Date created, Date lastModified, Map<String, String> extendedProperties) { + this.name = checkNotNull(name, "name"); + this.location = location; + this.affinityGroup = affinityGroup; + this.label = checkNotNull(label, "label"); + this.description = description; + this.status = checkNotNull(status, "status"); + this.created = checkNotNull(created, "created"); + this.lastModified = checkNotNull(lastModified, "lastModified"); + this.extendedProperties = checkNotNull(extendedProperties, "extendedProperties"); + } + + private final String name; + private final String location; + private final String affinityGroup; + private final String label; + private final String description; + private final Status status; + private final Date created; + private final Date lastModified; + private final Map<String, String> extendedProperties; + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object instanceof CloudService) { + CloudService that = CloudService.class.cast(object); + return equal(name, that.name) + && equal(location, that.location) + && equal(affinityGroup, that.affinityGroup) + && equal(label, that.label) + && equal(description, that.description) + && equal(status, that.status) + && equal(created, that.created) + && equal(lastModified, that.lastModified) + && equal(extendedProperties, that.extendedProperties); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(name, location, affinityGroup, label, description, status, created, lastModified, + extendedProperties); + } + + @Override + public String toString() { + return toStringHelper(this) + .add("name", name) + .add("location", location) + .add("affinityGroup", affinityGroup) + .add("label", label) + .add("description", description) + .add("status", status) + .add("created", created) + .add("lastModified", lastModified) + .add("extendedProperties", extendedProperties).toString(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java index 7a6986f..580c59d 100644 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Deployment.java @@ -51,7 +51,7 @@ public final class Deployment { return name; } - /** The environment to which the hosted service is deployed. */ + /** The environment to which the cloud service is deployed. */ public Slot slot() { return slot; } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java index 26a16b6..07ebf56 100644 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Disk.java @@ -39,7 +39,7 @@ public final class Disk { return deployment; } - /** The hosted service in which the disk is being used. */ + /** The cloud service in which the disk is being used. */ public String hostedService() { return hostedService; } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java deleted file mode 100644 index 6ef400b..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.azurecompute.domain; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Objects.toStringHelper; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Date; -import java.util.Map; - -import org.jclouds.javax.annotation.Nullable; - -import com.google.common.base.Objects; - -/** - * System properties for the specified hosted service. These properties include the service name and - * service type; the name of the affinity group to which the service belongs, or its location if it - * is not part of an affinity group. - * - * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a> - */ -public final class HostedService { - public enum Status { - CREATING, CREATED, DELETING, DELETED, CHANGING, RESOLVING_DNS, - UNRECOGNIZED; - } - - /** - * The name of the hosted service. This name is the DNS prefix name and can be used to access the - * hosted service. - * - * <p/>For example, if the service name is MyService you could access the access the service by - * calling: http://MyService.cloudapp.net - */ - public String name() { - return name; - } - - /** - * The geo-location of the hosted service in Windows Azure, if the hosted service is not - * associated with an affinity group. If a location has been specified, the AffinityGroup element - * is not returned. - */ - @Nullable public String location() { - return location; - } - - /** - * The affinity group with which this hosted service is associated, if any. If the service is - * associated with an affinity group, the Location element is not returned. - */ - @Nullable public String affinityGroup() { - return affinityGroup; - } - - /** - * The name can be up to 100 characters in length. The name can be used identify the storage account for your - * tracking purposes. - */ - public String label() { - return label; - } - - @Nullable public String description() { - return description; - } - - public Status status() { - return status; - } - - public Date created() { - return created; - } - - public Date lastModified() { - return lastModified; - } - - /** - * Represents the name of an extended hosted service property. Each extended property must have - * both a defined name and value. You can have a maximum of 50 extended property name/value - * pairs. - * - * <p/>The maximum length of the Name element is 64 characters, only alphanumeric characters and - * underscores are valid in the Name, and the name must start with a letter. Each extended - * property value has a maximum length of 255 characters. - */ - public Map<String, String> extendedProperties() { - return extendedProperties; - } - - public static HostedService create(String name, String location, String affinityGroup, String label, - String description, Status status, Date created, Date lastModified, Map<String, String> extendedProperties) { - return new HostedService(name, location, affinityGroup, label, description, status, created, lastModified, - extendedProperties); - } - - // TODO: Remove from here down with @AutoValue. - private HostedService(String name, String location, String affinityGroup, String label, String description, - Status status, Date created, Date lastModified, Map<String, String> extendedProperties) { - this.name = checkNotNull(name, "name"); - this.location = location; - this.affinityGroup = affinityGroup; - this.label = checkNotNull(label, "label"); - this.description = description; - this.status = checkNotNull(status, "status"); - this.created = checkNotNull(created, "created"); - this.lastModified = checkNotNull(lastModified, "lastModified"); - this.extendedProperties = checkNotNull(extendedProperties, "extendedProperties"); - } - - private final String name; - private final String location; - private final String affinityGroup; - private final String label; - private final String description; - private final Status status; - private final Date created; - private final Date lastModified; - private final Map<String, String> extendedProperties; - - @Override - public boolean equals(Object object) { - if (this == object) { - return true; - } - if (object instanceof HostedService) { - HostedService that = HostedService.class.cast(object); - return equal(name, that.name) - && equal(location, that.location) - && equal(affinityGroup, that.affinityGroup) - && equal(label, that.label) - && equal(description, that.description) - && equal(status, that.status) - && equal(created, that.created) - && equal(lastModified, that.lastModified) - && equal(extendedProperties, that.extendedProperties); - } else { - return false; - } - } - - @Override - public int hashCode() { - return Objects.hashCode(name, location, affinityGroup, label, description, status, created, lastModified, - extendedProperties); - } - - @Override - public String toString() { - return toStringHelper(this) - .add("name", name) - .add("location", location) - .add("affinityGroup", affinityGroup) - .add("label", label) - .add("description", description) - .add("status", status) - .add("created", created) - .add("lastModified", lastModified) - .add("extendedProperties", extendedProperties).toString(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/features/CloudServiceApi.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/features/CloudServiceApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/features/CloudServiceApi.java new file mode 100644 index 0000000..9cc8b5e --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/features/CloudServiceApi.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.features; + +import static javax.ws.rs.core.MediaType.APPLICATION_XML; +import static org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; +import static org.jclouds.Fallbacks.NullOnNotFoundOr404; + +import java.util.List; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; + +import org.jclouds.azurecompute.domain.CloudService; +import org.jclouds.azurecompute.functions.Base64EncodeLabel; +import org.jclouds.azurecompute.functions.ParseRequestIdHeader; +import org.jclouds.azurecompute.xml.CloudServiceHandler; +import org.jclouds.azurecompute.xml.ListCloudServicesHandler; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.XMLResponseParser; + +/** + * The Service Management API includes operations for managing the cloud services beneath your + * subscription. + * + * @see <a href="http://msdn.microsoft.com/en-us/library/ee460812">docs</a> + */ +@Path("/services/hostedservices") +@Headers(keys = "x-ms-version", values = "{jclouds.api-version}") +@Consumes(APPLICATION_XML) +public interface CloudServiceApi { + + /** + * The List Cloud Services operation lists the cloud services available under the current + * subscription. + * + * @return the response object + */ + @Named("ListCloudServices") + @GET + @QueryParams(keys = "embed-detail", values = "true") + @XMLResponseParser(ListCloudServicesHandler.class) + @Fallback(EmptyListOnNotFoundOr404.class) + List<CloudService> list(); + + /** + * The Create Cloud Service operation creates a new cloud service in Windows Azure. + * + * @param name + * A name for the cloud service that is unique within Windows Azure. This name is the + * DNS prefix name and can be used to access the cloud service. + * + * For example: http://name.cloudapp.net// + * @param label + * The name can be used identify the storage account for your tracking purposes. The + * name can be up to 100 characters in length. + * @param location + * The location where the cloud service will be created. + * @return the requestId to track this async request progress + * + * @see <a href="http://msdn.microsoft.com/en-us/library/ee460812">docs</a> + */ + @Named("CreateCloudService") + @POST + @Produces(APPLICATION_XML) + @ResponseParser(ParseRequestIdHeader.class) + @Payload("<CreateHostedService xmlns=\"http://schemas.microsoft.com/windowsazure\"><ServiceName>{name}</ServiceName><Label>{label}</Label><Location>{location}</Location></CreateHostedService>") + String createWithLabelInLocation(@PayloadParam("name") String name, + @PayloadParam("label") @ParamParser(Base64EncodeLabel.class) String label, + @PayloadParam("location") String location); + + /** + * The Get Cloud Service Properties operation retrieves system properties for the specified + * cloud service. These properties include the service name and service type; the name of the + * affinity group to which the service belongs, or its location if it is not part of an affinity + * group. + * + * @param name + * the unique DNS Prefix value in the Windows Azure Management Portal + */ + @Named("GetCloudServiceProperties") + @GET + @Path("/{name}") + @QueryParams(keys = "embed-detail", values = "true") + @XMLResponseParser(CloudServiceHandler.class) + @Fallback(NullOnNotFoundOr404.class) + @Nullable CloudService get(@PathParam("name") String name); + + /** + * The Delete Cloud Service operation deletes the specified cloud service from Windows Azure. + * + * @param name + * the unique DNS Prefix value in the Windows Azure Management Portal + * + * @return request id or null, if not found + */ + @Named("DeleteCloudService") + @DELETE + @Path("/{name}") + @Fallback(NullOnNotFoundOr404.class) + @ResponseParser(ParseRequestIdHeader.class) + String delete(@PathParam("name") String name); +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java deleted file mode 100644 index f8d1502..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.azurecompute.features; - -import static javax.ws.rs.core.MediaType.APPLICATION_XML; -import static org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; -import static org.jclouds.Fallbacks.NullOnNotFoundOr404; - -import java.util.List; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import org.jclouds.azurecompute.domain.HostedService; -import org.jclouds.azurecompute.functions.Base64EncodeLabel; -import org.jclouds.azurecompute.functions.ParseRequestIdHeader; -import org.jclouds.azurecompute.xml.HostedServiceHandler; -import org.jclouds.azurecompute.xml.ListHostedServicesHandler; -import org.jclouds.javax.annotation.Nullable; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.ParamParser; -import org.jclouds.rest.annotations.Payload; -import org.jclouds.rest.annotations.PayloadParam; -import org.jclouds.rest.annotations.QueryParams; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.rest.annotations.XMLResponseParser; - -/** - * The Service Management API includes operations for managing the hosted services beneath your - * subscription. - * - * @see <a href="http://msdn.microsoft.com/en-us/library/ee460812">docs</a> - */ -@Path("/services/hostedservices") -@Headers(keys = "x-ms-version", values = "{jclouds.api-version}") -@Consumes(APPLICATION_XML) -public interface HostedServiceApi { - - /** - * The List Hosted Services operation lists the hosted services available under the current - * subscription. - * - * @return the response object - */ - @Named("ListHostedServices") - @GET - @QueryParams(keys = "embed-detail", values = "true") - @XMLResponseParser(ListHostedServicesHandler.class) - @Fallback(EmptyListOnNotFoundOr404.class) - List<HostedService> list(); - - /** - * The Create Hosted Service operation creates a new hosted service in Windows Azure. - * - * @param name - * A name for the hosted service that is unique within Windows Azure. This name is the - * DNS prefix name and can be used to access the hosted service. - * - * For example: http://name.cloudapp.net// - * @param label - * The name can be used identify the storage account for your tracking purposes. The - * name can be up to 100 characters in length. - * @param location - * The location where the hosted service will be created. - * @return the requestId to track this async request progress - * - * @see <a href="http://msdn.microsoft.com/en-us/library/ee460812">docs</a> - */ - @Named("CreateHostedService") - @POST - @Produces(APPLICATION_XML) - @ResponseParser(ParseRequestIdHeader.class) - @Payload("<CreateHostedService xmlns=\"http://schemas.microsoft.com/windowsazure\"><ServiceName>{name}</ServiceName><Label>{label}</Label><Location>{location}</Location></CreateHostedService>") - String createWithLabelInLocation(@PayloadParam("name") String name, - @PayloadParam("label") @ParamParser(Base64EncodeLabel.class) String label, - @PayloadParam("location") String location); - - /** - * The Get Hosted Service Properties operation retrieves system properties for the specified - * hosted service. These properties include the service name and service type; the name of the - * affinity group to which the service belongs, or its location if it is not part of an affinity - * group. - * - * @param name - * the unique DNS Prefix value in the Windows Azure Management Portal - */ - @Named("GetHostedServiceProperties") - @GET - @Path("/{name}") - @QueryParams(keys = "embed-detail", values = "true") - @XMLResponseParser(HostedServiceHandler.class) - @Fallback(NullOnNotFoundOr404.class) - @Nullable HostedService get(@PathParam("name") String name); - - /** - * The Delete Hosted Service operation deletes the specified hosted service from Windows Azure. - * - * @param name - * the unique DNS Prefix value in the Windows Azure Management Portal - * - * @return request id or null, if not found - */ - @Named("DeleteHostedService") - @DELETE - @Path("/{name}") - @Fallback(NullOnNotFoundOr404.class) - @ResponseParser(ParseRequestIdHeader.class) - String delete(@PathParam("name") String name); -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/features/ImageApi.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/features/ImageApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/features/ImageApi.java index 7ccad03..3ca54c3 100644 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/features/ImageApi.java +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/features/ImageApi.java @@ -56,7 +56,7 @@ import org.jclouds.rest.annotations.XMLResponseParser; public interface ImageApi { /** - * The List Hosted Services operation lists the hosted services available under the current + * The List Cloud Services operation lists the cloud services available under the current * subscription. */ @Named("ListImages") @@ -87,7 +87,7 @@ public interface ImageApi { @BinderParam(ImageParamsToXML.class) ImageParams params); /** - * The Delete Hosted Service operation deletes the specified hosted service from Windows Azure. + * The Delete Cloud Service operation deletes the specified cloud service from Windows Azure. * * @param imageName * the unique DNS Prefix value in the Windows Azure Management Portal http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/features/LocationApi.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/features/LocationApi.java b/azurecompute/src/main/java/org/jclouds/azurecompute/features/LocationApi.java index 1621139..2a77e68 100644 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/features/LocationApi.java +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/features/LocationApi.java @@ -32,7 +32,7 @@ import static org.jclouds.Fallbacks.EmptyListOnNotFoundOr404; /** * The Service Management API includes operations for listing the available data center locations - * for a hosted service in your subscription. + * for a cloud service in your subscription. * <p/> * * @see <a href="http://msdn.microsoft.com/en-us/library/gg441299" /> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java new file mode 100644 index 0000000..f7e1833 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/CloudServiceHandler.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.xml; + +import static com.google.common.base.CaseFormat.UPPER_CAMEL; +import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; +import static com.google.common.base.Charsets.UTF_8; +import static com.google.common.io.BaseEncoding.base64; +import static org.jclouds.util.SaxUtils.currentOrNull; + +import java.util.Date; +import java.util.Map; + +import javax.inject.Inject; + +import org.jclouds.azurecompute.domain.CloudService; +import org.jclouds.date.DateService; +import org.jclouds.http.functions.ParseSax; +import org.xml.sax.Attributes; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; + +/** + * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >Response body description</a> + */ +public final class CloudServiceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<CloudService> { + private String name; + private String location; + private String affinityGroup; + private String label; + private String description; + private CloudService.Status status; + private Date created; + private Date lastModified; + private Map<String, String> extendedProperties = Maps.newLinkedHashMap(); + + private boolean inHostedServiceProperties; + private String propertyName; + private StringBuilder currentText = new StringBuilder(); + private final DateService dateService; + + @Inject CloudServiceHandler(DateService dateService) { + this.dateService = dateService; + } + + @Override public CloudService getResult() { + CloudService result = CloudService.create(name, location, affinityGroup, label, description, status, created, // + lastModified, ImmutableMap.copyOf(extendedProperties)); + resetState(); // handler is called in a loop. + return result; + } + + private void resetState() { + name = description = location = affinityGroup = label = null; + status = null; + created = lastModified = null; + extendedProperties.clear(); + inHostedServiceProperties = false; + propertyName = null; + } + + @Override public void startElement(String ignoredUri, String ignoredLocalName, String qName, Attributes ignoredAttributes) { + if (qName.equals("HostedServiceProperties")) { + inHostedServiceProperties = true; + } + } + + @Override public void endElement(String ignoredUri, String ignoredName, String qName) { + if (qName.equals("HostedServiceProperties")) { + inHostedServiceProperties = false; + } else if (inHostedServiceProperties) { + if (qName.equals("DateCreated")) { + created = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); + } else if (qName.equals("DateLastModified")) { + lastModified = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); + } else if (qName.equals("Status")) { + String statusText = currentOrNull(currentText); + if (statusText != null) { + status = status(statusText); + } + } else if (qName.equals("Name")) { + propertyName = currentOrNull(currentText); + } else if (qName.equals("Value")) { + extendedProperties.put(propertyName, currentOrNull(currentText)); + propertyName = null; + } else if (qName.equals("Description")) { + description = currentOrNull(currentText); + } else if (qName.equals("Location")) { + location = currentOrNull(currentText); + } else if (qName.equals("AffinityGroup")) { + affinityGroup = currentOrNull(currentText); + } else if (qName.equals("Label")) { + label = new String(base64().decode(currentOrNull(currentText)), UTF_8); + } + } else if (qName.equals("ServiceName")) { + name = currentOrNull(currentText); + } + currentText.setLength(0); + } + + @Override public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + + private static CloudService.Status status(String status) { + try { + return CloudService.Status.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, status)); + } catch (IllegalArgumentException e) { + return CloudService.Status.UNRECOGNIZED; + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java deleted file mode 100644 index 6bbe403..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.azurecompute.xml; - -import static com.google.common.base.CaseFormat.UPPER_CAMEL; -import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; -import static com.google.common.base.Charsets.UTF_8; -import static com.google.common.io.BaseEncoding.base64; -import static org.jclouds.util.SaxUtils.currentOrNull; - -import java.util.Date; -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.azurecompute.domain.HostedService; -import org.jclouds.date.DateService; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >Response body description</a> - */ -public final class HostedServiceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<HostedService> { - private String name; - private String location; - private String affinityGroup; - private String label; - private String description; - private HostedService.Status status; - private Date created; - private Date lastModified; - private Map<String, String> extendedProperties = Maps.newLinkedHashMap(); - - private boolean inHostedServiceProperties; - private String propertyName; - private StringBuilder currentText = new StringBuilder(); - private final DateService dateService; - - @Inject HostedServiceHandler(DateService dateService) { - this.dateService = dateService; - } - - @Override public HostedService getResult() { - HostedService result = HostedService.create(name, location, affinityGroup, label, description, status, created, // - lastModified, ImmutableMap.copyOf(extendedProperties)); - resetState(); // handler is called in a loop. - return result; - } - - private void resetState() { - name = description = location = affinityGroup = label = null; - status = null; - created = lastModified = null; - extendedProperties.clear(); - inHostedServiceProperties = false; - propertyName = null; - } - - @Override public void startElement(String ignoredUri, String ignoredLocalName, String qName, Attributes ignoredAttributes) { - if (qName.equals("HostedServiceProperties")) { - inHostedServiceProperties = true; - } - } - - @Override public void endElement(String ignoredUri, String ignoredName, String qName) { - if (qName.equals("HostedServiceProperties")) { - inHostedServiceProperties = false; - } else if (inHostedServiceProperties) { - if (qName.equals("DateCreated")) { - created = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("DateLastModified")) { - lastModified = dateService.iso8601SecondsDateParse(currentOrNull(currentText)); - } else if (qName.equals("Status")) { - String statusText = currentOrNull(currentText); - if (statusText != null) { - status = status(statusText); - } - } else if (qName.equals("Name")) { - propertyName = currentOrNull(currentText); - } else if (qName.equals("Value")) { - extendedProperties.put(propertyName, currentOrNull(currentText)); - propertyName = null; - } else if (qName.equals("Description")) { - description = currentOrNull(currentText); - } else if (qName.equals("Location")) { - location = currentOrNull(currentText); - } else if (qName.equals("AffinityGroup")) { - affinityGroup = currentOrNull(currentText); - } else if (qName.equals("Label")) { - label = new String(base64().decode(currentOrNull(currentText)), UTF_8); - } - } else if (qName.equals("ServiceName")) { - name = currentOrNull(currentText); - } - currentText.setLength(0); - } - - @Override public void characters(char ch[], int start, int length) { - currentText.append(ch, start, length); - } - - private static HostedService.Status status(String status) { - try { - return HostedService.Status.valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, status)); - } catch (IllegalArgumentException e) { - return HostedService.Status.UNRECOGNIZED; - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java new file mode 100644 index 0000000..48152d7 --- /dev/null +++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListCloudServicesHandler.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.xml; + +import java.util.List; + +import javax.inject.Inject; + +import org.jclouds.azurecompute.domain.CloudService; +import org.jclouds.http.functions.ParseSax; +import org.xml.sax.Attributes; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; + +/** + * @see <a href="http://msdn.microsoft.com/en-us/library/ee460781">Response body description</a> + */ +public final class ListCloudServicesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<CloudService>> { + private boolean inHostedService; + private final CloudServiceHandler cloudServiceHandler; + private final Builder<CloudService> hostedServices = ImmutableList.builder(); + + @Inject ListCloudServicesHandler(CloudServiceHandler cloudServiceHandler) { + this.cloudServiceHandler = cloudServiceHandler; + } + + @Override public List<CloudService> getResult() { + return hostedServices.build(); + } + + @Override public void startElement(String url, String name, String qName, Attributes attributes) { + if (qName.equals("HostedService")) { + inHostedService = true; + } + if (inHostedService) { + cloudServiceHandler.startElement(url, name, qName, attributes); + } + } + + @Override public void endElement(String uri, String name, String qName) { + if (qName.equals("HostedService")) { + inHostedService = false; + hostedServices.add(cloudServiceHandler.getResult()); + } else if (inHostedService) { + cloudServiceHandler.endElement(uri, name, qName); + } + } + + @Override public void characters(char ch[], int start, int length) { + if (inHostedService) { + cloudServiceHandler.characters(ch, start, length); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java deleted file mode 100644 index 15bb5b2..0000000 --- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.azurecompute.xml; - -import java.util.List; - -import javax.inject.Inject; - -import org.jclouds.azurecompute.domain.HostedService; -import org.jclouds.http.functions.ParseSax; -import org.xml.sax.Attributes; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; - -/** - * @see <a href="http://msdn.microsoft.com/en-us/library/ee460781">Response body description</a> - */ -public final class ListHostedServicesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<HostedService>> { - private boolean inHostedService; - private final HostedServiceHandler hostedServiceHandler; - private final Builder<HostedService> hostedServices = ImmutableList.builder(); - - @Inject ListHostedServicesHandler(HostedServiceHandler hostedServiceHandler) { - this.hostedServiceHandler = hostedServiceHandler; - } - - @Override public List<HostedService> getResult() { - return hostedServices.build(); - } - - @Override public void startElement(String url, String name, String qName, Attributes attributes) { - if (qName.equals("HostedService")) { - inHostedService = true; - } - if (inHostedService) { - hostedServiceHandler.startElement(url, name, qName, attributes); - } - } - - @Override public void endElement(String uri, String name, String qName) { - if (qName.equals("HostedService")) { - inHostedService = false; - hostedServices.add(hostedServiceHandler.getResult()); - } else if (inHostedService) { - hostedServiceHandler.endElement(uri, name, qName); - } - } - - @Override public void characters(char ch[], int start, int length) { - if (inHostedService) { - hostedServiceHandler.characters(ch, start, length); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java new file mode 100644 index 0000000..fb0e915 --- /dev/null +++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiLiveTest.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.features; + +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.jclouds.azurecompute.domain.CloudService.Status.UNRECOGNIZED; +import static org.jclouds.util.Predicates2.retry; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +import java.util.List; +import java.util.logging.Logger; + +import org.jclouds.azurecompute.domain.CloudService; +import org.jclouds.azurecompute.domain.CloudService.Status; +import org.jclouds.azurecompute.domain.Operation; +import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; + +@Test(groups = "live", testName = "CloudServiceApiLiveTest") +public class CloudServiceApiLiveTest extends BaseAzureComputeApiLiveTest { + + public static final String CLOUD_SERVICE = (System.getProperty("user.name") + "-jclouds-cloudService").toLowerCase(); + + private Predicate<String> operationSucceeded; + private Predicate<CloudService> cloudServiceCreated; + private Predicate<CloudService> cloudServiceGone; + + private String location; + + @BeforeClass(groups = { "integration", "live" }) + public void setup() { + super.setup(); + // TODO: filter locations on those who have compute + location = Iterables.get(api.getLocationApi().list(), 0).name(); + operationSucceeded = retry(new Predicate<String>() { + public boolean apply(String input) { + return api.getOperationApi().get(input).status() == Operation.Status.SUCCEEDED; + } + }, 600, 5, 5, SECONDS); + cloudServiceCreated = retry(new Predicate<CloudService>() { + public boolean apply(CloudService input) { + return api().get(input.name()).status() == Status.CREATED; + } + }, 600, 5, 5, SECONDS); + cloudServiceGone = retry(new Predicate<CloudService>() { + public boolean apply(CloudService input) { + return api().get(input.name()) == null; + } + }, 600, 5, 5, SECONDS); + } + + private CloudService cloudService; + + public void testCreate() { + + String requestId = api().createWithLabelInLocation(CLOUD_SERVICE, CLOUD_SERVICE, location); + assertTrue(operationSucceeded.apply(requestId), requestId); + Logger.getAnonymousLogger().info("operation succeeded: " + requestId); + + cloudService = api().get(CLOUD_SERVICE); + Logger.getAnonymousLogger().info("created cloudService: " + cloudService); + + assertEquals(cloudService.name(), CLOUD_SERVICE); + + checkHostedService(cloudService); + + assertTrue(cloudServiceCreated.apply(cloudService), cloudService.toString()); + cloudService = api().get(cloudService.name()); + Logger.getAnonymousLogger().info("cloudService available: " + cloudService); + + } + + @Test(dependsOnMethods = "testCreate") + public void testDelete() { + String requestId = api().delete(cloudService.name()); + assertTrue(operationSucceeded.apply(requestId), requestId); + Logger.getAnonymousLogger().info("operation succeeded: " + requestId); + + assertTrue(cloudServiceGone.apply(cloudService), cloudService.toString()); + Logger.getAnonymousLogger().info("cloudService deleted: " + cloudService); + } + + @Override @AfterClass(groups = "live") + protected void tearDown() { + String requestId = api().delete(CLOUD_SERVICE); + if (requestId != null) { + operationSucceeded.apply(requestId); + } + + super.tearDown(); + } + + public void testList() { + List<CloudService> response = api().list(); + + for (CloudService cloudService : response) { + checkHostedService(cloudService); + } + + if (!response.isEmpty()) { + CloudService cloudService = response.iterator().next(); + assertEquals(api().get(cloudService.name()), cloudService); + } + } + + private void checkHostedService(CloudService cloudService) { + assertNotNull(cloudService.name(), "ServiceName cannot be null for " + cloudService); + assertTrue(cloudService.location() != null || cloudService.affinityGroup() != null, + "Location or AffinityGroup must be present for " + cloudService); + assertNotNull(cloudService.label(), "Label cannot be null for " + cloudService); + assertNotNull(cloudService.status(), "Status cannot be null for " + cloudService); + assertNotEquals(cloudService.status(), UNRECOGNIZED, "Status cannot be UNRECOGNIZED for " + cloudService); + assertNotNull(cloudService.created(), "Created cannot be null for " + cloudService); + assertNotNull(cloudService.lastModified(), "LastModified cannot be null for " + cloudService); + assertNotNull(cloudService.extendedProperties(), "ExtendedProperties cannot be null for " + cloudService); + } + + private CloudServiceApi api() { + return api.getCloudServiceApi(); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java new file mode 100644 index 0000000..a929fff --- /dev/null +++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/CloudServiceApiMockTest.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; +import org.jclouds.azurecompute.xml.CloudServiceHandlerTest; +import org.jclouds.azurecompute.xml.ListCloudServicesHandlerTest; +import org.testng.annotations.Test; + +import com.squareup.okhttp.mockwebserver.MockResponse; +import com.squareup.okhttp.mockwebserver.MockWebServer; + +@Test(groups = "unit", testName = "CloudServiceApiMockTest") +public class CloudServiceApiMockTest extends BaseAzureComputeApiMockTest { + + public void listWhenFound() throws Exception { + MockWebServer server = mockAzureManagementServer(); + server.enqueue(xmlResponse("/hostedservices.xml")); + + try { + CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); + + assertEquals(api.list(), ListCloudServicesHandlerTest.expected()); + + assertSent(server, "GET", "/services/hostedservices?embed-detail=true"); + } finally { + server.shutdown(); + } + } + + public void listWhenNotFound() throws Exception { + MockWebServer server = mockAzureManagementServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + try { + CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); + + assertTrue(api.list().isEmpty()); + + assertSent(server, "GET", "/services/hostedservices?embed-detail=true"); + } finally { + server.shutdown(); + } + } + + public void getWhenFound() throws Exception { + MockWebServer server = mockAzureManagementServer(); + server.enqueue(xmlResponse("/hostedservice.xml")); + + try { + CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); + + assertEquals(api.get("myservice"), CloudServiceHandlerTest.expected()); + + assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); + } finally { + server.shutdown(); + } + } + + public void getWhenNotFound() throws Exception { + MockWebServer server = mockAzureManagementServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + try { + CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); + + assertNull(api.get("myservice")); + + assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); + } finally { + server.shutdown(); + } + } + + public void createWithLabelInLocation() throws Exception { + MockWebServer server = mockAzureManagementServer(); + server.enqueue(requestIdResponse("request-1")); + + try { + CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); + + assertEquals(api.createWithLabelInLocation("myservice", "service mine", "West US"), "request-1"); + + assertSent(server, "POST", "/services/hostedservices", "/create_hostedservice_location.xml"); + } finally { + server.shutdown(); + } + } + + public void deleteWhenFound() throws Exception { + MockWebServer server = mockAzureManagementServer(); + server.enqueue(requestIdResponse("request-1")); + + try { + CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); + + assertEquals(api.delete("myservice"), "request-1"); + + assertSent(server, "DELETE", "/services/hostedservices/myservice"); + } finally { + server.shutdown(); + } + } + + public void deleteWhenNotFound() throws Exception { + MockWebServer server = mockAzureManagementServer(); + server.enqueue(new MockResponse().setResponseCode(404)); + + try { + CloudServiceApi api = api(server.getUrl("/")).getCloudServiceApi(); + + assertNull(api.delete("myservice")); + + assertSent(server, "DELETE", "/services/hostedservices/myservice"); + } finally { + server.shutdown(); + } + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java deleted file mode 100644 index 08f53b4..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.azurecompute.features; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.jclouds.azurecompute.domain.HostedService.Status.UNRECOGNIZED; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.List; -import java.util.logging.Logger; - -import org.jclouds.azurecompute.domain.HostedService; -import org.jclouds.azurecompute.domain.HostedService.Status; -import org.jclouds.azurecompute.domain.Operation; -import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -@Test(groups = "live", testName = "HostedServiceApiLiveTest") -public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest { - - public static final String HOSTED_SERVICE = (System.getProperty("user.name") + "-jclouds-hostedService") - .toLowerCase(); - - private Predicate<String> operationSucceeded; - private Predicate<HostedService> hostedServiceCreated; - private Predicate<HostedService> hostedServiceGone; - - private String location; - - @BeforeClass(groups = { "integration", "live" }) - public void setup() { - super.setup(); - // TODO: filter locations on those who have compute - location = Iterables.get(api.getLocationApi().list(), 0).name(); - operationSucceeded = retry(new Predicate<String>() { - public boolean apply(String input) { - return api.getOperationApi().get(input).status() == Operation.Status.SUCCEEDED; - } - }, 600, 5, 5, SECONDS); - hostedServiceCreated = retry(new Predicate<HostedService>() { - public boolean apply(HostedService input) { - return api().get(input.name()).status() == Status.CREATED; - } - }, 600, 5, 5, SECONDS); - hostedServiceGone = retry(new Predicate<HostedService>() { - public boolean apply(HostedService input) { - return api().get(input.name()) == null; - } - }, 600, 5, 5, SECONDS); - } - - private HostedService hostedService; - - public void testCreateHostedService() { - - String requestId = api().createWithLabelInLocation(HOSTED_SERVICE, HOSTED_SERVICE, location); - assertTrue(operationSucceeded.apply(requestId), requestId); - Logger.getAnonymousLogger().info("operation succeeded: " + requestId); - - hostedService = api().get(HOSTED_SERVICE); - Logger.getAnonymousLogger().info("created hostedService: " + hostedService); - - assertEquals(hostedService.name(), HOSTED_SERVICE); - - checkHostedService(hostedService); - - assertTrue(hostedServiceCreated.apply(hostedService), hostedService.toString()); - hostedService = api().get(hostedService.name()); - Logger.getAnonymousLogger().info("hostedService available: " + hostedService); - - } - - @Test(dependsOnMethods = "testCreateHostedService") - public void testDeleteHostedService() { - String requestId = api().delete(hostedService.name()); - assertTrue(operationSucceeded.apply(requestId), requestId); - Logger.getAnonymousLogger().info("operation succeeded: " + requestId); - - assertTrue(hostedServiceGone.apply(hostedService), hostedService.toString()); - Logger.getAnonymousLogger().info("hostedService deleted: " + hostedService); - } - - @Override @AfterClass(groups = "live") - protected void tearDown() { - String requestId = api().delete(HOSTED_SERVICE); - if (requestId != null) { - operationSucceeded.apply(requestId); - } - - super.tearDown(); - } - - @Test - protected void testList() { - List<HostedService> response = api().list(); - - for (HostedService hostedService : api().list()) { - checkHostedService(hostedService); - } - - if (response.size() > 0) { - HostedService hostedService = response.iterator().next(); - assertEquals(api().get(hostedService.name()), hostedService); - } - } - - private void checkHostedService(HostedService hostedService) { - assertNotNull(hostedService.name(), "ServiceName cannot be null for " + hostedService); - assertTrue(hostedService.location() != null || hostedService.affinityGroup() != null, - "Location or AffinityGroup must be present for " + hostedService); - assertNotNull(hostedService.label(), "Label cannot be null for " + hostedService); - assertNotNull(hostedService.status(), "Status cannot be null for " + hostedService); - assertNotEquals(hostedService.status(), UNRECOGNIZED, "Status cannot be UNRECOGNIZED for " + hostedService); - assertNotNull(hostedService.created(), "Created cannot be null for " + hostedService); - assertNotNull(hostedService.lastModified(), "LastModified cannot be null for " + hostedService); - assertNotNull(hostedService.extendedProperties(), "ExtendedProperties cannot be null for " + hostedService); - } - - private HostedServiceApi api() { - return api.getHostedServiceApi(); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java deleted file mode 100644 index 9d0cf80..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.azurecompute.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest; -import org.jclouds.azurecompute.xml.HostedServiceHandlerTest; -import org.jclouds.azurecompute.xml.ListHostedServicesHandlerTest; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -@Test(groups = "unit", testName = "HostedServiceApiMockTest") -public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest { - - public void listWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/hostedservices.xml")); - - try { - HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi(); - - assertEquals(api.list(), ListHostedServicesHandlerTest.expected()); - - assertSent(server, "GET", "/services/hostedservices?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void listWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi(); - - assertTrue(api.list().isEmpty()); - - assertSent(server, "GET", "/services/hostedservices?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void getWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(xmlResponse("/hostedservice.xml")); - - try { - HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi(); - - assertEquals(api.get("myservice"), HostedServiceHandlerTest.expected()); - - assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void getWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi(); - - assertNull(api.get("myservice")); - - assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true"); - } finally { - server.shutdown(); - } - } - - public void createWithLabelInLocation() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi(); - - assertEquals(api.createWithLabelInLocation("myservice", "service mine", "West US"), "request-1"); - - assertSent(server, "POST", "/services/hostedservices", "/create_hostedservice_location.xml"); - } finally { - server.shutdown(); - } - } - - public void deleteWhenFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(requestIdResponse("request-1")); - - try { - HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi(); - - assertEquals(api.delete("myservice"), "request-1"); - - assertSent(server, "DELETE", "/services/hostedservices/myservice"); - } finally { - server.shutdown(); - } - } - - public void deleteWhenNotFound() throws Exception { - MockWebServer server = mockAzureManagementServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - try { - HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi(); - - assertNull(api.delete("myservice")); - - assertSent(server, "DELETE", "/services/hostedservices/myservice"); - } finally { - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java new file mode 100644 index 0000000..5a71396 --- /dev/null +++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/CloudServiceHandlerTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.util.Collections; + +import org.jclouds.azurecompute.domain.CloudService; +import org.jclouds.azurecompute.domain.CloudService.Status; +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.functions.BaseHandlerTest; +import org.testng.annotations.Test; + +@Test(groups = "unit", testName = "HostedServiceHandlerTest") +public class CloudServiceHandlerTest extends BaseHandlerTest { + private static final DateService DATE_SERVICE = new SimpleDateFormatDateService(); + + public void test() { + InputStream is = getClass().getResourceAsStream("/hostedservice.xml"); + CloudService result = factory.create(new CloudServiceHandler(DATE_SERVICE)).parse(is); + + assertEquals(result, expected()); + } + + public static CloudService expected() { + return CloudService.create( // + "neotys", // name + "West Europe", // location + null, // affinityGroup + "neotys", // label + "Implicitly created cloud service2012-08-06 14:55", // description + Status.CREATED, // status + DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T14:55:17Z"), // created + DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T15:50:34Z"), // lastModified + Collections.<String, String>emptyMap() // extendedProperties + ); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java deleted file mode 100644 index aefdca4..0000000 --- a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.azurecompute.xml; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.util.Collections; - -import org.jclouds.azurecompute.domain.HostedService; -import org.jclouds.azurecompute.domain.HostedService.Status; -import org.jclouds.date.DateService; -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.jclouds.http.functions.BaseHandlerTest; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "HostedServiceHandlerTest") -public class HostedServiceHandlerTest extends BaseHandlerTest { - private static final DateService DATE_SERVICE = new SimpleDateFormatDateService(); - - public void test() { - InputStream is = getClass().getResourceAsStream("/hostedservice.xml"); - HostedService result = factory.create(new HostedServiceHandler(DATE_SERVICE)).parse(is); - - assertEquals(result, expected()); - } - - public static HostedService expected() { - return HostedService.create( // - "neotys", // name - "West Europe", // location - null, // affinityGroup - "neotys", // label - "Implicitly created hosted service2012-08-06 14:55", // description - Status.CREATED, // status - DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T14:55:17Z"), // created - DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T15:50:34Z"), // lastModified - Collections.<String, String>emptyMap() // extendedProperties - ); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1f907d2a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListCloudServicesHandlerTest.java ---------------------------------------------------------------------- diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListCloudServicesHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListCloudServicesHandlerTest.java new file mode 100644 index 0000000..1a99c06 --- /dev/null +++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListCloudServicesHandlerTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.azurecompute.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.util.Collections; +import java.util.List; + +import org.jclouds.azurecompute.domain.CloudService; +import org.jclouds.azurecompute.domain.CloudService.Status; +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.http.functions.BaseHandlerTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; + +@Test(groups = "unit", testName = "ListHostedServicesHandlerTest") +public class ListCloudServicesHandlerTest extends BaseHandlerTest { + private static final DateService DATE_SERVICE = new SimpleDateFormatDateService(); + + public void test() { + InputStream is = getClass().getResourceAsStream("/hostedservices.xml"); + ListCloudServicesHandler handler = new ListCloudServicesHandler(new CloudServiceHandler(DATE_SERVICE)); + List<CloudService> result = factory.create(handler).parse(is); + + assertEquals(result, expected()); + } + + public static List<CloudService> expected() { + return ImmutableList.of( // + CloudService.create( // + "neotys", // name + "West Europe", // location + null, // affinityGroup + "neotys", // label + "Implicitly created cloud service2012-08-06 14:55", // description + Status.CREATED, // status + DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T14:55:17Z"), // created + DATE_SERVICE.iso8601SecondsDateParse("2012-08-06T15:50:34Z"), // lastModified + Collections.<String, String>emptyMap() // extendedProperties + ), // + CloudService.create( // + "neotys3", // name + "West Europe", // location + null, // affinityGroup + "neotys3", // label + null, // description + Status.CREATED, // status + DATE_SERVICE.iso8601SecondsDateParse("2012-08-07T09:00:02Z"), // created + DATE_SERVICE.iso8601SecondsDateParse("2012-08-07T09:00:02Z"), // lastModified + Collections.<String, String>emptyMap() // extendedProperties + )); + } +}
