|
| 1 | +/* |
| 2 | + * Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.ocpsoft.rewrite.faces.outbound; |
| 17 | + |
| 18 | +import static org.junit.Assert.assertEquals; |
| 19 | + |
| 20 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 21 | +import org.jboss.arquillian.junit.Arquillian; |
| 22 | +import org.jboss.shrinkwrap.api.spec.WebArchive; |
| 23 | +import org.junit.Test; |
| 24 | +import org.junit.experimental.categories.Category; |
| 25 | +import org.junit.runner.RunWith; |
| 26 | +import org.ocpsoft.rewrite.category.IgnoreForGlassfish4; |
| 27 | +import org.ocpsoft.rewrite.faces.annotation.RewriteFacesAnnotationsTest; |
| 28 | +import org.ocpsoft.rewrite.test.RewriteTest; |
| 29 | +import org.ocpsoft.rewrite.test.RewriteTestBase; |
| 30 | + |
| 31 | +import com.gargoylesoftware.htmlunit.html.DomElement; |
| 32 | +import com.gargoylesoftware.htmlunit.html.DomNodeList; |
| 33 | +import com.gargoylesoftware.htmlunit.html.HtmlPage; |
| 34 | +import org.ocpsoft.rewrite.config.ConfigurationProvider; |
| 35 | + |
| 36 | +/** |
| 37 | + * This test doesn't work on Glassfish 4.0 at all. For some reason Glassfish _always_ appends the JSESSIONID, even if |
| 38 | + * the href just contains JavaScript. This leads to links like this: |
| 39 | + * |
| 40 | + * <pre> |
| 41 | + * href = "javascript:void(0);jsessionid=fde6b122b14c03b5ad7dcf4c51b5" |
| 42 | + * </pre> |
| 43 | + * |
| 44 | + * This can be reproduced even in a simple sample application without Rewrite. |
| 45 | + */ |
| 46 | +@RunWith(Arquillian.class) |
| 47 | +@Category(IgnoreForGlassfish4.class) |
| 48 | +public class OutboundResourceTest extends RewriteTestBase |
| 49 | +{ |
| 50 | + |
| 51 | + @Deployment(testable = false) |
| 52 | + public static WebArchive getDeployment() |
| 53 | + { |
| 54 | + return RewriteTest.getDeployment() |
| 55 | + .addAsLibrary(RewriteFacesAnnotationsTest.getRewriteFacesArchive()) |
| 56 | + .addPackages(true, "org.ocpsoft.rewrite.servlet") |
| 57 | + .addClass(OutboundResourceTestProvider.class) |
| 58 | + .addAsWebInfResource("faces-config.xml") |
| 59 | + .addAsWebResource("outbound-resource.css", "resources/test/css/style.css") |
| 60 | + .addAsWebResource("outbound-resource.xhtml", "outbound.xhtml") |
| 61 | + .addAsServiceProvider(ConfigurationProvider.class, OutboundResourceTestProvider.class); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testResourceUrlRewritten() throws Exception |
| 66 | + { |
| 67 | + HtmlPage page = getWebClient("/outbound").getPage(); |
| 68 | + DomNodeList<DomElement> stylesheets = page.getElementsByTagName("link"); |
| 69 | + assertEquals(1, stylesheets.size()); |
| 70 | + assertEquals("/css/style.css", stylesheets.get(0).getAttribute("href")); |
| 71 | + } |
| 72 | + |
| 73 | +} |
0 commit comments