Java tutorial
/** * This file is part of the ChillDev-Web. * * @license http://mit-license.org/ The MIT license * @copyright 2014 by Rafa Wrzeszcz - Wrzasq.pl. */ package test.pl.chilldev.web.tags.page; import org.junit.Test; import static org.junit.Assert.*; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import javax.servlet.jsp.JspContext; import javax.servlet.jsp.JspTagException; import org.springframework.mock.web.MockPageContext; import pl.chilldev.web.core.page.PageMetaModel; import pl.chilldev.web.tags.context.JspPageMetaModelResolver; import pl.chilldev.web.tags.context.PageMetaModelContextUtils; import pl.chilldev.web.tags.page.XmlPrefixTag; public class XmlPrefixTagTest { @Test public void doTag() throws URISyntaxException, IOException, JspTagException { MockPageContext context = new MockPageContext(); XmlPrefixTag tag = new XmlPrefixTag(); PageMetaModel page = new PageMetaModel(); tag.setJspContext(context); // 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()); } }