Search in sources :

Example 21 with TestBean

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

the class SelectTagTests method withNullValue.

@Test
public void withNullValue() throws Exception {
    TestBean tb = getTestBean();
    tb.setCountry(null);
    this.tag.setPath("country");
    this.tag.setItems(Country.getCountries());
    assertList(false);
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Example 22 with TestBean

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

the class SelectTagTests method withOtherValue.

@Test
public void withOtherValue() throws Exception {
    TestBean tb = getTestBean();
    tb.setCountry("AT");
    this.tag.setPath("country");
    this.tag.setItems(Country.getCountries());
    assertList(false);
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Example 23 with TestBean

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

the class ModelAttributeMethodProcessorTests method resolveArgumentOrdering.

// SPR-9378
@Test
public void resolveArgumentOrdering() throws Exception {
    String name = "testBean";
    Object testBean = new TestBean(name);
    this.container.addAttribute(name, testBean);
    this.container.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, testBean);
    Object anotherTestBean = new TestBean();
    this.container.addAttribute("anotherTestBean", anotherTestBean);
    StubRequestDataBinder dataBinder = new StubRequestDataBinder(testBean, name);
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(this.request, testBean, name)).willReturn(dataBinder);
    this.processor.resolveArgument(this.paramModelAttr, this.container, this.request, binderFactory);
    Object[] values = this.container.getModel().values().toArray();
    assertThat(values[1]).as("Resolved attribute should be updated to be last").isSameAs(testBean);
    assertThat(values[2]).as("BindingResult of resolved attr should be last").isSameAs(dataBinder.getBindingResult());
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) Test(org.junit.jupiter.api.Test)

Example 24 with TestBean

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

the class ModelAttributeMethodProcessorTests method resolveArgumentBindException.

@Test
public void resolveArgumentBindException() throws Exception {
    String name = "testBean";
    Object target = new TestBean();
    this.container.getModel().addAttribute(target);
    StubRequestDataBinder dataBinder = new StubRequestDataBinder(target, name);
    dataBinder.getBindingResult().reject("error");
    WebDataBinderFactory binderFactory = mock(WebDataBinderFactory.class);
    given(binderFactory.createBinder(this.request, target, name)).willReturn(dataBinder);
    assertThatExceptionOfType(BindException.class).isThrownBy(() -> this.processor.resolveArgument(this.paramNonSimpleType, this.container, this.request, binderFactory));
    verify(binderFactory).createBinder(this.request, target, name);
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) BindException(org.springframework.validation.BindException) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) Test(org.junit.jupiter.api.Test)

Example 25 with TestBean

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

the class ServletModelAttributeMethodProcessorTests method createAttributeUriTemplateVar.

@Test
public void createAttributeUriTemplateVar() throws Exception {
    Map<String, String> uriTemplateVars = new HashMap<>();
    uriTemplateVars.put("testBean1", "Patty");
    request.setAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVars);
    // Type conversion from "Patty" to TestBean via TestBean(String) constructor
    TestBean testBean = (TestBean) processor.resolveArgument(testBeanModelAttr, mavContainer, webRequest, binderFactory);
    assertThat(testBean.getName()).isEqualTo("Patty");
}
Also used : HashMap(java.util.HashMap) 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