@Test public void testRequestFilterStripExpect() { // First, verify that by default, the StripExpectHeader filter is not applied Invokable<?, ?> method = method(TestRequestFilter.class, "post"); Invocation invocation = Invocation.create(method, ImmutableList.<Object>of(HttpRequest.builder().method("POST").endpoint("http://localhost") .addHeader(HttpHeaders.EXPECT, "100-Continue").build())); GeneratedHttpRequest request = processor.apply(invocation); assertEquals(request.getFilters().size(), 1); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class); // Now let's create a new injector with the property set. Use that to create the annotation processor. Properties overrides = new Properties(); overrides.setProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true"); Injector injector = ContextBuilder.newBuilder(forApiOnEndpoint(Callee.class, "http://localhost:9999")) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() { protected void configure() { bind(new TypeLiteral<Supplier<URI>>() { }).annotatedWith(Localhost2.class).toInstance( Suppliers.ofInstance(URI.create("http://localhost:1111"))); }})) .overrides(overrides).buildInjector(); RestAnnotationProcessor newProcessor = injector.getInstance(RestAnnotationProcessor.class); // Verify that this time the filter is indeed applied as expected. request = newProcessor.apply(invocation); assertEquals(request.getFilters().size(), 2); assertEquals(request.getFilters().get(1).getClass(), StripExpectHeader.class); }
@Test public void testRequestFilterAddConnection() { // First, verify that by default, the StripExpectHeader filter is not applied Invokable<?, ?> method = method(TestRequestFilter.class, "post"); Invocation invocation = Invocation.create(method, ImmutableList.<Object>of(HttpRequest.builder().method("POST").endpoint("http://localhost").build())); GeneratedHttpRequest request = processor.apply(invocation); assertEquals(request.getFilters().size(), 1); assertEquals(request.getFilters().get(0).getClass(), TestRequestFilter1.class); // Now let's create a new injector with the property set. Use that to create the annotation processor. Properties overrides = new Properties(); overrides.setProperty(Constants.PROPERTY_CONNECTION_CLOSE_HEADER, "true"); Injector injector = ContextBuilder.newBuilder(forApiOnEndpoint(Callee.class, "http://localhost:9999")) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() { protected void configure() { bind(new TypeLiteral<Supplier<URI>>() { }).annotatedWith(Localhost2.class).toInstance( Suppliers.ofInstance(URI.create("http://localhost:1111"))); }})) .overrides(overrides).buildInjector(); RestAnnotationProcessor newProcessor = injector.getInstance(RestAnnotationProcessor.class); // Verify that this time the filter is indeed applied as expected. request = newProcessor.apply(invocation); assertEquals(request.getFilters().size(), 2); assertEquals(request.getFilters().get(1).getClass(), ConnectionCloseHeader.class); }
/** * before class, as we need to ensure that the filter is threadsafe. * * @throws IOException * */ @BeforeClass protected void createFilter() throws IOException { injector = ContextBuilder .newBuilder( AnonymousRestApiMetadata .forClientMappedToAsyncClient(IntegrationTestClient.class, IntegrationTestAsyncClient.class) .toBuilder().build()) .endpoint("https://${jclouds.identity}.blob.core.windows.net") .credentials(ACCOUNT, "credential") .modules( ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AzureStorageRestClientModule<IntegrationTestClient, IntegrationTestAsyncClient>( typeToken(IntegrationTestClient.class), typeToken(IntegrationTestAsyncClient.class)))) .buildInjector(); filter = injector.getInstance(SharedKeyLiteAuthentication.class); } }
/** * before class, as we need to ensure that the filter is threadsafe. * * @throws IOException * */ @BeforeClass protected void createFilter() throws IOException { Injector injector = ContextBuilder.newBuilder(new ChefApiMetadata()).credentials(USER_ID, PRIVATE_KEY) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector(); HttpUtils utils = injector.getInstance(HttpUtils.class); Crypto crypto = injector.getInstance(Crypto.class); Supplier<PrivateKey> privateKey = injector.getInstance(Key.get(new TypeLiteral<Supplier<PrivateKey>>() { })); signing_obj = new SignedHeaderAuth(new SignatureWire(), Suppliers.ofInstance(new Credentials(USER_ID, PRIVATE_KEY)), privateKey, new Provider<String>() { @Override public String get() { return TIMESTAMP_ISO8601; } }, utils, crypto); }
/** * before class, as we need to ensure that the filter is threadsafe. * * @throws IOException * */ @BeforeClass protected void createFilter() throws IOException { Injector injector = ContextBuilder.newBuilder(new ChefApiMetadata()).credentials(USER_ID, PRIVATE_KEY) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector(); HttpUtils utils = injector.getInstance(HttpUtils.class); Supplier<PrivateKey> privateKey = injector.getInstance(Key.get(new TypeLiteral<Supplier<PrivateKey>>() { })); signing_obj = new SignedHeaderAuth(new SignatureWire(), Suppliers.ofInstance(new Credentials(USER_ID, PRIVATE_KEY)), privateKey, new Provider<String>() { @Override public String get() { return TIMESTAMP_ISO8601; } }, utils); }
@BeforeClass void setupFactory() { injector = ContextBuilder .newBuilder( AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(Callee.class, AsyncCallee.class, "http://localhost:9999")) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() { protected void configure() { bind(new TypeLiteral<Supplier<URI>>() { }).annotatedWith(Localhost2.class).toInstance( Suppliers.ofInstance(URI.create("http://localhost:1111"))); } })).buildInjector(); parserFactory = injector.getInstance(ParseSax.Factory.class); processor = injector.getInstance(RestAnnotationProcessor.class); transformer = injector.getInstance(TransformerForRequest.class); } }
/** * before class, as we need to ensure that the filter is threadsafe. * * @throws IOException * */ @BeforeClass protected void createFilter() throws IOException { injector = ContextBuilder .newBuilder("azureblob") .endpoint("https://${jclouds.identity}.blob.core.windows.net") .credentials(ACCOUNT, "credential") .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())) .buildInjector(); filter = injector.getInstance(SharedKeyLiteAuthentication.class); } }
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)); } }); }
@BeforeClass void setupFactory() { injector = ContextBuilder .newBuilder(forApiOnEndpoint(Callee.class, "http://localhost:9999")) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() { protected void configure() { bind(new TypeLiteral<Supplier<URI>>() { }).annotatedWith(Localhost2.class).toInstance( Suppliers.ofInstance(URI.create("http://localhost:1111"))); } })).buildInjector(); parserFactory = injector.getInstance(ParseSax.Factory.class); processor = injector.getInstance(RestAnnotationProcessor.class); transformer = injector.getInstance(TransformerForRequest.class); } }
private Injector injectorFor(ProviderMetadata md) { return Guice.createInjector(new BindNameToContext("test"), new BindProviderMetadataContextAndCredentials(md, ofInstance(new Credentials("user", "pass"))), new BindApiContextWithWildcardExtendsExplicitAndRawType( HttpApiMetadata.class.cast(md.getApiMetadata())), // stuff needed for ApiContextImpl 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)); } }); }
public static Injector injector(Credentials creds) { return ContextBuilder .newBuilder( AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(IntegrationTestClient.class, IntegrationTestAsyncClient.class, "http://localhost")) .credentialsSupplier(Suppliers.<Credentials> ofInstance(creds)).apiVersion("apiVersion") .modules(ImmutableList.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() { @Override protected void configure() { bind(RequestSigner.class).to(FormSigner.class); bind(String.class).annotatedWith(Names.named(PROPERTY_HEADER_TAG)).toInstance("amz"); bind(String.class).annotatedWith(TimeStamp.class).toInstance("2009-11-08T15:54:08.897Z"); } })).buildInjector(); }
@BeforeClass public void setup() { context = ContextBuilder.newBuilder(new HostedChefProviderMetadata()) .credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())) // .buildView(ChefContext.class); }
@BeforeClass public void setup() { context = ContextBuilder.newBuilder(new PrivateChefApiMetadata()) .credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())) // .buildView(ChefContext.class); }
public static Injector injector(Credentials creds) { return ContextBuilder.newBuilder(new S3ApiMetadata()) .credentialsSupplier(Suppliers.<Credentials>ofInstance(creds)) .modules(ImmutableList.<Module>of(new BaseRestApiTest.MockModule(), new NullLoggingModule(), new TestS3HttpApiModule())) .buildInjector(); }
private Injector injectorForCaller(HttpCommandExecutorService service, Module... modules) { return ContextBuilder.newBuilder(forApiOnEndpoint(Caller.class, "http://localhost:9999")) .modules(ImmutableSet.<Module> builder() .add(new MockModule(service)) .add(new NullLoggingModule()) .add(new CallerModule()) .addAll(Arrays.asList(modules)).build()).buildInjector(); }
public static Injector injector(Credentials creds) { return ContextBuilder .newBuilder(forApiOnEndpoint(IntegrationTestClient.class, "http://localhost")) .credentialsSupplier(Suppliers.<Credentials> ofInstance(creds)).apiVersion("apiVersion") .modules(ImmutableList.<Module> of(new MockModule(), new NullLoggingModule(), new AbstractModule() { @Override protected void configure() { bind(RequestSigner.class).to(FormSignerV2.class); bind(String.class).annotatedWith(Names.named(PROPERTY_HEADER_TAG)).toInstance("amz"); bind(String.class).annotatedWith(TimeStamp.class).toInstance("2009-11-08T15:54:08.897Z"); } })).buildInjector(); }
@BeforeClass public void setup() { Injector injector = ContextBuilder.newBuilder(new ChefApiMetadata()) .credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())).buildInjector(); chefService = injector.getInstance(BaseChefService.class); }
@BeforeClass public void setup() { context = ContextBuilder.newBuilder(new ChefApiMetadata()) .credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY) .modules(ImmutableSet.<Module> of(new MockModule(), new NullLoggingModule())) // .buildView(ChefContext.class); }
public static Injector injector(Credentials creds) { return ContextBuilder.newBuilder("s3") .credentialsSupplier(Suppliers.<Credentials> ofInstance(creds)) .modules(ImmutableList.<Module> of(new MockModule(), new NullLoggingModule(), new TestS3HttpApiModule())).buildInjector(); }