Package org.springframework.web.context.support

Examples of org.springframework.web.context.support.StaticWebApplicationContext


        ve.addTemplate("myLayoutUrl", new Template());
        return ve;
      }
    };

    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.getBeanFactory().registerSingleton("configurer", vc);

    VelocityLayoutViewResolver vr = new VelocityLayoutViewResolver();
    vr.setPrefix("prefix_");
    vr.setSuffix("_suffix");
    vr.setLayoutUrl("myLayoutUrl");
View Full Code Here


    assertEquals(Boolean.TRUE, value);
  }

  private void setViewProperties(AbstractJasperReportsView view) {
    view.setUrl("org/springframework/ui/jasperreports/DataSourceReport.jasper");
    StaticWebApplicationContext ac = new StaticWebApplicationContext();
    ac.setServletContext(new MockServletContext());
    ac.addMessage("page", Locale.GERMAN, "MeineSeite");
    ac.refresh();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
    view.setApplicationContext(ac);
  }
View Full Code Here

* @author Juergen Hoeller
*/
public class TilesViewTests extends TestCase {

  protected StaticWebApplicationContext prepareWebApplicationContext() throws Exception {
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    MockServletContext sc = new MockServletContext("/org/springframework/web/servlet/view/tiles/");
    wac.setServletContext(sc);
    wac.refresh();

    TilesConfigurer tc = new TilesConfigurer();
    tc.setDefinitions(new String[] {"tiles-test.xml"});
    tc.setValidateDefinitions(true);
    tc.setApplicationContext(wac);
View Full Code Here

  private MockHttpServletResponse response;


  public void setUp() throws Exception {
    wac = new StaticWebApplicationContext();
    wac.setServletContext(new MockServletContext());

    final Template expectedTemplate = new Template();
    VelocityConfig vc = new VelocityConfig() {
      public VelocityEngine getVelocityEngine() {
View Full Code Here

  }

  public void testTilesJstlView() throws Exception {
    Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

    StaticWebApplicationContext wac = prepareWebApplicationContext();

    InternalResourceViewResolver irvr = new InternalResourceViewResolver();
    irvr.setApplicationContext(wac);
    irvr.setViewClass(TilesJstlView.class);
    View view = irvr.resolveViewName("testTile", new Locale("nl", ""));

    MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));
    wac.addMessage("code1", locale, "messageX");
    view.render(new HashMap(), request, response);

    assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
    ComponentContext cc = (ComponentContext) request.getAttribute(ComponentConstants.COMPONENT_CONTEXT);
    assertNotNull(cc);
View Full Code Here

  }

  public void testTilesJstlViewWithContextParam() throws Exception {
    Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

    StaticWebApplicationContext wac = prepareWebApplicationContext();
    ((MockServletContext) wac.getServletContext()).addInitParameter(
        Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages");

    InternalResourceViewResolver irvr = new InternalResourceViewResolver();
    irvr.setApplicationContext(wac);
    irvr.setViewClass(TilesJstlView.class);
    View view = irvr.resolveViewName("testTile", new Locale("nl", ""));

    MockHttpServletRequest request = new MockHttpServletRequest(wac.getServletContext());
    MockHttpServletResponse response = new MockHttpServletResponse();
    wac.addMessage("code1", locale, "messageX");
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale));

    view.render(new HashMap(), request, response);
    assertEquals("/WEB-INF/jsp/layout.jsp", response.getForwardedUrl());
View Full Code Here

    assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
  }

  public void testInternalResourceViewResolverWithAttributes() throws Exception {
    MockServletContext sc = new MockServletContext();
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);
    wac.refresh();
    InternalResourceViewResolver vr = new InternalResourceViewResolver();
    Properties props = new Properties();
    props.setProperty("key1", "value1");
    vr.setAttributes(props);
    Map map = new HashMap();
View Full Code Here

    assertEquals(new Integer(2), request.getAttribute("key2"));
  }

  public void testInternalResourceViewResolverWithContextBeans() throws Exception {
    MockServletContext sc = new MockServletContext();
    final StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.registerSingleton("myBean", TestBean.class);
    wac.registerSingleton("myBean2", TestBean.class);
    wac.setServletContext(sc);
    wac.refresh();
    InternalResourceViewResolver vr = new InternalResourceViewResolver();
    Properties props = new Properties();
    props.setProperty("key1", "value1");
    vr.setAttributes(props);
    Map map = new HashMap();
    map.put("key2", new Integer(2));
    vr.setAttributesMap(map);
    vr.setExposeContextBeansAsAttributes(true);
    vr.setApplicationContext(wac);

    MockHttpServletRequest request = new MockHttpServletRequest(sc) {
      public RequestDispatcher getRequestDispatcher(String path) {
        return new MockRequestDispatcher(path) {
          public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
            assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
            assertEquals("value1", forwardRequest.getAttribute("key1"));
            assertEquals(new Integer(2), forwardRequest.getAttribute("key2"));
            assertSame(wac.getBean("myBean"), forwardRequest.getAttribute("myBean"));
            assertSame(wac.getBean("myBean2"), forwardRequest.getAttribute("myBean2"));
          }
        };
      }
    };
    HttpServletResponse response = new MockHttpServletResponse();
View Full Code Here

    view.render(new HashMap(), request, response);
  }

  public void testInternalResourceViewResolverWithSpecificContextBeans() throws Exception {
    MockServletContext sc = new MockServletContext();
    final StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.registerSingleton("myBean", TestBean.class);
    wac.registerSingleton("myBean2", TestBean.class);
    wac.setServletContext(sc);
    wac.refresh();
    InternalResourceViewResolver vr = new InternalResourceViewResolver();
    Properties props = new Properties();
    props.setProperty("key1", "value1");
    vr.setAttributes(props);
    Map map = new HashMap();
    map.put("key2", new Integer(2));
    vr.setAttributesMap(map);
    vr.setExposedContextBeanNames(new String[] {"myBean2"});
    vr.setApplicationContext(wac);

    MockHttpServletRequest request = new MockHttpServletRequest(sc) {
      public RequestDispatcher getRequestDispatcher(String path) {
        return new MockRequestDispatcher(path) {
          public void forward(ServletRequest forwardRequest, ServletResponse forwardResponse) {
            assertTrue("Correct rc attribute", forwardRequest.getAttribute("rc") == null);
            assertEquals("value1", forwardRequest.getAttribute("key1"));
            assertEquals(new Integer(2), forwardRequest.getAttribute("key2"));
            assertNull(forwardRequest.getAttribute("myBean"));
            assertSame(wac.getBean("myBean2"), forwardRequest.getAttribute("myBean2"));
          }
        };
      }
    };
    HttpServletResponse response = new MockHttpServletResponse();
View Full Code Here

  public void testInternalResourceViewResolverWithJstl() throws Exception {
    Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH;

    MockServletContext sc = new MockServletContext();
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);
    wac.addMessage("code1", locale, "messageX");
    wac.refresh();
    InternalResourceViewResolver vr = new InternalResourceViewResolver();
    vr.setViewClass(JstlView.class);
    vr.setApplicationContext(wac);

    View view = vr.resolveViewName("example1", Locale.getDefault());
View Full Code Here

TOP

Related Classes of org.springframework.web.context.support.StaticWebApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.