use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ContextLoaderTests method contextLoaderListenerWithProgrammaticAndGlobalInitializers.
@Test
void contextLoaderListenerWithProgrammaticAndGlobalInitializers() {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, TestWebContextInitializer.class.getName());
ContextLoaderListener listener = new ContextLoaderListener();
listener.setContextInitializers(new TestContextInitializer());
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ContextLoaderTests method contextLoaderListenerWithProgrammaticInitializers.
@Test
void contextLoaderListenerWithProgrammaticInitializers() {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
ContextLoaderListener listener = new ContextLoaderListener();
listener.setContextInitializers(new TestContextInitializer(), new TestWebContextInitializer());
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ContextLoaderTests method contextLoaderListenerWithMixedContextInitializers.
@Test
void contextLoaderListenerWithMixedContextInitializers() {
MockServletContext sc = new MockServletContext("");
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "org/springframework/web/context/WEB-INF/ContextLoaderTests-acc-context.xml");
sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, TestContextInitializer.class.getName());
sc.addInitParameter(ContextLoader.GLOBAL_INITIALIZER_CLASSES_PARAM, TestWebContextInitializer.class.getName());
ContextLoaderListener listener = new ContextLoaderListener();
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class ContextLoaderTests method classPathXmlApplicationContext.
@Test
@SuppressWarnings("resource")
void classPathXmlApplicationContext() throws IOException {
ApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/web/context/WEB-INF/applicationContext.xml");
assertThat(context.containsBean("father")).as("Has father").isTrue();
assertThat(context.containsBean("rod")).as("Has rod").isTrue();
assertThat(context.containsBean("kerry")).as("Hasn't kerry").isFalse();
assertThat(((TestBean) context.getBean("rod")).getSpouse() == null).as("Doesn't have spouse").isTrue();
assertThat("Roderick".equals(((TestBean) context.getBean("rod")).getName())).as("myinit not evaluated").isTrue();
context = new ClassPathXmlApplicationContext(new String[] { "/org/springframework/web/context/WEB-INF/applicationContext.xml", "/org/springframework/web/context/WEB-INF/context-addition.xml" });
assertThat(context.containsBean("father")).as("Has father").isTrue();
assertThat(context.containsBean("rod")).as("Has rod").isTrue();
assertThat(context.containsBean("kerry")).as("Has kerry").isTrue();
}
use of org.springframework.beans.testfixture.beans.TestBean in project spring-framework by spring-projects.
the class CheckboxesTagTests method createTestBean.
@Override
protected TestBean createTestBean() {
List colours = new ArrayList();
colours.add(Colour.BLUE);
colours.add(Colour.RED);
colours.add(Colour.GREEN);
List pets = new ArrayList();
pets.add(new Pet("Rudiger"));
pets.add(new Pet("Spot"));
pets.add(new Pet("Fluffy"));
pets.add(new Pet("Mufty"));
Set someObjects = new HashSet();
someObjects.add(new ItemPet("PET1"));
someObjects.add(new ItemPet("PET2"));
this.bean = new TestBean();
this.bean.setDate(getDate());
this.bean.setName("Rob Harrop");
this.bean.setJedi(true);
this.bean.setSomeBoolean(Boolean.TRUE);
this.bean.setStringArray(new String[] { "bar", "foo" });
this.bean.setSomeIntegerArray(new Integer[] { 2, 1 });
this.bean.setOtherColours(colours);
this.bean.setPets(pets);
this.bean.setSomeSet(someObjects);
List list = new ArrayList();
list.add("foo");
list.add("bar");
this.bean.setSomeList(list);
return this.bean;
}
Aggregations