예제 #1
0
  @Deprecated
  public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        VCloudAsyncClient.class.getMethod(
            "cloneVAppInVDC", URI.class, URI.class, String.class, CloneVAppOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method,
            URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
            URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"),
            "my-vapp");

    assertRequestLineEquals(
        request, "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml")),
        "application/vnd.vmware.vcloud.cloneVAppParams+xml",
        false);

    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, TaskHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
  public void testAllOptions() throws IOException {

    String expected =
        Strings2.toStringAndClose(
            getClass().getResourceAsStream("/InstantiateVAppTemplateParams-options-test.xml"));
    Multimap<String, String> headers =
        Multimaps.synchronizedMultimap(HashMultimap.<String, String>create());
    GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
    expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
    expect(request.getArgs())
        .andReturn(
            ImmutableList.<Object>of(
                InstantiateVAppTemplateOptions.Builder.processorCount(2)
                    .memory(512)
                    .inGroup("group")
                    .withPassword("password")
                    .inRow("row")
                    .addNetworkConfig(new NetworkConfig(URI.create("http://network")))))
        .atLeastOnce();
    expect(request.getFirstHeaderOrNull("Content-Type"))
        .andReturn("application/unknown")
        .atLeastOnce();
    expect(request.getHeaders()).andReturn(headers).atLeastOnce();
    request.setPayload(expected);
    replay(request);

    BindInstantiateVAppTemplateParamsToXmlPayload binder =
        injector.getInstance(BindInstantiateVAppTemplateParamsToXmlPayload.class);

    Map<String, String> map = Maps.newHashMap();
    map.put("name", "name");
    map.put("template", "https://vcloud/vAppTemplate/3");
    binder.bindToRequest(request, map);
  }
  private void assertCodeMakes(
      String method,
      URI uri,
      int statusCode,
      String message,
      String contentType,
      String content,
      Class<? extends Exception> expected) {

    ElasticStackErrorHandler function =
        Guice.createInjector().getInstance(ElasticStackErrorHandler.class);

    HttpCommand command = createMock(HttpCommand.class);
    HttpRequest request = new HttpRequest(method, uri);
    HttpResponse response =
        new HttpResponse(
            statusCode, message, Payloads.newInputStreamPayload(Strings2.toInputStream(content)));
    response.getPayload().getContentMetadata().setContentType(contentType);

    expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
    command.setException(classEq(expected));

    replay(command);

    function.handleError(command, response);

    verify(command);
  }
예제 #4
0
  public void testCaptureVAppInVDCOptions()
      throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        VCloudAsyncClient.class.getMethod(
            "captureVAppInVDC", URI.class, URI.class, String.class, CaptureVAppOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method,
            URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
            URI.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"),
            "my-template",
            new CaptureVAppOptions().withDescription("The description of the new vApp Template"));

    assertRequestLineEquals(
        request,
        "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
    assertNonPayloadHeadersEqual(
        request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp.xml")),
        "application/vnd.vmware.vcloud.captureVAppParams+xml",
        false);

    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
  public void testAddInternetServiceOptions()
      throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        TerremarkVCloudExpressAsyncClient.class.getMethod(
            "addInternetServiceToVDC",
            URI.class,
            String.class,
            Protocol.class,
            int.class,
            AddInternetServiceOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method,
            URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
            "name",
            Protocol.TCP,
            22,
            disabled().withDescription("yahoo"));

    assertRequestLineEquals(
        request, "POST https://vcloud.safesecureweb.com/api/v0.8/internetServices/1 HTTP/1.1");
    assertNonPayloadHeadersEqual(
        request, "Accept: application/vnd.tmrk.vCloud.internetService+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(
            getClass().getResourceAsStream("/CreateInternetService-options-test.xml")),
        "application/vnd.tmrk.vCloud.internetService+xml",
        false);
    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
  public void testInstantiateVAppTemplateInVDCURI()
      throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        TerremarkVCloudExpressAsyncClient.class.getMethod(
            "instantiateVAppTemplateInVDC",
            URI.class,
            URI.class,
            String.class,
            InstantiateVAppTemplateOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method,
            URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
            URI.create("https://vcloud/vAppTemplate/3"),
            "name");

    assertRequestLineEquals(
        request,
        "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(
            getClass().getResourceAsStream("/InstantiateVAppTemplateParams-test.xml")),
        "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
        false);

    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, VAppHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
  public void testAddInternetServiceToExistingIp()
      throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        TerremarkVCloudExpressAsyncClient.class.getMethod(
            "addInternetServiceToExistingIp",
            URI.class,
            String.class,
            Protocol.class,
            int.class,
            AddInternetServiceOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method, URI.create("https://vcloud/extensions/publicIp/12"), "name", Protocol.TCP, 22);

    assertRequestLineEquals(
        request, "POST https://vcloud/extensions/publicIp/12/internetServices HTTP/1.1");
    assertNonPayloadHeadersEqual(
        request, "Accept: application/vnd.tmrk.vCloud.internetService+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(
            getClass().getResourceAsStream("/CreateInternetService-test2.xml")),
        "application/vnd.tmrk.vCloud.internetService+xml",
        false);

    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
  public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        TerremarkVCloudExpressAsyncClient.class.getMethod(
            "addNode", URI.class, String.class, String.class, int.class, AddNodeOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method,
            URI.create("https://vcloud/extensions/internetService/12"),
            "10.2.2.2",
            "name",
            22,
            AddNodeOptions.Builder.disabled().withDescription("yahoo"));

    assertRequestLineEquals(
        request, "POST https://vcloud/extensions/internetService/12/nodeServices HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "Accept: application/vnd.tmrk.vCloud.nodeService+xml\n");

    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(
            getClass().getResourceAsStream("/CreateNodeService-options-test.xml")),
        "application/vnd.tmrk.vCloud.nodeService+xml",
        false);
    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, NodeHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
