public void bindToRequest(HttpRequest request, Object input) { checkArgument(checkNotNull(input, "input") instanceof Iterable<?>, "this binder is only valid for Iterable<?>: " + input.getClass()); checkValidUserGroup(input); indexIterableToFormValuesWithPrefix(request, "UserGroup", input); }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof LaunchSpecification, "this binder is only valid for LaunchSpecifications!"); LaunchSpecification launchSpec = LaunchSpecification.class.cast(input); return (R) request.toBuilder().replaceFormParams(Multimaps.forMap(apply(launchSpec))).build(); }
@Test(expectedExceptions = NullPointerException.class) public void testNullIsBad() { HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build(); binder.bindToRequest(request, null); } }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof LaunchSpecification, "this binder is only valid for LaunchSpecifications!"); LaunchSpecification launchSpec = LaunchSpecification.class.cast(input); return (R) request.toBuilder().replaceFormParams(Multimaps.forMap(apply(launchSpec))).build(); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testMustBeArray() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build(); binder.bindToRequest(request, new File("foo")); }
@SuppressWarnings("unchecked") @Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { checkArgument(input instanceof LaunchSpecification, "this binder is only valid for LaunchSpecifications!"); LaunchSpecification launchSpec = LaunchSpecification.class.cast(input); return (R) request.toBuilder().replaceFormParams(Multimaps.forMap(apply(launchSpec))).build(); }
public void test() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build(); request = binder.bindToRequest(request, ImmutableMap.<String, String>builder().put("one", "alpha").put("two", "beta").build()); assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=one&Tag.1.Value=alpha&Tag.2.Key=two&Tag.2.Value=beta"); }
@Test public void testApplyWithUserData() throws UnknownHostException { LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123") .userData("hello".getBytes()).build(); assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.UserData", base64().encode("hello".getBytes(UTF_8)))); }
public void testEmpty() { HttpRequest request = HttpRequest.builder().method("POST").endpoint("http://localhost").build(); request = binder.bindToRequest(request, ImmutableMap.<String, String>builder().put("empty", "").build()); assertEquals(request.getPayload().getRawContent(), "Tag.1.Key=empty&Tag.1.Value="); }
@Test public void testApplyWithIAMInstanceProfileArn() { LaunchSpecification spec = LaunchSpecification.builder() .instanceType(InstanceType.T1_MICRO) .imageId("ami-123") .iamInstanceProfileArn("arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver") .build(); assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.IamInstanceProfile.Arn", "arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver")); }
@Test public void testApplyWithSecurityId() throws UnknownHostException { LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123") .securityGroupId("sid-foo").build(); assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.SecurityGroupId.1", "sid-foo")); }
@Test public void testApplyWithSubnetId() throws UnknownHostException { LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123") .subnetId("subnet-xyz").build(); assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.SubnetId", "subnet-xyz")); }
@Test public void testApplyWithBlockDeviceMappings() throws UnknownHostException { LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123") .mapNewVolumeToDevice("/dev/sda1", 120, true).build(); assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.BlockDeviceMapping.1.DeviceName", "/dev/sda1", "LaunchSpecification.BlockDeviceMapping.1.Ebs.VolumeSize", "120", "LaunchSpecification.BlockDeviceMapping.1.Ebs.DeleteOnTermination", "true")); }
@Test public void testApplyWithIAMInstanceProfileName() { LaunchSpecification spec = LaunchSpecification.builder().instanceType(InstanceType.T1_MICRO).imageId("ami-123") .iamInstanceProfileName("Webserver").build(); assertEquals(binder.apply(spec), ImmutableMap.of("LaunchSpecification.InstanceType", "t1.micro", "LaunchSpecification.ImageId", "ami-123", "LaunchSpecification.IamInstanceProfile.Name", "Webserver")); } }