99
1010import java .util .Arrays ;
1111import java .util .Collections ;
12+ import java .util .List ;
1213import java .util .concurrent .CompletableFuture ;
1314import java .util .concurrent .ExecutionException ;
1415import java .util .concurrent .TimeUnit ;
1516
1617import org .junit .jupiter .api .BeforeEach ;
18+ import org .junit .jupiter .api .Test ;
1719import org .junit .jupiter .params .ParameterizedTest ;
1820import org .junit .jupiter .params .provider .MethodSource ;
1921import org .mockito .ArgumentCaptor ;
@@ -42,6 +44,11 @@ public class LambdaHttpHandlerTest {
4244 private static final String QUERY = "testParam1=testValue1&testParam2=testValue2" ;
4345 private static final String HOST_HEADER = "Host" ;
4446 private static final String HOST = "localhost" ;
47+
48+ private static final List <String > COOKIES = List .of ("testcookie1=cvalue1" , "testcookie2=cvalue2" );
49+ private static final String COOKIE_HEADER_KEY = "Cookie" ;
50+ private static final String COOKIE_HEADER_VALUE = "testcookie1=cvalue1; testcookie2=cvalue2" ;
51+
4552 private static final String METHOD = "GET" ;
4653
4754 private final Application application = mock (Application .class );
@@ -60,6 +67,7 @@ public void mockSetup() {
6067 when (requestContext .getHttp ()).thenReturn (requestContextMethod );
6168 when (requestContextMethod .getMethod ()).thenReturn (METHOD );
6269 when (request .getHeaders ()).thenReturn (Collections .singletonMap (HOST_HEADER , HOST ));
70+ when (request .getCookies ()).thenReturn (COOKIES );
6371 when (connection .peer ()).thenReturn (peer );
6472 when (peer .remoteAddress ()).thenReturn (new VirtualAddress ("whatever" ));
6573 }
@@ -116,4 +124,13 @@ public void verifyResponseStatusBypass(final HttpResponseStatus status) throws E
116124 assertEquals (status .code (), response .getStatusCode ());
117125 }
118126
127+ @ Test
128+ public void verifyCookies () throws ExecutionException , InterruptedException {
129+ mockHttpFunction (null , HttpResponseStatus .OK );
130+ ArgumentCaptor <Object > captor = ArgumentCaptor .forClass (Object .class );
131+ verify (connection , timeout (PROCESSING_TIMEOUT ).times (2 )).sendMessage (captor .capture ());
132+ DefaultHttpRequest rq = (DefaultHttpRequest ) captor .getAllValues ().get (0 );
133+ assertEquals (COOKIE_HEADER_VALUE , rq .headers ().get (COOKIE_HEADER_KEY ));
134+ }
135+
119136}
0 commit comments