|
9 | 9 | import com.amazonaws.http.apache.client.impl.SdkHttpClient; |
10 | 10 | import com.amazonaws.regions.Region; |
11 | 11 | import com.amazonaws.regions.Regions; |
| 12 | +import java.util.Arrays; |
| 13 | +import java.util.List; |
12 | 14 | import org.apache.http.HttpResponse; |
13 | 15 | import org.apache.http.HttpVersion; |
14 | 16 | import org.apache.http.client.methods.HttpUriRequest; |
@@ -81,6 +83,33 @@ public void testExecute_happy() throws IOException { |
81 | 83 | any(HttpContext.class)); |
82 | 84 | } |
83 | 85 |
|
| 86 | + @Test |
| 87 | + public void testExecute_happy_parameters() throws IOException { |
| 88 | + Map<String, String> headers = new HashMap<>(); |
| 89 | + headers.put("Account-Id", "fubar"); |
| 90 | + headers.put("Content-Type", "application/json"); |
| 91 | + Map<String,List<String>> parameters = new HashMap<>(); |
| 92 | + parameters.put("MyParam", Arrays.asList("MyParamValue")); |
| 93 | + GenericApiGatewayResponse response = client.execute( |
| 94 | + new GenericApiGatewayRequestBuilder() |
| 95 | + .withBody(new ByteArrayInputStream("test request".getBytes())) |
| 96 | + .withHttpMethod(HttpMethodName.POST) |
| 97 | + .withHeaders(headers) |
| 98 | + .withParameters(parameters) |
| 99 | + .withResourcePath("/test/orders").build()); |
| 100 | + |
| 101 | + assertEquals("Wrong response body", "test payload", response.getBody()); |
| 102 | + assertEquals("Wrong response status", 200, response.getHttpResponse().getStatusCode()); |
| 103 | + |
| 104 | + Mockito.verify(mockClient, times(1)).execute(argThat(new LambdaMatcher<>( |
| 105 | + x -> (x.getMethod().equals("POST") |
| 106 | + && x.getFirstHeader("Account-Id").getValue().equals("fubar") |
| 107 | + && x.getFirstHeader("x-api-key").getValue().equals("12345") |
| 108 | + && x.getFirstHeader("Authorization").getValue().startsWith("AWS4") |
| 109 | + && x.getURI().toString().equals("https://foobar.execute-api.us-east-1.amazonaws.com/test/orders?MyParam=MyParamValue")))), |
| 110 | + any(HttpContext.class)); |
| 111 | + } |
| 112 | + |
84 | 113 | @Test |
85 | 114 | public void testExecute_noApiKey_noCreds() throws IOException { |
86 | 115 | client = new GenericApiGatewayClientBuilder() |
|
0 commit comments