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/20 21:55:55 UTC

[05/11] git commit: Cleanup output-only Image object.

Cleanup output-only Image 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/96ebc7f6
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/96ebc7f6
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/96ebc7f6

Branch: refs/heads/master
Commit: 96ebc7f6f64f2b8156486b9c2c42b46c808f541a
Parents: de2f415
Author: Adrian Cole <ac...@twitter.com>
Authored: Thu Oct 16 19:49:17 2014 -0700
Committer: Adrian Cole <ac...@twitter.com>
Committed: Mon Oct 20 13:26:53 2014 -0400

----------------------------------------------------------------------
 .../org/jclouds/azurecompute/domain/Image.java  | 312 ++++++-------------
 .../org/jclouds/azurecompute/domain/OSType.java |  10 +-
 .../jclouds/azurecompute/xml/ImageHandler.java  | 102 +++---
 .../azurecompute/xml/ListImagesHandler.java     |  38 +--
 .../azurecompute/features/DiskApiLiveTest.java  |   2 +-
 .../azurecompute/features/ImageApiLiveTest.java |  88 ++----
 .../azurecompute/features/ImageApiMockTest.java |  24 +-
 .../azurecompute/parse/ListImagesTest.java      | 117 -------
 .../azurecompute/xml/ListImagesHandlerTest.java | 156 ++++++++++
 9 files changed, 377 insertions(+), 472 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java
index 0bde175..8a1e373 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/Image.java
@@ -16,198 +16,54 @@
  */
 package org.jclouds.azurecompute.domain;
 
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
+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.net.URI;
 import java.util.List;
 
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.jclouds.javax.annotation.Nullable;
+
+import com.google.common.base.Objects;
 
 /**
- * OS images from the image repository
+ * OS image from the image repository
  *
  * @see <a href="http://msdn.microsoft.com/en-us/library/jj157191" >api</a>
  */
