Code example for ImmutableMap.Builder

Methods: build, put, putAll

0
           .createTime(dateService.iso8601DateParse("2009-12-28T05:42:53.000Z")) 
           .build(); 
    
   public void testCreateVolumeInAvailabilityZone() { 
      Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
      builder.put(describeRegionsRequest, describeRegionsResponse);
      builder.putAll(describeAvailabilityZonesRequestResponse);
      builder.put(
            HttpRequest.builder()
                       .method("POST") 
                       .endpoint("https://ec2.us-east-1.amazonaws.com/") 
                       .addHeader("Host", "ec2.us-east-1.amazonaws.com") 
                       .payload(payloadFromStringWithContentType("Action=CreateVolume&AvailabilityZone=us-east-1a&Signature=NCu8HU8u0A385rTgj%2BN5lq606jkc1eu88jof9yAxb6s%3D&SignatureMethod=HmacSHA256&SignatureVersion=2&Size=4&Timestamp=2012-04-16T15%3A54%3A08.897Z&Version=2010-08-31&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(), 
            HttpResponse.builder()
                        .statusCode(200) 
                        .payload(payloadFromResource("/created_volume.xml")).build()); 
       
      ElasticBlockStoreApi client = requestsSendResponses(builder.build()).getElasticBlockStoreApi().get();
 
      assertEquals(client.createVolumeInAvailabilityZone("us-east-1a", 4), creating);
   } 
 
   public void testCreateVolumeInAvailabilityZoneWithOptions() { 
      Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
      builder.put(describeRegionsRequest, describeRegionsResponse);
      builder.putAll(describeAvailabilityZonesRequestResponse);
      builder.put(
              HttpRequest.builder()
                      .method("POST") 
                      .endpoint("https://ec2.us-east-1.amazonaws.com/") 
                      .addHeader("Host", "ec2.us-east-1.amazonaws.com") 
                      .payload(payloadFromStringWithContentType("Action=CreateVolume" + 
                              "&AvailabilityZone=us-east-1a" + 
                              "&Iops=0" + 
                              "&Signature=uI5tXrwV4zXB3uh0OP4RkfU2HMdQ2yICfpo4gKrajMI%3D" + 
                              "&SignatureMethod=HmacSHA256" + 
                              "&SignatureVersion=2" + 
                              "&Size=4" + 
                              "&Timestamp=2012-04-16T15%3A54%3A08.897Z" + 
                              "&Version=2010-08-31" + 
                              "&VolumeType=standard" + 
                              "&AWSAccessKeyId=identity", "application/x-www-form-urlencoded")).build(), 
              HttpResponse.builder()
                      .statusCode(200) 
                      .payload(payloadFromResource("/created_volume.xml")).build()); 
 
      ElasticBlockStoreApi client = requestsSendResponses(builder.build()).getElasticBlockStoreApi().get();
 
      assertEquals(client.createVolumeInAvailabilityZone("us-east-1a",
              CreateVolumeOptions.Builder.withSize(4).isEncrypted(false).volumeType("standard").withIops(0)), 
              creating);
   } 
 
   public void testCreateVolumeFromSnapshotInAvailabilityZoneEuSetsCorrectEndpoint() { 
      String region = "eu-west-1";
       
      Builder<HttpRequest, HttpResponse> builder = ImmutableMap.<HttpRequest, HttpResponse>builder();
      builder.put(describeRegionsRequest, describeRegionsResponse);
      builder.putAll(describeAvailabilityZonesRequestResponse);
      builder.put(
            formSigner.filter(HttpRequest.builder()
                    .method("POST") 
                    .endpoint("https://ec2." + region + ".amazonaws.com/")
                    .addHeader("Host", "ec2." + region + ".amazonaws.com")
                    .addFormParam("Action", "CreateVolume") 
                    .addFormParam("AvailabilityZone", "eu-west-1a") 
                    .addFormParam("Size", "1") 
                    .addFormParam("SnapshotId", "snap-8b7ffbdd") 
                    .build()), 
              HttpResponse.builder()
                      .statusCode(200) 
                      .payload(payloadFromResource("/created_volume.xml")).build()); 
       
      ElasticBlockStoreApi client = requestsSendResponses(builder.build()).getElasticBlockStoreApi().get();
 
      assertEquals(client.createVolumeFromSnapshotInAvailabilityZone(region + "a", 1, "snap-8b7ffbdd"), creating.toBuilder().region(region).build());
   } 
 
   HttpRequest filterVolumes = HttpRequest.builder().method("POST")
           .endpoint("https://ec2.us-east-1.amazonaws.com/") 
           .addHeader("Host", "ec2.us-east-1.amazonaws.com") 
           .addFormParam("Action", "DescribeVolumes") 
           .addFormParam("Filter.1.Name", "snapshot-id") 
           .addFormParam("Filter.1.Value.1", "snap-536d1b3a") 
           .addFormParam("Signature", "7g2ySW39nIVfxtIbuVttUBom7sssmQknxX/9SThkm2Y%3D") 
           .addFormParam("SignatureMethod", "HmacSHA256") 
           .addFormParam("SignatureVersion", "2") 
           .addFormParam("Timestamp", "2012-04-16T15%3A54%3A08.897Z") 
           .addFormParam("Version", "2010-08-31") 
           .addFormParam("AWSAccessKeyId", "identity").build(); 
 
   public void testFilterVolumesWhenResponseIs2xx() { 
      HttpResponse filterResponse = HttpResponse.builder().statusCode(200)
              .payload(payloadFromResourceWithContentType("/describe_volumes_single.xml", "text/xml")).build(); 
 
      EC2Api apiWhenExist = requestsSendResponses(describeRegionsRequest, describeRegionsResponse, filterVolumes, filterResponse);
 
      Volume volume = getOnlyElement(apiWhenExist.getElasticBlockStoreApi().get().describeVolumesInRegionWithFilter("us-east-1",
              ImmutableMultimap.<String, String>builder()
                      .put("snapshot-id", "snap-536d1b3a")
                      .build()));
 
Experience pair programming with AI  Get Codota for Java