EndpointToRegion { public static String guessRegionNameForEndpoint(String hostname) { return guessRegionNameForEndpoint(hostname, null); }  static String guessRegionNameForEndpoint(String hostname); static String guessRegionNameForEndpoint(String endpoint, String serviceHint); static String guessRegionNameForEndpointWithDefault(String hostname, String serviceHint, String defaultRegion); static Region guessRegionForEndpoint(String hostname); static Region guessRegionForEndpoint(String endpoint, String serviceHint);  }
@Test public void guessRegionForHostname_isBackwardCompatibleReplacementForAwsHostNameUtilsParseRegion() { assertEquals("us-east-1", guessRegionNameForEndpoint("iam.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("iam.us-west-2.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("ec2.us-west-2.amazonaws.com")); assertEquals("us-east-1", guessRegionNameForEndpoint("s3.amazonaws.com")); assertEquals("us-east-1", guessRegionNameForEndpoint("bucket.name.s3.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("s3-eu-west-1.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("s3.eu-west-1.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3-eu-west-1.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3.eu-west-1.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("cloudsearch.us-west-2.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("domain.us-west-2.cloudsearch.amazonaws.com")); assertEquals("us-east-1", EndpointToRegion.guessRegionNameForEndpoint("iam.amazonaws.com", "iam")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("iam.us-west-2.amazonaws.com", "iam")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("ec2.us-west-2.amazonaws.com", "ec2")); assertEquals("us-east-1", EndpointToRegion.guessRegionNameForEndpoint("s3.amazonaws.com", "s3")); assertEquals("us-east-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.s3.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("s3.eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.with.periods.s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.with.periods.s3.eu-west-1.amazonaws.com", "s3")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("cloudsearch.us-west-2.amazonaws.com", "cloudsearch")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("domain.us-west-2.cloudsearch.amazonaws.com", "cloudsearch")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("iam.cn-north-1.amazonaws.com.cn", "iam")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("ec2.cn-north-1.amazonaws.com.cn", "ec2")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("s3.cn-north-1.amazonaws.com.cn", "s3")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.with.periods.s3.cn-north-1.amazonaws.com.cn", "s3")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("cloudsearch.cn-north-1.amazonaws.com.cn", "cloudsearch")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("domain.cn-north-1.cloudsearch.amazonaws.com.cn", "cloudsearch")); assertEquals("us-east-1", guessRegionNameForEndpoint("s3-external-1.amazonaws.com")); assertEquals("us-east-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3-external-1.amazonaws.com")); assertEquals("us-gov-west-1", guessRegionNameForEndpoint("s3-fips-us-gov-west-1.amazonaws.com")); assertEquals("us-gov-west-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3-fips-us-gov-west-1.amazonaws.com")); assertEquals("us-east-1", guessRegionNameForEndpoint("iam.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("iam.us-west-2.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("ec2.us-west-2.amazonaws.com")); assertEquals("us-east-1", guessRegionNameForEndpoint("s3.amazonaws.com")); assertEquals("us-east-1", guessRegionNameForEndpoint("bucket.name.s3.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("s3-eu-west-1.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("s3.eu-west-1.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3-eu-west-1.amazonaws.com")); assertEquals("eu-west-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3.eu-west-1.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("cloudsearch.us-west-2.amazonaws.com")); assertEquals("us-west-2", guessRegionNameForEndpoint("domain.us-west-2.cloudsearch.amazonaws.com")); assertEquals("us-east-1", EndpointToRegion.guessRegionNameForEndpoint("iam.amazonaws.com", "iam")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("iam.us-west-2.amazonaws.com", "iam")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("ec2.us-west-2.amazonaws.com", "ec2")); assertEquals("us-east-1", EndpointToRegion.guessRegionNameForEndpoint("s3.amazonaws.com", "s3")); assertEquals("us-east-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.s3.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("s3.eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.with.periods.s3-eu-west-1.amazonaws.com", "s3")); assertEquals("eu-west-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.with.periods.s3.eu-west-1.amazonaws.com", "s3")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("cloudsearch.us-west-2.amazonaws.com", "cloudsearch")); assertEquals("us-west-2", EndpointToRegion.guessRegionNameForEndpoint("domain.us-west-2.cloudsearch.amazonaws.com", "cloudsearch")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("iam.cn-north-1.amazonaws.com.cn", "iam")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("ec2.cn-north-1.amazonaws.com.cn", "ec2")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("s3.cn-north-1.amazonaws.com.cn", "s3")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("bucket.name.with.periods.s3.cn-north-1.amazonaws.com.cn", "s3")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("cloudsearch.cn-north-1.amazonaws.com.cn", "cloudsearch")); assertEquals("cn-north-1", EndpointToRegion.guessRegionNameForEndpoint("domain.cn-north-1.cloudsearch.amazonaws.com.cn", "cloudsearch")); assertEquals("us-east-1", guessRegionNameForEndpoint("s3-external-1.amazonaws.com")); assertEquals("us-east-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3-external-1.amazonaws.com")); assertEquals("us-gov-west-1", guessRegionNameForEndpoint("s3-fips-us-gov-west-1.amazonaws.com")); assertEquals("us-gov-west-1", guessRegionNameForEndpoint("bucket.name.with.periods.s3-fips-us-gov-west-1.amazonaws.com")); assertNull(guessRegionNameForEndpoint("54.231.16.200")); }
@Test public void guessRegionForHostname_ipAddress() { assertNull(guessRegionNameForEndpoint("http: assertNull(guessRegionNameForEndpoint("http: assertNull(guessRegionNameForEndpoint("http: assertNull(guessRegionNameForEndpoint("http: assertNull(guessRegionNameForEndpoint("localhost")); assertNull(guessRegionNameForEndpoint("localhost:1234")); assertNull(guessRegionNameForEndpoint("127.0.0.1")); assertNull(guessRegionNameForEndpoint("127.0.0.1:1234")); }