예제 #9
0
  public void testUpdateGuestConfiguration()
      throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        VCloudAsyncClient.class.getMethod(
            "updateGuestCustomizationOfVm", URI.class, GuestCustomizationSection.class);
    GuestCustomizationSection guest =
        new GuestCustomizationSection(
            URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection"));
    guest.setCustomizationScript("cat > /tmp/foo.txt<<EOF\nI love candy\nEOF");
    HttpRequest request =
        processor.createRequest(
            method, URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), guest);

    assertRequestLineEquals(
        request,
        "PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(getClass().getResourceAsStream("/guestCustomizationSection.xml")),
        "application/vnd.vmware.vcloud.guestCustomizationSection+xml",
        false);

    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, TaskHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
 public void testWeCanReadAndWriteToDrive() throws IOException {
   drive2 =
       client.createDrive(
           new CreateDriveRequest.Builder().name(prefix + "2").size(1 * 1024 * 1024l).build());
   client.writeDrive(drive2.getUuid(), Payloads.newStringPayload("foo"));
   assertEquals(Strings2.toString(client.readDrive(drive2.getUuid(), 0, 3)), "foo");
 }
 @Test(groups = {"integration", "live"})
 public void testPut() throws IOException, InterruptedException {
   String bucketName = getContainerName();
   try {
     Map<String, Blob> map = createMap(context, bucketName);
     Blob blob = context.getBlobStore().newBlob("one");
     blob.setPayload(Strings2.toInputStream("apple"));
     Payloads.calculateMD5(blob);
     Blob old = map.put(blob.getMetadata().getName(), blob);
     getOneReturnsAppleAndOldValueIsNull(map, old);
     blob.setPayload(Strings2.toInputStream("bear"));
     Payloads.calculateMD5(blob);
     Blob apple = map.put(blob.getMetadata().getName(), blob);
     getOneReturnsBearAndOldValueIsApple(map, apple);
   } finally {
     returnContainer(bucketName);
   }
 }
 public void testPutAndGet() throws IOException {
   temp = File.createTempFile("foo", "bar");
   temp.deleteOnExit();
   SshClient client = setupClient();
   client.put(temp.getAbsolutePath(), Payloads.newStringPayload("rabbit"));
   Payload input = setupClient().get(temp.getAbsolutePath());
   String contents = Strings2.toStringAndClose(input.getInput());
   assertEquals(contents, "rabbit");
 }
 public String parseMessage(final HttpResponse response) {
   if (response.getPayload() == null) {
     return null;
   }
   try {
     return Strings2.toStringAndClose(response.getPayload().openStream());
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
예제 #14
0
  public void testMultipleParts() throws IOException {

    StringBuilder builder = new StringBuilder();
    addData(boundary, "hello", builder);
    addData(boundary, "goodbye", builder);

    builder.append("--").append(boundary).append("--").append("\r\n");
    String expects = builder.toString();

    assertEquals(expects.length(), 352);

    MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"), newPart("goodbye"));

    assertEquals(Strings2.toString(multipartForm), expects);

    // test repeatable
    assert multipartForm.isRepeatable();
    assertEquals(Strings2.toString(multipartForm), expects);
    assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(352));
  }
예제 #15
0
 @Override
 public ExecResponse create() throws Exception {
   try {
     ConnectionWithStreams<ChannelExec> connection = execConnection(command);
     executor = acquire(connection);
     String outputString = Strings2.toStringAndClose(connection.getInputStream());
     String errorString = Strings2.toStringAndClose(connection.getErrStream());
     int errorStatus = executor.getExitStatus();
     int i = 0;
     String message = String.format("bad status -1 %s", toString());
     while ((errorStatus = executor.getExitStatus()) == -1
         && i < JschSshClient.this.sshRetries) {
       logger.warn("<< " + message);
       backoffForAttempt(++i, message);
     }
     if (errorStatus == -1) throw new SshException(message);
     return new ExecResponse(outputString, errorString, errorStatus);
   } finally {
     clear();
   }
 }
  public void testRanges() throws IOException {
    blobStore.createContainerInLocation(null, CONTAINER_NAME);
    String input = "abcdefgh";
    Payload payload;
    Blob blob = blobStore.blobBuilder("test").payload(new StringPayload(input)).build();
    blobStore.putBlob(CONTAINER_NAME, blob);

    GetOptions getOptionsRangeStartAt = new GetOptions();
    getOptionsRangeStartAt.startAt(1);
    Blob blobRangeStartAt =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeStartAt);
    payload = blobRangeStartAt.getPayload();
    try {
      assertEquals(input.substring(1), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }

    GetOptions getOptionsRangeTail = new GetOptions();
    getOptionsRangeTail.tail(3);
    Blob blobRangeTail =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsRangeTail);
    payload = blobRangeTail.getPayload();
    try {
      assertEquals(input.substring(5), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }

    GetOptions getOptionsFragment = new GetOptions();
    getOptionsFragment.range(4, 6);
    Blob blobFragment =
        blobStore.getBlob(CONTAINER_NAME, blob.getMetadata().getName(), getOptionsFragment);
    payload = blobFragment.getPayload();
    try {
      assertEquals(input.substring(4, 7), Strings2.toString(payload));
    } finally {
      Closeables.closeQuietly(payload);
    }
  }
예제 #17
0
  public void testSinglePart() throws IOException {

    StringBuilder builder = new StringBuilder();
    addData(boundary, "hello", builder);
    builder.append("--").append(boundary).append("--").append("\r\n");
    String expects = builder.toString();
    assertEquals(expects.length(), 199);

    MultipartForm multipartForm = new MultipartForm(boundary, newPart("hello"));

    assertEquals(Strings2.toString(multipartForm), expects);
    assertEquals(multipartForm.getContentMetadata().getContentLength(), Long.valueOf(199));
  }
  public void testDefault() throws Exception {
    String expected =
        Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml"));

    GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object>of());

    BindCloneVAppParamsToXmlPayload binder =
        injector.getInstance(BindCloneVAppParamsToXmlPayload.class);

    Map<String, Object> map = Maps.newHashMap();
    map.put("newName", "my-vapp");
    map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181");
    assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected);
  }
  @VisibleForTesting
  HttpRequest calculateAndReplaceAuthorizationHeaders(HttpRequest request, String toSign)
      throws HttpException {
    String signature = sign(toSign);
    if (signatureWire.enabled()) signatureWire.input(Strings2.toInputStream(signature));
    String[] signatureLines =
        Iterables.toArray(Splitter.fixedLength(60).split(signature), String.class);

    Multimap<String, String> headers = ArrayListMultimap.create();
    for (int i = 0; i < signatureLines.length; i++) {
      headers.put("X-Ops-Authorization-" + (i + 1), signatureLines[i]);
    }
    return request.toBuilder().replaceHeaders(headers).build();
  }
