|
15 | 15 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
16 | 16 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
17 | 17 | import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.ErrorRequest;
|
| 18 | +import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.InvocationRequest; |
18 | 19 | import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.StackElement;
|
19 | 20 | import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.XRayErrorCause;
|
20 | 21 | import com.amazonaws.services.lambda.runtime.api.client.runtimeapi.dto.XRayException;
|
@@ -312,27 +313,62 @@ public void restoreNextWrongStatusCodeTest() {
|
312 | 313 | }
|
313 | 314 |
|
314 | 315 | @Test
|
315 |
| - public void nextTest() { |
| 316 | + public void nextWithoutTenantIdHeaderTest() { |
316 | 317 | try {
|
317 |
| - MockResponse mockResponse = new MockResponse(); |
318 |
| - mockResponse.setResponseCode(HTTP_ACCEPTED); |
319 |
| - mockResponse.setHeader("lambda-runtime-aws-request-id", "1234567890"); |
320 |
| - mockResponse.setHeader("Content-Type", "application/json"); |
| 318 | + MockResponse mockResponse = buildMockResponseForNextInvocation(); |
321 | 319 | mockWebServer.enqueue(mockResponse);
|
322 | 320 |
|
323 |
| - lambdaRuntimeApiClientImpl.nextInvocation(); |
324 |
| - RecordedRequest recordedRequest = mockWebServer.takeRequest(); |
325 |
| - HttpUrl actualUrl = recordedRequest.getRequestUrl(); |
326 |
| - String expectedUrl = "http://" + getHostnamePort() + "/2018-06-01/runtime/invocation/next"; |
327 |
| - assertEquals(expectedUrl, actualUrl.toString()); |
| 321 | + InvocationRequest invocationRequest = lambdaRuntimeApiClientImpl.nextInvocation(); |
| 322 | + verifyNextInvocationRequest(); |
| 323 | + assertNull(invocationRequest.getTenantId()); |
| 324 | + } catch(Exception e) { |
| 325 | + fail(); |
| 326 | + } |
| 327 | + } |
| 328 | + |
| 329 | + @Test |
| 330 | + public void nextWithTenantIdHeaderTest() { |
| 331 | + try { |
| 332 | + MockResponse mockResponse = buildMockResponseForNextInvocation(); |
| 333 | + String expectedTenantId = "my-tenant-id"; |
| 334 | + mockResponse.setHeader("lambda-runtime-aws-tenant-id", expectedTenantId); |
| 335 | + mockWebServer.enqueue(mockResponse); |
| 336 | + |
| 337 | + InvocationRequest invocationRequest = lambdaRuntimeApiClientImpl.nextInvocation(); |
| 338 | + verifyNextInvocationRequest(); |
| 339 | + assertEquals(expectedTenantId, invocationRequest.getTenantId()); |
328 | 340 |
|
329 |
| - String actualBody = recordedRequest.getBody().readUtf8(); |
330 |
| - assertEquals("", actualBody); |
331 | 341 | } catch(Exception e) {
|
332 | 342 | fail();
|
333 | 343 | }
|
334 | 344 | }
|
335 | 345 |
|
| 346 | + @Test |
| 347 | + public void nextWithEmptyTenantIdHeaderTest() { |
| 348 | + try { |
| 349 | + MockResponse mockResponse = buildMockResponseForNextInvocation(); |
| 350 | + mockResponse.setHeader("lambda-runtime-aws-tenant-id", ""); |
| 351 | + mockWebServer.enqueue(mockResponse); |
| 352 | + |
| 353 | + InvocationRequest invocationRequest = lambdaRuntimeApiClientImpl.nextInvocation(); |
| 354 | + verifyNextInvocationRequest(); |
| 355 | + assertNull(invocationRequest.getTenantId()); |
| 356 | + } catch(Exception e) { |
| 357 | + fail(); |
| 358 | + } |
| 359 | + } |
| 360 | + |
| 361 | + @Test |
| 362 | + public void nextWithNullTenantIdHeaderTest() { |
| 363 | + try { |
| 364 | + MockResponse mockResponse = buildMockResponseForNextInvocation(); |
| 365 | + assertThrows(NullPointerException.class, () -> { |
| 366 | + mockResponse.setHeader("lambda-runtime-aws-tenant-id", null); |
| 367 | + }); |
| 368 | + } catch(Exception e) { |
| 369 | + fail(); |
| 370 | + } |
| 371 | + } |
336 | 372 |
|
337 | 373 | @Test
|
338 | 374 | public void createUrlMalformedTest() {
|
@@ -376,6 +412,24 @@ public void lambdaReportErrorXRayHeaderTooLongTest() {
|
376 | 412 | }
|
377 | 413 | }
|
378 | 414 |
|
| 415 | + private MockResponse buildMockResponseForNextInvocation() { |
| 416 | + MockResponse mockResponse = new MockResponse(); |
| 417 | + mockResponse.setResponseCode(HTTP_ACCEPTED); |
| 418 | + mockResponse.setHeader("lambda-runtime-aws-request-id", "1234567890"); |
| 419 | + mockResponse.setHeader("Content-Type", "application/json"); |
| 420 | + return mockResponse; |
| 421 | + } |
| 422 | + |
| 423 | + private void verifyNextInvocationRequest() throws Exception { |
| 424 | + RecordedRequest recordedRequest = mockWebServer.takeRequest(); |
| 425 | + HttpUrl actualUrl = recordedRequest.getRequestUrl(); |
| 426 | + String expectedUrl = "http://" + getHostnamePort() + "/2018-06-01/runtime/invocation/next"; |
| 427 | + assertEquals(expectedUrl, actualUrl.toString()); |
| 428 | + |
| 429 | + String actualBody = recordedRequest.getBody().readUtf8(); |
| 430 | + assertEquals("", actualBody); |
| 431 | + } |
| 432 | + |
379 | 433 | private String getHostnamePort() {
|
380 | 434 | return mockWebServer.getHostName() + ":" + mockWebServer.getPort();
|
381 | 435 | }
|
|
0 commit comments