3939public  class  TestArnResource  extends  HadoopTestBase  {
4040  private  final  static  Logger  LOG  = LoggerFactory .getLogger (TestArnResource .class );
4141
42+   private  final  static  String  MOCK_ACCOUNT  = "123456789101" ;
43+ 
4244  @ Test 
4345  public  void  parseAccessPointFromArn () throws  IllegalArgumentException  {
4446    describe ("Parse AccessPoint ArnResource from arn string" );
4547
4648    String  accessPoint  = "testAp" ;
47-     String  accountId  = "123456789101" ;
4849    String [][] regionPartitionEndpoints  = new  String [][] {
49-         {Regions .EU_WEST_1 .getName (), "aws" , "eu-west-1.amazonaws.com" },
50-         {Regions .US_GOV_EAST_1 .getName (), "aws-us-gov" ,
51-             "us-gov-east-1.amazonaws.com" },
52-         {Regions .CN_NORTH_1 .getName (), "aws-cn" , "cn-north-1.amazonaws.com" },
50+         {Regions .EU_WEST_1 .getName (), "aws" },
51+         {Regions .US_GOV_EAST_1 .getName (), "aws-us-gov" },
52+         {Regions .CN_NORTH_1 .getName (), "aws-cn" },
5353    };
5454
5555    for  (String [] testPair  : regionPartitionEndpoints ) {
5656      String  region  = testPair [0 ];
5757      String  partition  = testPair [1 ];
58-       String  endpoint  = testPair [2 ];
59- 
60-       // arn:partition:service:region:account-id:resource-type/resource-id 
61-       String  arn  = String .format ("arn:%s:s3:%s:%s:accesspoint/%s" , partition , region , accountId ,
62-           accessPoint );
6358
64-       ArnResource  resource  = ArnResource .accessPointFromArn (arn );
65-       assertEquals ("Arn does not match" , arn , resource .getFullArn ());
59+       ArnResource  resource  = getArnResourceFrom (partition , region , MOCK_ACCOUNT , accessPoint );
6660      assertEquals ("Access Point name does not match" , accessPoint , resource .getName ());
67-       assertEquals ("Account Id does not match" , accountId , resource .getOwnerAccountId ());
61+       assertEquals ("Account Id does not match" , MOCK_ACCOUNT , resource .getOwnerAccountId ());
6862      assertEquals ("Region does not match" , region , resource .getRegion ());
69-       Assertions .assertThat (resource .getEndpoint ())
70-           .describedAs ("Endpoint does not match" )
71-           .contains (endpoint );
7263    }
7364  }
7465
66+   @ Test 
67+   public  void  makeSureEndpointHasTheCorrectFormat () {
68+     // Access point (AP) endpoints are different from S3 bucket endpoints, thus when using APs the 
69+     // endpoints for the client are modified. This test makes sure endpoint is set up correctly. 
70+     ArnResource  accessPoint  = getArnResourceFrom ("aws" , "eu-west-1" , MOCK_ACCOUNT ,
71+         "test" );
72+     String  expected  = "s3-accesspoint.eu-west-1.amazonaws.com" ;
73+ 
74+     Assertions .assertThat (accessPoint .getEndpoint ())
75+         .describedAs ("Endpoint has invalid format. Access Point requests will not work" )
76+         .isEqualTo (expected );
77+   }
78+ 
7579  @ Test 
7680  public  void  invalidARNsMustThrow () throws  Exception  {
7781    describe ("Using an invalid ARN format must throw when initializing an ArnResource." );
@@ -80,6 +84,23 @@ public void invalidARNsMustThrow() throws Exception {
8084        ArnResource .accessPointFromArn ("invalid:arn:resource" ));
8185  }
8286
87+   /** 
88+    * Create an {@link ArnResource} from string components 
89+    * @param partition - partition for ARN 
90+    * @param region - region for ARN 
91+    * @param accountId - accountId for ARN 
92+    * @param resourceName - ARN resource name 
93+    * @return ArnResource described by its properties 
94+    */ 
95+   private  ArnResource  getArnResourceFrom (String  partition , String  region , String  accountId ,
96+       String  resourceName ) {
97+     // arn:partition:service:region:account-id:resource-type/resource-id 
98+     String  arn  = String .format ("arn:%s:s3:%s:%s:accesspoint/%s" , partition , region , accountId ,
99+         resourceName );
100+ 
101+     return  ArnResource .accessPointFromArn (arn );
102+   }
103+ 
83104  private  void  describe (String  message ) {
84105    LOG .info (message );
85106  }
0 commit comments