From d25bd3165c07a4673d615ef4b71475a83b18db0e Mon Sep 17 00:00:00 2001 From: "Lincoln Baxter, III" Date: Sun, 8 Mar 2015 14:52:58 -0400 Subject: [PATCH] Test for #190 --- .../rewrite/faces/error/ErrorBean.java | 41 +++++++++++++ .../faces/error/ErrorPageFormTest.java | 59 +++++++++++++++++++ .../src/test/resources/error-page.xhtml | 17 ++++++ .../src/test/resources/error-web.xml | 12 ++++ 4 files changed, 129 insertions(+) create mode 100644 integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorBean.java create mode 100644 integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorPageFormTest.java create mode 100644 integration-faces-tests/src/test/resources/error-page.xhtml create mode 100755 integration-faces-tests/src/test/resources/error-web.xml diff --git a/integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorBean.java b/integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorBean.java new file mode 100644 index 000000000..0db710baf --- /dev/null +++ b/integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorBean.java @@ -0,0 +1,41 @@ +/* + * Copyright 2011 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * Copyright 2011 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.rewrite.faces.error; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.RequestScoped; + +@ManagedBean +@RequestScoped +public class ErrorBean +{ + +} \ No newline at end of file diff --git a/integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorPageFormTest.java b/integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorPageFormTest.java new file mode 100644 index 000000000..4b7f24fd5 --- /dev/null +++ b/integration-faces-tests/src/test/java/org/ocpsoft/rewrite/faces/error/ErrorPageFormTest.java @@ -0,0 +1,59 @@ +/* + * Copyright 2011 Lincoln Baxter, III + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.ocpsoft.rewrite.faces.error; + +import static org.hamcrest.Matchers.endsWith; +import static org.junit.Assert.assertThat; + +import org.apache.http.client.methods.HttpGet; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ocpsoft.rewrite.faces.annotation.RewriteFacesAnnotationsTest; +import org.ocpsoft.rewrite.test.HttpAction; +import org.ocpsoft.rewrite.test.RewriteTest; +import org.ocpsoft.rewrite.test.RewriteTestBase; + +@RunWith(Arquillian.class) +public class ErrorPageFormTest extends RewriteTestBase +{ + + @Deployment(testable = false) + public static WebArchive getDeployment() + { + return RewriteTest.getDeployment() + .addAsLibrary(RewriteFacesAnnotationsTest.getRewriteAnnotationArchive()) + .addAsLibrary(RewriteFacesAnnotationsTest.getRewriteFacesArchive()) + .addClass(ErrorBean.class) + .addAsWebInfResource("error-web.xml", "web.xml") + .addAsWebResource("error-page.xhtml", "error.xhtml"); + } + + @Test + public void testNavigateWithSimpleString() throws Exception + { + HttpAction client = get("/missingresource"); + assertThat(client.getCurrentURL(), endsWith("/missingresource")); + Assert.assertEquals(404, client.getResponse().getStatusLine().getStatusCode()); + + String content = client.getResponseContent(); + Assert.assertTrue(content.matches("(?s).*action=\"" + client.getContextPath() + "/faces/error\\.xhtml.*")); + } + +} diff --git a/integration-faces-tests/src/test/resources/error-page.xhtml b/integration-faces-tests/src/test/resources/error-page.xhtml new file mode 100644 index 000000000..bd0509aa5 --- /dev/null +++ b/integration-faces-tests/src/test/resources/error-page.xhtml @@ -0,0 +1,17 @@ + + + + + + +

Error Page

+ + +
+ + + diff --git a/integration-faces-tests/src/test/resources/error-web.xml b/integration-faces-tests/src/test/resources/error-web.xml new file mode 100755 index 000000000..4e23c22fe --- /dev/null +++ b/integration-faces-tests/src/test/resources/error-web.xml @@ -0,0 +1,12 @@ + + + + + + /faces/error.xhtml + + + +