Search in sources :

Example 11 with TestBean

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

the class RedirectAttributesModelMapTests method addAttributeValue.

@Test
void addAttributeValue() {
    this.redirectAttributes.addAttribute(new TestBean("Fred"));
    assertThat(this.redirectAttributes.get("testBean")).isEqualTo("Fred");
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Example 12 with TestBean

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

the class RedirectAttributesModelMapTests method addAttributeCustomType.

@Test
void addAttributeCustomType() {
    String attrName = "person";
    this.redirectAttributes.addAttribute(attrName, new TestBean("Fred"));
    assertThat(this.redirectAttributes.get(attrName)).as("ConversionService should have invoked toString()").isEqualTo("Fred");
    this.conversionService.addConverter(new TestBeanConverter());
    this.redirectAttributes.addAttribute(attrName, new TestBean("Fred"));
    assertThat(this.redirectAttributes.get(attrName)).as("Type converter should have been used").isEqualTo("[Fred]");
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Example 13 with TestBean

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

the class RedirectAttributesModelMapTests method put.

@Test
void put() {
    this.redirectAttributes.put("testBean", new TestBean("Fred"));
    assertThat(this.redirectAttributes.get("testBean")).isEqualTo("Fred");
}
Also used : TestBean(org.springframework.beans.testfixture.beans.TestBean) Test(org.junit.jupiter.api.Test)

Example 14 with TestBean

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

the class SessionAttributesHandlerTests method storeAttributes.

@Test
public void storeAttributes() {
    ModelMap model = new ModelMap();
    model.put("attr1", "value1");
    model.put("attr2", "value2");
    model.put("attr3", new TestBean());
    WebSession session = new MockWebSession();
    sessionAttributesHandler.storeAttributes(session, model);
    assertThat(session.getAttributes().get("attr1")).isEqualTo("value1");
    assertThat(session.getAttributes().get("attr2")).isEqualTo("value2");
    boolean condition = session.getAttributes().get("attr3") instanceof TestBean;
    assertThat(condition).isTrue();
}
Also used : MockWebSession(org.springframework.web.testfixture.server.MockWebSession) WebSession(org.springframework.web.server.WebSession) TestBean(org.springframework.beans.testfixture.beans.TestBean) ModelMap(org.springframework.ui.ModelMap) MockWebSession(org.springframework.web.testfixture.server.MockWebSession) Test(org.junit.jupiter.api.Test)

Example 15 with TestBean

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

the class ViewResolverTests method internalResourceViewResolverWithJstlAndContextParam.

@Test
public void internalResourceViewResolverWithJstlAndContextParam() throws Exception {
    Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;
    this.sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages");
    this.wac.addMessage("code1", locale, "messageX");
    this.wac.refresh();
    InternalResourceViewResolver vr = new InternalResourceViewResolver();
    vr.setViewClass(JstlView.class);
    vr.setApplicationContext(this.wac);
    View view = vr.resolveViewName("example1", Locale.getDefault());
    assertThat(view).isInstanceOf(JstlView.class);
    assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example1");
    view = vr.resolveViewName("example2", Locale.getDefault());
    assertThat(view).isInstanceOf(JstlView.class);
    assertThat(((JstlView) view).getUrl()).as("Correct URL").isEqualTo("example2");
    this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
    this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
    Map<String, Object> model = new HashMap<>();
    TestBean tb = new TestBean();
    model.put("tb", tb);
    view.render(model, this.request, this.response);
    assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
    assertThat(this.request.getAttribute("rc") == null).as("Correct rc attribute").isTrue();
    assertThat(Config.get(this.request, Config.FMT_LOCALE)).isEqualTo(locale);
    LocalizationContext lc = (LocalizationContext) Config.get(this.request, Config.FMT_LOCALIZATION_CONTEXT);
    assertThat(lc.getResourceBundle().getString("code1")).isEqualTo("message1");
    assertThat(lc.getResourceBundle().getString("code2")).isEqualTo("message2");
}
Also used : Locale(java.util.Locale) LocalizationContext(jakarta.servlet.jsp.jstl.fmt.LocalizationContext) HashMap(java.util.HashMap) TestBean(org.springframework.beans.testfixture.beans.TestBean) FixedLocaleResolver(org.springframework.web.servlet.i18n.FixedLocaleResolver) View(org.springframework.web.servlet.View) 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