@Before public void createMockPageContext() throws Exception { MockServletContext sc = new MockServletContext(); SimpleWebApplicationContext wac = new SimpleWebApplicationContext(); wac.setServletContext(sc); wac.setNamespace("test"); wac.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(sc); request.addPreferredLocale(Context.getLocale()); MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); openmrsMessageTag = new OpenmrsMessageTag(); mockPageContext = new MockPageContext(sc, request, response); openmrsMessageTag.setPageContext(mockPageContext); }
/** * @see RequireTag#doStartTag() */ @Test @SkipBaseSetup @Verifies(value = "should allow user to have any privilege", method = "doStartTag()") public void doStartTag_shouldAllowUserToHaveAnyPrivilege() 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("Manage WhirleyGigs, Manage WhoopDeDoos"); // the tag passes Assert.assertEquals(Tag.SKIP_BODY, tag.doStartTag()); Context.logout(); }
/** * @see RequireTag#doStartTag() */ @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(); }
/** * @see RequireTag#doStartTag() */ @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(); }
/** * @see RequireTag#doStartTag() */ @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(); }
/** * @see RequireTag#doStartTag() */ @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(); }
/** * @see RequireTag#doStartTag() */ @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(); }
/** * @see RequireTag#doStartTag() */ @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(); }
/** * @see RequireTag#doStartTag() */ @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(); }
/** * @see ForEachEncounterTag#doStartTag() * @regression TRUNK-2465 */ @Test @Verifies(value = "should sort encounters by encounterDatetime in descending order", method = "doStartTag()") public void doStartTag_shouldSortEncountersByEncounterDatetimeInDescendingOrder() throws Exception { int num = 3; executeDataSet("org/openmrs/web/taglib/include/ForEachEncounterTagTest.xml"); Patient patient = Context.getPatientService().getPatient(7); List<Encounter> encounters = Context.getEncounterService().getEncountersByPatient(patient); ForEachEncounterTag tag = new ForEachEncounterTag(); tag.setPageContext(new MockPageContext()); tag.setDescending(true); tag.setEncounters(encounters); tag.setVar("enc"); tag.setNum(num); // the tag passes Assert.assertEquals(BodyTag.EVAL_BODY_BUFFERED, tag.doStartTag()); //the match count should not exceed the limit Assert.assertTrue(num >= tag.matchingEncs.size()); //check the sorting Assert.assertEquals(11, tag.matchingEncs.get(0).getId().intValue()); Assert.assertEquals(16, tag.matchingEncs.get(1).getId().intValue()); Assert.assertEquals(7, tag.matchingEncs.get(2).getId().intValue()); }
/** * @verifies include body for user with the privilege * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldIncludeBodyForUserWithThePrivilege() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("dataclerk1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("View Patients"); assertThat(tag.doStartTag(), is(Tag.EVAL_BODY_INCLUDE)); Context.logout(); }
/** * @verifies skip body for user without the privilege * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldSkipBodyForUserWithoutThePrivilege() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("Manage Patients"); assertThat(tag.doStartTag(), is(Tag.SKIP_BODY)); Context.logout(); }
/** * @verifies skip body for user with the privilege if inverse is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldSkipBodyForUserWithThePrivilegeIfInverseIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("dataclerk1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("View Patients"); tag.setInverse("true"); assertThat(tag.doStartTag(), is(Tag.SKIP_BODY)); Context.logout(); }
/** * @verifies include body for user with any of the privileges * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldIncludeBodyForUserWithAnyOfThePrivileges() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("View Patients,Edit Patients,Manage Patients"); assertThat(tag.doStartTag(), is(Tag.EVAL_BODY_INCLUDE)); Context.logout(); }
/** * @verifies skip body for user with any of the privileges if inverse is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldSkipBodyForUserWithAnyOfThePrivilegesIfInverseIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("View Patients,Edit Patients,Manage Patients"); tag.setInverse("true"); assertThat(tag.doStartTag(), is(Tag.SKIP_BODY)); Context.logout(); }
/** * @verifies include body for user with all of the privileges if hasAll is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldIncludeBodyForUserWithAllOfThePrivilegesIfHasAllIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("dataclerk1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("View Patients,Edit Patients,Manage Patients"); tag.setHasAll("true"); assertThat(tag.doStartTag(), is(Tag.EVAL_BODY_INCLUDE)); Context.logout(); }
/** * @verifies skip body for user with not all of the privileges if hasAll is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldSkipBodyForUserWithNotAllOfThePrivilegesIfHasAllIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("View Patients,Edit Patients,Manage Patients"); tag.setHasAll("true"); assertThat(tag.doStartTag(), is(Tag.SKIP_BODY)); Context.logout(); }
/** * @verifies skip body for user with all of the privileges if hasAll is true and inverse is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldSkipBodyForUserWithAllOfThePrivilegesIfHasAllIsTrueAndInverseIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("dataclerk1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("View Patients,Edit Patients,Manage Patients"); tag.setHasAll("true"); tag.setInverse("true"); assertThat(tag.doStartTag(), is(Tag.SKIP_BODY)); Context.logout(); }
/** * @verifies include body for user without the privilege if inverse is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldIncludeBodyForUserWithoutThePrivilegeIfInverseIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("Manage Patients"); tag.setInverse("true"); assertThat(tag.doStartTag(), is(Tag.EVAL_BODY_INCLUDE)); Context.logout(); }
/** * @verifies skip body for user without any of the privileges * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldSkipBodyForUserWithoutAnyOfThePrivileges() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("Edit Patients,Manage Patients"); assertThat(tag.doStartTag(), is(Tag.SKIP_BODY)); Context.logout(); }
/** * @verifies include body for user without any of the privileges if inverse is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldIncludeBodyForUserWithoutAnyOfThePrivilegesIfInverseIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("Edit Patients,Manage Patients"); tag.setInverse("true"); assertThat(tag.doStartTag(), is(Tag.EVAL_BODY_INCLUDE)); Context.logout(); }
/** * @verifies skip body for user without any of the privileges if hasAll is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldSkipBodyForUserWithoutAnyOfThePrivilegesIfHasAllIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("Edit Patients,Manage Patients"); tag.setHasAll("true"); assertThat(tag.doStartTag(), is(Tag.SKIP_BODY)); Context.logout(); }
/** * @verifies include body for user without any of the privileges if hasAll is true and inverse is true * @see PrivilegeTag#doStartTag() */ @Test @SkipBaseSetup public void doStartTag_shouldIncludeBodyForUserWithoutAnyOfThePrivilegesIfHasAllIsTrueAndInverseIsTrue() throws Exception { initializeInMemoryDatabase(); executeDataSet("org/openmrs/web/taglib/include/PrivilegeTagTest.xml"); Context.authenticate("clinician1", "test"); PrivilegeTag tag = new PrivilegeTag(); tag.setPageContext(new MockPageContext()); tag.setPrivilege("Edit Patients,Manage Patients"); tag.setHasAll("true"); tag.setInverse("true"); assertThat(tag.doStartTag(), is(Tag.EVAL_BODY_INCLUDE)); Context.logout(); }
@Test 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<String, String[]> params = ref.getParameterMap(); Assert.assertEquals(0, params.size()); Assert.assertNull(ref.getAnchor()); Assert.assertNull(ref.getRequestedMode()); Assert.assertNull(ref.getRequestedState()); Assert.assertFalse(ref.isRequestedSecure()); }
@Test public void testCreateSecureHref() { final MockPageContext pageContext = new MockPageContext(); final MockPortletRequest request = new MockPortletRequest(); request.setSecure(true); 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<String, String[]> params = ref.getParameterMap(); Assert.assertEquals(0, params.size()); Assert.assertNull(ref.getAnchor()); Assert.assertNull(ref.getRequestedMode()); Assert.assertNull(ref.getRequestedState()); Assert.assertTrue(ref.isRequestedSecure()); }
@Before public void setup() throws Exception { mockPageContext = new MockPageContext(mockServletContext, new MockHttpServletRequest(), new MockHttpServletResponse()); tag = new PageTag(); tag.setAppcacheEnabled("false"); tag.setJspContext(mockPageContext); tag.setJspBody(new JspFragment() { @Override public void invoke(Writer out) throws JspException, IOException { } @Override public JspContext getJspContext() { return null; } }); }
@Before public void setup() throws Exception { mockPageContext = new MockPageContext(mockServletContext); tag = new MultiPageTag(); tag.setJspContext(mockPageContext); // Required attributes of the PageTag are: id, title so set them here. tag.setId(ID); tag.setTitle(TITLE); // Disable appcache and google analytics for simplicity. tag.setAppcacheEnabled(APPCACHE); tag.setDisableGoogleAnalytics(true); JspFragment jspBodyFragment = mock(JspFragment.class); doAnswer(new FakeJspBodyAnswerer()).when(jspBodyFragment) .invoke((Writer) anyObject()); tag.setJspBody(jspBodyFragment); }
protected MockPageContext createPageContext() { MockServletContext sc = new MockServletContext(); StaticWebApplicationContext wac = new StaticWebApplicationContext(); wac.setServletContext(sc); wac.setNamespace("test"); wac.registerSingleton("validator", org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.class); wac.refresh(); MockHttpServletRequest request = new MockHttpServletRequest(sc); MockHttpServletResponse response = new MockHttpServletResponse(); request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); LocaleResolver lr = new AcceptHeaderLocaleResolver(); request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr); ThemeResolver tr = new FixedThemeResolver(); request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr); request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac); return new MockPageContext(sc, request, response); }
@Before public void setUp() { this.output = new ByteArrayOutputStream(); this.writer = new OutputStreamWriter(this.output, UTF8); this.context = new MockPageContext() { private final MockJspWriter jspWriter = new MockJspWriter(writer); @Override public JspWriter getOut() { return this.jspWriter; } }; this.tag = new DumpTag(); this.tag.setPageContext(this.context); }
/** * */ @Before public void setUp() { Taxon taxon = new Taxon(); taxon.setScientificName("Aus aus"); taxon.setScientificNameAuthorship("Clark."); pageContext = new MockPageContext(); pageContext.setAttribute("taxon", taxon, PageContext.PAGE_SCOPE); }
/** * @see ForEachEncounterTag#doStartTag() */ @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()); }
@Override protected void setUp() throws Exception { super.setUp(); _servletContext = new MockServletContext(); _request = new MockHttpServletRequest(); _response = new MockHttpServletResponse(); _pageContext = new MockPageContext(_servletContext, _request, _response); }
@Test 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); }
@Test 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"); Assert.assertEquals("STRING_VALUE", strVal); final Integer intVal = helper.getIntParameter("INTEGER_PARAM"); Assert.assertEquals(new Integer(31337), intVal); final Integer nullIntVal = helper.getIntParameter("STRING_PARAM"); Assert.assertNull(nullIntVal); final Map<String, String[]> params = helper.getParameterMap(); Assert.assertEquals(2, params.size()); final String[] expextedStrArryVal = new String[]{"STRING_VALUE"}; final String[] strArryVal = params.get("STRING_PARAM"); Assert.assertEquals(expextedStrArryVal.length, strArryVal.length); Assert.assertEquals(expextedStrArryVal[0], strArryVal[0]); final String[] expextedIntArryVal = new String[]{"31337"}; final String[] intArryVal = params.get("INTEGER_PARAM"); Assert.assertEquals(expextedIntArryVal.length, intArryVal.length); Assert.assertEquals(expextedIntArryVal[0], intArryVal[0]); }
@Test 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<String, String[]> params = ref.getParameterMap(); Assert.assertEquals(2, params.size()); final String[] expextedStrArryVal = new String[]{"STRING_VALUE"}; final String[] strArryVal = params.get("STRING_PARAM"); Assert.assertEquals(expextedStrArryVal.length, strArryVal.length); Assert.assertEquals(expextedStrArryVal[0], strArryVal[0]); final String[] expextedIntArryVal = new String[]{"31337"}; final String[] intArryVal = params.get("INTEGER_PARAM"); Assert.assertEquals(expextedIntArryVal.length, intArryVal.length); Assert.assertEquals(expextedIntArryVal[0], intArryVal[0]); Assert.assertNull(ref.getAnchor()); Assert.assertNull(ref.getRequestedMode()); Assert.assertNull(ref.getRequestedState()); Assert.assertFalse(ref.isRequestedSecure()); }
@Before public void setup() throws Exception { mockPageContext = new MockPageContext(mockServletContext); tag = new DefinitionListDefinitionTag(); tag.setJspContext(mockPageContext); JspFragment jspBodyFragment = mock(JspFragment.class); doAnswer(new FakeJspBodyAnswerer()).when(jspBodyFragment) .invoke((Writer) anyObject()); tag.setJspBody(jspBodyFragment); }
@Before public void setup() throws Exception { mockPageContext = new MockPageContext(mockServletContext); tag = new FormTag(); tag.setJspContext(mockPageContext); JspFragment jspBodyFragment = mock(JspFragment.class); doAnswer(new FakeJspBodyAnswerer()).when(jspBodyFragment) .invoke((Writer) anyObject()); tag.setJspBody(jspBodyFragment); }
@Before public void setup() throws Exception { mockPageContext = new MockPageContext(mockServletContext); tag = new ListViewTag(); tag.setJspContext(mockPageContext); JspFragment jspBodyFragment = mock(JspFragment.class); doAnswer(new FakeJspBodyAnswerer()).when(jspBodyFragment) .invoke((Writer) anyObject()); tag.setJspBody(jspBodyFragment); }
@Before public void setup() throws Exception { mockPageContext = new MockPageContext(mockServletContext); tag = new ChildPageTag(); tag.setJspContext(mockPageContext); // Required attributes of the PageTag are: id, title so set them here. tag.setId(ID); tag.setTitle(TITLE); JspFragment jspBodyFragment = mock(JspFragment.class); doAnswer(new FakeJspBodyAnswerer()).when(jspBodyFragment) .invoke((Writer) anyObject()); tag.setJspBody(jspBodyFragment); }