• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.testutils.service.http;
17 
18 import java.time.Duration;
19 import java.util.List;
20 import software.amazon.awssdk.http.HttpExecuteResponse;
21 import software.amazon.awssdk.http.SdkHttpRequest;
22 import software.amazon.awssdk.http.SdkHttpResponse;
23 import software.amazon.awssdk.utils.Pair;
24 
25 public interface MockHttpClient {
26     /**
27      * Resets this mock by clearing any captured requests and wiping any stubbed responses.
28      */
reset()29     void reset();
30 
31     /**
32      * Sets up the next HTTP response that will be returned by the mock. Removes responses previously added to the mock.
33      */
stubNextResponse(HttpExecuteResponse nextResponse)34     void stubNextResponse(HttpExecuteResponse nextResponse);
35 
stubNextResponse200()36     default void stubNextResponse200() {
37         stubNextResponse(HttpExecuteResponse.builder()
38                                             .response(SdkHttpResponse.builder()
39                                                                      .statusCode(200)
40                                                                      .putHeader("Content-Length", "0")
41                                                                      .build())
42                                             .build());
43     }
44 
45     /**
46      * Sets up the next HTTP response that will be returned by the mock with a delay. Removes responses previously added to the
47      * mock.
48      */
stubNextResponse(HttpExecuteResponse nextResponse, Duration delay)49     void stubNextResponse(HttpExecuteResponse nextResponse, Duration delay);
50 
stubResponses(Pair<HttpExecuteResponse, Duration>.... responses)51     void stubResponses(Pair<HttpExecuteResponse, Duration>... responses);
52 
53     /**
54      * Sets the next set of HTTP responses that will be returned by the mock. Removes responses previously added to the mock.
55      */
stubResponses(HttpExecuteResponse... responses)56     void stubResponses(HttpExecuteResponse... responses);
57 
58     /**
59      * Get the last request called on the mock.
60      */
getLastRequest()61     SdkHttpRequest getLastRequest();
62 
63     /**
64      * Get all requests called on the mock.
65      */
getRequests()66     List<SdkHttpRequest> getRequests();
67 
68 }
69