예제 #20
0
 static String requestPayloadIfStringOrFormIfNotReturnEmptyString(HttpRequest request) {
   if (request.getPayload() != null
       && ("application/x-www-form-urlencoded"
               .equals(request.getPayload().getContentMetadata().getContentType())
           || request.getPayload() instanceof StringPayload)
       && request.getPayload().getContentMetadata().getContentLength() != null
       && request.getPayload().getContentMetadata().getContentLength() < 1024) {
     try {
       return String.format(
           " [%s] ",
           request.getPayload() instanceof StringPayload
               ? request.getPayload().getRawContent()
               : Strings2.toString(request.getPayload()));
     } catch (IOException e) {
     }
   }
   return "";
 }
  public void testWithDescriptionDeployOn() throws Exception {
    String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml"));

    CloneVAppOptions options =
        new CloneVAppOptions()
            .deploy()
            .powerOn()
            .withDescription("The description of the new vApp");
    GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object>of(options));

    BindCloneVAppParamsToXmlPayload binder =
        injector.getInstance(BindCloneVAppParamsToXmlPayload.class);

    Map<String, Object> map = Maps.newHashMap();
    map.put("newName", "new-linux-server");
    map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201");
    assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected);
  }
 @Test(dependsOnMethods = "testWeCanReadAndWriteToDrive")
 public void testWeCopyADriveContentsViaGzip() throws IOException {
   try {
     drive3 =
         client.createDrive(
             new CreateDriveRequest.Builder().name(prefix + "3").size(1 * 1024 * 1024l).build());
     System.err.println("before image; drive 2" + client.getDriveInfo(drive2.getUuid()));
     System.err.println("before image; drive 3" + client.getDriveInfo(drive3.getUuid()));
     client.imageDrive(drive2.getUuid(), drive3.getUuid());
     assert driveNotClaimed.apply(drive3) : client.getDriveInfo(drive3.getUuid());
     assert driveNotClaimed.apply(drive2) : client.getDriveInfo(drive2.getUuid());
     System.err.println("after image; drive 2" + client.getDriveInfo(drive2.getUuid()));
     System.err.println("after image; drive 3" + client.getDriveInfo(drive3.getUuid()));
     assertEquals(Strings2.toString(client.readDrive(drive3.getUuid(), 0, 3)), "foo");
   } finally {
     client.destroyDrive(drive2.getUuid());
     client.destroyDrive(drive3.getUuid());
   }
 }
  public void testDefault() throws IOException {
    String expected =
        Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml"));

    GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
    expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
    expect(request.getArgs()).andReturn(ImmutableList.<Object>of()).atLeastOnce();
    request.setPayload(expected);
    replay(request);

    BindCloneVCloudExpressVAppParamsToXmlPayload binder =
        injector.getInstance(BindCloneVCloudExpressVAppParamsToXmlPayload.class);

    Map<String, String> map = Maps.newHashMap();
    map.put("newName", "my-vapp");
    map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181");
    binder.bindToRequest(request, map);
    verify(request);
  }
  @Test
  public void testResponseOk() throws Exception {
    Function<HttpResponse, URI> function =
        new ParseURIFromListOrLocationHeaderIf20x(uriBuilderProvider);
    HttpResponse response = createMock(HttpResponse.class);
    Payload payload = createMock(Payload.class);

    expect(response.getStatusCode()).andReturn(200).atLeastOnce();
    expect(response.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE)).andReturn("text/uri-list");
    expect(response.getPayload()).andReturn(payload).atLeastOnce();
    expect(payload.getInput()).andReturn(Strings2.toInputStream("http://locahost")).atLeastOnce();
    payload.release();

    replay(payload);
    replay(response);
    assertEquals(function.apply(response), URI.create("http://locahost"));

    verify(payload);
    verify(response);
  }
  @DataProvider(name = "data")
  public Object[][] createData() throws IOException {
    InputStream is =
        ParseOsFamilyVersion64BitFromImageNameTest.class.getResourceAsStream("/osmatches.json");
    Map<String, OsFamilyVersion64Bit> values =
        json.fromJson(
            Strings2.toStringAndClose(is),
            new TypeLiteral<Map<String, OsFamilyVersion64Bit>>() {}.getType());

    return newArrayList(
            transform(
                values.entrySet(),
                new Function<Map.Entry<String, OsFamilyVersion64Bit>, Object[]>() {

                  @Override
                  public Object[] apply(Entry<String, OsFamilyVersion64Bit> input) {
                    return new Object[] {input.getKey(), input.getValue()};
                  }
                }))
        .toArray(new Object[][] {});
  }
  public void testInstantiateVAppTemplateInVDCURIOptions()
      throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        TerremarkVCloudExpressAsyncClient.class.getMethod(
            "instantiateVAppTemplateInVDC",
            URI.class,
            URI.class,
            String.class,
            InstantiateVAppTemplateOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method,
            URI.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/1"),
            URI.create("https://vcloud/vAppTemplate/3"),
            "name",
            TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(2)
                .memory(512)
                .inGroup("group")
                .withPassword("password")
                .inRow("row")
                .addNetworkConfig(new NetworkConfig(URI.create("http://network"))));

    assertRequestLineEquals(
        request,
        "POST https://vcloud.safesecureweb.com/api/v0.8/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(
            getClass()
                .getResourceAsStream("/terremark/InstantiateVAppTemplateParams-options-test.xml")),
        "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
        false);

    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, VCloudExpressVAppHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
  public void testComplete() throws IOException {
    CreateDriveRequest input =
        new CreateDriveRequest.Builder()
            .name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
            //
            .size(8589934592l) //
            .claimType(ClaimType.SHARED) //
            .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")) //
            .tags(ImmutableSet.of("tag1", "tag2"))
            .userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz")) //
            .encryptionCipher("aes-xts-plain")
            .avoid(ImmutableSet.of("avoid1"))
            .build();

    HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
    FN.bindToRequest(request, input);
    assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
    assertEquals(
        request.getPayload().getRawContent(),
        Strings2.toStringAndClose(
            BindDriveToPlainTextStringTest.class.getResourceAsStream("/create_drive.txt")));
  }