-public class Image {
-   public static Builder builder() {
-      return new Builder();
-   }
-
-   public Builder toBuilder() {
-      return new Builder().fromOSImage(this);
-   }
-
-   public static class Builder {
-      private OSType os;
-      private String name;
-      private Optional<Integer> logicalSizeInGB = Optional.absent();
-      private Optional<String> description = Optional.absent();
-      private Optional<String> category = Optional.absent();
-      private Optional<String> location = Optional.absent();
-      private Optional<String> affinityGroup = Optional.absent();
-      private Optional<URI> mediaLink = Optional.absent();
-      private ImmutableList.Builder<String> eula = ImmutableList.builder();
-      private String label;
-
-      /**
-       * @see Image#getOS()
-       */
-      public Builder os(OSType os) {
-         this.os = os;
-         return this;
-      }
-
-      /**
-       * @see Image#getName()
-       */
-      public Builder name(String name) {
-         this.name = name;
-         return this;
-      }
-
-      /**
-       * @see Image#getDescription()
-       */
-      public Builder description(String description) {
-         this.description = Optional.fromNullable(description);
-         return this;
-      }
-
-      /**
-       * @see Image#getLogicalSizeInGB()
-       */
-      public Builder logicalSizeInGB(Integer logicalSizeInGB) {
-         this.logicalSizeInGB = Optional.fromNullable(logicalSizeInGB);
-         return this;
-      }
-
-      /**
-       * @see Image#getCategory()
-       */
-      public Builder category(String category) {
-         this.category = Optional.fromNullable(category);
-         return this;
-      }
-
-      /**
-       * @see Image#getLocation()
-       */
-      public Builder location(String location) {
-         this.location = Optional.fromNullable(location);
-         return this;
-      }
+public final class Image {
 
-      /**
-       * @see Image#getAffinityGroup()
-       */
-      public Builder affinityGroup(String affinityGroup) {
-         this.affinityGroup = Optional.fromNullable(affinityGroup);
-         return this;
-      }
-
-      /**
-       * @see Image#getMediaLink()
-       */
-      public Builder mediaLink(URI mediaLink) {
-         this.mediaLink = Optional.fromNullable(mediaLink);
-         return this;
-      }
-
-      /**
-       * @see Image#getEula()
-       */
-      public Builder eula(Iterable<String> eula) {
-         this.eula.addAll(eula);
-         return this;
-      }
-
-      /**
-       * @see Image#getEula()
-       */
-      public Builder eula(String eula) {
-         this.eula.add(eula);
-         return this;
-      }
-
-      /**
-       * @see Image#getLabel()
-       */
-      public Builder label(String label) {
-         this.label = label;
-         return this;
-      }
-
-      public Image build() {
-         return new Image(os, name, logicalSizeInGB, description, category, location, affinityGroup, mediaLink,
-               eula.build(), label);
-      }
-
-      public Builder fromOSImage(Image in) {
-         return this.os(in.getOS()).name(in.getName()).logicalSizeInGB(in.getLogicalSizeInGB().orNull())
-                  .description(in.getDescription().orNull()).category(in.getCategory().orNull())
-                  .location(in.getLocation().orNull()).affinityGroup(in.getAffinityGroup().orNull())
-                  .mediaLink(in.getMediaLink().orNull()).eula(in.getEula()).label(in.getLabel());
-      }
-   }
-
-   private final OSType os;
-   private final String name;
-   private final Optional<Integer> logicalSizeInGB;
-   private final Optional<String> description;
-   private final Optional<String> category;
-   private final Optional<String> location;
-   private final Optional<String> affinityGroup;
-   private final Optional<URI> mediaLink;
-   private final List<String> eula;
-   private final String label;
-
-   private Image(OSType os, String name, Optional<Integer> logicalSizeInGB, Optional<String> description,
-         Optional<String> category, Optional<String> location, Optional<String> affinityGroup, Optional<URI> mediaLink,
-         List<String> eula, String label) {
-      this.name = checkNotNull(name, "name");
-      this.logicalSizeInGB = checkNotNull(logicalSizeInGB, "logicalSizeInGB for %s", name);
-      this.description = checkNotNull(description, "description for %s", name);
-      this.os = checkNotNull(os, "os for %s", name);
-      this.category = checkNotNull(category, "category for %s", name);
-      this.location = checkNotNull(location, "location for %s", name);
-      this.affinityGroup = checkNotNull(affinityGroup, "affinityGroup for %s", name);
-      this.mediaLink = checkNotNull(mediaLink, "mediaLink for %s", name);
-      this.eula = checkNotNull(eula, "eula for %s", name);
-      this.label = checkNotNull(label, "label for %s", name);
+   public String name() {
+      return name;
    }
 
    /**
-    * The operating system type of the OS image.
+    * The geo-location of the image in Windows Azure, if the image is not
+    * associated with an affinity group. If a location has been specified, the AffinityGroup element
+    * is not returned.
     */
-   public OSType getOS() {
-      return os;
+   @Nullable public String location() {
+      return location;
    }
 
    /**
-    * The name of the hosted service. This name is the DNS prefix name and can be used to access the
-    * hosted service.
-    *
-    * For example, if the service name is MyService you could access the access the service by
-    * calling: http://MyService.cloudapp.net
+    * The affinity group with which this image is associated, if any. If the service is
+    * associated with an affinity group, the Location element is not returned.
     */
-   public String getName() {
-      return name;
+   @Nullable public String affinityGroup() {
+      return affinityGroup;
    }
 
    /**
-    * The size, in GB, of the image.
+    * The name can be up to 100 characters in length. The name can be used identify the storage account for your
+    * tracking purposes.
     */
-   public Optional<Integer> getLogicalSizeInGB() {
-      return logicalSizeInGB;
+   public String label() {
+      return label;
    }
 
-   /**
-    * The description for the image.
-    */
-   public Optional<String> getDescription() {
+   @Nullable public String description() {
       return description;
    }
 
@@ -215,26 +71,13 @@ public class Image {
     * The repository classification of image. All user images have the category "User", but
     * categories for other images could be, for example "Canonical"
     */
-   public Optional<String> getCategory() {
+   @Nullable public String category() {
       return category;
    }
 
-   /**
-    * The geo-location in which this media is located. The Location value is derived from storage
-    * account that contains the blob in which the media is located. If the storage account belongs
-    * to an affinity group the value is absent.
-    */
-   public Optional<String> getLocation() {
-      return location;
-   }
-
-   /**
-    * The affinity in which the media is located. The AffinityGroup value is derived from storage
-    * account that contains the blob in which the media is located. If the storage account does not
-    * belong to an affinity group the value is absent.
-    */
-   public Optional<String> getAffinityGroup() {
-      return affinityGroup;
+   /** The operating system type of the OS image. */
+   public OSType os() {
+      return os;
    }
 
    /**
@@ -246,53 +89,92 @@ public class Image {
     *
     * http://example.blob.core.windows.net/disks/myimage.vhd
     */
-   public Optional<URI> getMediaLink() {
+   @Nullable public URI mediaLink() {
       return mediaLink;
    }
 
-   /**
-    * The eulas for the image, if available.
-    */
+   public int logicalSizeInGB() {
+      return logicalSizeInGB;
+   }
+
+   /** The eulas for the image, if available. */
    // Not URI as some providers put non-uri data in, such as riverbed.
-   public List<String> getEula() {
+   public List<String> eula() {
       return eula;
    }
 
-   /**
-    * The description of the image.
-    */
-   public String getLabel() {
-      return label;
+   public static Image create(String name, String location, String affinityGroup, String label, String description,
+         String category, OSType os, URI mediaLink, int logicalSizeInGB, List<String> eula) {
+      return new Image(name, location, affinityGroup, label, description, category, os, mediaLink, logicalSizeInGB,
+            eula);
    }
 
-   @Override
-   public int hashCode() {
-      return Objects.hashCode(name);
+   // TODO: Remove from here down with @AutoValue.
+   private Image(String name, String location, String affinityGroup, String label, String description, String category,
+         OSType os, URI mediaLink, int logicalSizeInGB, List<String> eula) {
+      this.name = checkNotNull(name, "name");
+      this.location = location;
+      this.affinityGroup = affinityGroup;
+      this.label = checkNotNull(label, "label");
+      this.description = description;
+      this.category = category;
+      this.os = checkNotNull(os, "os");
+      this.mediaLink = mediaLink;
+      this.logicalSizeInGB = logicalSizeInGB;
+      this.eula = checkNotNull(eula, "eula");
    }
 
+   private final String name;
+   private final String location;
+   private final String affinityGroup;
+   private final String label;
+   private final String category;
+   private final String description;
+   private final OSType os;
+   private final URI mediaLink;
+   private final int logicalSizeInGB;
+   private final List<String> eula;
+
    @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 Image) {
+         Image that = Image.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(category, that.category)
+               && equal(os, that.os)
+               && equal(mediaLink, that.mediaLink)
+               && equal(logicalSizeInGB, that.logicalSizeInGB)
+               && equal(eula, that.eula);
+      } else {
          return false;
-      Image other = (Image) obj;
-      return Objects.equal(this.name, other.name);
+      }
    }
 
    @Override
-   public String toString() {
-      return string().toString();
+   public int hashCode() {
+      return Objects.hashCode(name, location, affinityGroup, label, description, category, os, mediaLink,
+            logicalSizeInGB, eula);
    }
 
-   private ToStringHelper string() {
-      return MoreObjects.toStringHelper(this).omitNullValues().add("os", os).add("name", name)
-               .add("logicalSizeInGB", logicalSizeInGB.orNull()).add("description", description)
-               .add("category", category.orNull()).add("location", location.orNull())
-               .add("affinityGroup", affinityGroup.orNull()).add("mediaLink", mediaLink.orNull())
-               .add("eula", eula).add("label", label);
+   @Override
+   public String toString() {
+      return toStringHelper(this)
+            .add("name", name)
+            .add("location", location)
+            .add("affinityGroup", affinityGroup)
+            .add("label", label)
+            .add("description", description)
+            .add("category", category)
+            .add("os", os)
+            .add("mediaLink", mediaLink)
+            .add("logicalSizeInGB", logicalSizeInGB)
+            .add("eula", eula).toString();
    }
-
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java
index fd85bde..c81b590 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/domain/OSType.java
@@ -16,20 +16,18 @@
  */
 package org.jclouds.azurecompute.domain;
 
-import com.google.common.base.CaseFormat;
-
+import static com.google.common.base.CaseFormat.UPPER_CAMEL;
+import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public enum OSType {
 
    LINUX,
-
    WINDOWS,
-
    UNRECOGNIZED;
 
    public String value() {
-      return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name());
+      return UPPER_UNDERSCORE.to(UPPER_CAMEL, name());
    }
 
    @Override
@@ -39,7 +37,7 @@ public enum OSType {
 
    public static OSType fromValue(String type) {
       try {
-         return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
+         return valueOf(UPPER_CAMEL.to(UPPER_UNDERSCORE, checkNotNull(type, "type")));
       } catch (IllegalArgumentException e) {
          return UNRECOGNIZED;
       }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
index 08adfea..c53888d 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ImageHandler.java
@@ -16,73 +16,91 @@
  */
 package org.jclouds.azurecompute.xml;
 
-import com.google.common.base.Splitter;
-import com.google.common.base.Strings;
+import static com.google.common.base.Strings.emptyToNull;
+import static org.jclouds.util.SaxUtils.currentOrNull;
+
 import java.net.URI;
+import java.util.List;
+
 import org.jclouds.azurecompute.domain.Image;
 import org.jclouds.azurecompute.domain.OSType;
 import org.jclouds.http.functions.ParseSax;
-import org.xml.sax.SAXException;
 
-import static org.jclouds.util.SaxUtils.currentOrNull;
-import static org.jclouds.util.SaxUtils.equalsOrSuffix;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
 
 /**
  * @see <a href="http://msdn.microsoft.com/en-us/library/jj157191" >api</a>
  */
-public class ImageHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Image> {
+final class ImageHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Image> {
+   private String name;
+   private String location;
+   private String affinityGroup;
+   private String label;
+   private String category;
+   private String description;
+   private OSType os;
+   private URI mediaLink;
+   private Integer logicalSizeInGB;
+   private final List<String> eula = Lists.newArrayList();
 
-   private StringBuilder currentText = new StringBuilder();
-   private Image.Builder builder = Image.builder();
+   private final StringBuilder currentText = new StringBuilder();
 
-   @Override
-   public Image getResult() {
-      try {
-         return builder.build();
-      } finally {
-         builder = Image.builder();
-      }
+   @Override public Image getResult() {
+      Image result = Image.create(name, location, affinityGroup, label, description, category, os, mediaLink,
+            logicalSizeInGB, ImmutableList.copyOf(eula));
+      resetState(); // handler is called in a loop.
+      return result;
+   }
+
+   private void resetState() {
+      name = location = affinityGroup = label = description = category = null;
+      os = null;
+      mediaLink = null;
+      logicalSizeInGB = null;
+      eula.clear();
    }
 
-   @Override
-   public void endElement(String uri, String name, String qName) throws SAXException {
-      if (equalsOrSuffix(qName, "OS")) {
-         builder.os(OSType.fromValue(currentOrNull(currentText)));
-      } else if (equalsOrSuffix(qName, "Name")) {
-         builder.name(currentOrNull(currentText));
-      } else if (equalsOrSuffix(qName, "LogicalSizeInGB")) {
+   @Override public void endElement(String ignoredUri, String ignoredName, String qName) {
+      if (qName.equals("OS")) {
+         os = OSType.fromValue(currentOrNull(currentText));
+      } else if (qName.equals("Name")) {
+         name = currentOrNull(currentText);
+      } else if (qName.equals("LogicalSizeInGB")) {
          String gb = currentOrNull(currentText);
-         if (gb != null)
-            builder.logicalSizeInGB(Integer.parseInt(gb));
-      } else if (equalsOrSuffix(qName, "Description")) {
-         builder.description(currentOrNull(currentText));
-      } else if (equalsOrSuffix(qName, "Category")) {
-         builder.category(currentOrNull(currentText));
-      } else if (equalsOrSuffix(qName, "Location")) {
-         builder.location(currentOrNull(currentText));
-      } else if (equalsOrSuffix(qName, "AffinityGroup")) {
-         builder.affinityGroup(currentOrNull(currentText));
-      } else if (equalsOrSuffix(qName, "MediaLink")) {
+         if (gb != null) {
+            logicalSizeInGB = Integer.parseInt(gb);
+         }
+      } else if (qName.equals("Description")) {
+         description = currentOrNull(currentText);
+      } else if (qName.equals("Category")) {
+         category = currentOrNull(currentText);
+      } else if (qName.equals("Location")) {
+         location = currentOrNull(currentText);
+      } else if (qName.equals("AffinityGroup")) {
+         affinityGroup = currentOrNull(currentText);
+      } else if (qName.equals("MediaLink")) {
          String link = currentOrNull(currentText);
-         if (link != null)
-            builder.mediaLink(URI.create(link));
-      } else if (equalsOrSuffix(qName, "Eula")) {
+         if (link != null) {
+            mediaLink = URI.create(link);
+         }
+      } else if (qName.equals("Eula")) {
          String eulaField = currentOrNull(currentText);
          if (eulaField != null) {
             for (String eula : Splitter.on(';').split(eulaField)) {
-               if ((eula = Strings.emptyToNull(eula.trim())) != null) { // Dirty data in RightScale eula field.
-                  builder.eula(eula);
+               if ((eula = emptyToNull(eula.trim())) != null) { // Dirty data in RightScale eula field.
+                  this.eula.add(eula);
                }
             }
          }
-      } else if (equalsOrSuffix(qName, "Label")) {
-         builder.label(currentOrNull(currentText));
+      } else if (qName.equals("Label")) {
+         label = currentOrNull(currentText);
       }
       currentText.setLength(0);
    }
 
-   @Override
-   public void characters(char ch[], int start, int length) {
+   @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/96ebc7f6/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
index beae350..f220f8c 100644
--- a/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
+++ b/azurecompute/src/main/java/org/jclouds/azurecompute/xml/ListImagesHandler.java
@@ -16,58 +16,46 @@
  */
 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.Image;
 import org.jclouds.http.functions.ParseSax;
-import org.jclouds.util.SaxUtils;
 import org.xml.sax.Attributes;
-import org.xml.sax.SAXException;
 
-public class ListImagesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Image>> {
-
-   private final ImageHandler locationHandler;
-
-   private Builder<Image> locations = ImmutableList.<Image> builder();
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
 
+public final class ListImagesHandler extends ParseSax.HandlerForGeneratedRequestWithResult<List<Image>> {
    private boolean inOSImage;
-
-   @Inject
-   public ListImagesHandler(ImageHandler locationHandler) {
-      this.locationHandler = locationHandler;
-   }
+   private final ImageHandler imageHandler = new ImageHandler();
+   private final Builder<Image> images = ImmutableList.builder();
 
    @Override
    public List<Image> getResult() {
-      return locations.build();
+      return images.build();
    }
 
    @Override
-   public void startElement(String url, String name, String qName, Attributes attributes) throws SAXException {
-      if (SaxUtils.equalsOrSuffix(qName, "OSImage")) {
+   public void startElement(String url, String name, String qName, Attributes attributes) {
+      if (qName.equals("OSImage")) {
          inOSImage = true;
       }
-      if (inOSImage) {
-         locationHandler.startElement(url, name, qName, attributes);
-      }
    }
 
    @Override
-   public void endElement(String uri, String name, String qName) throws SAXException {
+   public void endElement(String uri, String name, String qName) {
       if (qName.equals("OSImage")) {
          inOSImage = false;
-         locations.add(locationHandler.getResult());
+         images.add(imageHandler.getResult());
       } else if (inOSImage) {
-         locationHandler.endElement(uri, name, qName);
+         imageHandler.endElement(uri, name, qName);
       }
    }
 
    @Override
    public void characters(char ch[], int start, int length) {
       if (inOSImage) {
-         locationHandler.characters(ch, start, length);
+         imageHandler.characters(ch, start, length);
       }
    }
 }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
index eb16847..478b1b3 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/DiskApiLiveTest.java
@@ -52,7 +52,7 @@ public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest {
       images = ImmutableSet.copyOf(transform(api.getImageApi().list(), new Function<Image, String>() {
          @Override
          public String apply(Image in) {
-            return in.getName();
+            return in.name();
          }
       }));
    }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
index 3507147..2b1aaf0 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiLiveTest.java
@@ -16,9 +16,12 @@
  */
 package org.jclouds.azurecompute.features;
 
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableSet;
-import java.util.List;
+import static com.google.common.collect.Iterables.transform;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
 import org.jclouds.azurecompute.domain.Image;
 import org.jclouds.azurecompute.domain.Location;
 import org.jclouds.azurecompute.domain.OSType;
@@ -26,11 +29,8 @@ import org.jclouds.azurecompute.internal.BaseAzureComputeApiLiveTest;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.transform;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.testng.Assert.assertNotEquals;
-import static org.testng.Assert.assertTrue;
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableSet;
 
 @Test(groups = "live", testName = "ImageApiLiveTest")
 public class ImageApiLiveTest extends BaseAzureComputeApiLiveTest {
@@ -41,65 +41,41 @@ public class ImageApiLiveTest extends BaseAzureComputeApiLiveTest {
    public void setup() {
       super.setup();
 
-      locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(),
-               new Function<Location, String>() {
-                  @Override
-                  public String apply(Location in) {
-                     return in.getName();
-                  }
-               }));
+      locations = ImmutableSet.copyOf(transform(api.getLocationApi().list(), new Function<Location, String>() {
+         public String apply(Location in) {
+            return in.getName();
+         }
+      }));
    }
 
-   @Test
-   protected void testList() {
-      List<Image> response = api().list();
-
-      for (Image image : response) {
+   public void testList() {
+      for (Image image : api().list()) {
          checkOSImage(image);
       }
    }
 
    private void checkOSImage(Image image) {
-      checkNotNull(image.getLabel(), "Label cannot be null for OSImage %s", image);
-      checkNotNull(image.getName(), "Name cannot be null for OSImage %s", image.getLabel());
-      checkNotNull(image.getOS(), "OS cannot be null for OSImage: %s", image);
-      assertNotEquals(image.getOS(), OSType.UNRECOGNIZED, "Status cannot be UNRECOGNIZED for OSImage: " + image);
-
-      checkNotNull(image.getCategory(), "While Category can be null for OSImage, its Optional wrapper cannot: %s",
-               image);
-      if (image.getCategory().isPresent())
-         assertNotEquals("", image.getCategory().get().trim(), "Invalid Category: " + image.toString());
-
-      checkNotNull(image.getLogicalSizeInGB(),
-               "While LogicalSizeInGB can be null for OSImage, its Optional wrapper cannot: %s", image);
-
-      if (image.getLogicalSizeInGB().isPresent())
-         assertTrue(image.getLogicalSizeInGB().get() > 0,
-                  "LogicalSizeInGB should be positive, if set" + image.toString());
-
-      checkNotNull(image.getMediaLink(), "While MediaLink can be null for OSImage, its Optional wrapper cannot: %s",
-               image);
-
-      if (image.getMediaLink().isPresent())
-         assertTrue(ImmutableSet.of("http", "https").contains(image.getMediaLink().get().getScheme()),
-                  "MediaLink should be an http(s) url" + image.toString());
-
-      checkNotNull(image.getDescription(),
-               "While Description can be null for OSImage, its Optional wrapper cannot: %s", image);
+      assertNotNull(image.label(), "Label cannot be null for " + image);
+      assertNotNull(image.name(), "Name cannot be null for " + image);
+      assertNotNull(image.os(), "OS cannot be null for " + image);
+      assertNotEquals(image.os(), OSType.UNRECOGNIZED, "Status cannot be UNRECOGNIZED for " + image);
+      assertTrue(image.logicalSizeInGB() > 0, "LogicalSizeInGB should be positive, if set" + image);
+
+      if (image.category() != null) {
+         assertNotEquals("", image.category().trim(), "Invalid Category for " + image);
+      }
 
-      checkNotNull(image.getLocation(), "While Location can be null for OSImage, its Optional wrapper cannot: %s",
-               image);
-      if (image.getLocation().isPresent()) {
-         assertTrue(locations.contains(image.getLocation().get()),
-                  "Location not in " + locations + " :" + image.toString());
+      if (image.mediaLink() != null) {
+         assertTrue(ImmutableSet.of("http", "https").contains(image.mediaLink().getScheme()),
+               "MediaLink should be an http(s) url" + image);
+      }
+      if (image.location() != null) {
+         assertTrue(locations.contains(image.location()), "Location not in " + locations + " :" + image);
       }
 
       // Ex. Dirty data in RightScale eula field comes out as an empty string.
-      assertThat(image.getEula()).isNotNull().doesNotContain("");
-
-      checkNotNull(image.getAffinityGroup(),
-               "While AffinityGroup can be null for OSImage, its Optional wrapper cannot: %s", image);
-      if (image.getAffinityGroup().isPresent()) {
+      assertFalse(image.eula().contains(""));
+      if (image.affinityGroup() != null) {
          // TODO: list getAffinityGroups and check if there
       }
    }

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
index 6c7b5c4..be3d9d7 100644
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/features/ImageApiMockTest.java
@@ -16,16 +16,20 @@
  */
 package org.jclouds.azurecompute.features;
 
-import com.squareup.okhttp.mockwebserver.MockResponse;
-import com.squareup.okhttp.mockwebserver.MockWebServer;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
 import java.net.URI;
+
 import org.jclouds.azurecompute.domain.ImageParams;
 import org.jclouds.azurecompute.domain.OSType;
 import org.jclouds.azurecompute.internal.BaseAzureComputeApiMockTest;
-import org.jclouds.azurecompute.parse.ListImagesTest;
+import org.jclouds.azurecompute.xml.ListImagesHandlerTest;
 import org.testng.annotations.Test;
 
-import static org.assertj.core.api.Assertions.assertThat;
+import com.squareup.okhttp.mockwebserver.MockResponse;
+import com.squareup.okhttp.mockwebserver.MockWebServer;
 
 @Test(groups = "unit", testName = "ImageApiMockTest")
 public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
@@ -37,7 +41,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
       try {
          ImageApi api = api(server.getUrl("/")).getImageApi();
 
-         assertThat(api.list()).containsExactlyElementsOf(ListImagesTest.expected());
+         assertEquals(api.list(), ListImagesHandlerTest.expected());
 
          assertSent(server, "GET", "/services/images");
       } finally {
@@ -52,7 +56,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
       try {
          ImageApi api = api(server.getUrl("/")).getImageApi();
 
-         assertThat(api.list()).isEmpty();
+         assertTrue(api.list().isEmpty());
 
          assertSent(server, "GET", "/services/images");
       } finally {
@@ -70,7 +74,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
          ImageParams params = ImageParams.builder().name("myimage").label("foo").os(OSType.LINUX)
                .mediaLink(URI.create("http://example.blob.core.windows.net/disks/mydisk.vhd")).build();
 
-         assertThat(api.add(params)).isEqualTo("request-1");
+         assertEquals(api.add(params), "request-1");
 
          assertSent(server, "POST", "/services/images", "/imageparams.xml");
       } finally {
@@ -88,7 +92,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
          ImageParams params = ImageParams.builder().name("myimage").label("foo").os(OSType.LINUX)
                .mediaLink(URI.create("http://example.blob.core.windows.net/disks/mydisk.vhd")).build();
 
-         assertThat(api.update(params)).isEqualTo("request-1");
+         assertEquals(api.update(params), "request-1");
 
          assertSent(server, "PUT", "/services/images/myimage", "/imageparams.xml");
       } finally {
@@ -103,7 +107,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
       try {
          ImageApi api = api(server.getUrl("/")).getImageApi();
 
-         assertThat(api.delete("myimage")).isEqualTo("request-1");
+         assertEquals(api.delete("myimage"), "request-1");
 
          assertSent(server, "DELETE", "/services/images/myimage");
       } finally {
@@ -118,7 +122,7 @@ public class ImageApiMockTest extends BaseAzureComputeApiMockTest {
       try {
          ImageApi api = api(server.getUrl("/")).getImageApi();
 
-         assertThat(api.delete("myimage")).isNull();
+         assertNull(api.delete("myimage"));
 
          assertSent(server, "DELETE", "/services/images/myimage");
       } finally {

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java
deleted file mode 100644
index d9e19b3..0000000
--- a/azurecompute/src/test/java/org/jclouds/azurecompute/parse/ListImagesTest.java
+++ /dev/null
@@ -1,117 +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.util.List;
-import org.jclouds.azurecompute.domain.Image;
-import org.jclouds.azurecompute.domain.OSType;
-import org.jclouds.azurecompute.xml.ListImagesHandler;
-import org.jclouds.http.functions.BaseHandlerTest;
-import org.testng.annotations.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@Test(groups = "unit", testName = "ListOSImagesTest")
-public class ListImagesTest extends BaseHandlerTest {
-
-   public void test() {
-      InputStream is = getClass().getResourceAsStream("/images.xml");
-
-      ListImagesHandler handler = injector.getInstance(ListImagesHandler.class);
-      List<Image> result = factory.create(handler).parse(is);
-
-      assertThat(result).usingFieldByFieldElementComparator().containsExactlyElementsOf(expected());
-   }
-
-   public static List<Image> expected() {
-      return ImmutableList.<Image>builder()
-         .add(Image.builder()
-                   .category("Canonical")
-                   .label("Ubuntu Server 12.04 LTS")
-                   .logicalSizeInGB(30)
-                   .name("CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd")
-                   .os(OSType.LINUX)
-                   .eula("http://www.ubuntu.com/project/about-ubuntu/licensing")
-                   .description("Ubuntu Server 12.04 LTS amd64 20120528 Cloud Image").build())
-         .add(Image.builder()
-                   .category("Microsoft")
-                   .label("Windows Server 2008 R2 SP1, June 2012")
-                   .logicalSizeInGB(30)
-                   .name("MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd")
-                   .os(OSType.WINDOWS)
-                   .description("Windows Server 2008 R2 is a multi-purpose server.").build())
-         .add(Image.builder()
-                   .category("Microsoft")
-                   .label("Microsoft SQL Server 2012 Evaluation Edition")
-                   .logicalSizeInGB(30)
-                   .name("MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd")
-                   .os(OSType.WINDOWS)
-                   .eula("http://go.microsoft.com/fwlink/?LinkID=251820") // NOTE multiple eula.
-                   .eula("http://go.microsoft.com/fwlink/?LinkID=131004")
-                   .description("SQL Server 2012 Evaluation Edition (64-bit).").build())
-         .add(Image.builder()
-                   .category("Microsoft")
-                   .label("Windows Server 2012 Release Candidate, July 2012")
-                   .logicalSizeInGB(30)
-                   .name("MSFT__Win2K12RC-Datacenter-201207.02-en.us-30GB.vhd")
-                   .os(OSType.WINDOWS)
-                   .description("Windows Server 2012 incorporates Microsoft's experience building.").build())
-         .add(Image.builder()
-                   .category("Microsoft")
-                   .label("Windows Server 2008 R2 SP1, July 2012")
-                   .logicalSizeInGB(30)
-                   .name("MSFT__Win2K8R2SP1-Datacenter-201207.01-en.us-30GB.vhd")
-                   .os(OSType.WINDOWS)
-                   .description("Windows Server 2008 R2 is a multi-purpose server.")
-                   .build())
-         .add(Image.builder()
-                   .category("OpenLogic")
-                   .label("OpenLogic CentOS 6.2")
-                   .logicalSizeInGB(30)
-                   .name("OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd")
-                   .os(OSType.LINUX)
-                   .eula("http://www.openlogic.com/azure/service-agreement/")
-                   .description("This distribution of Linux is based on CentOS.").build())
-         .add(Image.builder()
-                   .category("SUSE")
-                   .label("openSUSE 12.1")
-                   .logicalSizeInGB(30)
-                   .name("SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd")
-                   .os(OSType.LINUX)
-                   .eula("http://opensuse.org/")
-                   .description("openSUSE is a free and Linux-based operating system!")
-                   .build())
-         .add(Image.builder()
-                   .category("SUSE")
-                   .label("SUSE Linux Enterprise Server")
-                   .logicalSizeInGB(30)
-                   .name("SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd")
-                   .os(OSType.LINUX)
-                   .eula("http://www.novell.com/licensing/eula/")
-                   .description("SUSE Linux Enterprise Server is a highly reliable value.").build())
-         .add(Image.builder()
-                   .category("RightScale with Linux")
-                   .label("RightImage-CentOS-6.4-x64-v13.4")
-                   .logicalSizeInGB(10)
-                   .name("0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.4-x64-v13.4")
-                   .os(OSType.LINUX) // No EULA, as RightScale stuffed ';' into the field.
-                   .build()).build();
-   }
-
-}

http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/96ebc7f6/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java
----------------------------------------------------------------------
diff --git a/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java
new file mode 100644
index 0000000..823a6e2
--- /dev/null
+++ b/azurecompute/src/test/java/org/jclouds/azurecompute/xml/ListImagesHandlerTest.java
@@ -0,0 +1,156 @@
+/*
+ * 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.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.jclouds.azurecompute.domain.Image;
+import org.jclouds.azurecompute.domain.OSType;
+import org.jclouds.http.functions.BaseHandlerTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+
+@Test(groups = "unit", testName = "ListImagesHandlerTest")
+public class ListImagesHandlerTest extends BaseHandlerTest {
+
+   public void test() {
+      InputStream is = getClass().getResourceAsStream("/images.xml");
+      List<Image> result = factory.create(new ListImagesHandler()).parse(is);
+
+      assertEquals(result, expected());
+   }
+
+   public static List<Image> expected() {
+      return ImmutableList.of( //
+            Image.create( //
+                  "CANONICAL__Canonical-Ubuntu-12-04-amd64-server-20120528.1.3-en-us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "Ubuntu Server 12.04 LTS", // label
+                  "Ubuntu Server 12.04 LTS amd64 20120528 Cloud Image", //description
+                  "Canonical", // category
+                  OSType.LINUX, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Arrays.asList("http://www.ubuntu.com/project/about-ubuntu/licensing") // eula
+            ),
+            Image.create( //
+                  "MSFT__Win2K8R2SP1-120612-1520-121206-01-en-us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "Windows Server 2008 R2 SP1, June 2012", // label
+                  "Windows Server 2008 R2 is a multi-purpose server.", //description
+                  "Microsoft", // category
+                  OSType.WINDOWS, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Collections.<String>emptyList() // eula
+            ),
+            Image.create( //
+                  "MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "Microsoft SQL Server 2012 Evaluation Edition", // label
+                  "SQL Server 2012 Evaluation Edition (64-bit).", //description
+                  "Microsoft", // category
+                  OSType.WINDOWS, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Arrays.asList("http://go.microsoft.com/fwlink/?LinkID=251820",
+                                "http://go.microsoft.com/fwlink/?LinkID=131004") // eula
+            ),
+            Image.create( //
+                  "MSFT__Win2K12RC-Datacenter-201207.02-en.us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "Windows Server 2012 Release Candidate, July 2012", // label
+                  "Windows Server 2012 incorporates Microsoft's experience building.", //description
+                  "Microsoft", // category
+                  OSType.WINDOWS, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Collections.<String>emptyList() // eula
+            ),
+            Image.create( //
+                  "MSFT__Win2K8R2SP1-Datacenter-201207.01-en.us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "Windows Server 2008 R2 SP1, July 2012", // label
+                  "Windows Server 2008 R2 is a multi-purpose server.", //description
+                  "Microsoft", // category
+                  OSType.WINDOWS, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Collections.<String>emptyList() // eula
+            ),
+            Image.create( //
+                  "OpenLogic__OpenLogic-CentOS-62-20120531-en-us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "OpenLogic CentOS 6.2", // label
+                  "This distribution of Linux is based on CentOS.", //description
+                  "OpenLogic", // category
+                  OSType.LINUX, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Arrays.asList("http://www.openlogic.com/azure/service-agreement/") // eula
+            ),
+            Image.create( //
+                  "SUSE__openSUSE-12-1-20120603-en-us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "openSUSE 12.1", // label
+                  "openSUSE is a free and Linux-based operating system!", //description
+                  "SUSE", // category
+                  OSType.LINUX, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Arrays.asList("http://opensuse.org/") // eula
+            ),
+            Image.create( //
+                  "SUSE__SUSE-Linux-Enterprise-Server-11SP2-20120601-en-us-30GB.vhd", // name
+                  null, // location
+                  null, // affinityGroup
+                  "SUSE Linux Enterprise Server", // label
+                  "SUSE Linux Enterprise Server is a highly reliable value.", //description
+                  "SUSE", // category
+                  OSType.LINUX, // os
+                  null, // mediaLink
+                  30, // logicalSizeInGB
+                  Arrays.asList("http://www.novell.com/licensing/eula/") // eula
+            ),
+            Image.create( //
+                  "0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-6.4-x64-v13.4", // name
+                  null, // location
+                  null, // affinityGroup
+                  "RightImage-CentOS-6.4-x64-v13.4", // label
+                  null, //description
+                  "RightScale with Linux", // category
+                  OSType.LINUX, // os
+                  null, // mediaLink
+                  10, // logicalSizeInGB
+                  Collections.<String>emptyList() // No EULA, as RightScale stuffed ';' into the field.
+            )
+      );
+   }
+}