|
|
|
@ -23,6 +23,7 @@ import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.Comparator; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
@ -54,6 +55,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Jeremy Grelle |
|
|
|
* @author Jeremy Grelle |
|
|
|
* @author Dave Syer |
|
|
|
* @author Dave Syer |
|
|
|
|
|
|
|
* @author Sam Brannen |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" }) |
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" }) |
|
|
|
public class SelectTagTests extends AbstractFormTagTests { |
|
|
|
public class SelectTagTests extends AbstractFormTagTests { |
|
|
|
@ -78,6 +80,18 @@ public class SelectTagTests extends AbstractFormTagTests { |
|
|
|
this.tag.setPageContext(getPageContext()); |
|
|
|
this.tag.setPageContext(getPageContext()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected TestBean createTestBean() { |
|
|
|
|
|
|
|
this.bean = new TestBeanWithRealCountry(); |
|
|
|
|
|
|
|
this.bean.setName("Rob"); |
|
|
|
|
|
|
|
this.bean.setCountry("UK"); |
|
|
|
|
|
|
|
this.bean.setSex("M"); |
|
|
|
|
|
|
|
this.bean.setMyFloat(Float.valueOf("12.34")); |
|
|
|
|
|
|
|
this.bean.setSomeIntegerArray(new Integer[]{12, 34}); |
|
|
|
|
|
|
|
return this.bean; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void dynamicAttributes() throws JspException { |
|
|
|
void dynamicAttributes() throws JspException { |
|
|
|
String dynamicAttribute1 = "attr1"; |
|
|
|
String dynamicAttribute1 = "attr1"; |
|
|
|
@ -133,6 +147,78 @@ public class SelectTagTests extends AbstractFormTagTests { |
|
|
|
assertList(true); |
|
|
|
assertList(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-33023
|
|
|
|
|
|
|
|
void withListWithHtmlEscapingInPath() throws Exception { |
|
|
|
|
|
|
|
this.tag.setPath("favoriteCafé"); |
|
|
|
|
|
|
|
this.tag.setItems(List.of("Cup of Joe", "Jane's Coffee Shop")); |
|
|
|
|
|
|
|
this.tag.setSize("2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var expectedOutput = """ |
|
|
|
|
|
|
|
<select id="favoriteCafé" name="favoriteCafé" size="2"> |
|
|
|
|
|
|
|
<option value="Cup of Joe">Cup of Joe</option> |
|
|
|
|
|
|
|
<option value="Jane's Coffee Shop">Jane's Coffee Shop</option> |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
""".replace("\n", ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY); |
|
|
|
|
|
|
|
assertThat(getOutput()).isEqualTo(expectedOutput); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-33023
|
|
|
|
|
|
|
|
void withListWithHtmlEscapingAndCharacterEncodingInPath() throws Exception { |
|
|
|
|
|
|
|
this.getPageContext().getResponse().setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.tag.setPath("favoriteCafé"); |
|
|
|
|
|
|
|
this.tag.setItems(List.of("Cup of Joe", "Jane's Coffee Shop")); |
|
|
|
|
|
|
|
this.tag.setSize("2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var expectedOutput = """ |
|
|
|
|
|
|
|
<select id="favoriteCafé" name="favoriteCafé" size="2"> |
|
|
|
|
|
|
|
<option value="Cup of Joe">Cup of Joe</option> |
|
|
|
|
|
|
|
<option value="Jane's Coffee Shop">Jane's Coffee Shop</option> |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
""".replace("\n", ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY); |
|
|
|
|
|
|
|
assertThat(getOutput()).isEqualTo(expectedOutput); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-35783
|
|
|
|
|
|
|
|
void withListWithHtmlEscapingInOptions() throws Exception { |
|
|
|
|
|
|
|
this.tag.setPath("name"); |
|
|
|
|
|
|
|
this.tag.setItems(List.of("café", "Jane \"I Love Cafés\" Smith")); |
|
|
|
|
|
|
|
this.tag.setSize("2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var expectedOutput = """ |
|
|
|
|
|
|
|
<select id="name" name="name" size="2"> |
|
|
|
|
|
|
|
<option value="café">café</option> |
|
|
|
|
|
|
|
<option value="Jane "I Love Cafés" Smith">Jane "I Love Cafés" Smith</option> |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
""".replace("\n", ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY); |
|
|
|
|
|
|
|
assertThat(getOutput()).isEqualTo(expectedOutput); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-35783
|
|
|
|
|
|
|
|
void withListWithHtmlEscapingAndCharacterEncodingInOptions() throws Exception { |
|
|
|
|
|
|
|
this.getPageContext().getResponse().setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.tag.setPath("name"); |
|
|
|
|
|
|
|
this.tag.setItems(List.of("café", "Jane \"I Love Cafés\" Smith")); |
|
|
|
|
|
|
|
this.tag.setSize("2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var expectedOutput = """ |
|
|
|
|
|
|
|
<select id="name" name="name" size="2"> |
|
|
|
|
|
|
|
<option value="café">café</option> |
|
|
|
|
|
|
|
<option value="Jane "I Love Cafés" Smith">Jane "I Love Cafés" Smith</option> |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
""".replace("\n", ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY); |
|
|
|
|
|
|
|
assertThat(getOutput()).isEqualTo(expectedOutput); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void withResolvedList() throws Exception { |
|
|
|
void withResolvedList() throws Exception { |
|
|
|
this.tag.setPath("country"); |
|
|
|
this.tag.setPath("country"); |
|
|
|
@ -336,8 +422,58 @@ public class SelectTagTests extends AbstractFormTagTests { |
|
|
|
void withMap() throws Exception { |
|
|
|
void withMap() throws Exception { |
|
|
|
this.tag.setPath("sex"); |
|
|
|
this.tag.setPath("sex"); |
|
|
|
this.tag.setItems(getSexes()); |
|
|
|
this.tag.setItems(getSexes()); |
|
|
|
int result = this.tag.doStartTag(); |
|
|
|
|
|
|
|
assertThat(result).isEqualTo(Tag.SKIP_BODY); |
|
|
|
var expectedOutput = """ |
|
|
|
|
|
|
|
<select id="sex" name="sex"> |
|
|
|
|
|
|
|
<option value="F">Female</option> |
|
|
|
|
|
|
|
<option value="M" selected="selected">Male</option> |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
""".replace("\n", ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY); |
|
|
|
|
|
|
|
assertThat(getOutput()).isEqualTo(expectedOutput); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-35783
|
|
|
|
|
|
|
|
void withMapWithHtmlEscapingInOptions() throws Exception { |
|
|
|
|
|
|
|
var map = new LinkedHashMap<String, String>(); |
|
|
|
|
|
|
|
map.put("F", "Jane \"I Love Cafés\" Smith"); |
|
|
|
|
|
|
|
map.put("M", "Joe Café"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.tag.setPath("sex"); |
|
|
|
|
|
|
|
this.tag.setItems(map); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var expectedOutput = """ |
|
|
|
|
|
|
|
<select id="sex" name="sex"> |
|
|
|
|
|
|
|
<option value="F">Jane "I Love Cafés" Smith</option> |
|
|
|
|
|
|
|
<option value="M" selected="selected">Joe Café</option> |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
""".replace("\n", ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY); |
|
|
|
|
|
|
|
assertThat(getOutput()).isEqualTo(expectedOutput); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // gh-35783
|
|
|
|
|
|
|
|
void withMapWithHtmlEscapingAndCharacterEncodingInOptions() throws Exception { |
|
|
|
|
|
|
|
this.getPageContext().getResponse().setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var map = new LinkedHashMap<String, String>(); |
|
|
|
|
|
|
|
map.put("F", "Jane \"I Love Cafés\" Smith"); |
|
|
|
|
|
|
|
map.put("M", "Joe Café"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.tag.setPath("sex"); |
|
|
|
|
|
|
|
this.tag.setItems(map); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var expectedOutput = """ |
|
|
|
|
|
|
|
<select id="sex" name="sex"> |
|
|
|
|
|
|
|
<option value="F">Jane "I Love Cafés" Smith</option> |
|
|
|
|
|
|
|
<option value="M" selected="selected">Joe Café</option> |
|
|
|
|
|
|
|
</select> |
|
|
|
|
|
|
|
""".replace("\n", ""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(this.tag.doStartTag()).isEqualTo(Tag.SKIP_BODY); |
|
|
|
|
|
|
|
assertThat(getOutput()).isEqualTo(expectedOutput); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -959,7 +1095,7 @@ public class SelectTagTests extends AbstractFormTagTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Map getSexes() { |
|
|
|
private Map getSexes() { |
|
|
|
Map<String, String> sexes = new HashMap<>(); |
|
|
|
Map<String, String> sexes = new LinkedHashMap<>(); |
|
|
|
sexes.put("F", "Female"); |
|
|
|
sexes.put("F", "Female"); |
|
|
|
sexes.put("M", "Male"); |
|
|
|
sexes.put("M", "Male"); |
|
|
|
return sexes; |
|
|
|
return sexes; |
|
|
|
@ -997,17 +1133,6 @@ public class SelectTagTests extends AbstractFormTagTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected TestBean createTestBean() { |
|
|
|
|
|
|
|
this.bean = new TestBeanWithRealCountry(); |
|
|
|
|
|
|
|
this.bean.setName("Rob"); |
|
|
|
|
|
|
|
this.bean.setCountry("UK"); |
|
|
|
|
|
|
|
this.bean.setSex("M"); |
|
|
|
|
|
|
|
this.bean.setMyFloat(Float.valueOf("12.34")); |
|
|
|
|
|
|
|
this.bean.setSomeIntegerArray(new Integer[]{12, 34}); |
|
|
|
|
|
|
|
return this.bean; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TestBean getTestBean() { |
|
|
|
private TestBean getTestBean() { |
|
|
|
return (TestBean) getPageContext().getRequest().getAttribute(COMMAND_NAME); |
|
|
|
return (TestBean) getPageContext().getRequest().getAttribute(COMMAND_NAME); |
|
|
|
} |
|
|
|
} |
|
|
|
|