com.google.common.reflect.Invokable Java Examples

The following examples show how to use com.google.common.reflect.Invokable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testDeleteSecurityGroup() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "deleteSecurityGroupInRegionById", String.class,
         String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "id"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, "Action=DeleteSecurityGroup&GroupId=id",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);

   checkFilters(request);
}
 
Example #2
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testGetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "getUserDataForInstanceInRegion", String.class,
         String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request,
         "Action=DescribeInstanceAttribute&Attribute=userData&InstanceId=1",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, UnencodeStringValueHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #3
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testGetRootDeviceNameForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "getRootDeviceNameForInstanceInRegion", String.class,
         String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request,
         "Action=DescribeInstanceAttribute&Attribute=rootDeviceName&InstanceId=1",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, StringValueHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #4
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testGetDisableApiTerminationForInstanceInRegion() throws SecurityException, NoSuchMethodException,
      IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "isApiTerminationDisabledForInstanceInRegion",
         String.class, String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request,
         "Action=DescribeInstanceAttribute&Attribute=disableApiTermination&InstanceId=1",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, BooleanValueHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #5
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testGetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "getInstanceTypeForInstanceInRegion", String.class,
         String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request,
         "Action=DescribeInstanceAttribute&Attribute=instanceType&InstanceId=1",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, InstanceTypeHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #6
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testGetInstanceInitiatedShutdownBehaviorForInstanceInRegion() throws SecurityException,
      NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "getInstanceInitiatedShutdownBehaviorForInstanceInRegion",
         String.class, String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(
         request,
         "Action=DescribeInstanceAttribute&Attribute=instanceInitiatedShutdownBehavior&InstanceId=1",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, InstanceInitiatedShutdownBehaviorHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #7
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testGetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException,
      IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "getBlockDeviceMappingForInstanceInRegion", String.class,
         String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request,
         "Action=DescribeInstanceAttribute&Attribute=blockDeviceMapping&InstanceId=1",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, BlockDeviceMappingHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #8
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testSetUserDataForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "setUserDataForInstanceInRegion", String.class, String.class,
            byte[].class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", "test".getBytes()));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(setUserDataForInstance).getPayload().getRawContent().toString(),
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #9
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testSetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "setRamdiskForInstanceInRegion", String.class, String.class,
            String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", "test"));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(setRamdiskForInstance).getPayload().getRawContent().toString(),
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #10
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testSetKernelForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "setKernelForInstanceInRegion", String.class, String.class,
            String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", "test"));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(setKernelForInstance).getPayload().getRawContent().toString(),
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #11
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testSetApiTerminationDisabledForInstanceInRegion() throws SecurityException, NoSuchMethodException,
         IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "setApiTerminationDisabledForInstanceInRegion", String.class,
            String.class, boolean.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", true));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(setApiTerminationDisabled).getPayload().getRawContent().toString(),
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #12
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testSetInstanceTypeForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "setInstanceTypeForInstanceInRegion", String.class,
            String.class, String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", InstanceType.C1_MEDIUM));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(instanceTypeForInstance).getPayload().getRawContent().toString(),
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #13
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion() throws SecurityException,
         NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "setInstanceInitiatedShutdownBehaviorForInstanceInRegion",
            String.class, String.class, InstanceInitiatedShutdownBehavior.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", InstanceInitiatedShutdownBehavior.TERMINATE));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(setInstanceInitiatedShutdownBehavior).getPayload().getRawContent()
         .toString(), "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #14
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException,
      IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "setBlockDeviceMappingForInstanceInRegion", String.class,
         String.class, Map.class);

   Map<String, BlockDevice> mapping = Maps.newLinkedHashMap();
   mapping.put("/dev/sda1", new BlockDevice("vol-test1", true));
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", mapping));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(setBlockDeviceMapping).getPayload().getRawContent().toString(),
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #15
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testGetRamdiskForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "getRamdiskForInstanceInRegion", String.class,
         String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request,
         "Action=DescribeInstanceAttribute&Attribute=ramdisk&InstanceId=1",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, StringValueHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #16
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testDescribeSecurityGroups() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "describeSecurityGroupsInRegionById", String.class,
         String[].class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList((String) null));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, "Action=DescribeSecurityGroups",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, AWSEC2DescribeSecurityGroupsResponseHandler.class);
   assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);

   checkFilters(request);
}
 
