You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/10/24 18:08:40 UTC
[06/21] git commit: Cleanup output-only HostedService object.
Cleanup output-only HostedService object.
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/497c90b1
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/497c90b1
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/497c90b1
Branch: refs/heads/1.8.x
Commit: 497c90b164265e1a306a8e2b26be16b9d4d6be25
Parents: 867190e
Author: Adrian Cole <ac...@twitter.com>
Authored: Thu Oct 16 18:54:55 2014 -0700
Committer: Adrian Cole <ad...@apache.org>
Committed: Fri Oct 24 08:36:51 2014 -0700
----------------------------------------------------------------------
.../domain/DetailedHostedServiceProperties.java | 173 -------------
.../azurecompute/domain/HostedService.java | 241 +++++++++----------
.../domain/HostedServiceProperties.java | 169 -------------
.../HostedServiceWithDetailedProperties.java | 63 -----
.../azurecompute/features/HostedServiceApi.java | 40 ++-
.../DetailedHostedServicePropertiesHandler.java | 73 ------
.../azurecompute/xml/HostedServiceHandler.java | 126 ++++++----
.../xml/HostedServicePropertiesHandler.java | 64 -----
...tedServiceWithDetailedPropertiesHandler.java | 42 ----
.../xml/ListHostedServicesHandler.java | 43 ++--
.../features/HostedServiceApiLiveTest.java | 99 +++-----
.../features/HostedServiceApiMockTest.java | 74 ++----
.../parse/GetHostedServiceDetailsTest.java | 65 -----
.../parse/GetHostedServiceTest.java | 55 -----
.../parse/ListHostedServicesTest.java | 79 ------
.../xml/HostedServiceHandlerTest.java | 55 +++++
.../xml/ListHostedServicesHandlerTest.java | 71 ++++++
.../src/test/resources/hostedservice.xml | 9 +-
.../test/resources/hostedservice_details.xml | 13 -
.../src/test/resources/hostedservices.xml | 6 +-
20 files changed, 424 insertions(+), 1136 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java
deleted file mode 100644
index 76abdc5..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/DetailedHostedServiceProperties.java
+++ /dev/null
@@ -1,173 +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 com.google.common.base.Objects.ToStringHelper;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableMap;
-import java.util.Date;
-import java.util.Map;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-public class DetailedHostedServiceProperties extends HostedServiceProperties {
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromDetailedHostedServiceProperties(this);
- }
-
- public static class Builder extends HostedServiceProperties.Builder<Builder> {
-
- protected String rawStatus;
- protected Status status;
- protected Date created;
- protected Date lastModified;
- protected ImmutableMap.Builder<String, String> extendedProperties = ImmutableMap.<String, String>builder();
-
- /**
- * @see DetailedHostedServiceProperties#getRawStatus()
- */
- public Builder rawStatus(String rawStatus) {
- this.rawStatus = rawStatus;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getStatus()
- */
- public Builder status(Status status) {
- this.status = status;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getCreated()
- */
- public Builder created(Date created) {
- this.created = created;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getLastModified()
- */
- public Builder lastModified(Date lastModified) {
- this.lastModified = lastModified;
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getExtendedProperties()
- */
- public Builder extendedProperties(Map<String, String> extendedProperties) {
- this.extendedProperties.putAll(checkNotNull(extendedProperties, "extendedProperties"));
- return this;
- }
-
- /**
- * @see DetailedHostedServiceProperties#getExtendedProperties()
- */
- public Builder addExtendedProperty(String name, String value) {
- this.extendedProperties.put(checkNotNull(name, "name"), checkNotNull(value, "value"));
- return this;
- }
-
- @Override protected Builder self() {
- return this;
- }
-
- public DetailedHostedServiceProperties build() {
- return new DetailedHostedServiceProperties(description, location, affinityGroup, label, rawStatus, status,
- created, lastModified, extendedProperties.build());
- }
-
- public Builder fromDetailedHostedServiceProperties(DetailedHostedServiceProperties in) {
- return fromHostedServiceProperties(in).rawStatus(in.getRawStatus()).status(in.getStatus())
- .created(in.getCreated()).lastModified(in.getLastModified())
- .extendedProperties(in.getExtendedProperties());
- }
- }
-
- protected final String rawStatus;
- protected final Status status;
- protected final Date created;
- protected final Date lastModified;
- protected final Map<String, String> extendedProperties;
-
- protected DetailedHostedServiceProperties(Optional<String> description, Optional<String> location,
- Optional<String> affinityGroup, String label, String rawStatus, Status status, Date created, Date lastModified,
- Map<String, String> extendedProperties) {
- super(description, location, affinityGroup, label);
- this.rawStatus = checkNotNull(rawStatus, "rawStatus of %s", description);
- this.status = checkNotNull(status, "status of %s", description);
- this.created = checkNotNull(created, "created of %s", description);
- this.lastModified = checkNotNull(lastModified, "lastModified of %s", description);
- this.extendedProperties = ImmutableMap
- .copyOf(checkNotNull(extendedProperties, "extendedProperties of %s", description));
- }
-
- /**
- * The status of the hosted service.
- */
- public Status getStatus() {
- return status;
- }
-
- /**
- * The status of the hosted service unparsed.
- */
- public String getRawStatus() {
- return rawStatus;
- }
-
- /**
- * The date that the hosted service was created.
- */
- public Date getCreated() {
- return created;
- }
-
- /**
- * The date that the hosted service was last updated.
- */
- public Date getLastModified() {
- 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.
- *
- * 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> getExtendedProperties() {
- return extendedProperties;
- }
-
- @Override
- public ToStringHelper string() {
- return super.string().add("status", rawStatus).add("created", created).add("lastModified", lastModified)
- .add("extendedProperties", extendedProperties);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/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
index a0d1a32..6ef400b 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedService.java
@@ -16,168 +16,163 @@
*/
package org.jclouds.azurecompute.domain;
-import com.google.common.base.CaseFormat;
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
-import java.net.URI;
-
+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
+ * 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 class HostedService {
- public static enum Status {
-
- CREATING,
-
- CREATED,
-
- DELETING,
-
- DELETED,
-
- CHANGING,
-
- RESOLVING_DNS,
-
+public final class HostedService {
+ public enum Status {
+ CREATING, CREATED, DELETING, DELETED, CHANGING, RESOLVING_DNS,
UNRECOGNIZED;
-
- public String value() {
- return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
- }
-
- @Override
- public String toString() {
- return value();
- }
-
- public static Status fromValue(String status) {
- try {
- return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(status, "status")));
- } catch (IllegalArgumentException e) {
- return UNRECOGNIZED;
- }
- }
}
- public static Builder<?> builder() {
- return new ConcreteBuilder();
+ /**
+ * 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;
}
- public Builder<?> toBuilder() {
- return new ConcreteBuilder().fromHostedService(this);
+ /**
+ * 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;
}
- public abstract static class Builder<T extends Builder<T>> {
- protected abstract T self();
-
- protected URI url;
- protected String name;
- protected HostedServiceProperties properties;
-
- /**
- * @see HostedService#getUrl()
- */
- public T url(URI url) {
- this.url = url;
- return self();
- }
-
- /**
- * @see HostedService#getName()
- */
- public T name(String name) {
- this.name = name;
- return self();
- }
-
- /**
- * @see HostedService#getProperties()
- */
- public T properties(HostedServiceProperties properties) {
- this.properties = properties;
- return self();
- }
-
- public HostedService build() {
- return new HostedService(url, name, properties);
- }
+ /**
+ * 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;
+ }
- public T fromHostedService(HostedService in) {
- return this.url(in.getUrl()).name(in.getName()).properties(in.getProperties());
- }
+ /**
+ * 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;
}
- private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
- @Override
- protected ConcreteBuilder self() {
- return this;
- }
+ @Nullable public String description() {
+ return description;
}
- protected final URI url;
- protected final String name;
- protected final HostedServiceProperties properties;
+ public Status status() {
+ return status;
+ }
- protected HostedService(URI url, String name, HostedServiceProperties properties) {
- this.url = checkNotNull(url, "url");
- this.name = checkNotNull(name, "name");
- this.properties = checkNotNull(properties, "properties");
+ public Date created() {
+ return created;
}
- /**
- * The Service Management API request URI used to perform Get Hosted Service Properties requests
- * against the hosted service.
- */
- public URI getUrl() {
- return url;
+ public Date lastModified() {
+ return lastModified;
}
/**
- * The name of the hosted service. This name is the DNS prefix name and can be used to access the
- * hosted service.
+ * 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.
*
- * For example, if the service name is MyService you could access the access the service by
- * calling: http://MyService.cloudapp.net
+ * <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 String getName() {
- return name;
+ public Map<String, String> extendedProperties() {
+ return extendedProperties;
}
- /**
- * Provides the url of the database properties to be used for this DB HostedService.
- */
- public HostedServiceProperties getProperties() {
- return properties;
+ 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);
}
- @Override
- public int hashCode() {
- return Objects.hashCode(url);
+ // 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 obj) {
- if (this == obj)
+ public boolean equals(Object object) {
+ if (this == object) {
return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
+ }
+ 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;
- HostedService other = (HostedService) obj;
- return Objects.equal(this.url, other.url);
+ }
}
@Override
- public String toString() {
- return string().toString();
+ public int hashCode() {
+ return Objects.hashCode(name, location, affinityGroup, label, description, status, created, lastModified,
+ extendedProperties);
}
- protected ToStringHelper string() {
- return Objects.toStringHelper(this).omitNullValues().add("url", url).add("name", name)
- .add("properties", properties);
+ @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/497c90b1/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java
deleted file mode 100644
index 4d539ed..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceProperties.java
+++ /dev/null
@@ -1,169 +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 com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
-import com.google.common.base.Optional;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-/**
- * 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 class HostedServiceProperties {
- public static Builder<?> builder() {
- return new ConcreteBuilder();
- }
-
- public Builder<?> toBuilder() {
- return new ConcreteBuilder().fromHostedServiceProperties(this);
- }
-
- public abstract static class Builder<T extends Builder<T>> {
- protected abstract T self();
-
- protected Optional<String> description = Optional.absent();
- protected Optional<String> location = Optional.absent();
- protected Optional<String> affinityGroup = Optional.absent();
- protected String label;
-
- /**
- * @see HostedServiceProperties#getDescription()
- */
- public T description(String description) {
- this.description = Optional.fromNullable(description);
- return self();
- }
-
- /**
- * @see HostedServiceProperties#getLocation()
- */
- public T location(String location) {
- this.location = Optional.fromNullable(location);
- return self();
- }
-
- /**
- * @see HostedServiceProperties#getAffinityGroup()
- */
- public T affinityGroup(String affinityGroup) {
- this.affinityGroup = Optional.fromNullable(affinityGroup);
- return self();
- }
-
- /**
- * @see HostedServiceProperties#getLabel()
- */
- public T label(String label) {
- this.label = label;
- return self();
- }
-
- public HostedServiceProperties build() {
- return new HostedServiceProperties(description, location, affinityGroup, label);
- }
-
- public T fromHostedServiceProperties(HostedServiceProperties in) {
- return this.description(in.getDescription().orNull()).location(in.getLocation().orNull())
- .affinityGroup(in.getAffinityGroup().orNull()).label(in.getLabel());
- }
- }
-
- private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
- @Override
- protected ConcreteBuilder self() {
- return this;
- }
- }
-
- protected final Optional<String> description;
- protected final Optional<String> location;
- protected final Optional<String> affinityGroup;
- protected final String label;
-
- protected HostedServiceProperties(Optional<String> description, Optional<String> location,
- Optional<String> affinityGroup, String label) {
- this.description = checkNotNull(description, "description");
- this.location = checkNotNull(location, "location");
- this.affinityGroup = checkNotNull(affinityGroup, "affinityGroup");
- this.label = checkNotNull(label, "label");
- }
-
- /**
- * The description for the hosted service..
- */
- public Optional<String> getDescription() {
- return description;
- }
-
- /**
- * 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.
- */
- public Optional<String> getLocation() {
- 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.
- */
- public Optional<String> getAffinityGroup() {
- 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 getLabel() {
- return label;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(description, location, affinityGroup, label);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- HostedServiceProperties other = (HostedServiceProperties) obj;
- return Objects.equal(this.description, other.description) && Objects.equal(this.location, other.location)
- && Objects.equal(this.affinityGroup, other.affinityGroup) && Objects.equal(this.label, other.label);
- }
-
- @Override
- public String toString() {
- return string().toString();
- }
-
- protected ToStringHelper string() {
- return Objects.toStringHelper(this).omitNullValues().add("description", description.orNull())
- .add("location", location.orNull()).add("affinityGroup", affinityGroup.orNull()).add("label", label);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java
deleted file mode 100644
index 66c6640..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/HostedServiceWithDetailedProperties.java
+++ /dev/null
@@ -1,63 +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 java.net.URI;
-
-public class HostedServiceWithDetailedProperties extends HostedService {
-
- public static Builder builder() {
- return new Builder();
- }
-
- public Builder toBuilder() {
- return new Builder().fromHostedServiceWithDetailedProperties(this);
- }
-
- public static class Builder extends HostedService.Builder<Builder> {
-
- @Override
- public Builder properties(HostedServiceProperties properties) {
- this.properties = DetailedHostedServiceProperties.class.cast(properties);
- return this;
- }
-
- public HostedServiceWithDetailedProperties build() {
- return new HostedServiceWithDetailedProperties(url, name,
- DetailedHostedServiceProperties.class.cast(properties));
- }
-
- public Builder fromHostedServiceWithDetailedProperties(HostedServiceWithDetailedProperties in) {
- return fromHostedService(in);
- }
-
- @Override protected Builder self() {
- return this;
- }
- }
-
- protected HostedServiceWithDetailedProperties(URI url, String serviceName,
- DetailedHostedServiceProperties properties) {
- super(url, serviceName, properties);
- }
-
- @Override
- public DetailedHostedServiceProperties getProperties() {
- return DetailedHostedServiceProperties.class.cast(properties);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/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
index 9e6b9a2..bdfeda6 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/features/HostedServiceApi.java
@@ -16,7 +16,12 @@
*/
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;
@@ -25,15 +30,14 @@ import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
+
import org.jclouds.azurecompute.binders.BindCreateHostedServiceToXmlPayload;
import org.jclouds.azurecompute.domain.HostedService;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
import org.jclouds.azurecompute.functions.ParseRequestIdHeader;
import org.jclouds.azurecompute.options.CreateHostedServiceOptions;
import org.jclouds.azurecompute.xml.HostedServiceHandler;
-import org.jclouds.azurecompute.xml.HostedServiceWithDetailedPropertiesHandler;
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.MapBinder;
@@ -42,9 +46,6 @@ import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.XMLResponseParser;
-import static org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
-import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
-
/**
* The Service Management API includes operations for managing the hosted services beneath your
* subscription.
@@ -53,7 +54,7 @@ import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
*/
@Path("/services/hostedservices")
@Headers(keys = "x-ms-version", values = "{jclouds.api-version}")
-@Consumes(MediaType.APPLICATION_XML)
+@Consumes(APPLICATION_XML)
public interface HostedServiceApi {
/**
@@ -64,9 +65,10 @@ public interface HostedServiceApi {
*/
@Named("ListHostedServices")
@GET
+ @QueryParams(keys = "embed-detail", values = "true")
@XMLResponseParser(ListHostedServicesHandler.class)
@Fallback(EmptyListOnNotFoundOr404.class)
- List<HostedServiceWithDetailedProperties> list();
+ List<HostedService> list();
/**
* The Create Hosted Service operation creates a new hosted service in Windows Azure.
@@ -88,7 +90,7 @@ public interface HostedServiceApi {
@Named("CreateHostedService")
@POST
@MapBinder(BindCreateHostedServiceToXmlPayload.class)
- @Produces(MediaType.APPLICATION_XML)
+ @Produces(APPLICATION_XML)
@ResponseParser(ParseRequestIdHeader.class)
String createServiceWithLabelInLocation(@PayloadParam("name") String name,
@PayloadParam("label") String label, @PayloadParam("location") String location);
@@ -103,7 +105,7 @@ public interface HostedServiceApi {
@Named("CreateHostedService")
@POST
@MapBinder(BindCreateHostedServiceToXmlPayload.class)
- @Produces(MediaType.APPLICATION_XML)
+ @Produces(APPLICATION_XML)
@ResponseParser(ParseRequestIdHeader.class)
String createServiceWithLabelInLocation(@PayloadParam("name") String name,
@PayloadParam("label") String label, @PayloadParam("location") String location,
@@ -121,24 +123,10 @@ public interface HostedServiceApi {
@Named("GetHostedServiceProperties")
@GET
@Path("/{name}")
- @XMLResponseParser(HostedServiceHandler.class)
- @Fallback(NullOnNotFoundOr404.class)
- HostedService get(@PathParam("name") String name);
-
- /**
- * like {@link #get(String)}, except additional data such as status and deployment information is
- * returned.
- *
- * @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(HostedServiceWithDetailedPropertiesHandler.class)
+ @XMLResponseParser(HostedServiceHandler.class)
@Fallback(NullOnNotFoundOr404.class)
- HostedServiceWithDetailedProperties getDetails(@PathParam("name") String name);
+ @Nullable HostedService get(@PathParam("name") String name);
/**
* The Delete Hosted Service operation deletes the specified hosted service from Windows Azure.
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java
deleted file mode 100644
index ad77ab4..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/DetailedHostedServicePropertiesHandler.java
+++ /dev/null
@@ -1,73 +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 javax.inject.Inject;
-import org.jclouds.azurecompute.domain.DetailedHostedServiceProperties;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.date.DateService;
-import org.xml.sax.SAXException;
-
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
-
-/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a>
- */
-public class DetailedHostedServicePropertiesHandler extends HostedServicePropertiesHandler {
-
- private final DateService dateService;
-
- @Inject
- private DetailedHostedServicePropertiesHandler(DateService dateService) {
- this.dateService = dateService;
- }
-
- private DetailedHostedServiceProperties.Builder builder = DetailedHostedServiceProperties.builder();
-
- private String name;
-
- @Override
- public DetailedHostedServiceProperties getResult() {
- try {
- return builder.fromHostedServiceProperties(super.getResult()).build();
- } finally {
- builder = DetailedHostedServiceProperties.builder();
- }
- }
-
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
- if (equalsOrSuffix(qName, "DateCreated")) {
- builder.created(dateService.iso8601SecondsDateParse(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "DateLastModified")) {
- builder.lastModified(dateService.iso8601SecondsDateParse(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "Status")) {
- String rawStatus = currentOrNull(currentText);
- builder.rawStatus(rawStatus);
- builder.status(Status.fromValue(rawStatus));
- } else if (equalsOrSuffix(qName, "Name")) {
- this.name = currentOrNull(currentText);
- } else if (equalsOrSuffix(qName, "Value")) {
- builder.addExtendedProperty(this.name, currentOrNull(currentText));
- this.name = null;
- } else {
- super.endElement(uri, name, qName);
- }
- currentText = new StringBuilder();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/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
index 04f009a..5e3c3e9 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceHandler.java
@@ -16,78 +16,112 @@
*/
package org.jclouds.azurecompute.xml;
-import java.net.URI;
+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.azurecompute.domain.HostedService.Builder;
+import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a>
+ * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >Response body description</a>
*/
-public class HostedServiceHandler extends ParseSax.HandlerForGeneratedRequestWithResult<HostedService> {
-
- private final HostedServicePropertiesHandler hostedServicePropertiesHandler;
-
- @Inject protected HostedServiceHandler(HostedServicePropertiesHandler hostedServicePropertiesHandler) {
- this.hostedServicePropertiesHandler = hostedServicePropertiesHandler;
- }
+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();
- protected HostedService.Builder<?> builder = builder();
+ private final DateService dateService;
- protected Builder<?> builder() {
- return HostedService.builder();
+ @Inject HostedServiceHandler(DateService dateService) {
+ this.dateService = dateService;
}
- private boolean inHostedServiceProperties;
+ @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;
+ }
- @Override
- public HostedService getResult() {
- try {
- return builder.build();
- } finally {
- builder = builder();
- }
+ 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 url, String name, String qName, Attributes attributes) throws SAXException {
- if (equalsOrSuffix(qName, "HostedServiceProperties")) {
+ @Override public void startElement(String ignoredUri, String ignoredLocalName, String qName, Attributes ignoredAttributes) {
+ if (qName.equals("HostedServiceProperties")) {
inHostedServiceProperties = true;
}
- if (inHostedServiceProperties) {
- hostedServicePropertiesHandler.startElement(url, name, qName, attributes);
- }
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
-
- if (equalsOrSuffix(qName, "HostedServiceProperties")) {
- builder.properties(hostedServicePropertiesHandler.getResult());
+ @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
+ if (qName.equals("HostedServiceProperties")) {
inHostedServiceProperties = false;
} else if (inHostedServiceProperties) {
- hostedServicePropertiesHandler.endElement(uri, name, qName);
- } else if (equalsOrSuffix(qName, "Url")) {
- builder.url(URI.create(currentOrNull(currentText)));
- } else if (equalsOrSuffix(qName, "ServiceName")) {
- builder.name(currentOrNull(currentText));
+ 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 = new StringBuilder();
}
- @Override
- public void characters(char ch[], int start, int length) {
- if (inHostedServiceProperties) {
- hostedServicePropertiesHandler.characters(ch, start, length);
- } else {
- currentText.append(ch, start, length);
+ @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/497c90b1/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java
deleted file mode 100644
index d3962c5..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServicePropertiesHandler.java
+++ /dev/null
@@ -1,64 +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 org.jclouds.azurecompute.domain.HostedServiceProperties;
-import org.jclouds.http.functions.ParseSax;
-import org.xml.sax.SAXException;
-
-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 static org.jclouds.util.SaxUtils.equalsOrSuffix;
-
-/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/gg441293" >api</a>
- */
-public class HostedServicePropertiesHandler extends
- ParseSax.HandlerForGeneratedRequestWithResult<HostedServiceProperties> {
-
- protected StringBuilder currentText = new StringBuilder();
- private HostedServiceProperties.Builder<?> builder = HostedServiceProperties.builder();
-
- @Override
- public HostedServiceProperties getResult() {
- try {
- return builder.build();
- } finally {
- builder = HostedServiceProperties.builder();
- }
- }
-
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
- if (equalsOrSuffix(qName, "Description")) {
- builder.description(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Location")) {
- builder.location(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "AffinityGroup")) {
- builder.affinityGroup(currentOrNull(currentText));
- } else if (equalsOrSuffix(qName, "Label")) {
- builder.label(new String(base64().decode(currentOrNull(currentText)), UTF_8));
- }
- currentText = new StringBuilder();
- }
-
- @Override
- public void characters(char ch[], int start, int length) {
- currentText.append(ch, start, length);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java
deleted file mode 100644
index 69193b1..0000000
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/HostedServiceWithDetailedPropertiesHandler.java
+++ /dev/null
@@ -1,42 +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 javax.inject.Inject;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
-
-public class HostedServiceWithDetailedPropertiesHandler extends HostedServiceHandler {
-
- @Inject protected HostedServiceWithDetailedPropertiesHandler(
- DetailedHostedServicePropertiesHandler hostedServicePropertiesHandler) {
- super(hostedServicePropertiesHandler);
- }
-
- @Override
- protected HostedServiceWithDetailedProperties.Builder builder() {
- return HostedServiceWithDetailedProperties.builder();
- }
-
- @Override
- public HostedServiceWithDetailedProperties getResult() {
- try {
- return HostedServiceWithDetailedProperties.class.cast(builder.build());
- } finally {
- builder = builder();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/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
index 875e787..15bb5b2 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListHostedServicesHandler.java
@@ -16,42 +16,35 @@
*/
package org.jclouds.azurecompute.xml;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.inject.Inject;
import java.util.List;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
+
+import javax.inject.Inject;
+
+import org.jclouds.azurecompute.domain.HostedService;
import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
/**
- * @see <a href="http://msdn.microsoft.com/en-us/library/ee460781">doc</a>
+ * @see <a href="http://msdn.microsoft.com/en-us/library/ee460781">Response body description</a>
*/
-public class ListHostedServicesHandler extends
- ParseSax.HandlerForGeneratedRequestWithResult<List<HostedServiceWithDetailedProperties>> {
-
- private final HostedServiceWithDetailedPropertiesHandler hostedServiceHandler;
-
- private Builder<HostedServiceWithDetailedProperties> hostedServices = ImmutableList
- .<HostedServiceWithDetailedProperties> builder();
-
+public final class ListHostedServicesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<HostedService>> {
private boolean inHostedService;
+ private final HostedServiceHandler hostedServiceHandler;
+ private final Builder<HostedService> hostedServices = ImmutableList.builder();
- @Inject
- public ListHostedServicesHandler(HostedServiceWithDetailedPropertiesHandler hostedServiceHandler) {
+ @Inject ListHostedServicesHandler(HostedServiceHandler hostedServiceHandler) {
this.hostedServiceHandler = hostedServiceHandler;
}
- @Override
- public List<HostedServiceWithDetailedProperties> getResult() {
+ @Override public List<HostedService> getResult() {
return hostedServices.build();
}
- @Override
- public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
- if (SaxUtils.equalsOrSuffix(qName, "HostedService")) {
+ @Override public void startElement(String url, String name, String qName, Attributes attributes) {
+ if (qName.equals("HostedService")) {
inHostedService = true;
}
if (inHostedService) {
@@ -59,8 +52,7 @@ public class ListHostedServicesHandler extends
}
}
- @Override
- public void endElement(String uri, String name, String qName) throws SAXException {
+ @Override public void endElement(String uri, String name, String qName) {
if (qName.equals("HostedService")) {
inHostedService = false;
hostedServices.add(hostedServiceHandler.getResult());
@@ -69,8 +61,7 @@ public class ListHostedServicesHandler extends
}
}
- @Override
- public void characters(char ch[], int start, int length) {
+ @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/497c90b1/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
index 558689f..da816d3 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiLiveTest.java
@@ -16,37 +16,36 @@
*/
package org.jclouds.azurecompute.features;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
+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.DetailedHostedServiceProperties;
+
import org.jclouds.azurecompute.domain.HostedService;
import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
import org.jclouds.azurecompute.domain.Operation;
import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest;
-import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.jclouds.util.Predicates2.retry;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
+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();
+ .toLowerCase();
private Predicate<String> operationSucceeded;
- private Predicate<HostedServiceWithDetailedProperties> hostedServiceCreated;
+ private Predicate<HostedService> hostedServiceCreated;
private Predicate<HostedService> hostedServiceGone;
private String location;
@@ -61,19 +60,19 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
return api.getOperationApi().get(input).getStatus() == Operation.Status.SUCCEEDED;
}
}, 600, 5, 5, SECONDS);
- hostedServiceCreated = retry(new Predicate<HostedServiceWithDetailedProperties>() {
- public boolean apply(HostedServiceWithDetailedProperties input) {
- return api().getDetails(input.getName()).getProperties().getStatus() == Status.CREATED;
+ 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.getName()) == null;
+ return api().get(input.name()) == null;
}
}, 600, 5, 5, SECONDS);
}
- private HostedServiceWithDetailedProperties hostedService;
+ private HostedService hostedService;
public void testCreateHostedService() {
@@ -81,22 +80,22 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
assertTrue(operationSucceeded.apply(requestId), requestId);
Logger.getAnonymousLogger().info("operation succeeded: " + requestId);
- hostedService = api().getDetails(HOSTED_SERVICE);
+ hostedService = api().get(HOSTED_SERVICE);
Logger.getAnonymousLogger().info("created hostedService: " + hostedService);
- assertEquals(hostedService.getName(), HOSTED_SERVICE);
+ assertEquals(hostedService.name(), HOSTED_SERVICE);
checkHostedService(hostedService);
assertTrue(hostedServiceCreated.apply(hostedService), hostedService.toString());
- hostedService = api().getDetails(hostedService.getName());
+ hostedService = api().get(hostedService.name());
Logger.getAnonymousLogger().info("hostedService available: " + hostedService);
}
@Test(dependsOnMethods = "testCreateHostedService")
public void testDeleteHostedService() {
- String requestId = api().delete(hostedService.getName());
+ String requestId = api().delete(hostedService.name());
assertTrue(operationSucceeded.apply(requestId), requestId);
Logger.getAnonymousLogger().info("operation succeeded: " + requestId);
@@ -104,62 +103,40 @@ public class HostedServiceApiLiveTest extends BaseAzureComputeApiLiveTest {
Logger.getAnonymousLogger().info("hostedService deleted: " + hostedService);
}
- @Override
- @AfterClass(groups = "live")
+ @Override @AfterClass(groups = "live")
protected void tearDown() {
String requestId = api().delete(HOSTED_SERVICE);
- if (requestId != null)
+ if (requestId != null) {
operationSucceeded.apply(requestId);
+ }
super.tearDown();
}
@Test
protected void testList() {
- List<HostedServiceWithDetailedProperties> response = api().list();
+ List<HostedService> response = api().list();
- for (HostedServiceWithDetailedProperties hostedService : response) {
+ for (HostedService hostedService : api().list()) {
checkHostedService(hostedService);
}
if (response.size() > 0) {
HostedService hostedService = response.iterator().next();
- Assert.assertEquals(api().getDetails(hostedService.getName()), hostedService);
+ assertEquals(api().get(hostedService.name()), hostedService);
}
}
- private void checkHostedService(HostedServiceWithDetailedProperties hostedService) {
- checkNotNull(hostedService.getUrl(), "Url cannot be null for a HostedService.");
- checkNotNull(hostedService.getName(), "ServiceName cannot be null for HostedService %s", hostedService.getUrl());
- checkNotNull(hostedService.getProperties(), "Properties cannot be null for HostedService %s",
- hostedService.getUrl());
- checkProperties(hostedService.getProperties());
- }
-
- private void checkProperties(DetailedHostedServiceProperties hostedService) {
- checkNotNull(hostedService.getDescription(),
- "While Description can be null for DetailedHostedServiceProperties, its Optional wrapper cannot: %s",
- hostedService);
- checkNotNull(hostedService.getLocation(),
- "While Location can be null for DetailedHostedServiceProperties, its Optional wrapper cannot: %s",
- hostedService);
- checkNotNull(hostedService.getAffinityGroup(),
- "While AffinityGroup can be null for DetailedHostedServiceProperties, its Optional wrapper cannot: %s",
- hostedService);
- checkState(hostedService.getLocation().isPresent() || hostedService.getAffinityGroup().isPresent(),
- "Location or AffinityGroup must be present for DetailedHostedServiceProperties: %s", hostedService);
- checkNotNull(hostedService.getLabel(), "Label cannot be null for HostedService %s", hostedService);
-
- checkNotNull(hostedService.getStatus(), "Status cannot be null for DetailedHostedServiceProperties: %s",
- hostedService);
- assertNotEquals(hostedService.getStatus(), Status.UNRECOGNIZED,
- "Status cannot be UNRECOGNIZED for DetailedHostedServiceProperties: " + hostedService);
- checkNotNull(hostedService.getCreated(), "Created cannot be null for DetailedHostedServiceProperties %s",
- hostedService);
- checkNotNull(hostedService.getLastModified(),
- "LastModified cannot be null for DetailedHostedServiceProperties %s", hostedService);
- checkNotNull(hostedService.getExtendedProperties(),
- "ExtendedProperties cannot be null for DetailedHostedServiceProperties %s", 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() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/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
index a2a4aaf..1ac320d 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/HostedServiceApiMockTest.java
@@ -16,17 +16,19 @@
*/
package org.jclouds.azurecompute.features;
-import com.google.common.collect.ImmutableMap;
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import static org.jclouds.azurecompute.options.CreateHostedServiceOptions.Builder.description;
+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.parse.GetHostedServiceDetailsTest;
-import org.jclouds.azurecompute.parse.GetHostedServiceTest;
-import org.jclouds.azurecompute.parse.ListHostedServicesTest;
+import org.jclouds.azurecompute.xml.HostedServiceHandlerTest;
+import org.jclouds.azurecompute.xml.ListHostedServicesHandlerTest;
import org.testng.annotations.Test;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.jclouds.azurecompute.options.CreateHostedServiceOptions.Builder.description;
+import com.google.common.collect.ImmutableMap;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
@Test(groups = "unit", testName = "HostedServiceApiMockTest")
public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
@@ -38,9 +40,9 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.list()).containsExactlyElementsOf(ListHostedServicesTest.expected());
+ assertEquals(api.list(), ListHostedServicesHandlerTest.expected());
- assertSent(server, "GET", "/services/hostedservices");
+ assertSent(server, "GET", "/services/hostedservices?embed-detail=true");
} finally {
server.shutdown();
}
@@ -53,9 +55,9 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.list()).isEmpty();
+ assertTrue(api.list().isEmpty());
- assertSent(server, "GET", "/services/hostedservices");
+ assertSent(server, "GET", "/services/hostedservices?embed-detail=true");
} finally {
server.shutdown();
}
@@ -68,37 +70,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.get("myservice")).isEqualTo(GetHostedServiceTest.expected());
-
- assertSent(server, "GET", "/services/hostedservices/myservice");
- } finally {
- server.shutdown();
- }
- }
-
- public void getWhenNotFound() throws Exception {
- MockWebServer server = mockAzureManagementServer();
- server.enqueue(new MockResponse().setResponseCode(404));
-
- try {
- HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
-
- assertThat(api.get("myservice")).isNull();
-
- assertSent(server, "GET", "/services/hostedservices/myservice");
- } finally {
- server.shutdown();
- }
- }
-
- public void getDetailsWhenFound() throws Exception {
- MockWebServer server = mockAzureManagementServer();
- server.enqueue(xmlResponse("/hostedservice_details.xml"));
-
- try {
- HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
-
- assertThat(api.getDetails("myservice")).isEqualTo(GetHostedServiceDetailsTest.expected());
+ assertEquals(api.get("myservice"), HostedServiceHandlerTest.expected());
assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true");
} finally {
@@ -106,14 +78,14 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
}
}
- public void getDetailsWhenNotFound() throws Exception {
+ public void getWhenNotFound() throws Exception {
MockWebServer server = mockAzureManagementServer();
server.enqueue(new MockResponse().setResponseCode(404));
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.getDetails("myservice")).isNull();
+ assertNull(api.get("myservice"));
assertSent(server, "GET", "/services/hostedservices/myservice?embed-detail=true");
} finally {
@@ -128,8 +100,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.createServiceWithLabelInLocation("myservice", "service mine", "West US"))
- .isEqualTo("request-1");
+ assertEquals(api.createServiceWithLabelInLocation("myservice", "service mine", "West US"), "request-1");
assertSent(server, "POST", "/services/hostedservices", "/create_hostedservice_location.xml");
} finally {
@@ -144,9 +115,8 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.createServiceWithLabelInLocation("myservice", "service mine", "West US",
- description("my description").extendedProperties(ImmutableMap.of("Role", "Production"))))
- .isEqualTo("request-1");
+ assertEquals(api.createServiceWithLabelInLocation("myservice", "service mine", "West US",
+ description("my description").extendedProperties(ImmutableMap.of("Role", "Production"))), "request-1");
assertSent(server, "POST", "/services/hostedservices", "/create_hostedservice_location_options.xml");
} finally {
@@ -161,7 +131,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.delete("myservice")).isEqualTo("request-1");
+ assertEquals(api.delete("myservice"), "request-1");
assertSent(server, "DELETE", "/services/hostedservices/myservice");
} finally {
@@ -176,7 +146,7 @@ public class HostedServiceApiMockTest extends BaseAzureComputeApiMockTest {
try {
HostedServiceApi api = api(server.getUrl("/")).getHostedServiceApi();
- assertThat(api.delete("myservice")).isNull();
+ assertNull(api.delete("myservice"));
assertSent(server, "DELETE", "/services/hostedservices/myservice");
} finally {
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java
deleted file mode 100644
index 8a71f50..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceDetailsTest.java
+++ /dev/null
@@ -1,65 +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.parse;
-
-import java.io.InputStream;
-import java.net.URI;
-import org.jclouds.azurecompute.domain.DetailedHostedServiceProperties;
-import org.jclouds.azurecompute.domain.HostedService;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
-import org.jclouds.azurecompute.xml.HostedServiceWithDetailedPropertiesHandler;
-import org.jclouds.date.DateService;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "DetailedHostedServiceProperties")
-public class GetHostedServiceDetailsTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/hostedservice_details.xml");
-
- HostedService expected = expected();
-
- HostedServiceWithDetailedPropertiesHandler handler = injector.getInstance(HostedServiceWithDetailedPropertiesHandler.class);
- HostedServiceWithDetailedProperties result = HostedServiceWithDetailedProperties.class.cast(factory.create(handler).parse(is));
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- private static final DateService dateService = new SimpleDateFormatDateService();
-
- public static HostedServiceWithDetailedProperties expected() {
- return HostedServiceWithDetailedProperties.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys"))
- .name("neotys")
- .properties(DetailedHostedServiceProperties.builder()
- .description("Implicitly created hosted service2012-08-06 14:55")
- .location("West Europe")
- .label("neotys")
- .rawStatus("Created")
- .status(Status.CREATED)
- .created(dateService.iso8601SecondsDateParse("2012-08-06T14:55:17Z"))
- .lastModified(dateService.iso8601SecondsDateParse("2012-08-06T15:50:34Z"))
- .build())
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.java
deleted file mode 100644
index b5ccd31..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/GetHostedServiceTest.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.parse;
-
-import java.io.InputStream;
-import java.net.URI;
-import org.jclouds.azurecompute.domain.HostedService;
-import org.jclouds.azurecompute.domain.HostedServiceProperties;
-import org.jclouds.azurecompute.xml.HostedServiceHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "GetHostedServiceTest")
-public class GetHostedServiceTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/hostedservice.xml");
-
- HostedService expected = expected();
-
- HostedServiceHandler handler = injector.getInstance(HostedServiceHandler.class);
- HostedService result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- public static HostedService expected() {
- return HostedService.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys"))
- .name("neotys")
- .properties(HostedServiceProperties.builder()
- .description("Implicitly created hosted service2012-08-06 14:55")
- .location("West Europe")
- .label("neotys")
- .build())
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java
deleted file mode 100644
index 3eaf136..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListHostedServicesTest.java
+++ /dev/null
@@ -1,79 +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.parse;
-
-import com.google.common.collect.ImmutableList;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.List;
-import org.jclouds.azurecompute.domain.DetailedHostedServiceProperties;
-import org.jclouds.azurecompute.domain.HostedService.Status;
-import org.jclouds.azurecompute.domain.HostedServiceWithDetailedProperties;
-import org.jclouds.azurecompute.xml.ListHostedServicesHandler;
-import org.jclouds.date.DateService;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.testng.Assert.assertEquals;
-
-@Test(groups = "unit", testName = "ListHostedServicesTest")
-public class ListHostedServicesTest extends BaseHandlerTest {
-
- public void test() {
- InputStream is = getClass().getResourceAsStream("/hostedservices.xml");
-
- List<HostedServiceWithDetailedProperties> expected = expected();
-
- ListHostedServicesHandler handler = injector.getInstance(ListHostedServicesHandler.class);
- List<HostedServiceWithDetailedProperties> result = factory.create(handler).parse(is);
-
- assertEquals(result.toString(), expected.toString());
-
- }
-
- private static final DateService dateService = new SimpleDateFormatDateService();
-
- public static List<HostedServiceWithDetailedProperties> expected() {
- return ImmutableList.<HostedServiceWithDetailedProperties>builder()
- .add(HostedServiceWithDetailedProperties.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys"))
- .name("neotys")
- .properties(DetailedHostedServiceProperties.builder()
- .description("Implicitly created hosted service2012-08-06 14:55")
- .location("West Europe")
- .label("neotys")
- .rawStatus("Created")
- .status(Status.CREATED)
- .created(dateService.iso8601SecondsDateParse("2012-08-06T14:55:17Z"))
- .lastModified(dateService.iso8601SecondsDateParse("2012-08-06T15:50:34Z"))
- .build())
- .build())
- .add(HostedServiceWithDetailedProperties.builder()
- .url(URI.create("https://management.core.windows.net/eb0347c3-68d4-4550-9b39-5e7e0f92f7db/services/hostedservices/neotys3"))
- .name("neotys3")
- .properties(DetailedHostedServiceProperties.builder()
- .location("West Europe")
- .label("neotys3")
- .rawStatus("Created")
- .status(Status.CREATED)
- .created(dateService.iso8601SecondsDateParse("2012-08-07T09:00:02Z"))
- .lastModified(dateService.iso8601SecondsDateParse("2012-08-07T09:00:02Z"))
- .build())
- .build()).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/497c90b1/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
new file mode 100644
index 0000000..aefdca4
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/HostedServiceHandlerTest.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.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/497c90b1/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.java
new file mode 100644
index 0000000..f40f3c9
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListHostedServicesHandlerTest.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.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;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ListHostedServicesHandlerTest")
+public class ListHostedServicesHandlerTest extends BaseHandlerTest {
+ private static final DateService DATE_SERVICE = new SimpleDateFormatDateService();
+
+ public void test() {
+ InputStream is = getClass().getResourceAsStream("/hostedservices.xml");
+ ListHostedServicesHandler handler = new ListHostedServicesHandler(new HostedServiceHandler(DATE_SERVICE));
+ List<HostedService> result = factory.create(handler).parse(is);
+
+ assertEquals(result, expected());
+ }
+
+ public static List<HostedService> expected() {
+ return ImmutableList.of( //
+ 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
+ ), //
+ HostedService.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
+ ));
+ }
+}