1
+ package org .springframework .http .client .reactive ;
2
+
3
+ import io .netty .buffer .AdaptiveByteBufAllocator ;
4
+ import io .netty .handler .codec .http .DefaultHttpHeaders ;
5
+ import io .netty .handler .codec .http .cookie .Cookie ;
6
+ import io .netty .handler .codec .http .cookie .DefaultCookie ;
7
+ import org .junit .jupiter .api .Assertions ;
8
+ import org .junit .jupiter .api .BeforeEach ;
9
+ import org .junit .jupiter .api .Test ;
10
+ import org .springframework .http .ResponseCookie ;
11
+ import reactor .netty .Connection ;
12
+ import reactor .netty .NettyOutbound ;
13
+ import reactor .netty .http .client .HttpClientResponse ;
14
+
15
+ import java .util .*;
16
+
17
+ import static org .assertj .core .api .Assertions .assertThat ;
18
+ import static org .mockito .BDDMockito .given ;
19
+ import static org .mockito .Mockito .mock ;
20
+
21
+ class ReactorClientHttpResponseTest {
22
+ private final HttpClientResponse mockResponse = mock ();
23
+
24
+ private final DefaultHttpHeaders httpHeaders = mock ();
25
+
26
+ private final Connection connection = mock ();
27
+
28
+ private final NettyOutbound outbound = mock ();
29
+
30
+ private ReactorClientHttpResponse reactorClientHttpResponse ;
31
+
32
+
33
+ @ BeforeEach
34
+ void configureMocks () {
35
+ given (mockResponse .responseHeaders ()).willReturn (httpHeaders );
36
+ given (connection .outbound ()).willReturn (outbound );
37
+ given (outbound .alloc ()).willReturn (new AdaptiveByteBufAllocator ());
38
+ reactorClientHttpResponse = new ReactorClientHttpResponse (mockResponse , connection );
39
+ }
40
+
41
+ @ Test
42
+ void defaultCookies () {
43
+ Map <CharSequence , Set <Cookie >> mockCookieMap = new HashMap <>();
44
+ DefaultCookie cookie = new DefaultCookie ("foo" , "bar" );
45
+ cookie .setPartitioned (true );
46
+ mockCookieMap .put ("foo" , Set .of (cookie ));
47
+ given (mockResponse .cookies ()).willReturn (mockCookieMap );
48
+
49
+ Assertions .assertTrue (reactorClientHttpResponse .getCookies ().size () == 1 &&
50
+ reactorClientHttpResponse .getCookies ().containsKey ("foo" ));
51
+ ResponseCookie foo = reactorClientHttpResponse .getCookies ().getFirst ("foo" );
52
+ assertThat (foo .isPartitioned ()).isSameAs (cookie .isPartitioned ());
53
+ }
54
+ }
0 commit comments