21
21
import java .util .Collections ;
22
22
import java .util .List ;
23
23
import org .junit .jupiter .api .Test ;
24
+ import org .junit .jupiter .params .ParameterizedTest ;
25
+ import org .junit .jupiter .params .provider .ValueSource ;
24
26
import org .mockito .ArgumentCaptor ;
25
27
import software .amazon .awssdk .awscore .exception .AwsErrorDetails ;
26
28
import software .amazon .awssdk .awscore .exception .AwsServiceException ;
@@ -51,10 +53,11 @@ public abstract class S3DecoratorRedirectTestBase {
51
53
protected static final S3ServiceClientConfiguration CONFIGURED_ENDPOINT_PROVIDER =
52
54
S3ServiceClientConfiguration .builder ().endpointProvider (S3EndpointProvider .defaultProvider ()).build ();
53
55
54
- @ Test
55
- void decoratorAttemptsToRetryWithRegionNameInErrorResponse () throws Throwable {
56
+ @ ParameterizedTest
57
+ @ ValueSource (ints = {301 , 307 })
58
+ void decoratorAttemptsToRetryWithRegionNameInErrorResponse (Integer redirect ) throws Throwable {
56
59
stubServiceClientConfiguration ();
57
- stubClientAPICallWithFirstRedirectThenSuccessWithRegionInErrorResponse ();
60
+ stubClientAPICallWithFirstRedirectThenSuccessWithRegionInErrorResponse (redirect );
58
61
// Assert retrieved listObject
59
62
ListObjectsResponse listObjectsResponse = apiCallToService ();
60
63
assertThat (listObjectsResponse .contents ()).isEqualTo (S3_OBJECTS );
@@ -68,10 +71,11 @@ void decoratorAttemptsToRetryWithRegionNameInErrorResponse() throws Throwable {
68
71
verifyHeadBucketServiceCall (0 );
69
72
}
70
73
71
- @ Test
72
- void decoratorUsesCache_when_CrossRegionAlreadyPresent () throws Throwable {
74
+ @ ParameterizedTest
75
+ @ ValueSource (ints = {301 , 307 })
76
+ void decoratorUsesCache_when_CrossRegionAlreadyPresent (Integer redirect ) throws Throwable {
73
77
stubServiceClientConfiguration ();
74
- stubRedirectSuccessSuccess ();
78
+ stubRedirectSuccessSuccess (redirect );
75
79
76
80
ListObjectsResponse listObjectsResponse = apiCallToService ();
77
81
assertThat (listObjectsResponse .contents ()).isEqualTo (S3_OBJECTS );
@@ -93,20 +97,22 @@ void decoratorUsesCache_when_CrossRegionAlreadyPresent() throws Throwable {
93
97
* The redirected call fails because of incorrect parameters passed
94
98
* This exception should be reported correctly
95
99
*/
96
- @ Test
97
- void apiCallFailure_when_CallFailsAfterRedirection () {
100
+ @ ParameterizedTest
101
+ @ ValueSource (ints = {301 , 307 })
102
+ void apiCallFailure_when_CallFailsAfterRedirection (Integer redirectError ) {
98
103
stubServiceClientConfiguration ();
99
- stubRedirectThenError ();
104
+ stubRedirectThenError (redirectError );
100
105
assertThatExceptionOfType (S3Exception .class )
101
106
.isThrownBy (() -> apiCallToService ())
102
107
.withMessageContaining ("Invalid id (Service: S3, Status Code: 400, Request ID: 1, Extended Request ID: A1)" );
103
108
verifyHeadBucketServiceCall (0 );
104
109
}
105
110
106
- @ Test
107
- void headBucketCalled_when_RedirectDoesNotHasRegionName () throws Throwable {
111
+ @ ParameterizedTest
112
+ @ ValueSource (ints = {301 , 307 })
113
+ void headBucketCalled_when_RedirectDoesNotHasRegionName (Integer redirect ) throws Throwable {
108
114
stubServiceClientConfiguration ();
109
- stubRedirectWithNoRegionAndThenSuccess ();
115
+ stubRedirectWithNoRegionAndThenSuccess (redirect );
110
116
stubHeadBucketRedirect ();
111
117
ListObjectsResponse listObjectsResponse = apiCallToService ();
112
118
assertThat (listObjectsResponse .contents ()).isEqualTo (S3_OBJECTS );
@@ -119,10 +125,11 @@ void headBucketCalled_when_RedirectDoesNotHasRegionName() throws Throwable {
119
125
verifyHeadBucketServiceCall (1 );
120
126
}
121
127
122
- @ Test
123
- void headBucketCalledAndCached__when_RedirectDoesNotHasRegionName () throws Throwable {
128
+ @ ParameterizedTest
129
+ @ ValueSource (ints = {301 , 307 })
130
+ void headBucketCalledAndCached__when_RedirectDoesNotHasRegionName (Integer redirect ) throws Throwable {
124
131
stubServiceClientConfiguration ();
125
- stubRedirectWithNoRegionAndThenSuccess ();
132
+ stubRedirectWithNoRegionAndThenSuccess (redirect );
126
133
stubHeadBucketRedirect ();
127
134
ListObjectsResponse listObjectsResponse = apiCallToService ();
128
135
assertThat (listObjectsResponse .contents ()).isEqualTo (S3_OBJECTS );
@@ -165,11 +172,11 @@ void requestsAreNotOverridden_when_NoBucketInRequest() throws Throwable {
165
172
166
173
protected abstract void stubHeadBucketRedirect ();
167
174
168
- protected abstract void stubRedirectWithNoRegionAndThenSuccess ();
175
+ protected abstract void stubRedirectWithNoRegionAndThenSuccess (Integer redirect );
169
176
170
- protected abstract void stubRedirectThenError ();
177
+ protected abstract void stubRedirectThenError (Integer redirect );
171
178
172
- protected abstract void stubRedirectSuccessSuccess ();
179
+ protected abstract void stubRedirectSuccessSuccess (Integer redirect );
173
180
174
181
protected AwsServiceException redirectException (int statusCode , String region , String errorCode , String errorMessage ) {
175
182
SdkHttpFullResponse .Builder sdkHttpFullResponseBuilder = SdkHttpFullResponse .builder ();
@@ -210,5 +217,5 @@ void verifyTheEndPointProviderOverridden(int attempt,
210
217
211
218
protected abstract void stubServiceClientConfiguration ();
212
219
213
- protected abstract void stubClientAPICallWithFirstRedirectThenSuccessWithRegionInErrorResponse ();
220
+ protected abstract void stubClientAPICallWithFirstRedirectThenSuccessWithRegionInErrorResponse (Integer redirect );
214
221
}
0 commit comments