|
10 | 10 | import com.amazonaws.services.lambda.runtime.Context;
|
11 | 11 | import com.amazonaws.services.lambda.runtime.LambdaLogger;
|
12 | 12 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
| 13 | +import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; |
| 14 | +import com.amazonaws.services.lambda.runtime.events.APIGatewayV2ProxyRequestEvent; |
| 15 | +import com.amazonaws.services.lambda.runtime.events.APIGatewayV2ProxyResponseEvent; |
13 | 16 | import com.amazonaws.services.lambda.runtime.events.CloudFrontEvent;
|
14 | 17 | import com.amazonaws.services.lambda.runtime.events.CloudWatchLogsEvent;
|
15 | 18 | import com.amazonaws.services.lambda.runtime.events.CodeCommitEvent;
|
@@ -253,6 +256,74 @@ public void testAPIGatewayProxyRequestEvent() {
|
253 | 256 | "APIGatewayProxyRequestEventUserARN", span.tags().get("aws.lambda.eventSource.arn"));
|
254 | 257 | }
|
255 | 258 |
|
| 259 | + @Test |
| 260 | + public void testAPIGatewayProxyRequestResponseEvent() { |
| 261 | + int expectedStatusCode = 200; |
| 262 | + final MyApiGatewayProxyRequestResponseHandler myApiGatewayProxyRequestHandler = |
| 263 | + new MyApiGatewayProxyRequestResponseHandler(expectedStatusCode); |
| 264 | + |
| 265 | + final APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent = |
| 266 | + new APIGatewayProxyRequestEvent(); |
| 267 | + final APIGatewayProxyRequestEvent.RequestIdentity requestIdentity = |
| 268 | + new APIGatewayProxyRequestEvent.RequestIdentity(); |
| 269 | + requestIdentity.setUserArn("APIGatewayProxyRequestEventUserARN"); |
| 270 | + final APIGatewayProxyRequestEvent.ProxyRequestContext proxyRequestContext = |
| 271 | + new APIGatewayProxyRequestEvent.ProxyRequestContext(); |
| 272 | + proxyRequestContext.setIdentity(requestIdentity); |
| 273 | + apiGatewayProxyRequestEvent.setRequestContext(proxyRequestContext); |
| 274 | + |
| 275 | + myApiGatewayProxyRequestHandler.handleRequest(apiGatewayProxyRequestEvent, createContext()); |
| 276 | + final MockSpan span = mockTracer.finishedSpans().get(0); |
| 277 | + Assert.assertEquals( |
| 278 | + "APIGatewayProxyRequestEventUserARN", span.tags().get("aws.lambda.eventSource.arn")); |
| 279 | + Assert.assertEquals(Integer.toString(expectedStatusCode), span.tags().get("http.status_code")); |
| 280 | + } |
| 281 | + |
| 282 | + @Test |
| 283 | + public void testAPIGatewayV2ProxyRequestEvent() { |
| 284 | + final MyApiGatewayV2ProxyRequestHandler myApiGatewayV2ProxyRequestHandler = |
| 285 | + new MyApiGatewayV2ProxyRequestHandler(); |
| 286 | + |
| 287 | + final APIGatewayV2ProxyRequestEvent apiGatewayV2ProxyRequestEvent = |
| 288 | + new APIGatewayV2ProxyRequestEvent(); |
| 289 | + final APIGatewayV2ProxyRequestEvent.RequestIdentity requestIdentity = |
| 290 | + new APIGatewayV2ProxyRequestEvent.RequestIdentity(); |
| 291 | + requestIdentity.setUserArn("APIGatewayV2ProxyRequestEventUserARN"); |
| 292 | + final APIGatewayV2ProxyRequestEvent.RequestContext proxyRequestContext = |
| 293 | + new APIGatewayV2ProxyRequestEvent.RequestContext(); |
| 294 | + proxyRequestContext.setIdentity(requestIdentity); |
| 295 | + apiGatewayV2ProxyRequestEvent.setRequestContext(proxyRequestContext); |
| 296 | + |
| 297 | + myApiGatewayV2ProxyRequestHandler.handleRequest(apiGatewayV2ProxyRequestEvent, createContext()); |
| 298 | + final MockSpan span = mockTracer.finishedSpans().get(0); |
| 299 | + Assert.assertEquals( |
| 300 | + "APIGatewayV2ProxyRequestEventUserARN", span.tags().get("aws.lambda.eventSource.arn")); |
| 301 | + Assert.assertFalse(span.tags().containsKey("http.status_code")); |
| 302 | + } |
| 303 | + |
| 304 | + @Test |
| 305 | + public void testAPIGatewayV2ProxyRequestResponseEvent() { |
| 306 | + int expectedStatusCode = 200; |
| 307 | + final MyApiGatewayV2ProxyRequestResponseHandler myApiGatewayV2ProxyRequestHandler = |
| 308 | + new MyApiGatewayV2ProxyRequestResponseHandler(expectedStatusCode); |
| 309 | + |
| 310 | + final APIGatewayV2ProxyRequestEvent apiGatewayV2ProxyRequestEvent = |
| 311 | + new APIGatewayV2ProxyRequestEvent(); |
| 312 | + final APIGatewayV2ProxyRequestEvent.RequestIdentity requestIdentity = |
| 313 | + new APIGatewayV2ProxyRequestEvent.RequestIdentity(); |
| 314 | + requestIdentity.setUserArn("APIGatewayV2ProxyRequestEventUserARN"); |
| 315 | + final APIGatewayV2ProxyRequestEvent.RequestContext proxyRequestContext = |
| 316 | + new APIGatewayV2ProxyRequestEvent.RequestContext(); |
| 317 | + proxyRequestContext.setIdentity(requestIdentity); |
| 318 | + apiGatewayV2ProxyRequestEvent.setRequestContext(proxyRequestContext); |
| 319 | + |
| 320 | + myApiGatewayV2ProxyRequestHandler.handleRequest(apiGatewayV2ProxyRequestEvent, createContext()); |
| 321 | + final MockSpan span = mockTracer.finishedSpans().get(0); |
| 322 | + Assert.assertEquals( |
| 323 | + "APIGatewayV2ProxyRequestEventUserARN", span.tags().get("aws.lambda.eventSource.arn")); |
| 324 | + Assert.assertEquals(Integer.toString(expectedStatusCode), span.tags().get("http.status_code")); |
| 325 | + } |
| 326 | + |
256 | 327 | @Test
|
257 | 328 | @Ignore("We would like this but there doesn't seem to be an available arn currently")
|
258 | 329 | public void testCloudWatchLogsEvent() {
|
@@ -373,6 +444,55 @@ public Object doHandleRequest(
|
373 | 444 | }
|
374 | 445 | }
|
375 | 446 |
|
| 447 | + static class MyApiGatewayProxyRequestResponseHandler |
| 448 | + implements TracingRequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> { |
| 449 | + |
| 450 | + private int statusCode; |
| 451 | + |
| 452 | + public MyApiGatewayProxyRequestResponseHandler(int statusCode) { |
| 453 | + this.statusCode = statusCode; |
| 454 | + } |
| 455 | + |
| 456 | + @Override |
| 457 | + public APIGatewayProxyResponseEvent doHandleRequest( |
| 458 | + APIGatewayProxyRequestEvent apiGatewayV2ProxyRequestEvent, Context context) { |
| 459 | + APIGatewayProxyResponseEvent responseEvent = new APIGatewayProxyResponseEvent(); |
| 460 | + responseEvent.setStatusCode(statusCode); |
| 461 | + responseEvent.setBody("null"); |
| 462 | + return responseEvent; |
| 463 | + } |
| 464 | + } |
| 465 | + |
| 466 | + static class MyApiGatewayV2ProxyRequestHandler |
| 467 | + implements TracingRequestHandler<APIGatewayV2ProxyRequestEvent, Object> { |
| 468 | + |
| 469 | + @Override |
| 470 | + public Object doHandleRequest( |
| 471 | + APIGatewayV2ProxyRequestEvent apiGatewayV2ProxyRequestEvent, Context context) { |
| 472 | + return "null"; |
| 473 | + } |
| 474 | + } |
| 475 | + |
| 476 | + static class MyApiGatewayV2ProxyRequestResponseHandler |
| 477 | + implements TracingRequestHandler< |
| 478 | + APIGatewayV2ProxyRequestEvent, APIGatewayV2ProxyResponseEvent> { |
| 479 | + |
| 480 | + private int statusCode; |
| 481 | + |
| 482 | + public MyApiGatewayV2ProxyRequestResponseHandler(int statusCode) { |
| 483 | + this.statusCode = statusCode; |
| 484 | + } |
| 485 | + |
| 486 | + @Override |
| 487 | + public APIGatewayV2ProxyResponseEvent doHandleRequest( |
| 488 | + APIGatewayV2ProxyRequestEvent apiGatewayV2ProxyRequestEvent, Context context) { |
| 489 | + APIGatewayV2ProxyResponseEvent responseEvent = new APIGatewayV2ProxyResponseEvent(); |
| 490 | + responseEvent.setStatusCode(statusCode); |
| 491 | + responseEvent.setBody("null"); |
| 492 | + return responseEvent; |
| 493 | + } |
| 494 | + } |
| 495 | + |
376 | 496 | // Cloud Front
|
377 | 497 | static class MyCloudFrontRequestHandler
|
378 | 498 | implements TracingRequestHandler<CloudFrontEvent, Object> {
|
|
0 commit comments