Example usage for org.springframework.mock.web MockPageContext MockPageContext

List of usage examples for org.springframework.mock.web MockPageContext MockPageContext

Introduction

In this page you can find the example usage for org.springframework.mock.web MockPageContext MockPageContext.

Prototype

public MockPageContext() 

Source Link

Document

Create new MockPageContext with a default MockServletContext , MockHttpServletRequest , MockHttpServletResponse , MockServletConfig .

Usage

From source file:org.openmrs.web.taglib.RequireTagTest.java

/**
 * @see RequireTag#doStartTag()/* w  w w .j  av a  2s  . c  o  m*/
 */
@Test
@SkipBaseSetup
@Verifies(value = "should allow user with all privileges", method = "doStartTag()")
public void doStartTag_shouldAllowUserWithAllPrivileges() throws Exception {
    initializeInMemoryDatabase();
    executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml");
    Context.authenticate("overallmanager", "test");

    RequireTag tag = new RequireTag();
    tag.setPageContext(new MockPageContext());
    tag.setAllPrivileges("Manage WhirleyGigs, Manage WhoopDeDoos, Manage Thingamajigs");

    // the tag passes
    Assert.assertEquals(Tag.SKIP_BODY, tag.doStartTag());

    Context.logout();
}

From source file:test.pl.chilldev.web.tags.context.JspPageMetaModelResolverTest.java

@Test
public void getPageMetaModelWithGenerator() throws PageMetaModelContextException {
    JspContext context = new MockPageContext();
    Generator generator = new Generator(false, StringEscapeUtils.ESCAPE_JSON);
    PageMetaModelResolver resolver = new JspPageMetaModelResolver(generator);

    PageMetaModel page = resolver.getPageMetaModel(context);
    page.addKeywords(new String[] { "\"" });

    assertEquals(/*ww w.ja  v a 2 s  .c  o  m*/
            "JspPageMetaModelResolver should initialize new page meta model with given markup generator if specified.",
            "<meta content=\"\\\"\" name=\"keywords\">", page.generateMetaElements());
}

From source file:org.displaytag.portlet.PortletRequestHelperTest.java

public void testBasicPageContext() {
    final MockPageContext pageContext = new MockPageContext();

    pageContext.setAttribute(PortletRequestHelper.JAVAX_PORTLET_REQUEST, new MockPortletRequest());
    pageContext.setAttribute(PortletRequestHelper.JAVAX_PORTLET_RESPONSE, new MockRenderResponse());

    new PortletRequestHelper(pageContext);
}

From source file:org.openmrs.web.taglib.ForEachEncounterTagTest.java

/**
 * @see ForEachEncounterTag#doStartTag()
 *///  w w  w  . j  a v  a 2  s .  c  om
@Test
@Verifies(value = "should pass for a patient with no encounters", method = "doStartTag()")
public void doStartTag_shouldPassForAPatientWithNoEncounters() throws Exception {
    ForEachEncounterTag tag = new ForEachEncounterTag();
    tag.setPageContext(new MockPageContext());
    tag.setEncounters(new ArrayList<Encounter>());
    // the tag passes
    Assert.assertEquals(Tag.SKIP_BODY, tag.doStartTag());
}

From source file:org.hobsoft.symmetry.taglib.ComponentTagTest.java

@Before
public void setUp() {
    context = new MockPageContext();

    tag = new ComponentTag();
    tag.setJspContext(context);
}

From source file:org.displaytag.portlet.PortletRequestHelperTest.java

