use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class WebExchangeDataBinderTests method setup.
@BeforeEach
public void setup() throws Exception {
this.testBean = new TestBean();
this.binder = new WebExchangeDataBinder(this.testBean, "person");
this.binder.registerCustomEditor(ITestBean.class, new TestBeanPropertyEditor());
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testCollectionFieldsDefault.
// SPR-13502
@Test
public void testCollectionFieldsDefault() throws Exception {
TestBean target = new TestBean();
target.setSomeSet(null);
target.setSomeList(null);
target.setSomeMap(null);
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("_someSet", "visible");
request.addParameter("_someList", "visible");
request.addParameter("_someMap", "visible");
binder.bind(new ServletWebRequest(request));
assertThat(target.getSomeSet()).isNotNull().isInstanceOf(Set.class);
assertThat(target.getSomeList()).isNotNull().isInstanceOf(List.class);
assertThat(target.getSomeMap()).isNotNull().isInstanceOf(Map.class);
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testFieldDefaultWithNestedProperty.
@Test
public void testFieldDefaultWithNestedProperty() throws Exception {
TestBean target = new TestBean();
target.setSpouse(new TestBean());
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("!spouse.postProcessed", "on");
request.addParameter("_spouse.postProcessed", "visible");
request.addParameter("spouse.postProcessed", "on");
binder.bind(new ServletWebRequest(request));
assertThat(((TestBean) target.getSpouse()).isPostProcessed()).isTrue();
request.removeParameter("spouse.postProcessed");
binder.bind(new ServletWebRequest(request));
assertThat(((TestBean) target.getSpouse()).isPostProcessed()).isTrue();
request.removeParameter("!spouse.postProcessed");
binder.bind(new ServletWebRequest(request));
assertThat(((TestBean) target.getSpouse()).isPostProcessed()).isFalse();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testFieldPrefixCausesFieldResetWithIgnoreUnknownFields.
@Test
public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.setIgnoreUnknownFields(false);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("_postProcessed", "visible");
request.addParameter("postProcessed", "on");
binder.bind(new ServletWebRequest(request));
assertThat(target.isPostProcessed()).isTrue();
request.removeParameter("postProcessed");
binder.bind(new ServletWebRequest(request));
assertThat(target.isPostProcessed()).isFalse();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testMultipartFileAsStringArray.
@Test
public void testMultipartFileAsStringArray() {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("stringArray", "Juergen".getBytes()));
binder.bind(new ServletWebRequest(request));
assertThat(target.getStringArray().length).isEqualTo(1);
assertThat(target.getStringArray()[0]).isEqualTo("Juergen");
}
Aggregations