List of usage examples for org.springframework.mock.web MockPageContext MockPageContext
public MockPageContext()
From source file:org.openmrs.web.taglib.RequireTagTest.java
/** * @see RequireTag#doStartTag()//from w w w.j a v a2 s .co m */ @Test @SkipBaseSetup @Verifies(value = "should reject user without the privilege", method = "doStartTag()") public void doStartTag_shouldRejectUserWithoutThePrivilege() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml"); Context.authenticate("overallmanager", "test"); RequireTag tag = new RequireTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("Some Random Privilege"); // the tag passes Assert.assertEquals(Tag.SKIP_PAGE, tag.doStartTag()); Context.logout(); }
From source file:org.openmrs.web.taglib.FormatTagTest.java
/** * @see FormatTag#doStartTag()//from w w w .j a v a2s . c o m */ @Test @Verifies(value = "print any domain object", method = "doStartTag()") public void doStartTag_shouldPrintAnyDomainObject() throws Exception { FormatTag tag = new FormatTag(); PageContext pageContext = new MockPageContext(); tag.setPageContext(pageContext); tag.setVar(ATTRIBUTE_OBJECT_VALUE); // check if concept is properly printed checkStartTagEvaluation(pageContext, tag, Context.getConceptService().getConcept(3), "COUGH SYRUP"); // check if encounter is properly printed checkStartTagEvaluation(pageContext, tag, Context.getEncounterService().getEncounter(3), "Emergency @Unknown Location | 01/08/2008 | "); // check if observation value is properly printed checkStartTagEvaluation(pageContext, tag, Context.getObsService().getObs(7), "50.0"); // check if user is properly printed checkStartTagEvaluation(pageContext, tag, Context.getUserService().getUser(502), "<span class=\"user\"><span class=\"username\">butch</span><span class=\"personName\"> (Hippocrates of Cos)</span></span>"); // check if encounter type is properly printed checkStartTagEvaluation(pageContext, tag, Context.getEncounterService().getEncounterType(1), "Scheduled"); // check if location is properly printed checkStartTagEvaluation(pageContext, tag, Context.getLocationService().getLocation(1), "Unknown Location"); // check if program is properly printed checkStartTagEvaluation(pageContext, tag, Context.getProgramWorkflowService().getProgram(1), "HIV PROGRAM"); // check if visit is properly printed checkStartTagEvaluation(pageContext, tag, Context.getVisitService().getVisit(1), "Initial HIV Clinic Visit @Unknown Location | 01/01/2005"); // check if visit type is properly printed checkStartTagEvaluation(pageContext, tag, Context.getVisitService().getVisitType(1), "Initial HIV Clinic Visit"); // check if form is properly printed checkStartTagEvaluation(pageContext, tag, Context.getFormService().getForm(1), "Basic Form (v0.1)"); }
From source file:org.displaytag.portlet.PortletRequestHelperTest.java
public void testCreateSecureHref() { final MockPageContext pageContext = new MockPageContext(); final MockPortletRequest request = new MockPortletRequest(); request.setSecure(true);//from w ww . j av a 2 s . c o m pageContext.setAttribute(PortletRequestHelper.JAVAX_PORTLET_REQUEST, request); 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()); assertNull(ref.getAnchor()); assertNull(ref.getRequestedMode()); assertNull(ref.getRequestedState()); assertTrue(ref.isRequestedSecure()); }
From source file:org.openmrs.web.taglib.RequireTagTest.java
/** * @see RequireTag#doStartTag()// w w w . ja v a 2s. c om */ @Test @SkipBaseSetup @Verifies(value = "should set the right session attributes if the authenticated user misses some privileges", method = "doStartTag()") public void doStartTag_shouldSetTheRightSessionAttributesIfTheAuthenticatedUserMissesSomePrivileges() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml"); Context.authenticate("whirleygiguser", "test"); RequireTag tag = new RequireTag(); MockPageContext pageContext = new MockPageContext(); final String referer = "/denied.htm"; ((MockHttpServletRequest) pageContext.getRequest()).addHeader("Referer", referer); tag.setPageContext(pageContext); tag.setAllPrivileges("Manage WhirleyGigs,Manage Thingamajigs"); String redirect = "/myRedirect.html"; tag.setRedirect(redirect); Assert.assertEquals(Tag.SKIP_PAGE, tag.doStartTag()); Assert.assertEquals(true, pageContext.getAttribute(WebConstants.INSUFFICIENT_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertNotNull(pageContext.getAttribute(WebConstants.REQUIRED_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertEquals(redirect, pageContext.getAttribute(WebConstants.DENIED_PAGE, PageContext.SESSION_SCOPE).toString()); Context.logout(); }
From source file:org.displaytag.portlet.PortletRequestHelperTest.java
public void testParameterizedHref() { 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 PortletHref ref = (PortletHref) helper.getHref(); final Map params = ref.getParameterMap(); assertEquals(2, params.size());//from w w w . j a v a 2 s. c o m 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]); assertNull(ref.getAnchor()); assertNull(ref.getRequestedMode()); assertNull(ref.getRequestedState()); assertFalse(ref.isRequestedSecure()); }
From source file:org.openmrs.web.taglib.RequireTagTest.java
/** * @see RequireTag#doStartTag()/*from ww w . ja v a 2 s . c o m*/ */ @Test @SkipBaseSetup @Verifies(value = "should set the referer as the denied page url if no redirect url is specified", method = "doStartTag()") public void doStartTag_shouldSetTheRefererAsTheDeniedPageUrlIfNoRedirectUrlIsSpecified() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/RequireTagTest.xml"); Context.authenticate("whirleygiguser", "test"); RequireTag tag = new RequireTag(); MockPageContext pageContext = new MockPageContext(); final String referer = "/denied.htm"; ((MockHttpServletRequest) pageContext.getRequest()).addHeader("Referer", referer); tag.setPageContext(pageContext); tag.setAllPrivileges("Manage WhirleyGigs,Manage Thingamajigs"); tag.setRedirect(""); Assert.assertEquals(Tag.SKIP_PAGE, tag.doStartTag()); Assert.assertEquals(true, pageContext.getAttribute(WebConstants.INSUFFICIENT_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertNotNull(pageContext.getAttribute(WebConstants.REQUIRED_PRIVILEGES, PageContext.SESSION_SCOPE)); Assert.assertEquals(referer, pageContext.getAttribute(WebConstants.DENIED_PAGE, PageContext.SESSION_SCOPE).toString()); Context.logout(); }