PageRenderTime 772ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/apis/s3/src/test/java/org/jclouds/s3/functions/AssignCorrectHostnameForBucketTest.java

http://github.com/jclouds/jclouds
Java | 71 lines | 44 code | 11 blank | 16 comment | 0 complexity | 2efb040a392f0aed824ba14810eb2b56 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package org.jclouds.s3.functions;
  18. import static org.testng.Assert.assertEquals;
  19. import java.net.URI;
  20. import java.util.Map;
  21. import org.jclouds.location.Provider;
  22. import org.jclouds.location.Region;
  23. import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
  24. import org.testng.annotations.Test;
  25. import com.google.common.base.Functions;
  26. import com.google.common.base.Optional;
  27. import com.google.common.base.Supplier;
  28. import com.google.common.base.Suppliers;
  29. import com.google.common.collect.ImmutableMap;
  30. import com.google.inject.Binder;
  31. import com.google.inject.Guice;
  32. import com.google.inject.Module;
  33. import com.google.inject.Provides;
  34. @Test
  35. public class AssignCorrectHostnameForBucketTest {
  36. static final RegionToEndpointOrProviderIfNull REGION_TO_ENDPOINT = Guice.createInjector(new Module() {
  37. @Override public void configure(Binder binder) {
  38. binder.bindConstant().annotatedWith(Provider.class).to("s3");
  39. }
  40. @Provides @Provider Supplier<URI> defaultUri() {
  41. return Suppliers.ofInstance(URI.create("https://s3.amazonaws.com"));
  42. }
  43. @Provides @Region Supplier<Map<String, Supplier<URI>>> regionToEndpoints() {
  44. Map<String, Supplier<URI>> regionToEndpoint = ImmutableMap.of( //
  45. "us-standard", defaultUri(), //
  46. "us-west-1", Suppliers.ofInstance(URI.create("https://s3-us-west-1.amazonaws.com")));
  47. return Suppliers.ofInstance(regionToEndpoint);
  48. }
  49. }).getInstance(RegionToEndpointOrProviderIfNull.class);
  50. public void testWhenNoBucketRegionMappingInCache() {
  51. AssignCorrectHostnameForBucket fn = new AssignCorrectHostnameForBucket(REGION_TO_ENDPOINT,
  52. Functions.forMap(ImmutableMap.of("bucket", Optional.<String>absent())));
  53. assertEquals(fn.apply("bucket"), URI.create("https://s3.amazonaws.com"));
  54. }
  55. public void testWhenBucketRegionMappingInCache() {
  56. AssignCorrectHostnameForBucket fn = new AssignCorrectHostnameForBucket(REGION_TO_ENDPOINT,
  57. Functions.forMap(ImmutableMap.of("bucket", Optional.of("us-west-1"))));
  58. assertEquals(fn.apply("bucket"), URI.create("https://s3-us-west-1.amazonaws.com"));
  59. }
  60. }