Skip to content

Commit

Permalink
Test for #190
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Mar 8, 2015
1 parent ccff762 commit d25bd31
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
* 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 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
* 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
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
* 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<HttpGet> 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.*"));
}

}
17 changes: 17 additions & 0 deletions integration-faces-tests/src/test/resources/error-page.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<body>

<h:form id="form" prependId="false">

<h1>Error Page</h1>
<h:commandButton id="navigateOutcome"
action="#{jSessionIdBean.navigateOutcome}" value="navigate outcome" />

</h:form>

</body>
</html>
12 changes: 12 additions & 0 deletions integration-faces-tests/src/test/resources/error-web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false">

<error-page>
<location>/faces/error.xhtml</location>
</error-page>

</web-app>

0 comments on commit d25bd31

Please sign in to comment.