From d651fcf9e299010b3165148ec9b258e67bb091f5 Mon Sep 17 00:00:00 2001 From: Emerson Oliveira Date: Thu, 26 Sep 2013 13:35:01 -0300 Subject: [PATCH] IN PROGRESS - issue FWK-120: Testes da extensão JSF (segurança + mensagem + exceção) --- impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithCorrectRedirect.java | 15 +++++++++++++++ impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithWrongRedirect.java | 15 +++++++++++++++ impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectBean.java | 20 ++++++++++++++++++++ impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ impl/extension/jsf/src/test/resources/exception-handler-redirect/index.xhtml | 9 +++++++++ impl/extension/jsf/src/test/resources/exception-handler-redirect/page.xhtml | 9 +++++++++ impl/extension/jsf/src/test/resources/exception-handler-redirect/redirect.xhtml | 9 +++++++++ impl/extension/jsf/src/test/resources/exception-handler-redirect/web.xml | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 229 insertions(+), 0 deletions(-) create mode 100644 impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithCorrectRedirect.java create mode 100644 impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithWrongRedirect.java create mode 100644 impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectBean.java create mode 100644 impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java create mode 100644 impl/extension/jsf/src/test/resources/exception-handler-redirect/index.xhtml create mode 100644 impl/extension/jsf/src/test/resources/exception-handler-redirect/page.xhtml create mode 100644 impl/extension/jsf/src/test/resources/exception-handler-redirect/redirect.xhtml create mode 100644 impl/extension/jsf/src/test/resources/exception-handler-redirect/web.xml diff --git a/impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithCorrectRedirect.java b/impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithCorrectRedirect.java new file mode 100644 index 0000000..66ec2c6 --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithCorrectRedirect.java @@ -0,0 +1,15 @@ +package exception.handler.redirect; + +import br.gov.frameworkdemoiselle.annotation.Redirect; +import br.gov.frameworkdemoiselle.exception.ApplicationException; + +@Redirect(viewId="/redirect.jsf") +@ApplicationException +public class ExceptionWithCorrectRedirect extends RuntimeException{ + + private static final long serialVersionUID = 1L; + + public ExceptionWithCorrectRedirect(String msg) { + super(msg); + } +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithWrongRedirect.java b/impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithWrongRedirect.java new file mode 100644 index 0000000..f000481 --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/redirect/ExceptionWithWrongRedirect.java @@ -0,0 +1,15 @@ +package exception.handler.redirect; + +import br.gov.frameworkdemoiselle.annotation.Redirect; +import br.gov.frameworkdemoiselle.exception.ApplicationException; + +@Redirect(viewId="/inexist.jsf") +@ApplicationException +public class ExceptionWithWrongRedirect extends RuntimeException{ + + private static final long serialVersionUID = 1L; + + public ExceptionWithWrongRedirect(String msg) { + super(msg); + } +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectBean.java b/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectBean.java new file mode 100644 index 0000000..722cbb4 --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectBean.java @@ -0,0 +1,20 @@ +package exception.handler.redirect; + +import br.gov.frameworkdemoiselle.stereotype.ViewController; + +@ViewController +public class RedirectBean { + + private String redirectCorrectPage = "Correct Redirect Exception!"; + + private String redirectWrongPage = "Wrong Redirect Exception!"; + + public String getRedirectCorrectPage() { + throw new ExceptionWithCorrectRedirect(redirectCorrectPage); + } + + public String getRedirectWrongPage() { + throw new ExceptionWithWrongRedirect(redirectWrongPage); + } + +} diff --git a/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java b/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java new file mode 100644 index 0000000..08a6eeb --- /dev/null +++ b/impl/extension/jsf/src/test/java/exception/handler/redirect/RedirectExceptionTest.java @@ -0,0 +1,78 @@ +package exception.handler.redirect; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URL; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import test.Tests; + +@RunWith(Arquillian.class) +public class RedirectExceptionTest { + + @ArquillianResource + private URL deploymentUrl; + + private static final String PATH = "src/test/resources/exception-handler-redirect"; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + return Tests.createDeployment().addClass(RedirectExceptionTest.class) + .addClass(RedirectBean.class) + .addClass(ExceptionWithCorrectRedirect.class) + .addAsWebResource(Tests.createFileAsset(PATH + "/index.xhtml"), "index.xhtml") + .addAsWebResource(Tests.createFileAsset(PATH + "/page.xhtml"), "page.xhtml") + .addAsWebResource(Tests.createFileAsset(PATH + "/redirect.xhtml"), "redirect.xhtml") + .addAsWebInfResource(Tests.createFileAsset(PATH + "/web.xml"), "web.xml"); + } + + @Test + public void handleExceptionWithCorrectRedirect() { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(deploymentUrl + "/index.jsf"); + + try { + int status = client.executeMethod(method); + String message = method.getResponseBodyAsString(); + + assertEquals(HttpStatus.SC_OK, status); + assertFalse(message.contains("Correct Redirect Exception!")); + assertTrue(message.contains("Page redirected!")); + + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void handleExceptionWithWrongRedirect() { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(deploymentUrl + "/page.jsf"); + + try { + int status = client.executeMethod(method); + assertEquals(HttpStatus.SC_NOT_FOUND, status); + + } catch (HttpException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} + diff --git a/impl/extension/jsf/src/test/resources/exception-handler-redirect/index.xhtml b/impl/extension/jsf/src/test/resources/exception-handler-redirect/index.xhtml new file mode 100644 index 0000000..7cd2a05 --- /dev/null +++ b/impl/extension/jsf/src/test/resources/exception-handler-redirect/index.xhtml @@ -0,0 +1,9 @@ + + + + #{redirectBean.redirectCorrectPage} + + + + diff --git a/impl/extension/jsf/src/test/resources/exception-handler-redirect/page.xhtml b/impl/extension/jsf/src/test/resources/exception-handler-redirect/page.xhtml new file mode 100644 index 0000000..5beea92 --- /dev/null +++ b/impl/extension/jsf/src/test/resources/exception-handler-redirect/page.xhtml @@ -0,0 +1,9 @@ + + + + #{redirectBean.redirectWrongPage} + + + + \ No newline at end of file diff --git a/impl/extension/jsf/src/test/resources/exception-handler-redirect/redirect.xhtml b/impl/extension/jsf/src/test/resources/exception-handler-redirect/redirect.xhtml new file mode 100644 index 0000000..ae2b404 --- /dev/null +++ b/impl/extension/jsf/src/test/resources/exception-handler-redirect/redirect.xhtml @@ -0,0 +1,9 @@ + + + + Page redirected! + + + + \ No newline at end of file diff --git a/impl/extension/jsf/src/test/resources/exception-handler-redirect/web.xml b/impl/extension/jsf/src/test/resources/exception-handler-redirect/web.xml new file mode 100644 index 0000000..b8a230d --- /dev/null +++ b/impl/extension/jsf/src/test/resources/exception-handler-redirect/web.xml @@ -0,0 +1,74 @@ + + + + + br.gov.frameworkdemoiselle.util.ServletListener + + + Demoiselle Servlet Filter + br.gov.frameworkdemoiselle.util.ServletFilter + + + Demoiselle Servlet Filter + /* + + + + Pretty Filter + com.ocpsoft.pretty.PrettyFilter + + + + Pretty Filter + /* + FORWARD + REQUEST + ERROR + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.jsf + + \ No newline at end of file -- libgit2 0.21.2