static void addRestContextBinding(ApiMetadata apiMetadata, List<Module> modules) { if (apiMetadata instanceof HttpApiMetadata) { try { modules .add(new BindApiContextWithWildcardExtendsExplicitAndRawType(HttpApiMetadata.class.cast(apiMetadata))); } catch (IllegalArgumentException ignored) { } } else if (apiMetadata instanceof RestApiMetadata) { try { modules.add(new BindRestContextWithWildcardExtendsExplicitAndRawType(RestApiMetadata.class .cast(apiMetadata))); } catch (IllegalArgumentException ignored) { } } }
@SuppressWarnings("unchecked") @Override protected void configure() { TypeToken<?> concreteType = BaseRestApiMetadata.contextToken(typeToken(restApiMetadata.getApi()), typeToken(restApiMetadata.getAsyncApi())); // bind explicit type bind(TypeLiteral.get(concreteType.getType())).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); // bind potentially wildcard type if (!concreteType.equals(restApiMetadata.getContext())) { bind(TypeLiteral.get(restApiMetadata.getContext().getType())).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); } // bind w/o types bind(TypeLiteral.get(RestContext.class)).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); } }
@SuppressWarnings("unchecked") @Override protected void configure() { TypeToken<?> concreteType = BaseRestApiMetadata.contextToken(typeToken(restApiMetadata.getApi()), typeToken(restApiMetadata.getAsyncApi())); // bind explicit type bind(TypeLiteral.get(concreteType.getType())).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); // bind potentially wildcard type if (!concreteType.equals(restApiMetadata.getContext())) { bind(TypeLiteral.get(restApiMetadata.getContext().getType())).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); } // bind w/o types bind(TypeLiteral.get(RestContext.class)).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); } }
static void addRestContextBinding(ApiMetadata apiMetadata, List<Module> modules) { if (apiMetadata instanceof HttpApiMetadata) { try { modules .add(new BindApiContextWithWildcardExtendsExplicitAndRawType(HttpApiMetadata.class.cast(apiMetadata))); } catch (IllegalArgumentException ignored) { } } else if (apiMetadata instanceof RestApiMetadata) { try { modules.add(new BindRestContextWithWildcardExtendsExplicitAndRawType(RestApiMetadata.class .cast(apiMetadata))); } catch (IllegalArgumentException ignored) { } } }
@SuppressWarnings("unchecked") @Override protected void configure() { TypeToken<?> concreteType = BaseRestApiMetadata.contextToken(typeToken(restApiMetadata.getApi()), typeToken(restApiMetadata.getAsyncApi())); // bind explicit type bind(TypeLiteral.get(concreteType.getType())).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); // bind potentially wildcard type if (!concreteType.equals(restApiMetadata.getContext())) { bind(TypeLiteral.get(restApiMetadata.getContext().getType())).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); } // bind w/o types bind(TypeLiteral.get(RestContext.class)).to( TypeLiteral.class.cast(TypeLiteral.get(Types.newParameterizedType(RestContextImpl.class, restApiMetadata.getApi(), restApiMetadata.getAsyncApi())))); } }
static void addRestContextBinding(ApiMetadata apiMetadata, List<Module> modules) { if (apiMetadata instanceof HttpApiMetadata) { try { modules .add(new BindApiContextWithWildcardExtendsExplicitAndRawType(HttpApiMetadata.class.cast(apiMetadata))); } catch (IllegalArgumentException ignored) { } } else if (apiMetadata instanceof RestApiMetadata) { try { modules.add(new BindRestContextWithWildcardExtendsExplicitAndRawType(RestApiMetadata.class .cast(apiMetadata))); } catch (IllegalArgumentException ignored) { } } }
private Injector injectorFor(ProviderMetadata md) { return Guice.createInjector( new BindNameToContext("test"), new BindProviderMetadataContextAndCredentials(md, ofInstance(new Credentials("user", "pass"))), new BindRestContextWithWildcardExtendsExplicitAndRawType(RestApiMetadata.class.cast(md .getApiMetadata())), // stuff needed for RestContextImpl new MockModule(), new AbstractModule() { @Override protected void configure() { bind(Utils.class).toInstance(createMock(Utils.class)); bind(IntegrationTestClient.class).toInstance(createMock(IntegrationTestClient.class)); bind(IntegrationTestAsyncClient.class).toInstance(createMock(IntegrationTestAsyncClient.class)); } }); }