예제 #28
0
  public void testInstantiateVAppTemplateInVDCURIOptions()
      throws SecurityException, NoSuchMethodException, IOException {
    Method method =
        VCloudAsyncClient.class.getMethod(
            "instantiateVAppTemplateInVDC",
            URI.class,
            URI.class,
            String.class,
            InstantiateVAppTemplateOptions[].class);
    HttpRequest request =
        processor.createRequest(
            method,
            URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
            URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"),
            "my-vapp",
            addNetworkConfig(
                new NetworkConfig(
                    "aloha",
                    URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"),
                    FenceMode.NAT_ROUTED)));

    assertRequestLineEquals(
        request,
        "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
    assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
    assertPayloadEquals(
        request,
        Strings2.toStringAndClose(
            getClass().getResourceAsStream("/instantiationparams-network.xml")),
        "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
        false);

    assertResponseParserClassEquals(method, request, ParseSax.class);
    assertSaxResponseParserClassEquals(method, VAppHandler.class);
    assertExceptionParserClassEquals(method, null);

    checkFilters(request);
  }
  private void assertCodeMakes(
      String method,
      URI uri,
      int statusCode,
      String message,
      String contentType,
      String content,
      Class<? extends Exception> expected) {

    ParseAzureBlobErrorFromXmlContent function =
        Guice.createInjector(
                new SaxParserModule(),
                new AbstractModule() {

                  @Override
                  protected void configure() {
                    bind(SharedKeyLiteAuthentication.class)
                        .toInstance(createMock(SharedKeyLiteAuthentication.class));
                  }
                })
            .getInstance(ParseAzureBlobErrorFromXmlContent.class);

    HttpCommand command = createMock(HttpCommand.class);
    HttpRequest request = new HttpRequest(method, uri);
    HttpResponse response =
        new HttpResponse(
            statusCode, message, Payloads.newInputStreamPayload(Strings2.toInputStream(content)));
    response.getPayload().getContentMetadata().setContentType(contentType);

    expect(command.getCurrentRequest()).andReturn(request).atLeastOnce();
    command.setException(classEq(expected));

    replay(command);

    function.handleError(command, response);

    verify(command);
  }
  public void testWithDescriptionDeployOn() throws IOException {
    String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml"));

    CloneVAppOptions options =
        new CloneVAppOptions()
            .deploy()
            .powerOn()
            .withDescription("The description of the new vApp");
    GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
    expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
    expect(request.getArgs()).andReturn(ImmutableList.<Object>of(options)).atLeastOnce();
    request.setPayload(expected);
    replay(request);

    BindCloneVCloudExpressVAppParamsToXmlPayload binder =
        injector.getInstance(BindCloneVCloudExpressVAppParamsToXmlPayload.class);

    Map<String, String> map = Maps.newHashMap();
    map.put("newName", "new-linux-server");
    map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/201");
    binder.bindToRequest(request, map);
    verify(request);
  }