Java Code Examples for com.google.common.reflect.Invokable

The following examples show how to use com.google.common.reflect.Invokable. These examples are extracted from open source projects. 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 Project: ProjectAres   Source File: Methods.java    License: 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 2
Source Project: ProjectAres   Source File: Delegates.java    License: 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");
}
 
Example 3
Source Project: beanmother   Source File: SetterAndFieldFixtureMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void bind(Object target, String key, FixtureMap fixtureMap) {
    List<Method> candidates = findSetterCandidates(target, key);

    for (Method candidate : candidates) {
        ImmutableList<Parameter> paramTypes = Invokable.from(candidate).getParameters();
        if (paramTypes.size() != 1) continue;

        TypeToken<?> paramType = paramTypes.get(0).getType();
        try {
            Object candidateParam = getFixtureConverter().convert(fixtureMap, paramType);
            if (candidateParam != null) {
                candidate.invoke(target, candidateParam);
                return;
            }
        } catch (Exception e) {
            throw new FixtureMappingException(e);
        }
    }

    bindByField(target, key, fixtureMap);
}
 
Example 4
Source Project: beanmother   Source File: SetterAndFieldFixtureMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void bind(Object target, String key, FixtureList fixtureList) {
    List<Method> candidates = findSetterCandidates(target, key);

    for (Method candidate :candidates) {
        try {
            ImmutableList<Parameter> paramTypes = Invokable.from(candidate).getParameters();
            if (paramTypes.size() != 1) continue;

            TypeToken<?> paramType = paramTypes.get(0).getType();
            Object candidateParam = getFixtureConverter().convert(fixtureList, paramType);

            if (candidateParam != null) {
                candidate.invoke(target, candidateParam);
                return;
            }
        } catch (Exception e) {
            throw new FixtureMappingException(e);
        }
    }

    bindByField(target, key, fixtureList);
}
 
Example 5
Source Project: beanmother   Source File: SetterAndFieldFixtureMapper.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void bind(Object target, String key, FixtureValue fixtureValue) {
    if (fixtureValue == null || fixtureValue.isNull()) return;
    List<Method> candidates = findSetterCandidates(target, key);

    for (Method candidate : candidates) {
        ImmutableList<Parameter> paramTypes = Invokable.from(candidate).getParameters();
        if (paramTypes == null || paramTypes.size() != 1) continue;
        TypeToken<?> paramType = paramTypes.get(0).getType();
        Object param = getFixtureConverter().convert(fixtureValue, paramType);
        if (param == null) continue;

        try {
            candidate.invoke(target, param);
        } catch (Exception e) {
            throw new FixtureMappingException(e);
        }
    }

    bindByField(target, key, fixtureValue);
}
 
Example 6
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testRunInstancesOptions() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "runInstancesInRegion", String.class, String.class,
         String.class, int.class, int.class, RunInstancesOptions[].class);
   GeneratedHttpRequest request = processor.createRequest(
         method,
         Lists.<Object> newArrayList("us-east-1",
         "us-east-1a",
         "ami-voo",
         1,
         5,
         new AWSRunInstancesOptions().withKernelId("kernelId").enableMonitoring()
               .withSecurityGroups("group1", "group2")));

   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=RunInstances&ImageId=ami-voo&MinCount=1&MaxCount=5&KernelId=kernelId&Monitoring.Enabled=true&SecurityGroup.1=group1&SecurityGroup.2=group2&Placement.AvailabilityZone=us-east-1a",
         "application/x-www-form-urlencoded", false);
   assertResponseParserClassEquals(method, request, ParseSax.class);
   assertSaxResponseParserClassEquals(method, AWSRunInstancesResponseHandler.class);
   assertFallbackClassEquals(method, null);

   checkFilters(request);
}
 
Example 7
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testStopInstances() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "stopInstancesInRegion", String.class, boolean.class,
         String[].class);
   GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, true, "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=StopInstances&Force=true&InstanceId.1=1&InstanceId.2=2",
         "application/x-www-form-urlencoded", false);

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

   checkFilters(request);
}
 
Example 8
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 9
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testStartInstances() throws SecurityException, NoSuchMethodException, IOException {
   Invokable<?, ?> method = method(AWSInstanceApi.class, "startInstancesInRegion", 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=StartInstances&InstanceId.1=1&InstanceId.2=2",
         "application/x-www-form-urlencoded", false);

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

   checkFilters(request);
}
 
Example 10
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 11
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 12
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 13
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 14
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 15
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 16
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 17
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 18
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 19
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 20
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 21
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 22
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 23
Source Project: attic-stratos   Source File: AWSInstanceApiTest.java    License: 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 24
Source Project: attic-stratos   Source File: AWSSecurityGroupApiTest.java    License: 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 25
Source Project: attic-stratos   Source File: AWSSecurityGroupApiTest.java    License: 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 26
Source Project: attic-stratos   Source File: AWSSecurityGroupApiTest.java    License: 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 27
Source Project: attic-stratos   Source File: AWSSecurityGroupApiTest.java    License: 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 28
Source Project: attic-stratos   Source File: AWSSecurityGroupApiTest.java    License: 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 29
Source Project: attic-stratos   Source File: AWSSecurityGroupApiTest.java    License: 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 30
Source Project: attic-stratos   Source File: AWSSecurityGroupApiTest.java    License: 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);
}