Java Code Examples for org.springframework.web.context.support.StaticWebApplicationContext#addMessage()
The following examples show how to use
org.springframework.web.context.support.StaticWebApplicationContext#addMessage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test 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()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((JstlView) view).getUrl()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((JstlView) view).getUrl()); MockHttpServletRequest request = new MockHttpServletRequest(sc); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); 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, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") == null); assertEquals(locale, Config.get(request, Config.FMT_LOCALE)); LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT); assertEquals("messageX", lc.getResourceBundle().getString("code1")); }
Example 2
Source File: ViewResolverTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void testInternalResourceViewResolverWithJstlAndContextParam() throws Exception { Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH; MockServletContext sc = new MockServletContext(); sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages"); 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()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((JstlView) view).getUrl()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((JstlView) view).getUrl()); MockHttpServletRequest request = new MockHttpServletRequest(sc); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); 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, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") == null); assertEquals(locale, Config.get(request, Config.FMT_LOCALE)); LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT); assertEquals("message1", lc.getResourceBundle().getString("code1")); assertEquals("message2", lc.getResourceBundle().getString("code2")); }
Example 3
Source File: ViewResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test 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()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((JstlView) view).getUrl()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((JstlView) view).getUrl()); MockHttpServletRequest request = new MockHttpServletRequest(sc); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); 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, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") == null); assertEquals(locale, Config.get(request, Config.FMT_LOCALE)); LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT); assertEquals("messageX", lc.getResourceBundle().getString("code1")); }
Example 4
Source File: ViewResolverTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testInternalResourceViewResolverWithJstlAndContextParam() throws Exception { Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH; MockServletContext sc = new MockServletContext(); sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages"); 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()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((JstlView) view).getUrl()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((JstlView) view).getUrl()); MockHttpServletRequest request = new MockHttpServletRequest(sc); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); 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, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") == null); assertEquals(locale, Config.get(request, Config.FMT_LOCALE)); LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT); assertEquals("message1", lc.getResourceBundle().getString("code1")); assertEquals("message2", lc.getResourceBundle().getString("code2")); }
Example 5
Source File: ViewResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test 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()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((JstlView) view).getUrl()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((JstlView) view).getUrl()); MockHttpServletRequest request = new MockHttpServletRequest(sc); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale)); Map model = new HashMap(); TestBean tb = new TestBean(); model.put("tb", tb); view.render(model, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") == null); assertEquals(locale, Config.get(request, Config.FMT_LOCALE)); LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT); assertEquals("messageX", lc.getResourceBundle().getString("code1")); }
Example 6
Source File: ViewResolverTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testInternalResourceViewResolverWithJstlAndContextParam() throws Exception { Locale locale = !Locale.GERMAN.equals(Locale.getDefault()) ? Locale.GERMAN : Locale.FRENCH; MockServletContext sc = new MockServletContext(); sc.addInitParameter(Config.FMT_LOCALIZATION_CONTEXT, "org/springframework/web/context/WEB-INF/context-messages"); 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()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example1", ((JstlView) view).getUrl()); view = vr.resolveViewName("example2", Locale.getDefault()); assertEquals("Correct view class", JstlView.class, view.getClass()); assertEquals("Correct URL", "example2", ((JstlView) view).getUrl()); MockHttpServletRequest request = new MockHttpServletRequest(sc); HttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new FixedLocaleResolver(locale)); Map model = new HashMap(); TestBean tb = new TestBean(); model.put("tb", tb); view.render(model, request, response); assertTrue("Correct tb attribute", tb.equals(request.getAttribute("tb"))); assertTrue("Correct rc attribute", request.getAttribute("rc") == null); assertEquals(locale, Config.get(request, Config.FMT_LOCALE)); LocalizationContext lc = (LocalizationContext) Config.get(request, Config.FMT_LOCALIZATION_CONTEXT); assertEquals("message1", lc.getResourceBundle().getString("code1")); assertEquals("message2", lc.getResourceBundle().getString("code2")); }
Example 7
Source File: ExporterParameterTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
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); }
Example 8
Source File: AbstractJasperReportsViewTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected AbstractJasperReportsView getView(String url) throws Exception { AbstractJasperReportsView view = getViewImplementation(); view.setUrl(url); 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); return view; }