use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class WebRequestDataBinderTests method testWithCommaSeparatedStringArray.
@Test
public void testWithCommaSeparatedStringArray() throws Exception {
TestBean target = new TestBean();
WebRequestDataBinder binder = new WebRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("stringArray", "bar");
request.addParameter("stringArray", "abc");
request.addParameter("stringArray", "123,def");
binder.bind(new ServletWebRequest(request));
assertThat(target.getStringArray().length).as("Expected all three items to be bound").isEqualTo(3);
request.removeParameter("stringArray");
request.addParameter("stringArray", "123,def");
binder.bind(new ServletWebRequest(request));
assertThat(target.getStringArray().length).as("Expected only 1 item to be bound").isEqualTo(1);
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class RequestScopedProxyTests method testGetFromScope.
@Test
public void testGetFromScope() {
String name = "requestScopedObject";
TestBean bean = (TestBean) this.beanFactory.getBean(name);
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
MockHttpServletRequest request = new MockHttpServletRequest();
RequestAttributes requestAttributes = new ServletRequestAttributes(request);
RequestContextHolder.setRequestAttributes(requestAttributes);
try {
assertThat(request.getAttribute("scopedTarget." + name)).isNull();
assertThat(bean.getName()).isEqualTo("scoped");
assertThat(request.getAttribute("scopedTarget." + name)).isNotNull();
TestBean target = (TestBean) request.getAttribute("scopedTarget." + name);
assertThat(target.getClass()).isEqualTo(TestBean.class);
assertThat(target.getName()).isEqualTo("scoped");
assertThat(this.beanFactory.getBean(name)).isSameAs(bean);
assertThat(target.toString()).isEqualTo(bean.toString());
} finally {
RequestContextHolder.setRequestAttributes(null);
}
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ServletRequestDataBinderTests method testBindingWithNestedObjectCreation.
@Test
public void testBindingWithNestedObjectCreation() throws Exception {
TestBean tb = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(tb, "person");
binder.registerCustomEditor(ITestBean.class, new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(new TestBean());
}
});
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("spouse", "someValue");
request.addParameter("spouse.name", "test");
binder.bind(request);
assertThat(tb.getSpouse()).isNotNull();
assertThat(tb.getSpouse().getName()).isEqualTo("test");
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ServletRequestDataBinderTests method testFieldDefaultPreemptsFieldMarker.
@Test
public void testFieldDefaultPreemptsFieldMarker() throws Exception {
TestBean target = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(target);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("!postProcessed", "on");
request.addParameter("_postProcessed", "visible");
request.addParameter("postProcessed", "on");
binder.bind(request);
assertThat(target.isPostProcessed()).isTrue();
request.removeParameter("postProcessed");
binder.bind(request);
assertThat(target.isPostProcessed()).isTrue();
request.removeParameter("!postProcessed");
binder.bind(request);
assertThat(target.isPostProcessed()).isFalse();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ServletRequestDataBinderTests method testFieldPrefixCausesFieldResetWithIgnoreUnknownFields.
@Test
public void testFieldPrefixCausesFieldResetWithIgnoreUnknownFields() throws Exception {
TestBean target = new TestBean();
ServletRequestDataBinder binder = new ServletRequestDataBinder(target);
binder.setIgnoreUnknownFields(false);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("_postProcessed", "visible");
request.addParameter("postProcessed", "on");
binder.bind(request);
assertThat(target.isPostProcessed()).isTrue();
request.removeParameter("postProcessed");
binder.bind(request);
assertThat(target.isPostProcessed()).isFalse();
}
Aggregations