public void testRequestParameters() {
    final MockPageContext pageContext = new MockPageContext();
    final MockPortletRequest request = new MockPortletRequest();

    request.setParameter("STRING_PARAM", "STRING_VALUE");
    request.setParameter("INTEGER_PARAM", "31337");

    pageContext.setAttribute(PortletRequestHelper.JAVAX_PORTLET_REQUEST, request);
    pageContext.setAttribute(PortletRequestHelper.JAVAX_PORTLET_RESPONSE, new MockRenderResponse());

    final PortletRequestHelper helper = new PortletRequestHelper(pageContext);

    final String strVal = helper.getParameter("STRING_PARAM");
    assertEquals("STRING_VALUE", strVal);

    final Integer intVal = helper.getIntParameter("INTEGER_PARAM");
    assertEquals(new Integer(31337), intVal);

    final Integer nullIntVal = helper.getIntParameter("STRING_PARAM");
    assertNull(nullIntVal);/*w  ww  .  j  a  v a 2 s.  c o m*/

    final Map params = helper.getParameterMap();
    assertEquals(2, params.size());

    final String[] expextedStrArryVal = new String[] { "STRING_VALUE" };
    final String[] strArryVal = (String[]) params.get("STRING_PARAM");
    assertEquals(expextedStrArryVal.length, strArryVal.length);
    assertEquals(expextedStrArryVal[0], strArryVal[0]);

    final String[] expextedIntArryVal = new String[] { "31337" };
    final String[] intArryVal = (String[]) params.get("INTEGER_PARAM");
    assertEquals(expextedIntArryVal.length, intArryVal.length);
    assertEquals(expextedIntArryVal[0], intArryVal[0]);
}

From source file:org.openmrs.web.taglib.RequireTagTest.java

/**
 * @see RequireTag#doStartTag()//w w w .  j  a v  a 2s.  c  om
 */
@Test
@SkipBaseSetup
@Verifies(value = "should allow user with the privilege", method = "doStartTag()")
public void doStartTag_shouldAllowUserWithThePrivilege() throws Exception {
    initializeInMemoryDatabase();
    executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml");
    Context.authenticate("whirleygiguser", "test");

    RequireTag tag = new RequireTag();
    tag.setPageContext(new MockPageContext());
    tag.setPrivilege("Manage WhirleyGigs");

    // the tag passes
    Assert.assertEquals(Tag.SKIP_BODY, tag.doStartTag());

    Context.logout();
}

From source file:org.openmrs.web.taglib.RequireTagTest.java

/**
 * @see RequireTag#doStartTag()//from  ww  w . j a  va  2 s. c  om
 */
@Test
@SkipBaseSetup
@Verifies(value = "should reject user without all of the privileges", method = "doStartTag()")
public void doStartTag_shouldRejectUserWithoutAllOfThePrivileges() throws Exception {
    initializeInMemoryDatabase();
    executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml");
    Context.authenticate("whirleygiguser", "test");

    RequireTag tag = new RequireTag();
    tag.setPageContext(new MockPageContext());
    tag.setAllPrivileges("Manage WhirleyGigs, Manage WhoopDeDoos, Manage Thingamajigs");

    // the tag passes
    Assert.assertEquals(Tag.SKIP_PAGE, tag.doStartTag());

    Context.logout();
}

From source file:org.openmrs.web.taglib.RequireTagTest.java

/**
 * @see RequireTag#doStartTag()//w w w .j a  v  a 2 s. c o  m
 */
@Test
@SkipBaseSetup
@Verifies(value = "should reject user without any of the privileges", method = "doStartTag()")
public void doStartTag_shouldRejectUserWithoutAnyOfThePrivileges() throws Exception {
    initializeInMemoryDatabase();
    executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml");
    Context.authenticate("whirleygiguser", "test");

    RequireTag tag = new RequireTag();
    tag.setPageContext(new MockPageContext());
    tag.setAnyPrivilege("Random Privilege, Other Random Privilege");

    // the tag passes
    Assert.assertEquals(Tag.SKIP_PAGE, tag.doStartTag());

    Context.logout();
}

From source file:org.displaytag.portlet.PortletRequestHelperTest.java

public void testCreateEmptyHref() {
    final MockPageContext pageContext = new MockPageContext();

    pageContext.setAttribute(PortletRequestHelper.JAVAX_PORTLET_REQUEST, new MockPortletRequest());
    pageContext.setAttribute(PortletRequestHelper.JAVAX_PORTLET_RESPONSE, new MockRenderResponse());

    final PortletRequestHelper helper = new PortletRequestHelper(pageContext);

    final PortletHref ref = (PortletHref) helper.getHref();

    final Map params = ref.getParameterMap();
    assertEquals(0, params.size());/*  w w  w  .  j a v  a2s  . c om*/

    assertNull(ref.getAnchor());
    assertNull(ref.getRequestedMode());
    assertNull(ref.getRequestedState());

    assertFalse(ref.isRequestedSecure());
}