|
| 1 | +package com.ocpsoft.pretty.faces.test.dynaview; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | +import static org.junit.Assert.assertEquals; |
| 5 | + |
| 6 | +import org.jboss.arquillian.api.Deployment; |
| 7 | +import org.jboss.arquillian.junit.Arquillian; |
| 8 | +import org.jboss.jsfunit.jsfsession.JSFClientSession; |
| 9 | +import org.jboss.jsfunit.jsfsession.JSFSession; |
| 10 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 11 | +import org.junit.Test; |
| 12 | +import org.junit.runner.RunWith; |
| 13 | + |
| 14 | +import com.ocpsoft.pretty.faces.test.PrettyFacesTestBase; |
| 15 | + |
| 16 | +@RunWith(Arquillian.class) |
| 17 | +public class ParameterizedDynaViewTest extends PrettyFacesTestBase |
| 18 | +{ |
| 19 | + |
| 20 | + @Deployment |
| 21 | + public static WebArchive createDeployment() |
| 22 | + { |
| 23 | + return PrettyFacesTestBase.createDeployment() |
| 24 | + .addClass(PathParamDynaViewBean.class) |
| 25 | + .addClass(QueryParamDynaViewBean.class) |
| 26 | + .addClass(DynaViewParameterValidator.class) |
| 27 | + .addResource("dynaview/index.xhtml", "index.xhtml") |
| 28 | + .addResource("dynaview/correct.xhtml", "correct.xhtml"); |
| 29 | + } |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testPathParamInjectionHappensBeforeViewDetermination() throws Exception |
| 33 | + { |
| 34 | + |
| 35 | + // First visit the start page |
| 36 | + JSFSession jsfSession = new JSFSession("/index.jsf"); |
| 37 | + |
| 38 | + // click on the link talking the user to /pathparam/correct |
| 39 | + JSFClientSession client = jsfSession.getJSFClientSession(); |
| 40 | + client.click("pathParamLink"); |
| 41 | + |
| 42 | + // the dynaview code should send the user to the correct page. |
| 43 | + assertTrue(client.getPageAsText().contains("The parameter was correctly injected")); |
| 44 | + |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testQueryParamInjectionHappensBeforeViewDetermination() throws Exception |
| 49 | + { |
| 50 | + |
| 51 | + // First visit the start page |
| 52 | + JSFSession jsfSession = new JSFSession("/index.jsf"); |
| 53 | + |
| 54 | + // click on the link talking the user to /queryparam?param=correct |
| 55 | + JSFClientSession client = jsfSession.getJSFClientSession(); |
| 56 | + client.click("queryParamLink"); |
| 57 | + |
| 58 | + // the dynaview code should send the user to the correct page. |
| 59 | + assertTrue(client.getPageAsText().contains("The parameter was correctly injected")); |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void testInvalidPathParamWithDynaView() throws Exception |
| 65 | + { |
| 66 | + |
| 67 | + // First visit the start page |
| 68 | + JSFSession jsfSession = new JSFSession("/index.jsf"); |
| 69 | + jsfSession.getWebClient().setThrowExceptionOnFailingStatusCode(false); |
| 70 | + |
| 71 | + // click on the link talking the user to /pathparam/invalid |
| 72 | + JSFClientSession client = jsfSession.getJSFClientSession(); |
| 73 | + client.click("invalidPathParamLink"); |
| 74 | + |
| 75 | + // the dynaview code should send the user to the correct page. |
| 76 | + assertEquals(404, client.getContentPage().getWebResponse().getStatusCode()); |
| 77 | + |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testInvalidQueryParamWithDynaView() throws Exception |
| 82 | + { |
| 83 | + |
| 84 | + // First visit the start page |
| 85 | + JSFSession jsfSession = new JSFSession("/index.jsf"); |
| 86 | + jsfSession.getWebClient().setThrowExceptionOnFailingStatusCode(false); |
| 87 | + |
| 88 | + // click on the link talking the user to /queryparam?param=invalid |
| 89 | + JSFClientSession client = jsfSession.getJSFClientSession(); |
| 90 | + client.click("invalidQueryParamLink"); |
| 91 | + |
| 92 | + // the dynaview code should send the user to the correct page. |
| 93 | + assertEquals(404, client.getContentPage().getWebResponse().getStatusCode()); |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | +} |
0 commit comments