public void testApplyInputStreamDetails() throws UnknownHostException {
    InputStream is = getClass().getResourceAsStream("/test_list_images_detail.json");

    UnwrapOnlyJsonValue<List<Image>> parser =
        i.getInstance(Key.get(new TypeLiteral<UnwrapOnlyJsonValue<List<Image>>>() {}));
    List<Image> response =
        parser.apply(HttpResponse.builder().statusCode(200).message("ok").payload(is).build());

    assertEquals(response.get(0).getId(), 2);
    assertEquals(response.get(0).getName(), "CentOS 5.2");
    assertEquals(
        response.get(0).getCreated(), dateService.iso8601SecondsDateParse("2010-08-10T12:00:00Z"));
    assertEquals(response.get(0).getProgress(), null);
    assertEquals(response.get(0).getServerId(), null);
    assertEquals(response.get(0).getStatus(), ImageStatus.ACTIVE);
    assertEquals(
        response.get(0).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));

    assertEquals(response.get(1).getId(), 743);
    assertEquals(response.get(1).getName(), "My Server Backup");
    assertEquals(
        response.get(1).getCreated(),
        dateService.iso8601SecondsDateParse("2009-07-07T09:56:16-05:00"));
    ;
    assertEquals(response.get(1).getProgress(), Integer.valueOf(80));
    assertEquals(response.get(1).getServerId(), Integer.valueOf(12));
    assertEquals(response.get(1).getStatus(), ImageStatus.SAVING);
    assertEquals(
        response.get(1).getUpdated(), dateService.iso8601SecondsDateParse("2010-10-10T12:00:00Z"));
  }
Esempio n. 2
0
  public void testError() {
    InputStream is = getClass().getResourceAsStream("/task-error.xml");

    Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);

    Task expects =
        new TaskImpl(
            URI.create("http://10.150.4.49/api/v0.8/task/23"),
            null,
            TaskStatus.ERROR,
            dateService.iso8601SecondsDateParse("2009-12-07T19:05:02Z"),
            dateService.iso8601SecondsDateParse("2009-12-10T14:40:32Z"),
            null,
            new ReferenceTypeImpl(
                "testapp1",
                VCloudMediaType.VAPP_XML,
                URI.create("http://10.150.4.49/api/v0.8/vapp/1")),
            new ErrorImpl(
                "Error processing job",
                500,
                MinorCode.UNRECOGNIZED,
                " Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00",
                null));
    assertEquals(result, expects);
  }
Esempio n. 3
0
  public void testApplyInputStream2() {
    InputStream is = getClass().getResourceAsStream("/task-hosting.xml");

    Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is);

    Task expects =
        new TaskImpl(
            URI.create("https://vcloud.safesecureweb.com/api/v0.8/task/97806"),
            null,
            TaskStatus.SUCCESS,
            dateService.iso8601SecondsDateParse("2010-01-14T20:04:51Z"),
            dateService.iso8601SecondsDateParse("2010-01-14T20:05:02Z"),
            dateService.iso8601SecondsDateParse("2010-01-15T20:05:02Z"),
            new ReferenceTypeImpl(
                "188849-96",
                VCloudMediaType.VAPP_XML,
                URI.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-96")),
            null);
    assertEquals(result, expects);
  }
 public void test() {
   assertEquals(
       handler.apply(
           HttpResponse.builder()
               .statusCode(200)
               .message("ok")
               .payload(ParseSandboxFromJsonTest.class.getResourceAsStream("/sandbox.json"))
               .build()),
       Sandbox.builder()
           .rev("1-8c27b0ea4c2b7aaedbb44cfbdfcc11b2")
           .isCompleted(false)
           .createTime(dateService.iso8601SecondsDateParse("2010-07-07T03:36:00+00:00"))
           .name("f9d6d9b72bae465890aae87969f98a9c")
           .guid("f9d6d9b72bae465890aae87969f98a9c")
           .build());
 }
 @Override
 public void endElement(String uri, String name, String qName) {
   if (qName.equals("AccessKeyId")) {
     builder.accessKeyId(currentOrNull(currentText));
   } else if (qName.equals("SecretAccessKey")) {
     builder.secretAccessKey(currentOrNull(currentText));
   } else if (qName.equals("SessionToken")) {
     builder.sessionToken(currentOrNull(currentText));
   } else if (qName.equals("Expiration")) {
     try {
       builder.expiration(dateService.iso8601SecondsDateParse(currentOrNull(currentText)));
     } catch (IllegalArgumentException e) {
       builder.expiration(dateService.iso8601DateParse(currentOrNull(currentText)));
     }
   }
   currentText.setLength(0);
 }