Skip to content

Commit 1334611

Browse files
committed
tabular data on form post fix jooby-project#480
1 parent a5ef6af commit 1334611

13 files changed

Lines changed: 1086 additions & 317 deletions

File tree

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
package org.jooby.issues;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.Optional;
6+
7+
import org.jooby.test.ServerFeature;
8+
import org.junit.Test;
9+
10+
public class Issue480 extends ServerFeature {
11+
12+
public static class Member {
13+
String firstname;
14+
15+
String lastname;
16+
17+
@Override
18+
public String toString() {
19+
return firstname + " " + lastname;
20+
}
21+
}
22+
23+
public static class Group {
24+
25+
List<Member> members;
26+
27+
@Override
28+
public String toString() {
29+
return Optional.ofNullable(members).map(it -> it.toString()).orElse("[]");
30+
}
31+
32+
}
33+
34+
public static class Person {
35+
String name;
36+
37+
List<Person> children = new ArrayList<>();
38+
39+
@Override
40+
public String toString() {
41+
return name + children;
42+
}
43+
}
44+
45+
public static class RListOfStr {
46+
ListOfStr str;
47+
48+
@Override
49+
public String toString() {
50+
return str.toString();
51+
}
52+
}
53+
54+
public static class ListOfStr {
55+
List<String> children = new ArrayList<>();
56+
57+
@Override
58+
public String toString() {
59+
return children.toString();
60+
}
61+
}
62+
63+
public static class ListOfInt {
64+
List<Integer> children = new ArrayList<>();
65+
66+
@Override
67+
public String toString() {
68+
return children.toString();
69+
}
70+
}
71+
72+
{
73+
get("/480", req -> {
74+
return req.params().toList(Member.class);
75+
});
76+
77+
get("/480/nested", req -> {
78+
return req.params(Group.class);
79+
});
80+
81+
get("/480/tree", req -> {
82+
return req.params(Person.class);
83+
});
84+
85+
get("/480/listOfStr", req -> {
86+
return req.params(ListOfStr.class);
87+
});
88+
89+
get("/480/rlistOfStr", req -> {
90+
return req.params(RListOfStr.class);
91+
});
92+
93+
get("/480/listOfInt", req -> {
94+
return req.params(ListOfInt.class);
95+
});
96+
}
97+
98+
@Test
99+
public void rootList() throws Exception {
100+
request()
101+
.get("/480?[0][firstname]=Pedro&[0][lastname]=PicaPiedra")
102+
.expect("[Pedro PicaPiedra]");
103+
104+
request()
105+
.get(
106+
"/480?[0][firstname]=Pedro&[0][lastname]=PicaPiedra&[1][firstname]=Pablo&[1][lastname]=Marmol")
107+
.expect("[Pedro PicaPiedra, Pablo Marmol]");
108+
}
109+
110+
@Test
111+
public void nestedList() throws Exception {
112+
request()
113+
.get("/480/nested?members[0][firstname]=Pedro&members[0][lastname]=PicaPiedra")
114+
.expect("[Pedro PicaPiedra]");
115+
116+
request()
117+
.get(
118+
"/480/nested?members[0][firstname]=Pedro&members[0][lastname]=PicaPiedra&members[1][firstname]=Pablo&members[1][lastname]=Marmol")
119+
.expect("[Pedro PicaPiedra, Pablo Marmol]");
120+
121+
}
122+
123+
@Test
124+
public void skipUnknownPath() throws Exception {
125+
request()
126+
.get("/480/nested?unknown=x")
127+
.expect("[]");
128+
129+
request()
130+
.get("/480/nested?members[0][firstname]=Pedro&members[0][lastname]=PicaPiedra&unknown=x")
131+
.expect("[Pedro PicaPiedra]");
132+
}
133+
134+
@Test
135+
public void skipUnknownNestedPath() throws Exception {
136+
request()
137+
.get(
138+
"/480/nested?members[0][firstname]=Pedro&members[0][lastname]=PicaPiedra&members[0][unknown]=x")
139+
.expect("[Pedro PicaPiedra]");
140+
}
141+
142+
@Test
143+
public void shouldTraverseTreeLike() throws Exception {
144+
request()
145+
.get("/480/tree?name=A&children[0][name]=B")
146+
.expect("A[B[]]");
147+
148+
request()
149+
.get("/480/tree?name=A&children[0][name]=B&children[1][name]=C")
150+
.expect("A[B[], C[]]");
151+
}
152+
153+
@Test
154+
public void shouldWorkWithListOfStr() throws Exception {
155+
request()
156+
.get("/480/listOfStr?children[0]=foo")
157+
.expect("[foo]");
158+
159+
request()
160+
.get("/480/listOfStr?children[0]=foo&children[1]=bar")
161+
.expect("[foo, bar]");
162+
163+
request()
164+
.get("/480/rlistOfStr?str[children][0]=foo&str[children][1]=bar")
165+
.expect("[foo, bar]");
166+
}
167+
168+
@Test
169+
public void shouldGetItemsInOrder() throws Exception {
170+
request()
171+
.get("/480/listOfStr?children[1]=1&children[2]=2&children[0]=0")
172+
.expect("[0, 1, 2]");
173+
}
174+
175+
@Test
176+
public void shouldWorkWithListInt() throws Exception {
177+
request()
178+
.get("/480/listOfInt?children[0]=1")
179+
.expect("[1]");
180+
181+
request()
182+
.get("/480/listOfInt?children[0]=1&children[1]=2")
183+
.expect("[1, 2]");
184+
}
185+
186+
}

0 commit comments

Comments
 (0)