|
| 1 | +/* |
| 2 | + * JBoss, Home of Professional Open Source |
| 3 | + * Copyright 2009, Red Hat Middleware LLC, and individual contributors |
| 4 | + * by the @authors tag. See the copyright.txt in the distribution for a |
| 5 | + * full listing of individual contributors. |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package com.ocpsoft.pretty.faces.test; |
| 18 | + |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | + |
| 21 | +import javax.faces.context.FacesContext; |
| 22 | + |
| 23 | +import org.jboss.arquillian.MavenArtifactResolver; |
| 24 | +import org.jboss.arquillian.api.Deployment; |
| 25 | +import org.jboss.arquillian.junit.Arquillian; |
| 26 | +import org.jboss.jsfunit.jsfsession.JSFServerSession; |
| 27 | +import org.jboss.jsfunit.jsfsession.JSFSession; |
| 28 | +import org.jboss.shrinkwrap.api.Archive; |
| 29 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 30 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 31 | +import org.junit.Test; |
| 32 | +import org.junit.runner.RunWith; |
| 33 | + |
| 34 | +import com.ocpsoft.pretty.PrettyContext; |
| 35 | + |
| 36 | +@RunWith(Arquillian.class) |
| 37 | +public class PathParametersTest |
| 38 | +{ |
| 39 | + @Deployment |
| 40 | + public static Archive<?> createDeployment() |
| 41 | + { |
| 42 | + return ShrinkWrap.create(WebArchive.class, "test.war") |
| 43 | + .addResource("basic/index.xhtml", "index.xhtml") |
| 44 | + .addWebResource("faces-config.xml") |
| 45 | + .addWebResource("pretty-config.xml") |
| 46 | + .addLibrary(MavenArtifactResolver.resolve( |
| 47 | + "com.ocpsoft:prettyfaces-jsf2:3.1.1-SNAPSHOT" |
| 48 | + )) |
| 49 | + .setWebXML("jsf-web.xml"); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + public void testNamedPathParameterWithDefaultRegex() throws Exception |
| 54 | + { |
| 55 | + String initialPage = "/default/1234"; |
| 56 | + JSFSession jsfSession = new JSFSession(initialPage); |
| 57 | + JSFServerSession server = jsfSession.getJSFServerSession(); |
| 58 | + FacesContext context = server.getFacesContext(); |
| 59 | + |
| 60 | + PrettyContext prettyContext = PrettyContext.getCurrentInstance(context); |
| 61 | + |
| 62 | + assertEquals(initialPage, prettyContext.getRequestURL().toString()); |
| 63 | + assertEquals("1234", context.getExternalContext().getRequestParameterMap().get("digits")); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testNamedPathParameterWithCustomRegex() throws Exception |
| 68 | + { |
| 69 | + String initialPage = "/digits/1234"; |
| 70 | + JSFSession jsfSession = new JSFSession(initialPage); |
| 71 | + JSFServerSession server = jsfSession.getJSFServerSession(); |
| 72 | + FacesContext context = server.getFacesContext(); |
| 73 | + |
| 74 | + PrettyContext prettyContext = PrettyContext.getCurrentInstance(context); |
| 75 | + |
| 76 | + assertEquals(initialPage, prettyContext.getRequestURL().toString()); |
| 77 | + assertEquals("1234", context.getExternalContext().getRequestParameterMap().get("digits")); |
| 78 | + } |
| 79 | + |
| 80 | +} |
0 commit comments