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");
}
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]");
}
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");
}
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();
}
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");
}
Aggregations