Example #17
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testDescribeSecurityGroupsArgs() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "describeSecurityGroupsInRegionById", String.class,
         String[].class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", "2"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, "Action=DescribeSecurityGroups&GroupId.1=1&GroupId.2=2",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, AWSEC2DescribeSecurityGroupsResponseHandler.class);
   assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);

   checkFilters(request);
}
 
Example #18
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "createSecurityGroupInRegion", String.class,
         String.class, String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "name", "description"));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, "Action=CreateSecurityGroup&GroupName=name&GroupDescription=description&Version=2014-02-01",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #19
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testAuthorizeSecurityGroupIpPermission() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "authorizeSecurityGroupIngressInRegion",
         String.class, String.class, IpPermission.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "group", IpPermissions.permitAnyProtocol()));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(
         request,
         "Action=AuthorizeSecurityGroupIngress&GroupId=group&IpPermissions.0.IpProtocol=-1&IpPermissions.0.FromPort=1&IpPermissions.0.ToPort=65535&IpPermissions.0.IpRanges.0.CidrIp=0.0.0.0/0",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #20
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testAuthorizeSecurityGroupIpPermissions() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "authorizeSecurityGroupIngressInRegion",
         String.class, String.class, Iterable.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "group", ImmutableSet.<IpPermission> of(IpPermissions
         .permit(IpProtocol.TCP).originatingFromCidrBlock("1.1.1.1/32"), IpPermissions.permitICMP().type(8).andCode(0)
         .originatingFromSecurityGroupId("groupId"))));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(
         request,
         "Action=AuthorizeSecurityGroupIngress&GroupId=group&IpPermissions.0.IpProtocol=tcp&IpPermissions.0.FromPort=1&IpPermissions.0.ToPort=65535&IpPermissions.0.IpRanges.0.CidrIp=1.1.1.1/32&IpPermissions.1.IpProtocol=icmp&IpPermissions.1.FromPort=8&IpPermissions.1.ToPort=0&IpPermissions.1.Groups.0.GroupId=groupId",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #21
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testRevokeSecurityGroupIpPermission() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "revokeSecurityGroupIngressInRegion", String.class,
         String.class, IpPermission.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "group", IpPermissions.permitAnyProtocol()));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(
         request,
         "Action=RevokeSecurityGroupIngress&GroupId=group&IpPermissions.0.IpProtocol=-1&IpPermissions.0.FromPort=1&IpPermissions.0.ToPort=65535&IpPermissions.0.IpRanges.0.CidrIp=0.0.0.0/0",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #22
Source File: AWSSecurityGroupApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testRevokeSecurityGroupIpPermissions() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSSecurityGroupApi.class, "revokeSecurityGroupIngressInRegion", String.class,
         String.class, Iterable.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "group", ImmutableSet.<IpPermission> of(IpPermissions
         .permit(IpProtocol.TCP).originatingFromCidrBlock("1.1.1.1/32"), IpPermissions.permitICMP().type(8).andCode(0)
         .originatingFromSecurityGroupId("groupId"))));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(
         request,
         "Action=RevokeSecurityGroupIngress&GroupId=group&IpPermissions.0.IpProtocol=tcp&IpPermissions.0.FromPort=1&IpPermissions.0.ToPort=65535&IpPermissions.0.IpRanges.0.CidrIp=1.1.1.1/32&IpPermissions.1.IpProtocol=icmp&IpPermissions.1.FromPort=8&IpPermissions.1.ToPort=0&IpPermissions.1.Groups.0.GroupId=groupId",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #23
Source File: AWSKeyPairApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testImportKeyPair() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSKeyPairApi.class, "importKeyPairInRegion", String.class, String.class,
         String.class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "mykey", "ssh-rsa AA"));

   request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request);

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, filter.filter(importKeyPair).getPayload().getRawContent().toString(),
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, KeyPairResponseHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #24
Source File: AWSKeyPairApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testDescribeKeyPairs() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSKeyPairApi.class, "describeKeyPairsInRegion", String.class,
         String[].class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList((String) null));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, "Action=DescribeKeyPairs", "application/x-www-form-urlencoded",
         false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
   assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);

   checkFilters(request);
}
 
