List of usage examples for org.springframework.mock.web MockPageContext MockPageContext
public MockPageContext()
From source file:test.pl.chilldev.web.tags.page.PrintLinksTagTest.java
@Test public void doTag() throws IOException, JspTagException { MockPageContext context = new MockPageContext(); PrintLinksTag tag = new PrintLinksTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);//from ww w .ja v a2 s . c om // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String href = "href"; page.addStylesheet(href); // run the tag tag.doTag(); assertEquals("PrintLinksTag.doTag() should print page title.", page.generateLinkElements(), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:test.pl.chilldev.web.tags.page.PrintMetaTagTest.java
@Test public void doTag() throws IOException, JspTagException { MockPageContext context = new MockPageContext(); PrintMetaTag tag = new PrintMetaTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);/*w w w . ja va2 s.c o m*/ // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String key = "bar"; String value = "baz"; page.setMetaName(key, value); // run the tag tag.doTag(); assertEquals("PrintMetaTag.doTag() should print page title.", page.generateMetaElements(), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:test.pl.chilldev.web.tags.page.PrintTitleTagTest.java
@Test public void doTag() throws IOException, JspTagException { MockPageContext context = new MockPageContext(); PrintTitleTag tag = new PrintTitleTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);/*from w w w . j a v a 2 s .c o m*/ // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String part = "bar"; page.addTitlePart(part); // run the tag tag.doTag(); assertEquals("PrintTitleTag.doTag() should print page title.", page.generateTitleContent(), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:test.pl.chilldev.web.tags.page.PrintScriptsTagTest.java
@Test public void doTag() throws IOException, JspTagException { MockPageContext context = new MockPageContext(); PrintScriptsTag tag = new PrintScriptsTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);/*from w ww. j av a 2 s.c om*/ // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String src = "bar"; page.addScript(src); // run the tag tag.doTag(); assertEquals("PrintScriptsTag.doTag() should print page title.", page.generateScriptElements(), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:test.pl.chilldev.web.tags.context.JspPageMetaModelResolverTest.java
@Test public void getPageMetaModel() throws PageMetaModelContextException { JspContext context = new MockPageContext(); PageMetaModelResolver resolver = new JspPageMetaModelResolver(); PageMetaModel page = resolver.getPageMetaModel(context); assertNotNull(/*ww w. j a va 2 s.c o m*/ "JspPageMetaModelResolver.getPageMetaModel() should create new page model for given context if there is none.", page); assertSame( "JspPageMetaModelResolver.getPageMetaModel() should register newly created page model for next uses.", page, resolver.getPageMetaModel(context)); }
From source file:test.pl.chilldev.web.tags.page.PrintXmlnsTagTest.java
@Test public void doTag() throws URISyntaxException, IOException, JspTagException { MockPageContext context = new MockPageContext(); PrintXmlnsTag tag = new PrintXmlnsTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);/* w ww.j av a2s . com*/ // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); URI namespace = new URI("http://chilldev.pl/"); String alias = "cdv"; page.setXmlNamespace(namespace, alias); // run the tag tag.doTag(); assertEquals("PrintXmlnsTag.doTag() should print XML namespace attributes.", page.generateXmlnsAttributes(), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:test.pl.chilldev.web.tags.page.XmlPrefixTagTest.java
@Test public void doTag() throws URISyntaxException, IOException, JspTagException { MockPageContext context = new MockPageContext(); XmlPrefixTag tag = new XmlPrefixTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context);/*from w ww . ja v a 2 s . c o m*/ // set up context String attribute = "foo"; context.setAttribute(attribute, page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); URI namespace = new URI("http://chilldev.pl/"); String alias = "cdv"; page.setXmlNamespace(namespace, alias); // run the tag tag.setNamespace(namespace); tag.doTag(); assertEquals("XmlPrefixTag.doTag() should print XML prefix for given namespace.", page.getXmlPrefix(namespace), ((org.springframework.mock.web.MockHttpServletResponse) context.getResponse()) .getContentAsString()); }
From source file:test.pl.chilldev.web.tags.page.StylesheetTagTest.java
@Test public void doTag() throws JspTagException { JspContext context = new MockPageContext(); StylesheetTag tag = new StylesheetTag(); tag.setJspContext(context);//from w w w .ja v a2 s . c o m // set up context String attribute = "foo"; context.setAttribute(attribute, this.page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String href = "bar"; String type = "baz"; String media = "quux"; // run the tag tag.setHref(href); tag.setType(type); tag.setMedia(media); tag.doTag(); verify(this.page).addStylesheet(href, type, media); }
From source file:test.pl.chilldev.web.tags.page.TitleSeparatorTagTest.java
@Test public void doTag() throws JspTagException { JspContext context = new MockPageContext(); TitleSeparatorTag tag = new TitleSeparatorTag(); tag.setJspContext(context);/* www. j a va 2 s . c o m*/ // set up context String attribute = "foo"; context.setAttribute(attribute, this.page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String separator = " :: "; // run the tag tag.setSeparator(separator); tag.doTag(); verify(this.page).setTitleSeparator(separator); }
From source file:test.pl.chilldev.web.tags.page.MetaPropertyTagTest.java
@Test public void doEndTag() throws JspTagException { PageContext context = new MockPageContext(); MetaPropertyTag tag = new MetaPropertyTag(); tag.setPageContext(context);/*from ww w .ja v a2 s .co m*/ // set up context String attribute = "foo"; context.setAttribute(attribute, this.page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String key = "bar"; String value = "baz"; // run the tag tag.setKey(key); tag.setValue(value); tag.doEndTag(); verify(this.page).setMetaProperty(key, value); }