Skip to content

Commit b01629e

Browse files
committed
Began prettyfaces tests migration
1 parent c23f6ab commit b01629e

23 files changed

Lines changed: 776 additions & 7 deletions

‎config-prettyfaces-tests-2/pom.xml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.ocpsoft.rewrite</groupId>
7+
<artifactId>rewrite-parent</artifactId>
8+
<version>2.0.0-SNAPSHOT</version>
9+
<relativePath>../</relativePath>
10+
</parent>
11+
12+
<artifactId>rewrite-config-prettyfaces-tests-2</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.ocpsoft.rewrite</groupId>
17+
<artifactId>rewrite-config-prettyfaces</artifactId>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.ocpsoft.rewrite</groupId>
21+
<artifactId>rewrite-config-servlet</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.ocpsoft.rewrite</groupId>
25+
<artifactId>rewrite-impl-servlet</artifactId>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.ocpsoft.rewrite</groupId>
29+
<artifactId>rewrite-integration-cdi</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.jboss.spec.javax.servlet</groupId>
33+
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
34+
<scope>provided</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>javax.enterprise</groupId>
38+
<artifactId>cdi-api</artifactId>
39+
<scope>provided</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>org.ocpsoft.rewrite</groupId>
44+
<artifactId>rewrite-test-harness</artifactId>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
49+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., 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+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.ocpsoft.rewrite.prettyfaces;
23+
24+
import java.io.File;
25+
26+
import org.jboss.shrinkwrap.api.ShrinkWrap;
27+
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
28+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
29+
import org.jboss.shrinkwrap.api.spec.WebArchive;
30+
import org.ocpsoft.rewrite.test.RewriteTest;
31+
32+
/**
33+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
34+
*
35+
*/
36+
public final class PrettyFacesTestBase extends RewriteTest
37+
{
38+
public static WebArchive getDeployment()
39+
{
40+
return RewriteTest.getDeploymentWithCDI()
41+
.addAsWebInfResource(EmptyAsset.INSTANCE, "faces-config.xml")
42+
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
43+
.addAsLibraries(getPrettyFacesArchive())
44+
.addAsLibraries(getRewriteCDIArchive())
45+
.addAsLibraries(resolveDependencies("commons-digester:commons-digester:2.0"));
46+
}
47+
48+
protected static JavaArchive getPrettyFacesArchive()
49+
{
50+
JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "rewrite-config-prettyfaces.jar")
51+
52+
.addAsResource(new File("../config-prettyfaces/target/classes/org"))
53+
.addAsResource(new File("../config-prettyfaces/target/classes/com"))
54+
.addAsResource(new File("../config-prettyfaces/target/classes/META-INF"));
55+
56+
return archive;
57+
}
58+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 org.ocpsoft.rewrite.prettyfaces.context;
18+
19+
import org.apache.http.client.methods.HttpGet;
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.Assert;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.ocpsoft.rewrite.prettyfaces.PrettyFacesTestBase;
27+
import org.ocpsoft.rewrite.test.HttpAction;
28+
import org.ocpsoft.rewrite.test.RewriteTest;
29+
30+
@RunWith(Arquillian.class)
31+
public class PrettyContextTest extends RewriteTest
32+
{
33+
@Deployment(testable = false)
34+
public static WebArchive getDeployment()
35+
{
36+
WebArchive deployment = PrettyFacesTestBase.getDeployment()
37+
.addAsWebResource("context/index.xhtml", "index.xhtml")
38+
.addAsWebInfResource("context/pretty-config.xml", "pretty-config.xml");
39+
40+
System.out.println(deployment.toString(true));
41+
42+
return deployment;
43+
}
44+
45+
@Test
46+
public void testIsPrettyRequest() throws Exception
47+
{
48+
HttpAction<HttpGet> action = get("/");
49+
Assert.assertEquals(200, action.getStatusCode());
50+
Assert.assertTrue(action.getResponseContent().contains("url=/"));
51+
Assert.assertTrue(action.getResponseContent().contains("prettyRequest=true"));
52+
}
53+
54+
@Test
55+
public void testIsNotPrettyRequest() throws Exception
56+
{
57+
HttpAction<HttpGet> action = get("/index.jsf");
58+
Assert.assertEquals(200, action.getStatusCode());
59+
Assert.assertTrue(action.getResponseContent().contains("url=/index.jsf"));
60+
Assert.assertTrue(action.getResponseContent().contains("prettyRequest=false"));
61+
}
62+
63+
@Test
64+
public void testJSessionIdRemovedAutomatically() throws Exception
65+
{
66+
HttpAction<HttpGet> action = get("/;jsessionid=F97KJHsf9876sdf?foo=bar");
67+
Assert.assertEquals(200, action.getStatusCode());
68+
Assert.assertTrue(action.getResponseContent().contains("url=/"));
69+
Assert.assertTrue(action.getResponseContent().contains("query=?foo=bar"));
70+
Assert.assertTrue(action.getResponseContent().contains("prettyRequest=true"));
71+
}
72+
73+
@Test
74+
public void testJSessionIdRemovedAutomaticallyCluster() throws Exception
75+
{
76+
HttpAction<HttpGet> action = get("/;jsessionid=2437ae534134eeae.server1?foo=bar");
77+
Assert.assertEquals(200, action.getStatusCode());
78+
Assert.assertTrue(action.getResponseContent().contains("url=/"));
79+
Assert.assertTrue(action.getResponseContent().contains("query=?foo=bar"));
80+
Assert.assertTrue(action.getResponseContent().contains("prettyRequest=true"));
81+
}
82+
83+
@Test
84+
public void testJSessionIdRemovedAutomaticallyGAE() throws Exception
85+
{
86+
HttpAction<HttpGet> action = get("/;jsessionid=1E-y6jzfx53ou9wymGmcfw?foo=bar");
87+
Assert.assertEquals(200, action.getStatusCode());
88+
Assert.assertTrue(action.getResponseContent().contains("url=/"));
89+
Assert.assertTrue(action.getResponseContent().contains("query=?foo=bar"));
90+
Assert.assertTrue(action.getResponseContent().contains("prettyRequest=true"));
91+
}
92+
93+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2011, Red Hat, Inc., 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+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.ocpsoft.rewrite.prettyfaces.dynaview;
23+
24+
import javax.faces.bean.ManagedBean;
25+
import javax.faces.bean.RequestScoped;
26+
import javax.inject.Named;
27+
28+
/**
29+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
30+
*
31+
*/
32+
@ManagedBean
33+
@RequestScoped
34+
@Named("ambiguousBean")
35+
public class AmbiguousViewIdBean
36+
{
37+
public String getView()
38+
{
39+
return "/index.jsf";
40+
}
41+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 org.ocpsoft.rewrite.prettyfaces.dynaview;
18+
19+
import org.apache.http.client.methods.HttpGet;
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.Assert;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.ocpsoft.rewrite.prettyfaces.PrettyFacesTestBase;
27+
import org.ocpsoft.rewrite.test.HttpAction;
28+
import org.ocpsoft.rewrite.test.RewriteTestBase;
29+
30+
@RunWith(Arquillian.class)
31+
public class AmbiguousViewidTest extends RewriteTestBase
32+
{
33+
@Deployment(testable = false)
34+
public static WebArchive createDeployment()
35+
{
36+
return PrettyFacesTestBase.getDeployment()
37+
.addClass(AmbiguousViewIdBean.class)
38+
.addAsWebResource("dynaview/ambiguousViewId.xhtml", "index.xhtml")
39+
.addAsWebInfResource("dynaview/ambiguous-pretty-config.xml", "pretty-config.xml");
40+
}
41+
42+
@Test
43+
public void testLinkGenerationSelectsCorrectMapping() throws Exception
44+
{
45+
HttpAction<HttpGet> action = get("/foo");
46+
47+
Assert.assertEquals(200, action.getStatusCode());
48+
Assert.assertTrue(action.getResponseContent().contains("action=\"" + action.getContextPath() + "/foo\""));
49+
50+
Assert.assertTrue(action.getResponseContent().contains("href=\"" + action.getContextPath() + "/foo\""));
51+
Assert.assertTrue(action.getResponseContent().contains("href=\"" + action.getContextPath() + "/bar\""));
52+
Assert.assertTrue(action.getResponseContent().contains("href=\"" + action.getContextPath() + "/baz\""));
53+
}
54+
55+
@Test
56+
public void testRendersCorrectURLForDynaview() throws Exception
57+
{
58+
HttpAction<HttpGet> action = get("/baz");
59+
60+
Assert.assertEquals(200, action.getStatusCode());
61+
Assert.assertTrue(action.getResponseContent().contains("action=\"" + action.getContextPath() + "/baz\""));
62+
63+
Assert.assertTrue(action.getResponseContent().contains("href=\"" + action.getContextPath() + "/foo\""));
64+
Assert.assertTrue(action.getResponseContent().contains("href=\"" + action.getContextPath() + "/bar\""));
65+
Assert.assertTrue(action.getResponseContent().contains("href=\"" + action.getContextPath() + "/baz\""));
66+
}
67+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.ocpsoft.rewrite.prettyfaces.dynaview;
2+
3+
import org.apache.http.client.methods.HttpGet;
4+
import org.jboss.arquillian.container.test.api.Deployment;
5+
import org.jboss.arquillian.junit.Arquillian;
6+
import org.jboss.shrinkwrap.api.spec.WebArchive;
7+
import org.junit.Assert;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
import org.ocpsoft.rewrite.prettyfaces.PrettyFacesTestBase;
11+
import org.ocpsoft.rewrite.test.HttpAction;
12+
import org.ocpsoft.rewrite.test.RewriteTestBase;
13+
14+
@RunWith(Arquillian.class)
15+
public class ParameterizedDynaViewInboundTest extends RewriteTestBase
16+
{
17+
@Deployment(testable = false)
18+
public static WebArchive getDeployment()
19+
{
20+
return PrettyFacesTestBase.getDeployment()
21+
.addClass(ParameterizedDynaViewPathParamBean.class)
22+
.addClass(ParameterizedDynaViewQueryParamBean.class)
23+
.addClass(ParameterizedDynaViewValidator.class)
24+
.addAsWebResource("dynaview/parameterized-index.xhtml", "index.xhtml")
25+
.addAsWebResource("dynaview/parameterized-correct.xhtml", "correct.xhtml")
26+
.addAsWebResource("dynaview/parameterized-wrong.xhtml", "wrong.xhtml");
27+
}
28+
29+
@Test
30+
public void testPathParamInjectionHappensBeforeViewDetermination() throws Exception
31+
{
32+
HttpAction<HttpGet> action = get("/pathparam/correct");
33+
34+
Assert.assertEquals(200, action.getStatusCode());
35+
Assert.assertTrue(action.getResponseContent().contains("The parameter was correctly injected"));
36+
}
37+
38+
@Test
39+
public void testQueryParamInjectionHappensBeforeViewDetermination() throws Exception
40+
{
41+
HttpAction<HttpGet> action = get("/queryparam?param=correct");
42+
43+
Assert.assertEquals(200, action.getStatusCode());
44+
Assert.assertTrue(action.getResponseContent().contains("The parameter was correctly injected"));
45+
}
46+
47+
@Test
48+
public void testInvalidPathParamWithDynaView() throws Exception
49+
{
50+
HttpAction<HttpGet> action = get("/pathparam/invalid");
51+
Assert.assertEquals(404, action.getStatusCode());
52+
}
53+
54+
@Test
55+
public void testInvalidQueryParamWithDynaView() throws Exception
56+
{
57+
HttpAction<HttpGet> action = get("/queryparam?param=invalid");
58+
Assert.assertEquals(404, action.getStatusCode());
59+
}
60+
61+
}

0 commit comments

Comments
 (0)