Skip to content

Commit 07dfec8

Browse files
beikovchkal
authored andcommitted
Test for outbound JSF resource rewriting
Signed-off-by: Christian Beikov <christian.beikov@gmail.com>
1 parent 2f39e97 commit 07dfec8

4 files changed

Lines changed: 142 additions & 0 deletions

File tree

‎integration-faces-tests/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
<artifactId>rewrite-config-annotations</artifactId>
5252
<scope>test</scope>
5353
</dependency>
54+
<dependency>
55+
<groupId>org.ocpsoft.rewrite</groupId>
56+
<artifactId>rewrite-config-servlet</artifactId>
57+
<scope>test</scope>
58+
</dependency>
5459
<dependency>
5560
<groupId>javax.enterprise</groupId>
5661
<artifactId>cdi-api</artifactId>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 = &quot;javascript:void(0);jsessionid=fde6b122b14c03b5ad7dcf4c51b5&quot;
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+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 javax.servlet.ServletContext;
19+
20+
import org.ocpsoft.rewrite.config.Configuration;
21+
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
22+
import org.ocpsoft.rewrite.config.Direction;
23+
import org.ocpsoft.rewrite.servlet.config.DispatchType;
24+
import org.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
25+
import org.ocpsoft.rewrite.servlet.config.SendStatus;
26+
import org.ocpsoft.rewrite.servlet.config.rule.Join;
27+
28+
/**
29+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
30+
*
31+
*/
32+
public class OutboundResourceTestProvider extends HttpConfigurationProvider
33+
{
34+
@Override
35+
public int priority()
36+
{
37+
/*
38+
* Priority of overall configuration is lower than default.
39+
*/
40+
return 10;
41+
}
42+
43+
@Override
44+
public Configuration getConfiguration(final ServletContext context)
45+
{
46+
return ConfigurationBuilder.begin()
47+
.addRule(Join.path("/outbound").to("/faces/outbound.xhtml"))
48+
.addRule(Join.path("/css/{file}").to("/faces/javax.faces.resource/css/{file}?ln=test"))
49+
.addRule()
50+
.when(Direction.isInbound().and(DispatchType.isRequest()))
51+
.perform(SendStatus.error(403));
52+
}
53+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml"
3+
xmlns:ui="http://java.sun.com/jsf/facelets"
4+
xmlns:h="http://java.sun.com/jsf/html"
5+
xmlns:f="http://java.sun.com/jsf/core">
6+
<h:head>
7+
<h:outputStylesheet library="test" name="css/style.css"/>
8+
</h:head>
9+
<h:body>
10+
</h:body>
11+
</html>

0 commit comments

Comments
 (0)