Пример #1
0
  @Test
  public void testTypeToken()
      throws NoSuchMethodException, SecurityException, InvocationTargetException,
          IllegalAccessException {

    TypeToken<TypeTokenTest> token = TypeToken.of(TypeTokenTest.class);
    Invokable<TypeTokenTest, ?> invokable =
        token.method(TypeTokenTest.class.getMethod("helloWorld"));
    invokable.invoke(this);
  }
  public void testAuthorizeIngressICMPToSecurityGroups()
      throws SecurityException, NoSuchMethodException, IOException {
    Invokable<?, ?> method =
        Invokable.from(
            SecurityGroupAsyncClient.class.getMethod(
                "authorizeIngressICMPToSecurityGroups",
                String.class,
                int.class,
                int.class,
                Multimap.class,
                AccountInDomainOptions[].class));
    GeneratedHttpRequest httpRequest =
        processor.createRequest(
            method,
            ImmutableList.<Object>of(
                2,
                22,
                22,
                ImmutableMultimap.of("adrian", "group1", "adrian", "group2", "bob", "group1")));

    assertRequestLineEquals(httpRequest, authorizeSecurityGroupIngress2.getRequestLine());
    assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
    assertPayloadEquals(httpRequest, null, null, false);

    assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
    assertSaxResponseParserClassEquals(method, null);
    assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class);

    checkFilters(httpRequest);
  }
Пример #3
0
 private static <I> void invokeOnInjectee(Invokable<? super I, Object> method, I injectee) {
   try {
     method.invoke(injectee);
   } catch (InvocationTargetException ie) {
     throw propagate(ie.getTargetException());
   } catch (IllegalAccessException e) {
     throw propagate(e);
   }
 }
  public void testDeleteSecurityGroup()
      throws SecurityException, NoSuchMethodException, IOException {
    Invokable<?, ?> method =
        Invokable.from(
            SecurityGroupAsyncClient.class.getMethod("deleteSecurityGroup", String.class));
    GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object>of(5));

    assertRequestLineEquals(
        httpRequest,
        "GET http://localhost:8080/client/api?response=json&command=deleteSecurityGroup&id=5 HTTP/1.1");
    assertNonPayloadHeadersEqual(httpRequest, "");
    assertPayloadEquals(httpRequest, null, null, false);

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

    checkFilters(httpRequest);
  }
  public void testGetSecurityGroup() throws SecurityException, NoSuchMethodException, IOException {
    Invokable<?, ?> method =
        Invokable.from(SecurityGroupAsyncClient.class.getMethod("getSecurityGroup", String.class));
    GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object>of(5));

    assertRequestLineEquals(
        httpRequest,
        "GET http://localhost:8080/client/api?response=json&command=listSecurityGroups&listAll=true&id=5 HTTP/1.1");
    assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
    assertPayloadEquals(httpRequest, null, null, false);

    assertResponseParserClassEquals(
        method,
        httpRequest,
        Functions.compose(IdentityFunction.INSTANCE, IdentityFunction.INSTANCE).getClass());
    assertSaxResponseParserClassEquals(method, null);
    assertFallbackClassEquals(method, NullOnNotFoundOr404.class);

    checkFilters(httpRequest);
  }
  public void testListSecurityGroups()
      throws SecurityException, NoSuchMethodException, IOException {
    Invokable<?, ?> method =
        Invokable.from(
            SecurityGroupAsyncClient.class.getMethod(
                "listSecurityGroups", ListSecurityGroupsOptions[].class));
    GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of());

    assertRequestLineEquals(
        httpRequest,
        "GET http://localhost:8080/client/api?response=json&command=listSecurityGroups&listAll=true HTTP/1.1");
    assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
    assertPayloadEquals(httpRequest, null, null, false);

    assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
    assertSaxResponseParserClassEquals(method, null);
    assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class);

    checkFilters(httpRequest);
  }
  public void testCreateSecurityGroup()
      throws SecurityException, NoSuchMethodException, IOException {
    Invokable<?, ?> method =
        Invokable.from(
            SecurityGroupAsyncClient.class.getMethod("createSecurityGroup", String.class));
    GeneratedHttpRequest httpRequest =
        processor.createRequest(method, ImmutableList.<Object>of("goo"));

    assertRequestLineEquals(
        httpRequest,
        "GET http://localhost:8080/client/api?response=json&command=createSecurityGroup&name=goo HTTP/1.1");
    assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
    assertPayloadEquals(httpRequest, null, null, false);

    assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
    assertSaxResponseParserClassEquals(method, null);
    assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class);

    checkFilters(httpRequest);
  }
  public void testRevokeIngressRule() throws SecurityException, NoSuchMethodException, IOException {
    Invokable<?, ?> method =
        Invokable.from(
            SecurityGroupAsyncClient.class.getMethod(
                "revokeIngressRule", String.class, AccountInDomainOptions[].class));
    GeneratedHttpRequest httpRequest =
        processor.createRequest(
            method,
            ImmutableList.<Object>of(
                5, AccountInDomainOptions.Builder.accountInDomain("adrian", "1")));

    assertRequestLineEquals(
        httpRequest,
        "GET http://localhost:8080/client/api?response=json&command=revokeSecurityGroupIngress&id=5&account=adrian&domainid=1 HTTP/1.1");
    assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
    assertPayloadEquals(httpRequest, null, null, false);

    assertResponseParserClassEquals(method, httpRequest, ParseFirstJsonValueNamed.class);
    assertSaxResponseParserClassEquals(method, null);
    assertFallbackClassEquals(method, VoidOnNotFoundOr404.class);

    checkFilters(httpRequest);
  }
Пример #9
0
 public boolean apply(Invokable<?, ?> in) {
   return in.isAnnotationPresent(PreDestroy.class);
 }
Пример #10
0
 public boolean apply(Invokable<?, ?> in) {
   return in.isAnnotationPresent(PostConstruct.class);
 }