-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrokenQueryParamsTest.java
89 lines (76 loc) · 2.16 KB
/
BrokenQueryParamsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package org.example.queryparamsbugs;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import java.util.List;
import java.util.Map;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class BrokenQueryParamsTest {
@Autowired
private WebTestClient webTestClient;
@Test
void unindexedStringArray() {
final var expected = new ArrayDto(
List.of("asd"),
null
);
webTestClient.get()
.uri("/array?stringList[]=asd")
.exchange()
.expectStatus()
.is2xxSuccessful()
.expectBody(ArrayDto.class)
.isEqualTo(expected);
}
@Test
void indexedIntArray() {
final var expected = new ArrayDto(
List.of("asd"),
List.of(123)
);
webTestClient.get()
.uri("/array?stringList[0]=asd&intList[0]=123")
.exchange()
.expectStatus()
.is2xxSuccessful()
.expectBody(ArrayDto.class)
.isEqualTo(expected);
}
@Test
void mapWithIntValues() {
final var expected = new MapDto(
Map.of(
"key1", 123
)
);
webTestClient.get()
.uri("/map?intMap[key1]=123")
.exchange()
.expectStatus()
.is2xxSuccessful()
.expectBody(MapDto.class)
.isEqualTo(expected);
}
}
@RestController
class TestController {
@GetMapping("/array")
public Mono<ArrayDto> array(ArrayDto queryParams) {
return Mono.just(queryParams);
}
@GetMapping("/map")
public Mono<MapDto> array(MapDto queryParams) {
return Mono.just(queryParams);
}
}
record ArrayDto(
List<String> stringList,
List<Integer> intList
) {}
record MapDto(
Map<String, Integer> intMap
) {}