Skip to content

Commit 4e026b2

Browse files
committed
Add tests for pageable deserialization with various alias formats
Signed-off-by: weslyvinicius <weslyvinicius@hotmail.com>
1 parent bfccbcf commit 4e026b2

File tree

5 files changed

+370
-0
lines changed

5 files changed

+370
-0
lines changed

spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/PageJacksonModuleTests.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,71 @@ void serializeAndDeserializeFilledMultipleCascade() {
189189
assertThat(cascadedResult.getPageable().getPageNumber()).isEqualTo(6);
190190
}
191191

192+
@Test
193+
void deserializePageableWithHyphenatedAlias() {
194+
// Given
195+
File file = new File("./src/test/resources/withPageableAliasHyphen.json");
196+
// When
197+
Page<?> result = objectMapper.readValue(file, Page.class);
198+
// Then
199+
assertThat(result).isNotNull();
200+
assertThat(result.getTotalElements()).isEqualTo(15);
201+
assertThat(result.getContent()).hasSize(10);
202+
assertThat(result.getPageable()).isNotNull();
203+
assertThat(result.getPageable().getPageNumber()).isEqualTo(2);
204+
assertThat(result.getPageable().getPageSize()).isEqualTo(3);
205+
assertThat(result.getPageable().getSort().getOrderFor("firstName").getDirection())
206+
.isEqualTo(Sort.Direction.ASC);
207+
}
208+
209+
@Test
210+
void deserializePageableWithUnderscoreAlias() {
211+
// Given
212+
File file = new File("./src/test/resources/withPageableAliasUnderscore.json");
213+
// When
214+
Page<?> result = objectMapper.readValue(file, Page.class);
215+
// Then
216+
assertThat(result).isNotNull();
217+
assertThat(result.getTotalElements()).isEqualTo(10);
218+
assertThat(result.getContent()).hasSize(10);
219+
assertThat(result.getPageable()).isNotNull();
220+
assertThat(result.getPageable().getPageNumber()).isEqualTo(1);
221+
assertThat(result.getPageable().getPageSize()).isEqualTo(2);
222+
assertThat(result.getPageable().getSort().getOrderFor("lastName").getDirection())
223+
.isEqualTo(Sort.Direction.DESC);
224+
}
225+
226+
@Test
227+
void deserializePageableWithLowercaseAlias() {
228+
// Given
229+
File file = new File("./src/test/resources/withPageableAliasLowercase.json");
230+
// When
231+
Page<?> result = objectMapper.readValue(file, Page.class);
232+
// Then
233+
assertThat(result).isNotNull();
234+
assertThat(result.getTotalElements()).isEqualTo(8);
235+
assertThat(result.getContent()).hasSize(10);
236+
assertThat(result.getPageable()).isNotNull();
237+
assertThat(result.getPageable().getPageNumber()).isEqualTo(0);
238+
assertThat(result.getPageable().getPageSize()).isEqualTo(4);
239+
assertThat(result.getPageable().getSort()).isEqualTo(Sort.unsorted());
240+
}
241+
242+
@Test
243+
void deserializePageableWithPascalCaseAlias() {
244+
// Given
245+
File file = new File("./src/test/resources/withPageableAliasPascalCase.json");
246+
// When
247+
Page<?> result = objectMapper.readValue(file, Page.class);
248+
// Then
249+
assertThat(result).isNotNull();
250+
assertThat(result.getTotalElements()).isEqualTo(20);
251+
assertThat(result.getContent()).hasSize(10);
252+
assertThat(result.getPageable()).isNotNull();
253+
assertThat(result.getPageable().getPageNumber()).isEqualTo(3);
254+
assertThat(result.getPageable().getPageSize()).isEqualTo(2);
255+
assertThat(result.getPageable().getSort().getOrderFor("firstName").getDirection())
256+
.isEqualTo(Sort.Direction.ASC);
257+
}
258+
192259
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"content": [
3+
{
4+
"id": 3,
5+
"lastName": "Williams",
6+
"firstName": "Thomas",
7+
"email": "w.t@my.domain.com"
8+
},
9+
{
10+
"id": 1,
11+
"lastName": "Smith",
12+
"firstName": "James",
13+
"email": "s.j@my.domain.com"
14+
},
15+
{
16+
"id": 11,
17+
"lastName": "Scott",
18+
"firstName": "Steven",
19+
"email": "s.s@my.domain.com"
20+
},
21+
{
22+
"id": 8,
23+
"lastName": "Rodriguez",
24+
"firstName": "Daniel",
25+
"email": "r.d@my.domain.com"
26+
},
27+
{
28+
"id": 9,
29+
"lastName": "Martinez",
30+
"firstName": "Robert",
31+
"email": "m.r@my.domain.com"
32+
},
33+
{
34+
"id": 5,
35+
"lastName": "Jones",
36+
"firstName": "James",
37+
"email": "j.j@my.domain.com"
38+
},
39+
{
40+
"id": 2,
41+
"lastName": "Johnson",
42+
"firstName": "Robert",
43+
"email": "j.r@my.domain.com"
44+
},
45+
{
46+
"id": 6,
47+
"lastName": "Garcia",
48+
"firstName": "William",
49+
"email": "g.w@my.domain.com"
50+
},
51+
{
52+
"id": 7,
53+
"lastName": "Davis",
54+
"firstName": "Richard",
55+
"email": "d.r@my.domain.com"
56+
},
57+
{
58+
"id": 4,
59+
"lastName": "Brown",
60+
"firstName": "Paul",
61+
"email": "b.p@my.domain.com"
62+
}
63+
],
64+
"pageable": {
65+
"page-number": 2,
66+
"page-size": 3,
67+
"sort": {
68+
"orders": [
69+
{
70+
"direction": "ASC",
71+
"property": "firstName"
72+
}
73+
]
74+
}
75+
},
76+
"totalElements": 15
77+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"content": [
3+
{
4+
"id": 3,
5+
"lastName": "Williams",
6+
"firstName": "Thomas",
7+
"email": "w.t@my.domain.com"
8+
},
9+
{
10+
"id": 1,
11+
"lastName": "Smith",
12+
"firstName": "James",
13+
"email": "s.j@my.domain.com"
14+
},
15+
{
16+
"id": 11,
17+
"lastName": "Scott",
18+
"firstName": "Steven",
19+
"email": "s.s@my.domain.com"
20+
},
21+
{
22+
"id": 8,
23+
"lastName": "Rodriguez",
24+
"firstName": "Daniel",
25+
"email": "r.d@my.domain.com"
26+
},
27+
{
28+
"id": 9,
29+
"lastName": "Martinez",
30+
"firstName": "Robert",
31+
"email": "m.r@my.domain.com"
32+
},
33+
{
34+
"id": 5,
35+
"lastName": "Jones",
36+
"firstName": "James",
37+
"email": "j.j@my.domain.com"
38+
},
39+
{
40+
"id": 2,
41+
"lastName": "Johnson",
42+
"firstName": "Robert",
43+
"email": "j.r@my.domain.com"
44+
},
45+
{
46+
"id": 6,
47+
"lastName": "Garcia",
48+
"firstName": "William",
49+
"email": "g.w@my.domain.com"
50+
},
51+
{
52+
"id": 7,
53+
"lastName": "Davis",
54+
"firstName": "Richard",
55+
"email": "d.r@my.domain.com"
56+
},
57+
{
58+
"id": 4,
59+
"lastName": "Brown",
60+
"firstName": "Paul",
61+
"email": "b.p@my.domain.com"
62+
}
63+
],
64+
"pageable": {
65+
"pagenumber": 0,
66+
"pagesize": 4,
67+
"sort": {
68+
"orders": []
69+
}
70+
},
71+
"totalElements": 8
72+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"content": [
3+
{
4+
"id": 3,
5+
"lastName": "Williams",
6+
"firstName": "Thomas",
7+
"email": "w.t@my.domain.com"
8+
},
9+
{
10+
"id": 1,
11+
"lastName": "Smith",
12+
"firstName": "James",
13+
"email": "s.j@my.domain.com"
14+
},
15+
{
16+
"id": 11,
17+
"lastName": "Scott",
18+
"firstName": "Steven",
19+
"email": "s.s@my.domain.com"
20+
},
21+
{
22+
"id": 8,
23+
"lastName": "Rodriguez",
24+
"firstName": "Daniel",
25+
"email": "r.d@my.domain.com"
26+
},
27+
{
28+
"id": 9,
29+
"lastName": "Martinez",
30+
"firstName": "Robert",
31+
"email": "m.r@my.domain.com"
32+
},
33+
{
34+
"id": 5,
35+
"lastName": "Jones",
36+
"firstName": "James",
37+
"email": "j.j@my.domain.com"
38+
},
39+
{
40+
"id": 2,
41+
"lastName": "Johnson",
42+
"firstName": "Robert",
43+
"email": "j.r@my.domain.com"
44+
},
45+
{
46+
"id": 6,
47+
"lastName": "Garcia",
48+
"firstName": "William",
49+
"email": "g.w@my.domain.com"
50+
},
51+
{
52+
"id": 7,
53+
"lastName": "Davis",
54+
"firstName": "Richard",
55+
"email": "d.r@my.domain.com"
56+
},
57+
{
58+
"id": 4,
59+
"lastName": "Brown",
60+
"firstName": "Paul",
61+
"email": "b.p@my.domain.com"
62+
}
63+
],
64+
"pageable": {
65+
"PageNumber": 3,
66+
"PageSize": 2,
67+
"sort": {
68+
"orders": [
69+
{
70+
"direction": "ASC",
71+
"property": "firstName"
72+
}
73+
]
74+
}
75+
},
76+
"totalElements": 20
77+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"content": [
3+
{
4+
"id": 3,
5+
"lastName": "Williams",
6+
"firstName": "Thomas",
7+
"email": "w.t@my.domain.com"
8+
},
9+
{
10+
"id": 1,
11+
"lastName": "Smith",
12+
"firstName": "James",
13+
"email": "s.j@my.domain.com"
14+
},
15+
{
16+
"id": 11,
17+
"lastName": "Scott",
18+
"firstName": "Steven",
19+
"email": "s.s@my.domain.com"
20+
},
21+
{
22+
"id": 8,
23+
"lastName": "Rodriguez",
24+
"firstName": "Daniel",
25+
"email": "r.d@my.domain.com"
26+
},
27+
{
28+
"id": 9,
29+
"lastName": "Martinez",
30+
"firstName": "Robert",
31+
"email": "m.r@my.domain.com"
32+
},
33+
{
34+
"id": 5,
35+
"lastName": "Jones",
36+
"firstName": "James",
37+
"email": "j.j@my.domain.com"
38+
},
39+
{
40+
"id": 2,
41+
"lastName": "Johnson",
42+
"firstName": "Robert",
43+
"email": "j.r@my.domain.com"
44+
},
45+
{
46+
"id": 6,
47+
"lastName": "Garcia",
48+
"firstName": "William",
49+
"email": "g.w@my.domain.com"
50+
},
51+
{
52+
"id": 7,
53+
"lastName": "Davis",
54+
"firstName": "Richard",
55+
"email": "d.r@my.domain.com"
56+
},
57+
{
58+
"id": 4,
59+
"lastName": "Brown",
60+
"firstName": "Paul",
61+
"email": "b.p@my.domain.com"
62+
}
63+
],
64+
"pageable": {
65+
"page_number": 1,
66+
"page_size": 2,
67+
"sort": {
68+
"orders": [
69+
{
70+
"direction": "DESC",
71+
"property": "lastName"
72+
}
73+
]
74+
}
75+
},
76+
"totalElements": 10
77+
}

0 commit comments

Comments
 (0)