@Test
  public void testParseResponseFromGetSnapshot() {
    ParseSax<Snapshot> parser = createParser();

    Snapshot actual = parser.parse(payloadFromResource("/snapshot/snapshot.xml"));
    assertNotNull(actual, "Parsed content returned null");

    DateService dateParser = createDateParser();

    Snapshot expected =
        Snapshot.builder()
            .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh")
            .description("description")
            .size(1024f)
            .name("snapshot01")
            .state(ProvisioningState.AVAILABLE)
            .isBootable(true)
            .osType(OsType.LINUX)
            .isCpuHotPlug(true)
            .isCpuHotUnPlug(true)
            .isDiscVirtioHotPlug(true)
            .isDiscVirtioHotUnPlug(true)
            .isRamHotPlug(true)
            .isRamHotUnPlug(true)
            .isNicHotPlug(true)
            .isNicHotUnPlug(true)
            .location(Location.US_LAS)
            .creationTime(dateParser.iso8601DateOrSecondsDateParse("2015-01-26T07:09:23.138Z"))
            .lastModificationTime(
                dateParser.iso8601DateOrSecondsDateParse("2015-01-26T07:09:23.138Z"))
            .build();

    assertEquals(actual, expected);
  }
 public void endElement(String uri, String name, String qName) {
   if (qName.equals("volumeId")) {
     if (inAttachmentSet) {
       volumeId = currentText.toString().trim();
     } else {
       id = currentText.toString().trim();
     }
   } else if (qName.equals("size")) {
     size = Integer.parseInt(currentText.toString().trim());
   } else if (qName.equals("availabilityZone")) {
     availabilityZone = currentText.toString().trim();
   } else if (qName.equals("volumeId")) {
     if (inAttachmentSet) {
       volumeId = currentText.toString().trim();
     } else {
       id = currentText.toString().trim();
     }
   } else if (qName.equals("status")) {
     if (inAttachmentSet) {
       attachmentStatus = Attachment.Status.fromValue(currentText.toString().trim());
     } else {
       volumeStatus = Volume.Status.fromValue(currentText.toString().trim());
     }
   } else if (qName.equals("createTime")) {
     createTime = dateService.iso8601DateOrSecondsDateParse(currentText.toString().trim());
   } else if (qName.equals("attachmentSet")) {
     inAttachmentSet = false;
   } else if (qName.equals("instanceId")) {
     instanceId = currentText.toString().trim();
   } else if (qName.equals("snapshotId")) {
     snapshotId = currentText.toString().trim();
     if (snapshotId.equals("")) snapshotId = null;
   } else if (qName.equals("device")) {
     device = currentText.toString().trim();
   } else if (qName.equals("attachTime")) {
     attachTime = dateService.iso8601DateOrSecondsDateParse(currentText.toString().trim());
   } else if (qName.equals("volumeType")) {
     volumeType = currentText.toString().trim();
     if (volumeType.equals("")) volumeType = null;
   } else if (qName.equals("iops")) {
     iops = Integer.parseInt(currentText.toString().trim());
   } else if (qName.equals("encrypted")) {
     encrypted = Boolean.parseBoolean(currentText.toString().trim());
   } else if (qName.equals("item")) {
     if (inAttachmentSet) {
       attachments.add(
           new Attachment(region, volumeId, instanceId, device, attachmentStatus, attachTime));
       volumeId = null;
       instanceId = null;
       device = null;
       attachmentStatus = null;
       attachTime = null;
     }
   }
   currentText.setLength(0);
 }
 public void endElement(String uri, String name, String qName) {
   if (qName.equals("ID")) { // owner stuff
     currentOwner = new CanonicalUser(currentOrNull(currentText));
   } else if (qName.equals("DisplayName")) {
     currentOwner.setDisplayName(currentOrNull(currentText));
   } else if (qName.equals("Bucket")) {
     buckets.add(new BucketMetadata(currentName, currentCreationDate, currentOwner));
   } else if (qName.equals("Name")) {
     currentName = currentOrNull(currentText);
   } else if (qName.equals("CreationDate")) {
     currentCreationDate = dateParser.iso8601DateOrSecondsDateParse(currentOrNull(currentText));
   }
   currentText.setLength(0);
 }
  @Test
  public void testParseResponseFromGetDataCenter() {
    ParseSax<DataCenter> parser = createParser();

    DataCenter actual = parser.parse(payloadFromResource("/datacenter/datacenter.xml"));
    assertNotNull(actual, "Parsed content returned null");

    DateService dateParser = createDateParser();

    DataCenter expected =
        DataCenter.builder()
            .id("12345678-abcd-efgh-ijkl-987654321000")
            .version(10)
            .name("JClouds-DC")
            .state(ProvisioningState.AVAILABLE)
            .location(Location.US_LAS)
            .servers(
                ImmutableList.<Server>of(
                    Server.builder()
                        .dataCenter(
                            DataCenter.builder()
                                .id("12345678-abcd-efgh-ijkl-987654321000")
                                .version(10)
                                .build())
                        .id("qqqqqqqq-wwww-eeee-rrrr-tttttttttttt")
                        .name("jnode1")
                        .cores(4)
                        .ram(4096)
                        .hasInternetAccess(true)
                        .state(ProvisioningState.AVAILABLE)
                        .status(Server.Status.RUNNING)
                        .creationTime(
                            dateParser.iso8601DateOrSecondsDateParse("2014-12-04T07:09:23.138Z"))
                        .lastModificationTime(
                            dateParser.iso8601DateOrSecondsDateParse("2014-12-12T03:08:35.629Z"))
                        .osType(OsType.LINUX)
                        .availabilityZone(AvailabilityZone.AUTO)
                        .isCpuHotPlug(true)
                        .isRamHotPlug(true)
                        .isNicHotPlug(true)
                        .isNicHotUnPlug(true)
                        .isDiscVirtioHotPlug(true)
                        .isDiscVirtioHotUnPlug(true)
                        .storages(
                            ImmutableList.<Storage>of(
                                Storage.builder()
                                    .bootDevice(Boolean.TRUE)
                                    .id("ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh")
                                    .busType(Storage.BusType.VIRTIO)
                                    .deviceNumber(1)
                                    .size(40f)
                                    .name("jnode1-disk1")
                                    .build()))
                        .nics(
                            ImmutableList.<Nic>of(
                                Nic.builder()
                                    .dataCenterId("12345678-abcd-efgh-ijkl-987654321000")
                                    .id("zzzzzzzz-xxxx-cccc-vvvv-bbbbbbbbbbbb")
                                    .lanId(1)
                                    .internetAccess(true)
                                    .serverId("qqqqqqqq-wwww-eeee-rrrr-tttttttttttt")
                                    .ips(ImmutableList.of("202.94.38.12"))
                                    .macAddress("02:01:09:cd:f0:b0")
                                    .firewall(
                                        Firewall.builder()
                                            .active(false)
                                            .id("llllllll-kkkk-jjjj-hhhh-gggggggggggg")
                                            .nicId("zzzzzzzz-xxxx-cccc-vvvv-bbbbbbbbbbbb")
                                            .state(ProvisioningState.AVAILABLE)
                                            .build())
                                    .dhcpActive(true)
                                    .gatewayIp("202.94.38.1")
                                    .state(ProvisioningState.AVAILABLE)
                                    .build()))
                        .build()))
            .storages(
                ImmutableList.<Storage>of(
                    Storage.builder()
                        .id("ssssssss-aaaa-ffff-gggg-hhhhhhhhhhhh")
                        .size(40)
                        .name("jnode1-disk1")
                        .state(ProvisioningState.AVAILABLE)
                        .creationTime(
                            dateParser.iso8601DateOrSecondsDateParse("2014-12-04T07:09:23.138Z"))
                        .lastModificationTime(
                            dateParser.iso8601DateOrSecondsDateParse("2014-12-12T03:14:48.316Z"))
                        .serverIds(ImmutableList.of("qqqqqqqq-wwww-eeee-rrrr-tttttttttttt"))
                        .build()))
            .build();
    assertEquals(actual, expected);
  }