List of usage examples for org.springframework.mock.web MockPageContext MockPageContext
public MockPageContext()
From source file:test.pl.chilldev.web.tags.context.PageMetaModelContextUtilsTest.java
@Test public void getPageMetaModel() throws PageMetaModelContextException { JspContext context = new MockPageContext(); // reset resolver PageMetaModelContextUtils.setPageMetaModelResolver(null); PageMetaModel page = PageMetaModelContextUtils.getPageMetaModel(context); assertNotNull("PageMetaModelContextUtils.getPageMetaModel() should return page model for given context.", page);//w w w . jav a2s . c o m }
From source file:test.pl.chilldev.web.tags.page.TitleAddTagTest.java
@Test public void doEndTagWithBodyContent() throws JspTagException { PageContext context = new MockPageContext(); TitleAddTag tag = new TitleAddTag(); tag.setPageContext(context);/*from w w w. ja va 2s .c o m*/ // set up context String attribute = "foo"; context.setAttribute(attribute, this.page); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); String part = "bar"; when(this.body.getString()).thenReturn(part); // run the tag tag.setBodyContent(this.body); tag.doEndTag(); verify(this.page).addTitlePart(part); }
From source file:org.openmrs.web.taglib.RequireTagTest.java
/** * @see RequireTag#doStartTag()/*from w w w . j av a 2s .c o m*/ */ @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(); }
From source file:test.pl.chilldev.web.tags.page.MetaNameTagTest.java
@Test public void doEndTagWithBodyContent() throws JspTagException { PageContext context = new MockPageContext(); MetaNameTag tag = new MetaNameTag(); tag.setPageContext(context);//from w w w . jav a 2s . c o 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"; when(this.body.getString()).thenReturn(value); // run the tag tag.setKey(key); tag.setBodyContent(this.body); tag.doEndTag(); verify(this.page).setMetaName(key, value); }
From source file:org.openmrs.web.taglib.ForEachEncounterTagTest.java
/** * @see ForEachEncounterTag#doStartTag() * @regression TRUNK-2465// w w w. ja v a 2s . com */ @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()); }
From source file:test.pl.chilldev.web.tags.page.XmlnsTagTest.java
@Test(expected = JspTagException.class) public void doTagInvalidModelType() throws URISyntaxException, JspTagException { JspContext context = new MockPageContext(); XmlnsTag tag = new XmlnsTag(); tag.setJspContext(context);/*ww w .j a va 2 s. c om*/ // set up context String attribute = "foo"; context.setAttribute(attribute, this); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); // run the tag tag.doTag(); }
From source file:com.baidu.rigel.test.strut2.AbstractStruts2SpringContextTests.java
/** * Execute before test method.// w ww.ja v a2 s . co m */ public void executeBeforeTestMethod() { response = new MockHttpServletResponse(); request = new MockHttpServletRequest(); pageContext = new MockPageContext(); servletContext = new MockServletContext(); ActionContext context = new ActionContext(new HashMap<String, Object>()); ServletActionContext.setContext(context); ServletActionContext.setRequest(request); ServletActionContext.setResponse(response); }
From source file:test.pl.chilldev.web.tags.context.JspPageMetaModelResolverTest.java
@Test public void getPageMetaModelWithKey() throws PageMetaModelContextException { JspContext context = new MockPageContext(); String attribute = "foo"; PageMetaModelResolver resolver = new JspPageMetaModelResolver(attribute); PageMetaModel page = new PageMetaModel(); context.setAttribute(attribute, page); assertSame(// w ww .j ava 2s. c o m "JspPageMetaModelResolver.getPageMetaModel() should return existing page model if it's already in context.", page, resolver.getPageMetaModel(context)); }
From source file:test.pl.chilldev.web.tags.page.TitleAddTagTest.java
@Test(expected = JspTagException.class) public void doEndTagInvalidModelType() throws JspTagException { PageContext context = new MockPageContext(); TitleAddTag tag = new TitleAddTag(); tag.setPageContext(context);/*from ww w. ja v a 2 s .c o m*/ // set up context String attribute = "foo"; context.setAttribute(attribute, this); // set up resolver PageMetaModelContextUtils.setPageMetaModelResolver(new JspPageMetaModelResolver(attribute)); // run the tag tag.doEndTag(); }
From source file:test.pl.chilldev.web.spring.context.SpringBeansJspPageMetaModelResolverTest.java
@Test(expected = PageMetaModelContextException.class) public void getPageMetaModelWithoutBean() throws PageMetaModelContextException { GenericWebApplicationContext appContext = new GenericWebApplicationContext(); appContext.refresh();/*from w w w . j a v a 2s . c o m*/ PageContext jspContext = new MockPageContext(); jspContext.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext); PageMetaModelResolver resolver = new SpringBeansJspPageMetaModelResolver(); resolver.getPageMetaModel(jspContext); }