Example #25
Source File: AWSKeyPairApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testDescribeKeyPairsArgs() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSKeyPairApi.class, "describeKeyPairsInRegion", String.class,
         String[].class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", "2"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, "Action=DescribeKeyPairs&KeyName.1=1&KeyName.2=2",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, DescribeKeyPairsResponseHandler.class);
   assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);

   checkFilters(request);
}
 
Example #26
Source File: GuavaReflectionUtilsUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenInvokable_whenCheckFinalMethod_shouldReturnFalseForIsOverridable() throws NoSuchMethodException {
    //given
    Method method = CustomClass.class.getMethod("notOverridablePublicMethod");
    Invokable<CustomClass, ?> invokable = new TypeToken<CustomClass>() {
    }.method(method);

    //when
    boolean isOverridableStandardJava = (!(Modifier.isFinal(method.getModifiers()) || Modifier.isPrivate(method.getModifiers())
            || Modifier.isStatic(method.getModifiers())
            || Modifier.isFinal(method.getDeclaringClass().getModifiers())));
    boolean isOverridableFinalGauava = invokable.isOverridable();

    //then
    assertFalse(isOverridableStandardJava);
    assertFalse(isOverridableFinalGauava);
}
 
Example #27
Source File: AnnotatedAuroraAdminTest.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Test
public void testAllAuroraSchedulerManagerIfaceMethodsHaveAuthorizingParam() throws Exception {
  for (Method declaredMethod : AuroraSchedulerManager.Iface.class.getDeclaredMethods()) {
    Invokable<?, ?> invokable = Invokable.from(declaredMethod);
    Collection<Parameter> parameters = invokable.getParameters();
    Invokable<?, ?> annotatedInvokable = Invokable.from(
        AnnotatedAuroraAdmin.class.getDeclaredMethod(
            invokable.getName(),
            FluentIterable.from(parameters)
                .transform(input -> input.getType().getRawType())
                .toList()
                .toArray(new Class<?>[0])));

    Collection<Parameter> annotatedParameters = Collections2.filter(
        annotatedInvokable.getParameters(),
        input -> input.getAnnotation(AuthorizingParam.class) != null);

    assertFalse(
        "Method " + invokable + " should have at least 1 " + AuthorizingParam.class.getName()
            + " annotation but none were found.",
        annotatedParameters.isEmpty());
  }
}
 
Example #28
Source File: AWSInstanceApiTest.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public void testRebootInstances() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "rebootInstancesInRegion", String.class,
         String[].class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "1", "2"));

   assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1");
   assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n");
   assertPayloadEquals(request, "Action=RebootInstances&InstanceId.1=1&InstanceId.2=2",
         "application/x-www-form-urlencoded", false);

   assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
   assertSaxResponseParserClassEquals(method, null);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example #29
Source File: Methods.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private static @Nullable String invocationFailureReason(Invokable<?, ?> to, Invokable<?, ?> from) {
    final String reason = invocationFailureReason(methodType(to), methodType(from));
    if(reason != null) return reason;

    thrownLoop: for(TypeToken<? extends Throwable> thrown : from.getExceptionTypes()) {
        final Class<?> thrownRaw = thrown.getRawType();
        if(Error.class.isAssignableFrom(thrownRaw)) continue;
        if(RuntimeException.class.isAssignableFrom(thrownRaw)) continue ;
        for(TypeToken<? extends Throwable> caught : to.getExceptionTypes()) {
            if(caught.getRawType().isAssignableFrom(thrownRaw)) continue thrownLoop;
        }
        return "unhandled exception " + thrown.getRawType().getName();
    }

    return null;
}
 
Example #30
Source File: Delegates.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
MethodHandle createHandle(Method rawProxyMethod, Invokable<T, ?> proxyMethod) throws ReflectiveOperationException {
    if(proxyMethod.getReturnType().getRawType().equals(void.class)) {
        if(proxyMethod.getParameters().size() == 1) {
            return lookup.findStaticSetter(targetType,
                                           proxyMethod.getName(),
                                           proxyMethod.getParameters().get(0).getType().getRawType());
        }
    } else {
        if(proxyMethod.getParameters().isEmpty()) {
            return lookup.findStaticGetter(targetType,
                                           proxyMethod.getName(),
                                           proxyMethod.getReturnType().getRawType());
        }
    }

    throw new MethodFormException(rawProxyMethod, "Field delegate method does not have a getter or setter signature");
}