Search in sources :

Example 16 with TestBean

use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.

the class FreeMarkerMacroTests method testExposeSpringMacroHelpers.

@Test
public void testExposeSpringMacroHelpers() throws Exception {
    FreeMarkerView fv = new FreeMarkerView() {

        @Override
        @SuppressWarnings("rawtypes")
        protected void processTemplate(Template template, SimpleHash fmModel, HttpServletResponse response) throws TemplateException {
            Map model = fmModel.toMap();
            assertThat(model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE)).isInstanceOf(RequestContext.class);
            RequestContext rc = (RequestContext) model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
            BindStatus status = rc.getBindStatus("tb.name");
            assertThat(status.getExpression()).isEqualTo("name");
            assertThat(status.getValue()).isEqualTo("juergen");
        }
    };
    fv.setUrl(TEMPLATE_FILE);
    fv.setApplicationContext(wac);
    Map<String, Object> model = new HashMap<>();
    model.put("tb", new TestBean("juergen", 99));
    fv.render(model, request, response);
}
Also used : HashMap(java.util.HashMap) TestBean(org.springframework.beans.testfixture.beans.TestBean) SimpleHash(freemarker.template.SimpleHash) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) DummyMacroRequestContext(org.springframework.web.servlet.view.DummyMacroRequestContext) RequestContext(org.springframework.web.servlet.support.RequestContext) BindStatus(org.springframework.web.servlet.support.BindStatus) HashMap(java.util.HashMap) Map(java.util.Map) Template(freemarker.template.Template) Test(org.junit.jupiter.api.Test)

Example 17 with TestBean

use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.

the class TextareaTagTests method createTestBean.

@Override
protected TestBean createTestBean() {
    // set up test data
    this.rob = new TestBean();
    rob.setName("Rob");
    rob.setMyFloat(12.34f);
    TestBean sally = new TestBean();
    sally.setName("Sally");
    rob.setSpouse(sally);
    return rob;
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean)

Example 18 with TestBean

use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.

the class InputTagTests method createTestBean.

@Override
protected TestBean createTestBean() {
    // set up test data
    this.rob = new TestBean();
    this.rob.setName("Rob");
    this.rob.setMyFloat(Float.valueOf(12.34f));
    TestBean sally = new TestBean();
    sally.setName("Sally");
    this.rob.setSpouse(sally);
    return this.rob;
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean)

Example 19 with TestBean

use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.

the class LabelTagTests method createTestBean.

@Override
protected TestBean createTestBean() {
    TestBean bean = new TestBean();
    bean.setSpouse(new TestBean("Hoopy"));
    return bean;
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean)

Example 20 with TestBean

use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.

the class SelectTagTests method withInvalidList.

@Test
public void withInvalidList() throws Exception {
    this.tag.setPath("country");
    this.tag.setItems(new TestBean());
    this.tag.setItemValue("isoCode");
    assertThatExceptionOfType(JspException.class).as("use a non-Collection typed value as the value of 'items'").isThrownBy(this.tag::doStartTag).withMessageContaining("items").withMessageContaining("org.springframework.beans.testfixture.beans.TestBean");
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Aggregations

TestBean (org.springframework.beans.testfixture.beans.TestBean)808 Test (org.junit.jupiter.api.Test)765 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)472 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)268 NestedTestBean (org.springframework.beans.testfixture.beans.NestedTestBean)183 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)167 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)162 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)118 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)96 BooleanTestBean (org.springframework.beans.testfixture.beans.BooleanTestBean)40 NumberTestBean (org.springframework.beans.testfixture.beans.NumberTestBean)40 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)39 Properties (java.util.Properties)38 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)37 HashMap (java.util.HashMap)36 Errors (org.springframework.validation.Errors)35 PropertyEditorSupport (java.beans.PropertyEditorSupport)34 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)29 List (java.util.List)28 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)28