29
29
import java .io .IOException ;
30
30
import java .net .URI ;
31
31
import java .net .URISyntaxException ;
32
- import java .util .Collections ;
32
+ import java .util .HashMap ;
33
33
import java .util .Map ;
34
34
import org .junit .BeforeClass ;
35
35
import org .junit .ClassRule ;
43
43
import software .amazon .awssdk .core .internal .net .ConnectionUtils ;
44
44
import software .amazon .awssdk .core .retry .internal .CredentialsEndpointRetryParameters ;
45
45
import software .amazon .awssdk .core .retry .internal .CredentialsEndpointRetryPolicy ;
46
+ import software .amazon .awssdk .core .util .VersionInfo ;
46
47
import utils .http .SocketUtils ;
47
48
48
49
@ RunWith (MockitoJUnitRunner .class )
@@ -54,7 +55,14 @@ public class HttpCredentialsUtilsTest {
54
55
private static final String SUCCESS_BODY = "{\" AccessKeyId\" :\" ACCESS_KEY_ID\" ,\" SecretAccessKey\" :\" SECRET_ACCESS_KEY\" ,"
55
56
+ "\" Token\" :\" TOKEN_TOKEN_TOKEN\" ,\" Expiration\" :\" 3000-05-03T04:55:54Z\" }" ;
56
57
private static URI endpoint ;
57
- private final Map <String , String > emptyHeaders = Collections .emptyMap ();
58
+ private static Map <String , String > headers = new HashMap <String , String >()
59
+ {
60
+ {
61
+ put ("User-Agent" , String .format ("aws-sdk-java/%s" , VersionInfo .SDK_VERSION ));
62
+ put ("Accept" , "*/*" );
63
+ put ("Connection" , "keep-alive" );
64
+ }
65
+ };
58
66
59
67
private static CustomRetryPolicy customRetryPolicy ;
60
68
@@ -153,13 +161,13 @@ public void readResouceNonJsonErrorBody() throws IOException {
153
161
*/
154
162
@ Test
155
163
public void readResouceWithDefaultRetryPolicy_DoesNotRetry_ForIoException () throws IOException {
156
- Mockito .when (mockConnection .connectToEndpoint (endpoint , emptyHeaders )).thenThrow (new IOException ());
164
+ Mockito .when (mockConnection .connectToEndpoint (endpoint , headers )).thenThrow (new IOException ());
157
165
158
166
try {
159
167
new HttpCredentialsUtils (mockConnection ).readResource (endpoint );
160
168
fail ("Expected an IOexception" );
161
169
} catch (IOException exception ) {
162
- Mockito .verify (mockConnection , Mockito .times (1 )).connectToEndpoint (endpoint , emptyHeaders );
170
+ Mockito .verify (mockConnection , Mockito .times (1 )).connectToEndpoint (endpoint , headers );
163
171
}
164
172
}
165
173
@@ -170,13 +178,13 @@ public void readResouceWithDefaultRetryPolicy_DoesNotRetry_ForIoException() thro
170
178
*/
171
179
@ Test
172
180
public void readResouceWithCustomRetryPolicy_DoesRetry_ForIoException () throws IOException {
173
- Mockito .when (mockConnection .connectToEndpoint (endpoint , emptyHeaders )).thenThrow (new IOException ());
181
+ Mockito .when (mockConnection .connectToEndpoint (endpoint , headers )).thenThrow (new IOException ());
174
182
175
183
try {
176
184
new HttpCredentialsUtils (mockConnection ).readResource (endpointProvider (endpoint , customRetryPolicy ));
177
185
fail ("Expected an IOexception" );
178
186
} catch (IOException exception ) {
179
- Mockito .verify (mockConnection , Mockito .times (CustomRetryPolicy .MAX_RETRIES + 1 )).connectToEndpoint (endpoint , emptyHeaders );
187
+ Mockito .verify (mockConnection , Mockito .times (CustomRetryPolicy .MAX_RETRIES + 1 )).connectToEndpoint (endpoint , headers );
180
188
}
181
189
}
182
190
@@ -188,13 +196,13 @@ public void readResouceWithCustomRetryPolicy_DoesRetry_ForIoException() throws I
188
196
@ Test
189
197
public void readResouceWithCustomRetryPolicy_DoesNotRetry_ForNonIoException () throws IOException {
190
198
generateStub (500 , "Non Json error body" );
191
- Mockito .when (mockConnection .connectToEndpoint (endpoint , emptyHeaders )).thenCallRealMethod ();
199
+ Mockito .when (mockConnection .connectToEndpoint (endpoint , headers )).thenCallRealMethod ();
192
200
193
201
try {
194
202
new HttpCredentialsUtils (mockConnection ).readResource (endpointProvider (endpoint , customRetryPolicy ));
195
203
fail ("Expected an SdkServiceException" );
196
204
} catch (SdkServiceException exception ) {
197
- Mockito .verify (mockConnection , Mockito .times (1 )).connectToEndpoint (endpoint , emptyHeaders );
205
+ Mockito .verify (mockConnection , Mockito .times (1 )).connectToEndpoint (endpoint , headers );
198
206
}
199
207
}
200
208
0 commit comments