Search in sources :

Example 1 with ServletContextAttributeExporter

use of cn.taketoday.web.context.support.ServletContextAttributeExporter in project today-framework by TAKETODAY.

the class ServletContextSupportTests method testServletContextAttributeExporter.

@Test
public void testServletContextAttributeExporter() {
    TestBean tb = new TestBean();
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("attr1", "value1");
    attributes.put("attr2", tb);
    MockServletContext sc = new MockServletContext();
    ServletContextAttributeExporter exporter = new ServletContextAttributeExporter();
    exporter.setAttributes(attributes);
    exporter.setServletContext(sc);
    assertThat(sc.getAttribute("attr1")).isEqualTo("value1");
    assertThat(sc.getAttribute("attr2")).isSameAs(tb);
}
Also used : TestBean(cn.taketoday.beans.testfixture.beans.TestBean) HashMap(java.util.HashMap) MockServletContext(cn.taketoday.web.testfixture.servlet.MockServletContext) ServletContextAttributeExporter(cn.taketoday.web.context.support.ServletContextAttributeExporter) Test(org.junit.jupiter.api.Test)

Example 2 with ServletContextAttributeExporter

use of cn.taketoday.web.context.support.ServletContextAttributeExporter in project today-infrastructure by TAKETODAY.

the class ServletContextSupportTests method testServletContextAttributeExporter.

@Test
public void testServletContextAttributeExporter() {
    TestBean tb = new TestBean();
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("attr1", "value1");
    attributes.put("attr2", tb);
    MockServletContext sc = new MockServletContext();
    ServletContextAttributeExporter exporter = new ServletContextAttributeExporter();
    exporter.setAttributes(attributes);
    exporter.setServletContext(sc);
    assertThat(sc.getAttribute("attr1")).isEqualTo("value1");
    assertThat(sc.getAttribute("attr2")).isSameAs(tb);
}
Also used : TestBean(cn.taketoday.beans.testfixture.beans.TestBean) HashMap(java.util.HashMap) MockServletContext(cn.taketoday.web.mock.MockServletContext) ServletContextAttributeExporter(cn.taketoday.web.context.support.ServletContextAttributeExporter) Test(org.junit.jupiter.api.Test)

Aggregations

TestBean (cn.taketoday.beans.testfixture.beans.TestBean)2 ServletContextAttributeExporter (cn.taketoday.web.context.support.ServletContextAttributeExporter)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 MockServletContext (cn.taketoday.web.mock.MockServletContext)1 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)1